home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
new
/
amigalibdisks
/
d988
/
dqua
/
source
/
dqua10.pas
next >
Wrap
Pascal/Delphi Source File
|
1994-04-04
|
20KB
|
630 lines
Program DQua;
Uses Exec, Intuition, utility, gadtools, graphics, AmigaDOS, LSKExtras;
Const
LLGad = 1; { NULL initialised gadget }
CCGad = 2; { CreateContext() gadget }
STRGad_A = 3; { `a' string gadget }
STRGad_B = 4; { `b' string gadget }
STRGad_C = 5; { `c' string gadget }
Abt_Gad = 6; { about, ?, gadget }
BUTGad_S = 7; { Solve gadget }
Eqn_Disp = 8; { Gadget with displays Eq'n }
BorTop = 1; BorLeft = 2; BorRight = 3; BorBottom = 4;
DispBB_H = 5; EqBB_H = 6; BB_L = 7; BB_W = 8; StrG_W = 9; GadTxt_W = 10;
XSze = 11; TBS = 12; Abt_W = 13;
Vers : string = '$VER: DQua v1.0 © Lee S Kindness 23.11.93'#0;
Win_Title : string = 'DQua v1.0'#0;
Scr_Title : string = 'DQua, the de-quaderator. ©94 Lee Kindness'#0;
fontname : string = 'topaz.font'#0;
gad1text : string = '_a :'#0;
gad2text : string = '_b :'#0;
gad3text : string = '_c :'#0;
butgadtext : string = '_Solve'#0;
AbtGStr : string = '_?'#0;
defnum : string = '1'#0;
infotext : string = ' ax² + bx + c = 0'#0;
SampStr : string = 'b : '#0;
SampOut : string = 'Imaginary roots at 0.000000098'#0;
visualinf : pointer = NIL;
TheWindow : pWindow = NIL;
Var
Gads : Array [LLGad..Eqn_Disp] Of pGadget;
Gadgetflags : tNewGadget;
My_Font : tTextAttr;
BevelTags : Array[1..3] Of tTagItem;
Sizes : Array[1..13] Of Integer;
{ ===================================================================== }
{ ===================================================================== }
Procedure ErrExit(Errortxt : string; ExitCode : integer);
Begin
ErrorExit('** DQua Error **'#0, Errortxt);
CloseLibrary(pLibrary(IntuitionBase));
If GadToolsBase <> NIL then CloseLibrary(pLibrary(GadtoolsBase));
If TheWindow <> NIL then CloseWindow(TheWindow);
If gads[LLGad] <> NIL then FreeGadgets(gads[LLGad]);
If VisualInf <> NIL then FreeVisualInfo(VisualInf);
Halt(exitcode);
end;
{ ===================================================================== }
Procedure open_libs; { open used libraries }
Begin
IntuitionBase := NIL;
IntuitionBase := pIntuitionBase(OpenLibrary('intuition.library',34));
if IntuitionBase = NIL then halt(122);
If IntuitionBase^.LibNode.lib_Version < 36 Then
ErrExit('Intuition library v36 (2.0) required'#0, 122);
GadToolsBase := NIL;
GadToolsBase := pLibrary(Openlibrary('gadtools.library',36));
If GadtoolsBase = NIL Then
ErrExit('GadTools library v36 (2.0) required'#0, 122);
End;
{ ===================================================================== }
Procedure displayBevelboxes; { used to display and refresh the boxes }
Begin { output }
DrawBevelBoxA(TheWindow^.RPort, Sizes[BB_L], Sizes[TBS] + 4 + Sizes[EqBB_H], Sizes[BB_W], Sizes[DispBB_H], @Beveltags);
End;
{ ===================================================================== }
Procedure setupbevelBoxes; { set up boxes }
Begin
Beveltags[1].ti_Tag := GT_VisualInfo;
BevelTags[1].ti_Data := LONG(VisualInf);
BevelTags[2].ti_Tag := GTBB_Recessed;
BevelTags[2].ti_Data := True_;
BevelTags[3].ti_Tag := TAG_END;
End;
{ ===================================================================== }
Procedure open_window;
Const
PubName : string = 'error';
Var
Window_Tags : Array[0..17] Of tTagItem;
Gadget_Tags : Array[0..2] Of tTagItem;
sampTxt : tIntuiText;
screendef : pScreen;
LockKey : Longint;
PS_List : pList;
My_Node : pPubScreenNode;
Begin
gads[LLGad] := NIL;
{ Get visual info and create context }
LockKey := LockIBase(0);
screendef := IntuitionBase^.ActiveScreen;
PS_List := LockPubScreenList;
My_Node := pPubScreenNode(PS_List^.lh_Head);
While My_Node^.psn_Node.ln_Succ <> NIL Do Begin
If my_Node^.psn_Screen = screendef Then
PubName := retrievestr(My_Node^.psn_Node.ln_Name);
My_Node := pPubScreenNode(My_Node^.psn_Node.ln_Succ);
End;
UnLockPubScreenList;
UnlockIBase(LockKey);
If pubname = 'error' Then Begin
screendef := lockPubScreen(NIL);
If screendef = NIL Then
ErrExit('Failed to lock public screen'#0, 0);
End Else Begin
pubname := pubname + #0;
screendef := lockPubScreen(@PubName[1]);
If screendef = NIL Then
ErrExit('Failed to lock public screen'#0, 0);
End;
VisualInf := GetVisualInfoA(screendef, NIL);
If visualinf = NIL Then
ErrExit('Failed to get visual info'#0, 0);
Gads[CCGad] := CreateContext(@gads[LLGad]);
If Gads[CCGad] = NIL Then
ErrExit('Failed to create context'#0, 0);
{ Get some data from the screen }
My_Font := Screendef^.Font^;
Sizes[TBS] := screendef^.WBorTop + (screendef^.Font^.ta_YSize + 1);
Sizes[XSze] := Sizes[TBS] + 1;
sizes[BorTop] := Screendef^.WBorTop;
sizes[BorLeft] := Screendef^.WBorLeft;
sizes[BorRight] := Screendef^.WBorRight;
sizes[BorBottom] := Screendef^.WBorBottom;
Sizes[StrG_W] := My_Font.ta_YSize * 12;
Sizes[DispBB_H] := (Sizes[XSze] * 3) + 8;
Sizes[EqBB_H] := Sizes[XSze] ;
Samptxt.ITextFont := @My_Font;
Samptxt.IText := @Sampstr[1];
Sizes[GadTxt_W] := IntuiTextLength(@Samptxt) + 10;
Samptxt.IText := @SampOut[1];
Sizes[BB_W] := IntuiTextLength(@Samptxt) + 4;
Samptxt.IText := @AbtGStr[1];
Sizes[Abt_W] := IntuiTextLength(@Samptxt);
Sizes[BB_L] := Sizes[BorLeft] + Sizes[Gadtxt_W] + Sizes[StrG_W] + 4;
{ Initilise gadget structures }
Gadget_Tags[0].ti_Tag := GTST_String;
Gadget_Tags[0].ti_Data := LONG(@defnum[1]);
Gadget_Tags[1].ti_Tag := GT_UnderScore;
Gadget_Tags[1].ti_Data := LONG('_');
Gadget_Tags[2].ti_Tag := TAG_END;
With GadgetFlags Do Begin
ng_TextAttr := @My_Font;
ng_LeftEdge := sizes[BorLeft] + Sizes[GadTxt_W];
ng_TopEdge := Sizes[TBS] + 2;
ng_Width := Sizes[StrG_W];
ng_Height := Sizes[XSze];
ng_GadgetText := @gad1text[1];
ng_VisualInfo := VisualInf;
ng_GadgetID := STRGad_A;
End;
{ create gadgets }
Gads[STRGad_A] := CreateGadgetA(STRING_KIND, Gads[CCGad], @Gadgetflags, @Gadget_Tags);
With GadgetFlags Do Begin
ng_TopEdge := ng_TopEdge + Sizes[XSze] + 2;
ng_GadgetText := @gad2text[1];
ng_GadgetID := STRGad_B;
End;
Gads[STRGad_B] := CreateGadgetA(STRING_KIND, Gads[STRGad_A], @Gadgetflags, @Gadget_Tags);
With GadgetFlags Do Begin
ng_TopEdge := ng_TopEdge + Sizes[XSze] + 2;
ng_GadgetText := @gad3text[1];
ng_GadgetID := STRGad_C;
End;
Gads[STRGad_C] := CreateGadgetA(STRING_KIND, Gads[STRGad_B], @Gadgetflags, @Gadget_Tags);
With gadgetflags Do Begin
ng_LeftEdge := Sizes[BorLeft] + 4;
ng_TopEdge := ng_TopEdge + Sizes[XSze] + 2;
ng_Width := Sizes[Abt_W];
ng_Height := (Sizes[EqBB_H] + Sizes[DispBB_H] + Sizes[TBS] + 6 + Sizes[BorBottom]) - ng_TopEdge - 4;
ng_GadgetText := @AbtGStr[1];
ng_GadgetID := Abt_Gad;
End;
Gadget_Tags[0].ti_Tag := TAG_IGNORE;
Gads[Abt_Gad] := CreateGadgetA(BUTTON_KIND, Gads[STRGad_C], @Gadgetflags, @Gadget_Tags);
With gadgetflags Do Begin
ng_LeftEdge := Sizes[BorLeft] + Sizes[Abt_W] + 8;
ng_Width := Sizes[BB_L] - Sizes[BorLeft] - 12 - sizes[Abt_W];
ng_Height := (Sizes[EqBB_H] + Sizes[DispBB_H] + Sizes[TBS] + 6 + Sizes[BorBottom]) - ng_TopEdge - 4;
ng_GadgetText := @butgadtext[1];
ng_GadgetID := BUTGad_S;
End;
Gads[BUTGad_S] := CreateGadgetA(BUTTON_KIND, Gads[Abt_Gad], @Gadgetflags, @Gadget_Tags);
With GadgetFlags Do Begin
ng_LeftEdge := Sizes[BB_L];
ng_TopEdge := Sizes[TBS] + 2;
ng_Width := Sizes[BB_W];
ng_Height := Sizes[EqBB_H];
ng_GadgetText := NIL;
ng_GadgetID := Eqn_Disp;
End;
Gadget_Tags[0].ti_Tag := GTTX_Text;
Gadget_Tags[0].ti_Data := LONG(@infotext[1]);
Gadget_Tags[1].ti_Tag := GTTX_Border;
Gadget_Tags[1].ti_Data := True_;
Gads[Eqn_Disp] := CreateGadgetA(TEXT_KIND, Gads[BUTGad_S], @Gadgetflags, @Gadget_Tags);