Code: Select all
; ZOrder Demo AKJ 27-Jul-08
; Program to illustrate image gadget Z-ordering
#Program$ = "ZOrder Demo"
#Version$ = "1.0"
EnableExplicit
; Constants (GUI objects)
Enumeration
#winMain
; Four image gadgets, but I choose to call them canvas gadgets
#canvas
; Four image objects used to fill the canvasses
#image = #canvas+4
EndEnumeration
; Globals
Global cnvw, cnvh
Declare ColouredCanvas(canvas, image, colour, x, y)
; Gui Metrics
Define gap, winw, winh
gap = 30 ; Inter-object spacing
cnvw = 100: cnvh = 80 ; Canvas (image) gadgets
winw = cnvw*2+gap*3: winh = cnvh*2+gap*3 ; Window
; Create GUI
Define title$, flags, hwin, x, y
title$ = " "+#Program$+" v"+#Version$
flags = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered
hwin = OpenWindow(#winMain, 0, 0, winw, winh, title$, flags)
CreateGadgetList(hwin)
; Create 4 image gadgets, with 4 different images
x = (winw-cnvw)/2: y = gap
ColouredCanvas(#canvas+0, #image+0, #Red, x, y)
x = gap: y + (cnvh+gap)/2
ColouredCanvas(#canvas+1, #image+1, #Yellow, x, y)
x + cnvw+gap
ColouredCanvas(#canvas+2, #image+2, #Green, x, y)
x = (winw-cnvw)/2: y + (cnvh+gap)/2
ColouredCanvas(#canvas+3, #image+3, #Blue, x, y)
; Event loop
Define done=#False, canvas, cnv
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #canvas+0 To #canvas+3 ; If a canvas was clicked
canvas = EventGadget()
Debug "Canvas "+Str(canvas-#canvas)+" clicked"
BringWindowToTop_(GadgetID(canvas))
RedrawWindow_(hwin, 0, 0, #RDW_INVALIDATE)
EndSelect
Case #PB_Event_CloseWindow
done=#True
EndSelect
Until done
End
Procedure ColouredCanvas(canvas, image, colour, x, y)
; Create a coloured canvas, with the colour provided by an image object
Protected himg
himg = CreateImage(image, cnvw, cnvh)
StartDrawing(ImageOutput(image))
Box(0, 0, cnvw, cnvh, colour)
StopDrawing()
ImageGadget(canvas, x, y, cnvw, cnvh, himg)
EndProcedure