Solved

Writing to a TPaintbox Canvas ussing TextOut in XOR mode

Posted on 2003-10-29
10
1,514 Views
Last Modified: 2007-12-19
How can I write text to a canvas in XOR mode - setting

  Pen.Mode := pmNotXOR ;

doesn't have any effect like it does with LineTo.
0
Comment
Question by:rossmcm
  • 4
  • 3
10 Comments
 
LVL 34

Accepted Solution

by:
Slick812 earned 75 total points
ID: 9647401
as you have discovered, the raster-operation code setting for a hDC seting does not effect text drawing, in order to get an inverted text draw, I use the BitBlt( ) function with the SRCINVERT raster-operation code. Here is some code to have inverted text -


procedure TForm1.sbut_DoXORTextClick(Sender: TObject);
var
Bmp1: TBitmap;
begin
Bmp1 := TBitmap.Create;
Bmp1.Canvas.Brush.Color := clBlack;
{to have the SRCINVERT invert the text, you need a Black
background with white text}
Bmp1.Width := 120;
Bmp1.Height := 22;
Bmp1.Canvas.Font.Size := 14;
Bmp1.Canvas.Font.Color := clWhite;
Bmp1.Canvas.TextOut(1,1, 'T E X T Here');
BitBlt(PaintBox1.Canvas.Handle, 5, 5, Bmp1.width, Bmp1.height, Bmp1.canvas.handle, 0,0, SRCINVERT);
Sleep(800);
BitBlt(PaintBox1.Canvas.Handle, 5, 5, Bmp1.width, Bmp1.height, Bmp1.canvas.handle, 0,0, SRCINVERT);
FreeAndNil(Bmp1);
end;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ask questions if you need more information
0
 

Author Comment

by:rossmcm
ID: 9647510
OK we're close.  I can sort of see what you are doing, but I have tried to adopt your code to my aplication and am getting a lot of black rectangles.  Maybe I need to explain the application:

The app pains a graph on a white background with axes, graticules, and traces in various colors.  In order to make it responsive to scrolling when the vertical or horizontal position is changed (via scrollbars) I undraw the traces (by drawing them in pmNotXOR mode), change the position, then redraw them.  I want to able to do the same with the graph axis annotation.

What I want therefore is a version of TextOut (X, Y, TextToWrite) that does it in XOR mode so that I can remove the annotation by ddrawing it.  It also needs to use the same font/color etc as the existing PaintBox.Canvas.
0
 
LVL 34

Expert Comment

by:Slick812
ID: 9647815
if you want to do
 needs to use the same font/color etc as the existing PaintBox.Canvas

then you will need to REDRAW the section of the paintbox that is going to be painted, Refreshed, or whatever, and then draw the text on the new Redrawn DC to whatever spec you want. .  I thought you wanted an Inverse (XOR) text draw as you oridgenally specified, but you have confused me, if you use the inverse draw you can "Erase" by redrawing it in the same position again (as you have said) . . . if you draw in the "Text Color" you CAN NOT erase it by redrawing it. .  you will need to have a "Erase" redraw of that Text Rectangle, and then redraw the text. . . I'm also puzzeled by your method of "Scrolling". . . I would do a TBitmap, of whatever size the "Entire" area of the graph and then scroll the bitmap on the Paintbox. .  I have no idea why you get the black rectangles. . . my code works for me. .  it draws and then erases
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rossmcm
ID: 9648016
the virtual size of the paintbox is huge - it represents a graphocal trace of temperature vs time, where the temperature and time can be zoomed from 0.1 degree to 100 degrees, and from 1 sec to several years in the X direction, hence the implementation.
0
 
LVL 34

Expert Comment

by:Slick812
ID: 9652862
OK, I can see now that there is a size factor, , , I'm not to sure what to say to try and help you. . . as I have said, if you want to have the text draw we are talking about, in a certain Color, you will not be able to do an XOR type of thing, since that will only "Reverse" the Color of the DC it is applied to. . . I really have NO IDEA what methods you use (to paint or refresh or scroll) for your display. . ., It would seem that since you do not use any "Base" bitmap to scroll, , , when you do a scroll, you would repaint the entire paintbox?, if this is the case, then save all of your text drawing untill the last. . . but from your description of the problem, you somehow do not repaint the entire paintbox, but I guess you just XOR some lines and the redraw those lines, and paint a few lines of text. . . maybe you could just completely redraw the area where the text is, . . . . ? ?
 If where you are drawing the Text that needs to be "Updated" on a scroll  is on a soild color background, you could just do a FillRect or Rectangle with the background color over the old text to erase it,  and then draw the new text

Or I could maybe get it so it does not show the Black rectangles using my SRCINVERT  BliBlt code, , if you can show some code for that
0
 

Author Comment

by:rossmcm
ID: 9653052
You got it.  Rather than repaint the whole paintbox each time the scrollbar is repositioned, I unwrite and rewrite the traces, then the annotation.  For the traces it works perfectly as long as the pen mode is pmNotXOR.  For the annotation presently I am unwriting it be writing it in the same color as the packground of the paintbox and then rewriting it in the correct color.  This works OK unless parts of the trace and the annotation overlap.

0
 
LVL 34

Expert Comment

by:Slick812
ID: 9653116
works OK unless parts of the trace and the annotation overlap

then do your -
unwriting it be writing it in the same color
BEFORE the trace draw, and the new text AFTER the trace draw
0
 
LVL 5

Assisted Solution

by:DeerBear
DeerBear earned 75 total points
ID: 9660415
Hi,

I'm wondering why you don't simply keep a background
bitmap of the picture, clear the paintbox and then simply
redraw the annotations.

Am I missing anything here?

HTH,

Andrew
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question