summaryrefslogtreecommitdiff
path: root/examples/gfx/subwindow/subwindow.pas
blob: 177f49899527c6abaa7cf9dd409fb50fe1d6729f (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
91
92
93
94
95
96
97
98
99
100
{
    fpGUI  -  Free Pascal GUI Library

    SubWindow  -  Shows how to create a Sub-Window on GFX

    Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this
    distribution, for details of the copyright.

    See the file COPYING.modifiedLGPL, included in this distribution,
    for details about redistributing fpGUI.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
program subwindow;

uses
  SysUtils, Classes,
  fpGFX, GFXBase, fpgfxpackage;

type

  { TBoxWindow }

  TBoxWindow = class(TFWindow)
  public
    procedure Paint(Sender: TObject; const Rect: TRect);
    constructor Create(AParent: TFCustomWindow);
    procedure MouseReleased(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
  end;

  { TMainWindow }

  TMainWindow = class(TFWindow)
  public
    ABox: TBoxWindow;
    constructor Create;
    procedure MouseReleased(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
  end;
  
constructor TBoxWindow.Create(AParent: TFCustomWindow);
begin
  inherited Create(AParent, []);

  OnMouseReleased := @MouseReleased;
  OnPaint := @Paint;

  SetClientSize(Size(125, 125));
  SetMinMaxClientSize(Size(125, 125), Size(125, 125));
end;

procedure TBoxWindow.MouseReleased(Sender: TObject; AButton: TMouseButton;
  AShift: TShiftState; const AMousePos: TPoint);
begin
  WriteLn('Mouse released on child window');
end;

procedure TBoxWindow.Paint(Sender: TObject; const Rect: TRect);
var
  r: TRect;
begin
  Canvas.SetColor(colBlue);
  r.Left    := 0;
  r.Top     := 0;
  r.Right   := Width;
  r.Bottom  := Height;
  Canvas.FillRect(r);
end;

constructor TMainWindow.Create;
begin
  inherited Create(nil, [woWindow]);

  Title := 'fpGFX Sub-Window example';
  SetClientSize(Size(256, 256));
  SetMinMaxClientSize(Size(256, 256), Size(256, 256));

  OnMouseReleased := @MouseReleased;

  ABox := TBoxWindow.Create(Self);
  ABox.Show;
end;

procedure TMainWindow.MouseReleased(Sender: TObject; AButton: TMouseButton;
  AShift: TShiftState; const AMousePos: TPoint);
begin
  WriteLn('Mouse released on main window');
end;

var
  MainWindow: TMainWindow;
begin
  GFApplication.Initialize;
  MainWindow := TMainWindow.Create;
  GFApplication.AddWindow(MainWindow);
  MainWindow.Show;
  GFApplication.Run;
end.