diff options
-rw-r--r-- | EditManager.cpp | 3 | ||||
-rw-r--r-- | Room.h | 2 | ||||
-rw-r--r-- | SidebarAdd.cpp | 18 | ||||
-rw-r--r-- | SidebarManager.cpp | 19 | ||||
-rw-r--r-- | SidebarManager.h | 7 | ||||
-rw-r--r-- | SidebarToolbox.cpp | 7 | ||||
-rw-r--r-- | SidebarToolbox.h | 12 | ||||
-rw-r--r-- | Window.cpp | 2 |
8 files changed, 40 insertions, 30 deletions
diff --git a/EditManager.cpp b/EditManager.cpp index 37fbcfd..8e2c045 100644 --- a/EditManager.cpp +++ b/EditManager.cpp @@ -42,7 +42,7 @@ EditManager::EditManager(Window *window) { void EditManager::addRoom() { if(mode == VIEW) { - newRoom = Room(idManager.generate("room")); + newRoom = Room(); mode = ADD; activeRoom = &newRoom; @@ -56,6 +56,7 @@ void EditManager::finishRoom() { mode = VIEW; if(newRoom.size() > 2 && polygonOk(newRoom)) { + newRoom.setName(idManager.generate("room")); window->getLevel().push_back(newRoom); activeRoom = &window->getLevel().back(); } @@ -12,7 +12,7 @@ class Room : public Polygon { public: Room() {height = 10;} - Room(std::string name) {this->name = name; height= 10;} + Room(std::string name) {this->name = name; height = 10;} std::string &getName() {return name;} diff --git a/SidebarAdd.cpp b/SidebarAdd.cpp index 57de3ee..80ec74f 100644 --- a/SidebarAdd.cpp +++ b/SidebarAdd.cpp @@ -1,10 +1,6 @@ #include "SidebarAdd.h" -void SidebarAdd::buttonClicked(GtkButton *button, SidebarAdd *sidebar) { - sidebar->editor->finishRoom(); -} - SidebarAdd::SidebarAdd(EditManager *editor) { this->editor = editor; @@ -16,10 +12,6 @@ SidebarAdd::SidebarAdd(EditManager *editor) { gtk_misc_set_alignment(GTK_MISC(labelRoomInfo), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(sidebar), labelRoomInfo, FALSE, FALSE, 5); - buttonAdd = gtk_button_new_with_label("Add room"); - g_signal_connect(G_OBJECT(buttonAdd), "clicked", G_CALLBACK(buttonClicked), this); - gtk_box_pack_end(GTK_BOX(sidebar), buttonAdd, FALSE, FALSE, 0); - gtk_widget_show_all(sidebar); } @@ -30,13 +22,3 @@ SidebarAdd::~SidebarAdd() { GtkWidget* SidebarAdd::getWidget() { return sidebar; } - -void SidebarAdd::update() { - if(!editor->getActiveRoom()) - return; - - if(editor->getActiveRoom()->size() > 2 && editor->polygonOk(*editor->getActiveRoom())) - gtk_widget_set_sensitive(buttonAdd, TRUE); - else - gtk_widget_set_sensitive(buttonAdd, FALSE); -} diff --git a/SidebarManager.cpp b/SidebarManager.cpp index b3bbaa7..0eb1f7b 100644 --- a/SidebarManager.cpp +++ b/SidebarManager.cpp @@ -1,10 +1,12 @@ #include "SidebarManager.h" +#include "Window.h" -SidebarManager::SidebarManager(EditManager *editor) - : sidebarToolbox(editor), sidebarView(editor), sidebarAdd(editor), toolAddPolygon(editor) +SidebarManager::SidebarManager(Window *window) + : sidebarToolbox(window), sidebarView(&window->getEditManager()), + sidebarAdd(&window->getEditManager()), toolAddPolygon(&window->getEditManager()) { - this->editor = editor; + this->editor = &window->getEditManager(); activeSidebar = NULL; sidebar = gtk_vbox_new(FALSE, 0); @@ -12,14 +14,19 @@ SidebarManager::SidebarManager(EditManager *editor) gtk_box_pack_start(GTK_BOX(sidebar), sidebarToolbox.getWidget(), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(sidebar), gtk_hseparator_new(), FALSE, FALSE, 5); + + toolLabel = gtk_label_new(sidebarToolbox.getActiveTool()->getName()); + + gtk_box_pack_start(GTK_BOX(sidebar), toolLabel, FALSE, FALSE, 0); + scrolledWindow = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_box_pack_end_defaults(GTK_BOX(sidebar), scrolledWindow); + gtk_box_pack_start_defaults(GTK_BOX(sidebar), scrolledWindow); gtk_widget_show(scrolledWindow); viewport = gtk_viewport_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(scrolledWindow), viewport); - gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE); sidebarToolbox.addTool(&toolAddPolygon); @@ -50,6 +57,8 @@ void SidebarManager::update() { activeSidebar = newSidebar; } + gtk_label_set_text(GTK_LABEL(toolLabel), sidebarToolbox.getActiveTool()->getName()); + sidebarToolbox.update(); activeSidebar->update(); } diff --git a/SidebarManager.h b/SidebarManager.h index b5b18f0..90fc0cc 100644 --- a/SidebarManager.h +++ b/SidebarManager.h @@ -11,9 +11,12 @@ #include "ToolAddPolygon.h" +class Window; + + class SidebarManager { private: - GtkWidget *sidebar, *scrolledWindow, *viewport; + GtkWidget *sidebar, *toolLabel, *scrolledWindow, *viewport; SidebarToolbox sidebarToolbox; @@ -31,7 +34,7 @@ class SidebarManager { const SidebarManager& operator=(const SidebarManager &w); public: - SidebarManager(EditManager *editor); + SidebarManager(Window *window); virtual ~SidebarManager(); GtkWidget *getWidget() { diff --git a/SidebarToolbox.cpp b/SidebarToolbox.cpp index a26417b..b264835 100644 --- a/SidebarToolbox.cpp +++ b/SidebarToolbox.cpp @@ -1,4 +1,5 @@ #include "SidebarToolbox.h" +#include "Window.h" void SidebarToolbox::buttonToggled(GtkWidget *button, SidebarToolbox *toolbox) { @@ -6,6 +7,8 @@ void SidebarToolbox::buttonToggled(GtkWidget *button, SidebarToolbox *toolbox) { return; toolbox->activateTool(toolbox->buttonsRev[button]); + + toolbox->window->update(); } void SidebarToolbox::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, SidebarToolbox *toolbox) { @@ -56,7 +59,9 @@ void SidebarToolbox::activateTool(Tool *tool) { tool->activate(); } -SidebarToolbox::SidebarToolbox(EditManager *editManager) : toolSelector(editManager) { +SidebarToolbox::SidebarToolbox(Window *window) : toolSelector(&window->getEditManager()) { + this->window = window; + widget = gtk_table_new(1, 1, TRUE); g_object_ref_sink(G_OBJECT(widget)); diff --git a/SidebarToolbox.h b/SidebarToolbox.h index 49bfec4..8e8a1f2 100644 --- a/SidebarToolbox.h +++ b/SidebarToolbox.h @@ -9,10 +9,16 @@ #include "Tool.h" #include "ToolSelector.h" + +class Window; + + class SidebarToolbox : Sidebar { private: GtkWidget *widget; + Window *window; + std::list<Tool*> tools; std::map<Tool*, GtkWidget*> buttons; std::map<GtkWidget*, Tool*> buttonsRev; @@ -34,13 +40,17 @@ class SidebarToolbox : Sidebar { static void sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, SidebarToolbox *toolbox); public: - SidebarToolbox(EditManager *editManager); + SidebarToolbox(Window *window); virtual ~SidebarToolbox(); GtkWidget* getWidget() { return widget; } + Tool *getActiveTool() { + return activeTool; + } + void addTool(Tool *tool); void removeTool(Tool *tool); @@ -11,7 +11,7 @@ gboolean Window::deleteEvent(GtkWidget *widget, GdkEvent *event, Window *window) } Window::Window(GdkGLConfig *glconfig, WindowManager *manager) - : uiManager(this), editor(this), drawer(this, glconfig), sidebar(&editor), + : uiManager(this), editor(this), drawer(this, glconfig), sidebar(this), fileManager(this) { this->manager = manager; |