.comment-link {margin-left:.6em;}

Tuesday, September 11, 2007

 

wingraph template and demos for free pascal

This is just a simple template that creates the min needed for wingraph to make a window. It also shows some of the limitations of the ide's that are available for pascal.. To use this program_name.py File_to_be_created. I have asked on the bloodshed forums but I suspect that there isn't a way to do it without rebuilding the ide.



import sys

outfile = open(sys.argv[1],'w')
#//need to use the command line
outfile.write("""uses wingraph;
var
gd,gm : smallint;
begin;
gd:=Detect;
InitGraph(gd,gm,'');
//
repeat until CloseGraphRequest; //this waits for close button to be clicked
CloseGraph;
end.""")
#outfile.close()

The following is a new routine for wingraph that makes the outtextx, outtexty behave more like the crt.. for a rougelike or even for a text editor this is a must have procedure.

Procedure crt_out_text(x,y :integer; textstring :shortstring);
//THis is an attempt to imitate the behavior of the crt unit
//x,y is the position in letters not pixels
var
text_height, text_width : integer; //var for text width and height
xx,yy :integer; //use these to calculate pixel x,y of text

// end;
begin;
text_height := TextHeight('H'); //get height
text_width := TextWidth('H'); //get width
xx := (text_width * x) + 1; //calculate the width
yy := (text_height * y) + 1; //calculate the height
OutTextXY(xx,yy,textstring); //send the text out to the screen
end;

It is likely that I will end up with more routines to place in the library because I am getting ready to do some serious retro-gaming-programming. I also am aware of more pascal pages that are not on the wiki yet that are helpfull so look for those in the future. Until then two demos using the procedure and other wingraph command and the template generator are available on the line below. Comments can be directed towards the google group at google group


Heres another routine so that you can write over text.... it "erases the text that is there by drawing a rectangle.... to make it a crt curses like library that you can mix graphics with you would have to mess with GetPixel..

/If you want to get fancy you would save the background and then write it back.. would be a little slower though
var textlength : integer; //this is for the length of the string
loopx, loopy : integer; //this is for the x,y loops
lengthloop : integer; //this is for the length of the text loop
tw, th, twr, thr :integer; //textwidth textheight
begin;
textlength := Length(textstring);
for lengthloop := 1 to textlength do begin;
tw := TextWidth('H');
th := TextHeight('H');
twr := ((tw * x) + (lengthloop * tw) - tw);
thr := th * y;
SetColor(black);
setfillstyle(solidfill,black);
//SetBkColor(black);

Fillrect(twr,thr,twr + tw,thr + th);
end;
SetColor(white);

crt_out_text(x,y,textstring);
end;








download wingraph ext


Labels: ,


Comments: Post a Comment

Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?