@@ -57,7 +57,7 @@ class ShowHideButton : public Button {
57
57
/* outlineColor=*/ {});
58
58
}
59
59
if (!*(variable)) {
60
- int s = 0 , f = 24 ;
60
+ int s = 0 , f = 23 ;
61
61
RgbaColor color = { 255 , 0 , 0 , 150 };
62
62
uiCanvas->DrawLine (x+s, y-s, x+f, y-f, color, 2 );
63
63
uiCanvas->DrawLine (x+s, y-f, x+f, y-s, color, 2 );
@@ -82,42 +82,47 @@ class FacesButton : public ShowHideButton {
82
82
}
83
83
}
84
84
};
85
+
85
86
#include < array>
86
87
class TriStateButton : public Button {
87
88
public:
88
- TriStateButton (GraphicsWindow::ShowConstraintMode*variable,
89
- const std::array<GraphicsWindow::ShowConstraintMode,3 > &states,
90
- const std::array<std::string,3 > &tooltips,
91
- const std::array<std::string,3 > &iconNames ):variable(variable),states(states),tooltips(tooltips),iconNames(iconNames){}
89
+ static const size_t tri = 3 ;
90
+
91
+ TriStateButton (unsigned *variable, const std::array<unsigned , tri> &states,
92
+ const std::array<std::string, tri> &tooltips,
93
+ const std::array<std::string, tri> &iconNames)
94
+ : variable(variable), states(states), tooltips(tooltips), iconNames(iconNames) {
95
+ }
92
96
93
- GraphicsWindow::ShowConstraintMode* variable;
94
- std::array<GraphicsWindow::ShowConstraintMode, 3 > states;
95
- std::array<std::string,3 > tooltips;
96
- std::array<std::string,3 > iconNames;
97
- std::shared_ptr<Pixmap> icons[3 ];
97
+ unsigned * const variable;
98
+ const std::array<unsigned , tri > states;
99
+ const std::array<std::string, tri > tooltips;
100
+ const std::array<std::string, tri > iconNames;
101
+ std::shared_ptr<Pixmap> icons[tri ];
98
102
99
103
std::string Tooltip () override {
100
- for (size_t k = 0 ; k < 3 ; ++k )
101
- if ( *variable == states[k] ) return tooltips[k];
104
+ for (size_t k = 0 ; k < tri; ++k)
105
+ if (*variable == states[k])
106
+ return tooltips[k];
102
107
ssassert (false , " Unexpected mode" );
103
108
}
104
109
105
110
void Draw (UiCanvas *uiCanvas, int x, int y, bool asHovered) override {
106
- for (size_t k = 0 ; k < 3 ; ++k)
111
+ for (size_t k = 0 ; k < tri; ++k)
107
112
if (icons[k] == nullptr )
108
113
icons[k] = LoadPng (" icons/text-window/" + iconNames[k] + " .png" );
109
114
110
115
std::shared_ptr<Pixmap> icon;
111
- for (size_t k = 0 ; k < 3 ; ++k )
112
- if ( *variable == states[k] ) {
116
+ for (size_t k = 0 ; k < tri ; ++k)
117
+ if ( *variable == states[k]) {
113
118
icon = icons[k];
114
119
break ;
115
120
}
116
121
117
122
uiCanvas->DrawPixmap (icon, x, y - 24 );
118
123
if (asHovered) {
119
124
uiCanvas->DrawRect (x - 2 , x + 26 , y + 2 , y - 26 ,
120
- /* fillColor=*/ { 255 , 255 , 0 , 75 },
125
+ /* fillColor=*/ {255 , 255 , 0 , 75 },
121
126
/* outlineColor=*/ {});
122
127
}
123
128
}
@@ -126,9 +131,9 @@ class TriStateButton : public Button {
126
131
int AdvanceWidth () override { return 32 ; }
127
132
128
133
void Click () override {
129
- for (size_t k = 0 ;k < 3 ; ++k)
130
- if ( *variable == states[k] ) {
131
- *variable = states[(k+ 1 )% 3 ];
134
+ for (size_t k = 0 ; k < tri; ++k)
135
+ if ( *variable == states[k]) {
136
+ *variable = states[(k + 1 ) % tri ];
132
137
break ;
133
138
}
134
139
@@ -138,77 +143,6 @@ class TriStateButton : public Button {
138
143
}
139
144
};
140
145
141
-
142
- class OccludedLinesButton : public Button {
143
- public:
144
- std::shared_ptr<Pixmap> visibleIcon;
145
- std::shared_ptr<Pixmap> stippledIcon;
146
- std::shared_ptr<Pixmap> invisibleIcon;
147
-
148
- std::string Tooltip () override {
149
- switch (SS.GW .drawOccludedAs ) {
150
- case GraphicsWindow::DrawOccludedAs::INVISIBLE:
151
- return " Stipple occluded lines" ;
152
-
153
- case GraphicsWindow::DrawOccludedAs::STIPPLED:
154
- return " Draw occluded lines" ;
155
-
156
- case GraphicsWindow::DrawOccludedAs::VISIBLE:
157
- return " Don't draw occluded lines" ;
158
-
159
- default : ssassert (false , " Unexpected mode" );
160
- }
161
- }
162
-
163
- void Draw (UiCanvas *uiCanvas, int x, int y, bool asHovered) override {
164
- if (visibleIcon == NULL ) {
165
- visibleIcon = LoadPng (" icons/text-window/occluded-visible.png" );
166
- }
167
- if (stippledIcon == NULL ) {
168
- stippledIcon = LoadPng (" icons/text-window/occluded-stippled.png" );
169
- }
170
- if (invisibleIcon == NULL ) {
171
- invisibleIcon = LoadPng (" icons/text-window/occluded-invisible.png" );
172
- }
173
-
174
- std::shared_ptr<Pixmap> icon;
175
- switch (SS.GW .drawOccludedAs ) {
176
- case GraphicsWindow::DrawOccludedAs::INVISIBLE: icon = invisibleIcon; break ;
177
- case GraphicsWindow::DrawOccludedAs::STIPPLED: icon = stippledIcon; break ;
178
- case GraphicsWindow::DrawOccludedAs::VISIBLE: icon = visibleIcon; break ;
179
- }
180
-
181
- uiCanvas->DrawPixmap (icon, x, y - 24 );
182
- if (asHovered) {
183
- uiCanvas->DrawRect (x - 2 , x + 26 , y + 2 , y - 26 ,
184
- /* fillColor=*/ { 255 , 255 , 0 , 75 },
185
- /* outlineColor=*/ {});
186
- }
187
- }
188
-
189
- int AdvanceWidth () override { return 32 ; }
190
-
191
- void Click () override {
192
- switch (SS.GW .drawOccludedAs ) {
193
- case GraphicsWindow::DrawOccludedAs::INVISIBLE:
194
- SS.GW .drawOccludedAs = GraphicsWindow::DrawOccludedAs::STIPPLED;
195
- break ;
196
-
197
- case GraphicsWindow::DrawOccludedAs::STIPPLED:
198
- SS.GW .drawOccludedAs = GraphicsWindow::DrawOccludedAs::VISIBLE;
199
- break ;
200
-
201
- case GraphicsWindow::DrawOccludedAs::VISIBLE:
202
- SS.GW .drawOccludedAs = GraphicsWindow::DrawOccludedAs::INVISIBLE;
203
- break ;
204
- }
205
-
206
- SS.GenerateAll ();
207
- SS.GW .Invalidate ();
208
- SS.ScheduleShowTW ();
209
- }
210
- };
211
-
212
146
static SpacerButton spacerButton;
213
147
214
148
static ShowHideButton workplanesButton =
@@ -219,15 +153,13 @@ static ShowHideButton pointsButton =
219
153
{ &(SS.GW .showPoints ), " point" , " points" };
220
154
static ShowHideButton constructionButton =
221
155
{ &(SS.GW .showConstruction ), " construction" , " construction entities" };
222
- static TriStateButton constraintsButton =
223
- { &(SS.GW .showConstraints ),
224
- {GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL,
225
- GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM,
226
- GraphicsWindow::ShowConstraintMode::SCM_NOSHOW},
227
- {" constraints and dimensions" ," dimensions" ," none" },
228
- {" constraint" ," constraint-dimo" ," constraint-wo" }
229
- };
230
-
156
+ static TriStateButton constraintsButton = {
157
+ (unsigned *)(&(SS.GW .showConstraints )),
158
+ {(unsigned )GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL,
159
+ (unsigned )GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM,
160
+ (unsigned )GraphicsWindow::ShowConstraintMode::SCM_NOSHOW},
161
+ {" Show only dimensions" , " Hide constraints and dimensions" , " Show constraints and dimensions" },
162
+ {" constraint" , " constraint-dimo" , " constraint-wo" }};
231
163
static FacesButton facesButton;
232
164
static ShowHideButton shadedButton =
233
165
{ &(SS.GW .showShaded ), " shaded" , " shaded view of solid model" };
@@ -237,7 +169,13 @@ static ShowHideButton outlinesButton =
237
169
{ &(SS.GW .showOutlines ), " outlines" , " outline of solid model" };
238
170
static ShowHideButton meshButton =
239
171
{ &(SS.GW .showMesh ), " mesh" , " triangle mesh of solid model" };
240
- static OccludedLinesButton occludedLinesButton;
172
+ static TriStateButton occludedLinesButton = {
173
+ (unsigned *)(&(SS.GW .drawOccludedAs )),
174
+ {(unsigned )GraphicsWindow::DrawOccludedAs::INVISIBLE,
175
+ (unsigned )GraphicsWindow::DrawOccludedAs::STIPPLED,
176
+ (unsigned )GraphicsWindow::DrawOccludedAs::VISIBLE},
177
+ {" Stipple occluded lines" , " Draw occluded lines" , " Don't draw occluded lines" },
178
+ {" occluded-invisible" , " occluded-stippled" , " occluded-visible" }};
241
179
242
180
static Button *buttons[] = {
243
181
&workplanesButton,
0 commit comments