Repository navigation
Expand file tree
/
Copy pathFormPanel.cpp
More file actions
420 lines (377 loc) · 12.9 KB
/
Copy pathFormPanel.cpp
File metadata and controls
420 lines (377 loc) · 12.9 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include <FMX.Platform.Win.hpp>
//#include <algorithm>
//#include <memory>
//#include <filesystem>
//#include <cassert>
//#include <iterator>
#include "FormPanel.h"
#include "DataModStyleRes.h"
using Fmx::Platform::Win::WindowHandleToPlatform;
using std::make_unique;
//using std::swap;
//using std::filesystem::directory_iterator;
//using std::filesystem::recursive_directory_iterator;
//#include <filesystem>
//using std::filesystem::is_directory;
//using std::transform;
//using std::begin;
//using std::end;
//using std::towlower;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FMXFormPanelBase"
#pragma resource "*.fmx"
//TfrmPanel *frmPanel;
//---------------------------------------------------------------------------
__fastcall TfrmPanel::TfrmPanel( TComponent* Owner,
int MechSoundVolume,
bool FanNoise,
int NoiseSoundVol,
// String PicturesPath,
bool RecursivePicturesSearch,
FMXWinDisplayDev const * Display,
StoreOpts StoreOptions,
Anafestica::TConfigNode* const RootNode )
: TfrmPanelBase( Owner, Display, StoreOptions, RootNode )
, mechSoundVolume_{ MechSoundVolume }
, fanNoise_{ FanNoise }
, noiseSoundVolume_{ NoiseSoundVol }
, player_ { new WavePlayer{ WindowHandleToPlatform( Handle )->Wnd } }
, playerNoise_ { new WavePlayer{ WindowHandleToPlatform( Handle )->Wnd } }
// , picturesPath_{ PicturesPath }
// , recursivePicturesSearch_{ RecursivePicturesSearch }
{
mechSoundVolume_ = MechSoundVolume;
noiseSoundVolume_ = NoiseSoundVolume;
RestoreProperties();
LoadMechanicalSound();
// LoadPictures();
// Black-screen overlay: a solid black rectangle filling the whole projector
// surface, hidden until the "black screen" command turns it on. Owned by the
// form; HitTest off so it never eats input; kept above every other layer.
blackout_ = new TRectangle( this );
blackout_->Parent = layoutMain;
blackout_->Align = TAlignLayout::Client;
blackout_->HitTest = false;
blackout_->Stroke->Kind = TBrushKind::None;
blackout_->Fill->Kind = TBrushKind::Solid;
blackout_->Fill->Color = claBlack;
blackout_->Visible = false;
blackout_->BringToFront();
}
//---------------------------------------------------------------------------
__fastcall TfrmPanel::~TfrmPanel()
{
try {
SaveProperties();
}
catch ( ... ) {
}
}
//---------------------------------------------------------------------------
void TfrmPanel::RestoreProperties()
{
// Put code here to restore attribute(s)
}
//---------------------------------------------------------------------------
void TfrmPanel::ApplyCanvasSize( float W, float H )
{
inherited::ApplyCanvasSize( W, H );
// Layout1 is the sliding "film frame"; ImageViewer2 shows the picture and
// letterboxes it against its black background. Rectangle1 (vignette flash)
// and Layout2 (vignette overlay) are Align=Client and follow on their own.
Layout1->Size->Width = W;
Layout1->Size->Height = H;
ImageViewer2->Size->Width = W;
ImageViewer2->Size->Height = H;
}
//---------------------------------------------------------------------------
void TfrmPanel::SaveProperties() const
{
// Put code here to save attribute(s)
}
//---------------------------------------------------------------------------
void __fastcall TfrmPanel::FloatAnimation2Finish(TObject *Sender)
{
FloatAnimation2->Inverse = !FloatAnimation2->Inverse;
++phase_;
if ( ++FloatAnimation2->Tag & 1 ) {
// ONLOADIMAGE
if ( onLoadPicture_ ) {
onLoadPicture_( this, backward_ );
}
FloatAnimation2->Start();
FloatAnimation1->Start();
}
}
//---------------------------------------------------------------------------
/*
void TfrmPanel::LoadPictures()
{
//std::wstring Path = LR"=(C:\Users\Giuliano\Desktop\SlideShow)=";
//std::wstring Path = LR"=(C:\Users\Giuliano\Desktop\Lesso\SLIDE)=";
std::wstring Path = picturesPath_.c_str();
if ( is_directory( Path ) ) {
auto Inserter = [this]( auto const & Entry )
{
auto Path = Entry.path();
String Ext = String{ Path.extension().c_str() };
if ( SameText( Ext, _D( ".jpg" ) ) || SameText( Ext, _D( ".png" ) ) ) {
entries_.emplace_back( Path.c_str() );
}
};
if ( recursivePicturesSearch_ ) {
for ( decltype( auto ) Entry : recursive_directory_iterator( Path ) ) {
Inserter( Entry );
}
}
else {
for ( decltype( auto ) Entry : directory_iterator( Path ) ) {
Inserter( Entry );
}
}
}
if ( !entries_.empty() ) {
LoadImage( idx_ );
}
}
*/
//---------------------------------------------------------------------------
void TfrmPanel::SetNoiseSoundVolume( int Val )
{
if ( noiseSoundVolume_ != Val ) {
auto PlayerNoise = make_unique<WavePlayer>( WindowHandleToPlatform( Handle )->Wnd );
noiseSoundVolume_ = Val;
LoadNoiseSound( *PlayerNoise );
if ( fanNoise_ ) {
PlayerNoise->Play( true );
}
else {
PlayerNoise->Stop();
}
playerNoise_ = std::move( PlayerNoise );
}
}
//---------------------------------------------------------------------------
/*
void TfrmPanel::LoadImage( size_t Index )
{
auto FileName = entries_[Index];
auto Bmp = make_unique<TBitmap>( FileName );
ImageViewer2->Bitmap->Clear( {} );
auto WFactor = static_cast<float>( ImageViewer2->Width ) / Bmp->Width;
auto HFactor = static_cast<float>( ImageViewer2->Height ) / Bmp->Height;
if ( HFactor <= WFactor ) {
// H
ImageViewer2->BitmapScale = HFactor;
}
else {
// W
ImageViewer2->BitmapScale = WFactor;
}
ImageViewer2->Bitmap->Assign( Bmp.get() );
}
*/
void TfrmPanel::LoadPicture( TBitmap& Bmp )
{
// "Contain" fit: show the whole picture, scaled to fit the canvas with its
// aspect preserved and centered on black bands, so portrait photos are
// shown in full instead of being cropped.
float const CanvasW = ImageViewer2->Width;
float const CanvasH = ImageViewer2->Height;
float const CanvasAR = CanvasW / CanvasH;
float const SrcAR = static_cast<float>( Bmp.Width ) / Bmp.Height;
// Build a canvas-aspect bitmap large enough to hold the picture, then cap it
// to a safe max size: a wide canvas plus a tall photo can push a full-
// resolution letterbox past the texture limit ("Bitmap size too big").
int OutW, OutH;
if ( SrcAR > CanvasAR ) { // relatively wider -> bands top/bottom
OutW = Bmp.Width;
OutH = static_cast<int>( Bmp.Width / CanvasAR + 0.5f );
}
else { // relatively taller -> bands left/right
OutH = Bmp.Height;
OutW = static_cast<int>( Bmp.Height * CanvasAR + 0.5f );
}
constexpr int MaxDim = 4096; // safe upper bound for FMX bitmaps
int const Larger = OutW > OutH ? OutW : OutH;
float const Fit =
Larger > MaxDim ? static_cast<float>( MaxDim ) / Larger : 1.0f;
OutW = static_cast<int>( OutW * Fit + 0.5f );
OutH = static_cast<int>( OutH * Fit + 0.5f );
if ( OutW < 1 ) { OutW = 1; }
if ( OutH < 1 ) { OutH = 1; }
int DrawW = static_cast<int>( Bmp.Width * Fit + 0.5f );
int DrawH = static_cast<int>( Bmp.Height * Fit + 0.5f );
if ( DrawW < 1 ) { DrawW = 1; }
if ( DrawH < 1 ) { DrawH = 1; }
int const OfsX = ( OutW - DrawW ) / 2;
int const OfsY = ( OutH - DrawH ) / 2;
auto Out = make_unique<TBitmap>( OutW, OutH );
if ( Out->Canvas->BeginScene() ) {
// RAII: EndScene on every exit path, exceptions included.
struct TSceneGuard {
TCanvas& Canvas;
~TSceneGuard() { Canvas.EndScene(); }
} SceneGuard { *Out->Canvas };
Out->Canvas->Clear( claBlack );
Out->Canvas->DrawBitmap(
&Bmp,
TRectF( 0, 0, Bmp.Width, Bmp.Height ),
TRectF( OfsX, OfsY, OfsX + DrawW, OfsY + DrawH ),
1.0f, true
);
}
ImageViewer2->Bitmap->Clear( {} );
ImageViewer2->BitmapScale = CanvasW / OutW; // Out shares the canvas AR
ImageViewer2->Bitmap->Assign( Out.get() );
}
//---------------------------------------------------------------------------
bool TfrmPanel::GetVignetting() const
{
return NormalBlendEffect1->Enabled;
}
//---------------------------------------------------------------------------
void TfrmPanel::SetVignetting( bool Val )
{
NormalBlendEffect1->Enabled = Val;
}
//---------------------------------------------------------------------------
bool TfrmPanel::GetBlackout() const
{
return blackout_ && blackout_->Visible;
}
//---------------------------------------------------------------------------
void TfrmPanel::SetBlackout( bool Val )
{
if ( !blackout_ ) { return; }
if ( Val ) {
blackout_->BringToFront(); // stay above any later-added layer
}
blackout_->Visible = Val;
}
//---------------------------------------------------------------------------
/*
TfrmPanel::ImageFileNameCont& TfrmPanel::GetImages()
{
return entries_;
}
*/
//---------------------------------------------------------------------------
bool TfrmPanel::IsIdle() const
{
return ( phase_ % 3 ) == 0;
}
//---------------------------------------------------------------------------
void TfrmPanel::LoadMechanicalSound()
{
if ( player_ ) {
player_->LoadWaveFromResource(
HInstance, _D( "sound" ),
static_cast<float>( mechSoundVolume_ ) / 100.0F
);
}
}
//---------------------------------------------------------------------------
void TfrmPanel::LoadNoiseSound( WavePlayer& Player )
{
Player.LoadWaveFromResource(
HInstance, _D( "noise" ),
static_cast<float>( noiseSoundVolume_ ) / 100.0F
);
}
//---------------------------------------------------------------------------
void TfrmPanel::SetMechSoundVolume( int Val )
{
if ( mechSoundVolume_ != Val ) {
mechSoundVolume_ = Val;
LoadMechanicalSound();
}
}
//---------------------------------------------------------------------------
void TfrmPanel::PlayMechanicalSound()
{
if ( player_ ) {
player_->Play( false );
}
}
//---------------------------------------------------------------------------
void TfrmPanel::PlayNoiseSound()
{
if ( playerNoise_ ) {
if ( fanNoise_ ) {
playerNoise_->Play( true );
}
else {
playerNoise_->Stop();
}
}
}
//---------------------------------------------------------------------------
/*
void TfrmPanel::Next()
{
PlayMechanicalSound();
++phase_;
backward_ = false;
FloatAnimation2->StopValue = ImageViewer2->Width * 2;
FloatAnimation2->Start();
FloatAnimation1->Start();
}
//---------------------------------------------------------------------------
void TfrmPanel::Prior()
{
PlayMechanicalSound();
++phase_;
backward_ = true;
FloatAnimation2->StopValue = ImageViewer2->Width * 2;
FloatAnimation2->Start();
FloatAnimation1->Start();
}
//---------------------------------------------------------------------------
*/
void TfrmPanel::ChangePicture( bool Backward )
{
backward_ = Backward;
PlayMechanicalSound();
++phase_;
FloatAnimation2->StopValue = ImageViewer2->Width * 2;
FloatAnimation2->Start();
FloatAnimation1->Start();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPanel::KeyDown( System::Word &Key, System::WideChar &KeyChar,
System::Classes::TShiftState Shift )
{
// Give the host first crack at the key (e.g. the presenter shortcuts) so the
// projector window reacts even when the main window is minimized to the tray.
if ( onPictureKey_ && onPictureKey_( Key, KeyChar, Shift ) ) {
Key = 0;
KeyChar = 0;
return;
}
inherited::KeyDown( Key, KeyChar, Shift );
}
//---------------------------------------------------------------------------
void __fastcall TfrmPanel::FormShow(TObject *Sender)
{
LoadNoiseSound( *playerNoise_ );
PlayNoiseSound();
}
//---------------------------------------------------------------------------
bool TfrmPanel::GetFanNoise() const
{
return fanNoise_;
}
//---------------------------------------------------------------------------
void TfrmPanel::SetFanNoise( bool Val )
{
if ( fanNoise_ != Val ) {
fanNoise_ = Val;
PlayNoiseSound();
}
}
//---------------------------------------------------------------------------