summaryrefslogtreecommitdiff
path: root/examples/gui/stdimages/stdimglist.lpr
blob: 09e579902f1cb3fbbd01adcb5407dac18091570c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
program stdimglist;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils,
  fpg_base, fpg_main, fpg_form, fpg_imgfmt_bmp, fpg_button;

type

  TMainForm = class(TfpgForm)
  private
    btnClose: TfpgButton;
    procedure   btnCloseClick(Sender: TObject);
  protected
    procedure   HandlePaint; override;
  public
    procedure   AfterCreate; override;
  end;

{ TMainForm }

procedure TMainForm.AfterCreate;
begin
  SetPosition(100,100,700,500);
  WindowTitle := 'fpGUI Standard Image Listing';
  WindowPosition := wpOneThirdDown;
  MinWidth := 200;
  MinHeight := 100;

  btnClose := CreateButton(self, Width-90, Height-35, 75, 'Quit', @btnCloseClick);
  btnClose.ImageName := 'stdimg.quit';
  btnClose.Anchors := [anRight, anBottom];
end;

procedure TMainForm.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.HandlePaint;
var
  n: integer;
  x: TfpgCoord;
  y: TfpgCoord;
  sl: TStringList;
  img: TfpgImage;
begin
  Canvas.BeginDraw; // begin double buffering
  inherited HandlePaint;

  sl  := TStringList.Create;
  x   := 8;
  y   := 8;
  fpgImages.ListImages(sl);
  
  for n := 0 to sl.Count-1 do
  begin
    Canvas.DrawString(x, y, sl[n]+':');
    
    img := TfpgImage(sl.Objects[n]);
    if img <> nil then
      Canvas.DrawImage(x+130, y, img);

    inc(y, img.Height+8);
    if y > Height-32 then // largest images are 32 in height
    begin
      inc(x, 200);
      y := 8;
    end;
  end;

  Canvas.EndDraw;
  sl.Free;
end;

procedure MainProc;
var
  frm : TMainForm;
begin
  fpgApplication.Initialize;
  frm := TMainForm.Create(nil);
  frm.Show;
  fpgApplication.Run;
  frm.Free;
end;

begin
  MainProc;
end.