PureBasic Forum
http://forums.purebasic.com/english/

3D CanvasGadget Buttons
http://forums.purebasic.com/english/viewtopic.php?f=12&t=72184
Page 1 of 1

Author:  VB6_to_PBx [ Thu Jan 31, 2019 8:22 am ]
Post subject:  3D CanvasGadget Buttons

3D CanvasGadget Buttons ( 5 examples )

Code:
;-< Top >
;-
;-       3D_CanvasButtons.pb
;-
;-       Link :
;-       Post Subject/Date :
;-       PureBasic version : PB 5.41
;-     
;-< Start Program >------------------------------------------------------------
;
;
EnableExplicit
Global.i EW , WW , EG , ET , EM , AG     ;<<--- EW= EventWindow()  WW= WaitWindowEvent()  EG= EventGadget()  ET= EventType()  EM= EventMenu()  AG= GetActiveGadget()

Global.i CB, FontName, FontColor, BackColor, FrameColor
#CB = 20  ;<<--- Dim 20 potential CanvasButtons
Global.s Dim TextToDraw(#CB)

Global.i Dim EnterFontName(#CB),  Dim EnterFontColor(#CB),  Dim EnterBackColor(#CB),  Dim EnterFrameColor(#CB)
Global.i Dim LeaveFontName(#CB),  Dim LeaveFontColor(#CB),  Dim LeaveBackColor(#CB),  Dim LeaveFrameColor(#CB)

Global.i Dim LBDownFontName(#CB), Dim LBDownFontColor(#CB), Dim LBDownBackColor(#CB), Dim LBDownFrameColor(#CB)
Global.i Dim LBUpFontName(#CB),   Dim LBUpFontColor(#CB),   Dim LBUpBackColor(#CB),   Dim LBUpFrameColor(#CB)

Global.i Dim MBDownFontName(#CB), Dim MBDownFontColor(#CB), Dim MBDownBackColor(#CB), Dim MBDownFrameColor(#CB)
Global.i Dim MBUpFontName(#CB),   Dim MBUpFontColor(#CB),   Dim MBUpBackColor(#CB),   Dim MBUpFrameColor(#CB)

Global.i Dim RBDownFontName(#CB), Dim RBDownFontColor(#CB), Dim RBDownBackColor(#CB), Dim RBDownFrameColor(#CB)
Global.i Dim RBUpFontName(#CB),   Dim RBUpFontColor(#CB),   Dim RBUpBackColor(#CB),   Dim RBUpFrameColor(#CB)


#Verdana8 = 1
LoadFont(#Verdana8,"Verdana",8)

#Verdana8B = 2
LoadFont(#Verdana8B,"Verdana",8,#PB_Font_Bold)

#Verdana9B = 3
LoadFont(#Verdana9B,"Verdana",9,#PB_Font_Bold)

 
Declare CanvasButton()
Procedure CanvasButton()
    Select ET
    Case #PB_EventType_MouseEnter
         FontName = EnterFontName(CB)
         FontColor = EnterFontColor(CB)
         BackColor = EnterBackColor(CB)
         FrameColor = EnterFrameColor(CB)
     
    Case #PB_EventType_MouseLeave
         FontName = LeaveFontName(CB)
         FontColor = LeaveFontColor(CB)
         BackColor = LeaveBackColor(CB)
         FrameColor = LeaveFrameColor(CB)
     
    Case #PB_EventType_LeftButtonDown , #PB_EventType_RightButtonDown, #PB_EventType_MiddleButtonDown
         FontName = LBDownFontName(CB)
         FontColor = LBDownFontColor(CB)
         BackColor = LBDownBackColor(CB)
         FrameColor = LBDownFrameColor(CB)

    Case #PB_EventType_LeftButtonUp, #PB_EventType_RightButtonUp, #PB_EventType_MiddleButtonUp
         FontName = LBUpFontName(CB)
         FontColor = LBUpFontColor(CB)
         BackColor = LBUpBackColor(CB)
         FrameColor = LBUpFrameColor(CB)
    EndSelect
 
    If StartDrawing(CanvasOutput(EG))
         Box(0, 0, GadgetWidth(EG), GadgetHeight(EG), FrameColor)
         Box(1, 1, GadgetWidth(EG)-2, GadgetHeight(EG)-2, BackColor)
         DrawingFont(FontID(FontName))
         DrawText((GadgetWidth(EG)-TextWidth(TextToDraw(CB)))/2, (GadgetHeight(EG)-TextHeight(TextToDraw(CB)))/2, TextToDraw(CB), FontColor, BackColor)
         StopDrawing()
   EndIf

EndProcedure


OpenWindow(1, #PB_Ignore, #PB_Ignore, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetWindowColor(1,RGB(170,170,170))

    ContainerGadget(100, 60, 5 ,77, 20, #PB_Container_Double) : SetGadgetColor(100,#PB_Gadget_BackColor,RGB(0,0,0))
    CanvasGadget(1, 1, 1, 72, 15) : EG = 1 : CB = 1 : TextToDraw(CB) = " Calc 1 "
              FontName = #Verdana8B : FontColor = RGB(0,0,0)            : BackColor = RGB(255,255,255)          : FrameColor = RGB(0,0,0)
    EnterFontName(CB) = #Verdana8B  : EnterFontColor(CB) = RGB(180,0,0) : EnterBackColor(CB) = BackColor        : EnterFrameColor(CB) = RGB(180,0,0)
    LeaveFontName(CB) = #Verdana8B  : LeaveFontColor(CB) = FontColor    : LeaveBackColor(CB) = BackColor        : LeaveFrameColor(CB) = FrameColor
    LBDownFontName(CB) = #Verdana8B : LBDownFontColor(CB) = RGB(0,0,0)  : LBDownBackColor(CB) = RGB(255,255,0)  : LBDownFrameColor(CB) = RGB(255,255,0)
    LBUpFontName(CB) = #Verdana8B   : LBUpFontColor(CB) = FontColor     : LBUpBackColor(CB) = BackColor         : LBUpFrameColor(CB) = FrameColor
    CloseGadgetList()
    CanvasButton()

    ContainerGadget(200, 60, 35, 80, 23, #PB_Container_Raised) : SetGadgetColor(200,#PB_Gadget_BackColor,RGB(0,0,0))
    CanvasGadget(2, 1, 1, 72, 15) : EG = 2 : CB = 2 : TextToDraw(CB) = " Calc 2 "
              FontName = #Verdana8B : FontColor = RGB(255,255,255)      : BackColor = RGB(0,160,0)              : FrameColor = RGB(0,160,0)
    EnterFontName(CB) = #Verdana8B  : EnterFontColor(CB) = RGB(0,0,0)   : EnterBackColor(CB) = RGB(0,240,0)     : EnterFrameColor(CB) = RGB(0,160,0)
    LeaveFontName(CB) = #Verdana8B  : LeaveFontColor(CB) = FontColor    : LeaveBackColor(CB) = BackColor        : LeaveFrameColor(CB) = FrameColor
    LBDownFontName(CB) = #Verdana8B : LBDownFontColor(CB) = RGB(0,0,0)  : LBDownBackColor(CB) = RGB(255,255,0)  : LBDownFrameColor(CB) = RGB(255,255,0)
    LBUpFontName(CB) = #Verdana8B   : LBUpFontColor(CB) = FontColor     : LBUpBackColor(CB) = BackColor         : LBUpFrameColor(CB) = FrameColor
    CloseGadgetList()
    CanvasButton()

    ContainerGadget(300, 60, 65, 79, 22, #PB_Container_Raised) ;: SetGadgetColor(300,#PB_Gadget_BackColor,RGB(255,255,0))
    CanvasGadget(3, 0, 0, 72, 15) : EG = 3 : CB = 3 : TextToDraw(CB) = " Calc 3 "
              FontName = #Verdana8B : FontColor = RGB(0,0,0)            : BackColor = RGB(255,255,0)          : FrameColor = RGB(180,180,180)
    EnterFontName(CB) = #Verdana8B  : EnterFontColor(CB) = RGB(180,0,0) : EnterBackColor(CB) = BackColor      : EnterFrameColor(CB) = RGB(0,0,255)
    LeaveFontName(CB) = #Verdana8B  : LeaveFontColor(CB) = FontColor    : LeaveBackColor(CB) = BackColor      : LeaveFrameColor(CB) = FrameColor
    LBDownFontName(CB) = #Verdana8B : LBDownFontColor(CB) = RGB(0,0,0)  : LBDownBackColor(CB) = RGB(0,240,0)  : LBDownFrameColor(CB) = RGB(180,0,0)
    LBUpFontName(CB) = #Verdana8B   : LBUpFontColor(CB) = FontColor     : LBUpBackColor(CB) = BackColor       : LBUpFrameColor(CB) = FrameColor
    CloseGadgetList()
    CanvasButton()

    ContainerGadget(400, 60, 95, 79, 22, #PB_Container_Raised) ;: SetGadgetColor(400,#PB_Gadget_BackColor,RGB(0,0,0))
    CanvasGadget(4, 0, 0, 72, 15) : EG = 4 : CB = 4 : TextToDraw(CB) = " Calc 4 "
             FontName = #Verdana8B  : FontColor = RGB(0,0,0)            : BackColor = RGB(226,245,255)          : FrameColor = RGB(180,180,180)
    EnterFontName(CB) = #Verdana8B  : EnterFontColor(CB) = RGB(0,0,0)   : EnterBackColor(CB) = BackColor        : EnterFrameColor(CB) = RGB(0,0,255)
    LeaveFontName(CB) = #Verdana8B  : LeaveFontColor(CB) = FontColor    : LeaveBackColor(CB) = BackColor        : LeaveFrameColor(CB) = FrameColor
    LBDownFontName(CB) = #Verdana8B : LBDownFontColor(CB) = RGB(0,0,0)  : LBDownBackColor(CB) = RGB(255,255,0)  : LBDownFrameColor(CB) = RGB(0,0,0)
    LBUpFontName(CB) = #Verdana8B   : LBUpFontColor(CB) = FontColor     : LBUpBackColor(CB) = BackColor         : LBUpFrameColor(CB) = FrameColor
    CloseGadgetList()
    CanvasButton()

    CanvasGadget(5, 60, 125, 72, 18) : EG = 5 : CB = 5 : TextToDraw(CB) = " Calc 5 "
             FontName = #Verdana8B  : FontColor = RGB(0,0,0)            : BackColor = RGB(226,245,255)          : FrameColor = RGB(0,0,255)
    EnterFontName(CB) = #Verdana8B  : EnterFontColor(CB) = RGB(0,0,0)   : EnterBackColor(CB) = BackColor        : EnterFrameColor(CB) = RGB(180,0,0)
    LeaveFontName(CB) = #Verdana8B  : LeaveFontColor(CB) = FontColor    : LeaveBackColor(CB) = BackColor        : LeaveFrameColor(CB) = FrameColor
    LBDownFontName(CB) = #Verdana9B : LBDownFontColor(CB) = RGB(0,0,0)  : LBDownBackColor(CB) = RGB(255,255,0)  : LBDownFrameColor(CB) = RGB(0,0,0)
    LBUpFontName(CB) = #Verdana8B   : LBUpFontColor(CB) = FontColor     : LBUpBackColor(CB) = BackColor         : LBUpFrameColor(CB) = FrameColor
    CanvasButton()

 
Repeat
    EW = EventWindow()       ;<<--- In Programs with more than one Form or Window, which Window did the Event occur on.
    WW = WaitWindowEvent()   ;<<--- Wait until a new Window or Gadget Event occurs.
    EG = EventGadget()       ;<<--- Which Gadget did the Event occur on. ( Numerical Number or Constant #Name of the Gadget )
    ET = EventType()         ;<<--- What sort of Event Type occurred.
    EM = EventMenu()         ;<<--- Which Menu did the Event occur on.
    AG = GetActiveGadget()   ;<<--- Get the Active Gadget's Numerical Number or Constant #Name that has the current Focus

    Select EW
    Case 1
         Select WW
         Case #PB_Event_Gadget : If ET = #PB_EventType_LeftButtonUp : SetWindowTitle(1,"") : EndIf
              Select EG
              Case 1 : CB = 1 : CanvasButton() : If ET = #PB_EventType_LeftButtonDown : SetWindowTitle(1,"clicked Calc 1") : EndIf
              Case 2 : CB = 2 : CanvasButton() : If ET = #PB_EventType_LeftButtonDown : SetWindowTitle(1,"clicked Calc 2") : EndIf
              Case 3 : CB = 3 : CanvasButton() : If ET = #PB_EventType_LeftButtonDown : SetWindowTitle(1,"clicked Calc 3") : EndIf
              Case 4 : CB = 4 : CanvasButton() : If ET = #PB_EventType_LeftButtonDown : SetWindowTitle(1,"clicked Calc 4") : EndIf
              Case 5 : CB = 5 : CanvasButton() : If ET = #PB_EventType_LeftButtonDown : SetWindowTitle(1,"clicked Calc 5") : EndIf
              EndSelect
         EndSelect
    EndSelect
Until WW = #PB_Event_CloseWindow : End


;     #PB_Container_BorderLess : Without any border (Default).
;     #PB_Container_Flat       : Flat frame.
;     #PB_Container_Raised     : Raised frame.
;     #PB_Container_Single     : Single sunken frame.
;     #PB_Container_Double     : Double sunken frame.
;
;-< End Program >--------------------------------------------------------------


Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/