Board index » delphi » Problem with dragging text

Problem with dragging text


2006-02-27 07:32:53 PM
delphi214
Hello there!
I cannot get a text string to be dragged on a TCanvas using the
{DrawInPreviousPosn DrawInNewPosn} approach without leaving a trail of
previous renderings. It appears that setting the canvas pen mode to pmNotXor
does not affect the rendering of characters in the same way as it affects
the rendering of lines. In fact in the following event handler I would
expect to see the string alternately erased, but this is not the case.:
procedure TForm1.Button1Click(Sender: TObject);
var
PenMode: TPenMode;
begin
PenMode:= Paintbox1.Canvas.Pen.Mode;
Paintbox1.Canvas.Pen.Mode:= pmNotXOr;
Paintbox1.Canvas.TextOut(20, 20, 'Mystring');
Paintbox1.Canvas.Pen.Mode:= Penmode;
end;
end;
In the following MouseMove event handler one observes the correct behaviour
only for the box, while the label leaves a trail in its wake.
procedure TForm1.PaintBox1DragLabelMouseMove(Sender: TObject; Shift:
TShiftState;
X, Y: Integer);
begin
if Dragging then
begin
Paintbox1.Canvas.Brush.Style:= bsClear;
{Replot label and box in previous position to erase:}
Paintbox1.Canvas.TextOut(LabelPosn.x, LabelPosn.Y, DragLabel);
Paintbox1.Canvas.Rectangle(LabelPosn.x, LabelPosn.Y, LabelPosn.x +
LabelWidth, LabelPosn.Y + LabelHeight);
{Plot label and box in new position:}
LabelPosn.X:= x;
LabelPosn.Y:= y;
Paintbox1.Canvas.TextOut(LabelPosn.x, LabelPosn.Y, DragLabel);
Paintbox1.Canvas.Rectangle(LabelPosn.x, LabelPosn.Y, LabelPosn.x +
LabelWidth, LabelPosn.Y + LabelHeight);
end;
end;
Moreover the result depends on the speed of dragging the mouse. This seems
to suggest that when a new OnMouseMove event is fired the drawing code from
the previous event is aborted.
Can anybody explain how text is handled in VCL, and how to draw text?
Thanks in advance,
Enquiring Mind
 
 

Re:Problem with dragging text

In article <XXXX@XXXXX.COM>, Enquiring Mind writes:
Quote
I cannot get a text string to be dragged on a TCanvas using the
{DrawInPreviousPosn DrawInNewPosn} approach without leaving a trail of
previous renderings.

You have to draw the text in the old position using the background color
for Font.Color then redraw text in the new position. This works OK for
plain backgrounds, for complex backgrounds you need to store the
background before drawing the text. You might want to consider two
layers, a background bitmap buffer and a transparent text layer bitmap
buffer.
Gordon
--
www.mgcsoft.com/
 

Re:Problem with dragging text

Thanks for your advice. Does this imply that the method Canvas.TextOut only
works in Copy mode at the pixel level, and that it is not possible to copy
the character image in any other of the modes for combining the previous and
the new colours of an individual pixel?
"Gordon Whittam" <XXXX@XXXXX.COM>writes
Quote
You have to draw the text in the old position using the background color
for Font.Color then redraw text in the new position. This works OK for
plain backgrounds, for complex backgrounds you need to store the
background before drawing the text. You might want to consider two
layers, a background bitmap buffer and a transparent text layer bitmap
buffer.


 

Re:Problem with dragging text

In article <XXXX@XXXXX.COM>, Enquiring Mind writes:
Quote
and that it is not possible to copy
the character image in any other of the modes for combining the previous and
the new colours of an individual pixel?

As far as I know.
Gordon
--
MGCSoft Graphical and equation editors
www.mgcsoft.com/
 

Re:Problem with dragging text

please try TCanvasText
www.codeidea.com
"Enquiring Mind" <XXXX@XXXXX.COM>写入消息新闻:XXXX@XXXXX.COM...
Quote
Thanks for your advice. Does this imply that the method Canvas.TextOut
only works in Copy mode at the pixel level, and that it is not possible to
copy the character image in any other of the modes for combining the
previous and the new colours of an individual pixel?

"Gordon Whittam" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>You have to draw the text in the old position using the background color
>for Font.Color then redraw text in the new position. This works OK for
>plain backgrounds, for complex backgrounds you need to store the
>background before drawing the text. You might want to consider two
>layers, a background bitmap buffer and a transparent text layer bitmap
>buffer.
>
>