home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
026.lha
/
HP-10C
/
gadgets.mod
< prev
next >
Wrap
Text File
|
1987-04-02
|
15KB
|
566 lines
IMPLEMENTATION MODULE CalcGadgets;
(*
Create gadgets for calculator.
Created: Duncan Prindle, September 1, 1986
Modified: Perhaps
*)
FROM CalcFunctions IMPORT X, ErrorType, INDEG, BLANK,
Add, Subtract, Multiply, Divide,
POINT, PI, CLX, RDN, ENTER, LASTX, SIN,
ASIN, COS, ACOS, TAN, ATAN, LN, EXP, TENtotheX,
LOG, YtotheX, OneOverX, XSquared, SQRT,
XtoY, CHS, CLRST, StackUp, stored;
FROM Gadgets IMPORT BoolGadget, AddGadget, RefreshGadgets,
RemoveGadget;
FROM Intuition IMPORT
IDCMPFlags, IDCMPFlagSet,
GadgetPtr, Gadget, GadgetFlags, GadgetFlagSet,
ActivationFlags, ActivationFlagSet,
BorderPtr, Border, DrawBorder, Requester,
IntuitionTextPtr, IntuitionText, PrintIText,
IntuiMessagePtr, IntuiMessage,
NewWindow, WindowFlags, WindowFlagSet, WindowPtr,
ScreenFlags, ScreenFlagSet;
FROM Ports IMPORT GetMsg;
FROM Storage IMPORT ALLOCATE;
FROM SYSTEM IMPORT ADR, ADDRESS, BYTE, NULL;
FROM Tasks IMPORT SignalSet, Wait;
FROM Windows IMPORT OpenWindow;
TYPE XYPtr = POINTER TO Points;
Points = RECORD
XP : ARRAY[0..9] OF INTEGER;
END;
NAME = ARRAY[0..2] OF CHAR;
VAR
P : ARRAY[0..3] OF XYPtr;
Name : ARRAY[0..46] OF NAME;
Name2 : ARRAY[0..7] OF NAME;
LText : ARRAY[0..46] OF CARDINAL;
LText2 : ARRAY[0..7] OF CARDINAL;
keys : ARRAY[0..46] OF CalcButtonPtr;
KEY : CalcButtonPtr;
t : ARRAY[0..46] OF IntuitionTextPtr;
ts : ARRAY[0..7] OF IntuitionTextPtr;
temp : IntuitionText;
LGadge : ARRAY[0..46] OF CARDINAL;
TGadge : ARRAY[0..46] OF CARDINAL;
TOGGLE : CARDINAL;
w : NewWindow;
WinPtr : WindowPtr;
gPtr : ARRAY[0..46] OF GadgetPtr;
Signal : IntuiMessagePtr;
Sig1 : SignalSet;
Button : GadgetPtr;
CGadget : CARDINAL;
req : Requester;
CalcName : ARRAY[0..7] OF CHAR;
PROCEDURE InitBorder( VAR b : ARRAY OF BorderPtr );
VAR I : INTEGER;
BEGIN
(* Initialize arrays of points for four types of gadgets *)
FOR I := 0 TO 3 DO
NEW( P[I] );
WITH P[I]^ DO
XP[0] := 0; XP[1] := 0;
XP[2] := 0;
XP[7] := 0;
XP[8] := 0; XP[9] := 0;
END;
END;
P[0]^.XP[3] := 15; P[0]^.XP[4] := 25; P[0]^.XP[5] := 15; P[0]^.XP[6] := 25;
P[1]^.XP[3] := 15; P[1]^.XP[4] := 30; P[1]^.XP[5] := 15; P[1]^.XP[6] := 30;
P[2]^.XP[3] := 32; P[2]^.XP[4] := 30; P[2]^.XP[5] := 32; P[2]^.XP[6] := 30;
P[3]^.XP[3] := 15; P[3]^.XP[4] :=155; P[3]^.XP[5] := 15; P[3]^.XP[6] :=155;
(* Points for borders are initialised *)
(* Fill in Border structures *)
FOR I := 0 TO 3 DO
NEW( b[I] );
WITH b[I]^ DO
LeftEdge := 0;
TopEdge := 0;
FrontPen := BYTE (1);
DrawMode := BYTE (0);
Count := BYTE (5);
XY := P[I];
NextBorder := NULL;
END;
END;
b[3]^.TopEdge := -4;
(* Border Structures all filled in. *)
END InitBorder;
PROCEDURE InitGadgets( VAR g : ARRAY OF GadgetPtr;
VAR b : ARRAY OF BorderPtr );
VAR I : CARDINAL;
J : CARDINAL;
TopGadge : INTEGER;
BEGIN
(* Fill in array containing names of Buttons *)
Name[ 0] := " - ";
Name[ 1] := " 7 ";
Name[ 2] := " 8 ";
Name[ 3] := " 9 ";
Name[ 4] := " + ";
Name[ 5] := " 4 ";
Name[ 6] := " 5 ";
Name[ 7] := " 6 ";
Name[ 8] := " * ";
Name[ 9] := " 1 ";
Name[10] := " 2 ";
Name[11] := " 3 ";
Name[12] := " / ";
Name[13] := " 0 ";
Name[14] := " . ";
Name[15] := " pi";
Name[16] := "CLX";
Name[17] := "RDN";
Name[18] := " ^ "; Name2[0] := "| ";
Name[19] := "EEX";
Name[20] := "RAD";
Name[21] := "GLD";
Name[22] := "sin";
Name[23] := "cos";
Name[24] := "tan";
Name[25] := "ln ";
Name[26] := "e "; Name2[1] := "x ";
Name[27] := "X "; Name2[2] := "2 ";
Name[28] := "CHS";
Name[29] := "CLS";
Name[30] := "y "; Name2[3] := "x ";
Name[31] := "X-Y";
Name[32] := "STO";
Name[33] := "RCL";
Name[34] := "sin"; Name2[4] := " -1";
Name[35] := "cos"; Name2[5] := " -1";
Name[36] := "tan"; Name2[6] := " -1";
Name[37] := "log";
Name[38] := "10 "; Name2[7] := " x";
Name[39] := "sqr";
Name[40] := "CHS";
Name[41] := "CLS";
Name[42] := "1/X";
Name[43] := "lsX";
Name[44] := "STO";
Name[45] := "RCL";
Name[46] := "DEG";
(* Fill in the left positions of the start of the names *)
FOR I := 0 TO 15 DO
LText[I] := 1;
END;
FOR I := 16 TO 46 DO
LText[I] := 4;
END;
FOR I := 34 TO 36 DO
LText[I] := 1;
END;
LText[26] := 3;
LText[27] := 3;
LText[30] := 3;
LText2[0] :=12;
LText2[1] :=12;
LText2[2] :=12;
LText2[3] :=12;
LText2[4] := 8;
LText2[5] := 8;
LText2[6] := 8;
LText2[7] := 4;
(* Create Intuitext and Gadget records for the gadgets *)
FOR I := 0 TO 46 DO
NEW( t[I] );
WITH t[I]^ DO
FrontPen := BYTE (2); BackPen := BYTE (0);
DrawMode := BYTE (0); IText := ADR( Name[I] );
ITextFont := NULL; NextText := NULL;
LeftEdge := LText[I]; TopEdge := 4;
END;
END;
(* Now for the superscripts *)
FOR I := 0 TO 7 DO
NEW( ts[I] );
WITH ts[I]^ DO
FrontPen := BYTE (2); BackPen := BYTE (0);
DrawMode := BYTE (0); IText := ADR( Name2[I] );
ITextFont := NULL; NextText := NULL;
LeftEdge := LText2[I]; TopEdge := 4;
END;
END;
(* Link up text for superscripts *)
t[18]^.NextText := ts[0];
t[26]^.NextText := ts[1];
t[27]^.NextText := ts[2];
t[30]^.NextText := ts[3];
t[34]^.NextText := ts[4];
t[35]^.NextText := ts[5];
t[36]^.NextText := ts[6];
t[38]^.NextText := ts[7];
(* superscripts have different top edges *)
t[18]^.TopEdge :=10;
ts[0]^.TopEdge :=15;
ts[1]^.TopEdge := 0;
ts[2]^.TopEdge := 1;
ts[3]^.TopEdge := 0;
ts[4]^.TopEdge := 1;
ts[5]^.TopEdge := 1;
ts[6]^.TopEdge := 1;
ts[7]^.TopEdge := 1;
(* Text is finished *)
(* Assign functions to the keys *)
FOR I := 0 TO 46 DO
NEW( keys[I] );
END;
keys[ 0]^.CalcKey := Subtract;
keys[ 1]^.CalcKey := BLANK;
keys[ 2]^.CalcKey := BLANK;
keys[ 3]^.CalcKey := BLANK;
keys[ 4]^.CalcKey := Add;
keys[ 5]^.CalcKey := BLANK;
keys[ 6]^.CalcKey := BLANK;
keys[ 7]^.CalcKey := BLANK;
keys[ 8]^.CalcKey := Multiply;
keys[ 9]^.CalcKey := BLANK;
keys[10]^.CalcKey := BLANK;
keys[11]^.CalcKey := BLANK;
keys[12]^.CalcKey := Divide;
keys[13]^.CalcKey := BLANK;
keys[14]^.CalcKey := POINT;
keys[15]^.CalcKey := PI;
keys[16]^.CalcKey := CLX;
keys[17]^.CalcKey := RDN;
keys[18]^.CalcKey := ENTER;
keys[19]^.CalcKey := BLANK;
keys[20]^.CalcKey := DEG;
keys[21]^.CalcKey := GOLD;
keys[22]^.CalcKey := SIN;
keys[23]^.CalcKey := COS;
keys[24]^.CalcKey := TAN;
keys[25]^.CalcKey := LN;
keys[26]^.CalcKey := EXP;
keys[27]^.CalcKey := XSquared;
keys[28]^.CalcKey := CHS;
keys[29]^.CalcKey := CLRST;
keys[30]^.CalcKey := YtotheX;
keys[31]^.CalcKey := XtoY;
keys[32]^.CalcKey := STO;
keys[33]^.CalcKey := RCL;
keys[34]^.CalcKey := ASIN;
keys[35]^.CalcKey := ACOS;
keys[36]^.CalcKey := ATAN;
keys[37]^.CalcKey := LOG;
keys[38]^.CalcKey := TENtotheX;
keys[39]^.CalcKey := SQRT;
keys[40]^.CalcKey := CHS;
keys[41]^.CalcKey := CLRST;
keys[42]^.CalcKey := OneOverX;
keys[43]^.CalcKey := LASTX;
keys[44]^.CalcKey := STO;
keys[45]^.CalcKey := RCL;
keys[46]^.CalcKey := DEG;
(* Now fill in left and top edges of Gadgets *)
FOR I := 0 TO 3 DO
TopGadge := 32 + 17*I;
FOR J := 0 TO 3 DO
LGadge[4*I+J] := 10 + 30*J;
TGadge[4*I+J] := TopGadge;
END;
END;
LGadge[16] :=135; TGadge[16] := 32;
LGadge[17] :=135; TGadge[17] := 49;
LGadge[18] :=135; TGadge[18] := 66;
FOR I := 0 TO 4 DO
TopGadge := 15 + 17*I;
FOR J := 0 TO 2 DO
LGadge[19+3*I+J] := 180 + 37*J;
TGadge[19+3*I+J] := TopGadge;
END;
END;
FOR I := 0 TO 3 DO
TopGadge := 32 + 17*I;
FOR J := 0 TO 2 DO
LGadge[34+3*I+J] := 180 + 37*J;
TGadge[34+3*I+J] := TopGadge;
END;
END;
LGadge[46] := 217;
TGadge[46] := 15;
(* Create Gadget records *)
FOR I := 0 TO 46 DO
NEW( g[I] );
WITH g[I]^ DO
Flags := GadgetFlagSet{};
Activation:= ActivationFlagSet{RelVerify};
GadgetType:= BoolGadget;
SelectRender:= NULL;
GadgetText := t[I];
GadgetID := 50;
UserData := keys[I];
LeftEdge := LGadge[I];
TopEdge := TGadge[I];
IF I < 16
THEN Width := 25; Height := 15;
GadgetRender:= b[0];
ELSE Width := 30; Height := 15;
GadgetRender:= b[1];
END;
END;
END;
(* We want to be able to recognize the digit gadgets quickly *)
g[ 1]^.GadgetID := 7;
g[ 2]^.GadgetID := 8;
g[ 3]^.GadgetID := 9;
g[ 5]^.GadgetID := 4;
g[ 6]^.GadgetID := 5;
g[ 7]^.GadgetID := 6;
g[ 9]^.GadgetID := 1;
g[10]^.GadgetID := 2;
g[11]^.GadgetID := 3;
g[13]^.GadgetID := 0;
(* Gadgets with GadgetID <= 20 will not have SAME = FALSE automatically *)
g[14]^.GadgetID := 15;
g[18]^.GadgetID := 15;
g[28]^.GadgetID := 15;
(* Make the enter key the right size *)
g[18]^.Height := 34;
g[18]^.GadgetRender := b[2];
(* I don't know how to do the display right, so disable FIX *)
g[19]^.Flags := GadgetFlagSet{Disabled};
(* Lastly we link the gadgets up so they all get displayed *)
FOR I := 0 TO 32 DO
g[I]^.NextGadget := g[I+1];
END;
g[33]^.NextGadget := NULL;
(* Keep a copy of the pointers for the DEG and GOLD Functions *)
FOR I := 0 TO HIGH(g) DO
gPtr[I] := g[I];
END;
END InitGadgets;
PROCEDURE DEG (): ErrorType;
VAR NGadge : CARDINAL;
BEGIN
IF INDEG
THEN INDEG := FALSE;
(* replace the DEG gadget with the RAD gadget *)
NGadge := RemoveGadget( WinPtr, gPtr[46]^);
(* Remove DEG text *)
WITH temp DO
FrontPen := BYTE (0); BackPen := BYTE (0);
DrawMode := BYTE (0); ITextFont := NULL;
LeftEdge := t[46]^.LeftEdge; TopEdge := t[46]^.TopEdge;
IText := t[46]^.IText; NextText := t[46]^.NextText;
END;
PrintIText( WinPtr^.RPort^, temp, LGadge[46], TGadge[46] );
NGadge := AddGadget( WinPtr, gPtr[20]^, 20);
ELSE INDEG := TRUE;
(* replace the RAD gadget with the DEG gadget *)
NGadge := RemoveGadget( WinPtr, gPtr[20]^);
(* Remove RAD text *)
WITH temp DO
FrontPen := BYTE (0); BackPen := BYTE (0);
DrawMode := BYTE (0); ITextFont := NULL;
LeftEdge := t[20]^.LeftEdge; TopEdge := t[20]^.TopEdge;
IText := t[20]^.IText; NextText := t[20]^.NextText;
END;
PrintIText( WinPtr^.RPort^, temp, LGadge[46], TGadge[46] );
NGadge := AddGadget( WinPtr, gPtr[46]^, 20);
END;
(* Refresh all Gadgets to be sure *)
RefreshGadgets( gPtr[0]^, WinPtr, req);
RETURN NoError;
END DEG;
PROCEDURE STO (): ErrorType;
BEGIN
LOOP
Sig1 := Wait (Sig1);
Signal := GetMsg( WinPtr^.UserPort );
Button := Signal^.IAddress;
CGadget := Button^.GadgetID;
IF (CGadget = 0) OR (CGadget = 1) OR (CGadget = 2) OR
(CGadget = 3) OR (CGadget = 4) OR (CGadget = 5) OR
(CGadget = 6) OR (CGadget = 7) OR (CGadget = 8) OR
(CGadget = 9)
THEN stored[CGadget] := X;
EXIT;
END;
END;
RETURN NoError;
END STO;
PROCEDURE RCL (): ErrorType;
BEGIN
LOOP
Sig1 := Wait (Sig1);
Signal := GetMsg( WinPtr^.UserPort );
Button := Signal^.IAddress;
CGadget := Button^.GadgetID;
IF (CGadget = 0) OR (CGadget = 1) OR (CGadget = 2) OR
(CGadget = 3) OR (CGadget = 4) OR (CGadget = 5) OR
(CGadget = 6) OR (CGadget = 7) OR (CGadget = 8) OR
(CGadget = 9)
THEN StackUp;
X := stored[CGadget];
EXIT;
END;
END;
RETURN NoError;
END RCL;
PROCEDURE GOLD (): ErrorType;
VAR NGadge : CARDINAL;
IDontCare : INTEGER;
I : CARDINAL;
BEGIN
(* Remove Gadgets 22 through 33 *)
FOR NGadge := 22 TO 33 DO
IDontCare := RemoveGadget( WinPtr, gPtr[NGadge+TOGGLE]^);
END;
(* Remove the gadget text *)
WITH temp DO
FrontPen := BYTE (0); BackPen := BYTE (0);
DrawMode := BYTE (0); ITextFont := NULL;
NextText := NULL;
END;
FOR I := 22+TOGGLE TO 33+TOGGLE DO
WITH temp DO
LeftEdge := t[I]^.LeftEdge; TopEdge := t[I]^.TopEdge;
IText := t[I]^.IText;
END;
PrintIText( WinPtr^.RPort^, temp, LGadge[I], TGadge[I] );
END;
FOR I := 0 TO 7 DO
WITH temp DO
LeftEdge := ts[I]^.LeftEdge; TopEdge := ts[I]^.TopEdge;
IText := ts[I]^.IText;
END;
IF I=0 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[18], TGadge[18] );
ELSIF I=1 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[26], TGadge[26] );
ELSIF I=2 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[27], TGadge[27] );
ELSIF I=3 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[30], TGadge[30] );
ELSIF I=4 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[34], TGadge[34] );
ELSIF I=5 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[35], TGadge[35] );
ELSIF I=6 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[36], TGadge[36] );
ELSIF I=7 THEN PrintIText( WinPtr^.RPort^, temp, LGadge[38], TGadge[38] );
END;
END;
IF TOGGLE = 0
THEN TOGGLE := 12;
ELSE TOGGLE := 0;
END;
(* Now put in the new Gadgest *)
FOR NGadge := 22 TO 33 DO
IDontCare := AddGadget( WinPtr, gPtr[NGadge+TOGGLE]^, NGadge);
END;
(* Now refresh all gadgets just to be sure *)
RefreshGadgets( gPtr[0]^, WinPtr, req);
RETURN NoError;
END GOLD;
PROCEDURE InitWindow ( VAR wp : WindowPtr; g : GadgetPtr);
BEGIN
CalcName := "HP-10C";
WITH w DO
LeftEdge := 345; TopEdge := 1; Width := 295; Height := 103;
DetailPen := BYTE (0);
BlockPen := BYTE (1);
Title := ADR (CalcName);
Flags := WindowFlagSet {Activate, WindowClose, WindowDrag,
WindowDepth, Refresh1};
IDCMPFlags := IDCMPFlagSet{CloseWindowFlag,MenuPick,GadgetUp};
CheckMark := NULL;
FirstGadget := g;
Type := ScreenFlagSet{WBenchScreen};
Screen := NULL;
BitMap := NULL;
END;
wp := OpenWindow( w );
(* Initialize the signal Mask *)
Sig1 := SignalSet {};
(* Convert signal number to a mask *)
INCL (Sig1, CARDINAL (wp^.UserPort^.mpSigBit));
(* Make local copy of wp *)
WinPtr := wp;
END InitWindow;
END CalcGadgets.