front and back text style

Help and techniques for creating Air Manager Instrument Graphics

Moderators: Ralph, russ

Post Reply
Message
Author
sikorsky77
Posts: 22
Joined: Sun Dec 06, 2015 1:09 pm

front and back text style

#1 Post by sikorsky77 » Sun Dec 30, 2018 8:40 pm

Hi all
another question about text

i am creating a 2 tank fuel gauge with have 2 color conditions
if Quantity is > 200 kg then
background black with text written in green
else
background red with text written in white
end

i look the list of the the style text , but don't see nothing about the background style of a text
i look the canvas documentation and i think i can create 2 canvas Black and Red equal to the text size definition and write inside the text in the conditional color ?
but , the question is : is it the best technical and performed solution ?

sorry for this stupid basic question ?

best regards
Thierry

sikorsky77
Posts: 22
Joined: Sun Dec 06, 2015 1:09 pm

Re: front and back text style

#2 Post by sikorsky77 » Sun Dec 30, 2018 8:45 pm

hi all

please, forget my post
looking deeply in the canvas draw function i see that i can create a text inside with specific style attributes , color , size , font, etc...
sorry , my question was stupid

best regards
Thierry

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

Re: front and back text style

#3 Post by Ralph » Sun Dec 30, 2018 9:56 pm

You'll indeed need to draw a rectangle behind it and change the color.

sikorsky77
Posts: 22
Joined: Sun Dec 06, 2015 1:09 pm

Re: front and back text style

#4 Post by sikorsky77 » Mon Dec 31, 2018 1:15 am

HI Ralf
yes it is what i made but i have an issue i don't understand
i create 2 canvas
one is a vertical bar for the fuel in Left & Right Tank which works (the bar color change from green to red when tank is near empty)

and i add another 2 text canvas-draw with the fuel quantity for left & right tank and i have a error message i don't understand the sense
see attached screenshot

here the code of the fuel gauge
no ressources needed excepted this code

it is the _txt(.....) line 71 & 76 that generate the error , variables have values (see the print in console) , so i dont understand the error message
71 is _txt(V_TEMP_001 , V_TEMP_002, 0, 0) -- V_TEMP_001 = Text left fuel Qty , V_TEMP_002 = text style
76 is _txt(V_TEMP_011 , V_TEMP_012, 0, 0) -- V_TEMP_011 = Text right fuel Qty , V_TEMP_012 = text style

