Progress Bars - Elements - Hag GUI for Cobra
Progress bars are rectangular elements used to convey the progress of a task.
Progress bars expose the following read-only variables:
progressbar.x: Integer - Progress bar x position
progressbar.y: Integer - Progress bar y position
progressbar.w: Integer - Progress bar width
progressbar.h: Integer - Progress bar height
progressbar.enabled: Boolean - If progress bar is enabled
progressbar.visible: Boolean - If progress bar is visible
For a ready-to-run example, see Example_Progressbar in the Examples download.
Example:
Program (icon:"hag\icons\window.ico")
Uses
hagC2D,
cobra2D,
keyset
Var
frmMain: ^forms
prgMain: ^progressBars
sliMain: ^sliders
tbxMain: ^textBoxes
btnClose: ^buttons
background: Element
i: Integer
str: String
Begin
SetAppName("Progress bar 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()
tbxMain = CreateTextBox(frmMain, 20, 80, 80, "0")
sliMain = CreateSlider(frmMain, 120, 85, 180)
SliderSetPercent(sliMain, 0)
prgMain = CreateProgressBar(frmMain, 20, 120, 280)
ProgressBarPercent(prgMain, 0)
btnClose = CreateButton(frmMain, 250, 207, 50, "Close")
HagUpdateOnce()
While ExitRequested = FALSE
HagUpdateAll_AutoKeys()
If SliderUpdated(sliMain) then
ProgressBarPercent(prgMain, SliderGetPercent(sliMain))
TextBoxSetContents(tbxMain, ToString(SliderGetPercent(sliMain)))
FlushTextBox(tbxMain)
Endif
If TextBoxUpdated(tbxMain) then
str = TextBoxContents(tbxMain)
If Length(str) > 0 then
SliderSetPercent(sliMain, ToInt(str))
ProgressBarPercent(prgMain, ToInt(str))
FlushSlider(sliMain)
Endif
Endif
If ButtonClicked(btnClose) then RequestExit
If KeyHits(VK_ESCAPE) > 0 then RequestExit
Flip
Pause(1)
Wend
HagFreeAll()
CloseScreen()
End
Uses
hagC2D,
cobra2D,
keyset
Var
frmMain: ^forms
prgMain: ^progressBars
sliMain: ^sliders
tbxMain: ^textBoxes
btnClose: ^buttons
background: Element
i: Integer
str: String
Begin
SetAppName("Progress bar 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()
tbxMain = CreateTextBox(frmMain, 20, 80, 80, "0")
sliMain = CreateSlider(frmMain, 120, 85, 180)
SliderSetPercent(sliMain, 0)
prgMain = CreateProgressBar(frmMain, 20, 120, 280)
ProgressBarPercent(prgMain, 0)
btnClose = CreateButton(frmMain, 250, 207, 50, "Close")
HagUpdateOnce()
While ExitRequested = FALSE
HagUpdateAll_AutoKeys()
If SliderUpdated(sliMain) then
ProgressBarPercent(prgMain, SliderGetPercent(sliMain))
TextBoxSetContents(tbxMain, ToString(SliderGetPercent(sliMain)))
FlushTextBox(tbxMain)
Endif
If TextBoxUpdated(tbxMain) then
str = TextBoxContents(tbxMain)
If Length(str) > 0 then
SliderSetPercent(sliMain, ToInt(str))
ProgressBarPercent(prgMain, ToInt(str))
FlushSlider(sliMain)
Endif
Endif
If ButtonClicked(btnClose) then RequestExit
If KeyHits(VK_ESCAPE) > 0 then RequestExit
Flip
Pause(1)
Wend
HagFreeAll()
CloseScreen()
End
Stay Subscribed
RSS feed or get updates by e-mail.
, subscribe to theYou can also contact me directly - I make an effort to reply to every e-mail.