-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphicsDlgs.cpp
1645 lines (1583 loc) · 56 KB
/
GraphicsDlgs.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
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
/*
/ GraphicsDlgs.cpp
/ various dialog classes [graphics]
/
/ version 1.0, 2009 February 3
/
/ Author: Sandro Furieri a-furieri@lqt.it
/
/ Copyright (C) 2009 Alessandro Furieri
/
/ This program is free software: you can redistribute it and/or modify
/ it under the terms of the GNU General Public License as published by
/ the Free Software Foundation, either version 3 of the License, or
/ (at your option) any later version.
/
/ This program is distributed in the hope that it will be useful,
/ but WITHOUT ANY WARRANTY; without even the implied warranty of
/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/ GNU General Public License for more details.
/
/ You should have received a copy of the GNU General Public License
/ along with this program. If not, see <http://www.gnu.org/licenses/>.
/
*/
#include "wx/colordlg.h"
#include "wx/graphics.h"
#include "wx/imaglist.h"
#include "Classdef.h"
#include "icons/checked_brush.xpm"
bool PointGraphicsDialog::Create(MyFrame * parent, wxString & table,
wxString & geom, wxString & descName,
int symbolId, wxColour & foreground,
wxColour & background)
{
//
// creating the dialog
//
MainFrame = parent;
TableName = table;
GeometryColumn = geom;
DescName = descName;
SymbolId = symbolId;
ColorSymbol = false;
ForegroundColor = foreground;
BackgroundColor = background;
CurrentForeground = foreground;
CurrentBackground = background;
if (wxDialog::Create(parent, wxID_ANY, wxT("Layer Graphics - POINT")) ==
false)
return false;
// populates individual controls
Bitmap = wxBitmap(64, 64);
MainFrame->GetSymbolBitmaps(&SymbolsList);
CurrentSymbol = SymbolsList.FindById(SymbolId);
CreateControls();
// sets dialog sizer
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
// centers the dialog window
Centre();
return true;
}
void PointGraphicsDialog::CreateControls()
{
//
// creating individual controls and setting initial values
//
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(topSizer);
wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
// first row: the Layer Table+Geometry
wxBoxSizer *layerSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(layerSizer, 0, wxALIGN_RIGHT | wxALL, 0);
wxStaticText *layerLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Vector Layer:"));
layerSizer->Add(layerLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString name = TableName + wxT(".") + GeometryColumn;
wxTextCtrl *layerValue = new wxTextCtrl(this, wxID_STATIC,
name, wxDefaultPosition,
wxSize(350, 22), wxTE_READONLY);
layerSizer->Add(layerValue, 0, wxALIGN_RIGHT | wxALL, 5);
// second row: description
wxBoxSizer *descSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(descSizer, 0, wxALIGN_RIGHT | wxALL, 0);
wxStaticText *descLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Description:"));
descSizer->Add(descLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
DescCtrl = new wxTextCtrl(this, wxID_STATIC, DescName,
wxDefaultPosition, wxSize(350, 22));
descSizer->Add(DescCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
// third row: Symbol
wxBoxSizer *symbolBoxSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(symbolBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxStaticBox *symBox = new wxStaticBox(this, wxID_STATIC,
wxT("Symbol selection"),
wxDefaultPosition,
wxDefaultSize);
wxBoxSizer *symGroupSizer = new wxStaticBoxSizer(symBox, wxVERTICAL);
symbolBoxSizer->Add(symGroupSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
wxBoxSizer *symSizer = new wxBoxSizer(wxHORIZONTAL);
symGroupSizer->Add(symSizer, 0, wxALIGN_RIGHT | wxALL, 0);
SymbolsCtrl =
new wxListCtrl(this, ID_POINT_SYMBOLS, wxDefaultPosition, wxSize(400, 300),
wxLC_ICON | wxLC_SINGLE_SEL);
symGroupSizer->Add(SymbolsCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
SymbolsCtrl->AssignImageList(SymbolsList.BuildList(), wxIMAGE_LIST_NORMAL);
int i;
for (i = 0;
i < SymbolsCtrl->GetImageList(wxIMAGE_LIST_NORMAL)->GetImageCount(); i++)
SymbolsCtrl->InsertItem(i, i);
SymbolsCtrl->SetBackgroundColour(wxColour(240, 240, 208));
if (CurrentSymbol)
{
// selecting the current item
SymbolsCtrl->SetItemState(CurrentSymbol->GetListId(),
wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
SymbolsCtrl->EnsureVisible(CurrentSymbol->GetListId());
}
// fourth row: FOREGROUND and BACKGROUND buttons
wxBoxSizer *foreBackBox = new wxBoxSizer(wxHORIZONTAL);
symGroupSizer->Add(foreBackBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxStaticText *foreLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Foreground:"));
foreBackBox->Add(foreLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxBitmap disabledBmp;
GetDisabledButtonBitmap(disabledBmp);
wxBitmap foreBmp;
GetButtonBitmap(CurrentForeground, foreBmp);
ForegroundCtrl = new wxBitmapButton(this, ID_POINT_FOREGROUND, foreBmp);
ForegroundCtrl->SetBitmapDisabled(disabledBmp);
foreBackBox->Add(ForegroundCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxStaticText *backLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Background:"));
foreBackBox->Add(backLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxBitmap backBmp;
GetButtonBitmap(CurrentBackground, backBmp);
BackgroundCtrl = new wxBitmapButton(this, ID_POINT_BACKGROUND, backBmp);
BackgroundCtrl->SetBitmapDisabled(disabledBmp);
foreBackBox->Add(BackgroundCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
if (CurrentSymbol)
{
if (CurrentSymbol->IsFullColor() == true)
{
ForegroundCtrl->Enable(false);
BackgroundCtrl->Enable(false);
} else
{
ForegroundCtrl->Enable(true);
BackgroundCtrl->Enable(true);
}
} else
{
ForegroundCtrl->Enable(false);
BackgroundCtrl->Enable(false);
}
// fifth row: Example
wxBoxSizer *exampleBoxSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(exampleBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxStaticBox *exampleBox = new wxStaticBox(this, wxID_STATIC,
wxT("Example"),
wxDefaultPosition,
wxDefaultSize);
wxBoxSizer *exampleSizer = new wxStaticBoxSizer(exampleBox, wxHORIZONTAL);
exampleBoxSizer->Add(exampleSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
PaintBitmap();
ExampleCtrl =
new wxStaticBitmap(this, ID_POINT_EXAMPLE, Bitmap, wxDefaultPosition,
wxSize(Bitmap.GetWidth(), Bitmap.GetHeight()),
wxBORDER_SUNKEN);
exampleSizer->Add(ExampleCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
// OK - CANCEL buttons
wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
// appends event handler for OK button
Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
(wxObjectEventFunction) & PointGraphicsDialog::OnOk);
Connect(ID_POINT_SYMBOLS, wxEVT_COMMAND_LIST_ITEM_SELECTED,
(wxObjectEventFunction) & PointGraphicsDialog::OnSymbolSelected);
Connect(ID_POINT_FOREGROUND, wxEVT_COMMAND_BUTTON_CLICKED,
(wxObjectEventFunction) & PointGraphicsDialog::OnForeground);
Connect(ID_POINT_BACKGROUND, wxEVT_COMMAND_BUTTON_CLICKED,
(wxObjectEventFunction) & PointGraphicsDialog::OnBackground);
}
void PointGraphicsDialog::GetButtonBitmap(wxColour & color, wxBitmap & bmp)
{
// creating a Bitmap representing some Color
bmp = wxBitmap(64, 24);
wxMemoryDC *dc = new wxMemoryDC(bmp);
dc->SetBrush(wxBrush(color));
dc->DrawRectangle(-1, -1, 66, 26);
delete dc;
}
void PointGraphicsDialog::GetDisabledButtonBitmap(wxBitmap & bmp)
{
// creating the disabled Bitmap
bmp = wxBitmap(64, 24);
wxMemoryDC *dc = new wxMemoryDC(bmp);
dc->SetBrush(wxBrush(wxColour(240, 240, 240)));
dc->DrawRectangle(-1, -1, 66, 26);
delete dc;
}
void PointGraphicsDialog::PaintBitmap()
{
// painting the Example Bitmap
wxBrush checkedBrush;
checkedBrush.SetStipple(wxBitmap(checked_brush_xpm));
checkedBrush.SetStyle(wxSTIPPLE);
wxMemoryDC *dc = new wxMemoryDC(Bitmap);
wxGraphicsContext *gr = wxGraphicsContext::Create(*dc);
// background initialization
gr->SetBrush(checkedBrush);
gr->DrawRectangle(0, 0, Bitmap.GetWidth(), Bitmap.GetHeight());
// drawing the crosshair
gr->SetPen(wxPen(wxColour(255, 0, 0, 64)));
gr->StrokeLine(-1, -1, Bitmap.GetWidth(), Bitmap.GetHeight());
gr->StrokeLine(Bitmap.GetWidth(), -1, -1, Bitmap.GetHeight());
gr->StrokeLine(Bitmap.GetWidth() / 2, -1, Bitmap.GetWidth() / 2,
Bitmap.GetHeight());
gr->StrokeLine(-1, Bitmap.GetHeight() / 2, Bitmap.GetWidth(),
Bitmap.GetHeight() / 2);
if (CurrentSymbol == NULL)
{
// drawing a default marker
gr->SetPen(wxColour(0, 255, 0));
gr->SetBrush(wxBrush(wxColour(255, 0, 0)));
gr->DrawEllipse(Bitmap.GetWidth() / 2, Bitmap.GetHeight() / 2, 4, 4);
} else
{
// drawing the symbol
wxBitmap bmp;
CurrentSymbol->GetBitmap(bmp, CurrentForeground, CurrentBackground);
wxMask *mask = new wxMask(CurrentSymbol->GetMask());
bmp.SetMask(mask);
gr->DrawBitmap(bmp,
(Bitmap.GetWidth() / 2) - CurrentSymbol->GetHotPointX(),
(Bitmap.GetHeight() / 2) - CurrentSymbol->GetHotPointY(),
bmp.GetWidth(), bmp.GetHeight());
}
delete gr;
delete dc;
}
void PointGraphicsDialog::OnSymbolSelected(wxCommandEvent & WXUNUSED(event))
{
// symbol selection changed
int item = -1;
for (;;)
{
item =
SymbolsCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == -1)
break;
CurrentSymbol = SymbolsList.FindByPos(item);
}
PaintBitmap();
ExampleCtrl->SetBitmap(Bitmap);
if (CurrentSymbol)
{
if (CurrentSymbol->IsFullColor() == true)
{
ForegroundCtrl->Enable(false);
BackgroundCtrl->Enable(false);
} else
{
ForegroundCtrl->Enable(true);
BackgroundCtrl->Enable(true);
}
} else
{
ForegroundCtrl->Enable(false);
BackgroundCtrl->Enable(false);
}
}
void PointGraphicsDialog::OnForeground(wxCommandEvent & WXUNUSED(event))
{
// foreground color selection
wxColourData initColor;
int ret;
initColor.SetChooseFull(false);
initColor.SetColour(CurrentForeground);
wxColourDialog colorDialog(this, &initColor);
ret = colorDialog.ShowModal();
if (ret == wxID_OK)
{
wxColourData colorData = colorDialog.GetColourData();
CurrentForeground = colorData.GetColour();
PaintBitmap();
ExampleCtrl->SetBitmap(Bitmap);
wxBitmap bmp;
GetButtonBitmap(CurrentForeground, bmp);
ForegroundCtrl->SetBitmapLabel(bmp);
}
}
void PointGraphicsDialog::OnBackground(wxCommandEvent & WXUNUSED(event))
{
// background color selection
wxColourData initColor;
int ret;
initColor.SetChooseFull(false);
initColor.SetColour(CurrentBackground);
wxColourDialog colorDialog(this, &initColor);
ret = colorDialog.ShowModal();
if (ret == wxID_OK)
{
wxColourData colorData = colorDialog.GetColourData();
CurrentBackground = colorData.GetColour();
PaintBitmap();
ExampleCtrl->SetBitmap(Bitmap);
wxBitmap bmp;
GetButtonBitmap(CurrentBackground, bmp);
BackgroundCtrl->SetBitmapLabel(bmp);
}
}
void PointGraphicsDialog::OnOk(wxCommandEvent & WXUNUSED(event))
{
//
// all done:
//
if (CurrentSymbol)
{
SymbolId = CurrentSymbol->GetId();
ColorSymbol = CurrentSymbol->IsFullColor();
}
ForegroundColor = CurrentForeground;
BackgroundColor = CurrentBackground;
DescName = DescCtrl->GetValue();
wxDialog::EndModal(wxID_OK);
}
bool LineGraphicsDialog::Create(MyFrame * parent, wxString & table,
wxString & geom, wxString & descName,
wxColour & color, int thickness, int style)
{
//
// creating the dialog
//
MainFrame = parent;
TableName = table;
GeometryColumn = geom;
DescName = descName;
LineColor = color;
CurrentColor = color;
LineThickness = thickness;
CurrentThickness = thickness;
LineStyle = style;
CurrentStyle = style;
if (wxDialog::Create(parent, wxID_ANY, wxT("Layer Graphics - LINESTRING")) ==
false)
return false;
// populates individual controls
Bitmap = wxBitmap(400, 64);
CreateControls();
// sets dialog sizer
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
// centers the dialog window
Centre();
return true;
}
void LineGraphicsDialog::CreateControls()
{
//
// creating individual controls and setting initial values
//
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(topSizer);
wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
// first row: the Layer Table+Geometry
wxBoxSizer *layerSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(layerSizer, 0, wxALIGN_RIGHT | wxALL, 0);
wxStaticText *layerLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Vector Layer:"));
layerSizer->Add(layerLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString name = TableName + wxT(".") + GeometryColumn;
wxTextCtrl *layerValue = new wxTextCtrl(this, wxID_STATIC,
name, wxDefaultPosition,
wxSize(350, 22), wxTE_READONLY);
layerSizer->Add(layerValue, 0, wxALIGN_RIGHT | wxALL, 5);
// second row: description
wxBoxSizer *descSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(descSizer, 0, wxALIGN_RIGHT | wxALL, 0);
wxStaticText *descLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Description:"));
descSizer->Add(descLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
DescCtrl = new wxTextCtrl(this, wxID_STATIC, DescName,
wxDefaultPosition, wxSize(350, 22));
descSizer->Add(DescCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
// third row: Graphics
wxBoxSizer *graphicsBoxSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(graphicsBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxStaticBox *grBox = new wxStaticBox(this, wxID_STATIC,
wxT("Line graphics"),
wxDefaultPosition,
wxDefaultSize);
wxBoxSizer *grGroupSizer = new wxStaticBoxSizer(grBox, wxVERTICAL);
graphicsBoxSizer->Add(grGroupSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
wxBoxSizer *colorSizer = new wxBoxSizer(wxHORIZONTAL);
grGroupSizer->Add(colorSizer, 0, wxALIGN_RIGHT | wxALL, 0);
wxBitmap disabledBmp;
GetDisabledButtonBitmap(disabledBmp);
wxBitmap colorBmp;
GetButtonBitmap(CurrentColor, colorBmp);
ColorCtrl = new wxBitmapButton(this, ID_LINE_COLOR, colorBmp);
ColorCtrl->SetBitmapDisabled(disabledBmp);
colorSizer->Add(ColorCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxStaticText *alphaLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Transparency:"));
colorSizer->Add(alphaLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
AlphaCtrl =
new wxSlider(this, ID_LINE_ALPHA, CurrentColor.Alpha(), 0, 255,
wxDefaultPosition, wxSize(75, 20),
wxSL_HORIZONTAL | wxSL_INVERSE);
colorSizer->Add(AlphaCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxStaticText *thicknessLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Thickness:"));
colorSizer->Add(thicknessLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
char dummy[64];
sprintf(dummy, "%d", CurrentThickness);
wxString thick = wxString::FromUTF8(dummy);
ThicknessCtrl = new wxSpinCtrl(this, ID_LINE_THICKNESS, thick,
wxDefaultPosition, wxSize(80, 20),
wxSP_ARROW_KEYS, 1, 32, CurrentThickness);
colorSizer->Add(ThicknessCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxBoxSizer *styleBoxSizer = new wxBoxSizer(wxHORIZONTAL);
grGroupSizer->Add(styleBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxStaticBox *stlBox = new wxStaticBox(this, wxID_STATIC,
wxT("Style"),
wxDefaultPosition,
wxDefaultSize);
wxBoxSizer *styleSizer = new wxStaticBoxSizer(stlBox, wxVERTICAL);
styleBoxSizer->Add(styleSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
StyleCtrl =
new wxListCtrl(this, ID_LINE_STYLE, wxDefaultPosition, wxSize(400, 100),
wxLC_ICON | wxLC_SINGLE_SEL);
styleSizer->Add(StyleCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
StyleCtrl->AssignImageList(BuildStyleList(), wxIMAGE_LIST_NORMAL);
int i;
for (i = 0; i < StyleCtrl->GetImageList(wxIMAGE_LIST_NORMAL)->GetImageCount();
i++)
StyleCtrl->InsertItem(i, i);
// selecting the current item
int pos = Find();
if (pos > 0)
{
StyleCtrl->SetItemState(pos, wxLIST_STATE_SELECTED,
wxLIST_STATE_SELECTED);
StyleCtrl->EnsureVisible(pos);
}
// fourth row: Example
wxBoxSizer *exampleBoxSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(exampleBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxStaticBox *exampleBox = new wxStaticBox(this, wxID_STATIC,
wxT("Example"),
wxDefaultPosition,
wxDefaultSize);
wxBoxSizer *exampleSizer = new wxStaticBoxSizer(exampleBox, wxHORIZONTAL);
exampleBoxSizer->Add(exampleSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
PaintBitmap();
ExampleCtrl =
new wxStaticBitmap(this, ID_LINE_EXAMPLE, Bitmap, wxDefaultPosition,
wxSize(Bitmap.GetWidth(), Bitmap.GetHeight()),
wxBORDER_SUNKEN);
exampleSizer->Add(ExampleCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
// OK - CANCEL buttons
wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
// appends event handler for OK button
Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
(wxObjectEventFunction) & LineGraphicsDialog::OnOk);
Connect(ID_LINE_COLOR, wxEVT_COMMAND_BUTTON_CLICKED,
(wxObjectEventFunction) & LineGraphicsDialog::OnColor);
Connect(ID_LINE_ALPHA, wxEVT_SCROLL_THUMBRELEASE,
(wxObjectEventFunction) & LineGraphicsDialog::OnAlphaChanged);
Connect(ID_LINE_ALPHA, wxEVT_SCROLL_CHANGED,
(wxObjectEventFunction) & LineGraphicsDialog::OnAlphaChanged);
Connect(ID_LINE_THICKNESS, wxEVT_COMMAND_TEXT_UPDATED,
(wxObjectEventFunction) & LineGraphicsDialog::OnThicknessChanged);
Connect(ID_LINE_STYLE, wxEVT_COMMAND_LIST_ITEM_SELECTED,
(wxObjectEventFunction) & LineGraphicsDialog::OnStyleSelected);
}
void LineGraphicsDialog::GetButtonBitmap(wxColour & color, wxBitmap & bmp)
{
// creating a Bitmap representing some Color
bmp = wxBitmap(64, 24);
wxMemoryDC *dc = new wxMemoryDC(bmp);
dc->SetBrush(wxBrush(color));
dc->DrawRectangle(-1, -1, 66, 26);
delete dc;
}
void LineGraphicsDialog::GetDisabledButtonBitmap(wxBitmap & bmp)
{
// creating the disabled Bitmap
bmp = wxBitmap(64, 24);
wxMemoryDC *dc = new wxMemoryDC(bmp);
dc->SetBrush(wxBrush(wxColour(240, 240, 240)));
dc->DrawRectangle(-1, -1, 66, 26);
delete dc;
}
wxImageList *LineGraphicsDialog::BuildStyleList()
{
// building the style's images
wxBitmap img1(72, 8);
wxBitmap img2(72, 8);
wxBitmap img3(72, 8);
wxBitmap img4(72, 8);
wxBitmap img5(72, 8);
wxColour color(255, 255, 255);
wxBrush background(wxColour(204, 204, 204));
wxColour foreground(0, 0, 0);
wxImageList *list = new wxImageList(72, 8, true, 5);
wxMemoryDC *dc = new wxMemoryDC(img1);
// wxSOLID example
dc->SetBrush(background);
dc->DrawRectangle(-1, -1, img1.GetWidth() + 2, img1.GetHeight() + 2);
dc->SetPen(wxPen(foreground, 4, wxSOLID));
dc->DrawLine(0, 4, 128, 4);
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
delete dc;
list->Add(img1, color);
// wxDOT example
dc = new wxMemoryDC(img2);
dc->SetBrush(background);
dc->DrawRectangle(-1, -1, img2.GetWidth() + 2, img2.GetHeight() + 2);
dc->SetPen(wxPen(foreground, 4, wxDOT));
dc->DrawLine(0, 4, 128, 4);
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
delete dc;
list->Add(img2, color);
// wxLONG_DASH example
dc = new wxMemoryDC(img3);
dc->SetBrush(background);
dc->DrawRectangle(-1, -1, img3.GetWidth() + 2, img3.GetHeight() + 2);
dc->SetPen(wxPen(foreground, 4, wxLONG_DASH));
dc->DrawLine(0, 4, 128, 4);
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
delete dc;
list->Add(img3, color);
// wxSHORT_DASH example
dc = new wxMemoryDC(img4);
dc->SetBrush(background);
dc->DrawRectangle(-1, -1, img4.GetWidth() + 2, img4.GetHeight() + 2);
dc->SetPen(wxPen(foreground, 4, wxSHORT_DASH));
dc->DrawLine(0, 4, 128, 4);
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
delete dc;
list->Add(img4, color);
// wxDOT_DASH example
dc = new wxMemoryDC(img5);
dc->SetBrush(background);
dc->DrawRectangle(-1, -1, img5.GetWidth() + 2, img5.GetHeight() + 2);
dc->SetPen(wxPen(foreground, 4, wxDOT_DASH));
dc->DrawLine(0, 4, 128, 4);
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
delete dc;
list->Add(img5, color);
return list;
}
int LineGraphicsDialog::Find()
{
// return the position corresponding to the current style
if (CurrentStyle == wxSOLID)
return 0;
if (CurrentStyle == wxDOT)
return 1;
if (CurrentStyle == wxLONG_DASH)
return 2;
if (CurrentStyle == wxSHORT_DASH)
return 3;
if (CurrentStyle == wxDOT_DASH)
return 4;
// otherwyse we have some odd style
CurrentStyle = wxSOLID;
return 0;
}
int LineGraphicsDialog::Find(int pos)
{
// return the wxXXX constant corresponding to the currently selected style
if (pos == 0)
return wxSOLID;
if (pos == 1)
return wxDOT;
if (pos == 2)
return wxLONG_DASH;
if (pos == 3)
return wxSHORT_DASH;
if (pos == 4)
return wxDOT_DASH;
// otherwyse we have some odd style
return wxSOLID;
}
void LineGraphicsDialog::PaintBitmap()
{
// painting the Example Bitmap
wxBrush checkedBrush;
int tick = Bitmap.GetWidth() / 6;
checkedBrush.SetStipple(wxBitmap(checked_brush_xpm));
checkedBrush.SetStyle(wxSTIPPLE);
wxMemoryDC *dc = new wxMemoryDC(Bitmap);
wxGraphicsContext *gr = wxGraphicsContext::Create(*dc);
// background initialization
gr->SetBrush(checkedBrush);
gr->DrawRectangle(0, 0, Bitmap.GetWidth(), Bitmap.GetHeight());
// drawing the line
gr->SetPen(wxPen(CurrentColor, CurrentThickness, CurrentStyle));
wxGraphicsPath path = gr->CreatePath();
path.MoveToPoint(12, 12);
path.AddLineToPoint(tick, Bitmap.GetHeight() - 12);
path.AddLineToPoint((tick * 2), 12);
path.AddLineToPoint((tick * 3), Bitmap.GetHeight() - 12);
path.AddLineToPoint((tick * 4), 12);
path.AddLineToPoint((tick * 5), Bitmap.GetHeight() - 12);
path.AddLineToPoint(Bitmap.GetWidth() - 12, 12);
gr->StrokePath(path);
delete gr;
delete dc;
}
void LineGraphicsDialog::OnColor(wxCommandEvent & WXUNUSED(event))
{
// color selection
wxColourData initColor;
int ret;
initColor.SetChooseFull(false);
initColor.SetColour(CurrentColor);
wxColourDialog colorDialog(this, &initColor);
ret = colorDialog.ShowModal();
if (ret == wxID_OK)
{
wxColourData colorData = colorDialog.GetColourData();
wxColour color = colorData.GetColour();
CurrentColor =
wxColour(color.Red(), color.Green(), color.Blue(),
CurrentColor.Alpha());
PaintBitmap();
ExampleCtrl->SetBitmap(Bitmap);
wxBitmap bmp;
GetButtonBitmap(CurrentColor, bmp);
ColorCtrl->SetBitmapLabel(bmp);
}
}
void LineGraphicsDialog::OnAlphaChanged(wxCommandEvent & WXUNUSED(event))
{
//
// ALPHA selection changed
//
CurrentColor =
wxColour(CurrentColor.Red(), CurrentColor.Green(), CurrentColor.Blue(),
AlphaCtrl->GetValue());
PaintBitmap();
ExampleCtrl->SetBitmap(Bitmap);
}
void LineGraphicsDialog::OnThicknessChanged(wxCommandEvent & WXUNUSED(event))
{
//
// THICKNESS selection changed
//
CurrentThickness = ThicknessCtrl->GetValue();
PaintBitmap();
ExampleCtrl->SetBitmap(Bitmap);
}
void LineGraphicsDialog::OnStyleSelected(wxCommandEvent & WXUNUSED(event))
{
// style selection changed
int item = -1;
for (;;)
{
item =
StyleCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == -1)
break;
CurrentStyle = Find(item);
}
PaintBitmap();
ExampleCtrl->SetBitmap(Bitmap);
}
void LineGraphicsDialog::OnOk(wxCommandEvent & WXUNUSED(event))
{
//
// all done:
//
LineColor = CurrentColor;
LineThickness = CurrentThickness;
LineStyle = CurrentStyle;
DescName = DescCtrl->GetValue();
wxDialog::EndModal(wxID_OK);
}
bool PolygonGraphicsDialog::Create(MyFrame * parent, wxString & table,
wxString & geom, wxString & descName,
wxColour & borderColor, int thickness,
int style)
{
//
// creating the dialog - border, no interior filling
//
MainFrame = parent;
TableName = table;
GeometryColumn = geom;
DescName = descName;
BorderColor = borderColor;
CurrentBorderColor = borderColor;
BorderThickness = thickness;
CurrentBorderThickness = thickness;
BorderStyle = style;
CurrentBorderStyle = style;
DrawBorder = true;
ToFill = false;
SolidFilling = true;
CurrentDrawBorder = DrawBorder;
CurrentToFill = ToFill;
CurrentSolidFilling = SolidFilling;
FillColor = wxColour(0, 128, 64);
CurrentFillColor = FillColor;
PatternId = 1;
if (wxDialog::Create(parent, wxID_ANY, wxT("Layer Graphics - POLYGON")) ==
false)
return false;
// populates individual controls
Bitmap = wxBitmap(400, 64);
MainFrame->GetPatternBitmaps(&PatternsList);
CurrentPattern = PatternsList.FindById(PatternId);
CreateControls();
// sets dialog sizer
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
// centers the dialog window
Centre();
return true;
}
bool PolygonGraphicsDialog::Create(MyFrame * parent, wxString & table,
wxString & geom, wxString & descName,
wxColour & fillColor)
{
//
// creating the dialog - no border, solid color interior filling
//
MainFrame = parent;
TableName = table;
GeometryColumn = geom;
DescName = descName;
BorderColor = wxColour(0, 255, 128, 255);
CurrentBorderColor = BorderColor;
BorderThickness = 1;
CurrentBorderThickness = BorderThickness;
BorderStyle = wxSOLID;
CurrentBorderStyle = BorderStyle;
DrawBorder = false;
ToFill = true;
SolidFilling = true;
CurrentDrawBorder = DrawBorder;
CurrentToFill = ToFill;
CurrentSolidFilling = SolidFilling;
FillColor = fillColor;
CurrentFillColor = FillColor;
PatternId = 1;
if (wxDialog::Create(parent, wxID_ANY, wxT("Layer Graphics - POLYGON")) ==
false)
return false;
// populates individual controls
Bitmap = wxBitmap(400, 64);
MainFrame->GetPatternBitmaps(&PatternsList);
CurrentPattern = PatternsList.FindById(PatternId);
CreateControls();
// sets dialog sizer
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
// centers the dialog window
Centre();
return true;
}
bool PolygonGraphicsDialog::Create(MyFrame * parent, wxString & table,
wxString & geom, wxString & descName,
wxColour & borderColor, int thickness,
int style, wxColour & fillColor)
{
//
// creating the dialog - border and solid color interior filling
//
MainFrame = parent;
TableName = table;
GeometryColumn = geom;
DescName = descName;
BorderColor = borderColor;
CurrentBorderColor = borderColor;
BorderThickness = thickness;
CurrentBorderThickness = thickness;
BorderStyle = style;
CurrentBorderStyle = style;
DrawBorder = true;
ToFill = true;
SolidFilling = true;
CurrentDrawBorder = DrawBorder;
CurrentToFill = ToFill;
CurrentSolidFilling = SolidFilling;
FillColor = fillColor;
CurrentFillColor = FillColor;
PatternId = 1;
if (wxDialog::Create(parent, wxID_ANY, wxT("Layer Graphics - POLYGON")) ==
false)
return false;
// populates individual controls
Bitmap = wxBitmap(400, 64);
MainFrame->GetPatternBitmaps(&PatternsList);
CurrentPattern = PatternsList.FindById(PatternId);
CreateControls();
// sets dialog sizer
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
// centers the dialog window
Centre();
return true;
}
bool PolygonGraphicsDialog::Create(MyFrame * parent, wxString & table,
wxString & geom, wxString & descName,
int patternId, wxColour & fillColor)
{
//
// creating the dialog - no border, pattern interior filling
//
MainFrame = parent;
TableName = table;
GeometryColumn = geom;
DescName = descName;
BorderColor = wxColour(0, 255, 128, 255);
CurrentBorderColor = BorderColor;
BorderThickness = 1;
CurrentBorderThickness = BorderThickness;
BorderStyle = wxSOLID;
CurrentBorderStyle = BorderStyle;
DrawBorder = false;
ToFill = true;
SolidFilling = false;
CurrentDrawBorder = DrawBorder;
CurrentToFill = ToFill;
CurrentSolidFilling = SolidFilling;
FillColor = fillColor;
CurrentFillColor = FillColor;
PatternId = patternId;
if (wxDialog::Create(parent, wxID_ANY, wxT("Layer Graphics - POLYGON")) ==
false)
return false;
// populates individual controls
Bitmap = wxBitmap(400, 64);
MainFrame->GetPatternBitmaps(&PatternsList);
CurrentPattern = PatternsList.FindById(PatternId);
CreateControls();
// sets dialog sizer
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
// centers the dialog window
Centre();
return true;
}
bool PolygonGraphicsDialog::Create(MyFrame * parent, wxString & table,
wxString & geom, wxString & descName,
wxColour & borderColor, int thickness,
int style, int patternId,
wxColour & fillColor)
{
//
// creating the dialog - border and pattern interior filling
//
MainFrame = parent;
TableName = table;
GeometryColumn = geom;
DescName = descName;
BorderColor = borderColor;
CurrentBorderColor = borderColor;
BorderThickness = thickness;
CurrentBorderThickness = thickness;
BorderStyle = style;
CurrentBorderStyle = style;
DrawBorder = true;
ToFill = true;
SolidFilling = false;
CurrentDrawBorder = DrawBorder;
CurrentToFill = ToFill;
CurrentSolidFilling = SolidFilling;
FillColor = fillColor;
CurrentFillColor = FillColor;
PatternId = patternId;
if (wxDialog::Create(parent, wxID_ANY, wxT("Layer Graphics - POLYGON")) ==
false)
return false;
// populates individual controls
Bitmap = wxBitmap(128, 64);
MainFrame->GetPatternBitmaps(&PatternsList);
CurrentPattern = PatternsList.FindById(PatternId);
CreateControls();
// sets dialog sizer
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
// centers the dialog window
Centre();
return true;
}
void PolygonGraphicsDialog::CreateControls()
{
//
// creating individual controls and setting initial values
//
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(topSizer);
wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
// first row: the Layer Table+Geometry
wxBoxSizer *layerSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(layerSizer, 0, wxALIGN_RIGHT | wxALL, 0);
wxStaticText *layerLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Vector Layer:"));
layerSizer->Add(layerLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString name = TableName + wxT(".") + GeometryColumn;
wxTextCtrl *layerValue = new wxTextCtrl(this, wxID_STATIC,
name, wxDefaultPosition,
wxSize(350, 22), wxTE_READONLY);
layerSizer->Add(layerValue, 0, wxALIGN_RIGHT | wxALL, 5);
// second row: description
wxBoxSizer *descSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(descSizer, 0, wxALIGN_RIGHT | wxALL, 0);
wxStaticText *descLabel =
new wxStaticText(this, wxID_STATIC, wxT("&Description:"));
descSizer->Add(descLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
DescCtrl = new wxTextCtrl(this, wxID_STATIC, DescName,
wxDefaultPosition, wxSize(350, 22));
descSizer->Add(DescCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
// third row: Border Mode / Filling Mode
wxBoxSizer *modeSizer = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(modeSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
wxString border_modes[2];
border_modes[0] = wxT("&Visible");
border_modes[1] = wxT("&No border");
BorderModeCtrl = new wxRadioBox(this, ID_POLYGON_BORDER_MODE,
wxT("&Border Mode"), wxDefaultPosition,
wxDefaultSize, 2, border_modes, 1,
wxRA_SPECIFY_ROWS);
if (DrawBorder == true)
BorderModeCtrl->SetSelection(0);
else
BorderModeCtrl->SetSelection(1);
modeSizer->Add(BorderModeCtrl, 0, wxALIGN_LEFT | wxALL, 5);
wxString fill_modes[3];
fill_modes[0] = wxT("&Omit");
fill_modes[1] = wxT("&Solid Color");
fill_modes[2] = wxT("&Pattern");
FillingModeCtrl = new wxRadioBox(this, ID_POLYGON_FILL_MODE,
wxT("&Interior Filling Mode"),
wxDefaultPosition, wxDefaultSize, 3,
fill_modes, 1, wxRA_SPECIFY_ROWS);
if (ToFill == false)
FillingModeCtrl->SetSelection(0);