-
Notifications
You must be signed in to change notification settings - Fork 2
/
FormPanel.cpp
223 lines (196 loc) · 6.31 KB
/
FormPanel.cpp
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
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include <algorithm>
#include <memory>
#include <cassert>
#include "FormPanel.h"
#include "DataModStyleRes.h"
using std::make_unique;
using std::swap;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FMXFormPanelBase"
#pragma link "FMXFormPanelBase"
#pragma resource "*.fmx"
//TfrmPanel *frmPanel;
//---------------------------------------------------------------------------
/*
__fastcall TfrmPanel::TfrmPanel( TComponent* Owner,
FMXWinDisplayDev const * Display,
Anafestica::TConfigNode* const RootNode )
: TfrmPanel( Owner, Display, StoreOpts::All, RootNode )
{
}
*/
//---------------------------------------------------------------------------
__fastcall TfrmPanel::TfrmPanel( TComponent* Owner,
FMXWinDisplayDev const * Display,
StoreOpts StoreOptions,
Anafestica::TConfigNode* const RootNode,
TNumEvent OnNumberChanged )
: TfrmPanelBase( Owner, Display, StoreOptions, RootNode )
, onNumberChanged_{ OnNumberChanged }
{
// RestoreProperties();
auto It = begin( numFrames_ );
for ( int Idx = 1 ; Idx <= 90 ; ++Idx ) {
auto NewFrame = make_unique<TfrmeNum>( nullptr );
NewFrame->Text1->Text = Idx;
NewFrame->Parent = GridLayout1;
numFrames_[Idx-1] = std::move( NewFrame );
}
RestoreProperties();
}
//---------------------------------------------------------------------------
__fastcall TfrmPanel::~TfrmPanel()
{
try {
SaveProperties();
}
catch ( ... ) {
}
}
//---------------------------------------------------------------------------
void TfrmPanel::RestoreProperties()
{
// Put code here to restore attribute(s)
// RESTORE_LOCAL_PROPERTY( CurrNum );
RESTORE_LOCAL_PROPERTY( TabsText );
}
//---------------------------------------------------------------------------
void TfrmPanel::SaveProperties() const
{
// Put code here to save attribute(s)
SAVE_LOCAL_PROPERTY( TabsText );
// SAVE_LOCAL_PROPERTY( CurrNum );
}
//---------------------------------------------------------------------------
String TfrmPanel::GetTabsText() const
{
/*
auto SB = make_unique<TStringBuilder>();
for ( size_t Idx = 1 ; Idx <= 90 ; ++Idx ) {
SB->AppendFormat(
_T( "%s" ),
ARRAYOFCONST(( GetTab( Idx ) ? _T( "T" ) : _T( "F" ) ))
);
}
return SB->ToString();
*/
auto SB = make_unique<TStringBuilder>();
for ( size_t Idx = 1 ; Idx <= 90 ; ++Idx ) {
SB->Append(
String(
GetTab( Idx ) ? currNum_ == Idx ? _T( "B" ) : _T( "T" ) : _T( "F" )
)
);
}
return SB->ToString();
}
//---------------------------------------------------------------------------
void TfrmPanel::SetTabsText( String Val )
{
/*
Val = Val.Trim();
if ( Val.Length() == 90 ) {
auto const OldCurrNum = currNum_;
for ( size_t Idx = 1 ; Idx <= 90 ; ++Idx ) {
if ( Idx != OldCurrNum ) {
SetTab( Idx, Val[Idx] == _T( 'T' ) );
}
}
//currNum_ = OldCurrNum;
if ( OldCurrNum ) {
SetTab( OldCurrNum, Val[OldCurrNum] == _T( 'T' ) );
}
else {
currNum_ = 0;
}
}
*/
Val = Val.Trim();
if ( Val.Length() == 90 ) {
int CurrNum {};
for ( size_t Idx = 1 ; Idx <= 90 ; ++Idx ) {
switch( Val[Idx] ) {
case _T( 'T' ):
SetTab( Idx, true );
break;
case _T( 'B' ):
if ( !CurrNum ) {
CurrNum = Idx;
}
break;
default:
SetTab( Idx, false );
break;
}
}
if ( CurrNum ) {
SetTab( CurrNum, true );
}
}
}
//---------------------------------------------------------------------------
bool TfrmPanel::GetTab( size_t Idx ) const
{
assert( Idx >= 1 && Idx <= 90 );
return states_[Idx - 1];
}
//---------------------------------------------------------------------------
bool TfrmPanel::SetTab( size_t Idx, bool Val )
{
assert( Idx >= 1 && Idx <= 90 );
const size_t Ofs = Idx - 1;
swap( Val, states_[Ofs] );
if ( currNum_ ) {
const size_t CurrOfs = currNum_ - 1;
if ( states_[CurrOfs] ) {
numFrames_[CurrOfs]->GradientAnimation1->Stop();
numFrames_[CurrOfs]->GradientAnimation1->AutoReverse = false;
numFrames_[CurrOfs]->GradientAnimation1->Loop = false;
numFrames_[CurrOfs]->GradientAnimation1->Start();
currNum_ = 0;
}
}
if ( Val ^ states_[Idx-1] ) {
if ( Val ) {
numFrames_[Ofs]->GradientAnimation1->Stop();
numFrames_[Ofs]->GradientAnimation1->Inverse = true;
numFrames_[Ofs]->GradientAnimation1->AutoReverse = false;
numFrames_[Ofs]->GradientAnimation1->Loop = false;
numFrames_[Ofs]->GradientAnimation1->Start();
}
else {
currNum_ = Idx;
numFrames_[Ofs]->GradientAnimation1->Inverse = false;
numFrames_[Ofs]->GradientAnimation1->AutoReverse = true;
numFrames_[Ofs]->GradientAnimation1->Loop = true;
numFrames_[Ofs]->GradientAnimation1->Start();
}
}
NotifyNumberChanged( Idx, states_[Ofs] );
return Val;
}
//---------------------------------------------------------------------------
bool TfrmPanel::ToggleTab( size_t Idx )
{
return SetTab( Idx, !GetTab( Idx ) );
}
//---------------------------------------------------------------------------
void TfrmPanel::NotifyNumberChanged( int Num, bool Val )
{
if ( onNumberChanged_ ) {
onNumberChanged_( this, Num, states_[Num - 1] );
}
}
//---------------------------------------------------------------------------
void TfrmPanel::Clear()
{
currNum_ = 0;
for ( size_t Idx = 1 ; Idx <= 90 ; ++Idx ) {
SetTab( Idx, false );
}
}
//---------------------------------------------------------------------------