summaryrefslogtreecommitdiffstats
path: root/src/Gui
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2008-04-20 02:08:05 +0200
committerneoraider <devnull@localhost>2008-04-20 02:08:05 +0200
commit12ebbe18e1c54c854286e38a4cf9e15433cd1bb2 (patch)
tree67fd0c9b9f80c8f096133f7ceb06cb77b0cc9ce1 /src/Gui
parentc771232b7433c076290c2ac6c8c53090a1ad3592 (diff)
downloadzoomedit-12ebbe18e1c54c854286e38a4cf9e15433cd1bb2.tar
zoomedit-12ebbe18e1c54c854286e38a4cf9e15433cd1bb2.zip
zoomedit:
* Moved much stuff from RenderArea to TopView to make MapView possible * Created MapView class
Diffstat (limited to 'src/Gui')
-rw-r--r--src/Gui/RenderArea.cpp89
-rw-r--r--src/Gui/RenderArea.h25
2 files changed, 30 insertions, 84 deletions
diff --git a/src/Gui/RenderArea.cpp b/src/Gui/RenderArea.cpp
index 1904aa8..0cec471 100644
--- a/src/Gui/RenderArea.cpp
+++ b/src/Gui/RenderArea.cpp
@@ -22,8 +22,6 @@
#include <iostream>
#include <cstdlib>
#include <cmath>
-#include <gtkmm/toolbutton.h>
-#include <gtkmm/adjustment.h>
#include <GL/gl.h>
namespace ZoomEdit {
@@ -31,9 +29,8 @@ namespace Gui {
GdkGLConfig *RenderArea::glconfig = 0;
-RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &xml)
-: Gtk::DrawingArea(cobject), view(0), xCenter(0), yCenter(0), viewWidth(0), viewHeight(0), zoomLevel(0),
-scale(100), inWindow(false) {
+RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml>&)
+: Gtk::DrawingArea(cobject), view(0), inWindow(false) {
if(!glconfig) {
glconfig = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DOUBLE));
if(!glconfig) glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB); // Hmm, can't find double buffered config
@@ -51,13 +48,6 @@ scale(100), inWindow(false) {
signal_leave_notify_event().connect(sigc::mem_fun(this, &RenderArea::onLeaveNotifyEvent));
signal_motion_notify_event().connect(sigc::mem_fun(this, &RenderArea::onMotionNotifyEvent));
- Gtk::ToolButton *button;
- xml->get_widget("ToolButtonZoomIn", button);
- button->signal_clicked().connect(sigc::bind(sigc::mem_fun(this, &RenderArea::zoom), 2, 0.5f, 0.5f));
-
- xml->get_widget("ToolButtonZoomOut", button);
- button->signal_clicked().connect(sigc::bind(sigc::mem_fun(this, &RenderArea::zoom), -2, 0.5f, 0.5f));
-
gtk_widget_set_gl_capability(GTK_WIDGET(cobject), glconfig, 0, TRUE, GDK_GL_RGBA_TYPE);
}
@@ -93,9 +83,6 @@ bool RenderArea::onConfigureEvent(GdkEventConfigure*) {
gdkGLEnd();
- viewWidth = get_width()/scale;
- viewHeight = get_height()/scale;
-
queue_draw();
return true;
@@ -105,20 +92,9 @@ bool RenderArea::onExposeEvent(GdkEventExpose*) {
if(!gdkGLBegin())
return false;
- glClear(GL_COLOR_BUFFER_BIT);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-
- glScalef(scale, scale, 1);
- glTranslatef(-xCenter, -yCenter, 0);
-
if(view)
view->render(this);
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-
gdkSwapBuffers();
gdkGLEnd();
@@ -126,22 +102,26 @@ bool RenderArea::onExposeEvent(GdkEventExpose*) {
}
bool RenderArea::onScrollEvent(GdkEventScroll *event) {
- switch(event->direction) {
- case GDK_SCROLL_UP:
- zoom(1, event->x/get_width(), event->y/get_height());
- return true;
- case GDK_SCROLL_DOWN:
- zoom(-1, event->x/get_width(), event->y/get_height());
- return true;
- default:
- return false;
+ if(view) {
+ switch(event->direction) {
+ case GDK_SCROLL_UP:
+ view->zoom(this, 1, event->x - get_width()/2, event->y - get_height()/2);
+ return true;
+ case GDK_SCROLL_DOWN:
+ view->zoom(this, -1, event->x - get_width()/2, event->y - get_height()/2);
+ return true;
+ default:
+ return false;
+ }
}
+
+ return false;
}
bool RenderArea::onEnterNotifyEvent(GdkEventCrossing *event) {
inWindow = true;
- xHover = event->x/scale - getViewWidth()/2 + xCenter;
- yHover = event->y/scale - getViewHeight()/2 + yCenter;
+ xHover = event->x;
+ yHover = event->y;
return true;
}
@@ -153,34 +133,21 @@ bool RenderArea::onLeaveNotifyEvent(GdkEventCrossing*) {
}
bool RenderArea::onMotionNotifyEvent(GdkEventMotion *event) {
- inWindow = true;
-
- if(event->state & GDK_BUTTON3_MASK) {
- xCenter = xHover - event->x/scale + getViewWidth()/2;
- yCenter = yHover - event->y/scale + getViewHeight()/2;
- queue_draw();
- }
- else {
- xHover = event->x/scale - getViewWidth()/2 + xCenter;
- yHover = event->y/scale - getViewHeight()/2 + yCenter;
+ if(!inWindow) {
+ xHover = event->x;
+ yHover = event->y;
+ inWindow = true;
+
+ return true;
}
- return true;
-}
-
-void RenderArea::zoom(int zoom, float x, float y) {
- zoomLevel = std::max(std::min(zoomLevel + zoom, 50), -100);
- scale = 100*std::pow(1.1f, zoomLevel);
-
- const float newWidth = get_width()/scale, newHeight = get_height()/scale;
-
- xCenter += (x-0.5f)*(viewWidth-newWidth);
- yCenter += (y-0.5f)*(viewHeight-newHeight);
+ if(event->state & GDK_BUTTON3_MASK && view)
+ view->move(this, xHover - event->x, yHover - event->y);
- viewWidth = newWidth;
- viewHeight = newHeight;
+ xHover = event->x;
+ yHover = event->y;
- queue_draw();
+ return true;
}
}
diff --git a/src/Gui/RenderArea.h b/src/Gui/RenderArea.h
index c8b6d6e..08cb841 100644
--- a/src/Gui/RenderArea.h
+++ b/src/Gui/RenderArea.h
@@ -35,7 +35,7 @@ namespace Gui {
class RenderArea : public Gtk::DrawingArea {
public:
- RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &xml);
+ RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml>&);
View::View* getView() const {return view;}
void setView(View::View *view0) {
@@ -43,32 +43,13 @@ class RenderArea : public Gtk::DrawingArea {
queue_draw();
}
- float getViewWidth() const {
- return viewWidth;
- }
-
- float getViewHeight() const {
- return viewHeight;
- }
-
- float getScale() const {return scale;}
-
- float getXCenter() const {return xCenter;}
- float getYCenter() const {return yCenter;}
-
private:
static GdkGLConfig *glconfig;
View::View *view;
- float xCenter, yCenter;
- float viewWidth, viewHeight;
-
- int zoomLevel;
- float scale;
-
bool inWindow;
- float xHover, yHover;
+ gdouble xHover, yHover;
void onRealize();
bool onConfigureEvent(GdkEventConfigure*);
@@ -78,8 +59,6 @@ class RenderArea : public Gtk::DrawingArea {
bool onLeaveNotifyEvent(GdkEventCrossing*);
bool onMotionNotifyEvent(GdkEventMotion *event);
- void zoom(int zoom, float x = 0.5f, float y = 0.5f);
-
bool gdkGLBegin() {
GtkWidget *widget = GTK_WIDGET(gobj());