Strange graphics fault

Working on a instrument project or just finished a project? Show it to others!

Moderators: russ, Ralph

Post Reply
Message
Author
Detlef
Posts: 304
Joined: Mon Nov 16, 2020 9:43 am
Location: Bavaria

Strange graphics fault

#1 Post by Detlef »

Hello,

I need help here. I have a problem when showing instruments in a second layer (you could say pop-up layer). The same instrument looks fine in the base panel, but when I show it as part of an instrument group on top of other instruments, it gets very blurred. Please see the picture attached.

In my panel lua script I use group_obj_add() and z_order().
faulty-image.png
For what it's worth I attach the panel script and the instrument .siff also. Why does this happen? How can I correct that?

Thank you
Detlef

Code: Select all

-- Detlef von Reusner
-- 30.9.2022 V4 - after Air Manager Reinstall

-- Base panel that switches overlays on and off
-- An overlay is a group of instruments. Each group is automatically framed.
-- More than one overlay can be activated at the same time, if it has the same activation_code.
-- This panel must contain all instruments, including all instruments from the switched panels.

local FRAME_WIDTH = 14

local gOverlay = {}
local gOverlayCount = 0

local gMaxStackHeight = 0 -- needed to draw a frame arround the instruments of a panel
local gCurrentStackHeight = 0
local gCurrentStack = 0

-- ================== add instruments for base panel ===================
-- needed only to define the z_order

function AddBaseInstrument(name, order, uuid, offset)
  z_order(instrument_get(uuid, offset), order)
end

local order = -1

AddBaseInstrument("adaptive background", -2, "c3c51a67-6b2e-4e68-ae91-9ed80f1c35dd")

AddBaseInstrument("hw panel camera FS2020", order, "bc7e35f6-d4d7-4d62-0146-2529ddb3241f")
AddBaseInstrument("hw panel server FS2020", order, "874c8cea-9e44-46d3-a964-ca52c86a9852")
AddBaseInstrument("hw panel ap alt fs2020", order, "338d8818-1703-488e-969a-a18193e2789d")
AddBaseInstrument("hw panel nav 2020", order, "bab2e412-f1d4-4e52-b81d-4564ad1c8c38")
AddBaseInstrument("hw panel gear flaps parkbrake fs2020", order, "fd2825af-8f80-4ef4-9119-fa0ce338f828")
AddBaseInstrument("hw panel ovhd FS2020", order, "c0a9315e-de0c-4ece-0c71-f8c6a38c85b7")
AddBaseInstrument("hw Panel speed hdg fs2020", order, "cdb1003f-a927-4242-26c6-202ceb8e57fd")


-- AddBaseInstrument("AP MCP", order, "50ce3410-4fc8-4e2d-a5a3-83871e6315cd")
AddBaseInstrument("AP MCP", order, "1f763d02-e5c5-4b09-388c-ce8bd4516ed6")
AddBaseInstrument("efis", order, "816bfa0f-fbee-41c4-b33a-13954f9d8194")
AddBaseInstrument("flap auto brake", order, "e0b0fafe-b4a3-4932-8367-92e3a3902aaf")
AddBaseInstrument("fmc overlay", order, "594fb290-e0f0-4da2-25fc-4fa22e438193")
-- AddBaseInstrument("brake annunc", order, "df46f46f-2622-4d5f-8cbd-30c547dd21fa")
-- AddBaseInstrument("rudder trim", order, "94d5396f-bf97-41af-b9b7-3c736a3a0e43")
-- AddBaseInstrument("flexpanel fs2020", order, "624b02b7-9fe1-41e9-8205-456a9aa4629d")
AddBaseInstrument("master fire warning", order, "6eec81f5-0cb6-4efd-9eb4-712d172cdfca")
AddBaseInstrument("annunc ap", order, "12058a76-661e-40aa-3c50-f2fa3a4877e6")
AddBaseInstrument("nav radio", order, "a2e0618f-8cc6-4c4f-1e89-0e128741dfa4", 0)
AddBaseInstrument("nav radio", order, "a2e0618f-8cc6-4c4f-1e89-0e128741dfa4", 1)
AddBaseInstrument("com radio", order, "509cadc9-d22b-4381-816a-171f1a0dce93", 0)
AddBaseInstrument("com radio", order, "509cadc9-d22b-4381-816a-171f1a0dce93", 1)
AddBaseInstrument("adf radio", order, "838b04d9-3e61-4432-35ae-46c70aedd7c4")
AddBaseInstrument("transponder radio", order, "2e38d46d-2b08-4e9a-852f-690b7b64a755")
AddBaseInstrument("ambient light dimmer", order, "f8f83fd0-af45-4991-38cc-4eabc21e872d")
AddBaseInstrument("system annunc pilot", order, "0b1be2ec-0e95-435f-246c-368f4766f514", 0)
AddBaseInstrument("system annunc copilot", order, "0b1be2ec-0e95-435f-246c-368f4766f514", 1)
AddBaseInstrument("Speedbrake Lever", order, "5eb794ef-d1af-4880-1509-982d49ce7e20")

