'=========================================================================== ' Subject: GUI BUTTONS W/MOUSE SUPPORT Date: 01-09-97 (22:16) ' Author: Dave Shea Code: QB, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: GRAPHICS.ABC '=========================================================================== ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ' BUTTONS.BAS by Dave Shea ' Released to Public Domain ' on January 9th, 1997. No ' Warantees expressed or ' implied. ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= DECLARE SUB Page1 () DECLARE SUB Page2 () DECLARE SUB SetUpPage (PageNum) DECLARE SUB GPrint (x%, y%, Text$, Culler%, Font) DECLARE SUB CheckBox (x, y, PageNum) DECLARE SUB DrawUpButton (x%, y%, x1%, y1%, Text$) DECLARE SUB DrawDownButton (x%, y%, x1%, y1%, Text$) DECLARE SUB MouseSH (Num!) DECLARE SUB Mouse (HVSP$, Min, Max) '$INCLUDE: 'qb.bi' TYPE Button x AS INTEGER y AS INTEGER x1 AS INTEGER y1 AS INTEGER Pressed AS INTEGER Text AS STRING * 40 Page AS INTEGER END TYPE CONST NumOfButtons = 15 'COMMON SHARED B DIM SHARED InReg AS RegType, OutReg AS RegType DIM SHARED But(NumOfButtons) AS Button But(1).x = 100: But(1).y = 80: But(1).x1 = 220: But(1).y1 = 95 But(1).Text = "Next Page": But(1).Page = 1 But(2).x = 100: But(2).y = 105: But(2).x1 = 220: But(2).y1 = 120 But(2).Text = "Quit": But(2).Page = 1 But(3).x = 100: But(3).y = 80: But(3).x1 = 220: But(3).y1 = 95 But(3).Text = "Last Page": But(3).Page = 2 But(4).x = 100: But(4).y = 105: But(4).x1 = 220: But(4).y1 = 120 But(4).Text = "Quit": But(4).Page = 2 Mouse "R", 0, 0 Mouse "H", 1, 319 Mouse "V", 1, 199 Mouse "P", 0, 0 CLS : SCREEN 13 Page1 SUB CheckBox (x, y, PageNum) FOR Bc = 1 TO NumOfButtons But(Bc).Pressed = 0 IF x > But(Bc).x AND y > But(Bc).y THEN IF x < But(Bc).x1 AND y < But(Bc).y1 THEN IF OutReg.BX = 1 AND (But(Bc).Page = PageNum OR (But(Bc).Page = 0 AND PageNum > 2)) THEN DrawDownButton But(Bc).x, But(Bc).y, But(Bc).x1, But(Bc).y1, But(Bc).Text Mouse "S", 0, 0 DO WHILE OutReg.BX = 1: Mouse "S", 0, 0: LOOP DrawUpButton But(Bc).x, But(Bc).y, But(Bc).x1, But(Bc).y1, But(Bc).Text Mouse "S", 0, 0: x = (OutReg.Cx / 2) + 1: y = OutReg.Dx IF x > But(Bc).x AND y > But(Bc).y THEN IF x < But(Bc).x1 AND y < But(Bc).y1 THEN But(Bc).Pressed = 1 END IF END IF END IF END IF END IF NEXT END SUB SUB DrawDownButton (x%, y%, x1%, y1%, Text$) MouseSH 2 LINE (x% + 1, y%)-(x1% - 1, y%), 0 LINE (x%, y% + 1)-(x%, y1% - 1), 0 LINE (x% + 1, y1%)-(x1% - 1, y1%), 0 LINE (x1%, y% + 1)-(x1%, y1% - 1), 0 LINE (x% + 1, y% + 1)-(x1% - 1, y1% - 1), 28, BF LINE (x% + 1, y% + 1)-(x1% - 1, y% + 1), 25 LINE (x% + 1, y% + 1)-(x% + 1, y1% - 1), 25 PSET (x% + 2, y% + 2), 25 FOR TScan = LEN(Text$) TO 1 STEP -1 IF MID$(Text$, TScan, 1) <> CHR$(32) THEN LenText = TScan: EXIT FOR NEXT Px% = (((x1% - x%) / 2 + x%) + 1) - (LenText * 8) / 2 + 1 Py% = ((y1% - y%) / 2 + y%) + 1 - 2 GPrint Px%, Py%, Text$, 0, 1 MouseSH 1 END SUB SUB DrawUpButton (x%, y%, x1%, y1%, Text$) MouseSH 2 LINE (x% + 1, y%)-(x1% - 1, y%), 0 LINE (x%, y% + 1)-(x%, y1% - 1), 0 LINE (x% + 1, y1%)-(x1% - 1, y1%), 0 LINE (x1%, y% + 1)-(x1%, y1% - 1), 0 LINE (x% + 1, y% + 1)-(x1% - 1, y1% - 1), 28, BF LINE (x% + 1, y% + 1)-(x1% - 1, y1% - 1), 31, B LINE (x1% - 1, y% + 2)-(x1% - 1, y1% - 1), 25 LINE (x% + 2, y1% - 1)-(x1% - 1, y1% - 1), 25 LINE (x% + 2, y% + 2)-(x% + 2, y1% - 2), 31 LINE (x1% - 2, y% + 2)-(x1% - 2, y1% - 2), 25 PSET (x1% - 3, y1% - 2), 25 PSET (x1% - 1, y% + 1), 25 PSET (x% + 3, y% + 2), 31 PSET (x1% - 2, y1% - 2), 25 FOR TScan = LEN(Text$) TO 1 STEP -1 IF MID$(Text$, TScan, 1) <> CHR$(32) THEN LenText = TScan: EXIT FOR NEXT Px% = (((x1% - x%) / 2 + x%) - (LenText * 8) / 2) Py% = ((y1% - y%) / 2 + y%) - 3 GPrint Px%, Py%, Text$, 0, 1 MouseSH 1 END SUB SUB GPrint (x%, y%, Text$, Culler%, Font) 'this routine allows printing text at any pixel location ' in the graphics modes without disturbing the background 'by Douglas H. Lusher, 06-08-1996 ' 8 x 8 char box, CGA IF Font = 1 THEN CharSegment% = &HFFA6: CharOffset% = &HE CharWid% = 8: CharHgt% = 8 END IF ' 8 x 14 char box, EGA 'CharSegment% = &HC000: CharOffset% = &H4ED5 'CharWid% = 8: CharHgt% = 14 ' 8 x 16 char box, VGA IF Font = 2 THEN DIM Regs AS RegTypeX Regs.AX = &H1130: Regs.BX = &H600 CALL InterruptX(&H10, Regs, Regs) CharSegment% = Regs.ES: CharOffset% = Regs.BP CharWid% = 8: CharHgt% = 16 END IF DEF SEG = CharSegment% XX% = x% FOR char% = 1 TO LEN(Text$) Ptr% = CharHgt% * ASC(MID$(Text$, char%, 1)) + CharOffset% FOR Ln% = 0 TO CharHgt% - 1 BitPattern& = PEEK(Ptr% + Ln%) * 256& LineFormat% = (BitPattern& - 32768) XOR -32768 LINE (XX%, y% + Ln%)-STEP(CharWid% - 1, 0), Culler%, , LineFormat% NEXT XX% = XX% + CharWid% NEXT DEF SEG END SUB SUB Mouse (HVSPR$, Min, Max) 'If HVSPR$ = H or V 'Sets Minimum Or Maximum Horizontal And Vertical Boundaries 'If HVSPR$ = S Then It Returns Mouse Location And Status 'If HVSPR$ = P Then It Places The Cursor Inside The Boundaries 'If HVSPR$ = R Then It Resets Mouse Status IF HVSPR$ = "R" THEN InReg.AX = 0 IF HVSPR$ = "H" THEN InReg.AX = 7: InReg.Cx = Min: InReg.Dx = Max IF HVSPR$ = "V" THEN InReg.AX = 8: InReg.Cx = Min: InReg.Dx = Max IF HVSPR$ = "P" THEN InReg.AX = 4 IF HVSPR$ = "S" THEN InReg.AX = 1: CALL INTERRUPT(&H33, InReg, OutReg) IF HVSPR$ = "S" THEN InReg.AX = 3 CALL INTERRUPT(&H33, InReg, OutReg) END SUB SUB MouseSH (Num) 'If Num = 1 Then Show Mouse Cursor 'If Num = 2 Then Hide Mouse Cursor IF Num = 2 THEN InReg.AX = 2 IF Num = 1 THEN InReg.AX = 1 CALL INTERRUPT(&H33, InReg, OutReg) END SUB SUB Page1 PageNum = 1 SetUpPage PageNum DO Mouse "S", 0, 0 x = (OutReg.Cx / 2) + 1: y = OutReg.Dx CheckBox x, y, PageNum IF But(1).Pressed = 1 THEN Page2 IF But(2).Pressed = 1 THEN END LOOP END SUB SUB Page2 PageNum = 2 SetUpPage PageNum DO Mouse "S", 0, 0 x = (OutReg.Cx / 2) + 1: y = OutReg.Dx CheckBox x, y, PageNum IF But(3).Pressed = 1 THEN Page1 IF But(4).Pressed = 1 THEN END LOOP END SUB SUB SetUpPage (PageNum) MouseSH 2: LINE (0, 0)-(320, 200), 31, BF: MouseSH 1 LOCATE 1, 1: PRINT "Page Number "; PageNum FOR Db = 1 TO NumOfButtons IF But(Db).Page = PageNum OR But(Db).Page = 0 AND PageNum > 2 THEN DrawUpButton But(Db).x, But(Db).y, But(Db).x1, But(Db).y1, But(Db).Text END IF NEXT END SUB