;*=-----------------------------------------------------------------------------=* ; ; >> Action Based GUI << ; ; By Kevin Picone ; ; Built Using PlayBASIC V1.64n2 ; ; Copyright 2012 by Kevin Picone, All Rights Reserved. ; ;*=-----------------------------------------------------------------------------=* ; www.UnderwareDesign.com - www.PlayBASIC.com ;*=-----------------------------------------------------------------------------=* ; ; About: ; ====== ; ; This example using the Action GUI library demos a how the GUI can use ; CallFunction to call user defined code on demand. Action GUI is really ; simple, so simple it only creates basic window/panels object. Each panel ; is given Class Name, the GUI uses the class name to hook back into user code ; for that class. ; ; Each class has four basic action functions associated with it, those being ; CREATE, DELETE, REDRAW and UPDATE. So if the user creates a window with a ; class name of "TEST", then the GUI would expect to find Functions ; TEST_CREATE, TEST_DELETE TEST_REDRAW and TEST_UPDATE. The Create and ; Delete functions are called when the use the NewWindow or DeleteWindow ; functions. These let us customize the newly created window, where the Update ; function is called when the is mouse Over / input stuff and the redraw is ; when we want to repaint the window. ; Bellow, we've got a simple randomized scene with a bunch of windows, where ; each window has it's own backdrop colours, with a click-to-position circle. ; If you look closely at the code, the "GadgetWindow" class inherits from ; the GUI_WINDOW type. This means we're adding fields to the GUI_WINDOW ; structure, basically customizing it. The GUI can't see these extra fields, ; since they don't exist as far as it's concerned. But we can access them ; inside the Action functions as need be. Here i'm just getting the pointer ; and away we go. ; ; ; Controls: ; ======== ; ; Mouse = Clicks render /position ; ESC = EXIT ; ;*=-----------------------------------------------------------------------------=* // --------------------------------------- // Create a Gadget Window // --------------------------------------- index = NewWindow("GadgetWindow",370,200) PositionWindow(Index,200,50) // --------------------------------------- // Spawn a bunch of windows of "GadgetWindow" type // --------------------------------------- For lp=0 To 10 ; randomly calc a size and position for this new window panel Width =RndRange(100,300) Height=RndRange(100,200) Xpos =Rnd(800-Width) Ypos =Rnd(600-Height) ThisWindow = NewWindow("GadgetWindow",Width,Height) PositionWindow(ThisWindow,Xpos,Ypos) Next ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* ; *=---------------------- MAIN LOOP ---------------------------=* ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* SetFPS 60 Do Cls $203060 RenderWindows() // query what panel we're over (if any. zer0 = screen) //Index=FindWindowUnderPoint(MouseX(),MouseY()) //print Index Sync Loop End ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* ; *=--------------- GADGET WINDOW CLASS --------------------=* ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* // Each window has it's own variables Type GadgetWindow As GUI_Window // Backdrop BackDropColour(4) // coords of some thing that is to be positioned by left clicks // on the window CircleX CircleY CircleSize CircleColour EndType ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* ; *=---------------------- CREATE ---------------------------=* ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* ; ; Here we're pulling a bit of swifty and inserting our own ; replacement structure interited from GUI_Windows Structure. ; ; The Create function is called twice. Before the GUI creates it own ; structure and then after it's set up the default fields. ; ; *=----------------------------------------------------------------------=* Psub GadgetWindow_Create(Index) // Initial Allocation If GUI_WIndows(Index)=0 GUI_WIndows(Index)=New GadgetWindow Else // Secondary allocation (setup) Dim Me As GadgetWindow Pointer Me=GetMePointer(Index) For lp =0 To 3 me.BackdropColour(lp)=RndRGB() Next me.CircleSize =RndRange(10,20) me.CircleColour=RndRGB() RenderToImage Me.Image ShadeBox 0,0,Me.Width,Me.Height,me.BackdropColour(0),me.BackdropColour(1),me.BackdropColour(2),me.BackdropColour(3) Text 0,0,Me.Name$+" "+Str$(Me.Index) EndIf EndPsub ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* ; *=---------------------- DELETE ---------------------------=* ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* Psub GadgetWindow_Delete(Index) // Delete any media or extra stuff you've created for use in this window Dim Me As GadgetWindow Pointer Me=GetMePointer(Index) EndPsub ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* ; *=---------------------- RENDER ---------------------------=* ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* Psub GadgetWindow_Render(Index) Dim Me As GadgetWindow Pointer Me=GetMePointer(Index) RenderToImage Me.Image ShadeBox 0,0,Me.Width,Me.Height,me.BackdropColour(0),me.BackdropColour(1),me.BackdropColour(2),me.BackdropColour(3) Text 0,0,Me.Name$+" "+Str$(Me.Index) If Me.mb CircleC Me.CircleX,Me.CircleY,me.CircleSize,true,me.CircleColour EndIf EndPsub ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* ; *=---------------------- UPDATE ---------------------------=* ; *=----------------------------------------------------------------------=* ; *=----------------------------------------------------------------------=* Psub GadgetWindow_Update(Index) Dim Me As GadgetWindow Pointer Me=GetMePointer(Index) If Me.mb #Print "on click" // set the Me.CircleX = Me.MX Me.CircleY = Me.MY Me.repaint =true EndIf EndPsub |