-
Notifications
You must be signed in to change notification settings - Fork 1
/
sheetview.pas
180 lines (149 loc) · 4.66 KB
/
sheetview.pas
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
unit SheetView;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Math, CastleUIState,
{$ifndef cgeapp}
Forms, Controls, Graphics, Dialogs, CastleControl,
{$else}
CastleWindow,
{$endif}
CastleControls, CastleColors, CastleUIControls,
CastleTriangles, CastleShapes, CastleVectors,
CastleSceneCore, CastleScene, CastleTransform,
CastleViewport, CastleCameras, CastleProjection,
X3DNodes, X3DFields, X3DTIme,
CastleImages, CastleGLImages, CastleRectangles,
CastleTextureImages, CastleLog,
CastleApplicationProperties, CastleTimeUtils, CastleKeysMouse,
CastleGLUtils, multimodel, staging, Overlays, MiscFunctions,
ControlPanel;
type
{ TSheetViewer }
TSheetViewer = class(TUIState)
procedure BeforeRender; override; // TCastleUserInterface
procedure Render; override; // TCastleUserInterface
procedure Resize; override; // TCastleUserInterface
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; // TUIState
private
fSheetWidth: Cardinal;
fSheetHeight: Cardinal;
fControlWidth: Cardinal;
VPBackImage: TCastleImageControl;
MainControl: TCastleUserInterface;
ControlPanel: TControlPanel;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Start; override; // TUIState
procedure Stop; override; // TUIState
procedure LoadSheetViewer;
property ControlWidth: Cardinal read fControlWidth write fControlWidth;
property SheetWidth: Cardinal read fSheetWidth write fSheetWidth;
property SheetHeight: Cardinal read fSheetHeight write fSheetHeight;
end;
var
SheetViewer: TSheetViewer;
implementation
{$ifdef cgeapp}
uses AppInitialization, MainGameUnit;
{$else}
uses GUIInitialization, MainGameUnit;
{$endif}
constructor TSheetViewer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SheetWidth := 4096;
SheetHeight := 4096;
ControlWidth := 300;
LoadSheetViewer;
end;
destructor TSheetViewer.Destroy;
begin
inherited;
end;
procedure TSheetViewer.Start;
begin
inherited;
end;
procedure TSheetViewer.Stop;
begin
inherited;
end;
procedure TSheetViewer.BeforeRender;
begin
inherited;
end;
procedure TSheetViewer.Resize;
var
ProcTimer: Int64;
ProcTimer2: Int64;
DesiredAspect: Single;
ActualAspect: Single;
ViewWidth: Single;
begin
inherited;
ViewWidth := StateContainer.Width - ControlWidth;
DesiredAspect := SheetWidth / SheetHeight;
ActualAspect := ViewWidth / StateContainer.Height;
if DesiredAspect <= ActualAspect then
begin
if ViewWidth <= (StateContainer.Height / DesiredAspect) then
begin
MainControl.Height := StateContainer.Height;
MainControl.Width := StateContainer.Height * DesiredAspect;
end
else
begin
MainControl.Height := StateContainer.Height;
MainControl.Width := StateContainer.Height * DesiredAspect;
end;
end
else
begin
if ViewWidth <= (StateContainer.Height / DesiredAspect) then
begin
MainControl.Width := ViewWidth;
MainControl.Height := ViewWidth / DesiredAspect;
end
else
begin
MainControl.Width := ViewWidth;
MainControl.Height := ViewWidth / DesiredAspect;
end;
end;
MainControl.Left := Trunc((ViewWidth - MainControl.Width) / 2);
MainControl.Bottom := Trunc((StateContainer.Height - MainControl.Height) / 2);
if (TUIState.CurrentTop = SheetViewer) then
begin
ProcTimer := CastleGetTickCount64;
VPBackImage.Image := MakeTransparentLayerRectGrid(SheetWidth, SheetHeight, Trunc(MainControl.Width), Trunc(MainControl.Height), (CastleApp.SpriteWidth), (CastleApp.SpriteHeight));
ProcTimer2 := CastleGetTickCount64;
WriteLnLog('RectGrid took ' + FormatFloat('####0.000000', (ProcTimer2 - ProcTimer)) + ' seconds' + '[' + FloatToStr(ProcTimer) + ' - ' + FloatToStr(ProcTimer2) + ']');
VPBackImage.Left := MainControl.Left;
VPBackImage.Bottom := MainControl.Bottom;
VPBackImage.Width := MainControl.Width;
VPBackImage.Height := MainControl.Height;
end;
end;
procedure TSheetViewer.Render;
begin
inherited;
end;
procedure TSheetViewer.Update(const SecondsPassed: Single; var HandleInput: boolean);
begin
inherited;
end;
procedure TSheetViewer.LoadSheetViewer;
begin
MainControl := TCastleUserInterface.Create(Self);
MainControl.Height := Height;
MainControl.Width := Width - ControlWidth;
Self.InsertFront(MainControl);
VPBackImage := TCastleImageControl.Create(MainControl);
VPBackImage.OwnsImage := True;
VPBackImage.Stretch := False;
InsertFront(VPBackImage);
// ControlPanel := TControlPanel.Create(Self, ControlWidth);
end;
end.