This code is a bit incomplete but gives you a framework to work and learn from for your own windows. At this point I know there is some optimization I could do but I haven't gotten around to it.
Some of the variables and code may be similar to one of Nick's fancy windows and that's because I learned from reading that code and making my own.
Do with it what you will. Most of this is fairly static in how it does the layout for now.
See next post.
Some of the variables and code may be similar to one of Nick's fancy windows and that's because I learned from reading that code and making my own.
Do with it what you will. Most of this is fairly static in how it does the layout for now.
------
----- Everything below this point is for the graphical control window.
------
-- Config
currentTab = "Info"
GCW = "GleamControlWindow"..GetPluginID() -- GCW = Gleam Control Window.
-- window size in pixels
WINDOW_WIDTH = 420
WINDOW_HEIGHT = 299 -- 200 is 16 lines of 9-point Lucida Console
LEFT_MARGIN = 5
RIGHT_MARGIN = 5
TOP_MARGIN = 5
BOTTOM_MARGIN = 5
WINDOW_POSITION = 6
-- colours
WINDOW_BACKGROUND_COLOUR = ColourNameToRGB ("black")
WINDOW_TEXT_COLOUR = ColourNameToRGB ("black")
WINDOW_BORDER_COLOUR = ColourNameToRGB ("#E8E8E8")
-- Tab info
SystemTabs = {"Info", "Defenses", "Curing", "Parry", "Modes", "Help"} -- Each entry here has its own function.
buttons_max_width = GetInfo(240)*(string.len(table.concat(SystemTabs, ""))+2*table.maxn(SystemTabs))
buttons_left_start = (WINDOW_WIDTH - buttons_max_width) / 2
draw_tab_top = GetInfo(241)*3.5+1+TOP_MARGIN+3
draw_tab_left = LEFT_MARGIN + 5
-- font
FONT_NAME = "Dina"
FONT_SIZE = "8"
FONT_ID_NORMAL = "font" .. GCW
function init()
WindowCreate (GCW,
windowinfo.window_left,
windowinfo.window_top,
WINDOW_WIDTH,
WINDOW_HEIGHT,
windowinfo.window_mode,
windowinfo.window_flags,
WINDOW_BACKGROUND_COLOUR)
-- show border so we can see what we are doing
WindowRectOp (GCW, 1, 0, 0, 0, 0, WINDOW_BORDER_COLOUR)
-- write Gleam Control stuff to top of screen.
drawTitle()
-- Write buttons to screen.
drawButtons()
-- Write tab info to screen.
drawTab()
-- Show the window
WindowShow(GCW, true)
movewindow.save_state (GCW)
end
function drawTitle()
-- This function draws the system title etc above the control window buttons.
title_text = "Gleam Control Window"
title_height = GetInfo(241)*1.5
title_width = GetInfo(240)*(string.len(title_text)+2)
title_top = TOP_MARGIN
title_left = (WINDOW_WIDTH - title_width)/2
title_bottom = title_top + title_height
title_right = title_left + title_width
TITLE_TEXT_COLOUR = ColourNameToRGB ("gold")
WindowText(GCW, FONT_ID_NORMAL, title_text, title_left, title_top, title_right, title_bottom, TITLE_TEXT_COLOUR, false)
end
function drawButtons() -- The code below adds the tabs for each control.
WindowDeleteAllHotspots(GCW)
count = buttons_left_start
for a, tabTitle in pairs(SystemTabs) do
tab_width = GetInfo(240)*(string.len(tabTitle)+2)
tab_height = GetInfo(241)*1.5
tab_left = count
tab_right = tab_left + tab_width - 3
tab_top = GetInfo(241)*2
tab_bottom = tab_top + tab_height + 1
if string.lower(currentTab) == string.lower(tabTitle) then
TAB_TEXT_COLOUR = ColourNameToRGB "red"
else
TAB_TEXT_COLOUR = ColourNameToRGB "black"
end
if string.lower(currentTab) == string.lower(tabTitle) then -- Active tab is pushed in.
WindowRectOp (GCW, miniwin.rect_draw_edge, tab_left, tab_top, tab_right, tab_bottom,
miniwin.rect_edge_etched,
miniwin.rect_edge_at_all+miniwin.rect_option_fill_middle)
else -- inactive tabs are raised.
WindowRectOp (GCW, miniwin.rect_draw_edge, tab_left, tab_top, tab_right, tab_bottom,
miniwin.rect_edge_raised,
miniwin.rect_edge_at_all+miniwin.rect_option_fill_middle)
end
WindowAddHotspot(GCW, tabTitle, tab_left, tab_top, tab_right, tab_bottom, "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", tabTitle, 1, 0)
WindowText(GCW, FONT_ID_NORMAL, tabTitle, count+5, (GetInfo(241)*2.5)-1, count + tab_width - 5, 0, TAB_TEXT_COLOUR, false)
count = count + tab_width + 1
end
movewindow.add_drag_handler (GCW, 0, 0, WINDOW_WIDTH, GetInfo(241), 10)
end
See next post.