refactor DoNewPatchDlg

This commit is contained in:
Rudolf Polzer 2011-10-07 12:35:50 +02:00
parent bf8fb3fc0b
commit 9032995bd3

View File

@ -517,13 +517,13 @@ void Patch_Cone()
Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eCone, GlobalXYWnd_getCurrentViewType()); Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eCone, GlobalXYWnd_getCurrentViewType());
} }
void DoNewPatchDlg(); void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int maxrows, int maxcols);
void Patch_Plane() void Patch_Plane()
{ {
UndoableCommand undo("patchCreatePlane"); UndoableCommand undo("patchCreatePlane");
DoNewPatchDlg(); DoNewPatchDlg(ePlane, 3, 3, 0, 0);
} }
void Patch_InsertInsertColumn() void Patch_InsertInsertColumn()
@ -894,7 +894,7 @@ void Patch_constructMenu(GtkMenu* menu)
#include "gtkutil/dialog.h" #include "gtkutil/dialog.h"
#include "gtkutil/widget.h" #include "gtkutil/widget.h"
void DoNewPatchDlg() void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int maxrows, int maxcols)
{ {
ModalDialog dialog; ModalDialog dialog;
GtkComboBox* width; GtkComboBox* width;
@ -930,21 +930,22 @@ void DoNewPatchDlg()
{ {
GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text()); GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
gtk_combo_box_append_text(combo, "3"); #define D_ITEM(x) if(x >= mincols && (!maxcols || x <= maxcols)) gtk_combo_box_append_text(combo, #x)
gtk_combo_box_append_text(combo, "5"); D_ITEM(3);
gtk_combo_box_append_text(combo, "7"); D_ITEM(5);
gtk_combo_box_append_text(combo, "9"); D_ITEM(7);
gtk_combo_box_append_text(combo, "11"); D_ITEM(9);
gtk_combo_box_append_text(combo, "13"); D_ITEM(11);
gtk_combo_box_append_text(combo, "15"); D_ITEM(13);
gtk_combo_box_append_text(combo, "17"); D_ITEM(15);
gtk_combo_box_append_text(combo, "19"); D_ITEM(17);
gtk_combo_box_append_text(combo, "21"); D_ITEM(19);
gtk_combo_box_append_text(combo, "23"); D_ITEM(21);
gtk_combo_box_append_text(combo, "25"); D_ITEM(23);
gtk_combo_box_append_text(combo, "27"); D_ITEM(25);
gtk_combo_box_append_text(combo, "29"); D_ITEM(27);
gtk_combo_box_append_text(combo, "31"); // MAX_PATCH_SIZE is 32, so we should be able to do 31... D_ITEM(29);
D_ITEM(31); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
gtk_widget_show(GTK_WIDGET(combo)); gtk_widget_show(GTK_WIDGET(combo));
gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 0, 1, gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 0, 1,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
@ -954,21 +955,22 @@ void DoNewPatchDlg()
} }
{ {
GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text()); GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
gtk_combo_box_append_text(combo, "3"); #define D_ITEM(x) if(x >= minrows && (!maxrows || x <= maxrows)) gtk_combo_box_append_text(combo, #x)
gtk_combo_box_append_text(combo, "5"); D_ITEM(3);
gtk_combo_box_append_text(combo, "7"); D_ITEM(5);
gtk_combo_box_append_text(combo, "9"); D_ITEM(7);
gtk_combo_box_append_text(combo, "11"); D_ITEM(9);
gtk_combo_box_append_text(combo, "13"); D_ITEM(11);
gtk_combo_box_append_text(combo, "15"); D_ITEM(13);
gtk_combo_box_append_text(combo, "17"); D_ITEM(15);
gtk_combo_box_append_text(combo, "19"); D_ITEM(17);
gtk_combo_box_append_text(combo, "21"); D_ITEM(19);
gtk_combo_box_append_text(combo, "23"); D_ITEM(21);
gtk_combo_box_append_text(combo, "25"); D_ITEM(23);
gtk_combo_box_append_text(combo, "27"); D_ITEM(25);
gtk_combo_box_append_text(combo, "29"); D_ITEM(27);
gtk_combo_box_append_text(combo, "31"); // MAX_PATCH_SIZE is 32, so we should be able to do 31... D_ITEM(29);
D_ITEM(31); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
gtk_widget_show(GTK_WIDGET(combo)); gtk_widget_show(GTK_WIDGET(combo));
gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 1, 2, gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 1, 2,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
@ -1002,10 +1004,10 @@ void DoNewPatchDlg()
if(modal_dialog_show(window, dialog) == eIDOK) if(modal_dialog_show(window, dialog) == eIDOK)
{ {
int w = gtk_combo_box_get_active(width) * 2 + 3; int w = gtk_combo_box_get_active(width) * 2 + mincols;
int h = gtk_combo_box_get_active(height) * 2 + 3; int h = gtk_combo_box_get_active(height) * 2 + minrows;
Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), ePlane, GlobalXYWnd_getCurrentViewType(), w, h); Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), prefab, GlobalXYWnd_getCurrentViewType(), w, h);
} }
gtk_widget_destroy(GTK_WIDGET(window)); gtk_widget_destroy(GTK_WIDGET(window));