summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Drawer.cpp44
-rw-r--r--EditManager.cpp149
-rw-r--r--EditManager.h31
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.in26
-rw-r--r--SidebarAdd.cpp5
-rw-r--r--SidebarView.cpp9
-rw-r--r--Window.cpp2
-rw-r--r--draw.cpp61
-rw-r--r--draw.h12
-rw-r--r--edit.cpp169
-rw-r--r--edit.h32
-rw-r--r--zoomedit.cpp1
13 files changed, 227 insertions, 316 deletions
diff --git a/Drawer.cpp b/Drawer.cpp
index 48bc730..69aa261 100644
--- a/Drawer.cpp
+++ b/Drawer.cpp
@@ -1,7 +1,6 @@
#include "Drawer.h"
#include "Window.h"
#include "draw.h"
-#include "edit.h"
#include <GL/gl.h>
#include <math.h>
@@ -34,7 +33,7 @@ gboolean Drawer::eventHandler(GtkWidget *widget, GdkEvent *event, Drawer *drawer
return TRUE;
case GDK_EXPOSE:
- drawTopView(widget, &event->expose, NULL);
+ drawTopView(widget, &event->expose, &drawer->window->getLevel(), &drawer->window->getEditManager());
return TRUE;
case GDK_MOTION_NOTIFY:
@@ -46,32 +45,11 @@ gboolean Drawer::eventHandler(GtkWidget *widget, GdkEvent *event, Drawer *drawer
return TRUE;
case GDK_LEAVE_NOTIFY:
- setHoveredVertex(NULL);
- drawer->window->update();
+ drawer->window->getEditManager().setHoveredVertex(NULL);
return TRUE;
case GDK_BUTTON_PRESS:
- switch(event->button.button) {
- case 1:
- if(!getHoveredVertex())
- break;
-
- switch(drawer->window->getEditManager().getMode()) {
- case EditManager::VIEW:
- setActiveRoom(getHoveredRoom());
- break;
-
- case EditManager::ADD:
- if(isVertexOk(getHoveredVertex()))
- drawer->window->getEditManager().addVertex(*getHoveredVertex());
- }
-
- drawer->window->update();
- break;
-
- default:
- return FALSE;
- }
+ drawer->window->getEditManager().buttonPress(event->button.button);
return TRUE;
case GDK_SCROLL:
@@ -118,13 +96,13 @@ void Drawer::updateViewport() {
}
void Drawer::updateScrolling() {
- if(getImageWidth() < getWidth())
- setXTranslate((getImageWidth()-getWidth())/2);
+ if(getImageWidth(&window->getLevel()) < getWidth())
+ setXTranslate((getImageWidth(&window->getLevel())-getWidth())/2);
else
setXTranslate(gtk_adjustment_get_value(hAdjustment));
- if(getImageHeight() < getHeight())
- setYTranslate((getImageHeight()-getHeight())/2);
+ if(getImageHeight(&window->getLevel()) < getHeight())
+ setYTranslate((getImageHeight(&window->getLevel())-getHeight())/2);
else
setYTranslate(gtk_adjustment_get_value(vAdjustment));
@@ -132,7 +110,7 @@ void Drawer::updateScrolling() {
}
void Drawer::updateScrollbars(float x, float y) {
- const gdouble imageWidth = getImageWidth(), imageHeight = getImageHeight();
+ const gdouble imageWidth = getImageWidth(&window->getLevel()), imageHeight = getImageHeight(&window->getLevel());
const gdouble width = getWidth(), height = getHeight();
gdouble upper, pageSize, value;
@@ -165,10 +143,8 @@ void Drawer::updateScrollbars(float x, float y) {
void Drawer::updateHoveredPoint(float x, float y) {
Vertex v(x, y);
- viewToImage(&v);
- setHoveredVertex(&v);
-
- window->update();
+ viewToImage(&window->getLevel(), &v);
+ window->getEditManager().setHoveredVertex(&v);
}
Drawer::Drawer(Window *window, GdkGLConfig *glconfig) {
diff --git a/EditManager.cpp b/EditManager.cpp
index 34d53be..d2e65ce 100644
--- a/EditManager.cpp
+++ b/EditManager.cpp
@@ -1,19 +1,50 @@
#include "EditManager.h"
#include "Window.h"
-#include "edit.h"
+
+
+bool EditManager::lineOk(const Line& l) const {
+ Line l2;
+
+ if(activeRoom) {
+ for(size_t i = 0; i+2 < activeRoom->size(); i++) {
+ l2.setVertex1(activeRoom->at(i));
+ l2.setVertex2(activeRoom->at(i+1));
+
+ if(l.intersects(l2, NULL) == INTERSECTION_SEGMENT_SEGMENT) return false;
+ }
+
+ if(activeRoom->size() > 1) {
+ l2.setVertex1(activeRoom->at(activeRoom->size()-2));
+ l2.setVertex2(activeRoom->back());
+ if(l2.contains(l.getVertex2())) return false;
+ }
+ }
+
+ for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
+ if(room->intersects(l))
+ return false;
+ }
+
+ return true;
+}
EditManager::EditManager(Window *window) {
this->window = window;
+ activeRoom = NULL;
mode = VIEW;
+
+ hoveredRoom = NULL;
+
+ hasHoveredVertex = false;
}
void EditManager::addRoom() {
- //newRoom = Room();
+ newRoom = Room(idManager.generate("room"));
mode = ADD;
- startAddMode();
+ activeRoom = &newRoom;
window->update();
}
@@ -21,20 +52,118 @@ void EditManager::addRoom() {
void EditManager::finishRoom() {
mode = VIEW;
- if(getActiveRoom() && getActiveRoom()->size() > 2 && isPolygonOk(getActiveRoom())) {
- getLevel()->push_back(*getActiveRoom());
- setActiveRoom(&getLevel()->back());
-
- endAddMode();
+ if(newRoom.size() > 2 && polygonOk(newRoom)) {
+ window->getLevel().push_back(newRoom);
+ activeRoom = &window->getLevel().back();
}
window->update();
}
void EditManager::addVertex(const Vertex &v) {
- if(mode != ADD || !getActiveRoom())
+ if(mode != ADD || !activeRoom)
return;
- getActiveRoom()->push_back(v);
+ activeRoom->push_back(v);
window->update();
}
+
+Vertex* EditManager::getHoveredVertex() {
+ if(hasHoveredVertex) return &hoveredVertex;
+ else return NULL;
+}
+
+void EditManager::setHoveredVertex(Vertex *v) {
+ if(v) {
+ hasHoveredVertex = true;
+ hoveredVertex = *v;
+
+ hoveredRoom = NULL;
+
+ for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
+ if(room->contains(*v)) {
+ hoveredRoom = &*room;
+ break;
+ }
+ }
+ }
+ else {
+ hasHoveredVertex = false;
+ hoveredRoom = NULL;
+ }
+
+ window->update();
+}
+
+void EditManager::buttonPress(unsigned int button) {
+ switch(button) {
+ case 1:
+ if(!hasHoveredVertex)
+ break;
+
+ switch(mode) {
+ case VIEW:
+ activeRoom = getHoveredRoom();;
+ break;
+
+ case ADD:
+ if(vertexOk(hoveredVertex))
+ addVertex(hoveredVertex);
+ }
+
+ window->update();
+ }
+}
+
+bool EditManager::vertexOk(const Vertex& v) const {
+ Line l;
+
+ for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
+ if(room->contains(v)) return false;
+ }
+
+ if(!(activeRoom && !activeRoom->empty()))
+ return true;
+
+ l.setVertex1(activeRoom->back());
+ l.setVertex2(v);
+
+ return lineOk(l);
+}
+
+bool EditManager::polygonOk(const Polygon& polygon) const {
+ Line l, l2;
+
+ if(polygon.empty()) return false;
+
+ for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
+ if(room->empty()) continue;
+
+ if(room->contains(polygon.front()))
+ return false;
+
+ if(polygon.contains(room->front()))
+ return false;
+ }
+
+ if(polygon.size() == 1)
+ return true;
+
+ if(!polygon.isSimple())
+ return false;
+
+ for(Polygon::const_iterator it = polygon.begin(); it != polygon.end(); it++) {
+ Polygon::const_iterator it2 = it+1;
+ if(it2 == polygon.end()) it2 = polygon.begin();
+
+ l.setVertex1(*it);
+ l.setVertex2(*it2);
+
+ for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
+ if(room->intersects(l))
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/EditManager.h b/EditManager.h
index a1561eb..6b52389 100644
--- a/EditManager.h
+++ b/EditManager.h
@@ -2,6 +2,7 @@
#define EDITMANAGER_H_
#include "Room.h"
+#include "IdManager.h"
class Window;
@@ -16,9 +17,19 @@ class EditManager {
private:
Mode mode;
+ IdManager idManager;
+
Window *window;
- //Room newRoom;
+ Room newRoom;
+ Room *activeRoom;
+
+ Room *hoveredRoom;
+
+ Vertex hoveredVertex;
+ bool hasHoveredVertex;
+
+ bool lineOk(const Line& l) const;
public:
EditManager(Window *window);
@@ -28,9 +39,25 @@ class EditManager {
void addVertex(const Vertex &v);
- Mode getMode() {
+ Mode getMode() const {
return mode;
}
+
+ Room* getActiveRoom() {
+ return activeRoom;
+ }
+
+ Room* getHoveredRoom() {
+ return hoveredRoom;
+ }
+
+ Vertex* getHoveredVertex();
+ void setHoveredVertex(Vertex *v);
+
+ void buttonPress(unsigned int button);
+
+ bool vertexOk(const Vertex& v) const;
+ bool polygonOk(const Polygon& polygon) const;
};
#endif /*EDITMANAGER_H_*/
diff --git a/Makefile.am b/Makefile.am
index 2510265..a95c2ae 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
bin_PROGRAMS = zoomedit
-zoomedit_SOURCES = zoomedit.cpp ui.cpp draw.cpp edit.cpp Vertex.cpp \
+zoomedit_SOURCES = zoomedit.cpp ui.cpp draw.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 \
diff --git a/Makefile.in b/Makefile.in
index 785f3aa..db8f2e6 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -50,11 +50,10 @@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \
zoomedit-ui.$(OBJEXT) zoomedit-draw.$(OBJEXT) \
- zoomedit-edit.$(OBJEXT) zoomedit-Vertex.$(OBJEXT) \
- zoomedit-Line.$(OBJEXT) zoomedit-Polygon.$(OBJEXT) \
- zoomedit-Rectangle.$(OBJEXT) zoomedit-Room.$(OBJEXT) \
- zoomedit-Triangle.$(OBJEXT) zoomedit-IdManager.$(OBJEXT) \
- zoomedit-WindowManager.$(OBJEXT) \
+ zoomedit-Vertex.$(OBJEXT) zoomedit-Line.$(OBJEXT) \
+ zoomedit-Polygon.$(OBJEXT) zoomedit-Rectangle.$(OBJEXT) \
+ zoomedit-Room.$(OBJEXT) zoomedit-Triangle.$(OBJEXT) \
+ zoomedit-IdManager.$(OBJEXT) zoomedit-WindowManager.$(OBJEXT) \
zoomedit-SidebarManager.$(OBJEXT) zoomedit-Window.$(OBJEXT) \
zoomedit-SidebarView.$(OBJEXT) zoomedit-SidebarAdd.$(OBJEXT) \
zoomedit-Drawer.$(OBJEXT) zoomedit-EditManager.$(OBJEXT)
@@ -177,7 +176,7 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-zoomedit_SOURCES = zoomedit.cpp ui.cpp draw.cpp edit.cpp Vertex.cpp \
+zoomedit_SOURCES = zoomedit.cpp ui.cpp draw.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 \
@@ -288,7 +287,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Window.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-WindowManager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-draw.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-edit.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-ui.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-zoomedit.Po@am__quote@
@@ -348,20 +346,6 @@ zoomedit-draw.obj: draw.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-draw.obj `if test -f 'draw.cpp'; then $(CYGPATH_W) 'draw.cpp'; else $(CYGPATH_W) '$(srcdir)/draw.cpp'; fi`
-zoomedit-edit.o: edit.cpp
-@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-edit.o -MD -MP -MF $(DEPDIR)/zoomedit-edit.Tpo -c -o zoomedit-edit.o `test -f 'edit.cpp' || echo '$(srcdir)/'`edit.cpp
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-edit.Tpo $(DEPDIR)/zoomedit-edit.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='edit.cpp' object='zoomedit-edit.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-edit.o `test -f 'edit.cpp' || echo '$(srcdir)/'`edit.cpp
-
-zoomedit-edit.obj: edit.cpp
-@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-edit.obj -MD -MP -MF $(DEPDIR)/zoomedit-edit.Tpo -c -o zoomedit-edit.obj `if test -f 'edit.cpp'; then $(CYGPATH_W) 'edit.cpp'; else $(CYGPATH_W) '$(srcdir)/edit.cpp'; fi`
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-edit.Tpo $(DEPDIR)/zoomedit-edit.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='edit.cpp' object='zoomedit-edit.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-edit.obj `if test -f 'edit.cpp'; then $(CYGPATH_W) 'edit.cpp'; else $(CYGPATH_W) '$(srcdir)/edit.cpp'; fi`
-
zoomedit-Vertex.o: Vertex.cpp
@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Vertex.o -MD -MP -MF $(DEPDIR)/zoomedit-Vertex.Tpo -c -o zoomedit-Vertex.o `test -f 'Vertex.cpp' || echo '$(srcdir)/'`Vertex.cpp
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Vertex.Tpo $(DEPDIR)/zoomedit-Vertex.Po
diff --git a/SidebarAdd.cpp b/SidebarAdd.cpp
index 78509e0..57de3ee 100644
--- a/SidebarAdd.cpp
+++ b/SidebarAdd.cpp
@@ -1,5 +1,4 @@
#include "SidebarAdd.h"
-#include "edit.h"
void SidebarAdd::buttonClicked(GtkButton *button, SidebarAdd *sidebar) {
@@ -33,10 +32,10 @@ GtkWidget* SidebarAdd::getWidget() {
}
void SidebarAdd::update() {
- if(!getActiveRoom())
+ if(!editor->getActiveRoom())
return;
- if(getActiveRoom()->size() > 2 && isPolygonOk(getActiveRoom()))
+ 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/SidebarView.cpp b/SidebarView.cpp
index 82d4713..04c6dd0 100644
--- a/SidebarView.cpp
+++ b/SidebarView.cpp
@@ -1,5 +1,4 @@
#include "SidebarView.h"
-#include "edit.h"
void SidebarView::buttonClicked(GtkButton *button, SidebarView *sidebar) {
@@ -66,15 +65,15 @@ GtkWidget* SidebarView::getWidget() {
}
void SidebarView::update() {
- if(getActiveRoom()) {
- gtk_entry_set_text(GTK_ENTRY(entryName), getActiveRoom()->getName().c_str());
+ if(editor->getActiveRoom()) {
+ gtk_entry_set_text(GTK_ENTRY(entryName), editor->getActiveRoom()->getName().c_str());
gtk_widget_set_sensitive(entryName, TRUE);
- gchar *string = g_strdup_printf("%.2f", getActiveRoom()->area());
+ gchar *string = g_strdup_printf("%.2f", editor->getActiveRoom()->area());
gtk_label_set_text(GTK_LABEL(labelArea), string);
g_free(string);
- string = g_strdup_printf("%.2f", getActiveRoom()->perimeter());
+ string = g_strdup_printf("%.2f", editor->getActiveRoom()->perimeter());
gtk_label_set_text(GTK_LABEL(labelPerimeter), string);
g_free(string);
}
diff --git a/Window.cpp b/Window.cpp
index 7e4dd63..74cfdb2 100644
--- a/Window.cpp
+++ b/Window.cpp
@@ -1,7 +1,6 @@
#include "Window.h"
#include "WindowManager.h"
#include "ui.h"
-#include "edit.h"
gboolean Window::deleteEvent(GtkWidget *widget, GdkEvent *event, Window *window) {
@@ -16,7 +15,6 @@ Window::Window(GdkGLConfig *glconfig, WindowManager *manager)
: editor(this), drawer(this, glconfig), sidebar(&editor)
{
this->manager = manager;
- setLevel(&level);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
diff --git a/draw.cpp b/draw.cpp
index 2f42005..7e36d99 100644
--- a/draw.cpp
+++ b/draw.cpp
@@ -1,5 +1,4 @@
#include "draw.h"
-#include "edit.h"
#include "Rectangle.h"
#include <math.h>
#include <gtk/gtk.h>
@@ -97,17 +96,17 @@ static void drawPolygon(const Polygon &polygon, bool close) {
glEnd();
}
-gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
+gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, EditManager *editor) {
GdkGLContext *context = gtk_widget_get_gl_context(widget);
GdkGLDrawable *drawable = gtk_widget_get_gl_drawable(widget);
Vertex v1(0, 0), v2(widget->allocation.width, widget->allocation.height);
Rectangle rect;
- if(getLevel() == NULL) return FALSE;
+ if(level == NULL) return FALSE;
- viewToImage(&v1);
- viewToImage(&v2);
+ viewToImage(level, &v1);
+ viewToImage(level, &v2);
rect.setVertex1(v1);
rect.setVertex2(v2);
@@ -122,26 +121,26 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
glLineWidth(1.0f);
- glTranslatef(getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate, 0);
+ glTranslatef(getImageWidth(level)/2-xTranslate, getImageHeight(level)/2-yTranslate, 0);
glScalef(scale, scale, 1);
drawGrid(rect);
- for(Level::const_iterator room = getLevel()->begin(); room != getLevel()->end(); room++) {
- if(&*room == getActiveRoom() && getEditMode() == EDIT_MODE_ADD) continue;
+ for(Level::const_iterator room = level->begin(); room != level->end(); room++) {
+ if(&*room == editor->getActiveRoom() && editor->getMode() == EditManager::ADD) continue;
- if(&*room == getActiveRoom())
+ if(&*room == editor->getActiveRoom())
glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
else
glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
fillPolygon(*room);
- if(&*room == getActiveRoom()) {
+ if(&*room == editor->getActiveRoom()) {
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(&*room == getHoveredRoom() && getEditMode() != EDIT_MODE_ADD) {
+ else if(&*room == editor->getHoveredRoom() && editor->getMode() == EditManager::VIEW) {
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
glLineWidth(2.0f);
}
@@ -153,26 +152,26 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
drawPolygon(*room, true);
}
- if(getEditMode() == EDIT_MODE_ADD) {
- if(isPolygonOk(getActiveRoom()))
+ if(editor->getMode() == EditManager::ADD) {
+ if(editor->polygonOk(*editor->getActiveRoom()))
glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
else
glColor4f(1.0f, 0.3f, 0.3f, 0.2f);
- fillPolygon(*getActiveRoom());
+ fillPolygon(*editor->getActiveRoom());
glLineWidth(2.0f);
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
- drawPolygon(*getActiveRoom(), false);
+ drawPolygon(*editor->getActiveRoom(), false);
- if(!getActiveRoom()->empty() && getHoveredVertex()) {
- if(!isVertexOk(getHoveredVertex()))
+ if(!editor->getActiveRoom()->empty() && editor->getHoveredVertex()) {
+ if(!editor->vertexOk(*editor->getHoveredVertex()))
glColor4f(1.0f, 0.3f, 0.3f, 0.7f);
glBegin(GL_LINES);
- glVertex2d(getActiveRoom()->back().getX(), getActiveRoom()->back().getY());
- glVertex2d(getHoveredVertex()->getX(), getHoveredVertex()->getY());
+ glVertex2d(editor->getActiveRoom()->back().getX(), editor->getActiveRoom()->back().getY());
+ glVertex2d(editor->getHoveredVertex()->getX(), editor->getHoveredVertex()->getY());
glEnd();
}
@@ -196,22 +195,22 @@ void setScale(float s) {
scale = s;
}
-void imageToView(Vertex *v) {
- v->setX(v->getX()*scale+getImageWidth()/2-xTranslate);
- v->setY(v->getY()*scale+getImageHeight()/2-yTranslate);
+void imageToView(Level *level, Vertex *v) {
+ v->setX(v->getX()*scale+getImageWidth(level)/2-xTranslate);
+ v->setY(v->getY()*scale+getImageHeight(level)/2-yTranslate);
}
-void viewToImage(Vertex *v) {
- v->setX((v->getX()-getImageWidth()/2+xTranslate)/scale);
- v->setY((v->getY()-getImageHeight()/2+yTranslate)/scale);
+void viewToImage(Level *level, Vertex *v) {
+ v->setX((v->getX()-getImageWidth(level)/2+xTranslate)/scale);
+ v->setY((v->getY()-getImageHeight(level)/2+yTranslate)/scale);
}
-float getImageWidth() {
+float getImageWidth(Level *level) {
float min = 0.0, max = 0.0;
- if(getLevel()) {
- for(Level::iterator room = getLevel()->begin(); room != getLevel()->end(); room++) {
+ if(level) {
+ for(Level::iterator room = level->begin(); room != level->end(); room++) {
for(Room::iterator v = room->begin(); v != room->end(); v++) {
min = fminf(min, v->getX());
max = fmaxf(max, v->getX());
@@ -222,12 +221,12 @@ float getImageWidth() {
return (max-min+10)*scale;
}
-float getImageHeight() {
+float getImageHeight(Level *level) {
float min = 0.0, max = 0.0;
- if(getLevel()) {
- for(Level::iterator room = getLevel()->begin(); room != getLevel()->end(); room++) {
+ if(level) {
+ for(Level::iterator room = level->begin(); room != level->end(); room++) {
for(Room::iterator v = room->begin(); v != room->end(); v++) {
min = fminf(min, v->getY());
max = fmaxf(max, v->getY());
diff --git a/draw.h b/draw.h
index 90ebc00..ddffc5f 100644
--- a/draw.h
+++ b/draw.h
@@ -3,18 +3,20 @@
#include <gtk/gtk.h>
#include "Vertex.h"
+#include "EditManager.h"
+#include "Level.h"
-gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data);
+gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, EditManager *editor);
float getScale();
void setScale(float s);
-void imageToView(Vertex *v);
-void viewToImage(Vertex *v);
+void imageToView(Level *level, Vertex *v);
+void viewToImage(Level *level, Vertex *v);
-float getImageWidth();
-float getImageHeight();
+float getImageWidth(Level *level);
+float getImageHeight(Level *level);
float getXTranslate();
void setXTranslate(float x);
diff --git a/edit.cpp b/edit.cpp
deleted file mode 100644
index 487cf4f..0000000
--- a/edit.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-#include "edit.h"
-
-
-static int editMode = EDIT_MODE_VIEW;
-
-static Level *level = NULL;
-
-static Room *activeRoom = NULL;
-static Room *hoveredRoom = NULL;
-
-static Room addRoom;
-
-static Vertex hoveredVertex;
-static int hasHoveredVertex = 0;
-
-static IdManager idManager;
-
-int getEditMode() {
- return editMode;
-}
-
-Level *getLevel() {
- return level;
-}
-
-void setLevel(Level *l) {
- level = l;
-}
-
-Room *getActiveRoom() {
- return activeRoom;
-}
-
-void setActiveRoom(Room *room) {
- activeRoom = room;
-
- if(room == NULL) {
- editMode = EDIT_MODE_VIEW;
- }
- else if(editMode == EDIT_MODE_VIEW) {
- editMode = EDIT_MODE_SELECTED;
- }
-}
-
-Vertex *getHoveredVertex() {
- if(hasHoveredVertex) return &hoveredVertex;
- else return NULL;
-}
-
-void setHoveredVertex(Vertex *v) {
- if(v) {
- hasHoveredVertex = 1;
- hoveredVertex = *v;
-
- hoveredRoom = NULL;
-
- for(Level::iterator room = level->begin(); room != level->end(); room++) {
- if(room->contains(*v)) {
- hoveredRoom = &*room;
- break;
- }
- }
- }
- else {
- hasHoveredVertex = 0;
- hoveredRoom = NULL;
- }
-}
-
-void startAddMode() {
- addRoom = Room(idManager.generate("room"));
- activeRoom = &addRoom;
-
- editMode = EDIT_MODE_ADD;
-}
-
-void endAddMode() {
- editMode = activeRoom ? EDIT_MODE_SELECTED : EDIT_MODE_VIEW;
-}
-
-Room *getHoveredRoom() {
- return hoveredRoom;
-}
-
-IdManager *getIdManager() {
- return &idManager;
-}
-
-static bool isLineOk(Line *l) {
- Line l2;
-
-
- if(activeRoom) {
- for(size_t i = 0; i+2 < activeRoom->size(); i++) {
- l2.setVertex1(activeRoom->at(i));
- l2.setVertex2(activeRoom->at(i+1));
-
- if(l->intersects(l2, NULL) == INTERSECTION_SEGMENT_SEGMENT) return false;
- }
-
- if(activeRoom->size() > 1) {
- l2.setVertex1(activeRoom->at(activeRoom->size()-2));
- l2.setVertex2(activeRoom->back());
- if(l2.contains(l->getVertex2())) return false;
- }
- }
-
- for(Level::iterator room = level->begin(); room != level->end(); room++) {
- if(room->intersects(*l))
- return false;
- }
-
- return true;
-}
-
-bool isVertexOk(Vertex *v) {
- Line l;
-
- for(Level::iterator room = level->begin(); room != level->end(); room++) {
- if(room->contains(*v)) return false;
- }
-
- if(!(getActiveRoom() && !getActiveRoom()->empty()))
- return true;
-
- l.setVertex1(getActiveRoom()->back());
- l.setVertex2(*v);
-
- return isLineOk(&l);
-}
-
-
-
-bool isPolygonOk(Polygon *polygon) {
- Line l, l2;
-
- if(polygon->empty()) return false;
-
- for(Level::iterator room = level->begin(); room != level->end(); room++) {
- if(room->empty()) continue;
-
- if(room->contains(polygon->front()))
- return false;
-
- if(polygon->contains(room->front()))
- return false;
- }
-
- if(polygon->size() == 1)
- return true;
-
- if(!polygon->isSimple())
- return false;
-
- for(Polygon::const_iterator it = polygon->begin(); it != polygon->end(); it++) {
- Polygon::const_iterator it2 = it+1;
- if(it2 == polygon->end()) it2 = polygon->begin();
-
- l.setVertex1(*it);
- l.setVertex2(*it2);
-
- for(Level::iterator room = level->begin(); room != level->end(); room++) {
- if(room->intersects(l))
- return false;
- }
- }
-
- return true;
-}
diff --git a/edit.h b/edit.h
deleted file mode 100644
index 92cc761..0000000
--- a/edit.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef EDIT_H_
-#define EDIT_H_
-
-#include "Level.h"
-#include "IdManager.h"
-
-#define EDIT_MODE_VIEW 0
-#define EDIT_MODE_SELECTED 1
-#define EDIT_MODE_ADD 2
-
-int getEditMode();
-
-Level *getLevel();
-void setLevel(Level *l);
-
-Room *getActiveRoom();
-void setActiveRoom(Room *room);
-
-void startAddMode();
-void endAddMode();
-
-Room *getHoveredRoom();
-
-Vertex *getHoveredVertex();
-void setHoveredVertex(Vertex *v);
-
-IdManager *getIdManager();
-
-bool isVertexOk(Vertex *v);
-bool isPolygonOk(Polygon *polygon);
-
-#endif /*EDIT_H_*/
diff --git a/zoomedit.cpp b/zoomedit.cpp
index 682127c..e72aa55 100644
--- a/zoomedit.cpp
+++ b/zoomedit.cpp
@@ -3,7 +3,6 @@
#include <stdlib.h>
#include "Level.h"
#include "WindowManager.h"
-#include "edit.h"
int main(int argc, char *argv[]) {