1 #pragma once 2 #include <string> 3 #include <map> 4 #include "iselection.h" 5 #include "gtkutil/WindowPosition.h" 6 #include "gtkutil/window/PersistentTransientWindow.h" 7 #include "gtkutil/RegistryConnector.h" 8 namespace gtkutil { class ControlButton; } 9 10 // Forward Declarations 11 typedef struct _GtkWidget GtkWidget; 12 typedef struct _GtkEditable GtkEditable; 13 typedef struct _GtkTable GtkTable; 14 15 /* greebo: The dialog providing the Free Transform functionality. 16 * 17 */ 18 namespace ui { 19 20 class TransformDialog : 21 public gtkutil::PersistentTransientWindow, public SelectionSystem::Observer 22 { 23 // The overall vbox (for global sensitivity toggle) 24 GtkWidget* _dialogVBox; 25 26 // The entry fields 27 struct EntryRow { 28 bool isRotator; 29 int axis; 30 GtkWidget* hbox; 31 GtkWidget* label; 32 GtkWidget* step; 33 GtkWidget* stepLabel; 34 gtkutil::ControlButton* smaller; 35 gtkutil::ControlButton* larger; 36 }; 37 typedef std::map<std::string, EntryRow> EntryRowMap; 38 EntryRowMap _entries; 39 40 GtkWidget* _rotateLabel; 41 GtkTable* _rotateTable; 42 GtkWidget* _scaleLabel; 43 GtkTable* _scaleTable; 44 45 // The reference to the SelectionInfo (number of brushes, etc.) 46 //const SelectionInfo& _selectionInfo; 47 48 // The window position tracker 49 gtkutil::WindowPosition _windowPosition; 50 51 // The helper class that syncs the registry to/from widgets 52 gtkutil::RegistryConnector _connector; 53 54 public: 55 // Constructor 56 TransformDialog(); 57 58 /** greebo: Contains the static instance of this dialog. 59 * Constructs the instance and calls toggle() when invoked. 60 */ 61 static TransformDialog& Instance(); 62 63 /** greebo: This toggles the visibility of the dialog. 64 * It is constructed only once and never destructed during runtime. 65 */ 66 void toggleDialog(); 67 68 /** greebo: SelectionSystem::Observer implementation. Gets called by 69 * the SelectionSystem upon selection change to allow updating of the 70 * widget sensitivity. 71 */ 72 void selectionChanged(scene::Instance& instance, bool isComponent); 73 74 /** greebo: The command target compatible with FreeCaller<> to connect 75 * this method to the EventManager. 76 */ 77 static void toggle(); 78 79 private: 80 81 // TransientWindow callbacks 82 virtual void _preShow(); 83 virtual void _preHide(); 84 85 /** greebo: Updates the sensitivity of the widgets according to 86 * the current selection. 87 */ 88 void update(); 89 90 /** greebo: Saves the step values to the registry 91 */ 92 void saveToRegistry(); 93 94 // This is called to initialise the dialog window / create the widgets 95 void populateWindow(); 96 97 /** greebo: Helper method that creates a single row 98 * 99 * @param row: the row index of <table> where the widgets should be packed into. 100 * @param isRotator: set to true if a rotator row is to be created. 101 * @param axis: the axis this transformation is referring to. 102 */ 103 EntryRow createEntryRow(const std::string& label, GtkTable* table, 104 int row, bool isRotator, int axis); 105 106 // Callbacks to catch the scale/rotation button clicks 107 static void onClickSmaller(GtkWidget* button, EntryRow* row); 108 static void onClickLarger(GtkWidget* button, EntryRow* row); 109 110 // The callback ensuring that the step changes are written to the registry 111 static void onStepChanged(GtkEditable* editable, TransformDialog* self); 112 113 }; // class TransformDialog 114 115 } // namespace ui 116