summaryrefslogtreecommitdiffstats
path: root/window.cpp
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-09-21 23:47:05 +0200
committerneoraider <devnull@localhost>2007-09-21 23:47:05 +0200
commit62e42408485e9e1b7e939925b650a4b2e90ecddb (patch)
tree9305aa0f7b2d79c35250939beca2c268dd61e23d /window.cpp
parent1bce1d8ad7c32ce7b6723a284842b6890cf5209f (diff)
downloadzoomedit-62e42408485e9e1b7e939925b650a4b2e90ecddb.tar
zoomedit-62e42408485e9e1b7e939925b650a4b2e90ecddb.zip
zoomedit: Big transition Ciaro -> OpenGL, enormous speedup!
Diffstat (limited to 'window.cpp')
-rw-r--r--window.cpp168
1 files changed, 108 insertions, 60 deletions
diff --git a/window.cpp b/window.cpp
index d347964..ff570ce 100644
--- a/window.cpp
+++ b/window.cpp
@@ -2,10 +2,9 @@
#include "ui.h"
#include "edit.h"
#include "draw.h"
-#include "geometry.h"
#include <gtk/gtk.h>
-#include <stdlib.h>
-#include <string.h>
+#include <gtk/gtkgl.h>
+#include <GL/gl.h>
static GtkWidget *drawingArea = NULL, *sidebarView = NULL, *sidebarAdd = NULL;
@@ -14,10 +13,111 @@ static GtkAdjustment *hAdjustment = NULL, *vAdjustment = NULL;
static GtkWidget *entryName, *labelArea = NULL, *labelPerimeter = NULL, *buttonAdd = NULL, *buttonAddDo = NULL;
+static void refreshScrolling() {
+ if(getImageWidth() < drawingArea->allocation.width)
+ setXTranslate((getImageWidth()-drawingArea->allocation.width)/2);
+ else
+ setXTranslate(gtk_adjustment_get_value(hAdjustment));
+
+ if(getImageHeight() < drawingArea->allocation.height)
+ setYTranslate((getImageHeight()-drawingArea->allocation.height)/2);
+ else
+ setYTranslate(gtk_adjustment_get_value(vAdjustment));
+
+ gtk_widget_queue_draw(drawingArea);
+}
+
+static void updateScrollbars(double x, double y) {
+ const gdouble imageWidth = getImageWidth(), imageHeight = getImageHeight();
+ const gdouble width = drawingArea->allocation.width, height = drawingArea->allocation.height;
+ gdouble upper, pageSize, value;
+
+ gdk_window_freeze_updates(drawingArea->window);
+
+ g_object_get(G_OBJECT(hAdjustment), "upper", &upper, "page_size", &pageSize, NULL);
+ g_object_set(G_OBJECT(hAdjustment), "upper", imageWidth, "page_size", width, NULL);
+ gtk_adjustment_changed(hAdjustment);
+
+ if((pageSize > upper && width < imageWidth) || upper == 0)
+ value = (imageWidth-width)/2;
+ else
+ value = (gtk_adjustment_get_value(hAdjustment)+pageSize*x)/upper*imageWidth-width*x;
+ gtk_adjustment_set_value(hAdjustment, MAX(MIN(value, imageWidth-width), 0));
+
+ g_object_get(G_OBJECT(vAdjustment), "upper", &upper, "page_size", &pageSize, NULL);
+ g_object_set(G_OBJECT(vAdjustment), "upper", imageHeight, "page_size", height, NULL);
+ gtk_adjustment_changed(vAdjustment);
+
+ if((pageSize > upper && height < imageHeight) || upper == 0)
+ value = (imageHeight-height)/2;
+ else
+ value = (gtk_adjustment_get_value(vAdjustment)+pageSize*y)/upper*imageHeight-height*y;
+ gtk_adjustment_set_value(vAdjustment, MAX(MIN(value, imageHeight-height), 0));
+
+ gdk_window_thaw_updates(drawingArea->window);
+
+ refreshScrolling();
+}
+
static gboolean deleteEvent(GtkWidget *widget, GdkEvent *event, gpointer data) {
return FALSE;
}
+static void realize(GtkWidget *widget, gpointer data) {
+ GdkGLContext *context = gtk_widget_get_gl_context(widget);
+ GdkGLDrawable *drawable = gtk_widget_get_gl_drawable(widget);
+
+ if(!gdk_gl_drawable_gl_begin(drawable, context))
+ return;
+
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glEnable(GL_LINE_SMOOTH);
+
+ glViewport(0, 0, widget->allocation.width, widget->allocation.height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ if(widget->allocation.width != 0 && widget->allocation.height != 0) {
+ glTranslated(-1, 1, 0);
+ glScaled(2.0/widget->allocation.width, -2.0/widget->allocation.height, 1);
+ }
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ gdk_gl_drawable_gl_end(drawable);
+}
+
+static gboolean configureEvent(GtkWidget *widget, GdkEventConfigure *event, gpointer data) {
+ GdkGLContext *context = gtk_widget_get_gl_context(widget);
+ GdkGLDrawable *drawable = gtk_widget_get_gl_drawable(widget);
+
+ if(!gdk_gl_drawable_gl_begin(drawable, context))
+ return FALSE;
+
+ glViewport(0, 0, widget->allocation.width, widget->allocation.height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ if(widget->allocation.width != 0 && widget->allocation.height != 0) {
+ glTranslated(-1, 1, 0);
+ glScaled(2.0/widget->allocation.width, -2.0/widget->allocation.height, 1);
+ }
+
+ gdk_gl_drawable_gl_end(drawable);
+
+ updateScrollbars(0.5, 0.5);
+
+ return TRUE;
+}
+
+
static gboolean scrollEvent(GtkWidget *widget, GdkEventScroll *event, gpointer user_data) {
const gdouble x = event->x/widget->allocation.width, y = event->y/widget->allocation.height;
@@ -44,8 +144,6 @@ static gboolean buttonEvent(GtkWidget *widget, GdkEventButton *event, gpointer u
updateSidebar();
- redraw();
-
break;
case EDIT_MODE_ADD:
viewToImage(&v);
@@ -66,8 +164,6 @@ static gboolean buttonEvent(GtkWidget *widget, GdkEventButton *event, gpointer u
gboolean crossingNotifyEvent(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) {
Vertex v(event->x, event->y);
-
-
switch(event->type) {
case GDK_ENTER_NOTIFY:
viewToImage(&v);
@@ -99,56 +195,6 @@ static void destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}
-static void refreshScrolling() {
- if(getImageWidth() < drawingArea->allocation.width)
- setXTranslate((getImageWidth()-drawingArea->allocation.width)/2);
- else
- setXTranslate(gtk_adjustment_get_value(hAdjustment));
-
- if(getImageHeight() < drawingArea->allocation.height)
- setYTranslate((getImageHeight()-drawingArea->allocation.height)/2);
- else
- setYTranslate(gtk_adjustment_get_value(vAdjustment));
-
- gtk_widget_queue_draw(drawingArea);
-}
-
-static void updateScrollbars(double x, double y) {
- const gdouble imageWidth = getImageWidth(), imageHeight = getImageHeight();
- const gdouble width = drawingArea->allocation.width, height = drawingArea->allocation.height;
- gdouble upper, pageSize, value;
-
- gdk_window_freeze_updates(drawingArea->window);
-
- g_object_get(G_OBJECT(hAdjustment), "upper", &upper, "page_size", &pageSize, NULL);
- g_object_set(G_OBJECT(hAdjustment), "upper", imageWidth, "page_size", width, NULL);
- gtk_adjustment_changed(hAdjustment);
-
- if((pageSize > upper && width < imageWidth) || upper == 0)
- value = (imageWidth-width)/2;
- else
- value = (gtk_adjustment_get_value(hAdjustment)+pageSize*x)/upper*imageWidth-width*x;
- gtk_adjustment_set_value(hAdjustment, MAX(MIN(value, imageWidth-width), 0));
-
- g_object_get(G_OBJECT(vAdjustment), "upper", &upper, "page_size", &pageSize, NULL);
- g_object_set(G_OBJECT(vAdjustment), "upper", imageHeight, "page_size", height, NULL);
- gtk_adjustment_changed(vAdjustment);
-
- if((pageSize > upper && height < imageHeight) || upper == 0)
- value = (imageHeight-height)/2;
- else
- value = (gtk_adjustment_get_value(vAdjustment)+pageSize*y)/upper*imageHeight-height*y;
- gtk_adjustment_set_value(vAdjustment, MAX(MIN(value, imageHeight-height), 0));
-
- gdk_window_thaw_updates(drawingArea->window);
-
- refreshScrolling();
-}
-
-static void updateScrollbarsCentered() {
- updateScrollbars(0.5, 0.5);
-}
-
static void sidebarNameChanged(GtkEditable *editable, gpointer user_data) {
if(getActiveRoom() == NULL) return;
@@ -242,7 +288,7 @@ static GtkWidget* createSidebar() {
return sidebar;
}
-GtkWidget* createMainWindow() {
+GtkWidget* createMainWindow(GdkGLConfig *glconfig) {
GtkWidget *window, *hPaned, *vbox, *table, *vScroll, *hScroll, *sidebar;
GdkColor color = {0, 0, 0, 0};
@@ -267,8 +313,10 @@ GtkWidget* createMainWindow() {
gtk_paned_pack1(GTK_PANED(hPaned), table, TRUE, TRUE);
drawingArea = gtk_drawing_area_new();
- gtk_widget_modify_bg(drawingArea, (GtkStateType)GTK_WIDGET_STATE(drawingArea), &color);
- g_signal_connect(G_OBJECT(drawingArea), "configure-event", G_CALLBACK(updateScrollbarsCentered), NULL);
+ gtk_widget_set_gl_capability(drawingArea, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
+ gtk_widget_set_double_buffered(drawingArea, FALSE);
+ g_signal_connect(G_OBJECT(drawingArea), "realize", G_CALLBACK(realize), NULL);
+ g_signal_connect(G_OBJECT(drawingArea), "configure-event", G_CALLBACK(configureEvent), NULL);
g_signal_connect(G_OBJECT(drawingArea), "expose-event", G_CALLBACK(drawTopView), NULL);
g_signal_connect(G_OBJECT(drawingArea), "button-press-event", G_CALLBACK(buttonEvent), NULL);
g_signal_connect(G_OBJECT(drawingArea), "button-release-event", G_CALLBACK(buttonEvent), NULL);