画像を自分で作成して7セグメント風の表示をする。

私の場合はAffinty DEsinerを使って作成した。左上の「ドキュメント設定」から以下のようにチェックを入れてバックを透明にする。72dpiで作成。サイズは自分なりの微調整が必要。

Macのプレビューを72dpiで作成して大きさを確認して、imgui.Image(image_E_0, 67, 120)にも寸法を合わせる。X-Planeのノブを回すと合わせて数値が変化する。
数字は画像なので自由に作成できる。画像自体の大きさを全て統一して透明で作成するのがポイント。大きさも出来るだけ小さく、72dpiで作成するのもポイントになる。
目次
画像を使った7セグメントの基本の考え方
画像を入れる場合はdatarefから取得した数値の状態を把握する必要がある。その後、桁数毎に数値を取得する必要があるので結構面倒な作業に成る。

-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png")
local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png")
local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png")
local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png")
local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png")
local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png")
local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png")
local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png")
local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png")
local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png")
local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png")
local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png")
local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png")
local image_7seg_space = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_space.png")
local course_7seg_images = { image_7seg_space, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9
}
local IAS_MACH_7seg_images_3 = { image_7seg_space, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9
}
local IAS_MACH_7seg_images_2_1 = { image_7seg_0, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9
}
local HEADING_image_7seg_3_2_1 = { image_7seg_0, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9, image_7seg_A }
local ALTITUDE_image_7seg_5_4_3_2_1 = { image_7seg_0, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4,
image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 }
local VERT_SPEED_7seg_5_4_3_2_1 = { image_7seg_space, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4,
image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 }
local VS_7seg_image_pattern_B = { image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 }
local MACH_7seg_image_2_1 = { image_7seg_0, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5,
image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9, image_7seg_A }
local number_7seg = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" } --全体で使用する数の一番大きい数を設定しておくと良い
local VS_7seg_number_pattern_A = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" } --10
local VS_7seg_number_pattern_B = { "1", "2", "3", "4", "5", "6", "7", "8", "9" } --9
DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot")
DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach")
DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial")
DataRef("mcp_Alt_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial")
DataRef("ap_VVI_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos")
---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(350, 600, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "7segment Test")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
------------------- CPURSE 7セグメント表示 ------------------------------------------------------------------------------
Course_7seg = string.format("%03d", COURSE_7segment) --dataref値は整数 23、これに0をつけた3桁で023と表示されるようになる。
--桁毎に数値を取り出す
Course_1_digit = string.sub(Course_7seg, 3, 3) --1桁目、string.sub は数値でなく文字列なので入れる時は" " で囲む
Course_2_digit = string.sub(Course_7seg, 2, 2) --2桁目を取得
Course_3_digit = string.sub(Course_7seg, 1, 1) --3桁目を取得
imgui.TextUnformatted("COURSE_dataref: " .. Course_3_digit .. Course_2_digit .. Course_1_digit)
imgui.TextUnformatted("A-3 : " .. Course_3_digit) --3桁目
imgui.TextUnformatted("A-2 : " .. Course_2_digit) --2
imgui.TextUnformatted("A-1 : " .. Course_1_digit) --1
imgui.SetCursorPosX(200)
imgui.SetCursorPosY(30)
for i = 1, #course_7seg_images do
if Course_3_digit == number_7seg[i] then --文字列なので"0"と入れる必要がある。
imgui.Image(course_7seg_images[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #course_7seg_images do
if Course_2_digit == number_7seg[i] then --文字列なので"0"と入れる必要がある。
imgui.Image(course_7seg_images[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #course_7seg_images do
if Course_1_digit == number_7seg[i] then --文字列なので"0"と入れる必要がある。
imgui.Image(course_7seg_images[i], 17, 29)
end
end
------------IAS_MACH 7セグメント表示------------------------------------------------------------------------------
--IAS 7セグメント選択の場合
IAS_speed_7seg = string.format("%03d", IAS_MACH_7segment) --dataref値は整数 23、これで0をつけた3桁で023と表示されるようになる。
IAS_speed_3_digit = string.sub(IAS_speed_7seg, 1, 1) --3桁目を取得
IAS_speed_2_digit = string.sub(IAS_speed_7seg, 2, 2) --2
IAS_speed_1_digit = string.sub(IAS_speed_7seg, 3, 3) --1
imgui.SetCursorPosY(90)
imgui.TextUnformatted("IAS_MACH_dataref: " .. IAS_speed_3_digit .. IAS_speed_2_digit .. IAS_speed_1_digit)
imgui.TextUnformatted("IAS_MACH-3 : " .. IAS_speed_3_digit) --3桁目
imgui.TextUnformatted("IAS_MACH-2 : " .. IAS_speed_2_digit) --2
imgui.TextUnformatted("IAS_MACH-1 : " .. IAS_speed_1_digit) --1
imgui.SetCursorPosX(200)
imgui.SetCursorPosY(110)
for i = 1, #IAS_MACH_7seg_images_3 do
if IAS_speed_3_digit == number_7seg[i] then --文字列なので"0"と入れる必要がある。
imgui.Image(IAS_MACH_7seg_images_3[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #IAS_MACH_7seg_images_2_1 do
if IAS_speed_2_digit == number_7seg[i] then --文字列なので"0"と入れる必要がある。
imgui.Image(IAS_MACH_7seg_images_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #IAS_MACH_7seg_images_2_1 do
if IAS_speed_1_digit == number_7seg[i] then --文字列なので"0"と入れる必要がある。
imgui.Image(IAS_MACH_7seg_images_2_1[i], 17, 29)
end
end
--MACH 7セグメント選択の場合
---IAS_MACH_7segment_value_B = IAS_MACH_7segment + 0.005--小数点以下3桁目を四捨五入するため
MACH_speed_7seg = string.format("%3.2f", IAS_MACH_7segment)
MACH_speed_2_digit = string.sub(MACH_speed_7seg, 3, 3) --2
MACH_speed_1_digit = string.sub(MACH_speed_7seg, 4, 4) --1
imgui.SetCursorPosY(500)
--B_data = string.sub(IAS_MACH_7segment_value, 1, 4)
imgui.TextUnformatted("IAS_MACH_dataref " .. MACH_speed_7seg)
imgui.TextUnformatted("IAS_MACH-2 : " .. MACH_speed_2_digit) --2
imgui.TextUnformatted("IAS_MACH-1 : " .. MACH_speed_1_digit) --1
imgui.SetCursorPosX(200)
imgui.SetCursorPosY(520)
imgui.Image(image_7seg_point, 7, 26) --マッハの頭に入る「.」をここに入れている
imgui.SameLine(nil, 5)
for i = 1, 10 do --2桁目
if MACH_speed_2_digit == number_7seg[i] then --
imgui.Image(MACH_7seg_image_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, 10 do --1桁目
if MACH_speed_1_digit == number_7seg[i] then --
imgui.Image(MACH_7seg_image_2_1[i], 17, 29)
end
end
------------------- HEADING 7セグメント表示 ------------------------------------------------------------------------------
--桁毎に数値を取り出す
HEADING_1_digit = string.sub(mcp_hdg_dial_7segment, 3, 3) --1桁目を取得
HEADING_2_digit = string.sub(mcp_hdg_dial_7segment, 2, 2) --2桁目を取得
HEADING_3_digit = string.sub(mcp_hdg_dial_7segment, 1, 1) --3桁目を取得
imgui.SetCursorPosY(180) --+90
imgui.TextUnformatted("HEADING_dataref: " .. HEADING_3_digit .. HEADING_2_digit .. HEADING_1_digit)
imgui.TextUnformatted("HEADING-3 : " .. HEADING_3_digit) --3桁目
imgui.TextUnformatted("HEADING-2 : " .. HEADING_2_digit) --2
imgui.TextUnformatted("HEADING-1 : " .. HEADING_1_digit) --1
imgui.SetCursorPosX(200)
imgui.SetCursorPosY(205)
for i = 1, #HEADING_image_7seg_3_2_1 do --3桁目
if HEADING_3_digit == number_7seg[i] then
imgui.Image(HEADING_image_7seg_3_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #HEADING_image_7seg_3_2_1 do --2桁目
if HEADING_2_digit == number_7seg[i] then
imgui.Image(HEADING_image_7seg_3_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #HEADING_image_7seg_3_2_1 do --1桁目
if HEADING_1_digit == number_7seg[i] then
imgui.Image(HEADING_image_7seg_3_2_1[i], 17, 29)
end
end
-------------------- ALTITUDE 7セグメント表示 ------------------------------------------------------------------------------
--頭揃えになって、後ろに桁が増えるので位置が変化してしまう。最初から一番大きい桁にすると位置が固定になる。ここでは万の数値になるので5桁になる。
mcp_ALT_dial_7seg = string.format("%05d", mcp_Alt_dial_7segment) --dataref値整数 2300の場合、これで0をつけた5桁で02300と表示されるようになる。
--後は頭に付く0を空白に変えることになる。ここではそのまま0になっている。実際に使うときに変更すること。
--桁毎に数値を取り出す
ALTITUDE_5_digit = string.sub(mcp_ALT_dial_7seg, 1, 1) --5桁目を取得
ALTITUDE_4_digit = string.sub(mcp_ALT_dial_7seg, 2, 2) --4
ALTITUDE_3_digit = string.sub(mcp_ALT_dial_7seg, 3, 3) --3
ALTITUDE_2_digit = string.sub(mcp_ALT_dial_7seg, 4, 4) --2
ALTITUDE_1_digit = string.sub(mcp_ALT_dial_7seg, 5, 5) --1
imgui.SetCursorPosY(270) --+90
imgui.TextUnformatted("ALTITUDE_dataref: " ..
ALTITUDE_5_digit .. ALTITUDE_4_digit .. ALTITUDE_3_digit .. ALTITUDE_2_digit .. ALTITUDE_1_digit)
imgui.TextUnformatted("ALTITUDE-3 : " .. ALTITUDE_5_digit) --5桁目
imgui.TextUnformatted("ALTITUDE-3 : " .. ALTITUDE_4_digit) --4桁目
imgui.TextUnformatted("ALTITUDE-3 : " .. ALTITUDE_3_digit) --3桁目
imgui.TextUnformatted("ALTITUDE-2 : " .. ALTITUDE_2_digit) --2
imgui.TextUnformatted("ALTITUDE-1 : " .. ALTITUDE_1_digit) --1
imgui.SetCursorPosX(200)
imgui.SetCursorPosY(300)
for i = 1, #ALTITUDE_image_7seg_5_4_3_2_1 do --5桁目
if ALTITUDE_5_digit == number_7seg[i] then
imgui.Image(ALTITUDE_image_7seg_5_4_3_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #ALTITUDE_image_7seg_5_4_3_2_1 do --4桁目
if ALTITUDE_4_digit == number_7seg[i] then
imgui.Image(ALTITUDE_image_7seg_5_4_3_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #ALTITUDE_image_7seg_5_4_3_2_1 do --3桁目
if ALTITUDE_3_digit == number_7seg[i] then
imgui.Image(ALTITUDE_image_7seg_5_4_3_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #ALTITUDE_image_7seg_5_4_3_2_1 do --2桁目
if ALTITUDE_2_digit == number_7seg[i] then
imgui.Image(ALTITUDE_image_7seg_5_4_3_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
for i = 1, #ALTITUDE_image_7seg_5_4_3_2_1 do --1桁目
if ALTITUDE_1_digit == number_7seg[i] then
imgui.Image(ALTITUDE_image_7seg_5_4_3_2_1[i], 17, 29)
end
end
-------------------- VERT SPEED 7セグメント表示 ------------------------------------------------------------------------------
--VERT SPEED 7セグメント表示
VVI_pos_7seg = string.format("%05d", ap_VVI_pos_7segment) --マイナスが5桁になるので "%05d" になる
--桁毎に数値を取り出す
--上で変換した数字を取り指す作業、最初の「1,1」と最後の「6,6」もマイナス等が関係しているが実際は使わないので削除している。
ap_VVI_pos_4_digit = string.sub(VVI_pos_7seg, 2, 2) --4
ap_VVI_pos_3_digit = string.sub(VVI_pos_7seg, 3, 3) --3
ap_VVI_pos_2_digit = string.sub(VVI_pos_7seg, 4, 4) --2
ap_VVI_pos_1_digit = string.sub(VVI_pos_7seg, 5, 5) --1
imgui.SetCursorPosY(390) --+90
--データがどのようになっているかを見るために表示している。"ap_VVI_pos_1_digit :"と合わせると良い。
imgui.TextUnformatted("VERT SPEED_dataref : " .. ap_VVI_pos_7segment) --datare値を表示
imgui.TextUnformatted("VERT SPEED_4_digit : " .. ap_VVI_pos_4_digit) --4
imgui.TextUnformatted("VERT SPEED_3_digit : " .. ap_VVI_pos_3_digit) --3
imgui.TextUnformatted("VERT SPEED_2_digit : " .. ap_VVI_pos_2_digit) --2
imgui.TextUnformatted("ap_VVI_pos_1_digit : " .. ap_VVI_pos_1_digit) --1桁目を表示
--プラスとマイナスの記号を表示するたものもの
imgui.SetCursorPosX(200)
imgui.SetCursorPosY(400)
if ap_VVI_pos_7segment > 0 then
imgui.Image(image_7seg_plus, 17, 29)
end
if ap_VVI_pos_7segment < 0 then
imgui.Image(image_7seg_minus, 17, 29)
end
imgui.SetCursorPosX(225) --4桁以降のポジション
imgui.SetCursorPosY(400)
for i = 1, 10 do
if ap_VVI_pos_4_digit == number_7seg[i] then --一応0を入れているがこれは実際は使わないはずである。
imgui.Image(VERT_SPEED_7seg_5_4_3_2_1[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
--ここで50と-50と1000になったとき頭に0が付くので空白にするためのもの
if ap_VVI_pos_7segment == 50 or ap_VVI_pos_7segment == -50 or ap_VVI_pos_7segment == 0000 then
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_3_digit == "0" then --上以外の場合は空白ではなく"0"にする。
imgui.Image(image_7seg_0, 17, 29)
end
for i = 1, 9 do
if ap_VVI_pos_3_digit == VS_7seg_number_pattern_B[i] then
imgui.Image(VS_7seg_image_pattern_B[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
--ここで0000になったとき「2桁目」の数字を何も表示しないようにするためのもの
if ap_VVI_pos_7segment == 0000 then
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_2_digit == "0" then --上以外の場合は空白ではなく"0"にする。
imgui.Image(image_7seg_0, 17, 29)
end
for i = 1, 9 do
if ap_VVI_pos_2_digit == VS_7seg_number_pattern_B[i] then
imgui.Image(VS_7seg_image_pattern_B[i], 17, 29)
end
end
imgui.SameLine(nil, 5)
--ここで0000になったとき「1桁目」の数字を何も表示しないようにするためのもの
if ap_VVI_pos_7segment == 0000 then
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_1_digit == "0" then --上以外の場合は空白ではなく"0"にする。
imgui.Image(image_7seg_0, 17, 29)
end
for i = 1, 9 do
if ap_VVI_pos_1_digit == VS_7seg_number_pattern_B[i] then
imgui.Image(VS_7seg_image_pattern_B[i], 17, 29)
end
end
end
function on_close(view_selector_wnd)
end
整数のみの7セグメント表示
IAS/MACHとHEADINGの7セグメント
最初にいちばん簡単なスピードの7セグメント表示から。説明では実際の大きさで白色の7セグメントを作成して説明している。
dataref値から数字を読み込むのだが、この画像を表示する方法として桁ごとに数値を読み込む必要がある。
以下の場合は「100」と整数で数値が出ているので簡単である。

ここでは、31〜32行目で数値の位置を桁毎に取得することができる関数を使用している。
これは便利な関数になる。この関数の最後のパラメーター「1, 1」が数字の最初の文字を取得していることになる。つまり上の数字でいくと「100」なので「1」を取得していることになる。
この関数は取得したい数値の桁数分作成する必要がある。
このやり方で「IAS/MACH」と「HEADING」は完成する。dataref値が整数だけのとき。
-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png")
local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png")
local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png")
local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png")
local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png")
local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png")
local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png")
local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png")
local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png")
local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png")
local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png")
local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png")
local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png")
DataRef("course_7segment", "laminar/B738/autopilot/course_pilot")
DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach")
DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial")
DataRef("mcp_Alt_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial")
DataRef("ap_Vvi_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos")
---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(300, 150, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "7segment Test")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
AirSpd_1 = string.sub(IAS_MACH_7segment, 3, 3) --1桁目を取得
AirSpd_2 = string.sub(IAS_MACH_7segment, 2, 2) --2桁目を取得
AirSpd_3 = string.sub(IAS_MACH_7segment, 1, 1) --3桁目を取得
if AirSpd_3 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif AirSpd_3 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif AirSpd_3 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif AirSpd_3 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif AirSpd_3 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif AirSpd_3 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif AirSpd_3 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif AirSpd_3 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif AirSpd_3 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif AirSpd_3 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if AirSpd_2 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif AirSpd_2 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif AirSpd_2 == "2" then
imgui.Image(image_7seg, 17, 29)
elseif AirSpd_2 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif AirSpd_2 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif AirSpd_2 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif AirSpd_2 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif AirSpd_2 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif AirSpd_2 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif AirSpd_2 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if AirSpd_1 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif AirSpd_1 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif AirSpd_1 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif AirSpd_1 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif AirSpd_1 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif AirSpd_1 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif AirSpd_1 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif AirSpd_1 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif AirSpd_1 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif AirSpd_1 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.TextUnformatted("dataref: " .. AirSpd_3 .. AirSpd_2 .. AirSpd_1)
end
function on_close(view_selector_wnd)
end
ALTITUDEの7セグメント
これは整数だけなので上の3桁を5桁にするだけである。但し、桁が増えると右側に増えて行くので表示の位置がずれることに成るので注意が必要。

-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png")
local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png")
local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png")
local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png")
local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png")
local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png")
local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png")
local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png")
local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png")
local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png")
local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png")
local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png")
local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png")
DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot")
DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach")
DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial")
DataRef("mcp_ALT_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial")
DataRef("ap_Vvi_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos")
---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(300, 150, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "7segment Test")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
--ALTITUDE 7セグメント表示
--桁毎に数値を取り出す
mcp_ALT_dial_1 = string.sub(mcp_ALT_dial_7segment, 5, 5) --1桁目を取得
mcp_ALT_dial_2 = string.sub(mcp_ALT_dial_7segment, 4, 4) --2桁目を取得
mcp_ALT_dial_3 = string.sub(mcp_ALT_dial_7segment, 3, 3) --3桁目を取得
mcp_ALT_dial_4 = string.sub(mcp_ALT_dial_7segment, 2, 2) --4桁目を取得
mcp_ALT_dial_5 = string.sub(mcp_ALT_dial_7segment, 1, 1) --5桁目を取得
if mcp_ALT_dial_5 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif mcp_ALT_dial_5 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif mcp_ALT_dial_5 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif mcp_ALT_dial_5 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif mcp_ALT_dial_5 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif mcp_ALT_dial_5 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif mcp_ALT_dial_5 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif mcp_ALT_dial_5 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif mcp_ALT_dial_5 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif mcp_ALT_dial_5 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if mcp_ALT_dial_4 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif mcp_ALT_dial_4 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif mcp_ALT_dial_4 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif mcp_ALT_dial_4 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif mcp_ALT_dial_4 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif mcp_ALT_dial_4 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif mcp_ALT_dial_4 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif mcp_ALT_dial_4 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif mcp_ALT_dial_4 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif mcp_ALT_dial_4 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if mcp_ALT_dial_3 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif mcp_ALT_dial_3 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif mcp_ALT_dial_3 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif mcp_ALT_dial_3 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif mcp_ALT_dial_3 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif mcp_ALT_dial_3 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif mcp_ALT_dial_3 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif mcp_ALT_dial_3 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif mcp_ALT_dial_3 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif mcp_ALT_dial_3 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if mcp_ALT_dial_2 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif mcp_ALT_dial_2 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif mcp_ALT_dial_2 == "2" then
imgui.Image(image_7seg, 17, 29)
elseif mcp_ALT_dial_2 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif mcp_ALT_dial_2 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif mcp_ALT_dial_2 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif mcp_ALT_dial_2 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif mcp_ALT_dial_2 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif mcp_ALT_dial_2 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif mcp_ALT_dial_2 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if mcp_ALT_dial_1 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif mcp_ALT_dial_1 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif mcp_ALT_dial_1 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif mcp_ALT_dial_1 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif mcp_ALT_dial_1 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif mcp_ALT_dial_1 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif mcp_ALT_dial_1 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif mcp_ALT_dial_1 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif mcp_ALT_dial_1 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif mcp_ALT_dial_1 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.TextUnformatted("dataref: ".. mcp_ALT_dial_5 .. mcp_ALT_dial_4 .. mcp_ALT_dial_3 .. mcp_ALT_dial_2 .. mcp_ALT_dial_1)
end
function on_close(view_selector_wnd)
end
頭に0が入る7セグメントの場合
これはチョット工夫が必要になる。最初の数字が0以外の場合は3桁で表示されるが頭に0が来ると、dataref値を見れば分かるように「93」となっているが、実際のX-Planeでは「093」となっている。
頭に「0」を入れる工夫が必要になる。

以下のように34行目に入れている string.format を使って0を追加した3桁表示に変換する。dataref値は整数 93、これで0をつけた3桁で093と表示されるようになる。
“%03d”がポイント。3が3桁表示で2桁になったときは0が追加されることになる。dは整数の意味。
Course_7seg = string.format(“%03d”, COURSE_7segment)

-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png")
local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png")
local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png")
local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png")
local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png")
local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png")
local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png")
local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png")
local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png")
local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png")
local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png")
local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png")
local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png")
DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot")
DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach")
DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial")
DataRef("mcp_Alt_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial")
DataRef("ap_Vvi_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos")
---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(300, 150, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "7segment Test")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
--COURSE 7セグメント表示
Course_7seg = string.format("%03d", COURSE_7segment) --dataref値は整数 23、これで0をつけた3桁で023と表示されるようになる。
Course_1 = string.sub(Course_7seg, 3, 3) --1桁目を取得
Course_2 = string.sub(Course_7seg, 2, 2) --2桁目を取得
Course_3 = string.sub(Course_7seg, 1, 1) --3桁目を取得
if Course_3 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_3 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_3 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif Course_3 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_3 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_3 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_3 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_3 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_3 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_3 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if Course_2 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_2 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_2 == "2" then
imgui.Image(image_7seg, 17, 29)
elseif Course_2 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_2 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_2 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_2 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_2 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_2 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_2 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if Course_1 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_1 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_1 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif Course_1 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_1 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_1 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_1 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_1 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_1 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_1 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.TextUnformatted("dataref: " .. Course_3 .. Course_2 .. Course_1)
end
function on_close(view_selector_wnd)
end
ここでの説明は実際のCOURSEとは違って0を付けない場合のことになる。
“%3d”があるので使って見たがFlyWithLuaでは機能しない。0を付けて表示する”%03d”は機能するが頭に0が入ってしまう。ここでは0を入れないならどうするかである。

3桁になっても位置がずれていない。これは2桁と3桁の横位置を「imgui.SetCursorPosX(150)」と「imgui.SetCursorPosX(175)」で強引に位置を設定しているから実現している。どうしても取得した数値は頭揃えになり、98の場合は前に行ってしまうので表示が2桁と3桁ではずれてしまうのである。

-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png")
local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png")
local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png")
local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png")
local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png")
local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png")
local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png")
local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png")
local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png")
local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png")
local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png")
local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png")
local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png")
DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot")
DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach")
DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial")
DataRef("mcp_Alt_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial")
DataRef("ap_Vvi_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos")
---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(300, 150, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "7segment Test")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
--COURSE 7セグメント表示
Course_7seg = string.format("%3d", COURSE_7segment) --dataref値は整数 23、これで0をつけた3桁で023と表示されるようになる。
Course_3 = string.sub(Course_7seg, 1, 1) --3桁目を取得
Course_2 = string.sub(Course_7seg, 2, 2) --2
Course_1 = string.sub(Course_7seg, 3, 3) --1
imgui.TextUnformatted("A-3 : " .. Course_3) --3桁目
imgui.TextUnformatted("A-2 : " .. Course_2) --2
imgui.TextUnformatted("A-1 : " .. Course_1) --1
--2桁のときの数字の位置と表示
imgui.SetCursorPosX(175)
imgui.SetCursorPosY(80)
if COURSE_7segment <= 99 then
if Course_2 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_2 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_2 == "2" then
imgui.Image(image_7seg, 17, 29)
elseif Course_2 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_2 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_2 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_2 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_2 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_2 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_2 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if Course_1 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_1 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_1 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif Course_1 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_1 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_1 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_1 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_1 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_1 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_1 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
end
--3桁のときの数字の位置と表示
imgui.SetCursorPosX(150)
imgui.SetCursorPosY(80)
if COURSE_7segment >= 100 then
if Course_3 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_3 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_3 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif Course_3 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_3 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_3 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_3 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_3 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_3 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_3 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if Course_2 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_2 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_2 == "2" then
imgui.Image(image_7seg, 17, 29)
elseif Course_2 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_2 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_2 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_2 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_2 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_2 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_2 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if Course_1 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_1 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_1 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif Course_1 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_1 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_1 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_1 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_1 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_1 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_1 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
end
end
function on_close(view_selector_wnd)
end
もう一つの解決方法、何も数字を入れていない空白の画像を用意しておく。これを0の代わりに入れると位置がずれずに表示されることになる。”%3d”で桁数を指示して頭の0になる部分に空白の画像を入れるやり方である。スクリプトの記述が複雑にならないので、こちらがいい案になる。

以下は新しく空白の画像を用意して、44行の「0」の場合、45行で空白の画像を指定している。
-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png")
local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png")
local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png")
local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png")
local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png")
local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png")
local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png")
local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png")
local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png")
local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png")
local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png")
local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png")
local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png")
local image_7seg_space = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_space.png")
DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot")
DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach")
DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial")
DataRef("mcp_Alt_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial")
DataRef("ap_Vvi_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos")
---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(300, 150, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "7segment Test")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
--COURSE 7セグメント表示
Course_7seg = string.format("%03d", COURSE_7segment) --dataref値は整数 23、これで0をつけた3桁で023と表示されるようになる。
Course_3 = string.sub(Course_7seg, 1, 1) --3桁目を取得
Course_2 = string.sub(Course_7seg, 2, 2) --2
Course_1 = string.sub(Course_7seg, 3, 3) --1
imgui.TextUnformatted("A-3 : " .. Course_3)--3桁目
imgui.TextUnformatted("A-2 : " .. Course_2)--2
imgui.TextUnformatted("A-1 : " .. Course_1)--1
if Course_3 == "0" then
imgui.Image(image_7seg_space, 17, 29)
elseif Course_3 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_3 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif Course_3 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_3 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_3 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_3 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_3 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_3 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_3 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if Course_2 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_2 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_2 == "2" then
imgui.Image(image_7seg, 17, 29)
elseif Course_2 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_2 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_2 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_2 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_2 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_2 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_2 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if Course_1 == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif Course_1 == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif Course_1 == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif Course_1 == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif Course_1 == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif Course_1 == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif Course_1 == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif Course_1 == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif Course_1 == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif Course_1 == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.TextUnformatted("dataref: " .. Course_3 .. Course_2 .. Course_1)
end
function on_close(view_selector_wnd)
end
小数点が入る7セグメント表示
やり方は整数表示と基本的には同じで、小数点のpng画像を作成して指定の位置に入れるだけ。

-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_E_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-0.png")
local image_E_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-1.png")
local image_E_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-2.png")
local image_E_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-3.png")
local image_E_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-4.png")
local image_E_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-5.png")
local image_E_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-6.png")
local image_E_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-7.png")
local image_E_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-8.png")
local image_E_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-9.png")
local image_E_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-point.png")
DataRef("com1_freq_hz", "sim/cockpit/radios/com1_stdby_freq_hz")
DataRef("com1_freq_hz_833", "sim/cockpit2/radios/actuators/com1_standby_frequency_hz_833")
digit_7seg_number = { Com1_freq_7, Com1_freq_6, Com1_freq_5, Com1_freq_4, Com1_freq_3, Com1_freq_2, Com1_freq_1 }
---------------------------------------------------------------------------------
--コマンドを使う場合、この設定が必要
local view_selector_wnd = nil
--function show_wnd_2()
view_selector_wnd = float_wnd_create(500, 150, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "X-Plane View Selector")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
Com1_freq_1 = string.sub(com1_freq_hz_833, 7, 7) --string.sub は数値でなく文字列なので入れる時は " " で囲む
Com1_freq_2 = string.sub(com1_freq_hz_833, 6, 6) --2桁目
Com1_freq_3 = string.sub(com1_freq_hz_833, 5, 5) --3桁目
Com1_freq_4 = string.sub(com1_freq_hz_833, 4, 4) --4桁目
Com1_freq_5 = string.sub(com1_freq_hz_833, 3, 3) --5桁目
Com1_freq_6 = string.sub(com1_freq_hz_833, 2, 2) --6桁目
Com1_freq_7 = string.sub(com1_freq_hz_833, 1, 1) --6桁目
--6桁目
if Com1_freq_7 == "0" then
imgui.Image(image_E_0, 67, 120)
elseif Com1_freq_7 == "1" then
imgui.Image(image_E_1, 67, 120)
elseif Com1_freq_7 == "2" then
imgui.Image(image_E_2, 67, 120)
elseif Com1_freq_7 == "3" then
imgui.Image(image_E_3, 67, 120)
elseif Com1_freq_7 == "4" then
imgui.Image(image_E_4, 67, 120)
elseif Com1_freq_7 == "5" then
imgui.Image(image_E_5, 67, 120)
elseif Com1_freq_7 == "6" then
imgui.Image(image_E_6, 67, 120)
elseif Com1_freq_7 == "7" then
imgui.Image(image_E_7, 67, 120)
elseif Com1_freq_7 == "8" then
imgui.Image(image_E_8, 67, 120)
elseif Com1_freq_7 == "9" then
imgui.Image(image_E_9, 67, 120)
end
imgui.SameLine()
--5桁目
if Com1_freq_6 == "0" then
imgui.Image(image_E_0, 67, 120)
elseif Com1_freq_6 == "1" then
imgui.Image(image_E_1, 67, 120)
elseif Com1_freq_6 == "2" then
imgui.Image(image_E_2, 67, 120)
elseif Com1_freq_6 == "3" then
imgui.Image(image_E_3, 67, 120)
elseif Com1_freq_6 == "4" then
imgui.Image(image_E_4, 67, 120)
elseif Com1_freq_6 == "5" then
imgui.Image(image_E_5, 67, 120)
elseif Com1_freq_6 == "6" then
imgui.Image(image_E_6, 67, 120)
elseif Com1_freq_6 == "7" then
imgui.Image(image_E_7, 67, 120)
elseif Com1_freq_6 == "8" then
imgui.Image(image_E_8, 67, 120)
elseif Com1_freq_6 == "9" then
imgui.Image(image_E_9, 67, 120)
end
imgui.SameLine()
--4桁目
if Com1_freq_5 == "0" then
imgui.Image(image_E_0, 67, 120)
elseif Com1_freq_5 == "1" then
imgui.Image(image_E_1, 67, 120)
elseif Com1_freq_5 == "2" then
imgui.Image(image_E_2, 67, 120)
elseif Com1_freq_5 == "3" then
imgui.Image(image_E_3, 67, 120)
elseif Com1_freq_5 == "4" then
imgui.Image(image_E_4, 67, 120)
elseif Com1_freq_5 == "5" then
imgui.Image(image_E_5, 67, 120)
elseif Com1_freq_5 == "6" then
imgui.Image(image_E_6, 67, 120)
elseif Com1_freq_5 == "7" then
imgui.Image(image_E_7, 67, 120)
elseif Com1_freq_5 == "8" then
imgui.Image(image_E_8, 67, 120)
elseif Com1_freq_5 == "9" then
imgui.Image(image_E_9, 67, 120)
end
imgui.SameLine()
imgui.Image(image_E_point, 30, 120)
imgui.SameLine()
if Com1_freq_4 == "0" then
imgui.Image(image_E_0, 67, 120)
elseif Com1_freq_4 == "1" then
imgui.Image(image_E_1, 67, 120)
elseif Com1_freq_4 == "2" then
imgui.Image(image_E_2, 67, 120)
elseif Com1_freq_4 == "3" then
imgui.Image(image_E_3, 67, 120)
elseif Com1_freq_4 == "4" then
imgui.Image(image_E_4, 67, 120)
elseif Com1_freq_4 == "5" then
imgui.Image(image_E_5, 67, 120)
elseif Com1_freq_4 == "6" then
imgui.Image(image_E_6, 67, 120)
elseif Com1_freq_4 == "7" then
imgui.Image(image_E_7, 67, 120)
elseif Com1_freq_4 == "8" then
imgui.Image(image_E_8, 67, 120)
elseif Com1_freq_4 == "9" then
imgui.Image(image_E_9, 67, 120)
end
imgui.SameLine()
if Com1_freq_3 == "0" then
imgui.Image(image_E_0, 67, 120)
elseif Com1_freq_3 == "1" then
imgui.Image(image_E_1, 67, 120)
elseif Com1_freq_3 == "2" then
imgui.Image(image_E_2, 67, 120)
elseif Com1_freq_3 == "3" then
imgui.Image(image_E_3, 67, 120)
elseif Com1_freq_3 == "4" then
imgui.Image(image_E_4, 67, 120)
elseif Com1_freq_3 == "5" then
imgui.Image(image_E_5, 67, 120)
elseif Com1_freq_3 == "6" then
imgui.Image(image_E_6, 67, 120)
elseif Com1_freq_3 == "7" then
imgui.Image(image_E_7, 67, 120)
elseif Com1_freq_3 == "8" then
imgui.Image(image_E_8, 67, 120)
elseif Com1_freq_3 == "9" then
imgui.Image(image_E_9, 67, 120)
end
imgui.SameLine()
if Com1_freq_2 == "0" then
imgui.Image(image_E_0, 67, 120)
elseif Com1_freq_2 == "1" then
imgui.Image(image_E_1, 67, 120)
elseif Com1_freq_2 == "2" then
imgui.Image(image_E_2, 67, 120)
elseif Com1_freq_2 == "3" then
imgui.Image(image_E_3, 67, 120)
elseif Com1_freq_2 == "4" then
imgui.Image(image_E_4, 67, 120)
elseif Com1_freq_2 == "5" then
imgui.Image(image_E_5, 67, 120)
elseif Com1_freq_2 == "6" then
imgui.Image(image_E_6, 67, 120)
elseif Com1_freq_2 == "7" then
imgui.Image(image_E_7, 67, 120)
elseif Com1_freq_2 == "8" then
imgui.Image(image_E_8, 67, 120)
elseif Com1_freq_2 == "9" then
imgui.Image(image_E_9, 67, 120)
end
imgui.SameLine()
if Com1_freq_1 == "0" then
imgui.Image(image_E_0, 67, 120)
elseif Com1_freq_1 == "1" then
imgui.Image(image_E_1, 67, 120)
elseif Com1_freq_1 == "2" then
imgui.Image(image_E_2, 67, 120)
elseif Com1_freq_1 == "3" then
imgui.Image(image_E_3, 67, 120)
elseif Com1_freq_1 == "4" then
imgui.Image(image_E_4, 67, 120)
elseif Com1_freq_1 == "5" then
imgui.Image(image_E_5, 67, 120)
elseif Com1_freq_1 == "6" then
imgui.Image(image_E_6, 67, 120)
elseif Com1_freq_1 == "7" then
imgui.Image(image_E_7, 67, 120)
elseif Com1_freq_1 == "8" then
imgui.Image(image_E_8, 67, 120)
elseif Com1_freq_1 == "9" then
imgui.Image(image_E_9, 67, 120)
end
imgui.TextUnformatted(Com1_freq_6)
end
function on_close(view_selector_wnd)
end
for do文を使った小数点入り7セグメント表示
何故かポイントの左横4桁目の数値の7が表示されない。6から8に飛んでしまう。不思議。
-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_E_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-0.png")
local image_E_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-1.png")
local image_E_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-2.png")
local image_E_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-3.png")
local image_E_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-4.png")
local image_E_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-5.png")
local image_E_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-6.png")
local image_E_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-7.png")
local image_E_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-8.png")
local image_E_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-9.png")
local image_E_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg-point.png")
local image = { image_E_0, image_E_1, image_E_2, image_E_3, image_E_4, image_E_5, image_E_6, image_E_7, image_E_8,
image_E_9 }
DataRef("com1_freq_hz", "sim/cockpit/radios/com1_stdby_freq_hz")
DataRef("com1_freq_hz_833", "sim/cockpit2/radios/actuators/com1_standby_frequency_hz_833")
local values = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }
---------------------------------------------------------------------------------
--コマンドを使う場合、この設定が必要
local view_selector_wnd = nil
--function show_wnd_2()
view_selector_wnd = float_wnd_create(500, 150, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "X-Plane View Selector")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
--以下はこの位置に入れる必要がある。
--Com1_freq_1 = string.sub(com1_freq_hz_833, 7, 7) --string.sub は数値でなく文字列なので入れる時は " " で囲む
Com1_freq_1 = string.sub(com1_freq_hz_833, 6, 6) --1桁目
Com1_freq_2 = string.sub(com1_freq_hz_833, 5, 5) --2桁目
Com1_freq_3 = string.sub(com1_freq_hz_833, 4, 4) --3桁目
Com1_freq_4 = string.sub(com1_freq_hz_833, 3, 3) --4桁目
Com1_freq_5 = string.sub(com1_freq_hz_833, 2, 2) --5桁目
Com1_freq_6 = string.sub(com1_freq_hz_833, 1, 1) --6桁目
--6桁目
for i = 1, 10, 1 do
if Com1_freq_6 == values[i] then
imgui.Image(image[i], 67, 120)
end
end
imgui.SameLine()
--5桁目
for i = 1, 10, 1 do
if Com1_freq_5 == values[i] then
imgui.Image(image[i], 67, 120)
end
end
imgui.SameLine()
--4桁目(7の数字が飛んでしまう現象あり、不明)
for i = 1, 10, 1 do
if Com1_freq_4 == values[i] then
imgui.Image(image[i], 67, 120)
end
end
imgui.SameLine()
--ポイント
imgui.Image(image_E_point, 30, 120) --小数点表示
imgui.SameLine()
--3桁目
for i = 1, 10, 1 do
if Com1_freq_3 == values[i] then
imgui.Image(image[i], 67, 120)
end
end
imgui.SameLine()
--2桁目
for i = 1, 10, 1 do
if Com1_freq_2 == values[i] then
imgui.Image(image[i], 67, 120)
end
end
--1桁目
imgui.SameLine()
for i = 1, 10, 1 do
if Com1_freq_1 == values[i] then
imgui.Image(image[i], 67, 120)
end
end
imgui.TextUnformatted(Com1_freq_4)
end
function on_close(view_selector_wnd)
end
VERT SPEEDの7セグメントは厄介である
V/Sの場合はプラスまで含めると5桁表示になる。

数値は4桁で入るのだが、マイナスのときだけ「-」記号が入るのでプラスとマイナスでは桁位置が変化してしまうことになる。「-」はハイフンが使えるが「+」は多分使えないので入っていないということだと思うが、+がないので前揃えのために桁数の変化で位置が移動してしまう。
以下がマイナスになったときの桁の位置である。A-7の位置に「-」が入っていて、数値の先頭が下にズレているのがわかる。これにより表示位置がプラスとマイナスでは違ってくることになる。非常に面倒である。

そこで “%4d” があるので使って見たがFlyWithLuaでは機能しない。というより、imguiのテキストフォーマットを使ってやる場合は機能するが、ここでは使えなかった。
%04d”は機能するが頭に0が入ってしまうので実際とは違う表示になる。
そこで、マイナス記号まで入れて5桁ということで%05d”を使って、余分な0の代わりに空白に画像を置き換える方法を採用した。

完成したのが以下のとおりである。

-- 画像県警の初期設定 ----
-- E_Camera Move ----
local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png")
local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png")
local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png")
local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png")
local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png")
local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png")
local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png")
local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png")
local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png")
local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png")
local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png")
local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png")
local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png")
local image_7seg_space = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_space.png")
DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot")
DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach")
DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial")
DataRef("mcp_ALT_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial")
DataRef("ap_VVI_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos")
---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(300, 250, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "7segment Test")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------
function view_selector_build_wnd(view_selector_wnd, x, y)
--ALTITUDE 7セグメント表示
VVI_pos_7seg = string.format("%05d", ap_VVI_pos_7segment) --マイナスが5桁になるので "%05d" になる
--桁毎に数値を取り出す
ap_VVI_pos_5_plus = string.sub(VVI_pos_7seg, 1, 1) --5桁目を取得
ap_VVI_pos_4_plus = string.sub(VVI_pos_7seg, 2, 2) --4
ap_VVI_pos_3_plus = string.sub(VVI_pos_7seg, 3, 3) --3
ap_VVI_pos_2_plus = string.sub(VVI_pos_7seg, 4, 4) --2
ap_VVI_pos_1_plus = string.sub(VVI_pos_7seg, 5, 5) --1
ap_VVI_pos_5_minus = string.sub(VVI_pos_7seg, 1, 1) --5桁目を取得
ap_VVI_pos_4_minus = string.sub(VVI_pos_7seg, 2, 2) --4
ap_VVI_pos_3_minus = string.sub(VVI_pos_7seg, 3, 3) --3
ap_VVI_pos_2_minus = string.sub(VVI_pos_7seg, 4, 4) --2
ap_VVI_pos_1_minus = string.sub(VVI_pos_7seg, 5, 5) --1
imgui.TextUnformatted("plus-5 : " .. ap_VVI_pos_5_plus) --5桁目を表示
imgui.TextUnformatted("plus-4 : " .. ap_VVI_pos_4_plus) --4
imgui.TextUnformatted("plus-3 : " .. ap_VVI_pos_3_plus) --3
imgui.TextUnformatted("plus-2 : " .. ap_VVI_pos_2_plus) --2
imgui.TextUnformatted("plus-1 : " .. ap_VVI_pos_1_plus) --1
imgui.TextUnformatted("minus-5 : " .. ap_VVI_pos_5_minus) --5桁目を表示
imgui.TextUnformatted("minus-4 : " .. ap_VVI_pos_4_minus) --4
imgui.TextUnformatted("minus-3 : " .. ap_VVI_pos_3_minus) --3
imgui.TextUnformatted("minus-2 : " .. ap_VVI_pos_2_minus) --2
imgui.TextUnformatted("minus-1 : " .. ap_VVI_pos_1_minus) --1
imgui.TextUnformatted("dataref : " .. ap_VVI_pos_7segment)--datare値を表示
--プラスとマイナスの記号を表示するたものもの
imgui.SetCursorPosX(150)
imgui.SetCursorPosY(120)
if ap_VVI_pos_7segment > 0 then
imgui.Image(image_7seg_plus, 17, 29)
end
if ap_VVI_pos_7segment < 0 then
imgui.Image(image_7seg_minus, 17, 29)
end
imgui.SetCursorPosX(147)
imgui.SetCursorPosY(120)
--プラス側の設定-------------------------
if ap_VVI_pos_7segment > 0 then
if ap_VVI_pos_5_plus == " " then --空白を入れる
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_5_plus == "0" then -- --一応0を入れているがこれは実際は使わないはずである。
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_5_plus == "1" then --この数値なら
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_5_plus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_5_plus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_5_plus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_5_plus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_5_plus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_5_plus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_5_plus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_5_plus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_4_plus == " " then
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_4_plus == "0" then --一応0を入れているがこれは実際は使わないはずである。
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_4_plus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_4_plus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_4_plus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_4_plus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_4_plus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_4_plus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_4_plus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_4_plus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_4_plus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_7segment == 50 then
if ap_VVI_pos_3_plus == "0" then --空白を入れる
imgui.Image(image_7seg_space, 17, 29)
end
elseif ap_VVI_pos_7segment == 1000 or ap_VVI_pos_7segment == 2000 or ap_VVI_pos_7segment == 3000 or ap_VVI_pos_7segment == 4000 or ap_VVI_pos_7segment == 5000 or ap_VVI_pos_7segment == 6000 then
imgui.Image(image_7seg_0, 17, 29)
end
if ap_VVI_pos_3_plus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_3_plus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_3_plus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_3_plus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_3_plus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_3_plus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_3_plus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_3_plus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_3_plus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_2_plus == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif ap_VVI_pos_2_plus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_2_plus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_2_plus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_2_plus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_2_plus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_2_plus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_2_plus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_2_plus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_2_plus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_1_plus == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif ap_VVI_pos_1_plus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_1_plus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_1_plus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_1_plus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_1_plus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_1_plus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_1_plus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_1_plus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_1_plus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
end
--マイナス側の設定-------------------------
if ap_VVI_pos_7segment < 0 then
if ap_VVI_pos_5_minus == "-" then --空白を入れる
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_5_minus == "0" then -- --一応0を入れているがこれは実際は使わないはずである。
imgui.Image(image_7seg_0, 17, 29)
elseif ap_VVI_pos_5_minus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_5_minus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_5_minus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_5_minus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_5_minus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_5_minus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_5_minus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_5_minus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_4_minus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_4_minus == "-" then
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_4_minus == "0" then --一応0を入れているがこれは実際は使わないはずである。
imgui.Image(image_7seg_space, 17, 29)
elseif ap_VVI_pos_4_minus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_4_minus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_4_minus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_4_minus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_4_minus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_4_minus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_4_minus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_4_minus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_4_minus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_7segment == -50 then
if ap_VVI_pos_3_minus == "0" then --空白を入れる
imgui.Image(image_7seg_space, 17, 29)
end
--上の空白設定で余計に空白になるところをカバーするために入れる
elseif ap_VVI_pos_7segment == -1000 or ap_VVI_pos_7segment == -2000 or ap_VVI_pos_7segment == -3000 or ap_VVI_pos_7segment == -4000 or ap_VVI_pos_7segment == -5000 or ap_VVI_pos_7segment == -6000 or ap_VVI_pos_7segment == -7000 then
imgui.Image(image_7seg_0, 17, 29)
end
if ap_VVI_pos_3_minus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_3_minus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_3_minus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_3_minus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_3_minus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_3_minus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_3_minus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_3_minus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_3_minus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_2_minus == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif ap_VVI_pos_2_minus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_2_minus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_2_minus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_2_minus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_2_minus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_2_minus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_2_minus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_2_minus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_2_minus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
imgui.SameLine()
if ap_VVI_pos_1_minus == "0" then
imgui.Image(image_7seg_0, 17, 29)
elseif ap_VVI_pos_1_minus == "1" then
imgui.Image(image_7seg_1, 17, 29)
elseif ap_VVI_pos_1_minus == "2" then
imgui.Image(image_7seg_2, 17, 29)
elseif ap_VVI_pos_1_minus == "3" then
imgui.Image(image_7seg_3, 17, 29)
elseif ap_VVI_pos_1_minus == "4" then
imgui.Image(image_7seg_4, 17, 29)
elseif ap_VVI_pos_1_minus == "5" then
imgui.Image(image_7seg_5, 17, 29)
elseif ap_VVI_pos_1_minus == "6" then
imgui.Image(image_7seg_6, 17, 29)
elseif ap_VVI_pos_1_minus == "7" then
imgui.Image(image_7seg_7, 17, 29)
elseif ap_VVI_pos_1_minus == "8" then
imgui.Image(image_7seg_8, 17, 29)
elseif ap_VVI_pos_1_minus == "9" then
imgui.Image(image_7seg_9, 17, 29)
end
end
end
function on_close(view_selector_wnd)
end
これでうまく動作した。