AddBaseInstrument("dome white switch", order, "07d92b03-0407-4bfe-9d27-453654255d73")
AddBaseInstrument("Left Exterior Light Switches", order, "af6cbe42-eaa3-44fd-81c5-f8fb2793805e")
AddBaseInstrument("Right Exterior Light Switches", order, "09fb36a5-ba8b-4d60-b857-b3e7da7d8485")
AddBaseInstrument("Warning Lights Panel", order, "0da5c488-c148-4df5-b52e-033e83a175df")
AddBaseInstrument("clock", order, "02758343-a7a6-4e1d-b406-bd6afa8dc79e")
AddBaseInstrument("Panel select", order, "6b039865-1c7d-4db2-086f-e3af6d1dfc97")
AddBaseInstrument("Landing gear off", order, "4571e64c-49b6-4143-2cf3-78c94e0c0e5a")
-- AddBaseInstrument("Throttle quadrant", order, "ae995bcd-a010-4963-92ff-77aee58669b4")
AddBaseInstrument("Display select panel FO", order, "7c15dbed-b230-4cb3-3fd2-e2aa0cc25ade")
AddBaseInstrument("Display select panel Captain", order, "cf48483c-f787-467b-163f-32d6e910d445")
AddBaseInstrument("GPWS control panel", order, "c0b28794-449b-4324-8fca-5d057d6bcc2f")
AddBaseInstrument("Wiper control panel", order, "c586bf6b-a259-4d3a-aa14-95be04d47ac1")

--==================== functions to organize instruments in stacks of a panel ========================

function StartOverlay(overlay_name, activation_code, stack_width, x, y, scale)
  -- instr_width will be used as column width for this panel
  -- x and y marks the top left corner of this panel
  -- for example scale .5 means the instruments sizes are multiplied by .5
  gOverlayCount = gOverlayCount+1
  gOverlay[gOverlayCount] = {}
  
  local p = gOverlay[gOverlayCount]
  
  p.name = overlay_name
  p.group = group_add()
  p.frame = nil
  p.activation_code = activation_code
  -- multiple overlays can use the same activation_code
  -- the activation_code is sent per system variable
  
  p.stack_width = stack_width*scale
  p.x = x
  p.y = y
  p.scale = scale
  gMaxStackHeight = 0
  gCurrentStack = 0
end

function StartStack()
  gCurrentStackHeight = 0
  gCurrentStack = gCurrentStack+1
end

function AddInstrument(name, width, height, uuid, offset)
  local id = instrument_get(uuid, offset)
  group_obj_add(gOverlay[gOverlayCount].group, id)
  z_order(id, 99)
  local x, y, w, h
  x = (gCurrentStack-1)*gOverlay[gOverlayCount].stack_width + gOverlay[gOverlayCount].x + FRAME_WIDTH
  y = gCurrentStackHeight + gOverlay[gOverlayCount].y + FRAME_WIDTH
  w = width*gOverlay[gOverlayCount].scale
  h = height*gOverlay[gOverlayCount].scale
  if w<gOverlay[gOverlayCount].stack_width then
    x = x + (gOverlay[gOverlayCount].stack_width-w)/2 -- horizontally center within the stack
  end
  move(id, x, y, w, h)
  gCurrentStackHeight = gCurrentStackHeight + h
  if gCurrentStackHeight>gMaxStackHeight then gMaxStackHeight=gCurrentStackHeight end
end

function GenerateFrame()
  -- generate an overlay background with a frame
  local x, y, w, h
  x = gOverlay[gOverlayCount].x
  y = gOverlay[gOverlayCount].y
  w = gCurrentStack * gOverlay[gOverlayCount].stack_width + 2*FRAME_WIDTH
  h = gMaxStackHeight + 2*FRAME_WIDTH
  gOverlay[gOverlayCount].frame = canvas_add(x, y, w, h, function()
    _rect(0, 0, w, h)
    _fill("#101010ff")
    _move_to(FRAME_WIDTH/2, FRAME_WIDTH/2)
    _line_to(w - FRAME_WIDTH/2, FRAME_WIDTH/2)
    _line_to(w - FRAME_WIDTH/2, h - FRAME_WIDTH/2)
    _line_to(FRAME_WIDTH/2, h - FRAME_WIDTH/2)
    _line_to(FRAME_WIDTH/2, FRAME_WIDTH/2)
    _stroke("#080808ff", FRAME_WIDTH)
  end)
  z_order(gOverlay[gOverlayCount].frame, -1)
  z_order(gOverlay[gOverlayCount].group, 99)
end

-- ======================= shade base instruments while an overlay is active ===========================

local gShade = {}

