'=========================================================================== ' Subject: GUI LIBRARY V1.23 W/DOCS Date: 10-25-96 (14:07) ' Author: Tika Carr Code: QB, PDS ' Origin: itaiya@juno.com Packet: EGAVGA.ABC '=========================================================================== ===================== GUI Interface Programmer's Library v 1.23 Docs GUI Interface Programmer's Library v. 1.23 for QuickBasic 4.5 8/9/96 Copyright 1996 by Tika Carr These routines use the QB.QLB library. I put everything you need into one file, which is also a demo of some of the things that the GUI routines can do. CALL Mouse(x) x = 0 Initialize Mouse, 1 Show Mouse, 2 Hide Mouse, 3 Get mouse information You MUST CALL Mouse(0) to start the mouse. Then CALL Mouse(1) to show the mouse. mx, my is the mouse coordinates and mb is the mouse button, if you use CALL Mouse(3). These are global variables defined in GUI.BI. CALL gprint ("Text", x, y, color) This routine lets you print text on screen according to pixel location. Put the Text in quotes. X and Y are Pixel locations, not LOCATE locations, so you can go x up to 640 and Y up to 480. color is from 0 to 15 (standard VGA colors). See GUI.BI for more info on Palettes and Colors. Buttons, Pop Up Menus, Frames, Check Boxes, Radio Buttons: CALL drwbtn (style, color, frame offset, frame color, x1, y1, x2, y2) | | | | | | -------- --------------- ------------- Inside Outside Coordinates of button/frame of frame 3-D Push Buttons: Style 1 and Style 2 are for making those push buttons like "OK" or "Escape", etc. Style 1 is a pushed in button, and Style 2 is a normal button. CALL drwbtn(1, 3, 0, 0, 3, 3, 55, 18) 'Button is pushed (selected). CALL drwbtn(2, 3, 0, 0, 75, 3, 121, 18) 'Button is not pushed. Note that the frame offset and color values are not used for push buttons. Framed Pop-Ups: There are four styles of framed popup type windows that give a 3-D look: CALL drwbtn(3, 6, 10, 5, 3, 25, 103, 125) 'Frame Style 3 (On/Off) CALL drwbtn(4, 3, 10, 2, 110, 25, 210, 125) 'Frame Style 4 (Off/On) CALL drwbtn(5, 8, 10, 7, 220, 25, 320, 125) 'Frame Style 5 (On/On) CALL drwbtn(6, 11, 10, 10, 340, 25, 440, 125)'Frame Style 6 (Off/Off) Style 3: Inlaid frame with embossed interior. Style 4: Embossed frame with inlaid interior. Style 5: Inlaid frame and interior. Style 6: Embossed frame and interior. Note that we used an offset of 10 in the above 4 examples. This gives us a nice frame boarder. You can set this at any size in pixels that you wish. The color value after style is the color of the interior and the color value after frame offset is the color of the surrounding frame. The other values are the upper left and lower right corners of the entire pop up. Check Boxes: Styles 7 and 8 create check boxes: CALL drwbtn(7, 4, 0, 0, 3, 135, 18, 150) 'Plain Check Box CALL drwbtn(8, 4, 0, 0, 23, 135, 38, 150) 'Plain Check Box Checked Note again that the frame values are not used. Radio Buttons: Radio buttons use the values a bit differently from the others. They are: drwbtn(style, color, radius, center mark color, x, y, nul, nul) Styles 9 and 10 provide you with the standard circular radio buttons: CALL drwbtn(9, 9, 8, 0, 50, 143, 0, 0) 'Radio Button CALL drwbtn(10, 9, 8, 15, 70, 143, 0, 0) 'Radio Button On The center mark color is the color of the dot that goes in the center of a selected radio button. Only the x and y coordinates are needed, and the other x and y parameters are 0 (not used). Popup Input Box: (New for Version 1.23) PopInp(Prompt$, T2Len, x1, y1, CurClr) Prompt$ is what you'd like to ask the user. T2Len is the maximum amount of characters you will allow in the input field. x1 and y1 are the upper left corner coordinates. CurClr is the color of the cursor. Example: CALL PopInp("Do You Really Want To Quit?", 1, 160, 120, 3) I think I'll stop here with the GUI project, due to the fact I just don't have time to develop it much further. Of course, anyone is invited to add to it. Hopefully this was a start. This code is usable by anyone who wishes, as long as they give credit to the proper people in their program code and in the on-screen of the finished product (ie. in an "About" menu). The code in this library is not for commercial use. Tika Carr 1:2613/601 CREDITS: All routines written by Tika Carr, except the GPrint routine, which was written by Douglas Lusher. ================= GUI Interface Programmer's Library v. 1.23 Source Code 'GUI123.BAS 8/9/96 'GUI Interface Programmer's Library v. 1.23 'for QuickBasic 4.5 'Copyright 1996 by Tika Carr 'Contact: 'Tika Carr 1:2613/601 'kari@rochgte.fidonet.org DECLARE SUB clrscrn (clr%) DECLARE SUB drwbtn (ds%, dc%, dfs%, dfc%, dx1%, dy1%, dx2%, dy2%) DECLARE SUB gprint (z$, x%, y%, c%) DECLARE SUB Mouse (a%) DECLARE SUB PopInp (Prompt$, T2Len%, x1%, y1%, CurClr%) '$INCLUDE: 'qb.bi' COMMON SHARED mb%, mi%, mt%, mx%, my% 'mouse variables COMMON SHARED black%, white% 'used for palette COMMON SHARED T2$ 'PopInp results DIM SHARED Inregs AS RegType, Outregs AS RegType 'Interrupt DIM SHARED Regs AS RegTypeX 'InterruptX SCREEN 12: CLS '640 x 480 16 color VGA 80 x 30 text '** PALETTE ASSIGNMENT ** ' Color 0 and Color 15 are system colors (black and white) and should ' not be changed as they are used for buttons and such. black% = 0: white% = 15 DEFINT A-Z WIDTH 80, 60 'Clear the screen to color #3 (Cyan) CALL clrscrn(3) 'Change white to be 7, causing the boarder highlight to be grey 'instead of white. Change the menu bar to be white, then draw menu 'bar, and change white back to color #14 (white) white = 7 CALL drwbtn(2, 15, 0, 0, 0, 0, 639, 20) white = 15 'The "Exit" box in the upper left. CALL drwbtn(2, 7, 0, 0, 2, 2, 18, 18) CALL gprint("X", 6, 4, 0) 'The "Help" box in the upper right. CALL drwbtn(2, 7, 0, 0, 619, 2, 637, 18) CALL gprint("?", 624, 4, 0) 'Menu Options CALL gprint("File", 55, 3, 0) CALL gprint("Edit", 107, 3, 0) ' A boxed frame text box CALL drwbtn(4, 9, 10, 1, 10, 30, 629, 459) ' Some text in the box a$(1) = "Here is an example of some things you can do in the GUI interface." a$(2) = "I want to thank Douglas H. Lusher for his help in writing the gprint" a$(3) = "routine. He developed a faster way to print text on the screen. This" a$(4) = "routine does what the PRINT statement can't: Prints text virtually" a$(5) = "anywhere on the screen, and transparently over the graphics." y = 34 FOR g = 1 TO 5 y = y + g + 16 CALL gprint(a$(g), 32, y, 14) NEXT g Start: 'Loop to trap mouse events CALL Mouse(0) 'initialize mouse CALL Mouse(1) 'show mouse WHILE mb = 0 'trap events CALL Mouse(3) LOCATE 60, 1 PRINT mx, my, mb; WEND 'The "Exit" box in the upper left clicked on. IF mx > 2 AND my > 3 AND mx < 18 AND my < 18 THEN CALL Mouse(2) 'hide mouse CALL drwbtn(1, 7, 0, 0, 2, 2, 18, 18) CALL gprint("X", 6, 4, 0) FOR delay = 1 TO 30000: NEXT CALL drwbtn(2, 7, 0, 0, 2, 2, 18, 18) CALL gprint("X", 6, 4, 0) CALL PopInp("Do You Really Want To Quit?", 1, 160, 120, 3) IF LCASE$(T2$) = "n" THEN RUN ELSE END END IF GOTO Start SUB clrscrn (clr%) LINE (0, 0)-(639, 479), clr%, BF END SUB SUB drwbtn (ds, dc, dfs, dfc, dx1, dy1, dx2, dy2) IF ds >= 3 AND ds <= 6 THEN c = dfc ELSE c = dc SELECT CASE ds CASE 1: GOSUB dOn CASE 2: GOSUB dOff CASE 3: GOSUB dOn: GOSUB Inside: GOSUB dOff CASE 4: GOSUB dOff: GOSUB Inside: GOSUB dOn CASE 5: GOSUB dOn: GOSUB Inside: GOSUB dOn CASE 6: GOSUB dOff: GOSUB Inside: GOSUB dOff CASE 7: GOSUB Dsqu CASE 8: GOSUB Dsqu LINE (dx1, dy1)-(dx2, dy2), black% LINE (dx1, dy2)-(dx2, dy1), black% CASE 9: GOSUB Dcir CASE 10: GOSUB Dcir CIRCLE (dx1, dy1), (15 - dfs) \ 2, dfc PAINT (dx1, dy1), dfc, dfc END SELECT GOTO Ddone Dsqu: LINE (dx1, dy1)-(dx2, dy2), black%, B PAINT (dx2 - 4, dy2 - 4), c, black% RETURN DBold: GOSUB Dsqu LINE (dx1 + 1, dy1 + 1)-(dx2 - 1, dy2 - 1), black%, B RETURN dOn: GOSUB DBold LINE (dx1 + 1, dy2 - 1)-(dx2 - 1, dy2 - 1), white% LINE -(dx2 - 1, dy1 + 1), white% RETURN dOff: GOSUB DBold LINE (dx1 + 1, dy2 - 1)-(dx1 + 1, dy1 + 1), white% LINE -(dx2 - 1, dy1 + 1), white% RETURN Dcir: CIRCLE (dx1, dy1), dfs, black% PAINT (dx1, dy1), dc, black% RETURN Inside: dx1 = dx1 + dfs: dy1 = dy1 + dfs dx2 = dx2 - dfs: dy2 = dy2 - dfs c = dc RETURN Ddone: dx1 = dx1 - dfs: dy1 = dy1 - dfs dx2 = dx2 + dfs: dy2 = dy2 + dfs END SUB SUB gprint (z$, x%, y%, c%) Regs.ax = &H1130 Regs.bx = &H600 CALL INTERRUPTX(&H10, Regs, Regs) CharSegment% = Regs.es: CharOffset% = Regs.bp CharWid% = 8: CharHgt% = 16 DEF SEG = CharSegment% XX% = x FOR Char% = 1 TO LEN(z$) Ptr% = CharHgt% * ASC(MID$(z$, 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), c, , LineFormat% NEXT XX% = XX% + CharWid% NEXT DEF SEG END SUB SUB Mouse (a%) Inregs.ax = a% CALL INTERRUPT(&H33, Inregs, Outregs) mb = Outregs.bx 'button 0 = off 1 = left 2 = right mx = Outregs.cx 'x coordinate my = Outregs.dx 'y coordinate mi = Outregs.ax 'init (dummer variable) END SUB DEFSNG A-Z SUB PopInp (Prompt$, T2Len%, x1%, y1%, CurClr%) IF LEN(Prompt$) > T2Len% THEN PBoxLen = LEN(Prompt$) ELSE PBoxLen = T2Len% x2% = x1% + (PBoxLen + 2) * 8: y2% = y1% + 64: nx = x1%: ny = y1% CALL Mouse(2) BitsPerPixel = 1: planes = 4 'Screen Mode 12 Ary% = 4 + INT(((x2% - x1% + 1) * (BitsPerPixel) + 7) / 8) * planes * ((y2% - y1%) + 1) DIM VScreen(1 TO Ary%) GET (x1%, y1%)-(x2%, y2%), VScreen CALL drwbtn(2, 7, 0, 0, x1%, y1%, x2%, y2%) x1% = x1% + 8 CALL gprint(Prompt$, x1%, y1% + 8, 0) Inloop: y1% = y1% + 32 'Input Field CALL gprint(">", x1%, y1%, 0) CALL gprint(STRING$(T2Len%, 219), x1% + 8, y1%, 15) '** Turn on and show cursor x1% = x1% + 8 cursor$ = CHR$(219) CALL gprint(cursor$, x1%, y1%, 4) '** Get Input and move cursor T2$ = "" 1 T1$ = INKEY$: IF T1$ = "" THEN 1 'wait for keypress st = ASC(T1$) 'Backspace and erase IF st = 8 THEN 'checks to make sure its in field x1% = x1% - 8: IF x1% < nx + 16 THEN x1% = nx + 16: GOTO 1 CALL gprint(cursor$, x1% + 8, y1%, 15) CALL gprint(RIGHT$(T2$, 1), x1%, y1%, 0) CALL gprint(cursor$, x1%, y1%, 4) 'subtracts deleted character from string IF LEN(T2$) >= 1 THEN T2$ = LEFT$(T2$, LEN(T2$) - 1) GOTO 1 END IF IF T1$ = CHR$(13) THEN GOTO 2 'End of input when ENTER is pressed. IF st < 32 OR st > 127 THEN BEEP: GOTO 1 'check for illegal character 'Character ok, add to string, move cursor T2$ = T2$ + T1$ CALL gprint(cursor$, x1%, y1%, 15) CALL gprint(T1$, x1%, y1%, 0) x1% = x1% + 8 'checks to make sure its in field IF x1% > (nx + T2Len% * 8 + 8) THEN BEEP: GOTO 1 CALL gprint(cursor$, x1%, y1%, 4) 'Get more input GOTO 1 2 'Erase menu, restore what was underneath PUT (nx, ny), VScreen, PSET ERASE VScreen CALL Mouse(1) END SUB