This is about the first widget for my Action! windowing library. To separate a widgets function name from a window function, I used a G. So I’m calling them gadgets instead. This gadget is a progress bar.
Progress Bar (GProg)
The progress bar indicator displays only the actual progress bar at the coordinates within the window specified. This gives the freedom to include other elements in the progress window as desired. Each call to the function displays a bar for the percentage given. It is possible to go backwards as well (i.e.: 100 to 0 instead of 0 to 100).
The function GProg takes four parameters. They are:
- Window handle number (bN)
- X position / column (x) – within the windows bounds
- Y position / row (y) – within the windows bounds
- Bar size – percentage complete (0 to 100, whole numbers only)
There is no return value, and as such the function is declared as a PROCedure.
The procedure works as follows:
- First, and empty string is created.
- Next the string is filled from left to right with inverse spaces. The number of spaces is calculated by taking the bar size parameter and dividing it by 5. Why 5? The bar is 20 characters long. 20 * 5 is 100.
- Last the bar is printed to the window using WPrint, which writes directly to screen memory in the appropriate location.
; -------------------------------------- ; Proc..: GProg(BYTE bN,x,y,bS) ; Desc..: Displays progress bar ; Params: bN = number of window handle ; x = column for cursor ; y = row for cursor ; bS = bar size (pct complete) ; -------------------------------------- PROC GProg(BYTE bN,x,y,bS) INT i CHAR ARRAY cL(21),cB(21) ; Set default and block lines SCopy(cL," ") ; Update bar contents ; Div by 5 since bar is 1/5 100 for i=1 to bS/5 DO cL(i)=CINVSP OD ; Display new bar WPrint(bN,x,y,cL) RETURN
Usage
To demonstrate this gadget I created a new program. This one opens a window on the left to display each window handles status. A progress bar is displayed while each status is being gathered and printed.
; Program: WINDOW.ACT ; Author.: Wade Ripkowski ; Date...: 2016.04 ; Desc...: Test Windowing Library ; License: Creative Commons ; Attribution-NonCommercial- ; NoDerivatives ; 4.0 International ; Include library INCLUDE "D3:DEFINES.ACT" INCLUDE "D3:DEFWIN.ACT" INCLUDE "D3:LIBSTR.ACT" INCLUDE "D3:LIBWIN.ACT" INCLUDE "D3:LIBMISC.ACT" INCLUDE "D3:LIBGADG.ACT" ; Start MODULE PROC Main() ; Window handles BYTE bW1,bW2,bLp,bS INT iP ; Init Window System WInit() ; Open window 1 bW1=WOpen(9,2,20,14,WINVOFF) WTitle(bW1,"Status") WPrint(bW1,1,1,"Window Status") WPrint(bW1,1,2,"------ ------") ; Open progress bar window bW2=WOpen(7,18,24,4,WINVOFF) WPrint(bW2,2,1,"Progress:") ; Display initial progress bar GProg(bW2,2,2,0) ; Loop through each window handle for bLp=0 to 9 DO ; Get the status bS=WStat(bLp) ; Print the window handle # WPos(bW1,6,3+bLp) WPut(bW1,bLp+48) ; Print the handle status if bS=WSUSED then WPrint(bW1,8,3+bLp,"Used") else WPrint(bW1,8,3+bLp,"Free") fi ; Update progress bar iP=((bLp+1) MOD 10)*10 if iP=0 then iP=100 fi GProg(bW2,2,2,iP) ; Wait for a keystroke or console key WaitKC() OD ; Close window 2 WClose(bW2) ; Close window 1 WClose(bW1) RETURN
Results
When the program is run, it expects a keypress after each status line is printed. Screenshots of the demonstration program. The first is at the first of 10 window handles (or 10 percent):
The next is after the fifth window handle has been displayed (or 50 percent):
The last is after all 10 window handles status have been displayed (or 100 percent):
The next post will be the release of the entire library to date.