Debian Codegraph @

examples/lazarus/model_3d_with_2d_controls/mainf.pas

raw
1 {
2 Copyright 2014-2022 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Main form. }
17 unit MainF;
18
19 {$mode objfpc}{$H+}
20
21 interface
22
23 uses
24 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
25 CastleControl, CastleControls;
26
27 type
28 TForm1 = class(TForm)
29 Browser: TCastleControl;
30 procedure FormCreate(Sender: TObject);
31 procedure MainButtonClick(Sender: TObject);
32 end;
33
34 var
35 Form1: TForm1;
36
37 implementation
38
39 {$R *.lfm}
40
41 uses CastleSceneCore, CastleUtils, CastleImages, CastleVectors,
42 CastleUIControls, CastleComponentSerialize;
43
44 { TForm1 --------------------------------------------------------------------- }
45
46 procedure TForm1.FormCreate(Sender: TObject);
47
48 { Customize the look of all controls by adjusting Theme. }
49 procedure AdjustTheme;
50 begin
51 { Change the tooltip image to have rounded corners,
52 using a predefined TooltipRounded image from CastleInternalControlsImages
53 unit. You could also use load and use your own image,
54 e.g. by LoadImage. }
55 Theme.ImagesPersistent[tiTooltip].Url := 'castle-data:/TooltipRounded.png';
56 Theme.ImagesPersistent[tiTooltip].ProtectedSides.AllSides := 9;
57 end;
58
59 { Initialize user interface designed by CGE editor.
60 It is already loaded by Browser.DesignUrl.
61 This is the most advised way to design UI. }
62 procedure InitializeDesignedUserInterface;
63 var
64 MainButton: TCastleButton;
65 begin
66 MainButton := Browser.Container.DesignedComponent('MainButton') as TCastleButton;
67 MainButton.OnClick := @MainButtonClick;
68 end;
69
70 { Add additional user interface elements created manually,
71 by code, just to show that we can. }
72 procedure AddUserInterfaceFromCode;
73 var
74 Button: TCastleButton;
75 begin
76 Button := TCastleButton.Create(Self);
77 Button.Caption := 'Button added from code';
78 Button.Anchor(hpRight, -10);
79 Button.Anchor(vpBottom, 120);
80 Browser.Controls.InsertFront(Button);
81 end;
82
83 begin
84 AdjustTheme;
85 InitializeDesignedUserInterface;
86 AddUserInterfaceFromCode;
87 end;
88
89 procedure TForm1.MainButtonClick(Sender: TObject);
90 begin
91 ShowMessage('Main button clicked.');
92 end;
93
94 end.
95