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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Selection rectangle with crosshair in the center

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Uwe Posted - May 04 2014 : 17:50:50
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

2   L A T E S T    R E P L I E S    (Newest First)
Uwe Posted - May 04 2014 : 18:30:08
That's a good idea, Bill. Thanks! I'll give it a try.

-Uwe
w2m Posted - May 04 2014 : 18:25:29
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