if you have an idea to help me
best regards
Thierry
------------------------------------------ code -------------------------------------------------------------
-- Author --- Thierry Georgelin
-- Aircraft --- Falcon 2000
-- Simulator --- FSX
---------------------------- Init global parametres -----------------------
V_FONT_SIZE = 48
V_FONT_NAME = "arialbd.ttf" ------- or "Monda-bold.ttf"
V_GREEN_COLOR = "#00FF00"
V_WHITE_COLOR = "white"
V_RED_COLOR = "red"
V_BLACK_COLOR = "black"
V_GALLON_TO_LB = 6.703
V_FUEL_LEFT_QTY_HIGH_BAR = 0
V_FUEL_RIGHT_QTY_HIGH_BAR = 0
V_FUEL_LEFT_QUANTITY_LB = 0.0
V_FUEL_RIGHT_QUANTITY_LB = 0.0
--------------------------------- Init Various ID -----------------------------------
T_FUEL_MAX_CURRENT_QUANTITY_NAME = txt_add("", "font:"..V_FONT_NAME.."; size:".. V_FONT_SIZE .." ; color:" ..V_WHITE_COLOR .. "; halign:center;", 301 , 201 , 200 , 100)
CI_BAR_FUEL_QUANTITY_LEFT = canvas_add(221 , 176 , 60, 200 ) -- Canvas image left bar
CI_BAR_FUEL_QUANTITY_RIGHT = canvas_add(451 , 176 , 60, 200) -- Canvas image right bar
CT_BACK_FRONT_FUEL_QUANTITY_LEFT = canvas_add(21 , 201 , 160, 100 ) -- Canvas Text left Qty fuel
CT_BACK_FRONT_FUEL_QUANTITY_RIGHT = canvas_add(601 , 201 , 160, 100) -- Canvas Right left Qty fuel
-------------------------------- Function for Fuel Informattions ----------------------------------------------------------------
function F_FUEL_MAX_CURRENT_QUANTITY(V_FUEL_LEFT_CAPACITY ,V_FUEL_RIGHT_CAPACITY , V_FUEL_LEFT_QUANTITY , V_FUEL_RIGHT_QUANTITY)
V_Test = true
txt_set(T_FUEL_MAX_CURRENT_QUANTITY_NAME, "QTY LB")
V_FUEL_LEFT_QTY_HIGH_BAR = math.floor(100 * (V_FUEL_LEFT_QUANTITY / V_FUEL_LEFT_CAPACITY)) -- 100 pixels left fuel bar max x (% of Fuel)
V_FUEL_LEFT_QUANTITY_LB = math.floor(V_FUEL_LEFT_QUANTITY * V_GALLON_TO_LB / 5) * 5 -- convertion Fuel left qty in LB rounded at 5
V_TEMP_001 = tostring(math.floor(V_FUEL_LEFT_QUANTITY_LB)) -- convertion Fuel left Qty LB in Text
V_FUEL_RIGHT_QTY_HIGH_BAR = math.floor(100 * (V_FUEL_RIGHT_QUANTITY / V_FUEL_RIGHT_CAPACITY)) -- 100 pixels right fuel bar max x (% of Fuel)
V_FUEL_RIGHT_QUANTITY_LB = math.floor(V_FUEL_RIGHT_QUANTITY * V_GALLON_TO_LB / 5) * 5 -- convertion right Fuel qty in LB rounded at 5
V_TEMP_011 = tostring(math.floor(V_FUEL_RIGHT_QUANTITY_LB)) -- convertion Fuel right Qty LB in Text

