summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Drawer.cpp42
-rw-r--r--Drawer.h21
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.in26
-rw-r--r--Renderer.cpp148
-rw-r--r--Renderer.h26
-rw-r--r--draw.cpp181
-rw-r--r--draw.h12
8 files changed, 236 insertions, 222 deletions
diff --git a/Drawer.cpp b/Drawer.cpp
index 1a80997..5b6a6d5 100644
--- a/Drawer.cpp
+++ b/Drawer.cpp
@@ -1,6 +1,5 @@
#include "Drawer.h"
#include "Window.h"
-#include "draw.h"
#include <GL/gl.h>
#include <math.h>
@@ -33,7 +32,7 @@ gboolean Drawer::eventHandler(GtkWidget *widget, GdkEvent *event, Drawer *drawer
return TRUE;
case GDK_EXPOSE:
- drawTopView(widget, &event->expose, drawer->window, drawer);
+ drawer->render();
return TRUE;
case GDK_MOTION_NOTIFY:
@@ -147,7 +146,36 @@ void Drawer::updateHoveredPoint(float x, float y) {
window->getEditManager().setHoveredVertex(&v);
}
-Drawer::Drawer(Window *window, GdkGLConfig *glconfig) {
+void Drawer::render() {
+ GdkGLContext *context = gtk_widget_get_gl_context(drawingArea);
+ GdkGLDrawable *drawable = gtk_widget_get_gl_drawable(drawingArea);
+
+ Rectangle rect(0, 0, drawingArea->allocation.width, drawingArea->allocation.height);
+
+ viewToImage(&rect.getVertex1());
+ viewToImage(&rect.getVertex2());
+
+ if(!gdk_gl_drawable_gl_begin(drawable, context))
+ return;
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ glTranslatef(getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate, 0);
+ glScalef(scale, scale, 1);
+
+ renderer.render(window->getLevel(), rect, scale);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ gdk_gl_drawable_swap_buffers(drawable);
+ gdk_gl_drawable_gl_end(drawable);
+}
+
+Drawer::Drawer(Window *window, GdkGLConfig *glconfig)
+ : renderer(&window->getEditManager())
+{
this->window = window;
zoomExp = 0;
scale = 100;
@@ -196,17 +224,17 @@ void Drawer::zoom(int zoom, float x, float y) {
updateScrollbars(x, y);
}
-void Drawer::imageToView(Vertex *v) {
+void Drawer::imageToView(Vertex *v) const {
v->setX(v->getX()*scale+getImageWidth()/2-xTranslate);
v->setY(v->getY()*scale+getImageHeight()/2-yTranslate);
}
-void Drawer::viewToImage(Vertex *v) {
+void Drawer::viewToImage(Vertex *v) const {
v->setX((v->getX()-getImageWidth()/2+xTranslate)/scale);
v->setY((v->getY()-getImageHeight()/2+yTranslate)/scale);
}
-float Drawer::getImageWidth() {
+float Drawer::getImageWidth() const {
float min = 0, max = 0;
for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
@@ -219,7 +247,7 @@ float Drawer::getImageWidth() {
return (max-min+10)*scale;
}
-float Drawer::getImageHeight() {
+float Drawer::getImageHeight() const {
float min = 0, max = 0;
for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
diff --git a/Drawer.h b/Drawer.h
index 8dbac47..bfebe10 100644
--- a/Drawer.h
+++ b/Drawer.h
@@ -4,6 +4,7 @@
#include <gtk/gtk.h>
#include <gtk/gtkgl.h>
#include "Vertex.h"
+#include "Renderer.h"
class Window;
@@ -15,6 +16,8 @@ class Drawer {
GtkAdjustment *hAdjustment, *vAdjustment;
int zoomExp;
+ Renderer renderer;
+
Window *window;
float scale;
@@ -30,6 +33,8 @@ class Drawer {
void updateHoveredPoint(float x, float y);
+ void render();
+
gint getWidth() const {
return drawingArea->allocation.width;
}
@@ -48,25 +53,25 @@ class Drawer {
void zoom(int zoom, float x = 0.5f, float y = 0.5f);
- void imageToView(Vertex *v);
- void viewToImage(Vertex *v);
+ void imageToView(Vertex *v) const;
+ void viewToImage(Vertex *v) const;
- float getImageWidth();
- float getImageHeight();
+ float getImageWidth() const;
+ float getImageHeight() const;
- float getXTranslate() {
+ float getXTranslate() const {
return xTranslate;
}
- float getYTranslate() {
+ float getYTranslate() const {
return yTranslate;
}
- float getScale() {
+ float getScale() const {
return scale;
}
- GtkWidget *getWidget() {
+ GtkWidget *getWidget() const {
return drawer;
}
diff --git a/Makefile.am b/Makefile.am
index e1bfcce..25ebf7c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
bin_PROGRAMS = zoomedit
-zoomedit_SOURCES = zoomedit.cpp UIManager.cpp draw.cpp Vertex.cpp \
+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 \
diff --git a/Makefile.in b/Makefile.in
index e3f4308..4b1ccda 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -49,7 +49,7 @@ am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \
- zoomedit-UIManager.$(OBJEXT) zoomedit-draw.$(OBJEXT) \
+ zoomedit-UIManager.$(OBJEXT) zoomedit-Renderer.$(OBJEXT) \
zoomedit-Vertex.$(OBJEXT) zoomedit-Line.$(OBJEXT) \
zoomedit-Polygon.$(OBJEXT) zoomedit-Rectangle.$(OBJEXT) \
zoomedit-Room.$(OBJEXT) zoomedit-Triangle.$(OBJEXT) \
@@ -176,7 +176,7 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-zoomedit_SOURCES = zoomedit.cpp UIManager.cpp draw.cpp Vertex.cpp \
+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 \
@@ -278,6 +278,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Line.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Polygon.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Rectangle.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Renderer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Room.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarAdd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarManager.Po@am__quote@
@@ -287,7 +288,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Vertex.Po@am__quote@
@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-zoomedit.Po@am__quote@
.cpp.o:
@@ -332,19 +332,19 @@ zoomedit-UIManager.obj: UIManager.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-UIManager.obj `if test -f 'UIManager.cpp'; then $(CYGPATH_W) 'UIManager.cpp'; else $(CYGPATH_W) '$(srcdir)/UIManager.cpp'; fi`
-zoomedit-draw.o: draw.cpp
-@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-draw.o -MD -MP -MF $(DEPDIR)/zoomedit-draw.Tpo -c -o zoomedit-draw.o `test -f 'draw.cpp' || echo '$(srcdir)/'`draw.cpp
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-draw.Tpo $(DEPDIR)/zoomedit-draw.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='draw.cpp' object='zoomedit-draw.o' libtool=no @AMDEPBACKSLASH@
+zoomedit-Renderer.o: Renderer.cpp
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Renderer.o -MD -MP -MF $(DEPDIR)/zoomedit-Renderer.Tpo -c -o zoomedit-Renderer.o `test -f 'Renderer.cpp' || echo '$(srcdir)/'`Renderer.cpp
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Renderer.Tpo $(DEPDIR)/zoomedit-Renderer.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Renderer.cpp' object='zoomedit-Renderer.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-draw.o `test -f 'draw.cpp' || echo '$(srcdir)/'`draw.cpp
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-Renderer.o `test -f 'Renderer.cpp' || echo '$(srcdir)/'`Renderer.cpp
-zoomedit-draw.obj: draw.cpp
-@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-draw.obj -MD -MP -MF $(DEPDIR)/zoomedit-draw.Tpo -c -o zoomedit-draw.obj `if test -f 'draw.cpp'; then $(CYGPATH_W) 'draw.cpp'; else $(CYGPATH_W) '$(srcdir)/draw.cpp'; fi`
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-draw.Tpo $(DEPDIR)/zoomedit-draw.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='draw.cpp' object='zoomedit-draw.obj' libtool=no @AMDEPBACKSLASH@
+zoomedit-Renderer.obj: Renderer.cpp
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Renderer.obj -MD -MP -MF $(DEPDIR)/zoomedit-Renderer.Tpo -c -o zoomedit-Renderer.obj `if test -f 'Renderer.cpp'; then $(CYGPATH_W) 'Renderer.cpp'; else $(CYGPATH_W) '$(srcdir)/Renderer.cpp'; fi`
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Renderer.Tpo $(DEPDIR)/zoomedit-Renderer.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Renderer.cpp' object='zoomedit-Renderer.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-draw.obj `if test -f 'draw.cpp'; then $(CYGPATH_W) 'draw.cpp'; else $(CYGPATH_W) '$(srcdir)/draw.cpp'; fi`
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-Renderer.obj `if test -f 'Renderer.cpp'; then $(CYGPATH_W) 'Renderer.cpp'; else $(CYGPATH_W) '$(srcdir)/Renderer.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
diff --git a/Renderer.cpp b/Renderer.cpp
new file mode 100644
index 0000000..9365589
--- /dev/null
+++ b/Renderer.cpp
@@ -0,0 +1,148 @@
+#include "Renderer.h"
+#include <GL/gl.h>
+
+
+void Renderer::drawGrid(const Rectangle &rect, float scale) {
+ float depth = log10f(scale)-0.75f;
+ float depth2 = floorf(depth);
+ float step = powf(0.1f, depth2);
+ float f;
+ int i;
+ //gchar *string;
+ float x1 = rect.getVertex1().getX(), y1 = rect.getVertex1().getY();
+ float x2 = rect.getVertex2().getX(), y2 = rect.getVertex2().getY();
+
+
+ glBegin(GL_LINES);
+ //cairo_set_font_size(cr, 10.0/scale);
+
+ for(i = 0; 0.4f*(depth-depth2+i-1) < 0.5f; i++) {
+ f = fminf(0.4f*(depth-depth2+i), 0.5f);
+ glColor3f(f, f, f);
+
+ for(f = x1 - fmodf(x1, step) - step; f <= x2; f+=step) {
+ glVertex2f(f, y1);
+ glVertex2f(f, y2);
+
+ /*if(step > 0.005) {
+ if(step > 0.5)
+ string = g_strdup_printf("%i", (int)rint(d));
+ else
+ string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
+
+ cairo_move_to(cr, d+1/scale, y1+11/scale);
+ cairo_show_text(cr, string);
+
+ g_free(string);
+ }*/
+ }
+
+ for(f = y1 - fmodf(y1, step) - step; f <= y2; f+=step) {
+ glVertex2f(x1, f);
+ glVertex2f(x2, f);
+
+ /*if(step > 0.005) {
+ if(step > 0.5)
+ string = g_strdup_printf("%i", (int)rint(d));
+ else
+ string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
+
+ cairo_move_to(cr, x1+3/scale, d+11/scale);
+ cairo_show_text(cr, string);
+
+ g_free(string);
+ }*/
+ }
+
+ step *= 10;
+ }
+
+ glEnd();
+}
+
+void Renderer::fillPolygon(const Polygon &polygon) {
+ std::vector<Triangle> triangles;
+
+ polygon.triangulate(triangles);
+
+ glBegin(GL_TRIANGLES);
+
+ for(std::vector<Triangle>::iterator t = triangles.begin(); t != triangles.end(); t++) {
+ glVertex2f(t->getVertexA().getX(), t->getVertexA().getY());
+ glVertex2f(t->getVertexB().getX(), t->getVertexB().getY());
+ glVertex2f(t->getVertexC().getX(), t->getVertexC().getY());
+ }
+
+ glEnd();
+}
+
+void Renderer::drawPolygon(const Polygon &polygon, bool close) {
+ glBegin(GL_LINE_STRIP);
+
+ for(Polygon::const_iterator vertex = polygon.begin(); vertex != polygon.end(); vertex++)
+ glVertex2d(vertex->getX(), vertex->getY());
+
+ if(close)
+ glVertex2d(polygon.front().getX(), polygon.front().getY());
+
+ glEnd();
+}
+
+void Renderer::render(const Level &level, const Rectangle &rect, float scale) {
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glLineWidth(1.0f);
+
+ drawGrid(rect, scale);
+
+ for(Level::const_iterator room = level.begin(); room != level.end(); room++) {
+ if(&*room == editManager->getActiveRoom() && editManager->getMode() == EditManager::ADD) continue;
+
+ if(&*room == editManager->getActiveRoom())
+ glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
+ else
+ glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
+
+ fillPolygon(*room);
+
+ if(&*room == editManager->getActiveRoom()) {
+ glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
+ glLineWidth(2.0f);
+ }
+ else if(&*room == editManager->getHoveredRoom() && editManager->getMode() == EditManager::VIEW) {
+ glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
+ glLineWidth(2.0f);
+ }
+ else {
+ glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
+ glLineWidth(1.0f);
+ }
+
+ drawPolygon(*room, true);
+ }
+
+ if(editManager->getMode() == EditManager::ADD) {
+ if(editManager->polygonOk(*editManager->getActiveRoom()))
+ glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
+ else
+ glColor4f(1.0f, 0.3f, 0.3f, 0.2f);
+
+ fillPolygon(*editManager->getActiveRoom());
+
+ glLineWidth(2.0f);
+ glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
+ drawPolygon(*editManager->getActiveRoom(), false);
+
+ if(!editManager->getActiveRoom()->empty() && editManager->getHoveredVertex()) {
+ if(!editManager->vertexOk(*editManager->getHoveredVertex()))
+ glColor4f(1.0f, 0.3f, 0.3f, 0.7f);
+
+ glBegin(GL_LINES);
+
+ glVertex2d(editManager->getActiveRoom()->back().getX(), editManager->getActiveRoom()->back().getY());
+ glVertex2d(editManager->getHoveredVertex()->getX(), editManager->getHoveredVertex()->getY());
+
+ glEnd();
+ }
+ }
+}
diff --git a/Renderer.h b/Renderer.h
new file mode 100644
index 0000000..db8a927
--- /dev/null
+++ b/Renderer.h
@@ -0,0 +1,26 @@
+#ifndef RENDERER_H_
+#define RENDERER_H_
+
+#include "Rectangle.h"
+#include "Polygon.h"
+#include "EditManager.h"
+#include "Level.h"
+
+
+class Renderer {
+ private:
+ EditManager *editManager;
+
+ void drawGrid(const Rectangle &rect, float scale);
+ void fillPolygon(const Polygon &polygon);
+ void drawPolygon(const Polygon &polygon, bool close);
+
+ public:
+ Renderer(EditManager *editManager) {
+ this->editManager = editManager;
+ }
+
+ void render(const Level &level, const Rectangle &rect, float scale);
+};
+
+#endif /*RENDERER_H_*/
diff --git a/draw.cpp b/draw.cpp
deleted file mode 100644
index 708462f..0000000
--- a/draw.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-#include "draw.h"
-#include "Rectangle.h"
-#include <math.h>
-#include <gtk/gtk.h>
-#include <gtk/gtkgl.h>
-#include <GL/gl.h>
-
-
-static void drawGrid(const Rectangle &rect, float scale) {
- float depth = log10f(scale)-0.75f;
- float depth2 = floorf(depth);
- float step = powf(0.1f, depth2);
- float f;
- int i;
- //gchar *string;
- float x1 = rect.getVertex1().getX(), y1 = rect.getVertex1().getY();
- float x2 = rect.getVertex2().getX(), y2 = rect.getVertex2().getY();
-
-
- glBegin(GL_LINES);
- //cairo_set_font_size(cr, 10.0/scale);
-
- for(i = 0; 0.4f*(depth-depth2+i-1) < 0.5f; i++) {
- f = fminf(0.4f*(depth-depth2+i), 0.5f);
- glColor3f(f, f, f);
-
- for(f = x1 - fmodf(x1, step) - step; f <= x2; f+=step) {
- glVertex2f(f, y1);
- glVertex2f(f, y2);
-
- /*if(step > 0.005) {
- if(step > 0.5)
- string = g_strdup_printf("%i", (int)rint(d));
- else
- string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
-
- cairo_move_to(cr, d+1/scale, y1+11/scale);
- cairo_show_text(cr, string);
-
- g_free(string);
- }*/
- }
-
- for(f = y1 - fmodf(y1, step) - step; f <= y2; f+=step) {
- glVertex2f(x1, f);
- glVertex2f(x2, f);
-
- /*if(step > 0.005) {
- if(step > 0.5)
- string = g_strdup_printf("%i", (int)rint(d));
- else
- string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
-
- cairo_move_to(cr, x1+3/scale, d+11/scale);
- cairo_show_text(cr, string);
-
- g_free(string);
- }*/
- }
-
- step *= 10;
- }
-
- glEnd();
-}
-
-static void fillPolygon(const Polygon &polygon) {
- std::vector<Triangle> triangles;
-
- polygon.triangulate(triangles);
-
- glBegin(GL_TRIANGLES);
-
- for(std::vector<Triangle>::iterator t = triangles.begin(); t != triangles.end(); t++) {
- glVertex2f(t->getVertexA().getX(), t->getVertexA().getY());
- glVertex2f(t->getVertexB().getX(), t->getVertexB().getY());
- glVertex2f(t->getVertexC().getX(), t->getVertexC().getY());
- }
-
- glEnd();
-}
-
-static void drawPolygon(const Polygon &polygon, bool close) {
- glBegin(GL_LINE_STRIP);
-
- for(Polygon::const_iterator vertex = polygon.begin(); vertex != polygon.end(); vertex++)
- glVertex2d(vertex->getX(), vertex->getY());
-
- if(close)
- glVertex2d(polygon.front().getX(), polygon.front().getY());
-
- glEnd();
-}
-
-gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Window *window, Drawer *drawer) {
- 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;
-
-
- drawer->viewToImage(&v1);
- drawer->viewToImage(&v2);
-
- rect.setVertex1(v1);
- rect.setVertex2(v2);
-
- if(!gdk_gl_drawable_gl_begin(drawable, context))
- return FALSE;
-
- glClear(GL_COLOR_BUFFER_BIT);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-
- glLineWidth(1.0f);
-
- glTranslatef(drawer->getImageWidth()/2-drawer->getXTranslate(), drawer->getImageHeight()/2-drawer->getYTranslate(), 0);
- glScalef(drawer->getScale(), drawer->getScale(), 1);
-
- drawGrid(rect, drawer->getScale());
-
- for(Level::const_iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
- if(&*room == window->getEditManager().getActiveRoom() && window->getEditManager().getMode() == EditManager::ADD) continue;
-
- if(&*room == window->getEditManager().getActiveRoom())
- glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
- else
- glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
-
- fillPolygon(*room);
-
- if(&*room == window->getEditManager().getActiveRoom()) {
- glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
- glLineWidth(2.0f);
- }
- else if(&*room == window->getEditManager().getHoveredRoom() && window->getEditManager().getMode() == EditManager::VIEW) {
- glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
- glLineWidth(2.0f);
- }
- else {
- glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
- glLineWidth(1.0f);
- }
-
- drawPolygon(*room, true);
- }
-
- if(window->getEditManager().getMode() == EditManager::ADD) {
- if(window->getEditManager().polygonOk(*window->getEditManager().getActiveRoom()))
- glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
- else
- glColor4f(1.0f, 0.3f, 0.3f, 0.2f);
-
- fillPolygon(*window->getEditManager().getActiveRoom());
-
- glLineWidth(2.0f);
- glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
- drawPolygon(*window->getEditManager().getActiveRoom(), false);
-
- if(!window->getEditManager().getActiveRoom()->empty() && window->getEditManager().getHoveredVertex()) {
- if(!window->getEditManager().vertexOk(*window->getEditManager().getHoveredVertex()))
- glColor4f(1.0f, 0.3f, 0.3f, 0.7f);
-
- glBegin(GL_LINES);
-
- glVertex2d(window->getEditManager().getActiveRoom()->back().getX(), window->getEditManager().getActiveRoom()->back().getY());
- glVertex2d(window->getEditManager().getHoveredVertex()->getX(), window->getEditManager().getHoveredVertex()->getY());
-
- glEnd();
- }
- }
-
- glPopMatrix();
-
- gdk_gl_drawable_swap_buffers(drawable);
-
- gdk_gl_drawable_gl_end(drawable);
-
- return TRUE;
-}
diff --git a/draw.h b/draw.h
deleted file mode 100644
index 9754cf5..0000000
--- a/draw.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef DRAW_H_
-#define DRAW_H_
-
-#include <gtk/gtk.h>
-#include "Vertex.h"
-#include "Window.h"
-#include "Drawer.h"
-
-
-gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Window *window, Drawer *drawer);
-
-#endif /*DRAW_H_*/