TVirtualDrawtree

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

Now it's 17.05 Turkey Local Time (GMT+2) at 20.00 i have been back to hotel. I'll check it out.
Resim
Resim ....Resim
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

mia yazdı:thats how i get animation from url what i try so far i saved it to memory stream , but gif is too slow also i can i make diffrent image for each item ? and how to specif items with images ?
Hi again, I saw your example.

- There is a special situation in this example : when you DRAW a GRAPHIC on to a Canvas, then this is not an animated gif anymore. This is a static picture.

- Animation speed value is not sensitive. Only refresh rate affects speed of animation. In this case, you need to put a lower value to timer interval. ( you say timer1.interval := 10; for example )


Ok now I share the whole code below. You make your work over this.
Project source and executable attached the message

Kod: Tümünü seç

Uses GIFImg, GraphUtil;

Var
  xboolBlink : Boolean = False;
  
procedure TForm1.FormCreate(Sender: TObject);
begin
  GIFImg.GIFImageDefaultAnimate       := True;
  GIFImg.GIFImageDefaultAnimationLoop := glContinously;
  GIFImg.GIFImageDefaultTransparent   := True;

  // This is for repaint the ListView and so for the animation
    Timer1.Interval       := 200;
    Timer1.Enabled        := true;

  // This is for enlarge the ListView height
    ImageList1.Width      := 32;
    ImageList1.Height     := 32;
  With ListView1 do begin
    SmallImages := ImageList1;
    ViewStyle   := vsReport;
    RowSelect   := True;
    ReadOnly    := True;
    OwnerDraw   := True;
    DoubleBuffered := True;
    With Columns.Add do Width := 50;
    With Columns.Add do Width := 250;
    With Columns.Add do Width := 50;
    With Columns.Add do Width := 50;
  end;
end;
 
Procedure Add_Item( strCaption: String; ListView : TListView; strFile: String; boolBlink : Boolean );
Var
  aGIF : TGifImage;
