Max Gui Example |
|
blitzmax.import(brl.event); blitzmax.import(brl.eventqueue); blitzmax.import(brl.maxgui); blitzmax.import(brl.pixmap); -------------------------------------------------------------------------------- -- loadGuiFont Platform-independent "loadGuiFont" function -- -------------------------------------------------------------------------------- function loadGuiFont(FontName, FontSize, isBold, isItalic, isUnderlined) if (blitzmax.Platform ~= "Win32") then FontSize = math.floor(FontSize * 1.32); end; return brl.maxgui.loadGuiFont(FontName, FontSize, isBold, isItalic, isUnderlined); end; --****************************************************************************** --* * --* Main Program * --* * --****************************************************************************** --**** provide a few application-specific definitions **** local Title = "MaxGUI_00"; local Subtitle = "very first experiments with MaxGUI and Lua"; --**** load some application-specific images **** local Icon = loadPixmap("Lua-Logo.png"); -- Icon = maskPixmap(Icon, 212,208,200); -- does not work if (Icon == nil) then error("unable to load 'Lua-Logo.png'"); end; local sunkenLine = loadPixmap("sunkenLine.png"); if (sunkenLine == nil) then error("unable to load 'sunkenLine.png'"); end; --**** load any application-specific fonts **** local TitleFont = loadGuiFont("Arial", 12, true, true, false); local SubtitleFont = loadGuiFont("Arial", 9, true, false,false); local TextFont = loadGuiFont("Arial", 8, false,false,false); local BoldFont = loadGuiFont("Arial", 8, true, false,false); if (TitleFont == nil) or (SubtitleFont == nil) or (TextFont == nil) or (BoldFont == nil) then error("unable to load all requested fonts"); end; --**** setup the application window **** local Window = createWindow(Title.." - "..Subtitle, 20,20, 320,240, nil, WINDOW_TITLEBAR + WINDOW_RESIZABLE + WINDOW_CLIENTCOORDS); -- + WINDOW_STATUS); setMinWindowSize(Window, 320,240); local IconView = createPanel(2,4, 32,32, Window); setPanelPixmap (IconView, Icon, PANELPIXMAP_CENTER); setGadgetLayout(IconView, EDGE_ALIGNED,0,EDGE_ALIGNED,0); local TitleLabel = createLabel(Title, 36,2, 282,18, Window, LABEL_RIGHT); setGadgetFont (TitleLabel,TitleFont); setGadgetLayout(TitleLabel, 0,EDGE_ALIGNED,EDGE_ALIGNED,0); local SubtitleLabel = createLabel(Subtitle, 36,22, 282,16, Window, LABEL_RIGHT); setGadgetFont (SubtitleLabel,SubtitleFont); setGadgetLayout(SubtitleLabel, 0,EDGE_ALIGNED,EDGE_ALIGNED,0); local UpperSeparator = createPanel(2,40, 316,2, Window); setPanelPixmap (UpperSeparator, sunkenLine, PANELPIXMAP_TILE); setGadgetLayout(UpperSeparator, EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,0); local ClientArea = createTextArea(2,44, 316,174, Window, TEXTAREA_READONLY); setGadgetLayout(ClientArea, EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED); setGadgetColor (ClientArea, 128,128,128, true) local LowerSeparator = createPanel(2,220, 316,2, Window); setPanelPixmap (LowerSeparator, sunkenLine, PANELPIXMAP_TILE); setGadgetLayout(LowerSeparator, EDGE_ALIGNED,EDGE_ALIGNED,0,EDGE_ALIGNED); local Statusbar = createLabel("(no special action required)", 2,224, 316,18, Window); setGadgetFont (Statusbar,TextFont); setGadgetLayout(Statusbar, EDGE_ALIGNED,EDGE_ALIGNED,0,EDGE_ALIGNED); -- setStatusText(Window, "(no special action required)"); showGadget(Window); --**** handle any incoming events... **** while true do waitEvent(); if (EventId() == EVENT_WINDOWCLOSE) then break; end; end;
is produced by the script shown below (which currently crashes under Linux):
blitzmax.import(brl.event); blitzmax.import(brl.eventqueue); blitzmax.import(brl.maxgui); blitzmax.import(brl.pixmap); -------------------------------------------------------------------------------- -- loadGuiFont Platform-independent "loadGuiFont" function -- -------------------------------------------------------------------------------- function loadGuiFont(FontName, FontSize, isBold, isItalic, isUnderlined) if (blitzmax.Platform ~= "Win32") then FontSize = math.floor(FontSize * 1.32); end; return brl.maxgui.loadGuiFont(FontName, FontSize, isBold, isItalic, isUnderlined); end; --****************************************************************************** --* * --* Main Program * --* * --****************************************************************************** --**** provide a few application-specific definitions **** local Title = "MaxGUI_01"; local Subtitle = "displays several System and Environment Parameters"; --**** load some application-specific images **** local Icon = loadPixmap("Lua-Logo.png"); -- Icon = maskPixmap(Icon, 212,208,200); -- does not work if (Icon == nil) then error("unable to load 'Lua-Logo.png'"); end; local sunkenLine = loadPixmap("sunkenLine.png"); if (sunkenLine == nil) then error("unable to load 'sunkenLine.png'"); end; --**** load any application-specific fonts **** local TitleFont = loadGuiFont("Arial", 12, true, true, false); local SubtitleFont = loadGuiFont("Arial", 9, true, false,false); local TextFont = loadGuiFont("Arial", 8, false,false,false); local BoldFont = loadGuiFont("Arial", 8, true, false,false); if (TitleFont == nil) or (SubtitleFont == nil) or (TextFont == nil) or (BoldFont == nil) then error("unable to load all requested fonts"); end; --**** setup the application window **** local Window = createWindow(Title.." - "..Subtitle, 20,20, 400,300, nil, WINDOW_TITLEBAR + WINDOW_RESIZABLE + WINDOW_CLIENTCOORDS); -- + WINDOW_STATUS); setMinWindowSize(Window, 400,300); local IconView = createPanel(2,4, 32,32, Window); setPanelPixmap (IconView, Icon, PANELPIXMAP_CENTER); setGadgetLayout(IconView, EDGE_ALIGNED,0,EDGE_ALIGNED,0); local TitleLabel = createLabel(Title, 36,2, 362,18, Window, LABEL_RIGHT); setGadgetFont (TitleLabel,TitleFont); setGadgetLayout(TitleLabel, 0,EDGE_ALIGNED,EDGE_ALIGNED,0); local SubtitleLabel = createLabel(Subtitle, 36,22, 362,16, Window, LABEL_RIGHT); setGadgetFont (SubtitleLabel,SubtitleFont); setGadgetLayout(SubtitleLabel, 0,EDGE_ALIGNED,EDGE_ALIGNED,0); local UpperSeparator = createPanel(2,40, 396,2, Window); setPanelPixmap (UpperSeparator, sunkenLine, PANELPIXMAP_TILE); setGadgetLayout(UpperSeparator, EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,0); local ClientArea = createTextArea(2,44, 396,234, Window, TEXTAREA_READONLY); setGadgetLayout(ClientArea, EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED); setTextAreaTabs(ClientArea, 10); local LowerSeparator = createPanel(2,280, 396,2, Window); setPanelPixmap (LowerSeparator, sunkenLine, PANELPIXMAP_TILE); setGadgetLayout(LowerSeparator, EDGE_ALIGNED,EDGE_ALIGNED,0,EDGE_ALIGNED); local Statusbar = createLabel("(no special action required)", 2,284, 396,18, Window); setGadgetFont (Statusbar,TextFont); setGadgetLayout(Statusbar, EDGE_ALIGNED,EDGE_ALIGNED,0,EDGE_ALIGNED); -- setStatusText(Window, "(no special action required)"); showGadget(Window); --**** fill "ClientArea" with some information **** addTextAreaText(ClientArea,"Lua:\n"); formatTextAreaText(ClientArea, 0,0,0, TEXTFORMAT_BOLD, 0,1, TEXTAREA_LINES); addTextAreaText(ClientArea," Version:\t".._VERSION.."\n"); addTextAreaText(ClientArea," Arguments:\t"); if (#ArgList == 0) then addTextAreaText(ClientArea,"(none)\n"); else addTextAreaText(ClientArea,"\n"); for i,Value in ipairs(ArgList) do addTextAreaText(ClientArea," "..i..":\t\""..Value.."\"\n"); end; end; addTextAreaText(ClientArea,"\n"); addTextAreaText(ClientArea,"BlitzMAX:\n"); formatTextAreaText(ClientArea, 0,0,0, TEXTFORMAT_BOLD, TextAreaLen(ClientArea,TEXTAREA_LINES)-2,1, TEXTAREA_LINES); addTextAreaText(ClientArea," AppDir:\t\""..blitzmax.AppDir.."\"\n"); addTextAreaText(ClientArea," AppFile:\t\""..blitzmax.AppFile.."\"\n"); addTextAreaText(ClientArea," LaunchDir:\t\""..blitzmax.LaunchDir.."\"\n"); addTextAreaText(ClientArea,"\n"); addTextAreaText(ClientArea,"System:\n"); formatTextAreaText(ClientArea, 0,0,0, TEXTFORMAT_BOLD, TextAreaLen(ClientArea,TEXTAREA_LINES)-2,1, TEXTAREA_LINES); addTextAreaText(ClientArea," Platform:\t\""..blitzmax.Platform.."\"\n"); addTextAreaText(ClientArea," Date:\t\""..brl.system.currentDate().."\"\n"); addTextAreaText(ClientArea," Time:\t\""..brl.system.currentTime().."\"\n"); addTextAreaText(ClientArea,"\n"); addTextAreaText(ClientArea,"Display:\n"); formatTextAreaText(ClientArea, 0,0,0, TEXTFORMAT_BOLD, TextAreaLen(ClientArea,TEXTAREA_LINES)-2,1, TEXTAREA_LINES); local Display = Desktop(); addTextAreaText(ClientArea," Geometry:\t"..GadgetWidth(Display).."x".. GadgetHeight(Display).."+"..GadgetX(Display).."+"..GadgetY(Display).."\n"); --**** handle any incoming events... **** while true do waitEvent(); if (EventId() == EVENT_WINDOWCLOSE) then break; end; end; --**** ...and - finally - close the application window **** freeGadget(Window);