gShade[0] = canvas_add(200, 0, 3640, 1080, function()
  _rect(0, 0, 3640, 1080)
  _fill("black")
end)

gShade[1] = img_add_fullscreen("popup-mask-pmdg.png")

z_order(gShade[0], 98)
opacity(gShade[0], .8)
z_order(gShade[1], 98)
opacity(gShade[1], .8)

visible(gShade[0], false)
visible(gShade[1], false)

-- ========== forward overhead panel instruments ========================

StartOverlay("FWD Overhead Panel Left", 1, 400, 1140, 20, .9)

StartStack()
AddInstrument("Flight Control", 400, 560, "2fa3c344-3e29-444d-8966-a146d3147619")
AddInstrument("Fuel Pump Switches", 400, 580, "5f3fdf98-cf3f-47de-b7b5-9b4e13175dc9")

StartStack()
AddInstrument("EMER EXIT LIGHT", 200, 340, "3df6a207-c21d-4b7b-81ba-100c0dbbd4d5")
AddInstrument("APU EGT", 200, 200, "15f05f56-760f-4068-af56-c3a0fd64fae8")
AddInstrument("APU & Eng Start Switch", 400, 150, "11ae414a-51a7-4bdb-a0e6-bd54124ee5af")

GenerateFrame()

------------- split
StartOverlay("FWD Overhead Panel Right", 1, 400, 2433, 20, .8)

StartStack()
AddInstrument("ACDC Panel", 400, 550, "bfa16d59-e4f6-444d-2d7b-a8e597c20315")
AddInstrument("Standby Power", 400, 280, "518ebdb0-4a93-4477-01bd-514db3230904")
AddInstrument("Generator Switches", 400, 405, "3172aa53-47b5-415e-3366-878815a98a49")

StartStack()
AddInstrument("Pitot and Window Heat", 400, 460, "62f80aa5-b789-4ac3-3963-44fbce630aaf")
AddInstrument("Anti-Ice", 400, 255, "429f27b5-848e-4e9d-b27b-5d77ffa9a720")
AddInstrument("Hydraulics Switches", 400, 240, "fe61bfa7-21f8-4b7e-a4d3-045a198707cf")
AddInstrument("Doors", 400, 210, "283b8204-1550-4770-313b-9591e7ce92b7")

StartStack()
AddInstrument("Bleed", 400, 550, "94fa5175-840e-47c1-2c74-651487865d74")
AddInstrument("Pressurization", 400, 480, "a0ff71dd-e64d-4c5b-3594-1454fb02a930")


GenerateFrame()


-- ============== aft overhead panel instruments =====================

StartOverlay("Aft overhead panel", 2, 400, 1000, 50, 1.0)

StartStack()
AddInstrument("Cabin Pressure", 400, 410, "5d80ecb6-0aec-4d3b-37fd-d80e67b9e34f")
AddInstrument("IRS Select Mode", 400, 270, "315ded83-dea9-4a00-33b1-9ff9a6552040")
AddInstrument("LE Devices", 400, 185, "89604fa1-9faf-44e1-916f-049855ac9bb7")

GenerateFrame()

-- =================== panel activation and deactivation =========================

function ShowOverlays(activation_code)
  local active = false
  visible(gShade[0], activation_code ~= 0 and activation_code ~= 1)
  visible(gShade[1], activation_code == 1) -- specific mask for activation code 1
  for overlay=1,gOverlayCount do
    active = (activation_code == gOverlay[overlay].activation_code)
    visible(gOverlay[overlay].group, active)
    visible(gOverlay[overlay].frame, active)
  end
end

si_variable_subscribe("sivar_activate_panel", "INT", ShowOverlays)
--ShowOverlays(2)


User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Strange graphics fault

#2 Post by Ralph »

Please export your panel and the required assets, or it will be difficult to test.
And please try to put this into a small test panel, make it all as small as possible so it is easier to understand what is going on.
Now I have to go trough trough 222 lines of code to figure it out :)

Detlef
Posts: 304
Joined: Mon Nov 16, 2020 9:43 am
Location: Bavaria

Re: Strange graphics fault

#3 Post by Detlef »

Hi Ralph,

no it's not just the 222 lines in the panel script. In addition it's the 1000 lines of instrument/lib code :) I wanted to save me the process of shrinking everything down as much as possible, because maybe someone had had such a blurred instrument picture before. But of course I have no other way now than to do that.

Thanks
Detlef

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Strange graphics fault

#4 Post by Ralph »

It is easier for us to monitor and find out if it is a very simple panel. If you can reproduce it with two instruments for example, then that would be great.

Detlef
Posts: 304
Joined: Mon Nov 16, 2020 9:43 am
Location: Bavaria

Re: Strange graphics fault

#5 Post by Detlef »

Hi,

I have tried to produce the same error with less instruments and code but could not. So I have generated all-new panels and put the instruments in it. The fault is gone for now.
I have no explanation for that.

Thanks
Detlef

Post Reply