begin
  aGIF := TGifImage.Create;
  aGIF.LoadFromFile( strFile );
  aGIF.Transparent := True;
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( aGIF ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
  end;
  // DO NOT Free this image because now it is a SubItems[1] Object
end;

// This is the ARMAN magic... :)
procedure TForm1.ListView1CustomDraw(Sender: TCustomListView;
  const ARect: TRect; var DefaultDraw: Boolean);
Var
  R: TRect;
begin
  // Full ListView
  SetRect(R, ARect.Left, ARect.Top, ARect.Right - ((ARect.Right-ARect.Left) div 2), ARect.Bottom );
  GradientFillCanvas(Sender.Canvas, clSilver, clWhite, R, gdHorizontal); // GraphUtil
  SetRect(R, ARect.Right - ((ARect.Right-ARect.Left) div 2), ARect.Top, ARect.Right, ARect.Bottom );
  GradientFillCanvas(Sender.Canvas, clWhite, clSilver, R, gdHorizontal);
end;

procedure TForm1.ListView1DrawItem(Sender: TCustomListView; Item: TListItem;
  Rect: TRect; State: TOwnerDrawState);
Var
  xOff, yOff : Integer;
  R: TRect;
  i : Integer;
begin
  With TListView(Sender).Canvas do
  begin
    if Item.Selected then
    begin
      SetRect(R, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom-( (Rect.Bottom-Rect.Top) div 2 ) );
      GradientFillCanvas(Sender.Canvas, $00056AFF, clWhite, R, gdVertical); // GraphUtil
      SetRect(R, Rect.Left, Rect.Bottom-( (Rect.Bottom-Rect.Top) div 2 ), Rect.Right, Rect.Bottom );
      GradientFillCanvas(Sender.Canvas, clWhite, $000055FF, R, gdVertical);
      Sender.Canvas.Brush.Style := bsClear;
      Sender.Canvas.Pen.Color   := clRed;
      Sender.Canvas.Pen.Width   := 1;

      //Sender.Canvas.Font.Color  := clBlue;
      //Sender.Canvas.Brush.Color := clYellow;
      //Sender.Canvas.FillRect(Rect);
      Rectangle( Rect.Left, Rect.Top,  Rect.Right, Rect.Top + ImageList1.Height);
    end;
    Sender.Canvas.Brush.Style := bsClear;
    // Image
    xOff := Rect.Left + ((TListView(Sender).Columns[0].Width  - TGIFImage( Item.SubItems.Objects[1]).Width ) div 2);
    yOff := Rect.Top  + ((ImageList1.Height - TGIFImage( Item.SubItems.Objects[1]).Height) div 2);
      Draw( xOff, yOff, TGIFImage( Item.SubItems.Objects[1]) );

    // Caption and Text
    xOff := Rect.Left;
    for i := 1 to TListView(sender).Columns.Count - 1 do
    begin
      xOff := xOff + TListView(Sender).Columns[i-1].Width;
      yOff := Rect.Top + ((ImageList1.Height-Canvas.TextHeight('H')) div 2);
      if xboolBlink or ( Item.SubItems[2] = '' )
      then TextOut( xOff, yOff, Item.SubItems[i-1] );
    end;

  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
{$j+}
  Const iCount : Cardinal = 0;
{$j-}
begin
  inc(iCount);
  if (iCount * TTimer(Sender).Interval) > 500 then 
  begin  // this is for blink text which subitem[2] contains 'blink'
    xboolBlink := NOT xboolBlink;
    iCount := 0;
  end;
  ListView1.Repaint; // This is for animation over ListView Canvas
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
{$j+}
  Const boolblink : boolean = false;
{$j-}

begin
  boolblink := not boolblink;
  With TOpenDialog.Create(nil) do
  begin
    Filter      := 'GIF Image *.GIF|*.gif|Bitmap Images *.BMP|*.bmp';
    FilterIndex := 1;
    if Execute then begin
      Add_Item( 'Muharrem ARMAN - ' + IntToStr(ListView1.Items.Count+1), ListView1, FileName, boolblink );
    end;
    Free;
  end;
Resim
Dosya ekleri
AnimatedGIF_ListView.rar
(252.43 KiB) 119 kere indirildi
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i started to play around i got some pitfalls

- how to control on image size if i get it from url
- how to make the image and item indent in list view
- how to hide this scroll bar down
- and the most important point i want to add the item first then show its image

here is the project
Dosya ekleri
AnimatedGIF.rar
(79.7 KiB) 81 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

You want too many things...
- Image size issue; you need to lock with standart size to be control on you, you know. (lock the image size with 100x100) Because there is you have no power without controlled power by you. ImageList's Height value affects TListView's ItemHeight.
- indent is easy, you decide a margin then add every image(s) xOff value to this value.
- For hiding scrollbars issue, don't ask me, this is a standart TListView you know, Google it. :roll:
- Most important thing is the easiest thing, think like indent. xOff value + firstColWidth + indent = Image new X offset... Did you got it?
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i searched about tlistview scrollbars seems to be there is 2 way , First way that i do not prefer is using WindowProc this is i will not prefer because its will make the vertical scrollbar always showing i want only show it if there is extra items , second way by making columns width same as list view width and this is sounds good but i cannot verfiy how to do it with this project there is to many columns out there also i get ride of indy http and i use wininet seems much faster here is the current project
Dosya ekleri
AnimatedGIF.rar
(89.52 KiB) 79 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

if total amount of every column width equals or bigger than listview width, then scrollbar will became visible. Then you need to calculate column widths depend on this situation.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

thank you mrmarman yes i got it , i also created only 2 visible columns , also i discover something correct me if iam wrong i also can use hidden text as sub item without adding its column correct ? also i notice that i only allowed to add gif images can i added JPEG and bmp and png too ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

yes you're totally right.
i like using listviews. Many many SubItems you can add and use, plus you do not need to show all of them at the same time.
one last thing, an unit for png image type, that's all you need is.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

yes , i made it thank you for this directions you are awesome , but i still canot find solve for image size here is the project with gif and jpg and any other image can be done if i fix image size part this gonna be hilarious thing i tried

aGIF.Height := 20 and thats does not resize the image sadly to test the image just put image url in edit1
Dosya ekleri
AnimatedGIF.rar
(91.48 KiB) 93 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

you need to change ImageList height to higher value.

Imagelist controls the listview item height . According this, Controls the height of canvas section of item. finally co trols the image height.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

do you mean at this lines ?

Kod: Tümünü seç

 xOff := Rect.Left + ((TListView(Sender).Columns[0].Width  - TGIFImage( Item.SubItems.Objects[1]).Width ) div 2);
    yOff := Rect.Top  + ((ImageList1.Height - TGIFImage( Item.SubItems.Objects[1]).Height) div 2);
      Draw( xOff, yOff, TGIFImage( Item.SubItems.Objects[1]) );
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

no, listview column add section,
on the form create procedure

Kod: Tümünü seç

  // This is for enlarge the ListView height
    ImageList1.Width      := 32;
    ImageList1.Height     := 32;
listview height is wrong, listview item height is right. it's my bad.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i dont get it yet thats how my code looks like and thats how image looks like if its large
Dosya ekleri
inlargee.jpg
inlargee.jpg (12.74 KiB) 4046 kere görüntülendi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

I'm on field for shooting. I cannot see the picture in my condition.

If you change the imagelist height the listview item height changes.
after that, you xhange image size below.

Kod: Tümünü seç

aGIF := TGifImage.Create;
  aGIF.LoadFromFile( strFile );
  aGIF.Transparent := True;
  aGIF. Height := imagelist1.height;
  aGIF. Width := imagelist1.width;
  
if image stretch property enabled then you see bigger or smaller
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

adding

Kod: Tümünü seç

aGIF. Height := form1.imagelist1.height;
  aGIF. Width := form1.imagelist1.width;
does not changes gif size and also on

Kod: Tümünü seç

jpg.Height := form1.imagelist1.height;
  jpg.Width := form1.imagelist1.width;
  
says cannot change image size
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Cevapla