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
 Fastest code to draw a line as mouse pointer?

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
aleatprog Posted - Jan 26 2020 : 13:18:48
Hi,

I need to split an image vertically in two parts. The split point is set by clicking on the image. In order to get a more intuitive interface, I like to show a vertical line at the mouse pointer. The following code creates such a line by using a selection.

OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
MouseX := ImageEnView.XScr2Bmp(X);
MouseY := ImageEnView.YScr2Bmp(Y);
ImageEnView.Deselect;
ImageEnView.Select(MouseX, 0, MouseX + 1, ImageEnView.Bitmap.Height);
ImageEnView.Update();
end;

This code is working fine, overall for the fluidity with which the line moves. Anyway, I'ld prefer a 1-pixel wide colored line instead of the selection. Is there a way to draw such a line with the same fluidity as in the above shown code?

Thanks,
Al
2   L A T E S T    R E P L I E S    (Newest First)
rmklever Posted - Jan 26 2020 : 15:41:35
Hi,

You could try painting it directly in the backbuffer like this...


procedure TfrmMain.imgViewDrawBackBuffer(Sender: TObject);
type
  PRGBArr = ^TRGBArr;
  TRGBArr = array[0..32768] of TRGB;
const
  cMagenta: TRGB = (b: 255; g: 0;r: 255);
  cWhite: TRGB = (b: 255; g: 255;r: 255);
var
  rx, ry, rw, rh, sx, sy, sw, sh: Integer;
  y, x, i, j: Integer;
  SL: PRGBArr;
  Color: TRGB;
begin
  if chkSplit.Checked then begin
    imgView.GetRenderRectangles(rx, ry, rw, rh, sx, sy, sw, sh);

    // Position splitter in the middle of the view when activated
    if SplitPos = -1 then SplitPos:= (sw shr 1) + sx;

    x:= imgView.XBmp2Scr(SplitPos);  // Get splitter x position

    // Draw splitter
    if (x > 0) and (x < imgView.ClientWidth) then begin
      i:= 1;
      Color:= cMagenta;
      for y:= 0 to imgView.ClientHeight - 1 do begin
        SL:= imgView.BackBuffer.ScanLine[y];
        if y mod 4 = 0 then begin
          i:= -i;
          if i = -1 then Color:= cMagenta else Color:= cWhite;
        end;
        SL[x]:= Color;
      end;
    end;
  end;
end;


Roy M Klever
Klever on Delphi - www.rmklever.com
aleatprog Posted - Jan 26 2020 : 14:56:41
The following code is based on a line layer and does exactly what I like, but the line creation time is low and the line is drawn fluidly only if the mouse is moved slowly.

MouseX := ImageEnView.XScr2Bmp(X);
MouseY := ImageEnView.YScr2Bmp(Y);
if LayerIdx <> 0 then
ImageEnView.LayersRemove(LayerIdx);
LayerIdx := ImageEnView.LayersAdd(ielkLine);
TIELineLayer(ImageEnView.CurrentLayer).LineColor := clYellow;
TIELineLayer(ImageEnView.CurrentLayer).LineWidth := 1;
TIELineLayer(ImageEnView.CurrentLayer).LinePoint1 := Point(MouseX, 0);
TIELineLayer(ImageEnView.CurrentLayer).LinePoint2 := Point(MouseX, ImageEnView.Bitmap.Height);
ImageEnView.Update();

Also adding the following options don't let the line move become fluid:

ImageEnView.LayersFastDrawing := iefFast;
ImageEnView.LayersCaching := -1;