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
 Fastest code to draw a line as mouse pointer?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

aleatprog

135 Posts

Posted - Jan 26 2020 :  13:18:48  Show Profile  Reply
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

aleatprog

135 Posts

Posted - Jan 26 2020 :  14:56:41  Show Profile  Reply
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;
Go to Top of Page

rmklever

Norway
51 Posts

Posted - Jan 26 2020 :  15:41:35  Show Profile  Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: