Overview
This information is for software developers and mathematically inclined
adventurers who want to quickly create
plugins with interfaces to Dogwaffle.
The GUI server is there to help you make interactive dialogs for
plugins. Any program that supports activeX can use the GUI_Server.
Lua is one of the first, and it's also extremly simple to use.
Therefore, we'll take a look a a few samples in Lua first.
Interested? For
more on Lua scripting with Project Dogwaffle, read: DogLua
Example
of GUI Server usage in Lua scripts:
-- set the caption
(any time) to show "Mirror" as the window's title
GUI_SetCaption("Mirror")
-- add a check box for horrizontal mirroring
-- and another for vertical mirroring
-- start with the horizontal one already checked
h1 =
GUI_AddControl("Check", "Mirror h", 1)
h2
= GUI_AddControl("Check", "Mirror v", 0)
GUI_OpenPanel()
--event
loop. Repeat until ok or cancel pressed (idx variable -1 or -2)
repeat
idx,
retval, retstr = GUI_WaitOnEvent()
check1,string=GUI_GetSettings(h1)
check2,string=GUI_GetSettings(h2)
--optionally
respond to events as they happen.
until
idx < 0 --repeat until
GUI_ClosePanel() |

|
Here is
another updated GUI example with a combo box and comments.
--GUI_Test.lua
--you can set the caption of the panel at any time...
GUI_SetCaption("DogLua Test")
-- begin adding controls.
-- a scroller control for Red, Green & Blue sliders
-- start them at 50 (middle) positions in a range from 0 to 100
h1 = GUI_AddControl("Scroller", "Red", 50, 0, 100)
h2 = GUI_AddControl("Scroller", "Green", 50, 0, 100)
h3 = GUI_AddControl("Scroller", "Blue", 50, 0, 100)
-- add a separator line
h4 = GUI_AddControl("line")
--add a colorbox control (color picker)
h5 = GUI_AddControl("Colorbox", "Black", 00, 0, 000)
h6 = GUI_AddControl("line")
--
h7 = GUI_AddControl("TextLabel", "A label")
--a checkbox control
h8 = GUI_AddControl("Check", "Checked", 1)
--a button control
h9 = GUI_AddControl("Button", "Button...")
--a text control (text entry)
h10 = GUI_AddControl("Text", "Some text")
GUI_SetSettings (h10, 0, "There once was a man named...")
--a number control (numeric entry. text is blocked)
h11 = GUI_AddControl("Number", "Numbers only", 128)
--setup a combo box
h12 = GUI_AddControl("Combobox", "My Combo")
--set the list in the combo box
GUI_SetList (h12,0,"Dairy goat")
GUI_SetList (h12,1,"Puddle duck")
GUI_SetList (h12,2,"Family dog")
GUI_SetList (h12,3,"Crazy chicken")
--set the current string in the combo box
GUI_SetSettings (h12,0, "Dairy goat")
--when all controls are added, open the panel.
GUI_OpenPanel()
--wait for an event to happen.
--If the returned value is <0 then OK or Cancel was pressed.
-- -1 for OK and
-2 for Cancel.
repeat
idx, retval, retstr = GUI_WaitOnEvent()
--display the settings in the caption so we can see them.
--this is for testing only.
--GUI_SetCaption (idx)
--GUI_SetCaption (retval)
--GUI_SetCaption (retstr) -- beware setting a null in the caption...
until idx < 0
--example of getting the settings of a specific control
--read any settings before closing the panel
--value, string = GUI_GetSettings(h1)
GUI_ClosePanel()
|
|
Here is
another Example of Lua Script using the GUI interface options.
the Sunset filter (multiplying
your image top-to-bottom by a gradient of 2 colors)
--Sunset.lua
--it's good form to mention the name of this script.
--these two dashes (--) at the mean that these are comments.
--Here is a function that will be called by the main program.
function DoGradient (gr1,gr2)
local r,g,b,r2,g2,b2,r3,g3,b3,r4,g4,b4
local x,y, y2,y3
--we have to unpack the 'packed' hex colors.
r2,g2,b2 = decimal2rgb(gr1)
r3,g3,b3 = decimal2rgb(gr2)
for y = 0, height - 1 do
--setup the gradient colors.
y2=y/height
y3= 1-y2
r4=(r2*y3)+(r3*y2)
g4=(g2*y3)+(g3*y2)
b4=(b2*y3)+(b3*y2)
--
for x = 0, width - 1 do
r, g, b = get_rgb(x, y)
--combine the gradient with the image with
multiplication.
r=r*r4
g=g*g4
b=b*b4
set_rgb(x, y, r, g, b)
end
progress(y2)
end
progress(0) -- reset the progress bar after usage.
Dog_Refresh() -- show the updated buffer
end
-----------------------------------------------------------------
-- The main part of the program is where we setup the gui
-- and respond to the user selections and input
-----------------------------------------------------------------
-- start by saving one level of undo
Dog_SaveUndo()
--we are going to open a panel with a couple of controls on it.
--first, lets give the panel (window) a name.
GUI_SetCaption("Sunset filter")
--we will now add a couple of controls for selecting color.
--make use of the "hex" function to convert hex colors into decimal
numbers.
--if you're not familiar with colors represented in hex...
--hex (hexadecimal) is a way to represent numbers with 16 digits
--instead of ten (decimal)
--hex numbers are 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f, for 0-15.
--to represent numbers between 0-255, we use two hex numbers.
--00 = 0. FF = 255.
--to represent 24 bit color, we use 3 sets of hex numbers like...
--FF0000 would be bright blue. 0000FF would be bright red.
-- remember: RRGGBB
--lets add the conrols.
-- h1 and h2 will be the 'handles' that identify the color boxes
-- we can then later access these to get or set new values
h1 = GUI_AddControl("Colorbox", "", hex("44AAFF"), 0, 0)
h2 = GUI_AddControl("Colorbox", "", hex("FFFFFF") ,0, 0)
-- now that we've added all our controls, we can open the panel.
GUI_OpenPanel()
---------------------------------
--this is our main event loop.
---------------------------------
repeat
idx, retval, retstr = GUI_WaitOnEvent()
-- get the newest values from the color boxes
g1,dummy=GUI_GetSettings(h1)
g2,dummy=GUI_GetSettings(h2)
--update the screen everytime the user clicks a control.
--if idx was -1 we clicked OK, if -2 we clicked CANCEL
if idx >=0 then
DoGradient(g1,g2)
end
until idx < 0
--example of getting the settings of a specific control
--read any settings before closing the panel
--value, string = GUI_GetSettings(h1)
--if we clicked CANCEL we will want to restore what we
--had before entering the script.
if idx == -2 then
Dog_RestoreUndo()
Dog_GetBuffer()
Dog_Refresh()
end
--always close the panel before exiting or it will stay around.
GUI_ClosePanel()
|
|
Another example, this one using VB:
'VB
example:
'first, you have to create a GUI_Server object
Dim GUI_Server As Object 'could dim here, or globally
Set GUI_Server = CreateObject("GUI_Server.GUIServer")
'then you can use its methods.
'lets put a title on the titlebar of the panel we're going to open.
GUI_Server.SetCaption "Test of GUI_Server"
'Lets add some controls
GUI_Server.AddLogo "GUI_Server_Logo_Test2.bmp"
'if you wish to use a logo, it should be added before any
'conrols for proper layout.
'GUI_Server.setpath ("C:\basic")
''0 return app path
'1 return current path
GUI_Server.SetCaption GUI_Server.getpath(1)
'you can optionally set a reletive spacing.
'the default value is 27 pixels.
'this will be that spacing between the top of the conrol that's about
to be
added, to the top of the next control.
'it's not the spacing in between controls.
GUI_Server.SetSpacing 25
GUI_Server.AddControl "TextLabel", "Color control...", 0, 0, 0, 0
GUI_Server.AddControl "Colorbox", "", &HFFBB22, 0, 0, 0 'currently
there can
be up to 5 of these.
GUI_Server.AddControl "Line", "", 0, 0, 0, 0
GUI_Server.AddControl "TextLabel", "Number and Text controls...", 0, 0,
0, 0
GUI_Server.AddControl "Number", "My number", 8472, 0, 0, 0
Dim index As Long 'we can optionally get the index retuned by the
AddControl
method to access our controls later.
index = GUI_Server.AddControl("Text", "My Text", 0, 0, 0, 0) 'the
actual
text string can be added at any time...
GUI_Server.SetSettings index, 0, "Some text goes here"
'text can be added
to a text control after creation.
GUI_Server.AddControl "Line", "", 0, 0, 0, 0
GUI_Server.AddControl "TextLabel", "Scroller controls...", 0, 0, 0, 0
GUI_Server.AddControl "Scroller", "Red", 255, 1, 255, 0
GUI_Server.AddControl "Scroller", "Green", 64, 1, 255, 0
GUI_Server.AddControl "Scroller", "Blue", 0, 1, 255, 0
GUI_Server.AddControl "Line", "", 0, 0, 0, 0
GUI_Server.AddControl "TextLabel", "Check controls...", 0, 0, 0, 0
GUI_Server.AddControl "Check", "Checkbox", 0, 0, 0, 0
GUI_Server.AddControl "Check", "Checked", 1, 0, 0, 0
GUI_Server.AddControl "Line", "", 0, 0, 0, 0
GUI_Server.AddControl "TextLabel", "Button controls...", 0, 0, 0, 0
GUI_Server.AddControl "Button", "Click me", 0, 0, 0, 0
GUI_Server.AddControl "Button", "Another button", 0, 0, 0, 0
GUI_Server.AddControl "Line", "", 0, 0, 0, 0
GUI_Server.AddControl "TextLabel", "Combo control...", 0, 0, 0, 0
index = GUI_Server.AddControl("ComboBox", "A Combo", 0, 0, 0, 0) 'a
combo box.
GUI_Server.SetList index, 0, "Dairy goat" 'now add list items.
GUI_Server.SetList index, 1, "Puddle duck"
GUI_Server.SetList index, 2, "Family dog"
GUI_Server.SetList index, 3, "Crazy chicken"
GUI_Server.SetSettings index, 0, "Dairy goat" 'set the default string.
'do this after setting the list.
'open the panel.
GUI_Server.OpenPanel
' a loop to handle events as they happen.
Eventloop:
Dim MyIndex As Long, MyValue As Long, MyString As String, MyMessage As
String
MyIndex = GUI_Server.WaitOnEvent(MyValue, MyString)
MyMessage = "Index = " & MyIndex & " - " & "Value = " &
MyValue & " - " &
"String = " & MyString
If MyIndex = 17 Then ChangeStuff 'change stuff if the button was
clicked
(control 15)
GUI_Server.SetCaption MyMessage
'if the value returned is -1, the OK button was pressed. -2 for
Cancel.
If MyIndex >= 0 Then GoTo Eventloop
'lets read values for specific controls and print it in a message box.
'the conrol index starts at 0, not 1.
'
'MyIndex = 19 'just pick any of them for this test.
'GUI_Server.GetSettings MyIndex, MyValue, MyString
''print a message showing that you can get the settings.
'MyMessage = "Index = " & MyIndex & Chr$(10) & "Value = "
& MyValue &
Chr$(10) & "String = " & MyString
'we're done. Close up shop.
GUI_Server.ClosePanel |
 |
Interested? For more on
the general SDK and VB source examples, read: the SDK
|
|