REM Sample program for use of Buttons in QB2C REM Define and open three X windows to play with: SCREEN (500, 100), 400, 300: REM Open the main window PALETTE 2, 0x00, 0xff, 0x00: REM Green PALETTE 3, 0xff, 0xff, 0x00: REM Yellow PALETTE 4, 0xff, 0x00, 0x00: REM Red PALETTE 5, 0xc0, 0xc0, 0xc0: REM Background PALETTE 6, 0x00, 0x00, 0xff: REM Blue PALETTE 12, 0xff, 0x00, 0x00: REM Orange PALETTE 14, 0xf0, 0xf0, 0xf0: REM Button rim light PALETTE 15, 0x80, 0x80, 0x80: REM Button rim black XCLS 5 XWINDOW (150, 100), 300, 200 XCLS 5 XWINDOW (10, 100), 100, 200 XCLS 5 text0$ = "" text1$ = "" SET TXAL 0,0 SET TFON Hel, 14 REM Define buttons REM Buttons on xwindow 0 XDefineButton 0, 0, (20, 20), 80, 25 XDefineButton 0, 4, (20, 60), 80, 25 XDefineButton 0, 7, (20,100), 80, 25 REM Buttons on xwindow 1 XDefineButton 1, 12, (20,100), 80, 25 XDefineButton 1, 15, (120,100),80, 25 XDefineButton 1, 18, (120,70), 14, 14 XDefineButton 1, 19, (140,70), 14, 14 REM Buttons on xwindow 2 XDefineButton 2, 20, (0, 0), 80, 25 XDefineButton 2, 21, (0, 25), 80, 25 XDefineButton 2, 22, (0, 50), 80, 25 XDefineButton 2, 23, (0, 75), 80, 25 REM Define what happens when you point to a button (without clicking on it) XButtonFocus 20, "Up" XButtonFocus 21, "Up" XButtonFocus 22, "Up" XButtonFocus 23, "Down" XButtonFocus 7, "Square" XButtonFocus 12, "Square" XButtonFocus 15, "Square" REM Uncoment this to get yellow text background: REM SET BG 3 REM Draw buttons on all three windows text0$ = "Initial 0 text." text1$ = "Initial 1 text." XSELWI 0 XDrawInputButton 0, text0$ XDrawInputButton 4, text1$ XDrawButton 7, "Exit", "Up" XSELWI 1 XDrawButton 12, "Previous", "Up" XDrawButton 15, "Next", "Up" XDrawButton 18, "", "Up" XDrawButton 19, "", "Up" XSELWI 2 XDrawButton 20, "Button 20", "Flat" XDrawButton 21, "Button 21", "Flat" XDrawButton 22, "Button 22", "Flat" XDrawButton 23, "Button 23", "Flat" XUPDATE REM Button loop. The logic here is the following. In a loop, you call REM XPOINTER to know where the pointer (mouse) is and whether a mouse button REM has been pressed. You pass this information to XCheckButtons which REM checks whether a button has been pointed to by the pointer and which REM one it was (but%). If no button is pointed to then but% = 0, otherwise REM it returns the id number of the button. 10 XPOINTER (x%, y%), win%, answ% XCheckButtons (x%, y%), win%, but% IF but% >=0 THEN state% = XGetButtonState%(but%) IF but% = 0 AND answ% = 1 THEN XInputButton but%, text0$, status%: ? "Exit status="; status% IF but% = 4 AND answ% = 1 THEN XInputButton but%, text1$, status%: ? "Exit status="; status% IF but% = 7 AND answ% = 1 THEN XClickButton but% ? "First input button text:"; text0$ ? "Second input button text:"; text1$ pause 0.25 END END IF IF (but% = 12 OR but% = 15) AND answ% = 1 THEN XClickButton but% IF (but% >= 20 AND but% <= 23) AND answ% = 1 THEN XClickButton but%, 0.5 IF (but% = 18 OR but% = 19) AND answ% = 1 THEN XToggleButton but% 9 END IF GOTO 10 REM End of main END