home *** CD-ROM | disk | FTP | other *** search
- {$I switches.inc}
- {-------------------------------------------------------------------}
- { TWDEMO.PAS }
- { Copyright 1991 TEGL SYSTEMS CORPORATION, All rights reserved. }
- {-------------------------------------------------------------------}
-
-
- {$F+} {-- far call is necessary for EVENTS }
-
- Uses
- teglfont, {-- the graphics group }
- fastgrph,
- tgraph,
-
- virtmem, {-- memory }
-
- teglintr,
- teglunit, {-- window manager, menus and micellaneous }
- teglmenu,
- teglmain,
- teglspec,
-
- twcommon, {-- high-level windows }
- twkernel,
- twwindow,
- twworld,
- twdialog,
- twcontrl;
-
-
- {-- Global variables }
-
- VAR
- TechnaFont : Integer;
- TallFont : Integer;
- mainmenu: ImageStkPtr; {-- the main bar menu is only an ordinary frame}
- {-- with option menu click areas placed on it. }
- menufont: pointer; {-- the font to use with all menus. Set once so }
- {-- we can make the program look better on }
- {-- a variety of video displays. }
- fileom : optionmptr;
- devicesom: optionmptr;
- dialogom : optionmptr;
- worldom : optionmptr;
-
- {-- restores all the frames to being active and close the error }
- {-- message window. }
-
- function errorclose(ifs: imagestkptr; ms: msclickptr): Word;
- BEGIN
- resetframeactive(stackptr,true);
- twclose(findwinframe(ifs));
- END;
-
- {-- Display an error message and disable all other frames until }
- {-- the OK button is pressed. }
-
- procedure SayError(s: String);
- VAR wf : WinFramePtr;
- BEGIN
- { resetframeactive sets the activity of all the frames from }
- { the one passed (here the topmost) to the bottom of the stack.}
- { In this case all frames become inactive then we create one }
- { active frame (the error message) that must be delt with, before}
- { processing can continue. }
- resetframeactive(stackptr,false); {-- disable everything }
- twdInit(wf,0,(getmaxy DIV 2) - 35,getmaxx,(getmaxy DIV 2) + 35);
- twsetHeader(wf,'ERROR'); {-- set the header }
- twSetMaximize(wf,false); {-- disable MIN/MAX buttons }
- {-- add a button that will acknowlege the error }
- twdAddButton(wf,getmaxx DIV 2 - 20, 25, 'OK',errorclose);
- twsetcloseevent(wf,errorclose); {-- space bar menu CLOSE }
- twDrawWindowFrame(wf); {-- finally draw the window }
- {-- display the message. }
- prepareforupdate(wf^.ifs); {-- going to write to the window }
- settextjustify(centertext,toptext);
- OutTextXY((getmaxx DIV 2) - (wf^.thickness *2),5,s);
- commitupdate; {-- finished writing to the window }
- END;
- {---------------------------------------------------------}
- {-- These are some global variable for our dialog window to access }
-
- CONST wf : WinFramePtr = NIL;
- strtd: string[20] = 'This is a string';
- chkbox : boolean = TRUE;
- radio : integer = 2;
-
- {-- Note that closing a dialog calls twdClose not twClose, it must}
- {-- first dispose of the list of dialog entries before the window }
-
- function dialogclose(ifs : ImageStkPtr; ms: MsClickPtr): Word;
- begin
- dialogclose := twdClose(ifs,ms);
- wf := NIL;
- end;
-
- {-- Opens up a simple dialog window. }
-
- Function OpenDialogDemo(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR tempifs : imagestkptr;
- BEGIN
- if wf <> NIL then {-- only one allowed. }
- begin
- sayerror('The dialog demo is already running.');
- exit;
- end;
- twdInit(wf,100,100,400,300);
- twSetHeader(wf,'Simple Dialogue');
-
- twdAddLabel(wf,10,10,'Labels go anywhere');
- {-- input lines are string items, the last parameter is the }
- {-- length of the string. }
- twdAddInputLine(wf,10,30,'Edit this ',strtd,20);
- {-- check boxes are boolean values }
- twdAddCheckBox(wf,10,50,'a check box',chkbox);
- {-- radio buttons all access the same integer value. Their }
- {-- order is important. The first one will be one the }
- {-- second two, etc. Groups of radio buttons must be seperated }
- {-- by either some other dialog item or a label, if nothing is }
- {-- required use an empty label. }
- twdAddRadioButton(wf,10,70,'a radio button (1)',radio);
- twdAddRadioButton(wf,10,90,'a radio button (2)',radio);
- twdAddRadioButton(wf,10,110,'a radio button (3)',radio);
- {-- Buttons are associated with events, here the OK button does }
- {-- nothing, but the cancel button closes the dialog. }
- twdAddbutton(wf,50,150,'OK',nilunitproc);
- twdAddButton(wf,180,150,'CANCEL',dialogclose);
- twSetCloseEvent(wf,dialogclose); {-- the space bar menu }
-
- {-- Note that the window is only drawn AFTER ALL THE DIALOG ITEMS }
- {-- HAVE BEEN SET. }
- twDrawWindowFrame(wf);
- END;
-
- {-- The key to using scaled text is by setting the usercharsize }
- {-- with the ratio of the working area to the screen size }
-
- Function WorldTextRedraw(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf: WinFramePtr;
- BEGIN
- wf := FindWinFrame(ifs);
- twSelect(wf);
- twwDefineWorld(wf,0,0,1000,1000);
- PrepareforUpdate(ifs);
- SetTextJustify(lefttext,toptext);
- SetTextStyle(TechnaFont,horizdir,2);
- SetUserCharSize(wf^.wx2-wf^.wx1,getmaxx DIV 2,
- wf^.wy2-wf^.wy1,getmaxy DIV 2);
- twwOutTextXY(wf,10,10,'Scaled text');
- SetTextStyle(TallFont,Horizdir,5);
- SetUserCharSize(wf^.wx2-wf^.wx1,getmaxx DIV 2,
- wf^.wy2-wf^.wy1,getmaxy DIV 2);
- twwOutTextXY(wf,10,500,'Using Triplex & Small Font');
- CommitUpDate;
-
- END;
-
- Function OpenWorldTextDemo(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf : WinFramePtr;
- BEGIN
- twinit(wf,100,100,300,250);
- twSetHeader(wf,'Scaling text');
- twSetRedraw(wf,WorldTextRedraw);
- twDrawWindowFrame(wf);
- END;
-
-
- {---------------------------------------------------------}
- {-- Bar graph demo illustrates how to use the world coordinates }
- {-- to fit data into any sized window. }
- {---------------------------------------------------------}
-
- CONST MaxBars = 10;
- TYPE BarDef = RECORD x1,y1,x2,y2,color: Integer; END;
- CONST Bars : Array[1..MaxBars] OF BarDef =
- (
- (x1:-99;y1:80;x2:-81;y2:0;Color:blue),
- (x1:-80;y1:70;x2:-61;y2:0;Color:blue),
- (x1:-60;y1:20;x2:-41;y2:0;Color:blue),
- (x1:-40;y1:0;x2:-21;y2:-40;Color:red),
- (x1:-20;y1:0;x2:-1;y2:-99;Color:red),
- (x1:1;y1:0;x2:20;y2:-67;Color:red),
- (x1:21;y1:8;x2:40;y2:0;Color:green),
- (x1:41;y1:20;x2:60;y2:0;Color:yellow),
- (x1:61;y1:75;x2:80;y2:0;Color:magenta),
- (x1:81;y1:50;x2:99;y2:0;Color:blue));
-
-
-
- Function rtos(r: real) : string;
- var s : String;
- BEGIN
- str(r:5:1,s);
- rtos := s;
- END;
-
- Function WorldBarRedraw(ifs : ImageStkPtr; ms : MsClickPtr): Word;
- VAR wf: WinFramePtr;
- I : Integer;
- BEGIN
- wf := FindWinFrame(ifs);
- twwDefineWorld(wf,-100,100,100,-100);
- twwLine(wf,-100,0,100,0);
- twSetFont(wf,@f6x6norm);
- for I := 1 to MaxBars DO
- WITH BARS[I] DO
- BEGIN
- SetFillStyle(solidfill,color);
- twwBar(wf,x1,y1,x2,y2);
- SetColor(Black);
- twwRectangle(wf,x1,y1,x2,y2);
- {twwOutTextXy(wf,x1,y1,'('+rtos(x1)+','+rtos(y1)+')'); }
-
- END;
- SetColor(BLACK);
- {twwOutTextXy(wf,-10,-10,'(0,0)');}
- END;
-
- Function WorldSinRedraw(ifs : ImageStkPtr; ms : MsClickPtr): Word;
- VAR wf: WinFramePtr;
- t : real;
- const
- counter : real = 0.05;
- range : real = 8.0;
- BEGIN
- wf := FindWinFrame(ifs);
- twwDefineWorld(wf,-(range * 1.2),(range * 1.2),(range * 1.2),-(range * 1.2));
- twwline(wf,-range,0,range,0);
- twwline(wf,0,-range,0,range);
- twwline(wf,-range,range,-range,-range);
- twwline(wf,-range,-range,range,-range);
- setcolor(red);
- t := -range;
- while t <= range do
- begin
- { twwputpixel(wf,t,range * sin(t),red); }
-
- twwline(wf,t,range * sin(t),t+counter,range * sin(t+counter));
- t := t + counter;
- end;
-
- setcolor(black);
- END;
-
- Function OpenWorldBarDemo(ifs : ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf : WinFramePtr;
- BEGIN
- twInit(wf,100,100,400,400);
- twSetThickness(wf,4);
- twSetWinFrameColors(wf,lightgray,darkgray);
- twSetHeader(wf,'Bar Graph (-100,100,100,-100)');
- twSetRedraw(wf,worldBarredraw);
- twSetWindowStyle(wf,stdBox);
- twDrawWindowFrame(wf);
- END;
-
-
- Function OpenWorldSinDemo(ifs: ImageStkPtr; Ms: MsClickPtr): Word;
- VAR wf : WinFramePtr;
- BEGIN
- twInit(wf,200,200,400,400);
- twSetThickness(wf,4);
- twSetWinFrameColors(wf,lightblue,blue);
- twSetHeader(wf,'Sine Wave');
- twSetRedraw(wf,worldSinredraw);
- twSetWindowStyle(wf,BevBox);
- twDrawWindowFrame(wf);
- END;
-
-
- {$F+}
- {$IFDEF wcFloatLInt}
- Function worldredraw(ifs : ImageStkPtr; ms : MsClickPtr): Word;
- VAR wf : WinFramePtr;
- BEGIN
- twwDefineWorld(wf,-10000,10000,10000,-10000);
- twwLine(wf,-10000,10000, 10000,-10000);
- twwLine(wf,10000,10000,-10000,-10000);
- twwrectangle(wf,-5000,-5000,5000,5000);
-
- setfillstyle(solidfill,blue);
- twwbar(wf,-9000,9000,-5000,5000);
- twwarc(wf,0,0,180,360,5000);
- twwellipse(wf,0,0,180,360,6000,6000);
- setcolor(red);
- twwcircle(wf,0,0,6000);
- END;
-
-
- {$ELSE}
-
- Function worldredraw(ifs : ImageStkPtr; ms : MsClickPtr): Word;
- VAR wf : WinFramePtr;
- BEGIN
- {-- the redrawing event should alway find the window then }
- {-- select it. Selecting does a fix up in case the window has }
- {-- been move and sets the view port to the working area of the }
- {-- window. }
- wf := FindWinFrame(ifs);
- twselect(wf);
- {-- twwDefineWorld sets the coordinate system, this must be set }
- {-- after the window has been drawn (i.e. not before twDrawWindowFrame }
- twwDefineWorld(wf,-10.0,10.0,10.0,-10.0);
- {-- the world coordinate call all mimic the standard graphics calls }
- {-- execpt they start with tww, have a winframeptr as the first parameter}
- {-- and the arguments are real. Graphics functions that do not have }
- {-- coordinates have no equivalent. Just use the normal graphics call. }
- setcolor(black);
- twwLine(wf,-10.0,10.0, 10.0,-10.0);
- twwLIne(wf,10.0,10.0,-10.0,-10.0);
- twwrectangle(wf,-5,-5,5,5);
- setfillstyle(solidfill,blue);
- twwbar(wf,-9,9,-5,5);
- {-- arcs may not work the way you expect, ellipse is better }
-
- twwarc(wf,0,0,360,180,5.0);
- twwellipse(wf,0,0,180,360,4.0,4.0);
- {-- here we draw an ellipse then a circle with the same center point }
- {-- and radius, as you resize the window you can see the effect on the }
- {-- aspect ratio. }
- twwellipse(wf,0,0,1,360,6.0,6.0);
- setcolor(red);
- twwcircle(wf,0,0,6.0);
- END;
-
- {$ENDIF}
-
- function openworlddemo(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf : WinFramePtr;
-
- BEGIN
- {---------}
- twInit(wf,100,100,400,300);
- twSetThickness(wf,6);
- twSetWinFrameColors(wf,lightgray,darkgray);
- twSetHeader(wf,'World coordinates');
- twSetRedraw(wf,worldredraw);
- twSetWindowStyle(wf,StdBox);
- twDrawWindowFrame(wf);
- END;
-
- {---------------------------------------------------------}
- {-- Local menus in high level windows. }
- {-- This just draws the menus, no events are attached. }
-
- function OpenMenuDemo(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf: WinFramePtr;
- BEGIN
- twInit(wf,50,50,250,250);
- twSetDisplayFont(wf,@f8x8Bold);
- twSetHeader(wf,'LOCAL MENU Demo');
- {-- note that certain letters are surrounded by tildes, these }
- {-- will be underlined when display and the appropriate key will }
- {-- be captured. }
- twMenuItem(wf,'~F~ile',true);
- twSubMenuItem(wf,'~O~pen',true,NilUnitProc);
- twSubMenuItem(wf,'~S~ave',true,NilUnitProc);
- twSubMenuItem(wf,'Save ~a~s...',true,NilUnitProc);
- twSubMenuItem(wf,'-',false,nilunitproc);
-
- twSubMenuItem(wf,'E~x~it',true,twmenucloseEvent);
- twMenuItem(wf,'~E~dit ',true);
- twSubMenuItem(wf,'~U~ndo',true,NilUnitProc);
- twSubMenuItem(wf,'~S~elect',true,NilUnitProc);
- twMenuItem(wf,'~W~indow',true);
- twSubMenuItem(wf,'~T~ile',true,NilUnitProc);
- twSubMenuItem(wf,'~S~elect',true,NilUnitProc);
- twMenuItem(wf,'~H~elp',true);
- twSubMenuItem(wf,'~C~ontents',true,NilUnitProc);
- twSubMenuItem(wf,'~I~ndex',true,NilUnitProc);
- twDrawWindowFrame(wf);
- END;
-
-
- {---------------------------------------------------------}
- {-- Slider action in high level windows. The Window Frame }
- {-- maintains variables that are updated after a slider is}
- {-- moved or a slider end button is pressed. This is }
- {-- looked after by some events in TWKERNEL. The user must}
- {-- still create an event for each slider that will then }
- {-- interrogate these variables and take the appropriate }
- {-- action. }
-
-
-
- {-- this is the up down slider event that is called by tehe }
- {-- kernel after the slider is moved. }
-
- function showUpDownAction(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf: WinFramePtr;
- BEGIN
- wf := FindWinFrame(ifs);
- prepareforupdate(ifs);
- twCrtAssign(wf);
- twclear(wf);
- twgotoxy(wf,1,2);
- writeln(' Up Down Action');
- writeln(' Slider percent: ',wf^.updnslideper);
- writeln(' button up : ',wf^.upbuttonpress);
- writeln(' button down : ',wf^.dnbuttonpress);
- writeln(' Slider Range : ',wf^.updownrange);
- commitupdate;
- END;
-
- {-- this is the left right slider event that is called by the }
- {-- kernel after the slider is moved or the }
-
- function showLeftRightAction(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf: WinFramePtr;
- BEGIN
- wf := FindWinFrame(ifs);
- prepareforupdate(ifs);
- twCrtAssign(wf);
- twclear(wf);
- twgotoxy(wf,1,2);
- writeln(' Left Right Action');
- writeln(' Slider percent: ',wf^.lfrtslideper);
- writeln(' button left : ',wf^.lfbuttonpress);
- writeln(' button right : ',wf^.rtbuttonpress);
- writeln(' Slider Range : ',wf^.leftrightrange);
- commitupdate;
- END;
-
- {-- this event is called from a menu selection or a mouse click. }
- {-- It ignores the parameters and simply opens up a demo window }
- {-- for sliders. The WinFramePtr can be a local variable because }
- {-- it can be located in events that are attached to it (sliders }
- {-- here) by using findwinframe and the passed imagestkptr. }
-
- function OpenSliderDemo(ifs: ImageStkPtr; ms: MsClickPtr): Word;
- VAR wf: WinFramePtr;
- BEGIN
- twInit(wf,100,100,450,300); {-- allocates memory and set size }
- twSetUpDownRange(wf,2000,100);
- twSetLeftRightRange(wf,2000,100);
- twSetFont(wf,@f8x12bol); {-- the font to use }
- twSetHeader(wf,'A slider action example.'); {-- header on }
- twSetUpDownSlider(wf,true); {-- up down slider on }
- twSetLeftRightSlider(wf,true);{-- left right slider on }
- twSetUpDownEvent(wf,ShowUpDownAction); {-- attach above event }
- twSetLeftRightEvent(wf,showLeftRightAction); {-- ditto }
- twDrawWindowFrame(wf); {-- finally draw it. }
- END;
-
-
- BEGIN
- {-- simple start up, minimal normal heap, TWCOMMON }
- twEasyStart;
- TechnaFont := InstallUserFont('TECHNA.CHR');
- TallFont := InstallUserFont('TALL.CHR');
- setkeyboardmouse(false);
- {-- MaxWindowSize is the resolution of the window manager. Try }
- {-- changing this value between 32000 - 128000, larger values }
- {-- are better but may cause program failure because of heap size }
- {MaxWindowSize := 64000; }
- {-- memory monitor, TWCONTRL, optional }
- {twcInstallMonitor; }
-
- {-- grab standard io handles for redirection, TWWINDOW }
- twcrton;
-
- {-- set the font to use in window headers, TWCOMMON }
- twSetHeaderFont(@f8x12bol);
-
- menufont := @f8x12bol; {-- set the font to use on the menu }
-
- FileOm := CreateOptionMenu(MenuFont);
- DefineOptions(FileOm,'-',true,NilUnitProc);
- DefineOptions(FileOm,' E~x~it ',true,twExitOption);
- DevicesOm := CreateOptionMenu(MenuFont);
- DefineOptions(DevicesOm,'~M~enus' ,True,OpenMenuDemo);
- DefineOptions(DevicesOm,'~S~liders',True,OpenSliderDemo);
-
- DialogOm := CreateOptionMenu(MenuFont);
- DefineOptions(DialogOm,'~S~imple',True,OpenDialogDemo);
- WorldOm := CreateOptionMenu(MenuFont);
- DefineOptions(WorldOm,'~S~ample',True,OpenWorldDemo);
- DefineOptions(WorldOm,'~B~ar Graph ',True,OpenWorldBarDemo);
- DefineOptions(WorldOm,'S~i~ne wave',True,OpenWorldSinDemo);
- DefineOptions(WorldOm,'~T~ext (scaled)',True,OpenWorldTextDemo);
-
- {-- we create the bar menu last an attach all the option menus to }
- {-- it, this is the only order that will work. }
-
- SetTeglFont(menufont); {-- bar menu uses the current font }
- CreateBarMenu(0,0,getmaxx);
- MainMenu := StackPtr; {-- just another frame }
- OutBarOption(' ~F~ile ', FileOm);
- OutBarOption(' ~D~evices ', DevicesOm);
- OutBarOption(' Dia~l~ogues ',DialogOm);
- OutBarOption(' ~W~orld ', WorldOM);
-
- setautorotate(true); {-- windows rotate to the top automatically }
- teglsupervisor; {-- do not adjust your set, the supervisor }
- {-- is in control! }
- END.
-