ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Selection rectangle with crosshair in the center
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Uwe

284 Posts

Posted - May 04 2014 :  17:50:50  Show Profile  Reply
I'm trying to create a transparent selection rectangle (see attached image) which shows a crosshair right in its center after the mouse button has been released. When the selection rectangle is moved or resized, the crosshair should automatically be moved, resized and re-centered as well. Flicker-free if possible, and the crosshair should of course not be copied to memory together with the pixels within the selection rectangle.

What would be the best way to do that? Manipulating the DisplayGrid property? Create a transparent layer? Rewrite the selection code?

Some sample code would be much appreciated.

Thanks in advance
-Uwe

w2m

USA
1990 Posts

Posted - May 04 2014 :  18:25:29  Show Profile  Reply
The best flicker-free way probably would be to draw the crosshair in the OnBackBuffer event. I use it all the time to draw an ellipse for brush painting, so it probably should work for a crosshair.

procedure TForm1.ImageEnView1DrawBackBuffer(Sender: TObject);
{ Draw an ellipse in the DrawBackBuffer Event - refresh with Update. }
var
  i: Double;
  z: Double;
  mx1: Double;
  my1: Double;
  lx1: Double;
  ly1: Double;
  x1, y1, x2, y2: Integer;
  bx, by: Integer;
begin
  bx := ImageEnView1.Layers[ImageEnView1.LayersCurrent].ConvXScr2Bmp
    (ABackBufferX);
  by := ImageEnView1.Layers[ImageEnView1.LayersCurrent].ConvYScr2Bmp
    (ABackBufferY);
  if (bx >= 0) and (bx <= ImageEnView1.IEBitmap.Width - 1) and (by >= 0) and
    (by <= ImageEnView1.IEBitmap.Height - 1) then
        with ImageEnView1.BackBuffer.Canvas do
        begin
          i := BrushPaint1.BrushSize / 2;
          Pen.Mode := pmNOTXOR; // pmCopy;
          Brush.Style := bsClear;
          z := ImageEnView1.Zoom / 100;
          mx1 := ABackBufferX; ( integer set in OnMouseMoveEvent }
          my1 := ABackBufferY; ( integer set in OnMouseMoveEvent } 
          lx1 := ABackBufferX;
          ly1 := ABackBufferY;
          x1 := Round(mx1 - i * z);
          y1 := Round(my1 - i * z);
          x2 := Round(lx1 + i * z);
          y2 := Round(ly1 + i * z);
          {if ImageEnView1.Bitmap.Width > 64 then
            Ellipse(x1, y1, x2, y2)
          else
            Rectangle(x1, y1, x2, y2);}
          // Draw crosshairs here
          Pen.Style := psDash;
          Pen.Width := 2;
          MoveTo(x1, y1);
          LineTo(x1 + 5, y1 + 5);
        end;
      end;
end;


The on ImageEnView.OnBackBuffer event is called whenever ImageEnView.Update is called... such as in OnMouseMove.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom Commercial ImageEn Development
Go to Top of Page

Uwe

284 Posts

Posted - May 04 2014 :  18:30:08  Show Profile  Reply
That's a good idea, Bill. Thanks! I'll give it a try.

-Uwe
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: