News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Action GUI

Started by kevin, August 23, 2012, 10:20:10 AM

Previous topic - Next topic

kevin

  Action GUI

    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.   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.    


  So here's the main code with

PlayBASIC Code: [Select]
   // ---------------------------------------
// 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)
Login required to view complete source code



 Related Articles

   * Drag Rectangles/ GUI Selection
   * Abstraction Layer




 Download Attached