summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-12-05 19:34:01 +0100
committerneoraider <devnull@localhost>2007-12-05 19:34:01 +0100
commit19690f030457dadf4976f7403c315b3bbb4a39b8 (patch)
tree29077314f77be6b4371b0fdeeb6bed142a126b7e
parentd389dce3ef4f1342a2f91926a9dcd02b452c6045 (diff)
downloadzoomedit-19690f030457dadf4976f7403c315b3bbb4a39b8.tar
zoomedit-19690f030457dadf4976f7403c315b3bbb4a39b8.zip
zoomedit: Use toolbox for polygon adder.
-rw-r--r--EditManager.cpp33
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.in18
-rw-r--r--SidebarManager.cpp4
-rw-r--r--SidebarManager.h3
-rw-r--r--SidebarToolbox.cpp118
-rw-r--r--SidebarToolbox.h11
-rw-r--r--Tool.h3
-rw-r--r--ToolAddPolygon.cpp6
-rw-r--r--ToolAddPolygon.h5
-rw-r--r--ToolSelector.cpp20
-rw-r--r--ToolSelector.h34
12 files changed, 185 insertions, 72 deletions
diff --git a/EditManager.cpp b/EditManager.cpp
index 5822ffc..37fbcfd 100644
--- a/EditManager.cpp
+++ b/EditManager.cpp
@@ -41,23 +41,30 @@ EditManager::EditManager(Window *window) {
}
void EditManager::addRoom() {
- newRoom = Room(idManager.generate("room"));
- mode = ADD;
-
- activeRoom = &newRoom;
-
- window->update();
+ if(mode == VIEW) {
+ newRoom = Room(idManager.generate("room"));
+ mode = ADD;
+
+ activeRoom = &newRoom;
+
+ window->update();
+ }
}
void EditManager::finishRoom() {
- mode = VIEW;
-
- if(newRoom.size() > 2 && polygonOk(newRoom)) {
- window->getLevel().push_back(newRoom);
- activeRoom = &window->getLevel().back();
+ if(mode == ADD) {
+ mode = VIEW;
+
+ if(newRoom.size() > 2 && polygonOk(newRoom)) {
+ window->getLevel().push_back(newRoom);
+ activeRoom = &window->getLevel().back();
+ }
+ else {
+ activeRoom = NULL;
+ }
+
+ window->update();
}
-
- window->update();
}
void EditManager::addVertex(const Vertex &v) {
diff --git a/Makefile.am b/Makefile.am
index 6bf8c29..aeb0122 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,6 +4,6 @@ zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \
IdManager.cpp WindowManager.cpp SidebarManager.cpp \
Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \
EditManager.cpp FileManager.cpp SidebarToolbox.cpp \
- ToolAddPolygon.cpp
+ ToolSelector.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 bcca4ce..35421b0 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -59,6 +59,7 @@ am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \
zoomedit-Drawer.$(OBJEXT) zoomedit-EditManager.$(OBJEXT) \
zoomedit-FileManager.$(OBJEXT) \
zoomedit-SidebarToolbox.$(OBJEXT) \
+ zoomedit-ToolSelector.$(OBJEXT) \
zoomedit-ToolAddPolygon.$(OBJEXT)
zoomedit_OBJECTS = $(am_zoomedit_OBJECTS)
zoomedit_DEPENDENCIES =
@@ -186,7 +187,7 @@ zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \
IdManager.cpp WindowManager.cpp SidebarManager.cpp \
Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \
EditManager.cpp FileManager.cpp SidebarToolbox.cpp \
- ToolAddPolygon.cpp
+ ToolSelector.cpp ToolAddPolygon.cpp
zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @libxml2_CFLAGS@
zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ @libxml2_LIBS@
@@ -292,6 +293,7 @@ distclean-compile:
@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-ToolAddPolygon.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-ToolSelector.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@
@@ -579,6 +581,20 @@ 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-ToolSelector.o: ToolSelector.cpp
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ToolSelector.o -MD -MP -MF $(DEPDIR)/zoomedit-ToolSelector.Tpo -c -o zoomedit-ToolSelector.o `test -f 'ToolSelector.cpp' || echo '$(srcdir)/'`ToolSelector.cpp
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ToolSelector.Tpo $(DEPDIR)/zoomedit-ToolSelector.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ToolSelector.cpp' object='zoomedit-ToolSelector.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-ToolSelector.o `test -f 'ToolSelector.cpp' || echo '$(srcdir)/'`ToolSelector.cpp
+
+zoomedit-ToolSelector.obj: ToolSelector.cpp
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ToolSelector.obj -MD -MP -MF $(DEPDIR)/zoomedit-ToolSelector.Tpo -c -o zoomedit-ToolSelector.obj `if test -f 'ToolSelector.cpp'; then $(CYGPATH_W) 'ToolSelector.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolSelector.cpp'; fi`
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ToolSelector.Tpo $(DEPDIR)/zoomedit-ToolSelector.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ToolSelector.cpp' object='zoomedit-ToolSelector.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-ToolSelector.obj `if test -f 'ToolSelector.cpp'; then $(CYGPATH_W) 'ToolSelector.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolSelector.cpp'; fi`
+
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
diff --git a/SidebarManager.cpp b/SidebarManager.cpp
index a0bfb81..3e04016 100644
--- a/SidebarManager.cpp
+++ b/SidebarManager.cpp
@@ -2,7 +2,7 @@
SidebarManager::SidebarManager(EditManager *editor)
- : sidebarView(editor), sidebarAdd(editor), tool(editor)
+ : sidebarToolbox(editor), sidebarView(editor), sidebarAdd(editor), toolAddPolygon(editor)
{
this->editor = editor;
activeSidebar = NULL;
@@ -21,7 +21,7 @@ SidebarManager::SidebarManager(EditManager *editor)
gtk_container_add(GTK_CONTAINER(scrolledWindow), viewport);
gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
- sidebarToolbox.addTool(&tool);
+ sidebarToolbox.addTool(&toolAddPolygon);
gtk_widget_show(sidebar);
}
diff --git a/SidebarManager.h b/SidebarManager.h
index 18b8319..b5b18f0 100644
--- a/SidebarManager.h
+++ b/SidebarManager.h
@@ -7,6 +7,7 @@
#include "SidebarView.h"
#include "SidebarAdd.h"
#include "EditManager.h"
+#include "ToolSelector.h"
#include "ToolAddPolygon.h"
@@ -23,7 +24,7 @@ class SidebarManager {
EditManager *editor;
- ToolAddPolygon tool;
+ ToolAddPolygon toolAddPolygon;
// prevent shallow copy
SidebarManager(const SidebarManager &w);
diff --git a/SidebarToolbox.cpp b/SidebarToolbox.cpp
index 3094d2a..8c8511d 100644
--- a/SidebarToolbox.cpp
+++ b/SidebarToolbox.cpp
@@ -1,23 +1,73 @@
#include "SidebarToolbox.h"
-void SidebarToolbox::toolAction(GtkWidget *button, Tool *tool) {
- tool->action();
+void SidebarToolbox::buttonToggled(GtkWidget *button, SidebarToolbox *toolbox) {
+ if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
+ return;
+
+ toolbox->activateTool(toolbox->buttonsRev[button]);
}
void SidebarToolbox::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, SidebarToolbox *toolbox) {
toolbox->updateRows(false);
}
-SidebarToolbox::SidebarToolbox() {
+
+void SidebarToolbox::updateRows(bool changed) {
+ GtkRequisition requisition;
+
+ gtk_widget_size_request(buttons[tools.front()], &requisition);
+
+ int cols = MAX(1, widget->allocation.width/requisition.width);
+ int rows = (tools.size()+cols-1)/cols;
+
+ if(changed || this->cols != cols || this->rows != rows) {
+ 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::activateTool(Tool *tool) {
+ if(activeTool == tool)
+ return;
- cols = 1; rows = 0;
+ if(activeTool)
+ activeTool->deactivate();
+ activeTool = tool;
+ tool->activate();
+}
+
+SidebarToolbox::SidebarToolbox(EditManager *editManager) : toolSelector(editManager) {
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);
+ addTool(&toolSelector);
+ activeTool = NULL;
+ activateTool(&toolSelector);
+
gtk_widget_show(widget);
}
@@ -30,69 +80,41 @@ SidebarToolbox::~SidebarToolbox() {
}
void SidebarToolbox::addTool(Tool *tool) {
- tools.push_back(tool);
-
- GtkWidget *button = gtk_button_new();
+ GtkWidget *button;
+ if(tools.empty())
+ button = gtk_radio_button_new(NULL);
+ else
+ button = gtk_radio_button_new_from_widget(GTK_RADIO_BUTTON(buttons[tools.front()]));
g_object_ref_sink(G_OBJECT(button));
+ gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(button), FALSE);
+ gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
gtk_button_set_image(GTK_BUTTON(button), tool->getImage());
+
gtk_widget_show(button);
- g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(toolAction), tool);
+ g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(buttonToggled), this);
+ tools.push_back(tool);
buttons.insert(std::pair<Tool*, GtkWidget*>(tool, button));
+ buttonsRev.insert(std::pair<GtkWidget*, Tool*>(button, tool));
updateRows(true);
update();
}
void SidebarToolbox::removeTool(Tool *tool) {
+ if(tool == activeTool) {
+ activateTool(&toolSelector);
+ }
+
tools.remove(tool);
+ buttonsRev.erase(buttons[tool]);
g_object_unref(G_OBJECT(buttons[tool]));
buttons.erase(tool);
updateRows(true);
}
-void SidebarToolbox::updateRows(bool changed) {
- int cols, rows;
- GtkRequisition requisition = {0, 0};
-
- 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;
- }
-
- 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());
diff --git a/SidebarToolbox.h b/SidebarToolbox.h
index 46af985..49bfec4 100644
--- a/SidebarToolbox.h
+++ b/SidebarToolbox.h
@@ -7,6 +7,7 @@
#include "EditManager.h"
#include "Sidebar.h"
#include "Tool.h"
+#include "ToolSelector.h"
class SidebarToolbox : Sidebar {
private:
@@ -14,20 +15,26 @@ class SidebarToolbox : Sidebar {
std::list<Tool*> tools;
std::map<Tool*, GtkWidget*> buttons;
+ std::map<GtkWidget*, Tool*> buttonsRev;
+
+ Tool *activeTool;
+
+ ToolSelector toolSelector;
int cols, rows;
void updateRows(bool changed);
+ void activateTool(Tool *tool);
// prevent shallow copy
SidebarToolbox(const SidebarToolbox &w);
const SidebarToolbox& operator=(const SidebarToolbox &w);
- static void toolAction(GtkWidget *button, Tool *tool);
+ static void buttonToggled(GtkWidget *button, SidebarToolbox *toolbox);
static void sizeAllocate(GtkWidget *widget, GtkAllocation *allocation, SidebarToolbox *toolbox);
public:
- SidebarToolbox();
+ SidebarToolbox(EditManager *editManager);
virtual ~SidebarToolbox();
GtkWidget* getWidget() {
diff --git a/Tool.h b/Tool.h
index 12a06e6..b958ddf 100644
--- a/Tool.h
+++ b/Tool.h
@@ -8,7 +8,8 @@ class Tool {
public:
virtual ~Tool() {}
- virtual void action() = 0;
+ virtual void activate() {};
+ virtual void deactivate() {};
virtual const gchar *getName() = 0;
virtual GtkWidget *getImage() = 0;
diff --git a/ToolAddPolygon.cpp b/ToolAddPolygon.cpp
index 6e4b813..a958665 100644
--- a/ToolAddPolygon.cpp
+++ b/ToolAddPolygon.cpp
@@ -15,10 +15,14 @@ ToolAddPolygon::~ToolAddPolygon() {
g_object_unref(G_OBJECT(image));
}
-void ToolAddPolygon::action() {
+void ToolAddPolygon::activate() {
editManager->addRoom();
}
+void ToolAddPolygon::deactivate() {
+ editManager->finishRoom();
+}
+
GtkWidget *ToolAddPolygon::getImage() {
return image;
}
diff --git a/ToolAddPolygon.h b/ToolAddPolygon.h
index 7d17bdc..d3ec2d3 100644
--- a/ToolAddPolygon.h
+++ b/ToolAddPolygon.h
@@ -20,14 +20,15 @@ class ToolAddPolygon : public Tool {
ToolAddPolygon(EditManager *editManager);
virtual ~ToolAddPolygon();
- virtual void action();
+ virtual void activate();
+ virtual void deactivate();
virtual const gchar *getName() {
return name;
}
bool isSensitive() {
- return (editManager->getMode() != EditManager::ADD);
+ return TRUE;
}
virtual GtkWidget *getImage();
diff --git a/ToolSelector.cpp b/ToolSelector.cpp
new file mode 100644
index 0000000..aa19e65
--- /dev/null
+++ b/ToolSelector.cpp
@@ -0,0 +1,20 @@
+#include "ToolSelector.h"
+
+
+const gchar *ToolSelector::name = (const gchar*)"Select";
+
+
+ToolSelector::ToolSelector(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));
+}
+
+ToolSelector::~ToolSelector() {
+ g_object_unref(G_OBJECT(image));
+}
+
+GtkWidget *ToolSelector::getImage() {
+ return image;
+}
diff --git a/ToolSelector.h b/ToolSelector.h
new file mode 100644
index 0000000..1692bf3
--- /dev/null
+++ b/ToolSelector.h
@@ -0,0 +1,34 @@
+#ifndef TOOLSELECTOR_H_
+#define TOOLSELECTOR_H_
+
+#include "Tool.h"
+#include "EditManager.h"
+
+class ToolSelector : public Tool {
+ private:
+ GtkWidget *image;
+
+ EditManager *editManager;
+
+ static const gchar* name;
+
+ // prevent shallow copy
+ ToolSelector(const ToolSelector &t);
+ const ToolSelector& operator=(const ToolSelector &t);
+
+ public:
+ ToolSelector(EditManager *editManager);
+ virtual ~ToolSelector();
+
+ virtual const gchar *getName() {
+ return name;
+ }
+
+ bool isSensitive() {
+ return TRUE;
+ }
+
+ virtual GtkWidget *getImage();
+};
+
+#endif /*TOOLSELECTOR_H_*/