Draw Buttons

Just starting out? Need help? Post your questions and find answers here.
User avatar
braveheart
User
User
Posts: 37
Joined: Mon Jan 04, 2010 5:54 pm

Draw Buttons

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Draw Buttons

Post 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.
User avatar
braveheart
User
User
Posts: 37
Joined: Mon Jan 04, 2010 5:54 pm

Re: Draw Buttons

Post by braveheart »

Thanks Demivec, could you show me an example?
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Draw Buttons

Post 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.
User avatar
braveheart
User
User
Posts: 37
Joined: Mon Jan 04, 2010 5:54 pm

Re: Draw Buttons

Post by braveheart »

:o Thank you Demivec, no need to rush. If you please make it very simple.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Draw Buttons

Post by IdeasVacuum »

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply