Left to right - a small beginner snippet for progressbar

You can post your code snippets here for others to use and learn from
Post Reply
LarsB
Posts: 72
Joined: Sat May 06, 2017 4:37 pm

Left to right - a small beginner snippet for progressbar

Post by LarsB »

Hi there just enjoying Hollywood and a little RappaGUI.

Just a small example to move your progressbar from "empty" to "full" and backwards. So.. up ..side .. down :)

Here is the .hwp code:

Code: Select all

@REQUIRE "RapaGUI"
@DISPLAY 1,{Width = 640, Height = 480, Borderless = True}


/*just a small eventhandler for quiting and infos*/
Function EventFunktion(msg)
Switch msg.action

Case "RapaGUI"
     
	 Switch msg.id
	 Case "menabout":
	    moai.Request("Window-Test", "OK")
	 Case "menaboutrapagui":
	    moai.DoMethod("app", "aboutrapagui")	  
	 Case "menquit":
	    End         		 	  
	
    EndSwitch  
EndSwitch
EndFunction

/*sets the progressbar to a certain value*/
Function p_SetProgress(x)

	moai.Set("prgbar", "level", x)
EndFunction

/*incrmenting the progressbar so it gets "filled from left to right
hence prgbarc = prgbarc + 1*/
Function p_ProgressbarTimer()

	If prgbarc < moai.Get("prgbar", "max")
		prgbarc = prgbarc + 1	
		p_SetProgress(prgbarc)
	Else
		ClearInterval(1)
			
	EndIf 
EndFunction

/*derementing the progressbar so it gets "emptied"
hence prgbarc = prgbarc - 1*/
Function p_ProgressbarTimer2()

	If prgbarc < moai.Get("prgbar", "max")
		prgbarc = prgbarc - 1	
		p_SetProgress(prgbarc)
	Else
		ClearInterval(1)
			
	EndIf 
EndFunction

prgbarc = 0					
/*setting interval determines the speed of the bar movement*/
SetInterval(1, p_ProgressbarTimer, 30)	

InstallEventHandler({RapaGUI = EventFunktion})
moai.CreateApp(FileToString("ProGUI1.xml"))

/*first loop for incrmenting the bar. Watchout! Dont let it go to 100
(the default max) or the show is over ;)*/
Repeat
CheckEvent()
Until prgbarc >= 99


/*setting interval for the second, decrementingloop*/
SetInterval(1, p_ProgressbarTimer2, 30)

/*and off we go!*/
Repeat
CheckEvent()
Forever
And here is the xml which should be named ProGUI1.xml

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">

 <menubar id="mymenubar">
 <menu title="File">
 <item id="menabout">About...</item>
  <item id="menaboutrapagui"> About RapaGUI...</item>
         <item/>
         <item id="menquit">Quit</item>
      </menu>
   </menubar>

<window id="windows1" title="Window-Test" menubar="mymenubar" width="300" height="250">
<hgroup> 
<rectangle/>
<progressbar id="prgbar"/>
<rectangle/>

</hgroup>

</window>
</application>
:roll:
Post Reply