if V_Test == true then
print("Max Capa L = "..V_FUEL_LEFT_CAPACITY .. " Current Qty L = ".. V_FUEL_LEFT_QUANTITY)
print("Current Qty L & in LB = ".. V_FUEL_LEFT_QUANTITY_LB .. " & converted txt = " .. V_TEMP_001)
print("Max Capa R = "..V_FUEL_RIGHT_CAPACITY .. " Current Qty R = ".. V_FUEL_RIGHT_QUANTITY)
print("Current Qty R & in LB = ".. V_FUEL_RIGHT_QUANTITY_LB .. " & converted txt = " .. V_TEMP_011)
end
if V_FUEL_LEFT_QUANTITY_LB > 900 then -- check fuel Left qty in LB (if >900 then Bar and quantity are green on black background else Bar is red and Text is white on red background)
V_TEMP_002 = "font: " .. V_FONT_NAME .. " ; size: " .. V_FONT_SIZE .. " ; color: ".. V_GREEN_COLOR .. " ; halign: center ;" -- Text Style of left Qty LB
V_TEMP_003 = V_BLACK_COLOR -- Background color of left text canvas
V_TEMP_004 = V_GREEN_COLOR -- Fuel Left Quantity Bar color
else
V_TEMP_002 = "font:" .. V_FONT_NAME .. " ; size: " .. V_FONT_SIZE .. " ; color: ".. V_WHITE_COLOR .. " ; halign: center;" -- Text Style of left Qty LB
V_TEMP_003 = V_RED_COLOR -- Background color of left text canvas
V_TEMP_004 = V_RED_COLOR -- Fuel left Quantity Bar color
end
if V_FUEL_RIGHT_QUANTITY_LB > 900 then -- check fuel Right Qty in LB (if >900 then Bar and quantity are green on black background else Bar is red and Text is white on red background)
V_TEMP_012 = "font: " .. V_FONT_NAME .. " ; size: " .. V_FONT_SIZE .. " ; color: ".. V_GREEN_COLOR .. " ; halign: center ;" -- Text Style of right Qty LB
V_TEMP_013 = V_BLACK_COLOR -- Background color of right text canvas
V_TEMP_014 = V_GREEN_COLOR -- Fuel right Quantity Bar color
else
V_TEMP_012 = "font:" .. V_FONT_NAME .. " ; size: " .. V_FONT_SIZE .. " ; color: ".. V_WHITE_COLOR .. " ; halign: center;" -- Text Style of right Qty LB
V_TEMP_013 = V_RED_COLOR -- Background color of right text canvas
V_TEMP_014 = V_RED_COLOR -- Fuel right Quantity Bar color
end
if V_Test == true then
print("Background Left text color = " .. V_TEMP_003 .. " / Text style = " .. V_TEMP_002)
print("Fuel Quantity Left bar color = " .. V_TEMP_004)
print("Background Right text color = " .. V_TEMP_013 .. " / Text style = " .. V_TEMP_012)
print("Fuel Quantity Right bar color = " .. V_TEMP_014)
end
canvas_draw(CI_BAR_FUEL_QUANTITY_LEFT ,function() -- Bar of Fuel Quantity
_rect(0 , 0 , 60 , V_FUEL_LEFT_QTY_HIGH_BAR)
_fill(V_TEMP_004)
end)
canvas_draw(CI_BAR_FUEL_QUANTITY_RIGHT ,function() -- Bar of Fuel Quantity
_rect(0 , 0 , 60 , V_FUEL_RIGHT_QTY_HIGH_BAR)
_fill(V_TEMP_014)
end)
canvas_draw(CT_BACK_FRONT_FUEL_QUANTITY_LEFT , function() -- Text of Left Fuel Quantity
_rect(21 , 201 , 160, 100)
_txt(V_TEMP_001 , V_TEMP_002, 0, 0) -- V_TEMP_001 = Text Full Qty , V_TEMP_002 = text style
_fill(V_TEMP_003) -- Background color
end)
canvas_draw(CT_BACK_FRONT_FUEL_QUANTITY_RIGHT , function() -- Text of Right Fuel Quantity
_rect(601 , 201 , 160, 100)
_txt(V_TEMP_011 , V_TEMP_012, 0, 0) -- V_TEMP_011 = Text Full Qty , V_TEMP_012 = text style
_fill(V_TEMP_013) -- Background color
end)
end
------------------------------------- variables Subscription -----------------------------------------------------------------
fsx_variable_subscribe("FUEL LEFT CAPACITY" , "Gallons" , "FUEL RIGHT CAPACITY" , "Gallons"
, "FUEL LEFT QUANTITY" , "Gallons" , "FUEL RIGHT QUANTITY" , "Gallons" , F_FUEL_MAX_CURRENT_QUANTITY)
Attachments
Error Canvas_Draw.PNG

User avatar
Sling
Posts: 4441
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: front and back text style

#5 Post by Sling » Mon Dec 31, 2018 4:58 am

Thierry,

_txt is only available in the AM 3.5 beta. I bet you are using AM 3.4. This same functionality can be done in 3.4 though. Just create 2 background images or canvasses if you prefer and then use txt_add to add text of each colour on top of the img/canvas. Then just use visibility to show the background and text colour combination you want. You could change the text colour by using txt_style but it’s more efficient to create 2 text elements and show/hide.

Tony

sikorsky77
Posts: 22
Joined: Sun Dec 06, 2015 1:09 pm

Re: front and back text style

#6 Post by sikorsky77 » Mon Dec 31, 2018 10:13 am

Hi Tony

Thanks about your Quick answer
You believe true , i am in 3.4 version
i will apply your suggestion

Thanks again
THierry

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest