00001 #ifndef MODELSELECTOR_H_ 00002 #define MODELSELECTOR_H_ 00003 00004 #include <gtk/gtk.h> 00005 #include <string> 00006 #include "math/matrix.h" 00007 #include "igl.h" 00008 #include "imodel.h" 00009 #include "../common/ModelPreview.h" 00010 00011 namespace ui 00012 { 00013 00017 struct ModelAndSkin 00018 { 00019 // Model and skin strings 00020 std::string model; 00021 int skin; 00022 00023 // Constructor 00024 ModelAndSkin (const std::string& m, const int& s) : 00025 model(m), skin(s) 00026 { 00027 } 00028 }; 00029 00033 class ModelSelector 00034 { 00035 private: 00036 00037 // Main dialog widget 00038 GtkWidget* _widget; 00039 00040 // Model preview widget 00041 ModelPreview _modelPreview; 00042 00043 // Tree store containing model names 00044 GtkTreeStore* _treeStore; 00045 00046 // Currently-selected row in the tree store 00047 GtkTreeSelection* _selection; 00048 00049 // List store to contain attributes and values for the selected model 00050 GtkListStore* _infoStore; 00051 00052 // Last selected model, which will be returned by showAndBlock() once the 00053 // recursive main loop exits. 00054 std::string _lastModel; 00055 int _lastSkin; 00056 00057 private: 00058 00059 // Private constructor, creates GTK widgets 00060 ModelSelector (); 00061 00062 // Show the dialog, called internally by chooseModel(). Return the selected model path 00063 ModelAndSkin showAndBlock (); 00064 00065 // Helper function to construct the TreeView 00066 GtkWidget* createTreeView (); 00067 GtkWidget* createButtons (); 00068 GtkWidget* createPreviewAndInfoPanel (); 00069 00070 // Initialise the GL widget, to avoid doing this every frame 00071 void initialisePreview (); 00072 00073 // Update the info table with information from the currently-selected model 00074 // update the displayed model. 00075 void updateSelected (); 00076 00077 // Return the value from the selected column, or an empty string if nothing selected 00078 std::string getSelectedString (gint col); 00079 // Return the value from the selected column, or -1 if nothing was selected 00080 int getSelectedInteger (gint col); 00081 00082 /* GTK CALLBACKS */ 00083 static void callbackHide (GtkWidget*, GdkEvent*, ModelSelector*); 00084 static void callbackSelChanged (GtkWidget*, ModelSelector*); 00085 static void callbackOK (GtkWidget*, ModelSelector*); 00086 static void callbackCancel (GtkWidget*, ModelSelector*); 00087 00088 public: 00089 00095 static ModelAndSkin chooseModel (); 00096 }; 00097 } 00098 00099 #endif /*MODELSELECTOR_H_*/