GRAPHICS.BAS/GRAFSUP.BAS graphics routines for QBX 7.1, by Daniel L. Nice (Updated 10/23/1999) Functions are denoted by a 'x=' in front of their name. ANIMATEBOX(x1%, y1%, x2%, y2%, xdir%, ydir%, steps%, clr%, box3d%, border%, delay!): animates a box onto the screen. x1%,y1%,x2%,y1%: coodinates for the FINISHED box. xdir%: -1 = animate the box going up, 1 = animate down, 0 = do not animate X coordinate. ydir%: -1 = animate the box going left, 1 = animate right, 0 = do not animate Y coordinate. steps%: number of STEPS to animate before arriving at the finished coodinates. clr%: box's BASE color box3d%: 1= use 3D edges, 0 = do not use 3D edges border%: 1=draw border around box, 0=do not draw border around box delay!: seconds between STEPS (usually set to .001) x=ASK(m$,opt): displays a dialogue box M$: message to be displayed OPT: 1=display Yes+ No buttons, 2=display only OK button, 3=display OK+Cancel buttons Note: Putting a || (double pipe) in the middle of M$ will cause any remaining text to be on a second line. Returns: 1 if first button is pressed, 2 if second button is pressed. x$=BIN2HEX$(binn$): returns a HEXadecimal representation of a BINary number x$=CHANGEFONT(title$, opt%): Displays window for user to select font, or builds a list of fonts in PPATH$ Title$: Name of item whose font is being changed, displayed on title-bar (omit if desired) OPT%: 0 - font can be in any directory, returns FULL drive:\path\filename to font selected 1 - font must reside in PPATH$, returns only the font filename 2 - build a list of fonts in PPATH$, then exit. Returns nothing, but list is in PPATH$\FontList.TMP with a format of the type LBITEM. x=CHECKPAS(psw$, prompt$): Prompts user for a password. PSW$: the password which is the "correct response" (not displayed) PROMPT$: message to the user, displayed above the field to enter the password. Returns: 1 = password was entered correctly, 0 = password was entered incorrectly x$=CHOP$(s$,pixel%): chops S$ to less than PIXEL% pixels. S$: string to be chopped PIXEL%: pixels to chop S$ to Returns: chopped string *Note: S$ is returned if it is already less than pixel% pixels COLORSET(object): sets color of 'object' in color-settings array CLR() object: # of color in CLR() to change x=COPY(f1$, f2$): copies file F1$ to file F2$ F1$ and F2$ must both include FULL drive:\path\filename Returns: 0 = operation was successful, 1 = operation was not successful x$=DDcur$(opt%,obj%,new$): reads and sends items to Drop-down boxes OBJ%: mouse object# of drop-down box To add an item: NEW$ - text for new item OPT% - position to add new item at (if 0, item is added to the end of the list) To read an item: NEW$ is NULL ("") OPT% - position to read (if 0, the displayed item is read) Item's text is returned. Notes: -To put an icon with an item, put the icon in then LBITEM.ICON() array. -When reading items, the icon is placed in the LBITEM.ICON() array. -To get icons from disk into LBITEM.ICON, use LOADICON (use EDITICON to draw them) x$=EDITICON$(oldicon$,md%, xx%, yy%): edits/creates icons oldicon$ - used to send an existing icon in DRAW or IDRAW (string) format, for editing MD%: 0-18x18 string icon, 1-18x16 string icon, 2-18x16 binary icon, 3-xx% by yy% string icon, 4-16x16 mouse pointer Notes: -In all modes (MD%), EDITICON returns a string-format IDRAW icon -OLDICON$ can be used as input in any mode (MD%) -In mode 2 (MD%=2), LBITEM.ICON() can also be used for binary input -In mode 2 (MD%=2), LBITEM.ICON() also stores the new icon in binary format -In all modes, icons can be saved/loaded to disk, as well as returned by the function x$=FILEDLG(opt%,filespec$,X1%,Y1%): displays a file Open/SaveAs/ChangeDir/Browse dialogue opt%: 1-Open, 2-SaveAs, 3-ChangeDir, 4-Browse (returns same as Open) filespec$ is what to start with. It can just be a wildcard (*.exe) or include a path (c:\*.exe). X1% and Y1% specify where to display the window, in pixels. Returns: a valid filename /w full filespec (modes 1,2,4), or a directory name. GINPUT(num%,ext): used to enter text into text-input field num%: ASCII # of character to display (if positive) -2: Reset field -3: Call to set new TXTACTIVE and TX -4: Called by mouse to select text ext: 0-normal character, 1-extended character *Notes: GINPUT is normally handled by MOUSE GINPUT handles TAB, curser, backspace, DEL, HOME and END keys also TX - stores last 'x' click by mouse in text field TXTACTIVE - stores mouse object # of text field that has the cursor (is active) GPRINT(d$, xx%, yy%, cl%): prints graphical text on the screen D$: string containing text to be printed XX%: left-starting position of text (in pixels) YY%: 'y' position of bottom of text (in pixels) CL%: foreground color of text *Note: To set a font other than the default, set the variable FONTNEW to a font file name in PPATH$ GRAFSAVE(nm$,opt,x1,y1,x2,y2): saves an area of the screen to disk NM$: filename.ext to save to (MUST have extension!) opt: 1-save, 2-restore+erase, 3-erase, 4-erase all, 5-save (no record), 6-restore (no record) x1,y1,x2,y2: coodinates describing area to save (can all be 0 if restoring) *Note: NM$ should NOT include a path, except for options 5 and 6 (where path is required) HELP(topic$,xx%,yy%): displays help on TOPIC$ TOPIC$: help topic xx%,yy%: preferred top-left location of the HELP window *Note: help filename is stored in the shared HELPFILE$ variable x$=HEX2BIN$(hexx$): Returns a BINary representation of a HEXidecimal number x=HOWLONG%(s$): find how long (in pixels) a string of text is S$: text to find pixel leangth of Returns: pixel leangth of S$ IDRAW(icon$,xx%,yy%,c%): Draws "DRAW" or "IDRAW" icons ICON$: DRAW/IDRAW icon (to use a file from disk, icon$="IDRAWFILE=file.drw") xx%, yy%: top, left of where to start c%: default color (only IDRAW format uses this, it specifies a value for the variable-color in the IDRAW icons) LBUPDATE(obj%,rec%): adds/removes items from list-box OBJ%: mouse object # of list-box to be updated REC%: # of item in list to be removed (first item is ONE) Items must be in the LBITEM variable if adding. LBITEM is dimmensioned as follows: i(1 to 4) as string*80 'stores items for each column icon(1 to 99) 'stores binary icon sel '0=not selected, 1=selected ord 'reserved Notes: - This function either adds a new item to the list-box, or it removes an item. If REC%=0, the item stored in LBITEM will be added. If REC%>0, item REC% will be removed If REC%= -1, all *selected* items will be removed If REC%= -2, item in LBITEM will REPLACE selected item {whose number is in MF(x,9)} If REC%= -3, item in LBITEM will be INSERTED before selected item {whose number is in MF(x,9)} -Items will be sorted according the settings in LB() array if sorting is set, and if items are added using REC%= 0 LIMITMOUSE(x1%,y1%,x2%,y2%): Limits mouse pointer to specified coordinate range *Note: The current "limits" are stored in MLX1, MLX2, MLY1, and MLY2 x=LISTBOX(opt%,obj%): draws/maintains list-boxes OPT%: 1-setup/draw list box, 2-scroll/refresh list-box, 3-process a click on list-box, 4-select all, 5-deselect all, 6-fake a click on list-item MF(obj%,9), 7-load item MF(obj%,9) into LBITEM. OBJ%: mouse object # of list-box Uses a shared array: LB(x,y) {an integer array} X: a number 0-3, the list-box # (NOT same as mouse object #) Y: a number 0-10, list-box options (however, user only sets positions 0-5) lb(x,0) - top TEXT row (y1) {-1 to use MF pixil settings} lb(x,1) - left TEXT column (x1) lb(x,2) - bottom TEXT row (y2) lb(x,3) - right TEXT column (x2) lb(x,4) - allow selection (0-no, 1-always one, 2-none through all, 3-one or less) lb(x,5) - for auto-program scrollbar+buttons: -1, otherwise: scrollbar's mouse object # *lb(x,6) - top displayed row *lb(x,7) - previous top row *lb(x,8) - previous selection *lb(x,9) - # items in list lb(x,10)- # items displayed at a time (user only needs to set if lb(x,0)=-1 ) lb(x,11)- # columns of text lb(x,12)- pixels from the left to start col #1 lb(x,13)- " " col #2 lb(x,14)- " " col #3 lb(x,15)- " " col #4 lb(x,16)- pixels from left to display icons (0 for none) lb(x,17)- sort by which col (1-4), or 0 for no sort *lb(x,18)- total # of items selected lb(x,19)- use separator lines (0-no, 1-yes, 2-yes & user can move them) lb(x,20)- which mouse button can be used to select items (0-all, 1-left, 2-right, 3-both) Notes: -See section on setting up array MF() which must also be done. -If you set LB(x,4) to -1 (auto-set scrollbar), you MUST leave 3 mouse-object positions before list-box object. (i.e. if the list-box object # if 14, then #'s 11-13 will be used for scrollbar+buttons) -MF(x,0)-MF(x,3) are auto-set for list-box objects, unless LB(x,0)= -1. -If you use MF() to specify list-box position, scrolling will be much slower -Use the LBUPDATE sub to add/remove items from a list-box. *these are set by MOUSE or LISTBOX, not user LOADICON(cmd%,file$): loads (or saves) a binary icon from disk into LBITEM.ICON() CMD%: 1-load from disk, 2-save to disk FILE$: binary file to read from/write to, includes full path. x=MOUSE(mf%): draws/manages mouse objects, polls keyboard MF%: 0-normal check (use to poll, auto unhide), 1-initialize mouse, 2-hide mouse pointer 3-refresh objects w/o poll, 4-unhide w/o poll, -{mouse object type #} marks as unrefreshed *Note: you MUST setup the MF array, see end of this document. Mouse is automatically un-hidden on next x=MOUSE(0) call. POINTER(file$,h%,v%): loads a custom mouse-pointer from disk FILE$: filename to load from (do NOT specify path, PPATH$ is assumed) H%: horizontal "hot-spot" V%: vertical "hot-spot" *Note: set MPOINTER to a number>51 to keep the new pointer, set MPOINTER to 51 to reset. x=POPUP(title$): displays a popup menu at current mouse-pointer location TITLE$: an optional title for the menu, displayed as a title-bar on the menu (specify "" for none) Returns: the position in POP$ that was selected, or -1 if none was selected *Note: The shared array POP$(20) must contain the items for the menu, starting at item 0 x=PULLDOWN%(obj, opt, num): displays pull-down menus OBJ: # of mouse object in MF() containing menu-bar OPT: 1-draw menu-bar, otherwise process click on the menu-bar NUM: menu # in PULLDOWN(#,y) to display, or -1 to process click *Note: this sub returns results in 2 shared variables: MNUNUM=menu # that was selected (-1 if none) MNUITM=item on menu # that was selected (-1 if none) Pull-down menus are stored in the MNUBAR$(10,20) & MNUBAR%(10) (That is: mnubar$(menu#, item#) & mnubar%(menu#) ) item# 0 is the menu's title, and cannot be selected. mnubar% stores X locations of menu-titles on the menu-bar, set by MOUSE Note: This function is called directly only to manually activate menus. Normally, MOUSE does this. x$=REPLACE$(s1$,s2$,s3$): replaces every occurrence of S1$ in S2$ with S3$, returns X$ as a result SAVEINI: saves INI file specified in variable INIFILE$ to disk with current settings SAVEMOUSE(nm$,opt): saves mouse overlay to file nm$ NM$: file to save to (NO EXTENSION!) opt: 1-save, 2-restore, 3-erase, 4-restore w/o erase, 5-erase all, 6-mark object type "NM$" as unrefreshed, 7-save to disk w/o record, 8-retrieve from disk w/o record Note: OPT 7&8 are for saving/retrieving mouse overlays that need to be saved even after the program quits, and loaded next time it runs x=SCROLLBAR(cmd%,item%): draws/maintains scrollbar(s) cmd% is used as follows: 1-draw scrollbar according to MF(item%,x) {done by MOUSE} 2- make scrollbar MF(item%,x) active {done by MOUSE} 3-set scrollbar MF(SCRACTIVE,x) to position ITEM% 4-return new position for MF(SCRACTIVE,x) based on mouse *Note: SCRACTIVE is a shared variable that = active scrollbar's object number SETMOUSE(xx%,yy%): places mouse at specified coodinates x$=SP$(file$): searches DOS PATH for FILE$ Returns: Full {drive:}\{path}\FILE$ (if found), OR returns NULL string if not found (""). x$=STATUSBARHELP$(file$, item%): returns text for quick-help displayed on a status-bar (used in a polling loop) File$: name of sequential file to get text from, of the following format: (object #, can be 0-50) (text for object) (object #) (text) {and so on....} Item%: number of object to return text for Below describes how to set the mouse-object arrays, which tells the MOUSE sub how to draw/poll graphical objects The Common Shared arrays MF, DAT$, and KY store mouse-objects. Use this format for them: MF(x,y), DAT$(x), KY(x) X = the object number, up to 51 objects per mouse-overlay (0-50) Y = parameters for each object, used as follows: MF(x,0) = 'X1' coordinate of object 'left MF(x,1) = 'Y1' coordinate of object 'top MF(x,2) = 'X2' coordinate of object 'right MF(x,3) = 'Y2' coordinate of object 'bottom MF(x,4) = mouse button to check for, which can be any of the following: 0 - check for ALL buttons (variable B stores which was used) 1 - check for LEFT mouse button 2 - check for RIGHT mouse button MF(x,5) = return number (is returned by MOUSE when this object is clicked) MF(x,6) = type of click to check for, can be any of the following: 0 - register on press on object (Note! This event isn't stored in MEVENT. MEVENT=0 means NO event) 1 - register on press+release on object (use for buttons) 2 - register on press+move off object 3 - register on press+release OR press+move off 4 - register on press+release OR hold down for >1/2 second (used for pop-up menus) 5 - register on double-click 6 - register on pointer over object (no press) 7 - register on pointer over object OR press on object *Notes: -for settings that allow multiple events, check the MEVENT variable to see which actually occurred. -to make an object respond to the pointer being over it AND another event, use the negative event # MF(x,7) = type of object (mouse sub draws objects) 0 - INVISIBLE object, mouse sub draws nothing 1 - button object 2 - drop-down box and button (uses DRPDWN$(5,1), see below) 3 - text-input object (accepts user-input and/or displays text) 4 - scrollbar 5 - scrollbar button (must be associated /w scrollbar) 6 - title-bar 7 - window-shadow 8 - label 9 - window 10 - Line/Box 11 - check box 12 - menu-bar (uses MNUBAR$(10,20) and MNUBAR%(10)) 13 - list-box (uses LB(3,10)) 14 - status-bar MF(x,8) = additional options on object. If MF(x,7)=0 then save to file (0-no, 1-yes) If MF(x,7)=1 then # of pixels to right of left-side of button to print text from (leave 0 for auto-center) If MF(x,7)=2 then # 'x' in DRPDWN%(x,1) {tells which menu} If MF(x,7)=3 then # of letter that is shown at the left-most side of the text field (1 if field contains no text) If MF(x,7)=4 then # of positions on scrollbar (i.e. number of items in list) If MF(x,7)=5 then # of scrollbar mouse-object If MF(x,7)=6 then # of character that BOLD text starts at (0 for normal) If MF(x,7)=8 then (0-normal text, 1-bold text) If MF(x,7)=10 then (0-line, 1-box, 2-filled box, 3-filled box/w border) If MF(x,7)=11 then (0-not checked, 1-checked) If MF(x,7)=13 then # of 'x' in LB(x,19) {list-box #, can be 0-3} If MF(x,7)=14 then # of pixels to right to start text (or 3D indent), -1 for center MF(x,9) = more additional options on object If MF(x,7)=1 then (0-button /w text, 1-button /w icon) If MF(x,7)=2 then # of displayed item (use DDcur$ to read item) If MF(x,7)=3 then (0-text modifiable, 1-text field is static, 2-text NOT modified by MOUSE sub, but still modifiable by calling GINPUT, 3-text modifiable but length is limited text field's width) If MF(x,7)=4 then # of current position If MF(x,7)=8 then COLOR for TEXT (0 - default color, -17 - black, -{# of 'color'} use 'color') If MF(x,7)=10 then # of COLOR for line/box; # of FILL COLOR for filled box (uses def. border color) If MF(x,7)=11 then check-box width (w/o label), set by MOUSE sub If MF(x,7)=13 then # of current selection, 1st item is 1 (which item in list-box is highlighted), 0 for none If MF(x,7)=14 then use 3D indent (0-no | 1-yes) MF(x,10) = refresh -1 - object x was recently refreshed 0 - object x does NOT need to be refreshed 1 - object x NEEDS to be refreshed Note: setting a Window object to 1 will cause ALL objects to re-draw, setting any other object to 1 will cause only that object to be re-drawn. DAT$(x) stores string-data for mouse-objects. If MF(x,7)=1 then TEXT or ICON (in DRAW format) for button If MF(x,7)=2 then FILENAME (no path!) to use for drop-down box (ppath$ is assumed path) If MF(x,7)=3 then TEXT for text-input field If MF(x,7)=6 then TEXT for title-bar If MF(x,7)=8 then TEXT for label If MF(x,7)=10 then "object-type alias" {used to keep this object's color the same as aliased object-type} If MF(x,7)=11 then TEXT for check-box label If MF(x,7)=13 then FILENAME (no path!) to use for list-box (ppath$ is assumed path) If MF(x,7)=14 then TEXT for status-bar KY(x) stores a STRING for a key equivalent to clicking on object 'x' Common Shared variables: BRD - (Button ReDraw). Set to 1 after changing mouse-overlay. This tells the mouse sub to draw mouse-objects A better method is to set the window object's position 10 to (1) X - last 'x' coordinate mouse clicked on Y- last 'y' coordinate mouse clicked on B- button # used for the click (used if MF(x,4)=0 to check for button) D$ - any keystrokes that MOUSE could not handle MEVENT - stores the last MOUSE event that occurred (see section on MF(x,6) for the numbers) TXTEX - stores characters (string) that are NOT allowed to appear in text-input fields (concatenate them) LBACTIVE - stores mouse-object # of active list-box FONTNEW - reset this variable to a font file in PPATH$ to change the font for the next text operation (i.e. GPRINT) MENU95 - set to (1) if you want sticky menus, like Win95. This is saved in GRAPHICS.INI. MENU3D - set to (1) if you want 3D menu-highlighting. This is saved in GRAPHICS.INI FASTSCROLL - set to (1) to remove the slight delay when scrolling list-boxes. (stored in GRAPHICS.INI) INIFILE$ - set to the filename to be used for INI file (NO PATH) HELPFILE$ - set to the filename to be used for the help file (NO PATH) PPATH$ - variable is set by LOADINI to the location INIFILE$ is found at (current directory or in path) TEMPATH$ - variable is set to the TEMP environment variable (if it exists), or set to PPATH$ DRPDWN(5,1) stores additional parameters for drop-down boxes. mf(x, 8) tells which position to use (0-5) drpdwn(y,0) - use icons (0-no, 1-yes) drpdwn(y,1) - # of displayed rows at a time (min of 3, max of 24) drpdwn(y,2) - display text-search field (0-no, 1-yes) Note: DO NOT poll the keyboard with INKEY$! MOUSE polls the keyboard, and puts any non-handled keystrokes in the shared D$ variable. MOUSE will send text to text-input fields (unless told otherwise, see above) MOUSE will activate objects who have a keyboard equivalent stored in KY() (see above) In many cases, D$ does not even need to be checked, only MOUSE must be polled. This file goes with DEMO-DS2.BAS, GRAPHICS.BAS/.BI, GRAF-SUP.BAS, & SYSUTILS.BI/.QLB/.LIB DEMO-DS2.BAS -- an example program to demonstrate graphics routines. GRAPHICS.BAS -- graphics routines usable by any program GRAF-SUP.BAS -- more graphics routines GRAPHICS.BI, SYSUTILS.BI -- declarations files, MUST be '$INCLUDE 'ed in ALL modules that use graphics routines. The Graphics Routines store QBX color values for objects in the array CLR(). Use the COLORSET() sub to allow the user to change the values in CLR(). The Graphics Routines store font settings in the array OBJFONT(). Use the CHANGEFONT sub to return new filenames to place in the OBJFONT() array. Below are tables listing what each position in these arrays store. Color Settings Array Positions: clr(0) - Title Bar Background clr(1) - Title Bar Text clr(2) - List Box Background clr(3) - List Box Foreground clr(4) - List Box Highlight clr(5) - List Box Highlight Text clr(6) - Menu Background clr(7) - Menu Text clr(8) - Menu Highlight clr(9) - Menu Highlight Text clr(10) - Main Background clr(11) - Dialogue Background clr(12) - Dialogue Text clr(13) - Text Input Background clr(14) - Text Input Foreground clr(15) - Window Shadow clr(16) - Button Background clr(17) - Button Text clr(18) - Object Border clr(19) - Help Text Background clr(20) - Help Text Foreground clr(21) - Help HyperText clr(22) - Scrollbar Background clr(23) - Window Background clr(24) - Window Text clr(25) - Status Bar Background clr(26) - Edit Icon Background clr(27) - Status Bar Text Font Settings Array Positions: objfont(0) - Help-Text font objfont(1) - Button font objfont(2) - Drop-Down box font objfont(6) - Title-Bar font objfont(8) - Window-Text font objfont(11) - Check-Box font objfont(12) - Menu/Menu-Bar font objfont(13) - List-Box font objfont(14) - Status-Bar font QBX Color Values: 0 - Black 1 - Blue 2 - Green 3 - Cyan 4 - Red 5 - Violet 6 - Brown 7 - Gray 8 - Dark Gray 9 - Light Blue 10 - Light Green 11 - Light Cyan 12 - Light Red 13 - Light Violet 14 - Yellow 15 - White