summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-12-04 22:35:01 +0100
committerneoraider <devnull@localhost>2007-12-04 22:35:01 +0100
commitd389dce3ef4f1342a2f91926a9dcd02b452c6045 (patch)
treec3a7a88afd02cb3cdc88a987e227badcc6095b0c
parentecf40f86dfa6aa623bf31494125f3702f9fa0298 (diff)
downloadzoomedit-d389dce3ef4f1342a2f91926a9dcd02b452c6045.tar
zoomedit-d389dce3ef4f1342a2f91926a9dcd02b452c6045.zip
zoomedit: Got SidebarToolbox working.
-rw-r--r--Makefile.am3
-rw-r--r--Makefile.in28
-rw-r--r--SidebarManager.cpp19
-rw-r--r--SidebarManager.h8
-rw-r--r--SidebarToolbox.cpp94
-rw-r--r--SidebarToolbox.h23
-rw-r--r--SidebarView.cpp25
-rw-r--r--SidebarView.h3
-rw-r--r--Tool.cpp9
-rw-r--r--Tool.h15
-rw-r--r--ToolAddPolygon.cpp24
-rw-r--r--ToolAddPolygon.h36
-rw-r--r--UIManager.cpp2
-rw-r--r--UIManager.h2
14 files changed, 218 insertions, 73 deletions
diff --git a/Makefile.am b/Makefile.am
index 1537f4c..6bf8c29 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,6 +3,7 @@ zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \
Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \
IdManager.cpp WindowManager.cpp SidebarManager.cpp \
Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \
- EditManager.cpp FileManager.cpp SidebarToolbox.cpp Tool.cpp
+ EditManager.cpp FileManager.cpp SidebarToolbox.cpp \
+ ToolAddPolygon.cpp
zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @libxml2_CFLAGS@
zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ @libxml2_LIBS@ \ No newline at end of file
diff --git a/Makefile.in b/Makefile.in
index 65c7d58..bcca4ce 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -58,7 +58,8 @@ am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \
zoomedit-SidebarView.$(OBJEXT) zoomedit-SidebarAdd.$(OBJEXT) \
zoomedit-Drawer.$(OBJEXT) zoomedit-EditManager.$(OBJEXT) \
zoomedit-FileManager.$(OBJEXT) \
- zoomedit-SidebarToolbox.$(OBJEXT) zoomedit-Tool.$(OBJEXT)
+ zoomedit-SidebarToolbox.$(OBJEXT) \
+ zoomedit-ToolAddPolygon.$(OBJEXT)
zoomedit_OBJECTS = $(am_zoomedit_OBJECTS)
zoomedit_DEPENDENCIES =
DEFAULT_INCLUDES = -I.@am__isrc@
@@ -184,7 +185,8 @@ zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \
Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \
IdManager.cpp WindowManager.cpp SidebarManager.cpp \
Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \
- EditManager.cpp FileManager.cpp SidebarToolbox.cpp Tool.cpp
+ EditManager.cpp FileManager.cpp SidebarToolbox.cpp \
+ ToolAddPolygon.cpp
zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @libxml2_CFLAGS@
zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ @libxml2_LIBS@
@@ -289,7 +291,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarManager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarToolbox.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarView.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Tool.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-ToolAddPolygon.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Triangle.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-UIManager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Vertex.Po@am__quote@
@@ -577,19 +579,19 @@ zoomedit-SidebarToolbox.obj: SidebarToolbox.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-SidebarToolbox.obj `if test -f 'SidebarToolbox.cpp'; then $(CYGPATH_W) 'SidebarToolbox.cpp'; else $(CYGPATH_W) '$(srcdir)/SidebarToolbox.cpp'; fi`
-zoomedit-Tool.o: Tool.cpp
-@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Tool.o -MD -MP -MF $(DEPDIR)/zoomedit-Tool.Tpo -c -o zoomedit-Tool.o `test -f 'Tool.cpp' || echo '$(srcdir)/'`Tool.cpp
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Tool.Tpo $(DEPDIR)/zoomedit-Tool.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Tool.cpp' object='zoomedit-Tool.o' libtool=no @AMDEPBACKSLASH@
+zoomedit-ToolAddPolygon.o: ToolAddPolygon.cpp
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ToolAddPolygon.o -MD -MP -MF $(DEPDIR)/zoomedit-ToolAddPolygon.Tpo -c -o zoomedit-ToolAddPolygon.o `test -f 'ToolAddPolygon.cpp' || echo '$(srcdir)/'`ToolAddPolygon.cpp
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ToolAddPolygon.Tpo $(DEPDIR)/zoomedit-ToolAddPolygon.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ToolAddPolygon.cpp' object='zoomedit-ToolAddPolygon.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-Tool.o `test -f 'Tool.cpp' || echo '$(srcdir)/'`Tool.cpp
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-ToolAddPolygon.o `test -f 'ToolAddPolygon.cpp' || echo '$(srcdir)/'`ToolAddPolygon.cpp
-zoomedit-Tool.obj: Tool.cpp
-@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Tool.obj -MD -MP -MF $(DEPDIR)/zoomedit-Tool.Tpo -c -o zoomedit-Tool.obj `if test -f 'Tool.cpp'; then $(CYGPATH_W) 'Tool.cpp'; else $(CYGPATH_W) '$(srcdir)/Tool.cpp'; fi`
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Tool.Tpo $(DEPDIR)/zoomedit-Tool.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Tool.cpp' object='zoomedit-Tool.obj' libtool=no @AMDEPBACKSLASH@
+zoomedit-ToolAddPolygon.obj: ToolAddPolygon.cpp
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ToolAddPolygon.obj -MD -MP -MF $(DEPDIR)/zoomedit-ToolAddPolygon.Tpo -c -o zoomedit-ToolAddPolygon.obj `if test -f 'ToolAddPolygon.cpp'; then $(CYGPATH_W) 'ToolAddPolygon.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolAddPolygon.cpp'; fi`
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ToolAddPolygon.Tpo $(DEPDIR)/zoomedit-ToolAddPolygon.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ToolAddPolygon.cpp' object='zoomedit-ToolAddPolygon.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-Tool.obj `if test -f 'Tool.cpp'; then $(CYGPATH_W) 'Tool.cpp'; else $(CYGPATH_W) '$(srcdir)/Tool.cpp'; fi`
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-ToolAddPolygon.obj `if test -f 'ToolAddPolygon.cpp'; then $(CYGPATH_W) 'ToolAddPolygon.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolAddPolygon.cpp'; fi`
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
diff --git a/SidebarManager.cpp b/SidebarManager.cpp
index 86e70d0..a0bfb81 100644
--- a/SidebarManager.cpp
+++ b/SidebarManager.cpp
@@ -2,19 +2,27 @@
SidebarManager::SidebarManager(EditManager *editor)
- : sidebarView(editor), sidebarAdd(editor)
+ : sidebarView(editor), sidebarAdd(editor), tool(editor)
{
this->editor = editor;
activeSidebar = NULL;
- sidebar = gtk_scrolled_window_new(NULL, NULL);
- g_object_ref_sink(G_OBJECT(sidebar));
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sidebar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ sidebar = gtk_vbox_new(FALSE, 0);
+ g_object_ref_sink(G_OBJECT(sidebar));
+
+ gtk_box_pack_start_defaults(GTK_BOX(sidebar), sidebarToolbox.getWidget());
+
+ 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_widget_show(scrolledWindow);
viewport = gtk_viewport_new(NULL, NULL);
- gtk_container_add(GTK_CONTAINER(sidebar), viewport);
+ gtk_container_add(GTK_CONTAINER(scrolledWindow), viewport);
gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
+ sidebarToolbox.addTool(&tool);
+
gtk_widget_show(sidebar);
}
@@ -42,5 +50,6 @@ void SidebarManager::update() {
activeSidebar = newSidebar;
}
+ sidebarToolbox.update();
activeSidebar->update();
}
diff --git a/SidebarManager.h b/SidebarManager.h
index c195f08..18b8319 100644
--- a/SidebarManager.h
+++ b/SidebarManager.h
@@ -3,14 +3,18 @@
#include <gtk/gtk.h>
#include "Sidebar.h"
+#include "SidebarToolbox.h"
#include "SidebarView.h"
#include "SidebarAdd.h"
#include "EditManager.h"
+#include "ToolAddPolygon.h"
class SidebarManager {
private:
- GtkWidget *sidebar, *viewport;
+ GtkWidget *sidebar, *scrolledWindow, *viewport;
+
+ SidebarToolbox sidebarToolbox;
SidebarView sidebarView;
SidebarAdd sidebarAdd;
@@ -19,6 +23,8 @@ class SidebarManager {
EditManager *editor;
+ ToolAddPolygon tool;
+
// prevent shallow copy
SidebarManager(const SidebarManager &w);
const SidebarManager& operator=(const SidebarManager &w);
diff --git a/SidebarToolbox.cpp b/SidebarToolbox.cpp
index ed5e5da..3094d2a 100644
--- a/SidebarToolbox.cpp
+++ b/SidebarToolbox.cpp
@@ -1,31 +1,101 @@
#include "SidebarToolbox.h"
-SidebarToolbox::SidebarToolbox()
-{
- widget = gtk_vbox_new(FALSE, 0);
+
+void SidebarToolbox::toolAction(GtkWidget *button, Tool *tool) {
+ tool->action();
+}
+
+void SidebarToolbox::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, SidebarToolbox *toolbox) {
+ toolbox->updateRows(false);
+}
+
+SidebarToolbox::SidebarToolbox() {
+
+ cols = 1; rows = 0;
+
+ widget = gtk_table_new(1, 1, TRUE);
g_object_ref_sink(G_OBJECT(widget));
+
+ g_signal_connect(G_OBJECT(widget), "size-allocate", G_CALLBACK(sizeAllocate), this);
+
+ gtk_widget_show(widget);
}
-SidebarToolbox::~SidebarToolbox()
-{
+SidebarToolbox::~SidebarToolbox() {
+ for(std::map<Tool*, GtkWidget*>::iterator button = buttons.begin(); button != buttons.end(); button++) {
+ g_object_unref(G_OBJECT(button->second));
+ }
+
g_object_unref(G_OBJECT(widget));
}
-bool SidebarToolbox::addTool(Tool *tool) {
- bool ret = tools.insert(tool).second;
+void SidebarToolbox::addTool(Tool *tool) {
+ tools.push_back(tool);
+
+ GtkWidget *button = gtk_button_new();
+ g_object_ref_sink(G_OBJECT(button));
+ gtk_button_set_image(GTK_BUTTON(button), tool->getImage());
+ gtk_widget_show(button);
+ g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(toolAction), tool);
+
+ buttons.insert(std::pair<Tool*, GtkWidget*>(tool, button));
+ updateRows(true);
update();
+}
+
+void SidebarToolbox::removeTool(Tool *tool) {
+ tools.remove(tool);
- return ret;
+ g_object_unref(G_OBJECT(buttons[tool]));
+ buttons.erase(tool);
+
+ updateRows(true);
}
-bool SidebarToolbox::removeTool(Tool *tool) {
- bool ret = (tools.erase(tool) > 0);
+void SidebarToolbox::updateRows(bool changed) {
+ int cols, rows;
+ GtkRequisition requisition = {0, 0};
- update();
+ if(tools.empty()) {
+ cols = 1; rows = 0;
+ }
+ else {
+ gtk_widget_size_request(buttons[tools.front()], &requisition);
+
+ cols = MAX(1, widget->allocation.width/requisition.width);
+ rows = (tools.size()+cols-1)/cols;
+ }
- return ret;
+ if(this->cols != cols || this->rows != rows || changed) {
+ this->cols = cols;
+ this->rows = rows;
+
+ gtk_widget_set_size_request(widget, -1, rows*requisition.height);
+
+ for(std::map<Tool*, GtkWidget*>::iterator button = buttons.begin(); button != buttons.end(); button++) {
+ if(gtk_widget_get_parent(button->second))
+ gtk_container_remove(GTK_CONTAINER(widget), button->second);
+ }
+
+ gtk_table_resize(GTK_TABLE(widget), MAX(1, cols), MAX(1, rows));
+
+ int iCol = 0, iRow = 0;
+ for(std::list<Tool*>::iterator tool = tools.begin(); tool != tools.end(); tool++) {
+ gtk_table_attach(GTK_TABLE(widget), buttons[*tool], iCol, iCol+1, iRow, iRow+1, GTK_FILL, GTK_FILL, 0, 0);
+
+ iCol++;
+ if(iCol >= cols) {
+ iRow++;
+ iCol = 0;
+ }
+ }
+ }
}
void SidebarToolbox::update() {
+ for(std::list<Tool*>::iterator tool = tools.begin(); tool != tools.end(); tool++) {
+ gtk_widget_set_tooltip_text(buttons[*tool], (*tool)->getName());
+ gtk_widget_set_sensitive(buttons[*tool], (*tool)->isSensitive());
+ }
}
diff --git a/SidebarToolbox.h b/SidebarToolbox.h
index 4982502..46af985 100644
--- a/SidebarToolbox.h
+++ b/SidebarToolbox.h
@@ -2,23 +2,30 @@
#define SIDEBARTOOLBOX_H_
#include <gtk/gtk.h>
+#include <map>
#include <list>
-#include <set>
+#include "EditManager.h"
#include "Sidebar.h"
#include "Tool.h"
-class SidebarToolbox : Sidebar
-{
+class SidebarToolbox : Sidebar {
private:
GtkWidget *widget;
- std::list<GtkWidget*> buttonBoxes;
- std::set<Tool*> tools;
+ std::list<Tool*> tools;
+ std::map<Tool*, GtkWidget*> buttons;
+
+ int cols, rows;
+
+ void updateRows(bool changed);
// prevent shallow copy
SidebarToolbox(const SidebarToolbox &w);
const SidebarToolbox& operator=(const SidebarToolbox &w);
+ static void toolAction(GtkWidget *button, Tool *tool);
+ static void sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, SidebarToolbox *toolbox);
+
public:
SidebarToolbox();
virtual ~SidebarToolbox();
@@ -27,10 +34,10 @@ class SidebarToolbox : Sidebar
return widget;
}
- void update();
+ void addTool(Tool *tool);
+ void removeTool(Tool *tool);
- bool addTool(Tool *tool);
- bool removeTool(Tool *tool);
+ void update();
};
#endif /*SIDEBARTOOLBOX_H_*/
diff --git a/SidebarView.cpp b/SidebarView.cpp
index a0d4ae5..8e58967 100644
--- a/SidebarView.cpp
+++ b/SidebarView.cpp
@@ -8,10 +8,6 @@ void SidebarView::spinButtonHeightChanged(GtkSpinButton *spinbutton, SidebarView
view->editor->getActiveRoom()->setHeight(gtk_spin_button_get_value(spinbutton));
}
-void SidebarView::buttonClicked(GtkButton *button, SidebarView *sidebar) {
- sidebar->editor->addRoom();
-}
-
SidebarView::SidebarView(EditManager *editor) {
this->editor = editor;
@@ -25,12 +21,12 @@ SidebarView::SidebarView(EditManager *editor) {
gtk_box_pack_start(GTK_BOX(sidebar), gtk_hseparator_new(), FALSE, FALSE, 5);
- GtkWidget *labelName = gtk_label_new("Name:");
+ GtkWidget *labelName = gtk_label_new("Name: ");
gtk_misc_set_alignment(GTK_MISC(labelName), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(sidebar), labelName, FALSE, FALSE, 0);
entryName = gtk_entry_new();
- gtk_widget_set_usize(entryName, 1, -1);
+ gtk_widget_set_size_request(entryName, 0, -1);
//g_signal_connect(G_OBJECT(entryName), "focus-out-event", G_CALLBACK(sidebarNameFocusOutEvent), NULL);
//gtk_widget_add_events(entryName, GDK_FOCUS_CHANGE_MASK);
gtk_box_pack_start(GTK_BOX(sidebar), entryName, FALSE, FALSE, 0);
@@ -39,37 +35,34 @@ SidebarView::SidebarView(EditManager *editor) {
gtk_table_set_row_spacings(GTK_TABLE(tableRoomData), 5);
gtk_box_pack_start(GTK_BOX(sidebar), tableRoomData, FALSE, FALSE, 5);
- GtkWidget *labelAreaLabel = gtk_label_new("Room area:");
+ GtkWidget *labelAreaLabel = gtk_label_new("Room area: ");
gtk_misc_set_alignment(GTK_MISC(labelAreaLabel), 0.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelAreaLabel, 0, 1, 0, 1);
+ gtk_table_attach(GTK_TABLE(tableRoomData), labelAreaLabel, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
labelArea = gtk_label_new(NULL);
gtk_misc_set_alignment(GTK_MISC(labelArea), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelArea, 1, 2, 0, 1);
- GtkWidget *labelPerimeterLabel = gtk_label_new("Room perimeter:");
+ GtkWidget *labelPerimeterLabel = gtk_label_new("Room perimeter: ");
gtk_misc_set_alignment(GTK_MISC(labelPerimeterLabel), 0.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelPerimeterLabel, 0, 1, 1, 2);
+ gtk_table_attach(GTK_TABLE(tableRoomData), labelPerimeterLabel, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
labelPerimeter = gtk_label_new(NULL);
gtk_misc_set_alignment(GTK_MISC(labelPerimeter), 1.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelPerimeter, 1, 2, 1, 2);
- GtkWidget *labelHeight = gtk_label_new("Height:");
+ GtkWidget *labelHeight = gtk_label_new("Height: ");
gtk_misc_set_alignment(GTK_MISC(labelHeight), 0.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelHeight, 0, 1, 2, 3);
+ gtk_table_attach(GTK_TABLE(tableRoomData), labelHeight, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
spinButtonHeight = gtk_spin_button_new_with_range(0, 10000, 0.1f);
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonHeight), 2);
gtk_entry_set_alignment(GTK_ENTRY(spinButtonHeight), 1.0);
gtk_table_attach(GTK_TABLE(tableRoomData), spinButtonHeight, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL),
(GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0);
+ gtk_widget_set_size_request(spinButtonHeight, 0, -1);
g_signal_connect(G_OBJECT(spinButtonHeight), "value-changed", G_CALLBACK(spinButtonHeightChanged), this);
- 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);
}
diff --git a/SidebarView.h b/SidebarView.h
index a4c01f0..c0249fa 100644
--- a/SidebarView.h
+++ b/SidebarView.h
@@ -8,7 +8,7 @@
class SidebarView : public Sidebar {
private:
GtkWidget *sidebar;
- GtkWidget *entryName, *labelArea, *labelPerimeter, *spinButtonHeight, *buttonAdd;
+ GtkWidget *entryName, *labelArea, *labelPerimeter, *spinButtonHeight;
EditManager *editor;
@@ -17,7 +17,6 @@ class SidebarView : public Sidebar {
const SidebarView& operator=(const SidebarView &w);
static void spinButtonHeightChanged(GtkSpinButton *spinbutton, SidebarView *view);
- static void buttonClicked(GtkButton *button, SidebarView *view);
public:
SidebarView(EditManager *editor);
diff --git a/Tool.cpp b/Tool.cpp
deleted file mode 100644
index 52e711c..0000000
--- a/Tool.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "Tool.h"
-
-Tool::Tool()
-{
-}
-
-Tool::~Tool()
-{
-}
diff --git a/Tool.h b/Tool.h
index b95590a..12a06e6 100644
--- a/Tool.h
+++ b/Tool.h
@@ -1,11 +1,18 @@
#ifndef TOOL_H_
#define TOOL_H_
-class Tool
-{
+#include <gtk/gtk.h>
+
+
+class Tool {
public:
- Tool();
- virtual ~Tool();
+ virtual ~Tool() {}
+
+ virtual void action() = 0;
+
+ virtual const gchar *getName() = 0;
+ virtual GtkWidget *getImage() = 0;
+ virtual bool isSensitive() = 0;
};
#endif /*TOOL_H_*/
diff --git a/ToolAddPolygon.cpp b/ToolAddPolygon.cpp
new file mode 100644
index 0000000..6e4b813
--- /dev/null
+++ b/ToolAddPolygon.cpp
@@ -0,0 +1,24 @@
+#include "ToolAddPolygon.h"
+
+
+const gchar *ToolAddPolygon::name = (const gchar*)"Add polygonal room";
+
+
+ToolAddPolygon::ToolAddPolygon(EditManager *editManager) {
+ this->editManager = editManager;
+
+ image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON);
+ g_object_ref_sink(G_OBJECT(image));
+}
+
+ToolAddPolygon::~ToolAddPolygon() {
+ g_object_unref(G_OBJECT(image));
+}
+
+void ToolAddPolygon::action() {
+ editManager->addRoom();
+}
+
+GtkWidget *ToolAddPolygon::getImage() {
+ return image;
+}
diff --git a/ToolAddPolygon.h b/ToolAddPolygon.h
new file mode 100644
index 0000000..7d17bdc
--- /dev/null
+++ b/ToolAddPolygon.h
@@ -0,0 +1,36 @@
+#ifndef TOOLADDPOLYGON_H_
+#define TOOLADDPOLYGON_H_
+
+#include "Tool.h"
+#include "EditManager.h"
+
+class ToolAddPolygon : public Tool {
+ private:
+ GtkWidget *image;
+
+ EditManager *editManager;
+
+ static const gchar* name;
+
+ // prevent shallow copy
+ ToolAddPolygon(const ToolAddPolygon &t);
+ const ToolAddPolygon& operator=(const ToolAddPolygon &t);
+
+ public:
+ ToolAddPolygon(EditManager *editManager);
+ virtual ~ToolAddPolygon();
+
+ virtual void action();
+
+ virtual const gchar *getName() {
+ return name;
+ }
+
+ bool isSensitive() {
+ return (editManager->getMode() != EditManager::ADD);
+ }
+
+ virtual GtkWidget *getImage();
+};
+
+#endif /*TOOLADDPOLYGON_H_*/
diff --git a/UIManager.cpp b/UIManager.cpp
index 2b4fefd..bec4c43 100644
--- a/UIManager.cpp
+++ b/UIManager.cpp
@@ -2,7 +2,7 @@
#include "Window.h"
-const gchar* const UIManager::uiData = (const gchar*)
+const gchar* UIManager::uiData = (const gchar*)
"<ui>"
"<menubar>"
"<menu action=\"fileMenu\">"
diff --git a/UIManager.h b/UIManager.h
index 2ec7d6b..ac157b1 100644
--- a/UIManager.h
+++ b/UIManager.h
@@ -9,7 +9,7 @@ class Window;
class UIManager {
private:
- static const gchar* const uiData;
+ static const gchar* uiData;
GtkUIManager *uiManager;
Window *window;