HTBasic Help
×
Menu
Index

Example: Bar Meter Limits

 
10     ! *********************************************************************
20     ! Example: Bar/Meter/Limits
30     !
40     ! This program demonstrates the use of the BAR, METER, and LIMITS
50     ! widgets.
60     !
70     ! The program creates three widgets and sets them up and down through
80     ! their default range of 1 through 100. You can set the LOW LIMIT
90     ! and HIGH LIMIT thresholds on both the widgets using a pair of SLIDER
100   ! widgets. As the program passes through the thresholds, it changes
110   ! the color and string on a LABEL via use of events.
120   !
130   ! The program sets up the widgets, sets up events on the SLIDERS and
140   ! BAR (no event is set up on other widgets, since the method is the
150   ! same), and then goes through a loop from 1 to 100 and then back
160   ! down again, changing the widgets with each count.
170   !
180   ! A routine called "Lobound" handles the SLIDER that sets the lower
190   ! trip limit, a routine called "Hibound" that handles the LIMIT that
200   ! sets the higher trip limit, and a routine called "Trip" that handles
210   ! the BAR events.
220   !
230   ! Some features of this program are:
240   !
250   !  - The program will NOT allow you to set the HIGH LIMIT below the
260   !    LOW LIMIT, or the inverse. Try to scroll into these regions and
270   !    the slidebar will pop back.
280   !
290   !  - Normally a BAR event is "level sensitive": if you set an event
300   !    to happen on the "HIGH" ALARM RANGE, you get an event each and
310   !    every time you write a value to that range. For this program,
320   !    however, an event occurs only on transition between ALARM RANGEs.
330   !
340   ! *******************************************************************
350   !
360   ! Variables used:
370   !
380   !   N:                                Loop counter
390   !   Hibound:                Stores METER HIGH LIMIT
400   !   Lobound:                Stores METER LOW LIMIT
410   !   Sts:                                Used to RETURN items from widgets
420   !
430   INTEGER N,Hibound,Lobound,Sts
440   Hibound=100
450   Lobound=1
460   !
470   ! Define colors
480   !
490   INTEGER Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
500   DATA 0,1,2,3,4,5,6,7
510   READ Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
520   !
530   ! Declare variables for display handling
540   !
550   INTEGER D(1:4),Dw,Dh,Cursor
560   INTEGER Pw,Ph,Px,Py,Iw,Ih,Gx,Gy
570   INTEGER Mx,My,Mh,Mw,Brx,Bry,Brh,Brw
580   INTEGER Lmx,Lmy,Lmh,Lmw,Lx,Ly,Lh,Lw
590   INTEGER Lshx,Lshy,Lshw,Lshh,S2x,S2y,S2w,S2h
600   INTEGER Lslx,Lsly,Lslw,Lslh,Slx,Sly,Slw,Slh
610   !
620   ! Get display dimensions
630   !
640   GESCAPE CRT,3;D(*)
650   Dw=D(3)-D(1)
660   Dh=D(4)-D(2)
670   !
680   ! Set up PANEL dimensions, so that PANEL scales to display
690   !
700   Pw=Dw*.8                                                ! PANEL width
710   Ph=Dh*.9                                                ! PANEL height
720   Px=(Dw-Pw)/2                                ! Center PANEL along width
730   Py=(Dh-Ph)/2                                ! Center PANEL above DISP line
740   !
750   ! Build main PANEL
760   !
770   CLEAR SCREEN
780   !
790   ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
800   CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
810   CONTROL @Main;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
820   CONTROL @Main;SET ("TITLE":" Example: Bar Meter Limits")
830   CONTROL @Main;SET ("SYSTEM MENU":"Quit")
840   !
850   ! Get interior dimensions of PANEL
860   !
870   STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
880   !
890   ! Set up widget dimensions
900   !
910   Gx=Iw*.02                                                                ! Gap between widgets
920   Gy=Gx
930   !
940   Mw=Iw*.45                                                ! METER parameters
950   Mh=Ih*.5
960   Mx=Gx
970   My=Gy
980   !
990   Brw=(Iw-(Mw+2*Gx))*.3                                ! BAR parameters
1000  Brh=Mh
1010  Brx=Mx+Mw+Gx
1020  Bry=My
1030  !
1040  Lmw=Mw+Gy+Brw                                ! LIMITS parameters
1050  Lmh=Ih-(Mh+3*Gy)
1060  Lmx=Gx
1070  Lmy=My+Mh+Gy
1080  !
1090  Lw=Iw-(Mw+Brw+4*Gy)                                ! Indicator LABEL parameters
1100  Lh=Lw*.5
1110  Lx=Iw-(Lw+Gx)
1120  Ly=Gy
1130  !
1140  Lshw=(Lw-Gy)/2                                                ! High limit LABEL
1150  Lshh=Lshw*.4
1160  Lshx=Lx
1170  Lshy=Ly+Lh+Gy
1180  !
1190  Shw=Lshw                                                ! High limit SLIDER
1200  Shh=(Ih-(4*Gy+Lh+Lshh))
1210  Shx=Lx
1220  Shy=Lshy+Lshh+Gy
1230  !
1240  Lslw=Lshw                                                ! Low limit LABEL
1250  Lslh=Lshh
1260  Lslx=Lshx+Lshw+Gx
1270  Lsly=Lshy
1280  !
1290  Slw=Shw                                                                ! Low limit SLIDER
1300  Slh=Shh
1310  Slx=Lslx
1320  Sly=Shy
1330  !
1340  ! Build rest of PANEL
1350  !
1360  ! Create METER. (There is no need to set ALL these
1370  ! attributes, but this is an example program).
1380  !
1390  ! The three METER ranges are assigned as red, white and blue -
1400  ! an arbitrary choice.
1410  !
1420  ASSIGN @Meter TO WIDGET "METER";PARENT @Main
1430  CONTROL @Meter;SET ("X":Mx,"Y":My,"WIDTH":Mw,"HEIGHT":Mh)
1440  CONTROL @Meter;SET ("HIGH PEN":Red,"MIDDLE PEN":White,"LOW PEN":Blue)
1450  CONTROL @Meter;SET ("VALUE BACKGROUND":Yellow,"VALUE PEN":Black)
1460  CONTROL @Meter;SET ("LIMITS BACKGROUND":Blue,"LIMITS PEN":White)
1470  CONTROL @Meter;SET ("NEEDLE PEN":Blue,"METER BACKGROUND":Green)
1480  CONTROL @Meter;SET ("SWEEP ANGLE":175)
1490  !
1500  ! Create BAR. Basically the same, but not as many options.
1510  !
1520  ASSIGN @Bar TO WIDGET "BAR";PARENT @Main
1530  CONTROL @Bar;SET ("X":Brx,"Y":Bry,"WIDTH":Brw,"HEIGHT":Brh)
1540  CONTROL @Bar;SET ("HIGH PEN":Red,"MIDDLE PEN":White,"LOW PEN":Blue)
1550  !
1560  ! Create LIMITS
1570  !
1580  ASSIGN @Lim TO WIDGET "LIMITS";PARENT @Main
1590  CONTROL @Lim;SET ("X":Lmx,"Y":Lmy,"WIDTH":Lmw,"HEIGHT":Lmh)
1600  CONTROL @Lim;SET ("INSIDE PEN":White,"OUTSIDE PEN":Magenta)
1610  !
1620  ! Create LABEL to indicate METER range
1630  !
1640  ASSIGN @Label TO WIDGET "LABEL";PARENT @Main
1650  CONTROL @Label;SET ("X":Lx,"Y":Ly,"WIDTH":Lw,"HEIGHT":Lh)
1660  CONTROL @Label;SET ("BORDER":0,"BACKGROUND":White,"VALUE":"NORM")
1670  !
1680  ! Create LABEL for HIGH LIMIT SLIDER
1690  !
1700  ASSIGN @Lsh TO WIDGET "LABEL";PARENT @Main
1710  CONTROL @Lsh;SET ("X":Lshx,"Y":Lshy,"WIDTH":Lshw,"HEIGHT":Lshh)
1720  CONTROL @Lsh;SET ("VALUE":"High")
1730  !
1740  ! Create SLIDER to set HIGH LIMIT
1750  !
1760  ASSIGN @Sh TO WIDGET "SLIDER";PARENT @Main
1770  CONTROL @Sh;SET ("X":Shx,"Y":Shy,"WIDTH":Shw,"HEIGHT":Shh)
1780  CONTROL @Sh;SET ("DIRECT MOVE":1,"AUTO REPEAT":1)
1790  CONTROL @Sh;SET ("VALUE":100)
1800  !
1810  ! Create LABEL for LOW LIMIT SLIDER
1820  !
1830  ASSIGN @Lsl TO WIDGET "LABEL";PARENT @Main
1840  CONTROL @Lsl;SET ("X":Lslx,"Y":Lsly,"WIDTH":Lslw,"HEIGHT":Lslh)
1850  CONTROL @Lsl;SET ("VALUE":"Low")
1860  !
1870  ! Create SLIDER to set LOW LIMIT
1880  !
1890  ASSIGN @Sl TO WIDGET "SLIDER";PARENT @Main
1900  CONTROL @Sl;SET ("X":Slx,"Y":Sly,"WIDTH":Slw,"HEIGHT":Slh)
1910  CONTROL @Sl;SET ("DIRECT MOVE":1,"AUTO REPEAT":1)
1920  !
1930  ! Call bounds handlers to set up initial bounds, then
1940  ! make main PANEL visible. (The bounds handlers will
1950  ! both call the "Trip" routine to initialize the BAR event.)
1960  !
1970  GOSUB Hibound
1980  GOSUB Lobound
1990  CONTROL @Main;SET ("VISIBLE":1)
2000  !
2010  ! Set up the event handlers
2020  !
2030  N=1
2040  ON EVENT @Sl,"DONE" GOSUB Lobound                                                ! Event for LOW LIMIT SLIDER
2050  ON EVENT @Sh,"DONE" GOSUB Hibound                                ! Event for HI LIMIT SLIDER
2060  ON EVENT @Bar,"ALARM" GOSUB Trip                                                ! Event for BAR
2070  ON EVENT @Main,"SYSTEM MENU" GOTO Finis                                ! Event for QUIT toaster menu
2080  !
2090  ! Count from 1 to 100 and back down, and set METER and
2100  ! BAR as this is done.
2110  !
2120  LOOP
2130    FOR N=1 TO 100
2140      CONTROL @Meter;SET ("VALUE":N)
2150      CONTROL @Bar;SET ("VALUE":N)
2160      CONTROL @Lim;SET ("VALUE":N)
2170    NEXT N
2180    FOR N=100 TO 1 STEP -1
2190      CONTROL @Meter;SET ("VALUE":N)
2200      CONTROL @Bar;SET ("VALUE":N)
2210      CONTROL @Lim;SET ("VALUE":N)
2220    NEXT N
2230  END LOOP
2240  !
2250  ! ********************* End of Main Program ************************
2260  !
2270  ! Handler for LOW LIMIT SLIDER:
2280  !
2290 Lobound: !
2300  DISABLE
2310  STATUS @Sl;RETURN ("VALUE":Lobound)                                ! Get SLIDER VALUE
2320  IF Lobound>Hibound THEN                                                                ! If higher than HIGH LIMIT:
2330    Lobound=Hibound                                                                                ! Make sure it is not
2340    CONTROL @Sl;SET ("VALUE":Lobound)
2350  END IF
2360  CONTROL @Meter;SET ("LOW LIMIT":Lobound)                                ! Set limit on widgets
2370  CONTROL @Bar;SET ("LOW LIMIT":Lobound)
2380  CONTROL @Lim;SET ("LOW LIMIT":Lobound)
2390  GOSUB Trip                                                                                                ! Adjust BAR event handling
2400  ENABLE
2410  RETURN
2420  !
2430  ! HIGH LIMIT SCROLL BAR event handler
2440  !
2450 Hibound: !
2460  DISABLE
2470  STATUS @Sh;RETURN ("VALUE":Hibound)                                ! Get SLIDER VALUE
2480  IF Hibound<Lobound THEN                                                                ! If HIGH LIMIT < LOW LIMIT:
2490    Hibound=Lobound                                                                                ! Make sure it is not
2500    CONTROL @Sh;SET ("VALUE":Hibound)
2510  END IF
2520  CONTROL @Meter;SET ("HIGH LIMIT":Hibound) ! Reflect on METER & LIMITS
2530  CONTROL @Bar;SET ("HIGH LIMIT":Hibound)
2540  CONTROL @Lim;SET ("HIGH LIMIT":Hibound)
2550  GOSUB Trip                                                                                                ! Adjust event handling
2560  ENABLE
2570  RETURN
2580  !
2590  ! BAR event handler.
2600  ! You get the current value being sent to the BAR and determine
2610  ! the range it is in. Then, you set the event to occur on the
2620  ! adjoining range(s). This ensures that you only get an event when
2630  ! you transition between ranges.
2640  !
2650  ! As noted, the bounds handlers call Trip to adjust events. Since
2660  ! you are changing the HIGH & LOW LIMITs with the bounds handlers,
2670  ! you want to make sure that the events are rearranged accordingly.
2680  !
2690 Trip: !
2700  DISABLE
2710  SELECT N
2720  CASE <Lobound
2730    CONTROL @Bar;SET ("ALARM RANGES":"MIDDLE","ALARM TYPE":"EVENT")
2740    CONTROL @Label;SET ("BACKGROUND":Blue,"VALUE":"LOW")
2750  CASE <=Hibound
2760    CONTROL @Bar;SET ("ALARM RANGES":"LOW,HIGH","ALARM TYPE":"EVENT")
2770    CONTROL @Label;SET ("BACKGROUND":White,"VALUE":"NORM")
2780  CASE >Hibound
2790    CONTROL @Bar;SET ("ALARM RANGES":"MIDDLE","ALARM TYPE":"EVENT")
2800    CONTROL @Label;SET ("BACKGROUND":Red,"VALUE":"HIGH")
2810  END SELECT
2820  ENABLE
2830  RETURN
2840  !
2850 Finis: !
2860  ASSIGN @Main TO *                ! Delete PANEL widget
2870  END