unit Gui;
{Created By Matthew Brittle
2/4/2003}
interface
uses mouse,graph,crt;
type
TickBoxType = Object {tick box object}
Public
Start : Boolean;
Ticked : Boolean; {if box is ticked are not}
Procedure Init(X,Y,X1,Y1,Number : Integer; onof : boolean); {initialize the tick box}
Procedure Run(I : Char; Num : Integer); {run the tick Box}
Procedure Reset;
Private
TX,TY,TX1,TY1 : Integer; {Cordites of tick box}
Tnum : integer; {tab number}
Showed : Boolean; {if it has been shown are not}
End;
TBarObject = Object
Public
X,Y,X1,Y1 : Integer;
Paint : Boolean;
Procedure Init(xx,yy,xx1,yy1 : integer);
Procedure Run;
Procedure RePaint;
end;
BObject = Object {button object}
Public
pressed : Boolean; {if the button has been pressed}
clicked : Boolean; {if button has been clicked}
Show : Boolean; {if button has been shown}
Procedure Init(AX,AY,AX1,AY1,Num : Integer; Nam : String; colour : word; BType : Integer); {initialize button}
Procedure Reset; {reset the button to default}
Procedure Run(Num : Integer; Var I : Char); {run the button}
Procedure SetName(Names : String); {change name of button}
Private
BNumber : Integer; {tab number}
col : word; { button colour}
Show2 : Boolean; {if the button down image has been shown}
X,Y,X1,Y1 : Integer; {button coordinates}
Name : String[20]; {button name}
Buttype : Integer; {square edges or round 1 or 2}
Procedure Button_In; {draw button in}
Procedure Button_Out;{draw button out}
Procedure Button_In2;{draw button in}
Procedure Button_Out2;{draw button out}
End;
DDMObject = Object {drop down menu object}
Public
OButton : Array [1..10] Of BObject; {list of all buttons}
TButton : Array [1..10] Of String[20]; {list of all button names}
DropMenuOpen : Boolean; {true if menu is open}
MButton : BObject; {the main button to click for menu to drop down}
Procedure Init(AX,AY,AX1,AY1,Num : Integer; Nam : String; Colour : Word); {set up drop down menu}
Procedure Open; {open drop down menu}
Procedure Close; {close drop down menu}
Procedure Run(i : Char); {run drop down menu}
Private
ButtonPos : Integer;
Size : Integer;
Image : Pointer; {get image behind the menu}
X,Y,X1,Y1 : Integer; {menu coordinates}
Name: String; {name of button}
NumberOfButtons : Integer; {number of buttons in menu}
Col : Word; {buttons colour}
End;
TTextBox = Object {text box object}
Public
TextString : String[50]; {max length of text in box}
number : integer; {tab number}
CursorPoiter : Integer; {where the cursor is in the textbox}
Shown : Boolean; {if it has been shown}
Select : Boolean; {if it is selected}
Procedure Init(AX,AY,AX1,AY1,Num : Integer); {set up text box}
Procedure Run(Var tab : Integer; Var I : Char); {run the text box}
Procedure Reset; {reset box}
Private
X,Y,X1,Y1 : Integer; {cordinets}
MaxLength : Integer;
TextNum: Integer;
TextPart1,TextPart2 : String[50]; {store the text before and after cursor}
End;
boxselection = object
Public
Selected : Boolean; {if an option has been selected}
Selection : Integer; {the number of option sleeted}
BoxNames : Array[1..10] Of String; {the names of the options}
Procedure Init(Bx,By,Bx1,By1,Num1,Num2 : Integer); {set up the box}
Procedure Run(Tab : Integer; I : Char); {run the box}
Procedure Reset;
Private
X,Y,X1,Y1 : Integer; {coordinates of the box selection}
BNumber : Integer; {the number of the box Selection}
NNumber : Integer; {the number of options}
Show : Boolean; {if it has been show no screen}
B_Ok : BObject; {a button}
Options: Array[1..10] Of BObject; {an array of buttons}
Open : Boolean; {if it is open or not}
Image : Pointer; {holds and image}
Size : Integer; {gets size of image}
End;
procedure initvga; {set graph mode}
procedure squarof(x,y,x1,y1 : integer); {group items together}
procedure newwindow(x,y,x1,y1 : integer); {a new window at (x,y,x1,y1)}
procedure taskbar(x,y,x1,y1 : integer; outtext : String); {a task bar}
procedure error_box(x,y,x1,y1 : integer; output,output1,output2 : string; soundon : boolean);
{a pop up error dialog box where outputs are the messages and if sound = true then it will bleep}
procedure comformation(x1,y1,x2,y2 : integer; Title,line1,line2 : string;var yesno: boolean; textcol : word);
{A pop up conformation box with ok and cancel buttons}
Procedure Display_Desktop; {display a desktop}
procedure new_box(x,y,x2,y2,col : integer); {like new window}
procedure show_box(x,y,x1,y1 : integer; output : string); {like a text box but the text is read only}
Procedure Panal(X,Y,X1,Y1 : Integer);
implementation
Procedure Panal;
Begin
Setcolor(White);
Line(X,Y,X1,Y);
Line(X,Y,X,Y1);
SetFillStyle(1,7);
Bar(X+1,Y+1,X1-1,Y1-1);
SetColor(8);
Line(X,Y1,X1,Y1);
Line(X1,Y,X1,Y1);
End;
Procedure TbarObject.Init;
begin
Paint:=False;
x:=xx;
y:=yy;
X1:=xx1;
Y1:=yy1;
end;
Procedure TBarObject.run;
Begin;
If Not Paint Then
Begin
Paint:=True;
Panal(X,Y,X1,Y1);
End;
end;
Procedure TbarObject.RePaint;
Begin
Paint:=False;
End;
Procedure TickBoxType.Reset;
Begin
Ticked:=Start;
If Ticked Then Showed:=True else Showed:=False;
End;
Procedure TickBoxType.Init;
Begin
tx:=x;
ty:=y;
tx1:=x1;
ty1:=y1;
Ticked:=onof;
Tnum:=Number;
Showed:=onof;
Start:=OnOf;
End;
Procedure TickBoxType.Run;
Begin
If (I=Chr(13)) And (Tnum=num) Then {if i = enter or tab=num}
Ticked:=Not Ticked;
If LMouseDown Then
If (GetMouseX>=TX) And (GetMouseX<=TX1) And (GetMouseY>=TY) And (GetMouseY<=TY1) Then
Begin
{check that mouse is over box and is pressed}
Ticked:=Not Ticked;
repeat
until not lmousedown;
End;
If Not Ticked And Not Showed then
Begin
HideMouse;
{if box is not shown the display}
Showed:=True;
SetFillstyle(1,7);
Bar(tx+1,ty+1,tx1-1,ty1-1);
SetColor(White);
Line(TX,TY,TX1,TY);
Line(TX,TY,TX,TY1);
SetColor(8);
Line(TX1,TY,TX1,TY1);
Line(TX,TY1,TX1,TY1);
ShowMouse;
End;
If Ticked And Showed then
Begin
HideMouse;
{show the box when ticked}
Showed:=false;
SetFillstyle(1,7);
Bar(tx+1,ty+1,tx1-1,ty1-1);
SetColor(8);
Line(TX,TY,TX1,TY);
Line(TX,TY,TX,TY1);
SetColor(White);
Line(TX1,TY,TX1,TY1);
Line(TX,TY1,TX1,TY1);
ShowMouse;
End;
End;
Procedure BObject.Button_Out;
Begin
HideMouse;
{display round buttons when not pressed}
SetTextJustify(1,1);
SetLineStyle(0,0,2);
setfillstyle(1,col+8);
Bar(X+5,Y+1,X1-5,Y1-1);
Bar(X+1,Y+5,X1-1,Y1-5);
setcolor(col+8);
Pieslice(X1-7,Y+7,0,90,7);
Pieslice(X1-7,Y1-7,270,360,7);
Pieslice(X+7,Y+7,90,180,7);
Pieslice(X+7,Y1-7,180,270,7);
SetColor(White);
Arc(X+7,Y+7,90,180,7);
Arc(X+7,Y1-7,180,225,7);
Arc(X1-7,Y+7,45,90,7);
Line(X+5,Y,X1-5,Y);
Line(X,Y+5,X,Y1-5);
SetColor(col);
Arc(X+7,Y1-7,225,270,7);
Arc(X1-7,Y1-7,270,360,7);
Arc(X1-7,Y+7,0,45,7);
Line(X1,Y+5,X1,Y1-5);
Line(X+5,Y1,X1-5,Y1);
SetColor(Black);
Outtextxy((X1+X) Div 2,(Y+Y1) Div 2,Name);
ShowMouse;
End;
Procedure BObject.Button_In;
Begin
HideMouse;
{display round buttons when pressed}
SetTextJustify(1,1);
setfillstyle(1,col+8);
Bar(X+5,Y+1,X1-5,Y1-1);
Bar(X+1,Y+5,X1-1,Y1-5);
setcolor(col+8);
Pieslice(X1-7,Y+7,0,90,7);
Pieslice(X1-7,Y1-7,270,360,7);
Pieslice(X+7,Y+7,90,180,7);
Pieslice(X+7,Y1-7,180,270,7);
SetColor(Col);
Arc(X+7,Y+7,90,180,7);
Arc(X+7,Y1-7,180,225,7);
Arc(X1-7,Y+7,45,90,7);
Line(X+5,Y,X1-5,Y);
Line(X,Y+5,X,Y1-5);
SetColor(White);
Arc(X+7,Y1-7,225,270,7);
Arc(X1-7,Y1-7,270,360,7);
Arc(X1-7,Y+7,0,45,7);
Line(X1,Y+5,X1,Y1-5);
Line(X+5,Y1,X1-5,Y1);
SetColor(8);
Outtextxy((X1+X) Div 2 +1,(Y+Y1) Div 2 +1,Name);
ShowMouse;
End;
Procedure BObject.Button_In2;
Begin
HideMouse;
{display square buttons when not pressed}
SetTextJustify(1,1);
SetFillStyle(1,Col+8);
Bar(X,Y,X1,Y1);
SetColor(Col);
Line(X,Y,X1,Y);
Line(X,Y,X,Y1);
SetColor(White);
Line(X1,Y,X1,Y1);
Line(X,Y1,X1,Y1);
SetColor(Black);
Outtextxy((X1+X) Div 2 +1,(Y+Y1) Div 2 +1,Name);
ShowMouse;
End;
Procedure BObject.Button_Out2;
Begin
{Display round buttons when pressed}
HideMouse;
SetTextJustify(1,1);
SetFillStyle(1,Col+8);
Bar(X,Y,X1,Y1);
SetColor(White);
Line(X,Y,X1,Y);
Line(X,Y,X,Y1);
SetColor(Col);
Line(X1,Y,X1,Y1);
Line(X,Y1,X1,Y1);
SetColor(8);
Outtextxy((X1+X) Div 2,(Y+Y1) Div 2,Name);
ShowMouse;
End;
Procedure BObject.Init;
Begin
{animalize the button}
X:=AX;
Y:=AY;
X1:=AX1;
Y1:=AY1;
Show:=False;
Show2 := False;
clicked:=False;
Col:=Colour;
Name:=Nam;
pressed:=False;
BNumber:=Num;
ButType:=BType;
End;
Procedure BObject.Reset;
Begin
Init(x,y,x1,y1,BNumber,name,col,ButType);
End;
Procedure BObject.Run;
Begin
clicked:=False;
If Not Show Then {If the button has not been draw then draw the button}
Begin
If ButType=1 Then
Button_Out {Draw The image for the button when not clicked}
Else
Button_Out2;
Show:=True; {the image has been draw show is now true}
Show2:=False;
End;
If (LMouseDown) Then {if the left mouse button is clicked}
If (GetMouseX>X) And (GetMouseX<X1) And (GetMouseY>Y) And (GetMouseY<Y1) Then
Begin {see in the mouse is inside the button}
If Not Show2 Then {if the seconded image has not been show}
Begin
If ButType=1 Then
Button_In {draw button when clicked}
Else
Button_In2;
Show2:=True; {button now shown}
End;
pressed:=True; {The Button Has Been clicked}
End;
If (BNumber = Num) Then
Begin
SetColor(0);
Line( ((X1+X) Div 2) - (8 * Length(Name) Div 2), (Y1+Y) Div 2 + 5,
((X1+X) Div 2) + (8 * Length(Name) Div 2), (Y1+Y) Div 2 + 5);
End
Else
Begin
SetColor(Col+8);
Line( ((X1+X) Div 2) - (8 * Length(Name) Div 2), (Y1+Y) Div 2 + 5,
((X1+X) Div 2) + (8 * Length(Name) Div 2), (Y1+Y) Div 2 + 5);
End;
If pressed And Not LMouseDown Then {if the button pressed and the left mouse is not been clicked}
If (GetMouseX>X) And (GetMouseX<X1) And (GetMouseY>Y) And (GetMouseY<Y1) Then
Begin {see if mouse is inside the button}
pressed:=False; {the button is not pressed anymore}
clicked:=True; {The Button Has now been clicked}
Show:=False;
End
Else
Reset;
If pressed And LMouseDown Then
If (GetMouseX<X) Or (GetMouseX>X1) Or (GetMouseY<Y) Or (GetMouseY>Y1) Then
Reset;
If BNumber=Num Then
If (i=Chr(13)) Then
clicked:=True;
If (i=(Chr(13))) And clicked Then
I:='1';
End;
Procedure BObject.SetName;
Begin
Name:=Names;
End;
Procedure DDMObject.Init;
Var C: Integer;
Begin
{set up drop down menu}
DropmenuOpen:=False;
NumberOfButtons := Num;
X:=AX;
Y:=AY;
X1:=AX1;
Y1:=AY1;
Col:=Colour;
Name:=Nam;
MButton.init(X,Y,X1,Y1,1,Name,Col,2);
ButtonPos:=1;
For C:=1 to NumberOfButtons Do
OButton[C].Init(X,Y+( c * (Y1-Y) ),X1,Y+( (c+1) * (Y1-Y)),C,TButton[C],Col,2)
{Set up all buttons in menu}
End;
Procedure DDMObject.Open;
Var C: Integer;
Begin
{open the menu}
If Not DropMenuOpen Then
Begin
DropMenuOpen:=True;
Size:=ImageSize(X,Y,X1,Y1+(NumberOfButtons*(Y1-Y) ));
GetMem(Image,Size);
HideMouse;
GetImage(X,Y,X1,Y1+(NumberOfButtons*(Y1-Y) ),Image^);
MButton.Reset;
For C:=1 to NumberOfButtons Do
OButton[C].Reset;
ShowMouse;
End;
End;
Procedure DDMObject.Close;
Var C : Integer;
Begin
{close the menu}
If DropMenuOpen Then
Begin
HideMouse;
PutImage(X,Y,Image^,0);
ShowMouse;
FreeMem(Image,Size);
DropMenuOpen:=False;
MButton.Reset;
For C:=1 to NumberOfButtons Do
OButton[C].Reset;
End;
End;
Procedure DDMObject.Run;
Var C : Integer;
Begin
MButton.Run(0,i); {run codin for main button}
If MButton.clicked And Not DropMenuOpen Then
Open;
{if main button pressed then open menu}
If DropMenuOpen Then {If The Drop Down menu has opened then}
Begin
If I = Chr(72) Then
Dec(ButtonPos);
If I = Chr(80) Then
Inc(ButtonPos);
If ButtonPos>NumberOfButtons Then ButtonPos := 1;
If ButtonPos<1 Then ButtonPos:=NumberOfButtons;
For C:= 1 to NumberOfButtons Do
OButton[C].Run(ButtonPos,i);
If (I = Chr(67)) Then
Close;
If LMouseDown Or RMouseDown Then
If (GetMouseX<X) Or (GetMouseX>X1) Or (GetMouseY<Y) Or (GetMouseY>Y+((NumberOfButtons+1) * (Y1-Y))) Then
Close;
{if mouse click outside menu then close}
End;
End;
Procedure BoxSelection.Init;
Var C : Integer; {Counter Variable}
Begin
Selected:=False; {no option has been seleted}
Open:=False; {the box is not open}
BNumber:=Num1; {set the box number}
NNumber:=Num2; {set the number of options}
If NNumber>10 Then {cheak if number of options is <= 10}
NNumber:=10; {if not set nnubmer to 10;}
X:=Bx; {set coridnets}
Y:=By;
X1:=Bx1;
Y1:=By1;
B_Ok.Init(X1-20,Y,X1,Y1,Num1,'\/',Green,2); {set up the button for the box}
Show:=False; {the box has not been shown}
For C:=1 To NNumber Do {loop until c = number}
Options[C].Init(X,Y1+((Y1-Y)*(C-1)),X1,Y1+((Y1-Y)*C),C,BoxNames[C],7,2); {set up all options}
End; {end procedure init}
Procedure BoxSelection.Run;
Var C,C1 : Integer; {Counter Variables}
Begin
If Not Show Then
Begin
Show_Box(X-1,Y,X1-20,Y1-1,'');
Show:=True;
End;
If Not Open Then
Begin
B_Ok.Run(Tab,I);
If B_Ok.Clicked Then
Begin
Selection:=1;
Open := True;
HideMouse;
Size:=ImageSize(X,Y1,X1,Y1+((Y1-Y)*NNumber));
GetMem(Image,Size);
GetImage(X,Y1,X1,Y1+((Y1-Y)*NNumber),Image^);
ShowMouse;
End;
End;
If Open Then
Begin
If I=Chr(80) Then
Inc(Selection);
If I=Chr(72) Then
Selection:=Selection-1;
If Selection>Nnumber Then
Selection:=1;
If Selection <1 Then
Selection:=NNumber;
For C:=1 To NNumber Do
Options[C].Run(Selection,I);
If Open Then
For C:=1 To NNumber Do
If Options[C].Clicked Then
Begin
HideMouse;
Selected:=True;
PutImage(X,Y1,Image^,0);
FreeMem(Image,Size);
Open:=False;
Show_Box(X-1,Y,X1-20,Y1-1,BoxNames[C]);
Selection:=c;
For C1:=1 To NNumber Do
Options[C1].Reset;
ShowMouse;
End;
End;
End;
Procedure Boxselection.Reset;
Begin
init(X,Y,X1,Y1,BNumber,NNumber);
End;
Procedure show_box;
Begin
{output text in a text box}
setfillstyle(1,white);
bar(x+1,y+1,x1-1,y1-1);
setcolor(0);
line(x,y,x1,y);
line(x,y,x,y1);
setcolor(7);
line(x,y1,x1,y1);
line(x1,y,x1,y1);
settextjustify(0,1);
Outtextxy(x+2,round((y+y1)/2),output);
End;
procedure initvga;
var a,b : integer;
begin
a:=detect;
InitGraph(a,b,'.\bgi');
{set graph mode}
end;
procedure squarof;
begin
{group boxes together}
setcolor(darkgray);
line(x,y,x1,y);
line(x,y,x,y1);
line(x1,y,x1,y1);
line(x,y1,x1,y1);
setcolor(white);
line(x+1,y+1,x1-1,y+1);
line(x+1,y+1,x+1,y1);
line(x1+1,y+1,x1+1,y1+1);
line(x+1,y1+1,x1-1,y1+1);
end;
procedure newwindow;
const h=10;
begin
{place a new window on the screen}
SetFillStyle(1,Blue);
SetColor(blue);
Line(x,y1,x1,y1);
Line(X+1,Y,X+1,Y1);
Line(X1,Y,X1,Y1-1);
Arc(X1-7,Y,0,90,7);
Line(X+2,Y+H,X1-2,Y+H);
SetFillStyle(1,LightBlue);
SetColor(LightBlue);
Line(x+1,y1-1,x1-2,y1-1);
Line(X,Y,X,Y1);
Line(X1-1,Y,X1-1,Y1-1);
Arc(X+7,Y,90,180,7);
PieSlice(X1-8,Y,0,90,7);
PieSlice(X+7,Y,90,180,7);
Bar(X+7,Y-7,X1-7,Y+H-1);
Bar(X,Y,X+7,Y+H-1);
Bar(X1,Y,X1-7,Y+H-1);
SetFillStyle(1,3);
Bar(X+2,Y+H+1,X1-2,Y1-2);
end;
procedure new_box;
begin
hidemouse;
setfillstyle(1,col+8);
setcolor(col+8);
pieslice(x+8,y+8,0,360,7);
pieslice(x2-8,y+8,0,360,7);
bar(x+11,y,x2-11,y2);
bar(x,y+11,x2,y2);
setcolor(col);
setlinestyle(0,0,3);
line(x,y2-1,x2-1,y2-1);
line(x+1,y+10,x+1,y2-1);
line(x2-1,y+10,x2-1,y2);
setlinestyle(0,0,0);
taskbar(x,y,x2,y+15,'');
showmouse;
end;
Procedure TaskBar;
Begin
{place a task bar on screen usually at the top}
HideMouse;
SetFillStyle(1,9);
Bar(X,Y+1,X1,Y1);
SetColor(11);
Line(X,Y,X1,Y);
Line(X,Y1-1,X1,Y1-1);
Line(X + ((X1-X) Div 3),Y+4,X1 - ((X1-X) Div 3),Y+4);
Line(X + ((X1-X) Div 3),Y1-4,X1 - ((X1-X) Div 3),Y1-4);
Line(X + ((X1-X) Div 5),Y+7,X + ((X1-X) Div 3)+10,Y+7);
Line(X1 - ((X1-X) Div 5),Y+7,X1 - ((X1-X) Div 3)-10,Y+7);
Line(X + ((X1-X) Div 5),Y1-7,X + ((X1-X) Div 3)+10,Y1-7);
Line(X1 - ((X1-X) Div 5),Y1-7,X1 - ((X1-X) Div 3)-10,Y1-7);
Line(X,(Y1+Y) Div 2+1,X+(X1-X) Div 4,(Y1+Y) Div 2+1);
Line(X1,(Y1+Y) Div 2+1,X1-(X1-X) Div 4,(Y1+Y) Div 2+1);
SetColor(1);
Line(X,Y+1,X1,Y+1);
Line(X,Y1,X1,Y1);
Line(X + ((X1-X) Div 3),Y+5,X1 - ((X1-X) Div 3),Y+5);
Line(X + ((X1-X) Div 3),Y1-3,X1 - ((X1-X)