Code: Select all
/****************************************************************
** **
** Name: Demo **
** Author: Andreas Falkenhahn **
** Version: 1.0 **
** Date: 24.04.16 **
** Interpreter: Hollywood 6.1 **
** Licence: Sample program **
** Function: Demonstrates most of RapaGUI's widgets **
** **
** History: **
** **
** 1.0: (24.04.16) **
** **
** - initial release **
** **
****************************************************************/
/*
** Make sure we have at least Hollywood 6.1!
*/
@VERSION 6,1
/*
** This script requires the RapaGUI plugin
*/
@REQUIRE "RapaGUI", {Link = True}
/*
** Information about this app
*/
@APPTITLE "Demo"
@APPVERSION "$VER: Demo 1.0 (24.04.16)"
@APPCOPYRIGHT "(C) Copyright 2015-2016 by Andreas Falkenhahn"
@APPAUTHOR "Andreas Falkenhahn"
@APPDESCRIPTION "Demonstrates RapaGUI's widgets"
/*
** External brushes that we use in our GUI
*/
@BRUSH 1, "data/ok.png", {LoadAlpha = True}
@BRUSH 2, "data/cancel.png", {LoadAlpha = True}
@BRUSH 3, "data/rapagui.png", {LoadAlpha = True}
@BRUSH 4, "data/button.png", {LoadAlpha = True}
@BRUSH 5, "data/checkbox.png", {LoadAlpha = True}
@BRUSH 6, "data/choice.png", {LoadAlpha = True}
@BRUSH 7, "data/editfield.png", {LoadAlpha = True}
@BRUSH 8, "data/editor.png", {LoadAlpha = True}
@BRUSH 9, "data/listview.png", {LoadAlpha = True}
@BRUSH 10, "data/progress.png", {LoadAlpha = True}
@BRUSH 11, "data/radiobuttons.png", {LoadAlpha = True}
@BRUSH 12, "data/sliderbutton.png", {LoadAlpha = True}
@BRUSH 13, "data/image.png", {LoadAlpha = True}
@BRUSH 14, "data/register.png", {LoadAlpha = True}
@BRUSH 15, "data/popfile.png", {LoadAlpha = True}
@BRUSH 16, "data/busybar.png", {LoadAlpha = True}
@BRUSH 17, "data/sketchboard.png", {LoadAlpha = True}
@BRUSH 18, "data/treeview.png", {LoadAlpha = True}
@BRUSH 19, "data/floattext.png", {LoadAlpha = True}
@BRUSH 20, "data/listbox.png", {LoadAlpha = True}
@BRUSH 21, "data/chooser.png", {LoadAlpha = True}
@FILE 1, "Demo.xml"
/*
** This display as the output device for Hollywood class
*/
@DISPLAY {Width = 480, Height = 240}
/*
** Add a message to our log listview
*/
Function p_Log(t$)
moai.DoMethod("log", "insert", "bottom", GetTime(True) .. ": " .. t$)
moai.DoMethod("log", "jump", "bottom")
EndFunction
/*
** Enable/disable list buttons
*/
Function p_EnableListButtons(pre$, d)
d = Not d
moai.Set(pre$ .. "delcur", "disabled", d)
moai.Set(pre$ .. "delitem", "disabled", d)
moai.Set(pre$ .. "visitem", "disabled", d)
moai.Set(pre$ .. "chgitem", "disabled", d)
EndFunction
/*
** Set progress bar level
*/
Function p_SetProgress(x)
moai.Set("prgbar", "level", x)
EndFunction
/*
** Interval function which updates the progress bar
*/
Function p_ProgressbarTimer()
If prgbarc < moai.Get("prgbar", "max")
prgbarc = prgbarc + 1
p_SetProgress(prgbarc)
Else
ClearInterval(1)
moai.Set("pbsimprg", "text", "Simulate progress")
p_Log("Progress bar finished")
EndIf
EndFunction
/*
** Interval function which animates the busy bar
*/
Function p_BusybarTimer()
moai.DoMethod("busybar", "move")
EndFunction
/*
** Handles all incoming events
*/
Function p_EventFunc(msg)
Switch msg.action
Case "RapaGUI"
Switch msg.attribute
Case "Pressed":
Switch msg.id
Case "cycledemo":
moai.Set("cycle", "active", moai.Get("cycleactive", "text"), "nonotify", True)
Case "cmselect":
moai.Set("checkmark", "selected", True, "nonotify", True)
Case "cmdeselect":
moai.Set("checkmark", "selected", False, "nonotify", True)
Case "lbaddfew":
Local t = {"First", "another one", "and the last (very very very very very very very very very very long) one"}
For Local k = 0 To ListItems(t) - 1 Do moai.DoMethod("listbox", "insert", "bottom", t[k])
Case "lbaddmany":
For Local k = 0 To 999 Do moai.DoMethod("listbox", "insert", "bottom", "item #" .. k)
Case "lbadditem":
moai.DoMethod("listbox", "insert", "bottom", moai.Get("lbadditemtxt", "text"))
Case "lbchgitem":
moai.Set("listbox", "active", moai.Get("lbchgitemnum", "text"))
Case "lbvisitem":
moai.DoMethod("listbox", "jump", moai.Get("lbvisitemnum", "text"))
Case "lbdelitem":
moai.DoMethod("listbox", "remove", moai.Get("lbdelitemnum", "text"))
Case "lbdelcur":
moai.DoMethod("listbox", "remove", "active")
Case "lbclear":
moai.DoMethod("listbox", "clear")
Case "lvaddfew":
Local c = moai.Get("listview", "entries")
For Local k = 0 To 2 Do moai.DoMethod("listview", "insert", "bottom", "Row " .. c + k .. " item " .. "1", "Row " .. c + k .. " item " .. "2", "Row " .. c + k .. " item " .. "3")
Case "lvaddmany":
Local c = moai.Get("listview", "entries")
For Local k = 0 To 999 Do moai.DoMethod("listview", "insert", "bottom", "Row " .. c + k .. " item " .. "1", "Row " .. c + k .. " item " .. "2", "Row " .. c + k .. " item " .. "3")
Case "lvadditem":
Local t$ = moai.Get("lvadditemtxt", "text")
moai.DoMethod("listview", "insert", "bottom", t$, t$, t$)
Case "lvchgitem":
moai.Set("listview", "active", moai.Get("lvchgitemnum", "text"))
Case "lvvisitem":
moai.DoMethod("listview", "jump", moai.Get("lvvisitemnum", "text"))
Case "lvdelitem":
moai.DoMethod("listview", "remove", moai.Get("lvdelitemnum", "text"))
Case "lvdelcur":
moai.DoMethod("listview", "remove", "active")
Case "lvclear":
moai.DoMethod("listview", "clear")
Case "pbsetval":
prgbarc = Val(moai.Get("pbsetvalnum", "text"))
moai.Set("prgbar", "level", prgbarc)
Case "pbsetrange":
moai.Set("prgbar", "max", moai.Get("pbsetrangenum", "text"))
Case "pbsimprg":
If Not HaveObject(#INTERVAL, 1)
p_Log("Starting progress bar...")
prgbarc = 0
SetInterval(1, p_ProgressbarTimer, 100)
moai.Set("pbsimprg", "text", "Stop timer")
Else
ClearInterval(1)
moai.Set("pbsimprg", "text", "Simulate progress")
EndIf
Case "pbclear":
moai.Set("prgbar", "level", 0)
prgbarc = 0
Case "slsetval":
moai.Set("slider", "level", moai.Get("slsetvalnum", "text"))
Case "slsetrange":
moai.Set("slider", "max", moai.Get("slsetrangenum", "text"))
Case "rdsetval":
moai.Set("radio", "active", moai.Get("rdsetvalnum", "text"), "nonotify", True)
Case "bbsimprg":
If Not HaveObject(#INTERVAL, 2)
p_Log("Starting busy bar...")
SetInterval(2, p_BusybarTimer, 80)
moai.Set("bbsimprg", "text", "Stop timer")
Else
ClearInterval(2)
moai.DoMethod("busybar", "reset")
moai.Set("bbsimprg", "text", "Simulate activity")
EndIf
Case "hwclear":
Cls
Case "cosetval":
moai.Set("combobox", "value", moai.Get("cosetvalstr", "text"), "nonotify", True)
Default:
p_Log("Button click: " .. msg.id)
EndSwitch
Case "Active":
Switch msg.id
Case "cycle":
moai.Set("cycleactive", "text", msg.triggervalue)
p_Log("Choice select: " .. msg.triggervalue)
Case "listbox":
moai.Set("lbdelitemnum", "text", IIf(msg.triggervalue = -1, 0, msg.triggervalue))
p_EnableListButtons("lb", msg.triggervalue <> -1)
p_Log("Listbox active: " .. msg.triggervalue)
Case "listview":
moai.Set("lvdelitemnum", "text", IIf(msg.triggervalue = -1, 0, msg.triggervalue))
p_EnableListButtons("lv", msg.triggervalue <> -1)
p_Log("Listview active: " .. msg.triggervalue)
Case "radio":
p_Log("Radio select: " .. msg.triggervalue)
Case "pageview":
p_Log("Changed page: " .. msg.triggervalue)
EndSwitch
Case "Selected":
Switch msg.id
Case "checkmark":
p_Log("Checkbox toggle: " .. msg.triggervalue)
Case "togglebutton":
p_Log("Button toggle: " .. msg.triggervalue)
Case "mn_quit":
End
Case "mn_about":
moai.Request("", "Widgets demo\n(C) 2015-2016 by Andreas Falkenhahn\n\nVisit the official Hollywood portal at:\nhttp://www.hollywood-mal.com", "OK")
Case "mn_aboutrapagui":
moai.DoMethod("app", "aboutrapagui")
EndSwitch
Case "Text":
p_Log("Textentry: " .. msg.id .. " " .. msg.triggervalue)
Case "Level":
Switch msg.id
Case "prgbar":
moai.Set("pblevel", "text", msg.triggervalue)
Case "slider":
moai.Set("sllevel", "text", msg.triggervalue)
EndSwitch
Case "File":
p_Log("Popfile: " .. msg.triggervalue)
Case "Path":
p_Log("Poppath: " .. msg.triggervalue)
Case "Font":
p_Log("Popfont: " .. msg.triggervalue)
Case "RGB":
p_Log("Popcolor: " .. HexStr(msg.triggervalue))
Case "Value":
p_Log("Combobox: " .. msg.triggervalue)
EndSwitch
Case "OnMouseDown":
Circle(MouseX() - 5, MouseY() - 5, 5, #WHITE)
Case "OnMouseMove":
If IsLeftMouse() = True Then Circle(MouseX() - 5, MouseY() - 5, 5, #WHITE)
EndSwitch
EndFunction
SetFillStyle(#FILLCOLOR)
; dynamically create GUI from an external *.xml file definition
moai.CreateApp(ReadString(1))
; listen to these events!
InstallEventHandler({RapaGUI = p_EventFunc, OnMouseDown = p_EventFunc, OnMouseMove = p_EventFunc})
; main loop!
Repeat
WaitEvent
Forever