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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
|
////////////////////////////////////////////////////////////////////////////////
// All code below is exclusively owned by author of Chess4Net - Pavel Perminov
// (packpaul@mail.ru, packpaul1@gmail.com).
// Any changes, modifications, borrowing and adaptation are a subject for
// explicit permition from the owner.
unit GameChessBoardUnit;
interface
uses
ExtCtrls, TntStdCtrls, Buttons, Controls, StdCtrls, Classes, Forms, TntForms,
Graphics, Messages,
// Chess4net
ChessBoardHeaderUnit, ChessBoardUnit, ChessRulesEngine,
LocalizerUnit, PosBaseChessBoardLayerUnit;
type
TGameChessBoardEvent =
(cbeMoved, cbeMate, cbeStaleMate, cbeInsuffMaterial, cbeKeyPressed,
cbeClockSwitched, cbeTimeOut, cbeExit, cbeMenu, cbeActivate, cbeFormMoving,
cbeRefreshAll);
// It's possible to add new events. cbeRefreshAll signals that global options had been changed
TGameChessBoardHandler = procedure(e: TGameChessBoardEvent;
d1: pointer = nil; d2: pointer = nil) of object;
{$IFDEF THREADED_CHESSCLOCK}
TGameChessBoard = class;
TTimeLabelThread = class(TThread)
private
ChessBoard: TGameChessBoard;
player_time: array[TFigureColor] of TDateTime;
protected
procedure Execute; override;
public
WhiteTime, BlackTime: string;
constructor Create(ChessBoard: TGameChessBoard);
end;
{$ENDIF}
TGameChessBoard = class(TTntForm, ILocalizable)
TimePanel: TPanel;
WhiteLabel: TTntLabel;
WhiteTimeLabel: TLabel;
BlackLabel: TTntLabel;
BlackTimeLabel: TLabel;
GameTimer: TTimer;
WhiteFlagButton: TSpeedButton;
BlackFlagButton: TSpeedButton;
WhitePanel: TPanel;
BlackPanel: TPanel;
ChessBoardPanel: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure GameTimerTimer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormActivate(Sender: TObject);
procedure FlagButtonClick(Sender: TObject);
procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
var Resize: Boolean);
procedure TimePanelResize(Sender: TObject);
private
m_ChessBoard: TChessBoard;
m_PosBaseChessBoardLayer: TPosBaseChessBoardLayer;
FHandler: TGameChessBoardHandler;
auto_flag: boolean; // èíäèêàòîð àâòîôëàãà
player_time: array[TFigureColor] of TDateTime; // âðåìÿ áåëûõ è ÷¸ðíûõ
past_time: TDateTime; // âðåìÿ íà÷àëà îáäóìûâàíèÿ õîäà
unlimited_var: array[TFigureColor] of boolean; // ïàðòèÿ áåç âðåìåííîãî êîíòðîëÿ
clock_color: TFigureColor; // öâåò àíèìèðóåìîé ôèãóðû
shuted: boolean; // èíäèêàòîð âíåøíåãî çàêðûòèÿ îêíà
// Resizing
m_ResizingType: (rtNo, rtHoriz, rtVert);
// m_iDeltaWidthHeight: integer;
m_iTimePanelInitialWidth: integer;
m_iWhitePanelInitialLeft, m_iBlackPanelInitialLeft: integer;
m_iWhitePanelInitialWidth, m_iBlackPanelInitialWidth: integer;
m_TimeFont: TFont;
m_bFlashOnMove: boolean; // flag for flashing window on icoming move
{$IFDEF THREADED_CHESSCLOCK}
TimeLabelThread: TTimeLabelThread; // íèòü èñïîëüçóåòñÿ äëÿ áîðüáû ñ ëàãîì â Ìèðàíäå
{$ENDIF}
function FGetMode: TMode;
procedure FSetMode(const Value: TMode);
procedure ShowTime(const c: TFigureColor);
function FGetPlayerColor: TFigureColor;
procedure FSetPlayerColor(const Value: TFigureColor);
function FGetFlipped: boolean;
procedure FSetFlipped(bValue: boolean);
function FGetTime(color: TFigureColor): TDateTime;
procedure FSetTime(color: TFigureColor; const tm: TDateTime);
procedure FSetUnlimited(color: TFigureColor; const unl: boolean);
function FGetUnlimited(color: TFigureColor): boolean;
function FGetLastMoveHilighted: boolean;
procedure FSetLastMoveHilighted(bValue: boolean);
function FGetCoordinatesShown: boolean;
procedure FSetCoordinatesShown(bValue: boolean);
function GetStayOnTop: boolean;
procedure FSetStayOnTop(onTop: boolean);
procedure FSetAutoFlag(auto_flag: boolean);
procedure FFlashWindow;
function FGetAnimation: TAnimation;
procedure FSetAnimation(const Value: TAnimation);
function FGetViewGaming: boolean;
procedure FSetViewGaming(bValue: boolean);
// Localization
procedure ILocalizable.Localize = FLocalize;
procedure FLocalize;
procedure WMMoving(var Msg: TWMMoving); message WM_MOVING;
procedure WMSizing(var Msg: TMessage); message WM_SIZING;
function FGetPositionColor: TFigureColor;
function FGetTrainingMode: boolean;
procedure FSetTrainingMode(bValue: boolean);
function FGetUseUserBase: boolean;
procedure FSetUseUserBase(bValue: boolean);
procedure FChessBoardHandler(e: TChessBoardEvent; d1: pointer = nil;
d2: pointer = nil);
procedure FDoHandler(e: TGameChessBoardEvent; d1: pointer = nil;
d2: pointer = nil);
public
constructor Create(Owner: TComponent; AHandler: TGameChessBoardHandler = nil;
const strPosBaseName: string = ''); reintroduce;
procedure FCreateChessBoard(const strPosBaseName: string);
procedure FDestroyChessBoard;
procedure TakeBack; // âçÿòèå õîäà îáðàòíî
procedure SwitchClock(clock_color: TFigureColor);
procedure InitPosition;
procedure PPRandom;
procedure StopClock;
procedure ResetMoveList;
function SetPosition(const strPosition: string): boolean;
function GetPosition: string;
function NMoveDone: integer; // êîëè÷åñòâî ñäåëàííûõ õîäîâ
function DoMove(const strMove: string): boolean;
procedure Shut;
procedure WriteGameToBase(vGameResult: TGameResult);
procedure SetExternalBase(const strExtPosBaseName: string);
procedure UnsetExternalBase;
property Unlimited[color: TFigureColor]: boolean read FGetUnlimited write FSetUnlimited;
property Time[color: TFigureColor]: TDateTime read FGetTime write FSetTime;
property PlayerColor: TFigureColor read FGetPlayerColor write FSetPlayerColor;
property PositionColor: TFigureColor read FGetPositionColor; // Whos move it is in the current position
property ClockColor: TFigureColor read clock_color;
property Mode: TMode read FGetMode write FSetMode;
property CoordinatesShown: boolean read FGetCoordinatesShown write FSetCoordinatesShown;
property Flipped: boolean read FGetFlipped write FSetFlipped;
property LastMoveHilighted: boolean read FGetLastMoveHilighted write FSetLastMoveHilighted;
property FlashOnMove: boolean read m_bFlashOnMove write m_bFlashOnMove;
property StayOnTop: boolean read GetStayOnTop write FSetStayOnTop;
property AutoFlag: boolean read auto_flag write FSetAutoFlag;
property Animation: TAnimation read FGetAnimation write FSetAnimation;
property ViewGaming: boolean read FGetViewGaming write FSetViewGaming;
property pTrainingMode: boolean read FGetTrainingMode write FSetTrainingMode;
property pUseUserBase: boolean read FGetUseUserBase write FSetUseUserBase;
end;
implementation
{$J+}
{$R *.dfm}
uses
SysUtils, Types, Windows,
//
ChessClockUnit;
const
TIME_COLOR = clBlack;
ZEITNOT_COLOR = clMaroon;
// CHEAT_TIME_CONST = 1.5; // > 1
WHITE_LONG_LABEL: WideString = 'White ';
WHITE_MEDIUM_LABEL: WideString = 'White ';
WHITE_SHORT_LABEL: WideString = 'W ';
BLACK_LONG_LABEL: WideString = 'Black ';
BLACK_MEDIUM_LABEL: WideString = 'Black ';
BLACK_SHORT_LABEL: WideString = 'B ';
////////////////////////////////////////////////////////////////////////////////
// TTimeLabelThread
{$IFDEF THREADED_CHESSCLOCK}
procedure TTimeLabelThread.Execute;
begin
while ChessBoard.GameTimer.Enabled do
begin
if self.player_time[fcWhite] <> ChessBoard.player_time[fcWhite] then
ChessBoard.ShowTime(fcWhite);
if self.player_time[fcBlack] <> ChessBoard.player_time[fcBlack] then
ChessBoard.ShowTime(fcBlack);
Sleep(ChessBoard.GameTimer.Interval div 2);
end;
ChessBoard.TimeLabelThread := nil;
end;
constructor TTimeLabelThread.Create(ChessBoard: TGameChessBoard);
begin
self.ChessBoard := ChessBoard;
self.player_time[fcWhite] := ChessBoard.player_time[fcWhite];
self.player_time[fcBlack] := ChessBoard.player_time[fcBlack];
inherited Create(TRUE);
//Priority := tpNormal;
FreeOnTerminate := TRUE;
Resume;
end;
{$ENDIF}
////////////////////////////////////////////////////////////////////////////////
// TGameChessBoard
function TGameChessBoard.DoMove(const strMove: string): boolean;
begin
Result := m_ChessBoard.DoMove(strMove);
if (Result) then
begin
if (m_bFlashOnMove and (Mode = mGame)) then
FFlashWindow;
end;
end;
procedure TGameChessBoard.ShowTime(const c: TFigureColor);
var
time_label: TLabel;
begin
if c = fcWhite then time_label:= WhiteTimeLabel
else time_label:= BlackTimeLabel;
if unlimited_var[c] then
begin
time_label.Caption:= '';
exit;
end;
if (TChessClock.IsZeitnot(player_time[c])) then
time_label.Font.Color := ZEITNOT_COLOR
else
time_label.Font.Color := TIME_COLOR;
time_label.Caption := TChessClock.ConvertToStr(player_time[c]);
end;
procedure TGameChessBoard.ResetMoveList;
begin
m_ChessBoard.ResetMoveList;
end;
function TGameChessBoard.SetPosition(const strPosition: string): boolean;
begin
Result := m_ChessBoard.SetPosition(strPosition);
if (Result) then
clock_color := PositionColor;
end;
function TGameChessBoard.GetPosition: string;
begin
Result := m_ChessBoard.GetPosition;
end;
procedure TGameChessBoard.FormCreate(Sender: TObject);
begin
m_iTimePanelInitialWidth := TimePanel.Width;
m_iWhitePanelInitialLeft := WhitePanel.Left;
m_iWhitePanelInitialWidth := WhitePanel.Width;
m_iBlackPanelInitialLeft := BlackPanel.Left;
m_iBlackPanelInitialWidth := BlackPanel.Width;
m_TimeFont := TFont.Create;
m_TimeFont.Assign(WhiteTimeLabel.Font);
BlackFlagButton.Glyph := WhiteFlagButton.Glyph; // For size minimization
TLocalizer.Instance.AddSubscriber(self);
FLocalize;
// Clock initialization
FSetUnlimited(fcWhite, TRUE);
FSetUnlimited(fcBlack, TRUE);
end;
constructor TGameChessBoard.Create(Owner: TComponent;
AHandler: TGameChessBoardHandler = nil; const strPosBaseName: string = '');
begin
FHandler := AHandler;
inherited Create(Owner);
FCreateChessBoard(strPosBaseName);
end;
procedure TGameChessBoard.FCreateChessBoard(const strPosBaseName: string);
begin
m_ChessBoard := TChessBoard.Create(self, FChessBoardHandler);
m_PosBaseChessBoardLayer := TPosBaseChessBoardLayer.Create(strPosBaseName);
m_ChessBoard.AddLayer(m_PosBaseChessBoardLayer);
with ChessBoardPanel do
SetBounds(Left, Top, m_ChessBoard.ClientWidth, m_ChessBoard.ClientHeight);
m_ChessBoard.BorderStyle := bsNone;
m_ChessBoard.Align := alClient;
m_ChessBoard.Parent := ChessBoardPanel;
m_ChessBoard.Visible := TRUE;
InitPosition;
end;
procedure TGameChessBoard.FDestroyChessBoard;
begin
m_ChessBoard.RemoveLayer(m_PosBaseChessBoardLayer); // m_ChessBoard is destroyed by its parent
FreeAndNil(m_PosBaseChessBoardLayer);
end;
procedure TGameChessBoard.FormDestroy(Sender: TObject);
begin
TLocalizer.Instance.DeleteSubscriber(self);
m_TimeFont.Free;
FDestroyChessBoard;
end;
procedure TGameChessBoard.InitPosition;
begin
m_ChessBoard.InitPosition;
end;
procedure TGameChessBoard.FSetMode(const Value: TMode);
begin
m_ChessBoard.Mode := Value;
if (Value <> mGame) then
begin
WhiteFlagButton.Visible := FALSE;
BlackFlagButton.Visible := FALSE;
end;
end;
function TGameChessBoard.FGetMode: TMode;
begin
Result := m_ChessBoard.Mode;
end;
procedure TGameChessBoard.FSetTime(color: TFigureColor; const tm: TDateTime);
begin
if (not Unlimited[color]) then
begin
if ((not auto_flag) and (not ViewGaming)) then
begin
case color of
fcWhite:
WhiteFlagButton.Visible := ((PlayerColor = fcBlack) and (tm = 0.0));
fcBlack:
BlackFlagButton.Visible := ((PlayerColor = fcWhite) and (tm = 0.0));
end;
end;
player_time[color] := tm;
ShowTime(color);
end;
end;
function TGameChessBoard.FGetTime(color: TFigureColor): TDateTime;
begin
Result:= player_time[color];
end;
procedure TGameChessBoard.GameTimerTimer(Sender: TObject);
begin
if unlimited_var[clock_color] then
begin
GameTimer.Enabled := FALSE;
exit;
end;
// TODO: cheating check
player_time[clock_color] := player_time[clock_color] - (Now - past_time);
if player_time[clock_color] <= 0.0 then
begin
player_time[clock_color] := 0.0;
ShowTime(clock_color);
if ((not auto_flag) and (PlayerColor <> clock_color) and (not ViewGaming)) then
begin
case clock_color of
fcWhite:
WhiteFlagButton.Visible := TRUE;
fcBlack:
BlackFlagButton.Visible := TRUE;
end;
end;
if ((PlayerColor <> clock_color) and (Mode = mGame) and (auto_flag)) then
FDoHandler(cbeTimeOut, self);
GameTimer.Enabled := FALSE;
end;
{$IFNDEF THREADED_CHESSCLOCK}
ShowTime(clock_color);
{$ENDIF}
past_time:= Now;
end;
procedure TGameChessBoard.FSetUnlimited(color: TFigureColor; const unl: boolean);
begin
unlimited_var[color]:= unl;
ShowTime(color);
end;
function TGameChessBoard.FGetUnlimited(color: TFigureColor): boolean;
begin
Result := unlimited_var[color];
end;
procedure TGameChessBoard.SwitchClock(clock_color: TFigureColor);
begin
self.clock_color := clock_color;
if (not GameTimer.Enabled) then
begin
past_time := Now;
GameTimer.Enabled := TRUE;
end;
if (Mode = mGame) then
FDoHandler(cbeClockSwitched, self);
ShowTime(clock_color);
{$IFDEF THREADED_CHESSCLOCK}
if (not Assigned(TimeLabelThread)) then
TimeLabelThread := TTimeLabelThread.Create(self);
{$ENDIF}
end;
procedure TGameChessBoard.FSetPlayerColor(const Value: TFigureColor);
begin
m_ChessBoard.PlayerColor := Value;
end;
function TGameChessBoard.FGetPlayerColor: TFigureColor;
begin
Result := m_ChessBoard.PlayerColor;
end;
procedure TGameChessBoard.StopClock;
begin
GameTimer.Enabled := FALSE;
WhiteFlagButton.Visible := FALSE;
BlackFlagButton.Visible := FALSE;
end;
procedure TGameChessBoard.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
var
iNewChessBoardWidth, iNewChessBoardHeight: integer;
begin
Resize := (m_ResizingType <> rtNo);
if (not Resize) then
exit;
iNewChessBoardWidth := m_ChessBoard.Width + (NewWidth - self.Width);
iNewChessBoardHeight := m_ChessBoard.Height + (NewHeight - self.Height);
m_ChessBoard.FormCanResize(self, iNewChessBoardWidth, iNewChessBoardHeight, Resize);
if (Resize) then
begin
NewWidth := self.Width + (iNewChessBoardWidth - m_ChessBoard.Width);
NewHeight := self.Height + (iNewChessBoardHeight - m_ChessBoard.Height);
end;
end;
procedure TGameChessBoard.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (not shuted) then
begin
FDoHandler(cbeExit, self);
Action:= caNone;
end
else
shuted := FALSE;
end;
procedure TGameChessBoard.Shut;
begin
shuted:= TRUE;
Close;
end;
procedure TGameChessBoard.PPRandom;
begin
m_ChessBoard.PPRandom;
end;
procedure TGameChessBoard.TakeBack;
begin
m_ChessBoard.TakeBack;
end;
function TGameChessBoard.FGetLastMoveHilighted: boolean;
begin
Result := m_ChessBoard.LastMoveHilighted;
end;
procedure TGameChessBoard.FSetLastMoveHilighted(bValue: boolean);
begin
m_ChessBoard.LastMoveHilighted := bValue;
end;
procedure TGameChessBoard.FSetCoordinatesShown(bValue: boolean);
begin
m_ChessBoard.CoordinatesShown := bValue;
end;
function TGameChessBoard.FGetCoordinatesShown: boolean;
begin
Result := m_ChessBoard.CoordinatesShown;
end;
function TGameChessBoard.NMoveDone: integer;
begin
Result := m_ChessBoard.NMoveDone;
end;
procedure TGameChessBoard.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
FDoHandler(cbeKeyPressed, Pointer(Key), self);
end;
function TGameChessBoard.GetStayOnTop: boolean;
begin
Result := (self.FormStyle = fsStayOnTop);
end;
procedure TGameChessBoard.FSetStayOnTop(onTop: boolean);
begin
if (onTop) then
self.FormStyle := fsStayOnTop
else
self.FormStyle := fsNormal;
end;
procedure TGameChessBoard.FormActivate(Sender: TObject);
begin
FDoHandler(cbeActivate, self);
end;
procedure TGameChessBoard.WMMoving(var Msg: TWMMoving);
begin
// TODO: it's possible to handle if form is outside of the screen
FDoHandler(cbeFormMoving, Pointer(Msg.DragRect.Left - Left), Pointer(Msg.DragRect.Top - Top));
inherited;
end;
procedure TGameChessBoard.WMSizing(var Msg: TMessage);
begin
m_ChessBoard.Perform(Msg.Msg, Msg.WParam, Msg.LParam);
case Msg.WParam of
WMSZ_RIGHT, WMSZ_LEFT, WMSZ_BOTTOMRIGHT, WMSZ_TOPLEFT:
m_ResizingType := rtHoriz;
WMSZ_BOTTOM, WMSZ_TOP:
m_ResizingType := rtVert;
else
begin
m_ResizingType := rtNo;
PRect(Msg.LParam).Left := Left;
PRect(Msg.LParam).Top := Top;
end;
end; // case
end;
function TGameChessBoard.FGetPositionColor: TFigureColor;
begin
Result := m_ChessBoard.PositionColor;
end;
procedure TGameChessBoard.FlagButtonClick(Sender: TObject);
begin
if (Mode = mGame) then
FDoHandler(cbeTimeOut, self);
end;
procedure TGameChessBoard.FSetAutoFlag(auto_flag: boolean);
begin
self.auto_flag := auto_flag;
if (auto_flag) then
begin
WhiteFlagButton.Visible := FALSE;
BlackFlagButton.Visible := FALSE;
end;
end;
procedure TGameChessBoard.TimePanelResize(Sender: TObject);
var
rRatio: real;
begin
// Adjust panels on TimePanel
rRatio := TimePanel.Width / m_iTimePanelInitialWidth;
WhitePanel.Left := Round(rRatio * m_iWhitePanelInitialLeft);
WhitePanel.Width := m_iWhitePanelInitialWidth;
BlackPanel.Left := Round(rRatio * m_iBlackPanelInitialLeft);
BlackPanel.Width := m_iBlackPanelInitialWidth;
WhiteTimeLabel.Font.Assign(m_TimeFont);
BlackTimeLabel.Font.Assign(m_TimeFont);
if (WhitePanel.Left + WhitePanel.Width < BlackPanel.Left) then
begin
WhiteLabel.Caption := WHITE_LONG_LABEL;
BlackLabel.Caption := BLACK_LONG_LABEL;
end
else
begin
WhitePanel.Left := 4;
WhitePanel.Width := TimePanel.Width div 2;
BlackPanel.Left := TimePanel.Width div 2;
BlackPanel.Width := TimePanel.Width div 2 - 4;
WhiteLabel.Caption := WHITE_MEDIUM_LABEL;
BlackLabel.Caption := BLACK_MEDIUM_LABEL;
end;
// Adjust color labels
if ((WhiteTimeLabel.Left + WhiteTimeLabel.Width > WhitePanel.Width) or
(BlackTimeLabel.Left + BlackTimeLabel.Width > BlackPanel.Width)) then
begin
WhiteLabel.Caption := WHITE_MEDIUM_LABEL;
BlackLabel.Caption := BLACK_MEDIUM_LABEL;
if ((WhiteTimeLabel.Left + WhiteTimeLabel.Width <= WhitePanel.Width) and
(BlackTimeLabel.Left + BlackTimeLabel.Width <= BlackPanel.Width)) then
exit; // TODO: a KLUDGE - make it nice!
WhiteTimeLabel.Font.Size := WhiteTimeLabel.Font.Size - 4;
BlackTimeLabel.Font.Size := BlackTimeLabel.Font.Size - 4;
WhiteLabel.Caption := WHITE_SHORT_LABEL;
BlackLabel.Caption := BLACK_SHORT_LABEL;
end;
end;
procedure TGameChessBoard.FFlashWindow;
var
flushWindowInfo: TFlashWInfo;
begin
// Flash with taskbar
flushWindowInfo.cbSize := SizeOf(flushWindowInfo);
flushWindowInfo.hwnd := Application.Handle;
flushWindowInfo.dwflags := FLASHW_TRAY; // FLASHW_ALL; //FLASHW_TRAY;
flushWindowInfo.ucount := 3; // Flash times
flushWindowInfo.dwtimeout := 0; // speed in msec, 0 - frequency of cursor flashing
FlashWindowEx(flushWindowInfo);
if (self.Focused) then
exit;
// Flash window
flushWindowInfo.hwnd := self.Handle; // handle of the flashing window
flushWindowInfo.dwflags := FLASHW_CAPTION; // FLASHW_TRAY; // FLASHW_ALL; //FLASHW_TRAY;
FlashWindowEx(flushWindowInfo);
end;
procedure TGameChessBoard.FLocalize;
begin
with TLocalizer.Instance do
begin
WHITE_LONG_LABEL := GetLabel(13);
WHITE_MEDIUM_LABEL := GetLabel(14);
WHITE_SHORT_LABEL := GetLabel(15);
BLACK_LONG_LABEL := GetLabel(16);
BLACK_MEDIUM_LABEL := GetLabel(17);
BLACK_SHORT_LABEL := GetLabel(18);
end;
TimePanelResize(nil);
end;
procedure TGameChessBoard.WriteGameToBase(vGameResult: TGameResult);
begin
m_PosBaseChessBoardLayer.WriteGameToBase(vGameResult);
end;
procedure TGameChessBoard.SetExternalBase(const strExtPosBaseName: string);
begin
m_PosBaseChessBoardLayer.SetExternalBase(strExtPosBaseName);
end;
procedure TGameChessBoard.UnsetExternalBase;
begin
m_PosBaseChessBoardLayer.UnsetExternalBase;
end;
function TGameChessBoard.FGetTrainingMode: boolean;
begin
Result := m_PosBaseChessBoardLayer.TrainingMode;
end;
procedure TGameChessBoard.FSetTrainingMode(bValue: boolean);
begin
m_PosBaseChessBoardLayer.TrainingMode := bValue;
end;
function TGameChessBoard.FGetUseUserBase: boolean;
begin
Result := m_PosBaseChessBoardLayer.UseUserBase;
end;
procedure TGameChessBoard.FSetUseUserBase(bValue: boolean);
begin
m_PosBaseChessBoardLayer.UseUserBase := bValue;
end;
function TGameChessBoard.FGetFlipped: boolean;
begin
Result := m_ChessBoard.Flipped;
end;
procedure TGameChessBoard.FSetFlipped(bValue: boolean);
begin
m_ChessBoard.Flipped := bValue;
end;
function TGameChessBoard.FGetAnimation: TAnimation;
begin
Result := m_ChessBoard.Animation;
end;
procedure TGameChessBoard.FSetAnimation(const Value: TAnimation);
begin
m_ChessBoard.Animation := Value;
end;
function TGameChessBoard.FGetViewGaming: boolean;
begin
Result := m_ChessBoard.ViewGaming;
end;
procedure TGameChessBoard.FSetViewGaming(bValue: boolean);
begin
m_ChessBoard.ViewGaming := bValue;
end;
procedure TGameChessBoard.FChessBoardHandler(e: TChessBoardEvent; d1: pointer = nil;
d2: pointer = nil);
begin
case e of
ChessBoardUnit.cbeMate:
FDoHandler(cbeMate, self);
ChessBoardUnit.cbeStaleMate:
FDoHandler(cbeStaleMate, self);
ChessBoardUnit.cbeMoved:
begin
if ((Mode = mGame) and (PositionColor <> PlayerColor)) then
FDoHandler(cbeMoved, d1, self);
SwitchClock(PositionColor);
end;
ChessBoardUnit.cbeMenu:
FDoHandler(cbeMenu, self);
end;
end;
procedure TGameChessBoard.FDoHandler(e: TGameChessBoardEvent; d1: pointer = nil;
d2: pointer = nil);
begin
if (Assigned(FHandler)) then
FHandler(e, d1, d2);
end;
end.
|