home *** CD-ROM | disk | FTP | other *** search
-
- (*****************************************************************)
- (** **)
- (** File Name : VDIDMO.DMO **)
- (** **)
- (** Purpose **)
- (** Sample application program to demonstrate the use of **)
- (** the GEM Virtual Device Interface bindings from TURBO **)
- (** PASCAL. **)
- (** **)
- (** Comments **)
- (** This program is designed to run as a VDI only **)
- (** application. It assumes that the system is using **)
- (** a mouse. Non-mouse systems will need to modify **)
- (** the procedure do_prompt. **)
- (** **)
- (** All VDI interface ARRAYs are relative to 0 here **)
- (** so coords should match GEM VDI programmers manual **)
- (** **)
- (** Uses RC coordinate mapping (MODE 2 on open) **)
- (** **)
- (** To run : Load GEM VDI and execute **)
- (** DMOVDI from DOS prompt **)
- (** **)
- (** Author : Athol M. Foden **)
- (** History : Oct 1984 **)
- (** Modified by : James Taaffe and JoAnn Yang **)
- (** of the Mass. General Hospital **)
- (** in Jun 1985. **)
- (** **)
- (** **)
- (*****************************************************************)
- (*****************************************************************)
-
- PROGRAM gemvdi;
-
- {$IPasvdi.bnd}
-
- VAR
- (* local variables for this program *)
-
- handle : INTEGER; (* handle of the active driver *)
- workin : intin_ARRAY; (* initial values for open *)
- workout : ARRAY_57; (* functions of driver *)
- pxy : ptsin_ARRAY; (* general array of input coords *)
- xyarray : ARRAY_4; (* corner coords array typically *)
- totalfonts : INTEGER; (* total # fonts avail for WS *)
- afont : ARRAY[1..20] OF INTEGER; (* font ids for all active ones *)
- crt : BOOLEAN; (* true if a crt WS *)
- done : BOOLEAN; (* main loop terminator *)
- xmax, ymax : INTEGER; (* max pixels in x,y direction for W-S*)
- ret : INTEGER; (* dummy return param *)
- x, y : ARRAY[1..20] OF INTEGER; (* convenient ratios for coords *)
- i,j,k,l : INTEGER; (* work integers *)
-
-
- (******************************************)
- (** initialize requested graphics device **)
- (******************************************)
-
- PROCEDURE init_gvdi;
-
- VAR
-
- i : INTEGER;
- inchar : CHAR;
- name : STRING80;
- BEGIN
-
- FOR i:=0 TO intin_max DO workin[i]:=1; (* Initial defaults used *)
- FOR i:=0 TO intout_max DO workout[i]:=0; (* make sure flushed first *)
- REPEAT
- WRITELN; WRITELN;
- WRITELN(' PASCAL MT+ DEMO PROGRAM');
- WRITELN;
- WRITELN(' Select Graphics Output Device : ');
- WRITELN(' 1 = Screen (B&W)');
- WRITELN(' 2 = Screen (Color)');
- WRITELN(' 3 = Printer');
- WRITELN(' 4 = Plotter');
- WRITELN(' 5 = Camera');
- WRITELN;
- WRITE(' Selection ? : ');
- READ(inchar);
- UNTIL inchar IN ['1'..'5']; (* valid char ? *)
- crt:=FALSE; (* not a crt driver yet *)
- IF inchar = '1' THEN BEGIN
- workin[0]:=1; (* device driver - B&W *)
- crt:=TRUE;
- END
- ELSE IF inchar = '2' THEN BEGIN
- workin[0]:=2; (* color *)
- crt:=TRUE;
- END
- ELSE IF inchar = '3' THEN workin[0]:=21 (* printer *)
- ELSE IF inchar = '4' THEN workin[0]:=11 (* plotter *)
- ELSE workin[0]:=41; (* camera *)
-
- workin[10]:=2; (* use RC space system *)
- ret:=v_opnwk(workin,handle,workout); (* pascal open workstation *)
- totalfonts:=workout[10]; (* total no. of font faces in driver *)
- xmax:=workout[0]; (* max width in RC space *)
- ymax:=workout[1]; (* max height *)
- FOR i:=1 TO 20 DO BEGIN (* handy ratios of sides *)
- x[i]:=(xmax DIV 20) * i; (* 1/20 increment in x drctn *)
- y[i]:=(ymax DIV 20) * i; (* 1/20 in y direction *)
- END;
-
- totalfonts:=totalfonts + vst_load_fonts(handle,0);
- (* load extra fonts if any *)
- FOR i:=1 TO totalfonts DO BEGIN (* for all avail fonts *)
- afont[i]:=vqt_name(handle,i,name); (* find & save font ID *)
- END;
- END;
-
- (******************************************)
- (** general point fonts text routine **)
- (******************************************)
-
- PROCEDURE do_text(x, y, dface, psize, color, effects : INTEGER;
- tstring : STRING80);
- BEGIN
- ret:=vst_font(handle,dface); (* choose the face reqd *)
- ret:=vst_point(handle,psize,i,j,k,l); (* set cell height points mode *)
- (* returned char and cell heights and widths ignored here *)
- ret:=vst_effects (handle, effects); (* set graphic text effects *)
- ret:=vst_color(handle,color); (* set color *)
- ret:=v_gtext(handle,x,y,tstring); (* text output *)
- END;
-
- (*******************)
- (** draw dri logo **)
- (*******************)
-
- PROCEDURE dri_logo;
- VAR
- xyarray : ARRAY_4;
- BEGIN
- (* inside left solid rectangle *)
- xyarray[0]:=x[3];
- xyarray[1]:=y[9];
- xyarray[2]:=x[4];
- xyarray[3]:=y[5];
- ret:=vsf_color(handle,red); (* in black *)
- ret:=vsf_interior(handle,solid); (* solid fill style ? *)
- ret:=vswr_mode(handle,replace); (* draw in replace mode *)
- ret:=v_rfbox(handle,xyarray); (* filled rounded box *)
-
- ret:=vsl_type(handle,solid); (* solid lines please on open rectangles *)
- (* outide rounded rectangle *)
- xyarray[0]:=x[2]; (* lower left x coordinate *)
- xyarray[1]:=y[10]; (* lower left y coordinate *)
- xyarray[2]:=x[7]; (* top right x *)
- xyarray[3]:=y[4]; (* top right y *)
- ret:=vsl_width(handle,6); (* line width 6 *)
- ret:=vsl_color(handle, red); (* color of lines *)
- ret:=v_rbox(handle,xyarray); (* rounded open box line attr *)
- (* inside little open rectangle *)
- xyarray[0]:=x[5];
- xyarray[1]:=y[9];
- xyarray[2]:=x[6];
- xyarray[3]:=y[5];
- ret:=vsl_width(handle,3); (* narrower lines now - same color *)
- ret:=v_rbox(handle,xyarray); (* open rectangle *)
- END;
-
- (***************************************************************)
- (** draw a border around the "artwork" - a polyline operation **)
- (***************************************************************)
-
- PROCEDURE draw_border;
- BEGIN
- pxy[0]:=x[1]; (* top left of WS - center of lne*)
- pxy[1]:=y[1];
- pxy[2]:=x[20]; (* top right of ws *)
- pxy[3]:=y[1];
- pxy[4]:=x[20]; (* bottom right *)
- pxy[5]:=y[20];
- pxy[6]:=x[1]; (* bottom left *)
- pxy[7]:=y[20];
- pxy[8]:=x[1]; (* back to square one *)
- pxy[9]:=y[1];
- ret:=vsl_type(handle,solid); (* solid line style *)
- ret:=vsl_color(handle,cyan); (* in cyan please *)
- ret:=vsl_width(handle,6); (* fat line - 6 coords wide *)
- ret:=v_pline(handle,5,pxy); (* draw the 5 coord polyline *)
- END;
-
- (***************************)
- (** draw dri name with tm **)
- (***************************)
-
- PROCEDURE draw_name;
- BEGIN
- do_text(x[9],y[4],afont[2],20,green,bold,'DIGITAL'); (* font 2 in bold *)
- do_text(x[9],y[7],afont[2],20,green,bold,'RESEARCH');
- do_text(x[16],y[5],afont[1],10,yellow,light,'TM'); (* light TM in small *)
- END;
-
- (**************************************)
- (** Use new GDP function for ellipse **)
- (**************************************)
-
- PROCEDURE draw_ellipse;
- BEGIN
- ret:=vsf_interior(handle,pattern); (* patterned ellipse *)
- ret:=vsf_color(handle,yellow); (* in yellow *)
- ret:=v_ellipse(handle,x[17],y[17],x[2],y[1]); (* draw ellipse *)
- END;
-
- (*******************************************************)
- (** Bitblt - Use rastor ops to copy ellipse instantly **)
- (*******************************************************)
-
- PROCEDURE copy_ellipse;
- VAR
- i : INTEGER;
- srcM, destM : MFDB; (* source and destination MFDB's *)
- pxy8 : ARRAY_8;
- BEGIN
- srcM.mptr.hi:=$0000; (* long addr zero for source MDFB *)
- srcM.mptr.lo:=$0000; (* as it is physical device *)
- destM.mptr.hi:=$0000; (* long addr zero for source MDFB *)
- destM.mptr.lo:=$0000;
- pxy8[0]:=x[14]; (* pick up rectangle with ellipse in *)
- pxy8[1]:=y[16];
- pxy8[2]:=x[19];
- pxy8[3]:=y[18];
- pxy8[4]:=x[14]; (* and put it down here *)
- pxy8[5]:=y[8];
- pxy8[6]:=x[19];
- pxy8[7]:=y[10];
- ret:=vro_cpyfm(handle,3,pxy8,srcM,destM); (*copy rastor rectangle *)
- (* 3 = replace mode *) (* N.B. Not same as C binding ! *)
- END;
-
- (*************************************)
- (** triangle to demo filled polygon **)
- (*************************************)
-
- PROCEDURE draw_triangle;
- BEGIN
- pxy[0]:=x[3];
- pxy[1]:=y[18];
- pxy[2]:=x[5];
- pxy[3]:=y[18];
- pxy[4]:=x[4];
- pxy[5]:=y[15];
- ret:=vsf_interior(handle,hatch); (* hatch fill pattern *)
- ret:=vsf_style(handle,9); (* narrow spaced horizontal lines for hatch *)
- ret:=vsf_color(handle,magenta);
- ret:=v_fillarea(handle,3,pxy); (* an area with 3 corners *)
- END;
-
- (**********************************************************)
- (** Draw a little trap (box) into which mouse can point **)
- (** Only execute if using CRT driver! **)
- (** NOTE: This could be done more elegantly with GEMAES **)
- (**********************************************************)
-
- PROCEDURE draw_trap(tx,ty : INTEGER; tstring : STRING80);
- VAR
- ix,iy : INTEGER;
- xyarray : ARRAY_4;
- BEGIN
- xyarray[0]:=tx; (* bottom left x coord corner of rectangle *)
- xyarray[1]:=ty; (* bottom left y coord *)
- xyarray[2]:=tx + x[3]; (* top right x *)
- xyarray[3]:=ty - y[2]; (* top right y *)
- ret:=vsf_perimeter(handle,1); (* set to visible perimiter *)
- ret:=vsf_color(handle,red); (* a red box *)
- ret:=vsf_interior(handle,hollow); (* hollow fill style *)
- ret:=vswr_mode(handle,1); (* replace mode for the line drawing *)
- ret:=v_bar (handle,xyarray); (* bar = rectangle *)
- ix:=tx + (x[1] DIV 2);
- iy:=ty - (y[1] DIV 2);
- do_text(ix,iy,afont[1],10,blue,normal,tstring); (*prompt - normal style*)
- END;
-
- (************************************)
- (** Get mouse for those who have it *)
- (************************************)
-
- PROCEDURE getmouse;
- VAR
- newx, newy : INTEGER;
- termchar : CHAR;
- BEGIN
- ret:=vrq_locator(handle,x[9],y[19],newx,newy,termchar);
- (* place mouse & find *)
- IF ((newx > x[11]) AND (newx < x[14])) (* mouse clicked but where? *)
- AND ((newy > y[17]) AND (newy < y[18]))
- THEN done:=TRUE; (* quit selected *)
- END;
-
- (***************************)
- (** Get a single keystroke *)
- (***************************)
-
- PROCEDURE getkeyin;
- VAR
- instring : STRING80;
- BEGIN
- ret:=vst_font(handle,afont[1]); (* std font for echo *)
- ret:=vst_point(handle,20,i,j,k,l); (* 20 point size echo char *)
- ret:=vrq_string(handle,1,1,x[10],y[18],instring); (* request 1 char, echo *)
- IF instring[1] IN ['q','Q'] THEN done:=TRUE; (* yes, time to quit *)
- END;
-
- (**************************************************************************)
- (*** Prompt on crt in case another flash of the picture is required ***)
- (** Note: GEMAES lets you check key-in or mouse-in much easier ***)
- (**************************************************************************)
-
- PROCEDURE do_prompt;
- BEGIN
- draw_trap(x[6],y[18],'R = Redo'); (* draw mouse trap for another go *)
- draw_trap(x[11],y[18],'Q = Quit'); (* or trap to say goodbye *)
- getmouse; (* mouse input required *)
- (* getkeyin *) (* activate this to use keyboard input instead *)
- END;
-
- (*********************************)
- (** Close all GEM VDI resources **)
- (*********************************)
-
- PROCEDURE close_gvdi;
- BEGIN
- ret:=vst_unload_fonts(handle,0); (* unload any fonts loaded *)
- ret:=v_clswk(handle); (* close that workstation *)
- END;
-
- (*************************)
- (** mainline of program **)
- (*************************)
- BEGIN
-
- init_gvdi; (* initialize right graphics device *)
- done:=FALSE; (* not done yet *)
- REPEAT
- ret:=v_clrwk(handle); (* clear work station *)
- draw_border; (* surround it *)
- dri_logo; (* binary logo symbol *)
- draw_ellipse;
- draw_triangle;
- draw_name; (* name with trade mark *)
- do_text(x[9],y[12],afont[3],36,magenta,bold+skew+underline,'GEM VDI');
- (* in 36 point font 3 with many effects *)
- do_text(x[2],y[18],afont[1],10,red,normal,'GEM'); (* in small *)
- ret:=vst_rotation(handle,900); (* rotate 90 degrees *)
- do_text(x[2],y[19],afont[1],10,red,bold,'GEM');
- ret:=vst_rotation(handle,1800); (* upside down *)
- do_text(x[2],y[17],afont[1],10,cyan,bold,'GEM');
- ret:=vst_rotation(handle,0); (* reset angle of text *)
- IF crt THEN BEGIN (* screen driver loaded ? *)
- copy_ellipse; (* rastor ops only on crt's *)
- do_prompt; (* & prompt for go around *)
- END
- ELSE done:=TRUE; (* no - cheers *)
- UNTIL done;
- close_gvdi; (* clear up *)
- END.
-