PDA

View Full Version : Drawing lines with DelphiX



mrpr1989
05-08-2003, 04:29 PM
How can I draw a line with the DelphiX component? I can't see any functions whom does this.

Traveler
05-08-2003, 07:32 PM
This is done quite easily. It's actually not much different from drawing a line on the form's canvas.


procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
//enter coords to the point you start drawing
DXDraw1.Surface.Canvas.MoveTo(10,10);
//enter coords to the endpoint of your line
DXDraw1.Surface.Canvas.LineTo(100,100);
//never forget this line when drawing on the canvas!
DXDraw1.Surface.Canvas.Release;

DxDraw1.Flip;
end;

procedure TForm1.DXDraw1Initialize(Sender: TObject);
begin
DXDraw1.Surface.Canvas.Pen.Color:=clRed;
end;

end.

Just make make you release the canvas again, else bad things will happen.

Displaying a text is should be easy now :D

DXDraw1.surface.Canvas.Textout(100,100,'Welcome to DGDev!');


[Edited by BlueCat - hope you don't mind Traveler, I pascal-ed your code tags :twisted: ]

mrpr1989
05-08-2003, 10:07 PM
Thanks, everything works fine now, except that the background of the text is white.
Does anybody know how to make it black, or even better, transparent :?:

DraculaLin
06-08-2003, 03:05 AM
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
with DXDraw1.Surface.Canvas do
begin
Brush.Style:=bsClear;
Font.Color:=clRed;
TextOut(100,100,'Welcome to DGDev!');
Release;
end;
DXDraw1.Flip;
end;

Traveler
06-08-2003, 07:20 AM
Your code is correct DraculaLin, although I would recommend placing these 2 lines

Brush.Style:=bsClear;
Font.Color:=clRed;

in a initialization procedure, like I did in my sample. There's no need to change the brushstyle and font color every cycle.

mrpr1989
06-08-2003, 11:25 AM
Thanks again, but I've still one more question:
How can I fill everything beneath the lines, very fast.

I've tried with
DXDraw1.Surface.Canvas.FloodFill(400,595,clRed,fsB order);
But that was way to slow.

Traveler
06-08-2003, 11:32 AM
Floodfill is indeed very slow. You'd be better off drawing a rectangle (you must also change the brush style in case you still have the style set to bsclear) or, even better use an image...

mrpr1989
06-08-2003, 11:54 AM
It's just that the lines are random generated and curved. So neither an image or a rectangle would work.

Yin
14-11-2003, 11:15 PM
I have no idea if this would be faster, but couldn't you draw a rectangle starting two pixels away (leaving a small hole) from the lowest one in your curved-line-thing, and then floodfill whats left?

atozix
29-11-2003, 05:39 AM
hi ALLLLLLLL :)

Now the answers here all work very well....

BUT here is a further question..

How can you draw lines and/or text so they appear on top of sprites???

cheeeeeerrrrrrrssssss ato

Avatar
29-11-2003, 08:24 AM
How can you draw lines and/or text so they appear on top of sprites???


Guess you should draw your lines and your text after drawing the sprites ...

I mean, if you have this :

DrawLines;
DrawText;
DrawSprite;

This won't be good ... Just put them in the inverse order :

DrawSprite(draws the sprites first)
DrawLines(then draws the lines on the top of the sprites)
DrawText(and finally, draws the text on the top of the two others)

I don't know if it's what you were looking for ^^
but I hope it helped :)

Bye
Avatar

atozix
29-11-2003, 08:56 PM
Hi Avatar.... :)

Yep , sure was... I was just not seeing the obvious...:)

THX... cheeeeeeeeeeerrrrrrrrrsssssssssss ato