Board index » delphi » Question about the Pen Mode.

Question about the Pen Mode.


2005-05-16 04:29:18 PM
delphi227
Dear ladies and gentlemen,
I used the following codes to draw lines on canvas at run time:
public
FDrawing: Boolean;
FStartP : TPoint;
FEndP : TPoint;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDrawing := False;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = bmLeft then
begin
FDrawing := True;
FStartP := Point(X, Y);
FEndP := Point(X, Y);
Image1.Canvas.Pen.Width := 10;
Image1.Canvas.Pen.Mode := pmNotXor;
end;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FDrawing then
begin
// Erasing the last one.
Image1.Canvas.ModeTo(FStartP.X, FStartP.Y);
Image1.Canvas.LineTo(FEndP.X, FEndP.Y);
FEndPoint := Point(X, Y);
// Drawing the new one.
Image1.Canvas.ModeTo(FStartP.X, FStartP.Y);
Image1.Canvas.LineTo(FEndP.X, FEndP.Y);
end;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if FDrawing then
begin
Image1.Canvas.Pen.Mode := pmCopy;
FDrawing := False;
end;
end;
Please note that I used the pmNotXor as the Pen Mode in order to let the
lines always be appeared in any against background. But if I have two lines,
and the two lines have the same part. In this case, the same part of the two
lines will disappears. it is not what I want. I have tried every mode of the
pen, and nothing satisfies my requirement. Please help me.
Thank you very much.
Best regards.
Xiaoguang
 
 

Re:Question about the Pen Mode.

"Ma Xiaoguang" <XXXX@XXXXX.COM>writes
Quote
lines will disappears. it is not what I want. I have tried every mode of
the
pen, and nothing satisfies my requirement. Please help me.
Don't use pen modes. XOR drawing is a trick from the bad old days and does
not scale up. Also, it works good only with paletted modes and is then
wasteful. With today's hardware, buffering and repainting 2D images is a
breeze. As a general strategy, consider caching as bitmap non-dynamic and/or
overly-complex-to-draw-as-vector parts of a canvas. For large canvasses, you
can use a simple grid approach and/or bounding boxes (quadtrees and such are
rarely necessary imo). For zooms and pans it gets a bit more complex but if
you do it right from the start it will save you lots of headaches.
 

Re:Question about the Pen Mode.

Are there examples (with source) in the net?
"somebody" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote

"Ma Xiaoguang" <XXXX@XXXXX.COM>writes

>lines will disappears. it is not what I want. I have tried every mode of
>the
>pen, and nothing satisfies my requirement. Please help me.

Don't use pen modes. XOR drawing is a trick from the bad old days and does
not scale up. Also, it works good only with paletted modes and is then
wasteful. With today's hardware, buffering and repainting 2D images is a
breeze. As a general strategy, consider caching as bitmap non-dynamic
and/or
overly-complex-to-draw-as-vector parts of a canvas. For large canvasses,
you
can use a simple grid approach and/or bounding boxes (quadtrees and such
are
rarely necessary imo). For zooms and pans it gets a bit more complex but
if
you do it right from the start it will save you lots of headaches.


 

Re:Question about the Pen Mode.

Ma Xiaoguang writes:
Quote

I used the following codes to draw lines on canvas at run time:
<snip>
Please note that I used the pmNotXor as the Pen Mode in order to let the
lines always be appeared in any against background. But if I have two lines,
and the two lines have the same part. In this case, the same part of the two
lines will disappears. it is not what I want. I have tried every mode of the
pen, and nothing satisfies my requirement. Please help me.
I use this XOR technical for all my "{*word*221} banding" task, all the time.
It works well.
I do NOT understand what you are asking, but I assume you mean (with any
exisitng line), if its color is an XOR of new line, it will disappear!
(Well, that is obvious, that is what is supposed do for the
erase/redraw).
So DON"T choose a (XOR) color of your new "{*word*221} band" line that is
anything like the colours being utilised currently on the form!
--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia
 

Re:Question about the Pen Mode.

somebody writes:
Quote

"Ma Xiaoguang" <XXXX@XXXXX.COM>writes

Don't use pen modes. XOR drawing is a trick from the bad old days and does
not scale up. Also, it works good only with paletted modes and is then
wasteful. With today's hardware, buffering and repainting 2D images is a
breeze. As a general strategy, consider caching as bitmap non-dynamic and/or
overly-complex-to-draw-as-vector parts of a canvas. For large canvasses, you
can use a simple grid approach and/or bounding boxes (quadtrees and such are
rarely necessary imo). For zooms and pans it gets a bit more complex but if
you do it right from the start it will save you lots of headaches.
No, using a second redraw bitmap is the HIGHEST WASTEFUL technique.
XOR is the standard way for "{*word*221} banding", and is STILL used.
(Also when "{*word*221} banding" is taking place, it is NOT likely that
simultaneously scalling is occuring!)
Using a second Bitmap for a simple "{*word*221} banding" is definitely "using
a cannon to kill an ant".
(Not to flame anyone but, you can tell the programers with low
background, and possibly super high speed computers!!.
I keep saying, develop on a Pentium-1 (one) computer, and be amazed that
it works so much better on a faster machine, than develop on a faster
machine and be astounded it fails on a slower computer!).
--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia
 

Re:Question about the Pen Mode.

Ma Xiaoguang writes:
Quote

Please note that I used the pmNotXor as the Pen Mode in order to let the
lines always be appeared in any against background. But if I have two lines,
and the two lines have the same part. In this case, the same part of the two
lines will disappears. it is not what I want. I have tried every mode of the
pen, and nothing satisfies my requirement. Please help me.

