From a6a43f1b95bd33990a21fd1a52bff8c4a129d4e9 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 22 Aug 2000 14:14:07 +0000 Subject: Several changes, see docs/CHANGES.txt for a complete list git-svn-id: http://svn.leocad.org/trunk@103 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- linux/dlgpiece.cpp | 345 +++++++++++++---------------------------------------- 1 file changed, 82 insertions(+), 263 deletions(-) (limited to 'linux/dlgpiece.cpp') diff --git a/linux/dlgpiece.cpp b/linux/dlgpiece.cpp index 17d91b2..2735356 100755 --- a/linux/dlgpiece.cpp +++ b/linux/dlgpiece.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "opengl.h" #include "gtkglarea.h" #include "gtktools.h" @@ -20,43 +21,24 @@ #include "dialogs.h" #include "matrix.h" #include "pieceinf.h" -#include "project.h" #include "main.h" +#include "minifig.h" // ========================================================= // Minifig Wizard -typedef enum { - MFW_HAT, - MFW_HEAD, - MFW_TORSO, - MFW_NECK, - MFW_LEFT_ARM, - MFW_RIGHT_ARM, - MFW_LEFT_HAND, - MFW_RIGHT_HAND, - MFW_LEFT_TOOL, - MFW_RIGHT_TOOL, - MFW_HIPS, - MFW_LEFT_LEG, - MFW_RIGHT_LEG, - MFW_LEFT_SHOE, - MFW_RIGHT_SHOE, - MFW_NUMITEMS -}; - typedef struct { - LC_MINIFIGDLG_OPTS* opts; - GtkWidget *pieces[MFW_NUMITEMS]; - GtkWidget *colors[MFW_NUMITEMS]; + MinifigWizard* opts; + GtkWidget *pieces[LC_MFW_NUMITEMS]; + GtkWidget *colors[LC_MFW_NUMITEMS]; + GtkWidget *angles[LC_MFW_NUMITEMS]; GtkWidget *preview; } LC_MINIFIGDLG_STRUCT; static gint minifigdlg_redraw (GtkWidget *widget, GdkEventExpose *event) { LC_MINIFIGDLG_STRUCT* data; - int i; // Draw only last expose. if (event->count > 0) @@ -70,25 +52,8 @@ static gint minifigdlg_redraw (GtkWidget *widget, GdkEventExpose *event) if (!gtk_gl_area_make_current(GTK_GL_AREA(widget))) return TRUE; - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - for (i = 0; i < 15; i++) - { - if (data->opts->info[i] == NULL) - continue; - - glPushMatrix(); - Matrix mat; - float rot[4]; - mat.CreateOld(0,0,0, data->opts->rot[i][0], data->opts->rot[i][1], data->opts->rot[i][2]); - mat.ToAxisAngle(rot); - glTranslatef(data->opts->pos[i][0], data->opts->pos[i][1], data->opts->pos[i][2]); - glRotatef(rot[3], rot[0], rot[1], rot[2]); - data->opts->info[i]->RenderPiece(data->opts->colors[i]); - glPopMatrix(); - } + data->opts->Redraw (); - glFinish(); gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); gtk_gl_area_make_current(GTK_GL_AREA(drawing_area)); @@ -98,26 +63,15 @@ static gint minifigdlg_redraw (GtkWidget *widget, GdkEventExpose *event) // Setup the OpenGL projection static gint minifigdlg_resize (GtkWidget *widget, GdkEventConfigure *event) { + LC_MINIFIGDLG_STRUCT* data = (LC_MINIFIGDLG_STRUCT*)gtk_object_get_data (GTK_OBJECT (widget), "minifig"); + + if (!data) + return TRUE; + if (!gtk_gl_area_make_current(GTK_GL_AREA(widget))) return TRUE; - float aspect = (float)widget->allocation.width/(float)widget->allocation.height; - glViewport(0, 0, widget->allocation.width, widget->allocation.height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(30.0f, aspect, 1.0f, 20.0f); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - gluLookAt (0, -9, 4, 0, 5, 1, 0, 0, 1); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - float *bg = project->GetBackgroundColor(); - glClearColor(bg[0], bg[1], bg[2], bg[3]); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glDisable (GL_DITHER); - glShadeModel (GL_FLAT); + data->opts->Resize (widget->allocation.width, widget->allocation.height); gtk_gl_area_make_current(GTK_GL_AREA(drawing_area)); @@ -150,7 +104,7 @@ static void minifigdlg_color_response (GtkWidget *widget, gpointer data) if (info->colors[i] == button) break; - info->opts->colors[i] = (int)data; + info->opts->ChangeColor (i, GPOINTER_TO_INT (data)); gtk_widget_draw (info->preview, NULL); set_button_pixmap2 (button, FlatColorArray[(int)data]); } @@ -186,18 +140,17 @@ static gint minifigdlg_color_expose (GtkWidget *widget) } // New piece was selected -static void minifigdlg_piece_changed (GtkWidget *widget) +static void minifigdlg_piece_changed (GtkWidget *widget, gpointer data) { LC_MINIFIGDLG_STRUCT* info; - PieceInfo* piece_info = NULL; - int i, j, piece_type; + int i, piece_type; char* desc; info = (LC_MINIFIGDLG_STRUCT*)gtk_object_get_data (GTK_OBJECT (widget), "info"); if (info == NULL) return; - for (i = 0; i < 15; i++) + for (i = 0; i < LC_MFW_NUMITEMS; i++) if (GTK_COMBO (info->pieces[i])->entry == widget) { piece_type = i; @@ -206,140 +159,35 @@ static void minifigdlg_piece_changed (GtkWidget *widget) desc = gtk_entry_get_text (GTK_ENTRY (widget)); - for (j = 0; j < MFW_PIECES; j++) - { - if (strcmp (desc, mfwpieceinfo[j].description) == 0) - { - piece_info = project->FindPieceInfo(mfwpieceinfo[j].name); - if (piece_info == NULL) - continue; - - if (info->opts->info[i]) - info->opts->info[i]->DeRef(); - info->opts->info[i] = piece_info; - piece_info->AddRef(); - break; - } - } + info->opts->ChangePiece (i, desc); - // Piece not found ("None") - if (j == MFW_PIECES) - { - if (info->opts->info[i]) - info->opts->info[i]->DeRef(); - info->opts->info[i] = NULL; - } + gtk_widget_draw (info->preview, NULL); +} - // Get the pieces in the right place - // TODO: Find a way to make this cross-platform - if (i == MFW_NECK) - { - if (info->opts->info[3] != NULL) - { - info->opts->pos[0][2] = 3.92f; - info->opts->pos[1][2] = 3.92f; - - if (strcmp (piece_info->m_strName,"4498") == 0) - info->opts->rot[3][2] = 180.0f; - else - info->opts->rot[3][2] = 0.0f; - } - else - { - info->opts->pos[0][2] = 3.84f; - info->opts->pos[1][2] = 3.84f; - } - } +static void adj_changed (GtkAdjustment *adj, gpointer data) +{ + LC_MINIFIGDLG_STRUCT* info = (LC_MINIFIGDLG_STRUCT*)data; + int i; - if (i == MFW_LEFT_SHOE) - { - if (strcmp (desc, "Ski")) - info->opts->pos[13][1] = 0; - else - info->opts->pos[13][1] = -0.12f; - } + for (i = 0; i < LC_MFW_NUMITEMS; i++) + if (info->angles[i] != NULL) + if (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (info->angles[i])) == adj) + break; - if (i == MFW_RIGHT_SHOE) - { - if (strcmp (desc, "Ski")) - info->opts->pos[14][1] = 0; - else - info->opts->pos[14][1] = -0.12f; - } + if (i == LC_MFW_NUMITEMS) + return; - if ((i == MFW_LEFT_TOOL) || (i == MFW_RIGHT_TOOL)) - if (piece_info != NULL) - { - float rx = 45, ry = 0, rz = 0, x = 0.92f, y = -0.62f, z = 1.76f; - - if (strcmp (piece_info->m_strName,"4529") == 0) - { rx = -45; y = -1.14f; z = 2.36f; } - if (strcmp (piece_info->m_strName,"3899") == 0) - { y = -1.64f; z = 1.38f; } - if (strcmp (piece_info->m_strName,"4528") == 0) - { rx = -45; y = -1.26f; z = 2.36f; } - if (strcmp (piece_info->m_strName,"4479") == 0) - { rz = 90; y = -1.22f; z = 2.44f; } - if (strcmp (piece_info->m_strName,"3962") == 0) - { rz = 90; y = -0.7f; z = 1.62f; } - if (strcmp (piece_info->m_strName,"4360") == 0) - { rz = -90; y = -1.22f; z = 2.44f; } - if (strncmp (piece_info->m_strName,"6246",4) == 0) - { y = -1.82f; z = 2.72f; rz = 90; } - if (strcmp (piece_info->m_strName,"4349") == 0) - { y = -1.16f; z = 2.0f; } - if (strcmp (piece_info->m_strName,"4479") == 0) - { y = -1.42f; z = 2.26f; } - if (strcmp (piece_info->m_strName,"3959") == 0) - { y = -1.0f; z = 1.88f; } - if (strcmp (piece_info->m_strName,"4522") == 0) - { y = -1.64f; z = 2.48f; } - if (strcmp (piece_info->m_strName,"194") == 0) - { rz = 180; y = -1.04f; z = 1.94f; } - if (strcmp (piece_info->m_strName,"4006") == 0) - { rz = 180; y = -1.24f; z = 2.18f; } - if (strcmp (piece_info->m_strName,"6246C") == 0) - { rx = 45; rz = 0; y = -0.86f; z = 1.78f; } - if (strcmp (piece_info->m_strName,"4497") == 0) - { y = -2.16f; z = 3.08f; rz = 90; } - if (strcmp (piece_info->m_strName,"30092") == 0) - { x = 0; rz = 180; } - if (strcmp (piece_info->m_strName,"37") == 0) - { z = 1.52f; y = -0.64f; } - if (strcmp (piece_info->m_strName,"38") == 0) - { z = 1.24f; y = -0.34f; } - if (strcmp (piece_info->m_strName,"3841") == 0) - { z = 2.24f; y = -1.34f; rz = 180; } - if (strcmp (piece_info->m_strName,"4499") == 0) - { rz = ((i == MFW_RIGHT_TOOL) ? 10 : -10); z = 1.52f; } - if (strcmp (piece_info->m_strName,"3852") == 0) - { rz = -90; x = 0.90f; y = -0.8f; z = 1.84f; } - if (strcmp (piece_info->m_strName,"30152") == 0) - { z = 3.06f; y = -2.16f; } - if (strcmp (piece_info->m_strName,"2570") == 0) - { z = 1.68f; y = -0.8f; } - if (strcmp (piece_info->m_strName,"2614") == 0) - { z = 1.74f; y = -0.86f; } - - if (i == MFW_RIGHT_TOOL) - x = -x; - - info->opts->pos[i][0] = x; - info->opts->pos[i][1] = y; - info->opts->pos[i][2] = z; - info->opts->rot[i][0] = rx; - info->opts->rot[i][1] = ry; - info->opts->rot[i][2] = rz; - } + info->opts->ChangeAngle (i, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (info->angles[i]))); - gtk_widget_draw (info->preview, NULL); + if (info->preview != NULL) + gtk_widget_draw (info->preview, NULL); } - // Create a combo box with a color selection control static void minifigdlg_createpair (LC_MINIFIGDLG_STRUCT* info, int num, GtkWidget* vbox) { - GtkWidget *hbox, *combo, *color; + GtkWidget *hbox, *combo, *color, *spin; + GtkObject *adj; hbox = gtk_hbox_new (FALSE, 5); gtk_widget_show (hbox); @@ -357,7 +205,7 @@ static void minifigdlg_createpair (LC_MINIFIGDLG_STRUCT* info, int num, GtkWidge color = info->colors[num] = gtk_button_new_with_label (""); gtk_widget_set_events (color, GDK_EXPOSURE_MASK); gtk_widget_show (color); - gtk_object_set_data (GTK_OBJECT (color), "color", &info->opts->colors[num]); + gtk_object_set_data (GTK_OBJECT (color), "color", &info->opts->m_Colors[num]); gtk_object_set_data (GTK_OBJECT (color), "info", info); gtk_widget_set_usize (color, 40, 25); gtk_signal_connect (GTK_OBJECT (color), "expose_event", @@ -365,12 +213,19 @@ static void minifigdlg_createpair (LC_MINIFIGDLG_STRUCT* info, int num, GtkWidge gtk_signal_connect (GTK_OBJECT (color), "clicked", GTK_SIGNAL_FUNC (minifigdlg_color_clicked), info); gtk_box_pack_start (GTK_BOX (hbox), color, FALSE, TRUE, 0); -} -// sort the names from the combo boxes -static gint minifigdlg_compare (gconstpointer a, gconstpointer b) -{ - return strcmp ((const char*)a, (const char*)b); + if ((num == LC_MFW_TORSO) || (num == LC_MFW_HIPS)) + return; + + adj = gtk_adjustment_new (0, -180, 180, 1, 10, 10); + gtk_signal_connect (adj, "value_changed", GTK_SIGNAL_FUNC (adj_changed), info); + + spin = info->angles[num] = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 0); + gtk_widget_show (spin); + gtk_object_set_data (GTK_OBJECT (color), "info", info); + // gtk_widget_set_usize (spin, 40, -1); + gtk_box_pack_start (GTK_BOX (hbox), spin, FALSE, TRUE, 0); + gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin), TRUE); } int minifigdlg_execute(void* param) @@ -382,7 +237,8 @@ int minifigdlg_execute(void* param) GtkWidget *button; int i; - s.opts = (LC_MINIFIGDLG_OPTS*)param; + memset (&s, 0, sizeof (s)); + s.opts = (MinifigWizard*)param; dlg = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (dlg), "delete_event", @@ -391,7 +247,7 @@ int minifigdlg_execute(void* param) GTK_SIGNAL_FUNC (gtk_widget_destroy), NULL); gtk_widget_set_usize (dlg, 600, 360); gtk_window_set_title (GTK_WINDOW (dlg), "Minifig Wizard"); - gtk_window_set_policy (GTK_WINDOW (dlg), FALSE, FALSE, FALSE); + // gtk_window_set_policy (GTK_WINDOW (dlg), FALSE, FALSE, FALSE); gtk_widget_realize (dlg); vbox1 = gtk_vbox_new (FALSE, 10); @@ -401,20 +257,20 @@ int minifigdlg_execute(void* param) hbox = gtk_hbox_new (FALSE, 5); gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0); vbox2 = gtk_vbox_new (FALSE, 5); gtk_widget_show (vbox2); gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); - minifigdlg_createpair (&s, MFW_HAT, vbox2); - minifigdlg_createpair (&s, MFW_NECK, vbox2); - minifigdlg_createpair (&s, MFW_RIGHT_ARM, vbox2); - minifigdlg_createpair (&s, MFW_RIGHT_HAND, vbox2); - minifigdlg_createpair (&s, MFW_RIGHT_TOOL, vbox2); - minifigdlg_createpair (&s, MFW_HIPS, vbox2); - minifigdlg_createpair (&s, MFW_RIGHT_LEG, vbox2); - minifigdlg_createpair (&s, MFW_RIGHT_SHOE, vbox2); + minifigdlg_createpair (&s, LC_MFW_HAT, vbox2); + minifigdlg_createpair (&s, LC_MFW_NECK, vbox2); + minifigdlg_createpair (&s, LC_MFW_RIGHT_ARM, vbox2); + minifigdlg_createpair (&s, LC_MFW_RIGHT_HAND, vbox2); + minifigdlg_createpair (&s, LC_MFW_RIGHT_TOOL, vbox2); + minifigdlg_createpair (&s, LC_MFW_HIPS, vbox2); + minifigdlg_createpair (&s, LC_MFW_RIGHT_LEG, vbox2); + minifigdlg_createpair (&s, LC_MFW_RIGHT_SHOE, vbox2); // Create new OpenGL widget. s.preview = gtk_gl_area_share_new (attrlist, GTK_GL_AREA (drawing_area)); @@ -430,7 +286,7 @@ int minifigdlg_execute(void* param) gtk_container_add (GTK_CONTAINER (hbox), frame); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); - gtk_widget_set_usize (GTK_WIDGET (s.preview), 100, 300); + gtk_widget_set_usize (GTK_WIDGET (s.preview), 150, 300); gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (s.preview)); gtk_widget_show (GTK_WIDGET (s.preview)); gtk_object_set_data (GTK_OBJECT (s.preview), "minifig", &s); @@ -439,13 +295,13 @@ int minifigdlg_execute(void* param) gtk_widget_show (vbox2); gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); - minifigdlg_createpair (&s, MFW_HEAD, vbox2); - minifigdlg_createpair (&s, MFW_TORSO, vbox2); - minifigdlg_createpair (&s, MFW_LEFT_ARM, vbox2); - minifigdlg_createpair (&s, MFW_LEFT_HAND, vbox2); - minifigdlg_createpair (&s, MFW_LEFT_TOOL, vbox2); - minifigdlg_createpair (&s, MFW_LEFT_LEG, vbox2); - minifigdlg_createpair (&s, MFW_LEFT_SHOE, vbox2); + minifigdlg_createpair (&s, LC_MFW_HEAD, vbox2); + minifigdlg_createpair (&s, LC_MFW_TORSO, vbox2); + minifigdlg_createpair (&s, LC_MFW_LEFT_ARM, vbox2); + minifigdlg_createpair (&s, LC_MFW_LEFT_HAND, vbox2); + minifigdlg_createpair (&s, LC_MFW_LEFT_TOOL, vbox2); + minifigdlg_createpair (&s, LC_MFW_LEFT_LEG, vbox2); + minifigdlg_createpair (&s, LC_MFW_LEFT_SHOE, vbox2); hbox = gtk_hbox_new (FALSE, 10); gtk_widget_show (hbox); @@ -473,64 +329,27 @@ int minifigdlg_execute(void* param) GDK_Escape, 0, GTK_ACCEL_VISIBLE); // Fill the combo boxes with the available pieces - GList* names[15]; - for (i = 0; i < 15; i++) - names[i] = NULL; - - for (i = 0; i < MFW_PIECES; i++) + for (i = 0; i < LC_MFW_NUMITEMS; i++) { - PieceInfo* piece_info; - int id; + GList* names = NULL; + int count; + char **list; + s.opts->GetDescriptions (i, &list, &count); - piece_info = project->FindPieceInfo(mfwpieceinfo[i].name); - if (piece_info == NULL) - continue; + for (int j = 0; j < count; j++) + names = g_list_append (names, list[j]); - switch (mfwpieceinfo[i].type) + if (names != NULL) { - case MF_HAT: id = MFW_HAT; break; - case MF_HEAD: id = MFW_HEAD; break; - case MF_TORSO: id = MFW_TORSO; break; - case MF_NECK: id = MFW_NECK; break; - case MF_ARML: id = MFW_LEFT_ARM; break; - case MF_ARMR: id = MFW_RIGHT_ARM; break; - case MF_HAND: id = MFW_LEFT_HAND; break; - case MF_TOOL: id = MFW_LEFT_TOOL; break; - case MF_HIPS: id = MFW_HIPS; break; - case MF_LEGL: id = MFW_LEFT_LEG; break; - case MF_LEGR: id = MFW_RIGHT_LEG; break; - case MF_SHOE: id = MFW_LEFT_SHOE; break; - default: - continue; + gtk_combo_set_popdown_strings (GTK_COMBO (s.pieces[i]), names); + g_list_free (names); } - - if (i != 29) - names[id] = g_list_insert_sorted (names[id], mfwpieceinfo[i].description, minifigdlg_compare); - - if (id == MFW_LEFT_HAND || id == MFW_LEFT_TOOL || id == MFW_LEFT_SHOE) - names[id+1] = g_list_insert_sorted (names[id+1], mfwpieceinfo[i].description, minifigdlg_compare); - - if (i == 6) i++; + free (list); } - names[MFW_HAT] = g_list_prepend (names[MFW_HAT], (void*)"None"); - names[MFW_NECK] = g_list_prepend (names[MFW_NECK], (void*)"None"); - names[MFW_LEFT_TOOL] = g_list_prepend (names[MFW_LEFT_TOOL], (void*)"None"); - names[MFW_RIGHT_TOOL] = g_list_prepend (names[MFW_RIGHT_TOOL], (void*)"None"); - names[MFW_LEFT_SHOE] = g_list_prepend (names[MFW_LEFT_SHOE], (void*)"None"); - names[MFW_RIGHT_SHOE] = g_list_prepend (names[MFW_RIGHT_SHOE], (void*)"None"); - - for (i = 0; i < 15; i++) - gtk_combo_set_popdown_strings ( GTK_COMBO (s.pieces[i]), names[i]); - - gtk_list_select_item ( GTK_LIST (GTK_COMBO (s.pieces[MFW_HAT])->list), 7); - gtk_list_select_item ( GTK_LIST (GTK_COMBO (s.pieces[MFW_HEAD])->list), 4); - gtk_list_select_item ( GTK_LIST (GTK_COMBO (s.pieces[MFW_TORSO])->list), 22); + gtk_list_select_item (GTK_LIST (GTK_COMBO (s.pieces[LC_MFW_HAT])->list), 7); + gtk_list_select_item (GTK_LIST (GTK_COMBO (s.pieces[LC_MFW_HEAD])->list), 4); + gtk_list_select_item (GTK_LIST (GTK_COMBO (s.pieces[LC_MFW_TORSO])->list), 22); return dlg_domodal(dlg, LC_CANCEL); } - - - - - -- cgit v1.2.3