home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_PAS
/
XLIB_TP5.ZIP
/
DEMO
/
X_DEMO.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1993-12-19
|
14KB
|
400 lines
(* All these Compiler-directives make the EXE smaler , but the error would
be more invisible . *)
{$D-,Y-,R-,S-,O-}
uses crt,X_Const,X_Main,X_Text,X_Button,X_Bitmap,X_Keys,X_Mouse,X_Break,
X_Menu,X_polygon,X_Pal,X_Rect;
const Font0=2;
Font1=2;
var dummy:Boolean;
procedure Part_A;
label A_End; (* Ok, it's not fine - but easy to manage. *)
var a:Char;
s:String;
i:Byte;
r,x:Integer;
r1,r2:Word;
begin;
ClrScr;
WriteLn('First you have to set the VideoMode :'#13#10);
WriteLn(' with x_set_mode(mode,Screen_Width:Word); from X_Lib'#13#10);
WriteLn('Modes are used by XLib (all with 256 Colors):');
for i:=0 to x_Max_Modi do
begin;
x_Mode_Info(i,r1,r2);
Write(i:4,' = ',r1:3,' x ',r2:3,' ');
if odd(i) then WriteLn;
end;
WriteLn('Dont forget, we have only 256 KB on VGA-card, you can calculate the');
WriteLn('numbers of videopages in any mode.');
WriteLn('With the 2ed argument, a virtuell Screen-Width will be set.');
WriteLn('But now, I will call x_set_mode(8,360); (Space).');
repeat a:=ReadKeys; until a in [Space,ESC];if a=ESC then goto A_End;
x_set_mode(8,360);
x_ClearAll;
x_Set_RGB_Pal;
x_set_font(Font1);
E_Write(10,10,Gray5,Gray3,'Well, we are in Graphic Mode.');
E_Write(10,2*x_font_height,Gray5,Gray3,'I will show you the importenst variables of X_Const :');
E_Write(10,4*x_font_height,Gray5,Gray3,'InGraphics :');
if InGraphics then s:='True' else s:='false';
E_Write(150,4*x_font_height,Gray5,Gray3,s);
E_Write(180,4*x_font_height,Gray5,Gray3,'CurrXMode :');
E_WriteInt(330,4*x_font_height,Gray5,Gray3,CurrXMode);
E_Write(10,5*x_font_height,Gray5,Gray3,'GetMaxX :');
E_WriteInt(150,5*x_font_height,Gray5,Gray3,GetMaxX);
E_Write(180,5*x_font_height,Gray5,Gray3,'GetMaxY :');
E_WriteInt(330,5*x_font_height,Gray5,Gray3,GetMaxY);
E_Write(10,6*x_font_height,Gray5,Gray3,'MaxScrollX :');
E_WriteInt(150,6*x_font_height,Gray5,Gray3,MaxScrollX);
E_Write(180,6*x_font_height,Gray5,Gray3,'MaxScrollY :');
E_WriteInt(330,6*x_font_height,Gray5,Gray3,MaxScrollY);
E_Write(10,7*x_font_height,Gray5,Gray3,'ScreenOfs is now 0, but this is the variable to the start-');
E_Write(10,8*x_font_height,Gray5,Gray3,'adress of the activ videopage. Every procedure, which work');
E_Write(10,9*x_font_height,Gray5,Gray3,'directly with the Videomemory begins on this address.');
E_Write(10,10*x_font_height,Gray5,Gray3,'You wont to see the Power of Mode X now, Ok.');
repeat a:=ReadKeys; until a in ['Y','J',Space,ESC];if a=ESC then goto A_End;
E_Write(10,300,Gray5,Gray3,'ScreenOfs :');
E_Write(10,320,Gray5,Gray3,'x_set_visible_start_addr(0,');
i:=0;r:=1;x:=x_Length('x_set_visible_start_addr(0,')+10;
repeat
Inc(i,r);
if i+2>MaxScrollY then r:=-1;
if i=0 then r:=1;
{str(i,s);}s:=str(i)+');';
WaitVsyncStart;
x_set_visible_start_addr(0,i);
Box(x,300,x+100,340,0);
E_WriteInt(x,300,Gray5,Gray3,ScreenOfs);
E_Write(x,320,Gray5,Gray3,s);
until KeysPressed;
repeat a:=ReadKeys; until a in [Space,ESC];if a=ESC then goto A_End;
Box(0,299,400,340,0);
x_set_visible_start_addr(0,0);
E_Write(10,12*x_font_height,Gray5,Gray3,'Now the same scrolling.');
repeat a:=ReadKeys; until a in ['Y','J',Space,ESC];if a=ESC then goto A_End;
i:=0;r:=1;x:=x_Length('x_set_visible_start_addr(0,')+10;
if 10+x_Length('x_set_activ_start_addr(0,')>x then x:=x_Length('x_set_activ_start_addr(0,')+10;
i:=0;r:=2;
repeat
Inc(i,r);
if i+2>MaxScrollY then r:=-2;
if i<2 then r:=2;
{str(i,s);}s:=str(i)+');';
WaitVsyncStart;
x_set_visible_start_addr(0,i);
x_set_activ_start_addr(0,i);
Box(0,299,400,360,0);
E_Write(10,300,Gray5,Gray3,'ScreenOfs :');
E_WriteInt(100,300,Gray5,Gray3,ScreenOfs);
E_Write(10,320,Gray5,Gray3,'x_set_visible_start_addr(0,'+S);
E_Write(10,340,Gray5,Gray3,'x_set_activ_start_addr(0,'+s);
until KeysPressed;
repeat a:=ReadKeys; until a in [Space,ESC];if a=ESC then goto A_End;
Box(0,250,getMaxX,GetMaxY,0);
x_set_visible_start_addr(0,0);
x_set_activ_start_addr(0,0);
E_Write(10,13*x_font_height,Gray5,Gray3,'Yeahh - flickering is terrible ? The Font is to Big.');
E_Write(10,14*x_font_height,Gray5,Gray3,'What the next function on X_Lib ?');
E_Write(10,16*x_font_height,Gray5,Gray3,'PutPixel(x,y:Word;Color:Byte); :');
for i:=1 to 255 do PutPixel(355-random(120),16*x_font_height+random(10),random(255));
E_Write(10,17*x_font_height,Gray5,Gray3,'Line(x1,y1,x2,y2:Word); : ');
for i:=1 to 25 do Line(getMaxX-i*7,17*x_font_height,GetMaxX-60-I*7,19*x_font_height-1,252-i);
E_Write(10,19*x_font_height,Gray5,Gray3,'rectangle(x1,y1,x2,y2,Color:Word); (No fill)');
E_Write(10,20*x_font_height,Gray5,Gray3,'triangle(x1,y1,x2,y2,x3,y3,Color:Word); (No fill)');
E_Write(10,21*x_font_height,Gray5,Gray3,'box(x1,y1,x2,y2,Color:Word);');
E_Write(10,22*x_font_height,Gray5,Gray3,'Shadow_Box(x1,y1,x2,y2,C1,C2,C3:Word); :');
Shadow_Box(260,22*x_font_height,340,23*x_font_height-1,Gray5,Gray4,Gray3);
E_Write(10,23*x_font_height,Gray5,Gray3,'x_circle(x1,y1,r,Color:Word);');
E_Write(10,24*x_font_height,Gray5,Gray3,'x_filled_circle(x1,y1,r,Color:Word);');
repeat a:=ReadKeys; until a in [Space,ESC];if a=ESC then goto A_End;
x_Text_Mode;
A_End:x_Text_Mode;
end;
procedure Part_B;
label B_End;
VAR A:Char;
Z:Byte;
i,x1,x2,x3:Word;
s:String;
begin;
x_set_mode(9,400);
x_ClearAll;
x_Set_RGB_Pal;
x_set_font(Font0);
z:=x_font_height;
E_Write(20,1*z,Gray5,Gray3,'Now, I will init your Mouse for Mode X:');
E_Write(10,3*z,Gray5,Gray3,'MyMouseInit; Define event-handler for ModeX');
E_Write(10,4*z,Gray5,Gray3,'DefineMouseCursor(MyMouseForm,Gray5); Define shape and Color');
E_Write(10,5*z,Gray5,Gray3,'SetMouseWindow(0,0,GetMaxX+4,getMaxY+4); Ok. :-)');
E_Write(20,6*z,Gray5,Gray3,'And now ...');
repeat a:=ReadKeys; until a in [Space,ESC];if a=ESC then goto B_End;
E_Write(10,7*z,Gray5,Gray3,'ShowMouse; ');
E_Write(20,8*z,Gray5,Gray3,'Every Time, you draw to Screen, you hide the mousecursor !');
E_Write(20,9*z,Gray5,Gray3,'In the global variables Mouse_X,Mouse_Y and ButtonStatus');
E_Write(20,10*z,Gray5,Gray3,'from the X_Mouse-unit you can every time read the actuell');
E_Write(20,11*z,Gray5,Gray3,'Position.');
MyMouseInit;
DefineMouseCursor(MyMouseForm,Gray5);
SetMouseWindow(0,0,GetMaxX+4,getMaxY+4);
OldMouseTyp:=true;a:=#0;
ShowMouse;
if IsMouseHidden then
begin;
E_Write(10,12*z,Gray5,Gray3,'if isMouseHidden then ... If return IsMouseHidden after');
E_Write(20,13*z,Gray5,Gray3,'ShowMouse, no Mouse-device are installed. But the X_Mouse-');
E_Write(20,14*z,Gray5,Gray3,'unit do nothing (no hangup), if no mouse present.');
end else
begin;
x1:=x_Length('MouseX: ')+10;x2:=x_Length('MouseX: MouseY: ')+10;
x3:=x_Length('MouseX: MouseY: ButtonStatus: ')+10;
E_Write(10,13*z,Gray5,Gray3,'MouseX: MouseY: ButtonStatus:');
a:=#0;
MouseAction:=False;
repeat
if MouseAction then
begin;
HideMouse;
Box(x1,13*z,x1+20,14*z,0);E_WriteInt(x1,13*z,Gray5,Gray3,MouseX);
Box(x2,13*z,x2+20,14*z,0);E_WriteInt(x2,13*z,Gray5,Gray3,MouseY);
Box(x3,13*z,x3+20,14*z,0);E_WriteInt(x3,13*z,Gray5,Gray3,ButtonStatus);
ShowMouse;
MouseAction:=False;
end;
if keyspressed then a:=ReadKeys;
until a in [Space,ESC];if a=ESC then goto B_End;
HideMouse;
end;
E_Write(10,15*z,Gray5,Gray3,'function InBox(x1,y1,x2,y2):Boolean return true, if Mouse in rectangle.');
E_Write(20,16*z,Gray5,Gray3,'With this function, we could program a Mouse-Button, but these is');
E_Write(20,17*z,Gray5,Gray3,'the X_Button unit.');
rectangle(100,Z*18,260,z*20,Gray4);
MouseAction:=false;a:=#0;
repeat
if MouseAction then
begin;
if InBox(100,Z*18,260,z*20) then s:='InBox(..)=True'
else s:='InBox(..)=False';
HideMouse;
Box(1,z*19,99,z*20,0);
E_Write(1,z*19,Gray5,Gray3,s);
ShowMouse;
MouseAction:=False;
end;
if keyspressed then a:=ReadKeys;
until a in [Space,ESC];if a=ESC then goto B_End;
HideMouse;
x_ClearAll;
x_Set_font(Font0);
E_Write(20,Z*2,Gray5,Gray3,'Now the mean idea of X_Button. It`s a dynamic Buttonmanager.');
E_Write(10,Z*3,Gray5,Gray3,'Add_Button(ID ,');E_Write(150,Z*3,Gray5,Gray3,'(* any number to identivication *)');
E_Write(10,Z*4,Gray5,Gray3,' x,y : Word;');E_Write(150,Z*4,Gray5,Gray3,'(* Position *)');
E_Write(10,Z*5,Gray5,Gray3,'C1,C2,C3,high,low : Byte;');E_Write(150,Z*5,Gray5,Gray3,'(* Box 1-3,Char,CharShadow - Color *)');
E_Write(10,Z*6,Gray5,Gray3,' Mask : Byte;');E_Write(150,Z*6,Gray5,Gray3,'(* MouseButton - Mask see doc *)');
E_Write(10,Z*7,Gray5,Gray3,' S : String);');E_Write(150,Z*7,Gray5,Gray3,'(* name on the Button *)');
E_Write(10,Z*8,Gray5,Gray3,'Add_Button_Gray(ID,x,y,mask,s); (* In X_Const exist variables *)');
E_Write(10,Z*9,Gray5,Gray3,' (* named Gray0...Gray5 *)');
E_Write(20,Z*10,Gray5,Gray3,'For example: ');
E_Write(10,Z*11,Gray5,Gray3,'Add_Button_Gray(1,300,300,all,'#39'Hello'#39');');
dummy:=Add_Button_Gray(1,300,300,all,'Hello');
ShowMouse;
repeat a:=ReadKeys; until a in [Space,ESC];if a=ESC then goto B_End;
HideMouse;
E_Write(20,Z*12,Gray5,Gray3,'Uhhh - nothing happens on the button ? Jeahh.');
E_Write(20,Z*13,Gray5,Gray3,'You have to <watch> the button with the function');
E_Write(10,Z*14,Gray5,Gray3,'Get_Pressed_Button :ID_Typ; Returns the selected Button');
E_Write(20,Z*15,Gray5,Gray3,'or zero, if nothing chossed.');
E_Write(20,Z*16,Gray5,Gray3,'For example :');
E_Write(10,Z*17,Gray5,Gray3,'repeat; i:=Get_pressed_Button; until keyspressed; (* Click now *)');
ShowMouse;
repeat; i:=Get_pressed_Button; until keyspressed;
Clear_Buffer;
HideMouse;
E_Write(10,Z*19,Gray5,Gray3,'Add_ButtonInt_Gray in a loop :');
x1:=10+x_Length('Add_ButtonInt_Gray in a loop :');
for i:=2 to 40 do dummy:=Add_ButtonInt_Gray(i,((i-2) mod 10)*36+10,((i-2) div 10)*z*2+Z*20+5,all,i*100);
E_Write(10,Z*25,Gray5,Gray3,'Kill_Button(ID)'); (* this is the end of a button *)
ShowMouse;
repeat;
i:=Get_pressed_Button;
if i<>0 then
begin;
HideMouse;
Box(x1,z*19,x1+100,z*20,0);
E_WriteInt(x1,z*19,Gray5,Gray3,i*100);
ShowMouse;
end;
until keyspressed;
Clear_Buffer;
HideMouse;
for i:=1 to 40 do dummy:=Kill_Button(i);
B_End:
MyMouseDestroy;
x_Text_Mode;
end;
procedure Part_C;
var M:X_Menu.Menu_Typ;
I:X_Menu.ID_Typ;
a:Char;
merk1,merk2:LongInt;
label C_End;
begin;
X_set_mode(8,400);
x_text_init;
x_ClearAll;
x_Set_RGB_Pal;
x_set_font(Font0);
MyMouseInit;
DefineMouseCursor(MyMouseForm,Gray5);
SetMouseWindow(0,0,GetMaxX+4,getMaxY+4);
OldMouseTyp:=true;
(* Init the variable of the menu . *)
X_Init_Menu(M,Gray5,Gray4,Gray3,Gray2,Gray0,Gray2,3);
(* Add the Menulines *)
X_Add_Menu(M,1,'Hallo','H');
X_Add_Menu(M,2,'hIhghi','i');
X_Add_Menu(M,3,'hhhOhoho','o');
X_Add_Menu(M,4,'Jeah','j');
X_Add_Menu(M,5,'Juh«'+str(Gray5)+'»u','u');
X_Add_Menu(M,6,'J«'+str(Gray5)+'»e«o»llaug','e');
X_Add_Menu(M,7,'Ende (X)','x');
X_Show_Menu(M,10,10);
ShowMouse;
a:=#0;
repeat
i:=Wait_Selected_MenuLine(M); (* wait, until selected or abort *)
if i<>0 then (* What line are selectet ? *)
begin;
HideMouse;
Box(200,10,GetMaxX,30,0);
E_Write(150,10,Gray5,Gray3,'selected line :'+str(i));
ShowMouse;
delay(10);
if i=7 then a:=ESC;
end
else a:=ESC;
until a =ESC;
C_End:
X_Kill_Menu(M);
HideMouse;
MyMouseDestroy;
x_Text_Mode;
end;
procedure Part_D;
const Max_Points = 10;
var i,j:Word;
P:Array[0..Max_Points] of Point;
a:Char;
Line_Color:Array[0..1100] of Byte;
label D_End;
begin;
x_set_mode(8,368);
x_set_rgb_pal;
for i:=0 to 1100 do Line_Color[i]:=(i div 8) and $FF;
repeat;
x_triangleCol(random(GetMaxX-10)+5,random(GetMaxY-10)+5,
random(GetMaxX-10)+5,random(GetMaxY-10)+5,
random(GetMaxX-10)+5,random(GetMaxY-10)+5,
Line_Color[random(40)*16]);
until keyspressed;a:=ReadKeys;
x_ClearAll;
E_Write(10,GetMaxY-x_font_height,Gray5,Gray3,'Correct only with convex polygons.');
repeat
j:=random(Max_Points-5)+4;
for i:=0 to j do
begin;
P[i].x:=random(GetMaxX-10)+5;
P[i].y:=random(GetMaxY-50)+5;
end;
X_poly(P,j,random(250));
until keyspressed;a:=ReadKeys;
D_End:
x_Text_Mode;
end;
{$F+}
procedure MyBreakProcedure;
begin;
MyMouseDestroy;
x_Text_Mode;
WriteLn('He, what`s going on ? Do you like DOS more than Mode X ?');
Halt;
end;
{$F-}
{$I timpani.inc} (* created by FEX *)
var a:Char;
P:Pointer;
begin;
InitBreak(MyBreakProcedure);
x_text_init;
x_register_userfont(Font_timpani);
x_set_font(2);
repeat
ClrScr;
WriteLn('Mode X - Demo : How do you program with XLib in Turbo Pascal.');
WriteLn;
WriteLn(' A : X_Const and X_Lib.');
WriteLn(' B : X_Mouse and X_Button');
WriteLn(' C : X_Menu ');
WriteLn(' D : X_Triangle and X_Triangle');
WriteLn(#10#13' End : Anytime with Ctrl+Break or now with ESC');
WriteLn('Type Char to select');
a:=Upcase(ReadKeys);
case a of
'A':Part_A; 'B':Part_B; 'C':Part_C; 'D':Part_D;
end;
until a=ESC;
RestoreBreak;
end.