Page 1 of 1

Draw Buttons

Posted: Sun Apr 29, 2012 3:26 pm
by braveheart
I want to create a simple draw buttons. How to make the #button1 accessible on top another canvas gadget?

Code: Select all

Enumeration
  #main_window 
  #button1
  #fontdefault
  #wrapper
EndEnumeration

LoadFont(#fontdefault,"Trebuchet MS",12,#PB_Font_Bold | #PB_Font_HighQuality)

Procedure mybutton(obj,b) 
  y = 3
  If b
    x = 16
  Else
    x = 15
  EndIf
  StartDrawing(CanvasOutput(obj))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,100,30,$33ccff)
  DrawingFont(FontID(#fontdefault))
  DrawText(x,y,"Button",$000000)
  StopDrawing()  
EndProcedure

If OpenWindow(#main_window,0,0,400,200,"TEST",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
 ; background
  CanvasGadget(#wrapper,0,0,400,200)
  StartDrawing(CanvasOutput(#wrapper))
  Box(0,0,400,200,$1C614D)
  StopDrawing()
  
  CanvasGadget(#button1,10,10,85,30)
  mybutton(#button1,0)  

EndIf

Repeat
  Delay(1)
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      Select EventType()
        Case #PB_EventType_LeftButtonDown
          Select EventGadget()
            Case #button1
              Debug "Clicked"
              mybutton(#button1,1)
          EndSelect
        Case #PB_EventType_LeftButtonUp
          Select EventGadget()
            Case #button1
              mybutton(#button1,0)
          EndSelect          
      EndSelect      
  EndSelect
Until Event = #PB_Event_CloseWindow

Re: Draw Buttons

Posted: Sun Apr 29, 2012 3:37 pm
by Demivec
Canvas gadgets can't contain other gadgets. Anytime two gadgets overlap there aren't any predictable (or simple) ways of telling which one is in front.


I think you would need to create an additional structure within a single canvas gadget that contains the button as well. The structure would let you define the region that acts as a button, it's drawing methods (especially if it changes), and event handlers (procedures) for it.


I'm guessing that probably doesn't fit with your ideas for a simple button. Perhaps someone else has a simpler method.

Re: Draw Buttons

Posted: Sun Apr 29, 2012 3:44 pm
by braveheart
Thanks Demivec, could you show me an example?

Re: Draw Buttons

Posted: Sun Apr 29, 2012 4:30 pm
by Demivec
braveheart wrote:Thanks Demivec, could you show me an example?
I would be willing to do a proof-of-concept to test the ideas I told you. I have part of it already completed but I may not be able to post it for a few hours.

Re: Draw Buttons

Posted: Sun Apr 29, 2012 4:48 pm
by braveheart
:o Thank you Demivec, no need to rush. If you please make it very simple.

Re: Draw Buttons

Posted: Sun Apr 29, 2012 6:05 pm
by IdeasVacuum