This content is provided AS IS for archive purposes only. Content may be out of date with no guarantee of correctness.

Sliders - Elements - Hag GUI for Cobra - Static

Main Article

Sliders - Elements - Hag GUI for Cobra

Sliders using the XP theme.

Sliders allow the user to set a value by moving an indicator. Sliders may optionally have divisions which allow only a finite amount of values.

Sliders expose the following read-only variables:

slider.x: Integer - Slider x position
slider.y: Integer - Slider y position
slider.w: Integer - Slider width
slider.h: Integer - Slider height
slider.enabled: Boolean - If slider is enabled
slider.visible: Boolean - If slider is visible
slider.gotUpdated: Boolean - If slider got updated

For a ready-to-run example, see Example_Slider in the Examples download.

Example:

Program (icon:"hag\icons\window.ico")
   Uses
       hagC2D,
       cobra2D,
       keyset

Var
   frmMain: ^forms
       prgMain: ^progressBars
       btnClose: ^buttons
       sliExample: Array[7] of ^sliders
   
   background: Element
   i: Integer

Begin

   SetAppName("Sliders example")
   OpenScreen(320, 240, 32, FALSE, COB_SHOWBORDER+COB_SHOWCLOSE)
   
   background = CreateSprite(320,240)
   Cls(ToRGBA(235,233,237),background) ; Flip
   

   // Init GUI
   HagBaseDir("hag\")
   HagInit(320, 240, 1) // Start at sprite index 1 because of the background sprite    
   HagLoadGuiTheme("xp")    
   
   // Set up GUI Elements
   frmMain = CreateForm()
       
       sliExample[0] = CreateSlider(frmMain, 20, 20, 200, 5, HAG_VERTICAL)
       sliExample[1] = CreateSlider(frmMain, 60, 20, 240)
       sliExample[2] = CreateSlider(frmMain, 60, 50, 240, 3)
       sliExample[3] = CreateSlider(frmMain, 60, 80, 240, 4)
       sliExample[4] = CreateSlider(frmMain, 60, 110, 240, 5)
       sliExample[5] = CreateSlider(frmMain, 60, 140, 240, 10)
       sliExample[6] = CreateSlider(frmMain, 60, 170, 240, 15)
       
       SliderSetPercent(sliExample[1], 12)
       SliderSetDivision(sliExample[5], 6)
                   
       btnClose = CreateButton(frmMain, 250, 207, 50, "Close")
   
   
   FocusButton(btnClose)
   HagUpdateOnce()
   
   
   While ExitRequested = FALSE
       
       HagUpdateAll_AutoKeys()
       
       For i = 0 to 6
           If SliderUpdated(sliExample[i]) then
               SetAppName("Slider: "+i+", Percent: "+SliderGetPercent(sliExample[i])+"%, Division: "+SliderGetDivision(sliExample[i]))
           Endif
       Next

       If
ButtonClicked(btnClose) then RequestExit

       If KeyHits(VK_ESCAPE) > 0 then RequestExit
       
       Flip
       Pause
(1)
   Wend
   
   HagFreeAll()
   CloseScreen()

End

Stay Subscribed

@golightlyb, subscribe to the RSS feed or get updates by e-mail.

You can also contact me directly - I make an effort to reply to every e-mail.


Login
v0.34.archive