If I understood what you want correctly, just redraw the line with a
different pen style/color in the MouseUp event:
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
//*********************
var
OldPenColor : TColor;
//*********************
begin
if FDrawing then
begin
//*****************************************
OldPenColor := Image1.Canvas.Pen.Color;
Image1.Canvas.Pen.Color := $00AAAAAA;
Image1.Canvas.Pen.Mode := pmMerge;
Image1.Canvas.MoveTo(FStartP.X, FStartP.Y);
Image1.Canvas.LineTo(FEndP.X, FEndP.Y);
Image1.Canvas.Pen.Color := OldPenColor;
//*****************************************
Image1.Canvas.Pen.Mode := pmCopy;
FDrawing := False;
end;
end;
The Color and Mode used are just an example. Change them to get the best
look with your images.
Good luck,
Ronaldo
 

Re:Question about the Pen Mode.

Charles Hacker writes:
Quote

I keep saying, develop on a Pentium-1 (one) computer, and be amazed that
it works so much better on a faster machine, than develop on a faster
machine and be astounded it fails on a slower computer!).
Very true. OTOH, I have found myself trying to fix bugs that didn't occur
on slower machines and happend all the time on faster ones. In all
cases, the general scenario was a dying thread trying to access an
already freed object. Now, my work machine is an AMD-Duron 750MHz with
W98-SE and the test machine is a P-IV 2.4GHz with XP.
Ronaldo
 

Re:Question about the Pen Mode.

"Charles Hacker" <XXXX@XXXXX.COM>wrote
Quote
somebody writes:
>"Ma Xiaoguang" <XXXX@XXXXX.COM>writes
>Don't use pen modes. XOR drawing is a trick from the bad old days and
>does
>not scale up. Also, it works good only with paletted modes and is then
No, using a second redraw bitmap is the HIGHEST WASTEFUL technique.
XOR is the standard way for "{*word*221} banding", and is STILL used.
For {*word*221} banding, you have a good point. I had assumed (maybe erroneously)
that he was using xor drawing for his generic vector needs since he
mentioned multiple overlapping lines.
 

Re:Question about the Pen Mode.

Hi Max,
I haven't upload my codes on the Web. Thanks for your attention for this
question. Please read my new message later. I will explain what I want.
Thank you very much.
Best regards.
Xiaoguang
"Max" <XXXX@XXXXX.COM>writes
Quote
Are there examples (with source) in the net?

"somebody" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
news:XXXX@XXXXX.COM...
>
>"Ma Xiaoguang" <XXXX@XXXXX.COM>writes
>
>>lines will disappears. it is not what I want. I have tried every mode
of
>>the
>>pen, and nothing satisfies my requirement. Please help me.
>
>Don't use pen modes. XOR drawing is a trick from the bad old days and
does
>not scale up. Also, it works good only with paletted modes and is then
>wasteful. With today's hardware, buffering and repainting 2D images is a
>breeze. As a general strategy, consider caching as bitmap non-dynamic
and/or
>overly-complex-to-draw-as-vector parts of a canvas. For large canvasses,
you
>can use a simple grid approach and/or bounding boxes (quadtrees and such
are
>rarely necessary imo). For zooms and pans it gets a bit more complex but
if
>you do it right from the start it will save you lots of headaches.
>
>


 

Re:Question about the Pen Mode.

Hi,
Thank you all for the helps. I think that I haven't explain what I want
clearly. I am interested in the Measure Tool of Photoshop 6 recently. After
we drew the first measure line in Photoshop, press Alt key and click on one
of the two endpoints, Photoshop will draw the second measure line, the two
measure lines were connected. I found that the two lines in Photoshop are
seems like the lines we drawn in Delphi with NotXor Pen Mode. But in Delphi,
if such the two lines are overlapped, when we drawing the two lines, the
overlapped part will be disappeared. How can we drawing the two lines same
as Photoshop?
To handle the problem, I used two different colored lines as the measure
lines. But the two measure lines in Photoshop have the same color. How can
the Photoshop had done that?
Please give me some suggestions. Thank you very much!
Best regards.
Xiaoguang
"Ma Xiaoguang" <XXXX@XXXXX.COM>writes
Quote
Dear ladies and gentlemen,

I used the following codes to draw lines on canvas at run time:

public
FDrawing: Boolean;
FStartP : TPoint;
FEndP : TPoint;

procedure TForm1.FormCreate(Sender: TObject);
begin
FDrawing := False;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button:
TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = bmLeft then
begin
FDrawing := True;
FStartP := Point(X, Y);
FEndP := Point(X, Y);
Image1.Canvas.Pen.Width := 10;
Image1.Canvas.Pen.Mode := pmNotXor;
end;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState;
X,
Y: Integer);
begin
if FDrawing then
begin
// Erasing the last one.
Image1.Canvas.ModeTo(FStartP.X, FStartP.Y);
Image1.Canvas.LineTo(FEndP.X, FEndP.Y);
FEndPoint := Point(X, Y);
// Drawing the new one.
Image1.Canvas.ModeTo(FStartP.X, FStartP.Y);
Image1.Canvas.LineTo(FEndP.X, FEndP.Y);
end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if FDrawing then
begin
Image1.Canvas.Pen.Mode := pmCopy;
FDrawing := False;
end;
end;

Please note that I used the pmNotXor as the Pen Mode in order to let the
lines always be appeared in any against background. But if I have two
lines,
and the two lines have the same part. In this case, the same part of the
two
lines will disappears. it is not what I want. I have tried every mode of
the
pen, and nothing satisfies my requirement. Please help me.

Thank you very much.

Best regards.

Xiaoguang