2 * @file SetScaleDialog.cpp
3 * Implements the SetScaleDialog class.
8 * Copyright 2012 Joel Baxter
10 * This file is part of MeshTex.
12 * MeshTex is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * (at your option) any later version.
17 * MeshTex is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
28 #include "GenericPluginUI.h"
29 #include "SetScaleDialog.h"
30 #include "PluginUIMessages.h"
36 * Size of buffer for the text conversion of float values written to various
39 #define ENTRY_BUFFER_SIZE 128
45 * @param rowArgs The row (S axis) arguments; NULL if none.
46 * @param colArgs The column (T axis) arguments; NULL if none.
48 SetScaleDialog::SetScaleVisitor::SetScaleVisitor(
49 const SliceArgs *rowArgs,
50 const SliceArgs *colArgs) :
57 * Visitor action; invoke MeshEntity::SetScale on a mesh.
59 * @param [in,out] meshEntity The mesh entity.
64 SetScaleDialog::SetScaleVisitor::Execute(MeshEntity& meshEntity) const
68 meshEntity.SetScale(MeshEntity::ROW_SLICE_TYPE,
69 _rowArgs->alignSlice, _rowArgs->refSlice,
70 _rowArgs->naturalScale, _rowArgs->scaleOrTiles);
74 meshEntity.SetScale(MeshEntity::COL_SLICE_TYPE,
75 _colArgs->alignSlice, _colArgs->refSlice,
76 _colArgs->naturalScale, _colArgs->scaleOrTiles);
82 * Constructor. Configure the dialog window and create all the contained
83 * widgets. Connect widgets to callbacks as necessary.
85 * @param key The unique key identifying this dialog.
87 SetScaleDialog::SetScaleDialog(const std::string& key) :
89 _nullVisitor(new MeshVisitor())
91 // Enable the usual handling of the close event.
92 CreateWindowCloseCallback();
94 // Configure the dialog window.
95 gtk_window_set_resizable(GTK_WINDOW(_dialog), FALSE);
96 gtk_window_set_title(GTK_WINDOW(_dialog), DIALOG_SET_SCALE_TITLE);
97 gtk_container_set_border_width(GTK_CONTAINER(_dialog), 10);
99 // Create the contained widgets.
103 GtkWidget *applybutton, *refbutton, *button;
105 GtkWidget *mainvbox, *vbox, *hbox;
108 table = gtk_table_new(2, 2, FALSE);
109 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 15);
110 gtk_table_set_col_spacing(GTK_TABLE(table), 0, 10);
111 gtk_container_add(GTK_CONTAINER(_dialog), table);
112 gtk_widget_show(table);
114 // Checkbox for the "S" grouping of widgets. All the widgets in that
115 // grouping will have a dependence registered on this checkbox; i.e. they
116 // will only be active when it is checked.
118 applybutton = gtk_check_button_new_with_label(DIALOG_SET_SCALE_S_ACTIVE_OPT_LABEL);
119 gtk_object_set_data(GTK_OBJECT(_dialog), "s_apply", applybutton);
120 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(applybutton), TRUE);
121 gtk_widget_show(applybutton);
123 frame = gtk_frame_new(NULL);
124 gtk_frame_set_label_widget(GTK_FRAME(frame), applybutton);
125 gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 0, 1);
126 gtk_widget_show(frame);
128 mainvbox = gtk_vbox_new(FALSE, 0);
129 gtk_container_add(GTK_CONTAINER(frame), mainvbox);
130 gtk_widget_show(mainvbox);
132 hbox = gtk_hbox_new(FALSE, 0);
133 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
134 gtk_widget_show(hbox);
136 // Widgets for specifying S scaling.
138 label = gtk_label_new(DIALOG_SET_SCALE_METHOD_FRAME_TITLE);
139 gtk_widget_show(label);
141 UIInstance().RegisterWidgetDependence(applybutton, label);
143 frame = gtk_frame_new(NULL);
144 gtk_frame_set_label_widget(GTK_FRAME(frame), label);
145 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
146 gtk_widget_show(frame);
148 vbox = gtk_vbox_new(FALSE, 0);
149 gtk_container_add(GTK_CONTAINER(frame), vbox);
150 gtk_widget_show(vbox);
152 hbox = gtk_hbox_new(FALSE, 0);
153 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
154 gtk_widget_show(hbox);
156 button = gtk_radio_button_new_with_label(NULL, DIALOG_SET_SCALE_TILES_OPT_LABEL);
157 gtk_object_set_data(GTK_OBJECT(_dialog), "s_tiling", button);
158 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
159 gtk_widget_show(button);
161 UIInstance().RegisterWidgetDependence(applybutton, button);
163 entry = gtk_entry_new();
164 gtk_object_set_data(GTK_OBJECT(_dialog), "s_tiles", entry);
165 gtk_entry_set_text(GTK_ENTRY(entry), "1");
166 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
167 gtk_widget_set_usize(entry, 50, -2);
168 gtk_widget_set_sensitive(entry, FALSE);
169 gtk_widget_show(entry);
171 UIInstance().RegisterWidgetDependence(applybutton, entry);
172 UIInstance().RegisterWidgetDependence(button, entry);
174 hbox = gtk_hbox_new(FALSE, 0);
175 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
176 gtk_widget_show(hbox);
178 button = gtk_radio_button_new_with_label(
179 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
180 DIALOG_SET_SCALE_NATURAL_OPT_LABEL);
181 gtk_object_set_data(GTK_OBJECT(_dialog), "s_natural", button);
182 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
183 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
184 gtk_widget_show(button);
186 UIInstance().RegisterWidgetDependence(applybutton, button);
188 entry = gtk_entry_new();
189 gtk_object_set_data(GTK_OBJECT(_dialog), "s_scale", entry);
190 gtk_entry_set_text(GTK_ENTRY(entry), "1");
191 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
192 gtk_widget_set_usize(entry, 50, -2);
193 gtk_widget_set_sensitive(entry, TRUE);
194 gtk_widget_show(entry);
196 UIInstance().RegisterWidgetDependence(applybutton, entry);
197 UIInstance().RegisterWidgetDependence(button, entry);
199 hbox = gtk_hbox_new(FALSE, 0);
200 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
201 gtk_widget_show(hbox);
203 // Widgets for specifying the alignment column.
205 label = gtk_label_new(DIALOG_SET_SCALE_S_ALIGN_FRAME_TITLE);
206 gtk_widget_show(label);
208 UIInstance().RegisterWidgetDependence(applybutton, label);
210 frame = gtk_frame_new(NULL);
211 gtk_frame_set_label_widget(GTK_FRAME(frame), label);
212 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
213 gtk_widget_show(frame);
215 vbox = gtk_vbox_new(FALSE, 0);
216 gtk_container_add(GTK_CONTAINER(frame), vbox);
217 gtk_widget_show(vbox);
219 hbox = gtk_hbox_new(FALSE, 0);
220 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
221 gtk_widget_show(hbox);
223 button = gtk_radio_button_new(NULL);
224 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
225 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
226 gtk_widget_show(button);
228 UIInstance().RegisterWidgetDependence(applybutton, button);
230 entry = gtk_entry_new();
231 gtk_object_set_data(GTK_OBJECT(_dialog), "col_num_align", entry);
232 gtk_entry_set_text(GTK_ENTRY(entry), "0");
233 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
234 gtk_widget_set_usize(entry, 25, -2);
235 gtk_widget_show(entry);
237 UIInstance().RegisterWidgetDependence(applybutton, entry);
238 UIInstance().RegisterWidgetDependence(button, entry);
240 button = gtk_radio_button_new_with_label(
241 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
242 DIALOG_SET_SCALE_MAX_OPT_LABEL);
243 gtk_object_set_data(GTK_OBJECT(_dialog), "col_max_align", button);
244 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
245 gtk_widget_show(button);
247 UIInstance().RegisterWidgetDependence(applybutton, button);
249 hbox = gtk_hbox_new(FALSE, 0);
250 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
251 gtk_widget_show(hbox);
253 // Widgets for specifying the reference row & usage.
255 refbutton = gtk_check_button_new_with_label(DIALOG_SET_SCALE_S_REF_ROW_OPT_LABEL);
256 gtk_object_set_data(GTK_OBJECT(_dialog), "row_ref", refbutton);
257 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(refbutton), TRUE);
258 gtk_widget_show(refbutton);
260 UIInstance().RegisterWidgetDependence(applybutton, refbutton);
262 frame = gtk_frame_new(NULL);
263 gtk_frame_set_label_widget(GTK_FRAME(frame), refbutton);
264 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
265 gtk_widget_show(frame);
267 vbox = gtk_vbox_new(FALSE, 0);
268 gtk_container_add(GTK_CONTAINER(frame), vbox);
269 gtk_widget_show(vbox);
271 hbox = gtk_hbox_new(FALSE, 0);
272 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
273 gtk_widget_show(hbox);
275 button = gtk_radio_button_new(NULL);
276 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
277 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
278 gtk_widget_show(button);
280 UIInstance().RegisterWidgetDependence(applybutton, button);
281 UIInstance().RegisterWidgetDependence(refbutton, button);
283 entry = gtk_entry_new();
284 gtk_object_set_data(GTK_OBJECT(_dialog), "row_num_ref", entry);
285 gtk_entry_set_text(GTK_ENTRY(entry), "0");
286 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
287 gtk_widget_set_usize(entry, 25, -2);
288 gtk_widget_show(entry);
290 UIInstance().RegisterWidgetDependence(applybutton, entry);
291 UIInstance().RegisterWidgetDependence(refbutton, entry);
292 UIInstance().RegisterWidgetDependence(button, entry);
294 button = gtk_radio_button_new_with_label(
295 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
296 DIALOG_SET_SCALE_MAX_OPT_LABEL);
297 gtk_object_set_data(GTK_OBJECT(_dialog), "row_max_ref", button);
298 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
299 gtk_widget_show(button);
301 UIInstance().RegisterWidgetDependence(applybutton, button);
302 UIInstance().RegisterWidgetDependence(refbutton, button);
304 hbox = gtk_hbox_new(FALSE, 0);
305 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
306 gtk_widget_show(hbox);
308 button = gtk_check_button_new_with_label(DIALOG_SET_SCALE_REF_TOTAL_OPT_LABEL);
309 gtk_object_set_data(GTK_OBJECT(_dialog), "row_ref_total", button);
310 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
311 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
312 gtk_widget_show(button);
314 UIInstance().RegisterWidgetDependence(applybutton, button);
315 UIInstance().RegisterWidgetDependence(refbutton, button);
317 // Checkbox for the "T" grouping of widgets. All the widgets in that
318 // grouping will have a dependence registered on this checkbox; i.e. they
319 // will only be active when it is checked.
321 applybutton = gtk_check_button_new_with_label(DIALOG_SET_SCALE_T_ACTIVE_OPT_LABEL);
322 gtk_object_set_data(GTK_OBJECT(_dialog), "t_apply", applybutton);
323 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(applybutton), TRUE);
324 gtk_widget_show(applybutton);
326 frame = gtk_frame_new(NULL);
327 gtk_frame_set_label_widget(GTK_FRAME(frame), applybutton);
328 gtk_table_attach_defaults(GTK_TABLE(table), frame, 1, 2, 0, 1);
329 gtk_widget_show(frame);
331 mainvbox = gtk_vbox_new(FALSE, 0);
332 gtk_container_add(GTK_CONTAINER(frame), mainvbox);
333 gtk_widget_show(mainvbox);
335 hbox = gtk_hbox_new(FALSE, 0);
336 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
337 gtk_widget_show(hbox);
339 // Widgets for specifying T scaling.
341 label = gtk_label_new(DIALOG_SET_SCALE_METHOD_FRAME_TITLE);
342 gtk_widget_show(label);
344 UIInstance().RegisterWidgetDependence(applybutton, label);
346 frame = gtk_frame_new(NULL);
347 gtk_frame_set_label_widget(GTK_FRAME(frame), label);
348 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
349 gtk_widget_show(frame);
351 vbox = gtk_vbox_new(FALSE, 0);
352 gtk_container_add(GTK_CONTAINER(frame), vbox);
353 gtk_widget_show(vbox);
355 hbox = gtk_hbox_new(FALSE, 0);
356 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
357 gtk_widget_show(hbox);
359 button = gtk_radio_button_new_with_label(NULL, DIALOG_SET_SCALE_TILES_OPT_LABEL);
360 gtk_object_set_data(GTK_OBJECT(_dialog), "t_tiling", button);
361 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
362 gtk_widget_show(button);
364 UIInstance().RegisterWidgetDependence(applybutton, button);
366 entry = gtk_entry_new();
367 gtk_object_set_data(GTK_OBJECT(_dialog), "t_tiles", entry);
368 gtk_entry_set_text(GTK_ENTRY(entry), "1");
369 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
370 gtk_widget_set_usize(entry, 50, -2);
371 gtk_widget_set_sensitive(entry, FALSE);
372 gtk_widget_show(entry);
374 UIInstance().RegisterWidgetDependence(applybutton, entry);
375 UIInstance().RegisterWidgetDependence(button, entry);
377 hbox = gtk_hbox_new(FALSE, 0);
378 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
379 gtk_widget_show(hbox);
381 button = gtk_radio_button_new_with_label(
382 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
383 DIALOG_SET_SCALE_NATURAL_OPT_LABEL);
384 gtk_object_set_data(GTK_OBJECT(_dialog), "t_natural", button);
385 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
386 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
387 gtk_widget_show(button);
389 UIInstance().RegisterWidgetDependence(applybutton, button);
391 entry = gtk_entry_new();
392 gtk_object_set_data(GTK_OBJECT(_dialog), "t_scale", entry);
393 gtk_entry_set_text(GTK_ENTRY(entry), "1");
394 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
395 gtk_widget_set_usize(entry, 50, -2);
396 gtk_widget_set_sensitive(entry, TRUE);
397 gtk_widget_show(entry);
399 UIInstance().RegisterWidgetDependence(applybutton, entry);
400 UIInstance().RegisterWidgetDependence(button, entry);
402 hbox = gtk_hbox_new(FALSE, 0);
403 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
404 gtk_widget_show(hbox);
406 // Widgets for specifying the alignment row.
408 label = gtk_label_new(DIALOG_SET_SCALE_T_ALIGN_FRAME_TITLE);
409 gtk_widget_show(label);
411 UIInstance().RegisterWidgetDependence(applybutton, label);
413 frame = gtk_frame_new(NULL);
414 gtk_frame_set_label_widget(GTK_FRAME(frame), label);
415 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
416 gtk_widget_show(frame);
418 vbox = gtk_vbox_new(FALSE, 0);
419 gtk_container_add(GTK_CONTAINER(frame), vbox);
420 gtk_widget_show(vbox);
422 hbox = gtk_hbox_new(FALSE, 0);
423 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
424 gtk_widget_show(hbox);
426 button = gtk_radio_button_new(NULL);
427 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
428 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
429 gtk_widget_show(button);
431 UIInstance().RegisterWidgetDependence(applybutton, button);
433 entry = gtk_entry_new();
434 gtk_object_set_data(GTK_OBJECT(_dialog), "row_num_align", entry);
435 gtk_entry_set_text(GTK_ENTRY(entry), "0");
436 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
437 gtk_widget_set_usize(entry, 25, -2);
438 gtk_widget_show(entry);
440 UIInstance().RegisterWidgetDependence(applybutton, entry);
441 UIInstance().RegisterWidgetDependence(button, entry);
443 button = gtk_radio_button_new_with_label(
444 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
445 DIALOG_SET_SCALE_MAX_OPT_LABEL);
446 gtk_object_set_data(GTK_OBJECT(_dialog), "row_max_align", button);
447 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
448 gtk_widget_show(button);
450 UIInstance().RegisterWidgetDependence(applybutton, button);
452 hbox = gtk_hbox_new(FALSE, 0);
453 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
454 gtk_widget_show(hbox);
456 // Widgets for specifying the reference column & usage.
458 refbutton = gtk_check_button_new_with_label(DIALOG_SET_SCALE_T_REF_COL_OPT_LABEL);
459 gtk_object_set_data(GTK_OBJECT(_dialog), "col_ref", refbutton);
460 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(refbutton), TRUE);
461 gtk_widget_show(refbutton);
463 UIInstance().RegisterWidgetDependence(applybutton, refbutton);
465 frame = gtk_frame_new(NULL);
466 gtk_frame_set_label_widget(GTK_FRAME(frame), refbutton);
467 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
468 gtk_widget_show(frame);
470 vbox = gtk_vbox_new(FALSE, 0);
471 gtk_container_add(GTK_CONTAINER(frame), vbox);
472 gtk_widget_show(vbox);
474 hbox = gtk_hbox_new(FALSE, 0);
475 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
476 gtk_widget_show(hbox);
478 button = gtk_radio_button_new(NULL);
479 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
480 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
481 gtk_widget_show(button);
483 UIInstance().RegisterWidgetDependence(applybutton, button);
484 UIInstance().RegisterWidgetDependence(refbutton, button);
486 entry = gtk_entry_new();
487 gtk_object_set_data(GTK_OBJECT(_dialog), "col_num_ref", entry);
488 gtk_entry_set_text(GTK_ENTRY(entry), "0");
489 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
490 gtk_widget_set_usize(entry, 25, -2);
491 gtk_widget_show(entry);
493 UIInstance().RegisterWidgetDependence(applybutton, entry);
494 UIInstance().RegisterWidgetDependence(refbutton, entry);
495 UIInstance().RegisterWidgetDependence(button, entry);
497 button = gtk_radio_button_new_with_label(
498 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
499 DIALOG_SET_SCALE_MAX_OPT_LABEL);
500 gtk_object_set_data(GTK_OBJECT(_dialog), "col_max_ref", button);
501 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
502 gtk_widget_show(button);
504 UIInstance().RegisterWidgetDependence(applybutton, button);
505 UIInstance().RegisterWidgetDependence(refbutton, button);
507 hbox = gtk_hbox_new(FALSE, 0);
508 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
509 gtk_widget_show(hbox);
511 button = gtk_check_button_new_with_label(DIALOG_SET_SCALE_REF_TOTAL_OPT_LABEL);
512 gtk_object_set_data(GTK_OBJECT(_dialog), "col_ref_total", button);
513 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
514 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
515 gtk_widget_show(button);
517 UIInstance().RegisterWidgetDependence(applybutton, button);
518 UIInstance().RegisterWidgetDependence(refbutton, button);
520 hbox = gtk_hbox_new(FALSE, 0);
521 gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 2, 1, 2);
522 gtk_widget_show(hbox);
524 // Create Cancel button and hook it to callback.
526 button = gtk_button_new_with_label(DIALOG_CANCEL_BUTTON);
527 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
528 gtk_widget_set_usize(button, 60, -2);
529 gtk_widget_show(button);
531 CreateCancelButtonCallback(button);
533 // Create Apply button and hook it to callback.
535 button = gtk_button_new_with_label(DIALOG_APPLY_BUTTON);
536 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 10);
537 gtk_widget_set_usize (button, 60, -2);
538 gtk_widget_show(button);
540 CreateApplyButtonCallback(button);
542 // Create OK button and hook it to callback.
544 button = gtk_button_new_with_label(DIALOG_OK_BUTTON);
545 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
546 gtk_widget_set_usize (button, 60, -2);
547 gtk_widget_show(button);
549 CreateOkButtonCallback(button);
555 SetScaleDialog::~SetScaleDialog()
560 * Handler for the Apply logic for this dialog. Apply the specified scaling to
561 * the selected mesh entities.
563 * @return true if any meshes are selected, false otherwise.
566 SetScaleDialog::Apply()
568 // Before doing anything, check to see if there are some meshes selected.
569 _nullVisitor->ResetVisitedCount();
570 GlobalSelectionSystem().foreachSelected(*_nullVisitor);
571 if (_nullVisitor->GetVisitedCount() == 0)
573 // Nope. Warn and bail out.
574 GenericPluginUI::WarningReportDialog(DIALOG_WARNING_TITLE,
575 DIALOG_NOMESHES_MSG);
579 // See if we're going to be affecting the S and/or T texture axis.
580 bool sApply = NamedToggleWidgetActive("s_apply");
581 bool tApply = NamedToggleWidgetActive("t_apply");
583 if (!sApply && !tApply)
585 // Not affecting either, so bail out.
589 // OK read the remaining info from the widgets.
591 MeshEntity::SliceDesignation alignCol, alignRow;
592 MeshEntity::RefSliceDescriptor refRow, refCol;
593 SetScaleVisitor::SliceArgs row, col;
594 SetScaleVisitor::SliceArgs *rowArgs = NULL;
595 SetScaleVisitor::SliceArgs *colArgs = NULL;
598 // S axis is affected, so read the S info.
599 row.naturalScale = NamedToggleWidgetActive("s_natural");
600 if (row.naturalScale)
602 row.scaleOrTiles = (float)atof(NamedEntryWidgetText("s_scale"));
606 row.scaleOrTiles = (float)atof(NamedEntryWidgetText("s_tiles"));
608 alignCol.maxSlice = NamedToggleWidgetActive("col_max_align");
609 alignCol.index = atoi(NamedEntryWidgetText("col_num_align"));
610 row.alignSlice = &alignCol;
612 if (NamedToggleWidgetActive("row_ref"))
614 // Reference row is specified, so get that info.
615 refRow.designation.maxSlice = NamedToggleWidgetActive("row_max_ref");
616 refRow.designation.index = atoi(NamedEntryWidgetText("row_num_ref"));
617 refRow.totalLengthOnly = NamedToggleWidgetActive("row_ref_total");
618 row.refSlice = &refRow;
624 // T axis is affected, so read the T info.
625 col.naturalScale = NamedToggleWidgetActive("t_natural");
626 if (col.naturalScale)
628 col.scaleOrTiles = (float)atof(NamedEntryWidgetText("t_scale"));
632 col.scaleOrTiles = (float)atof(NamedEntryWidgetText("t_tiles"));
634 alignRow.maxSlice = NamedToggleWidgetActive("row_max_align");
635 alignRow.index = atoi(NamedEntryWidgetText("row_num_align"));
636 col.alignSlice = &alignRow;
638 if (NamedToggleWidgetActive("col_ref"))
640 // Reference column is specified, so get that info.
641 refCol.designation.maxSlice = NamedToggleWidgetActive("col_max_ref");
642 refCol.designation.index = atoi(NamedEntryWidgetText("col_num_ref"));
643 refCol.totalLengthOnly = NamedToggleWidgetActive("col_ref_total");
644 col.refSlice = &refCol;
649 // Let Radiant know the name of the operation responsible for the changes
650 // that are about to happen.
651 UndoableCommand undo(_triggerCommand.c_str());
653 // Apply the specified scaling to every selected mesh.
654 SmartPointer<SetScaleVisitor> scaleVisitor(new SetScaleVisitor(rowArgs, colArgs));
655 GlobalSelectionSystem().foreachSelected(*scaleVisitor);
662 * Allow an external caller to set some of the S-axis entries.
664 * @param scale Texture scaling.
665 * @param tiles Texture tiles.
668 SetScaleDialog::PopulateSWidgets(float scale,
671 // Use the texture info to populate some of our widgets.
672 PopulateEntry("s_scale", scale);
673 PopulateEntry("s_tiles", tiles);
677 * Allow an external caller to set some of the T-axis entries.
679 * @param scale Texture scaling.
680 * @param tiles Texture tiles.
683 SetScaleDialog::PopulateTWidgets(float scale,
686 // Use the texture info to populate some of our widgets.
687 PopulateEntry("t_scale", scale);
688 PopulateEntry("t_tiles", tiles);
692 * Populate a text widget with a floating point number.
694 * @param widgetName Name of the widget.
695 * @param value The number to write to the widget.
698 SetScaleDialog::PopulateEntry(const char *widgetName,
701 static char entryBuffer[ENTRY_BUFFER_SIZE + 1] = { 0 };
702 snprintf(entryBuffer, ENTRY_BUFFER_SIZE, "%f", value);
703 gtk_entry_set_text(GTK_ENTRY(NamedWidget(widgetName)), entryBuffer);