-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwxmain.cpp
More file actions
1061 lines (961 loc) · 29.1 KB
/
wxmain.cpp
File metadata and controls
1061 lines (961 loc) · 29.1 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
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
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* wxmain.cpp
*
* wxWindows GUI framework
*
* Copyright (c) 2003 by Martin Trautmann (martintrautmann@gmx.de)
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free Software
* Foundation.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "zertz/network.hpp" //workaround for cygwin
#include "dvonn/network.hpp" //workaround for cygwin
#include "bloks/network.hpp" //workaround for cygwin
#include "relax/network.hpp" //workaround for cygwin
#include "wxmain.hpp"
#include "util.hpp"
#include <wx/wx.h>
#include <wx/image.h>
#include <wx/html/helpctrl.h> // use HTML help
#include <wx/cshelp.h>
#include <wx/zipstrm.h>
#include <wx/filesys.h>
#include <wx/fs_zip.h>
#include <wx/filefn.h>
#include <wx/stdpaths.h>
#ifndef DEFAULT_DATA_DIR
#define DEFAULT_DATA_DIR "./" // will be overridden by Makefile.am
#endif
#ifndef DEFAULT_DATA_DIR2
#define DEFAULT_DATA_DIR2 "./"
#endif
// enables to reproduce a specific sequence of random numbers
#define RANDOMIZE
//#define FIXED_RANDOM_SEED 123456789
namespace holtz
{
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
// the application icon
#ifndef __WXMSW__
#include "icon.xpm"
#endif
// ----------------------------------------------------------------------------
// event tables and other macros for wxWindows
// ----------------------------------------------------------------------------
// the event tables connect the wxWindows events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(Main_Frame, wxFrame) //**/
EVT_MENU(HOLTZ_NEW_ZERTZ_GAME, Main_Frame::on_new_zertz_game) //**/
EVT_MENU(HOLTZ_NEW_DVONN_GAME, Main_Frame::on_new_dvonn_game) //**/
EVT_MENU(HOLTZ_NEW_BLOKS_GAME, Main_Frame::on_new_bloks_game) //**/
EVT_MENU(HOLTZ_NEW_RELAX_GAME, Main_Frame::on_new_relax_game) //**/
EVT_MENU(HOLTZ_UNDO, Main_Frame::on_undo_move) //**/
EVT_MENU(HOLTZ_VARIANTS, Main_Frame::on_variants) //**/
EVT_MENU(HOLTZ_SETTINGS, Main_Frame::on_settings) //**/
EVT_MENU(HOLTZ_QUIT, Main_Frame::on_quit) //**/
EVT_MENU(HOLTZ_HELP_CONTENTS, Main_Frame::on_help_contents) //**/
EVT_MENU(HOLTZ_HELP_LICENSE, Main_Frame::on_help_license) //**/
EVT_MENU(HOLTZ_ABOUT, Main_Frame::on_about) //**/
EVT_CLOSE(Main_Frame::on_close) //**/
END_EVENT_TABLE() //**/
BEGIN_EVENT_TABLE(Game_Window, wxScrolledWindow) //**/
EVT_LEFT_DOWN(Game_Window::on_mouse_event) //**/
EVT_RIGHT_DOWN(Game_Window::on_mouse_event) //**/
EVT_WIZARD_CANCEL(DIALOG_WIZARD, Game_Window::on_wizard_cancel) //**/
EVT_WIZARD_PAGE_CHANGING(DIALOG_WIZARD, Game_Window::on_wizard_page_changing) //**/
EVT_WIZARD_FINISHED(DIALOG_WIZARD, Game_Window::on_wizard_finished) //**/
#ifdef DRAW_BACKGROUND
EVT_ERASE_BACKGROUND(Game_Window::on_erase_background) //**/
#endif
END_EVENT_TABLE() //**/
// ============================================================================
// implementation
// ============================================================================
/* for translation selection dialog
// language data
static const wxLanguage langIds[] =
{
wxLANGUAGE_USER_DEFINED,
wxLANGUAGE_GERMAN
};
// note that it makes no sense to translate these strings, they are
// shown before we set the locale anyhow
const wxString langNames[] =
{
wxT("English"),
wxT("Deutsch")
};
*/
// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------
// 'Main program' equivalent: the program execution "starts" here
bool wxHoltz::OnInit()
{
#ifdef RANDOMIZE
randomize();
#else
# ifdef FIXED_RANDOM_SEED
# warning "!!!undefine FIXED_RANDOM_SEED before compiling production code!!!"
srand(FIXED_RANDOM_SEED);
# endif
#endif
wxLocale *loc = new wxLocale();
int language = wxLANGUAGE_DEFAULT;
if( argc > 1 )
{
if( wxString(argv[1]) == wxT("de") || wxString(argv[1]) == wxT("de_DE") )
{
language = wxLANGUAGE_GERMAN;
}
if( wxString(argv[1]) == wxT("it") || wxString(argv[1]) == wxT("it_IT") )
{
language = wxLANGUAGE_ITALIAN;
}
}
loc->Init(language); // get default language from OS
wxLocale::AddCatalogLookupPathPrefix(wxT("locale")); // enable translation lookup from ./locale/
loc->AddCatalog(wxT("holtz")); // load translation file holtz.mo if available
loc->AddCatalog(wxT("holtz-hotkey")); // load translation file holtz-hotkey.mo if available
SetAppName(wxT("Holtz"));
SetVendorName(wxT("Martin Trautmann"));
global_config = new wxConfig(GetAppName());
wxConfig::Set(global_config);
// this will link all image libraries, also the unused ones
// wxInitAllImageHandlers(); // make it possible to load PNG images
// that's better, we don't use other image formats:
wxImage::AddHandler(new wxXPMHandler);
wxImage::AddHandler(new wxPNGHandler);
wxImage::AddHandler(new wxJPEGHandler);
// for html help
wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
provider->SetHelpController(&get_help_controller());
wxHelpProvider::Set(provider);
// for help: zip files
wxFileSystem::AddHandler(new wxZipFSHandler);
if(!init_help(*loc))
wxLogWarning(wxT("%s"),_("No help file found."));
check_config(); // asks for configuration if not yet done
// create the main application window
Main_Frame *frame = new Main_Frame( _("Holtz") );
// and show it (the frames, unlike simple controls, are not shown when
// created initially)
frame->Show(true);
SetTopWindow(frame);
SetExitOnFrameDelete(true);
// success: wxApp::OnRun() will be called which will enter the main message
// loop and the application will run. If we returned FALSE here, the
// application would exit immediately.
return TRUE;
}
bool wxHoltz::init_help(wxLocale& loc)
{
// try to load the HTML help file, in decreasing order:
// - data_dir1/help/help_la_co.*
// - data_dir1/help/help_la.*
// - data_dir2/help/help_la_co.*
// - data_dir2/help/help_la.*
// - data_dir1/help/help_en.*
// - data_dir2/help/help_en.*
// where 'la' is the language, and 'co' the country of the currently used locale
// if all fails, return false
wxString language = loc.GetCanonicalName();
if(!get_help_controller().Initialize(wxString(wxT(DEFAULT_DATA_DIR))
+ wxT("help/help_") + language))
if(language.Len() <= 2
|| !get_help_controller().Initialize(wxString(wxT(DEFAULT_DATA_DIR))
+ wxT("help/help_") + language.Left(2)))
if(!get_help_controller().Initialize(wxString(wxT(DEFAULT_DATA_DIR2))
+ wxT("help/help_") + language))
if(language.Len() <= 2
|| !get_help_controller().Initialize(wxString(wxT(DEFAULT_DATA_DIR2))
+ wxT("help/help_")
+ language.Left(2)))
if(!get_help_controller().Initialize(wxString(wxT(DEFAULT_DATA_DIR))
+ wxT("help/help_en")))
if(!get_help_controller().Initialize(wxString(wxT(DEFAULT_DATA_DIR2))
+ wxT("help/help_en")))
return false;
return true;
}
bool wxHoltz::check_config()
{
return true;
}
wxHoltz::~wxHoltz()
{
// doesn't work? seems to be already deleted
//delete global_config; // writes things back
}
// ----------------------------------------------------------------------------
// Game Window
// ----------------------------------------------------------------------------
Game_Window::Game_Window( wxFrame *parent_frame )
: wxScrolledWindow( parent_frame ),
parent_frame(*parent_frame),
active_game(NO_GAME),
zertz_game_manager(0), zertz_variants_frame(0), zertz_gui_manager(0), zertz_game_dialog(0),
dvonn_game_manager(0), dvonn_variants_frame(0), dvonn_gui_manager(0), dvonn_game_dialog(0),
bloks_game_manager(0), bloks_variants_frame(0), bloks_gui_manager(0), bloks_game_dialog(0),
relax_game_manager(0), relax_variants_frame(0), relax_gui_manager(0), relax_game_dialog(0)
{
SetBackgroundColour(*wxWHITE);
}
Game_Window::~Game_Window()
{
close_game();
}
void Game_Window::close_game()
{
switch( active_game ) {
case ZERTZ:
if( zertz_game_manager )
zertz_game_manager->stop_game();
active_game = NO_GAME;
delete zertz_game_dialog; // still needs game manager
delete zertz_gui_manager;
delete zertz_game_manager;
zertz_variants_frame->Destroy();
zertz_variants_frame = 0;
break;
case DVONN:
if( dvonn_game_manager )
dvonn_game_manager->stop_game();
active_game = NO_GAME;
delete dvonn_game_dialog; // still needs game manager
delete dvonn_gui_manager;
delete dvonn_game_manager;
dvonn_variants_frame->Destroy();
dvonn_variants_frame = 0;
break;
case BLOKS:
if( bloks_game_manager )
bloks_game_manager->stop_game();
active_game = NO_GAME;
delete bloks_game_dialog; // still needs game manager
delete bloks_gui_manager;
delete bloks_game_manager;
bloks_variants_frame->Destroy();
bloks_variants_frame = 0;
break;
case RELAX:
if( relax_game_manager )
relax_game_manager->stop_game();
active_game = NO_GAME;
delete relax_game_dialog; // still needs game manager
delete relax_gui_manager;
delete relax_game_manager;
relax_variants_frame->Destroy();
relax_variants_frame = 0;
break;
case NO_GAME:
break;
}
}
bool Game_Window::on_close()
{
return true;
}
void Game_Window::load_settings()
{
switch( active_game ) {
case ZERTZ:
zertz_gui_manager->load_settings();
break;
case DVONN:
dvonn_gui_manager->load_settings();
break;
case BLOKS:
bloks_gui_manager->load_settings();
break;
case RELAX:
relax_gui_manager->load_settings();
break;
case NO_GAME:
break;
}
}
void Game_Window::init_zertz()
{
close_game();
zertz_game_manager = new zertz::Game_Manager(wxEVT_ZERTZ_NOTIFY);
zertz_variants_frame = new zertz::Game_Variants_Frame( this );
zertz_gui_manager = new zertz::WX_GUI_Manager( *zertz_game_manager, *this,
*zertz_variants_frame->get_game_variants() );
zertz_game_dialog = new zertz::Game_Dialog( this, *zertz_game_manager, *zertz_gui_manager );
active_game = ZERTZ;
refresh();
}
void Game_Window::init_dvonn()
{
close_game();
dvonn_game_manager = new dvonn::Game_Manager(wxEVT_DVONN_NOTIFY);
dvonn_variants_frame = new dvonn::Game_Variants_Frame( this );
dvonn_gui_manager = new dvonn::WX_GUI_Manager( *dvonn_game_manager, *this,
*dvonn_variants_frame->get_game_variants() );
dvonn_game_dialog = new dvonn::Game_Dialog( this, *dvonn_game_manager, *dvonn_gui_manager );
active_game = DVONN;
refresh();
}
void Game_Window::init_bloks()
{
close_game();
bloks_game_manager = new bloks::Game_Manager(wxEVT_BLOKS_NOTIFY);
bloks_variants_frame = new bloks::Game_Variants_Frame( this );
bloks_gui_manager = new bloks::WX_GUI_Manager( *bloks_game_manager, *this,
*bloks_variants_frame->get_game_variants() );
bloks_game_dialog = new bloks::Game_Dialog( this, *bloks_game_manager, *bloks_gui_manager );
active_game = BLOKS;
refresh();
}
void Game_Window::init_relax()
{
close_game();
relax_game_manager = new relax::Game_Manager(wxEVT_RELAX_NOTIFY);
relax_variants_frame = new relax::Game_Variants_Frame( this );
relax_gui_manager = new relax::WX_GUI_Manager( *relax_game_manager, *this,
*relax_variants_frame->get_game_variants() );
relax_game_dialog = new relax::Game_Dialog( this, *relax_game_manager, *relax_gui_manager );
active_game = RELAX;
refresh();
}
void Game_Window::new_zertz_game()
{
if( active_game != ZERTZ )
{
if( active_game != NO_GAME )
{
if( wxMessageDialog
( this, _("You are about to switch to Zertz and close your current game. Proceed?"),
_("Closing Game"), wxYES_NO | wxCANCEL | wxICON_QUESTION ).ShowModal()
!= wxID_YES )
{
return;
}
}
init_zertz();
}
switch( active_game ) {
case ZERTZ:
zertz_game_manager->new_game();
break;
case DVONN:
dvonn_game_manager->new_game();
break;
case BLOKS:
bloks_game_manager->new_game();
break;
case RELAX:
relax_game_manager->new_game();
break;
case NO_GAME:
break;
}
}
void Game_Window::new_dvonn_game()
{
if( active_game != DVONN )
{
if( active_game != NO_GAME )
{
if( wxMessageDialog
( this, _("You are about to switch to Dvonn and close your current game. Proceed?"),
_("Closing Game"), wxYES_NO | wxCANCEL | wxICON_QUESTION ).ShowModal()
!= wxID_YES )
{
return;
}
}
init_dvonn();
}
switch( active_game ) {
case ZERTZ:
zertz_game_manager->new_game();
break;
case DVONN:
dvonn_game_manager->new_game();
break;
case BLOKS:
bloks_game_manager->new_game();
break;
case RELAX:
relax_game_manager->new_game();
break;
case NO_GAME:
break;
}
}
void Game_Window::new_bloks_game()
{
if( active_game != BLOKS )
{
if( active_game != NO_GAME )
{
if( wxMessageDialog
( this, _("You are about to switch to Bloks and close your current game. Proceed?"),
_("Closing Game"), wxYES_NO | wxCANCEL | wxICON_QUESTION ).ShowModal()
!= wxID_YES )
{
return;
}
}
init_bloks();
}
switch( active_game ) {
case ZERTZ:
zertz_game_manager->new_game();
break;
case DVONN:
dvonn_game_manager->new_game();
break;
case BLOKS:
bloks_game_manager->new_game();
break;
case RELAX:
relax_game_manager->new_game();
break;
case NO_GAME:
break;
}
}
void Game_Window::new_relax_game()
{
if( active_game != RELAX )
{
if( active_game != NO_GAME )
{
if( wxMessageDialog
( this, _("You are about to switch to Relax and close your current game. Proceed?"),
_("Closing Game"), wxYES_NO | wxCANCEL | wxICON_QUESTION ).ShowModal()
!= wxID_YES )
{
return;
}
}
init_relax();
}
switch( active_game ) {
case ZERTZ:
zertz_game_manager->new_game();
break;
case DVONN:
dvonn_game_manager->new_game();
break;
case BLOKS:
bloks_game_manager->new_game();
break;
case RELAX:
relax_game_manager->new_game();
break;
case NO_GAME:
break;
}
}
void Game_Window::undo_move()
{
switch( active_game ) {
case ZERTZ:
zertz_gui_manager->clear_target_variant();
zertz_game_manager->undo_moves();
break;
case DVONN:
dvonn_gui_manager->clear_target_variant();
dvonn_game_manager->undo_moves();
break;
case BLOKS:
bloks_gui_manager->clear_target_variant();
bloks_game_manager->undo_moves();
break;
case RELAX:
relax_gui_manager->clear_target_variant();
relax_game_manager->undo_moves();
break;
case NO_GAME:
break;
}
}
void Game_Window::variants()
{
switch( active_game ) {
case ZERTZ:
zertz_variants_frame->show_frame();
zertz_gui_manager->refresh();
break;
case DVONN:
dvonn_variants_frame->show_frame();
dvonn_gui_manager->refresh();
break;
case BLOKS:
bloks_variants_frame->show_frame();
bloks_gui_manager->refresh();
break;
case RELAX:
relax_variants_frame->show_frame();
relax_gui_manager->refresh();
break;
case NO_GAME:
break;
}
}
void Game_Window::settings_dialog()
{
switch( active_game ) {
case ZERTZ:
{
zertz::Settings_Dialog dialog( this, *zertz_gui_manager );
dialog.Center();
dialog.ShowModal();
}
break;
case DVONN:
{
dvonn::Settings_Dialog dialog( this, *dvonn_gui_manager );
dialog.Center();
dialog.ShowModal();
}
break;
case BLOKS:
{
bloks::Settings_Dialog dialog( this, *bloks_gui_manager );
dialog.Center();
dialog.ShowModal();
}
break;
case RELAX:
{
relax::Settings_Dialog dialog( this, *relax_gui_manager );
dialog.Center();
dialog.ShowModal();
}
break;
case NO_GAME:
break;
}
}
void Game_Window::show_status_text( wxString text ) // shows text in status bar
{
parent_frame.SetStatusText( text );
}
void Game_Window::init_scrollbars()
{
switch( active_game ) {
case ZERTZ:
SetScrollbars( 10, 10, zertz_gui_manager->get_width() / 10 + 1,
zertz_gui_manager->get_height() / 10 + 1 );
break;
case DVONN:
SetScrollbars( 10, 10, dvonn_gui_manager->get_width() / 10 + 1,
dvonn_gui_manager->get_height() / 10 + 1 );
break;
case BLOKS:
SetScrollbars( 10, 10, bloks_gui_manager->get_width() / 10 + 1,
bloks_gui_manager->get_height() / 10 + 1 );
break;
case RELAX:
SetScrollbars( 10, 10, relax_gui_manager->get_width() / 10 + 1,
relax_gui_manager->get_height() / 10 + 1 );
break;
case NO_GAME:
break;
}
}
const wxBitmap &Game_Window::get_background_bitmap()
{
switch( active_game ) {
case ZERTZ:
return zertz_gui_manager->get_game_panel().get_background();
case DVONN:
return dvonn_gui_manager->get_game_panel().get_background();
case BLOKS:
return bloks_gui_manager->get_game_panel().get_background();
case RELAX:
return relax_gui_manager->get_game_panel().get_background();
case NO_GAME:
break;
}
assert(false);
return *new wxBitmap();
}
void Game_Window::OnDraw( wxDC &_dc )
{
if( active_game == NO_GAME )
return;
// prepare background:
int width, width2;
int height, height2;
GetVirtualSize(&width,&height); // get size from scrolled window
GetSize(&width2,&height2);
if( width2 > width ) width = width2;
if( height2 > height ) height = height2;
#ifdef DOUBLE_BUFFER
wxBitmap buffer( width, height );
wxMemoryDC mem;
mem.SelectObject(buffer);
PrepareDC(mem);
wxDC *dc = &mem;
#else
wxDC *dc = &_dc;
//dc->BeginDrawing();
#endif
#ifdef DRAW_BACKGROUND
const wxBitmap &background = get_background_bitmap();
int bg_width = background.GetWidth();
int bg_height = background.GetHeight();
for( int y = 0; y < height + bg_height; y += bg_height )
{
for( int x = 0; x < width + bg_width; x += bg_width )
{
dc->DrawBitmap( background, x, y );
}
}
#endif
switch( active_game ) {
case ZERTZ:
zertz_gui_manager->draw( *dc );
zertz_gui_manager->draw_mark( *dc );
break;
case DVONN:
dvonn_gui_manager->draw( *dc );
dvonn_gui_manager->draw_mark( *dc );
break;
case BLOKS:
bloks_gui_manager->draw( *dc );
bloks_gui_manager->draw_mark( *dc );
break;
case RELAX:
relax_gui_manager->draw( *dc );
relax_gui_manager->draw_mark( *dc );
break;
case NO_GAME:
break;
}
#ifdef DOUBLE_BUFFER
#ifdef __WXGTK__ // work around for wxGTK which doesn't draw text on MemoryDC
// draw text directly on the real device context
//_dc.BeginDrawing();
_dc.Blit(0,0, width, height, dc, 0, 0 );
dc = &_dc;
#endif
#endif
switch( active_game ) {
case ZERTZ:
zertz_gui_manager->draw_text( *dc );
break;
case DVONN:
dvonn_gui_manager->draw_text( *dc );
break;
case BLOKS:
bloks_gui_manager->draw_text( *dc );
break;
case RELAX:
relax_gui_manager->draw_text( *dc );
break;
case NO_GAME:
break;
}
#ifdef DOUBLE_BUFFER
#ifndef __WXGTK__
// draw buffer on the real device context
//_dc.BeginDrawing();
_dc.Blit(0,0, width, height, dc, 0, 0 );
//_dc.EndDrawing();
#else
//_dc.EndDrawing();
#endif
#else
// dc->EndDrawing();
#endif
}
void Game_Window::on_erase_background( wxEraseEvent &event )
{
if( active_game == NO_GAME )
event.Skip(); // execute parent handler for this event
else
{
// do nothing, just don't erase background...
}
}
void Game_Window::on_mouse_event( wxMouseEvent &event )
{
int cl_x, cl_y;
GetViewStart( &cl_x, &cl_y ); // window might be scrolled
cl_x = cl_x*10 + event.GetX();
cl_y = cl_y*10 + event.GetY();
if( event.LeftDown() ) // if event is left click
{
switch( active_game ) {
case ZERTZ:
zertz_gui_manager->mouse_click_left( cl_x, cl_y );
break;
case DVONN:
dvonn_gui_manager->mouse_click_left( cl_x, cl_y );
break;
case BLOKS:
bloks_gui_manager->mouse_click_left( cl_x, cl_y );
break;
case RELAX:
relax_gui_manager->mouse_click_left( cl_x, cl_y );
break;
case NO_GAME:
break;
}
}
else
{
if( event.RightDown() ) // if event is left click
{
switch( active_game ) {
case ZERTZ:
zertz_gui_manager->mouse_click_right( cl_x, cl_y );
break;
case DVONN:
dvonn_gui_manager->mouse_click_right( cl_x, cl_y );
break;
case BLOKS:
bloks_gui_manager->mouse_click_right( cl_x, cl_y );
break;
case RELAX:
relax_gui_manager->mouse_click_right( cl_x, cl_y );
break;
case NO_GAME:
break;
}
}
}
}
void Game_Window::on_wizard_page_changing( wxWizardEvent& event )
{
switch( active_game ) {
case ZERTZ:
zertz_game_dialog->on_wizard_page_changing( event );
break;
case DVONN:
dvonn_game_dialog->on_wizard_page_changing( event );
break;
case BLOKS:
bloks_game_dialog->on_wizard_page_changing( event );
break;
case RELAX:
relax_game_dialog->on_wizard_page_changing( event );
break;
case NO_GAME:
break;
}
}
void Game_Window::on_wizard_finished( wxWizardEvent& event )
{
switch( active_game ) {
case ZERTZ:
zertz_game_dialog->on_wizard_finished( event );
break;
case DVONN:
dvonn_game_dialog->on_wizard_finished( event );
break;
case BLOKS:
bloks_game_dialog->on_wizard_finished( event );
break;
case RELAX:
relax_game_dialog->on_wizard_finished( event );
break;
case NO_GAME:
break;
}
}
void Game_Window::on_wizard_cancel( wxWizardEvent& event )
{
switch( active_game ) {
case ZERTZ:
zertz_game_dialog->on_wizard_cancel( event );
break;
case DVONN:
dvonn_game_dialog->on_wizard_cancel( event );
break;
case BLOKS:
bloks_game_dialog->on_wizard_cancel( event );
break;
case RELAX:
relax_game_dialog->on_wizard_cancel( event );
break;
case NO_GAME:
break;
}
}
void Game_Window::refresh()
{
Refresh();
Update();
}
wxDC *Game_Window::get_client_dc() // must be destroyed
{
wxDC *dc = new wxClientDC(this);
PrepareDC(*dc);
return dc;
}
// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------
// frame constructor
Main_Frame::Main_Frame( const wxString& title )
: wxFrame( /*paRent*/0, /*id*/-1, title, restore_position(), restore_size(),
wxDEFAULT_FRAME_STYLE ),
game_window(this),
setting_menu(0)
{
// set the frame icon
SetIcon(wxICON(icon));
// create the menu
SetMenuBar(create_menu());
#if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(1);
SetStatusText(_("Welcome to Holtz!"));
#endif // wxUSE_STATUSBAR
game_window.Show(true);
}
Main_Frame::~Main_Frame()
{
}
wxMenuBar* Main_Frame::create_menu()
{
// create a menu bar
wxMenu *file_menu = new wxMenu;
file_menu->Append(HOLTZ_NEW_ZERTZ_GAME, _("New &Zertz Game...\tCtrl-Z"),
_("Start a new Zertz game"));
file_menu->Append(HOLTZ_NEW_DVONN_GAME, _("New &Dvonn Game...\tCtrl-D"),
_("Start a new Dvonn game"));
file_menu->Append(HOLTZ_NEW_BLOKS_GAME, _("New &Bloks Game...\tCtrl-B"),
_("Start a new Bloks game"));
file_menu->Append(HOLTZ_NEW_RELAX_GAME, _("New &Relax Game...\tCtrl-R"),
_("Start a new Relax game"));
file_menu->AppendSeparator();
file_menu->Append(HOLTZ_QUIT, _("E&xit\tAlt-X"), _("Quit Holtz"));
// the "Setting" item should be in the help menu
setting_menu = new wxMenu;
setting_menu->Append(HOLTZ_SETTINGS, _("Display s&ettings...\tCtrl-E"),
_("Change display settings"));
// the "Setting" item should be in the help menu
game_menu = new wxMenu;
game_menu->Append(HOLTZ_UNDO, _("&Undo move\tCtrl-U"), _("Try to undo move"));
game_menu->Append(HOLTZ_VARIANTS, _("Show &Variants\tCtrl-V"),
_("Show window with variant tree"));
// the "About" item should be in the help menu
wxMenu *help_menu = new wxMenu;
help_menu->Append(HOLTZ_HELP_CONTENTS, _("Contents\tF1"), _("Show help file"));
help_menu->Append(HOLTZ_HELP_LICENSE, _("License"), _("Information about the Holtz license"));
help_menu->Append(HOLTZ_ABOUT, _("About"), _("Show about dialog"));
// now append the freshly created menu to the menu bar...
wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append(file_menu, _("&File"));
menu_bar->Append(setting_menu, _("&Settings"));
menu_bar->Append(game_menu, _("&Game"));
menu_bar->Append(help_menu, _("&Help"));
return menu_bar;
}
void Main_Frame::save_size_and_position()
{
wxPoint pos = GetPosition();
wxSize size = GetSize();
wxConfigBase* cfg = wxConfig::Get();
cfg->Write(wxT("MainXPos"), (long)pos.x);
cfg->Write(wxT("MainYPos"), (long)pos.y);
cfg->Write(wxT("MainXSize"), (long)size.GetWidth());
cfg->Write(wxT("MainYSize"), (long)size.GetHeight());
cfg->Flush();
}
wxSize Main_Frame::restore_size()
{
wxConfigBase* cfg = wxConfig::Get();
wxSize size;
size.SetWidth(cfg->Read(wxT("MainXSize"), 640));
size.SetHeight(cfg->Read(wxT("MainYSize"), 480));
return size;
}
wxPoint Main_Frame::restore_position()
{
wxConfigBase* cfg = wxConfig::Get();
wxPoint pos;
pos.x = cfg->Read(wxT("MainXPos"), -1); // -1 is the default position
pos.y = cfg->Read(wxT("MainYPos"), -1);
return pos;
}
void Main_Frame::load_settings()
{
game_window.load_settings();
}
// event handlers
void Main_Frame::on_new_zertz_game(wxCommandEvent& WXUNUSED(event))
{
game_window.new_zertz_game();
}
void Main_Frame::on_new_dvonn_game(wxCommandEvent& WXUNUSED(event))
{
game_window.new_dvonn_game();
}
void Main_Frame::on_new_bloks_game(wxCommandEvent& WXUNUSED(event))
{
game_window.new_bloks_game();
}