SG_ButtonGadget

Syntax:

Result=SG_ButtonGadget(SG_GadgetID_L.l, X_Pos_L.l, Y_Pos_L.l, Width_L.l, Height_L.l, GadgetText_S.s, [Flags_L.l])

Parameters:

SG_GadgetID_L

=

The number of the gadget

X_Pos_L

=

the x-position of the gadget

Y_Pos_L

=

the y position of the gadget

Width_L

=

the width of the gadget

Height_L

=

the height of the gadget

GadgetText_S

=

the text of the item

[Flags_L]

=

'Flags' are always optional and can be composed of one or several (using the bitwise OR operator '|') of the following constants:

#PB_Button_Right : Aligns the button text at the right.

=

#PB_Button_Left : Aligns the button text at the left.

=

#PB_Button_Default : Makes the button look as if it is the default button in the window.

=

#PB_Button_Toggle : Creates a toggle button: one click pushes it, another will release it.

=


Return Values:

Result

=

contains a pointer to the internal gadget structur. See the source of this lib for more information


Description:

Create a button gadget in the current GadgetList. SG_GadgetID_L will be the number returned by SG_ScreenGadgetEvent() command.

The following Events are supported:

#SG_EventType_LeftClick : Left mouse button click.

#SG_EventType_RightClick : Right mouse button click.

#SG_EventType_LeftRelease : Left mouse button released.

#SG_EventType_RightRelease : Right mouse button released.


Example:

; Shows possible flags of SG_ButtonGadget in action... 
  If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu|#PB_Window_ScreenCentered,"SG_ButtonGadgets") And InitSprite() And InitMouse() And InitKeyboard()
    If OpenWindowedScreen(WindowID(), 0, 0, 300, 200, 0, 0, 0)
      SG_ButtonGadget(0, 10, 10, 200, 20, "Standard Button (quit)") 
      SG_ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left) 
      SG_ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right) 
      SG_ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
      
      ; create a mouse
      If CreateSprite(0, 8, 8) 
        If StartDrawing(SpriteOutput(0)) 
          Circle(4, 4, 4, RGB(255, 255, 255)) 
          StopDrawing()
        EndIf 
      EndIf
      
      Repeat
        ClearScreen(0, 0, 0)
        SG_DrawAllGadgets()
        ExamineMouse() 
        DisplayTransparentSprite (0, MouseX(), MouseY())
        FlipBuffers()
        
        ; standard loop
        Event = SG_ScreenGadgetEvent() ; This line checks if an event happened 
        GadgetID = SG_EventScreenGadgetID() ; Is it a gadget event? 
        EventType = SG_EventType() ; The event type
        
        If Event = #PB_EventGadget 
          If GadgetID = 0
            If EventType = #SG_EventType_LeftRelease
              Debug "button 0"
              SG_FreeAllGadgets()
              Event = #PB_Event_CloseWindow
            EndIf
          ElseIf GadgetID = 1
            If EventType = #SG_EventType_LeftRelease
              Debug "button 1"
            EndIf
          ElseIf GadgetID = 2
            If EventType = #SG_EventType_LeftRelease
              Debug "button 2"
            EndIf
          ElseIf GadgetID = 4
            If EventType = #SG_EventType_LeftRelease
              Debug "button 4"
            EndIf
          EndIf
        EndIf
        
        Delay(1)
      Until WindowEvent() = #PB_Event_CloseWindow Or Event = #PB_Event_CloseWindow
      
    EndIf
  EndIf

Remarks:



Supported OS:   Windows