From e9d27f488c8653967c9a5b86c94801367253444c Mon Sep 17 00:00:00 2001 From: neoraider Date: Sun, 13 Jan 2008 16:41:01 +0000 Subject: zoomedit: Added grab tool. --- Drawer.cpp | 1 + EventHandler.h | 1 + LevelObject.h | 2 ++ Makefile.am | 3 ++- Makefile.in | 21 ++++++++++++++++-- PlayerStart.h | 5 +++++ Room.h | 7 ++++++ SidebarManager.cpp | 4 +++- SidebarManager.h | 2 ++ ToolGrab.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ToolGrab.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 ToolGrab.cpp create mode 100644 ToolGrab.h diff --git a/Drawer.cpp b/Drawer.cpp index db3dbdf..8bcfe4a 100644 --- a/Drawer.cpp +++ b/Drawer.cpp @@ -38,6 +38,7 @@ gboolean Drawer::eventHandler(GtkWidget *widget, GdkEvent *event, Drawer *drawer case GDK_MOTION_NOTIFY: drawer->updateHoveredPoint(event->motion.x, event->motion.y); + drawer->window->getActiveTool()->getEventHandler()->motion(); return TRUE; case GDK_ENTER_NOTIFY: diff --git a/EventHandler.h b/EventHandler.h index 6bb6c0f..dabb25b 100644 --- a/EventHandler.h +++ b/EventHandler.h @@ -7,6 +7,7 @@ class EventHandler { virtual bool buttonPress(unsigned int button) {return false;} virtual bool buttonRelease(unsigned int button) {return false;} + virtual bool motion() {return false;} }; #endif /*EVENTHANDLER_H_*/ diff --git a/LevelObject.h b/LevelObject.h index c8d4d47..5dcdd74 100644 --- a/LevelObject.h +++ b/LevelObject.h @@ -11,6 +11,8 @@ class LevelObject : public Object { virtual bool hit(const Vertex &v) const = 0; virtual int getPriority() const = 0; + + virtual void move(float x, float y) {} }; #endif /*LEVELOBJECT_H_*/ diff --git a/Makefile.am b/Makefile.am index 560c273..474e944 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,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 \ - ToolSelector.cpp ToolAddPolygon.cpp ToolAddRect.cpp Vertex3d.cpp + ToolSelector.cpp ToolAddPolygon.cpp ToolAddRect.cpp \ + ToolGrab.cpp Vertex3d.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 17e0fa0..4db79b8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -61,7 +61,8 @@ am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \ zoomedit-SidebarToolbox.$(OBJEXT) \ zoomedit-ToolSelector.$(OBJEXT) \ zoomedit-ToolAddPolygon.$(OBJEXT) \ - zoomedit-ToolAddRect.$(OBJEXT) zoomedit-Vertex3d.$(OBJEXT) + zoomedit-ToolAddRect.$(OBJEXT) zoomedit-ToolGrab.$(OBJEXT) \ + zoomedit-Vertex3d.$(OBJEXT) zoomedit_OBJECTS = $(am_zoomedit_OBJECTS) zoomedit_DEPENDENCIES = DEFAULT_INCLUDES = -I.@am__isrc@ @@ -188,7 +189,8 @@ 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 \ - ToolSelector.cpp ToolAddPolygon.cpp ToolAddRect.cpp Vertex3d.cpp + ToolSelector.cpp ToolAddPolygon.cpp ToolAddRect.cpp \ + ToolGrab.cpp Vertex3d.cpp zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @libxml2_CFLAGS@ zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ @libxml2_LIBS@ @@ -294,6 +296,7 @@ distclean-compile: @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-ToolAddRect.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-ToolGrab.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@ @@ -611,6 +614,20 @@ zoomedit-ToolAddRect.obj: ToolAddRect.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-ToolAddRect.obj `if test -f 'ToolAddRect.cpp'; then $(CYGPATH_W) 'ToolAddRect.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolAddRect.cpp'; fi` +zoomedit-ToolGrab.o: ToolGrab.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ToolGrab.o -MD -MP -MF $(DEPDIR)/zoomedit-ToolGrab.Tpo -c -o zoomedit-ToolGrab.o `test -f 'ToolGrab.cpp' || echo '$(srcdir)/'`ToolGrab.cpp +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ToolGrab.Tpo $(DEPDIR)/zoomedit-ToolGrab.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ToolGrab.cpp' object='zoomedit-ToolGrab.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-ToolGrab.o `test -f 'ToolGrab.cpp' || echo '$(srcdir)/'`ToolGrab.cpp + +zoomedit-ToolGrab.obj: ToolGrab.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ToolGrab.obj -MD -MP -MF $(DEPDIR)/zoomedit-ToolGrab.Tpo -c -o zoomedit-ToolGrab.obj `if test -f 'ToolGrab.cpp'; then $(CYGPATH_W) 'ToolGrab.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolGrab.cpp'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ToolGrab.Tpo $(DEPDIR)/zoomedit-ToolGrab.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ToolGrab.cpp' object='zoomedit-ToolGrab.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-ToolGrab.obj `if test -f 'ToolGrab.cpp'; then $(CYGPATH_W) 'ToolGrab.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolGrab.cpp'; fi` + zoomedit-Vertex3d.o: Vertex3d.cpp @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Vertex3d.o -MD -MP -MF $(DEPDIR)/zoomedit-Vertex3d.Tpo -c -o zoomedit-Vertex3d.o `test -f 'Vertex3d.cpp' || echo '$(srcdir)/'`Vertex3d.cpp @am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Vertex3d.Tpo $(DEPDIR)/zoomedit-Vertex3d.Po diff --git a/PlayerStart.h b/PlayerStart.h index dbae78c..d5c10cd 100644 --- a/PlayerStart.h +++ b/PlayerStart.h @@ -16,6 +16,11 @@ class PlayerStart : public Vertex3d, public LevelObject { virtual const char* getType() const { return "PlayerStart"; } + + virtual void move(float x, float y) { + setX(getX()+x); + setZ(getZ()+y); + } }; #endif /*PLAYERSTART_H_*/ diff --git a/Room.h b/Room.h index b6d086e..8e72c61 100644 --- a/Room.h +++ b/Room.h @@ -28,6 +28,13 @@ class Room : public Polygon, public LevelObject { virtual const char* getType() const { return "Room"; } + + virtual void move(float x, float y) { + for(iterator v = begin(); v != end(); v++) { + v->setX(v->getX()+x); + v->setY(v->getY()+y); + } + } }; #endif /*ROOM_H_*/ diff --git a/SidebarManager.cpp b/SidebarManager.cpp index 42731a8..4cf0e36 100644 --- a/SidebarManager.cpp +++ b/SidebarManager.cpp @@ -3,7 +3,8 @@ SidebarManager::SidebarManager(Window *window) - : sidebarToolbox(window), toolAddRect(&window->getEditManager()), toolAddPolygon(&window->getEditManager()) + : sidebarToolbox(window), toolGrab(&window->getEditManager()), + toolAddRect(&window->getEditManager()), toolAddPolygon(&window->getEditManager()) { this->window = window; activeSidebar = NULL; @@ -27,6 +28,7 @@ SidebarManager::SidebarManager(Window *window) viewport = gtk_viewport_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(scrolledWindow), viewport); + sidebarToolbox.addTool(&toolGrab); sidebarToolbox.addTool(&toolAddRect); sidebarToolbox.addTool(&toolAddPolygon); diff --git a/SidebarManager.h b/SidebarManager.h index 75fc06b..b8deb72 100644 --- a/SidebarManager.h +++ b/SidebarManager.h @@ -5,6 +5,7 @@ #include "Sidebar.h" #include "SidebarToolbox.h" #include "EditManager.h" +#include "ToolGrab.h" #include "ToolAddRect.h" #include "ToolAddPolygon.h" @@ -22,6 +23,7 @@ class SidebarManager { Window *window; + ToolGrab toolGrab; ToolAddRect toolAddRect; ToolAddPolygon toolAddPolygon; diff --git a/ToolGrab.cpp b/ToolGrab.cpp new file mode 100644 index 0000000..2d2467a --- /dev/null +++ b/ToolGrab.cpp @@ -0,0 +1,64 @@ +#include "ToolGrab.h" + +ToolGrab::ToolGrab(EditManager *editManager) : sidebar(editManager) { + this->editManager = editManager; + + pressed = false; + + image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON); + g_object_ref_sink(G_OBJECT(image)); +} + +ToolGrab::~ToolGrab() { + g_object_unref(G_OBJECT(image)); +} + +void ToolGrab::activate() { + pressed = false; + editManager->setSelectedObject(NULL); +} + +bool ToolGrab::buttonPress(unsigned int button) { + if(button != 1) + return false; + + pressed = true; + grabbedVertex = *editManager->getHoveredVertex(); + + editManager->setSelectedObject(editManager->getHoveredObject()); + + editManager->redraw(); + sidebar.update(); + + return true; +} + +bool ToolGrab::buttonRelease(unsigned int button) { + if(button != 1) + return false; + + pressed = false; + + editManager->setSelectedObject(NULL); + + editManager->redraw(); + sidebar.update(); + + return true; +} + +bool ToolGrab::motion() { + if(!pressed) + return false; + + Vertex *v = editManager->getHoveredVertex(); + + if(!v) + return false; + + editManager->getSelectedObject()->move(v->getX()-grabbedVertex.getX(), v->getY()-grabbedVertex.getY()); + + grabbedVertex = *v; + + return true; +} diff --git a/ToolGrab.h b/ToolGrab.h new file mode 100644 index 0000000..ec9f110 --- /dev/null +++ b/ToolGrab.h @@ -0,0 +1,59 @@ +#ifndef TOOLGRAB_H_ +#define TOOLGRAB_H_ + +#include "Tool.h" +#include "EditManager.h" +#include "SidebarView.h" + + +class ToolGrab : public Tool, public EventHandler { + private: + GtkWidget *image; + + EditManager *editManager; + + SidebarView sidebar; + + bool pressed; + Vertex grabbedVertex; + + // prevent shallow copy + ToolGrab(const ToolGrab &t); + const ToolGrab& operator=(const ToolGrab &t); + + public: + ToolGrab(EditManager *editManager); + virtual ~ToolGrab(); + + virtual void activate(); + + virtual const char *getType() const { + return "ToolGrab"; + } + + virtual const char *getName() const { + return "Grab"; + } + + virtual bool isSensitive() { + return TRUE; + } + + virtual GtkWidget *getImage() { + return image; + } + + virtual EventHandler* getEventHandler() { + return this; + } + + virtual bool buttonPress(unsigned int button); + virtual bool buttonRelease(unsigned int button); + virtual bool motion(); + + virtual Sidebar* getSidebar() { + return &sidebar; + } +}; + +#endif /*TOOLGRAB_H_*/ -- cgit v1.2.3