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
 Detect the index of the first visible image?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

933 Posts

Posted - Jan 02 2017 :  06:40:57  Show Profile  Reply
I need to get the INDEX of the first image (even partially) visible in the ImageEnMView.

So far I've looped through ALL the images in the ImageEnMView and stopped at the first image where ImageEnMView1.IsVisible(i) = True.

But this is very inefficient when the ImageEnMView contains a LARGE number of images. Is there a better way?

PeterPanino

933 Posts

Posted - Jan 02 2017 :  09:34:32  Show Profile  Reply
I made this code:

function GetImageCountPerRow: Integer;
var
  i: Integer;
begin
  Result := -1;

  for i := 0 to ImageEnMView1.ImageCount - 1 do
  begin
    if ImageEnMView1.ImageRow[i] = 1 then
    begin
      Result := i;
      BREAK;
    end;
  end;
end;

CodeSite.Send('Index of first visible Image', 
  (ImageEnMView1.ViewY div ImageEnMView1.ThumbHeight) * GetImageCountPerRow);


It works. But do you think that this could be always reliable?
Go to Top of Page

PeterPanino

933 Posts

Posted - Jan 02 2017 :  09:55:47  Show Profile  Reply
This looks much better:

function TForm2.GetImageCountPerRow(const AImageEnMView: TImageEnMView): Integer;
var
  i: Integer;
begin
  Result := -1;

  for i := 0 to AImageEnMView.ImageCount - 1 do
  begin
    if AImageEnMView.ImageRow[i] = 1 then
    begin
      Result := i;
      BREAK;
    end;
  end;
end;

function TForm2.GetIndexOfFirstVisibleImage(const AImageEnMView: TImageEnMView): Integer;
var
  c: Integer;
begin
  c := GetImageCountPerRow(AImageEnMView);

  if c = -1 then
    Result := -1
  else
    Result := (AImageEnMView.ViewY div AImageEnMView.ThumbHeight) * c;
end;

CodeSite.Send('Index of first visible Image', GetIndexOfFirstVisibleImage(ImageEnMView1));
Go to Top of Page

PeterPanino

933 Posts

Posted - Jan 02 2017 :  11:45:08  Show Profile  Reply
There was a bug in my code. So here is the (hopefully) bugfree code:

function TForm2.GetImageCountPerRow(const AImageEnMView: TImageEnMView): Integer;
var
  i: Integer;
begin
  Result := -1;

  for i := 0 to AImageEnMView.ImageCount - 1 do
  begin
    if AImageEnMView.ImageRow[i] = 1 then
    begin
      Result := i;
      BREAK;
    end;
  end;
end;

function TForm2.GetIndexOfFirstVisibleImage(const AImageEnMView: TImageEnMView): Integer;
var
  c: Integer;
begin
  c := GetImageCountPerRow(AImageEnMView);

  if c = -1 then
  begin
    // not enough images to fill a row + 1
    Result := 0;
  end
  else
    Result := (AImageEnMView.ViewY div AImageEnMView.ThumbHeight) * c;
end;

CodeSite.Send('Index of first visible Image', GetIndexOfFirstVisibleImage(ImageEnMView1));


Can please anybody test this.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jan 02 2017 :  11:55:47  Show Profile  Reply
It works here.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38610 Posts

Posted - Jan 05 2017 :  17:17:24  Show Profile  Reply
Hi

You can also use ViewY:

http://www.imageen.com/help/TImageEnMView.ViewX.html

I'm out of the office, so I cannot confirm whether it includes partial thumbnails. If not, you can at least use it to set the range for your iteration which will greatly speed up the process.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

PeterPanino

933 Posts

Posted - Jan 06 2017 :  06:53:24  Show Profile  Reply
Thank you, Nigel. In my function GetIndexOfFirstVisibleImage I do use ViewY. It works well and it really helps me to speed things up. It does indeed support partial view. Thank you!

BTW, I am not sure whether there is a typo at: http://www.imageen.com/help/TImageEnMView.ViewY.html when it says: "if the user has scrolled vertically by two columns".
Go to Top of Page

xequte

38610 Posts

Posted - Jan 08 2017 :  20:02:24  Show Profile  Reply
Thanks, I have corrected it to:

if the user has scrolled vertically by two *rows*

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: