summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2014-01-18 10:43:36 +0100
committerJonas Suhr Christensen <jsc@umbraculum.org>2014-01-18 10:43:36 +0100
commitf4635499bc96a597764f9cefb0b7b44f532e9c9b (patch)
tree1f3ef87b23db41aec7fe2b0fa5ca3feb396893c1
parentfe9e38995f5a0abc196e9600c38d95385d6bf84f (diff)
Added enable-pugl as configure parameter.
Added nativewindow_pugl files.
-rw-r--r--configure.ac5
-rw-r--r--plugingui/Makefile.am.plugingui10
-rw-r--r--plugingui/nativewindow_pugl.cc212
-rw-r--r--plugingui/nativewindow_pugl.h72
4 files changed, 295 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index d85c345..fdabdbf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,11 +36,12 @@ if test x$with_experimental == xyes; then
CXXFLAGS="$CXXFLAGS -DEXPERIMENTAL"
fi
-AC_ARG_WITH(pugl, [ --with-pugl Build with Pugl support])
-if test x$with_pugl == xyes; then
+AC_ARG_ENABLE(pugl, [ --enable-pugl Build with Pugl support])
+if test x$enable_pugl == xyes; then
AC_MSG_WARN([*** Building with pugl support!])
CXXFLAGS="$CXXFLAGS -DPUGL -lGL -lGLU -lglut"
fi
+AM_CONDITIONAL([ENABLE_PUGL], [test "x$enable_pugl" = "xyes"])
AC_ARG_WITH(test, [ --with-test Build unit tests])
if test x$with_test == xyes; then
diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui
index f47582c..1c95310 100644
--- a/plugingui/Makefile.am.plugingui
+++ b/plugingui/Makefile.am.plugingui
@@ -1,8 +1,14 @@
+
+if ENABLE_PUGL
+puglsources = $(top_srcdir)/pugl/pugl/pugl_x11.c $(top_srcdir)/plugingui/nativewindow_pugl.cc
+else
+puglsources =
+endif
+
PLUGIN_GUI_SOURCES = \
$(top_srcdir)/hugin/hugin.c \
$(top_srcdir)/hugin/hugin_syslog.c \
- $(top_srcdir)/pugl/pugl/pugl_x11.c \
- $(top_srcdir)/plugingui/nativewindow_pugl.cc \
+ $(puglsources) \
$(top_srcdir)/plugingui/nativewindow_x11.cc \
$(top_srcdir)/plugingui/nativewindow_win32.cc \
$(top_srcdir)/plugingui/plugingui.cc \
diff --git a/plugingui/nativewindow_pugl.cc b/plugingui/nativewindow_pugl.cc
new file mode 100644
index 0000000..45cddab
--- /dev/null
+++ b/plugingui/nativewindow_pugl.cc
@@ -0,0 +1,212 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * nativewindow_pugl.cc
+ *
+ * Fri Dec 28 18:45:57 CET 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "nativewindow_pugl.h"
+
+#include <stdlib.h>
+#include <list>
+
+#include "hugin.hpp"
+#include "guievent.h"
+
+static GUI::Window* windowptr;
+static std::list<GUI::Event*> eventq;
+
+static void onDisplay(PuglView* view)
+{
+
+ glDisable(GL_DEPTH_TEST);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ GLuint image;
+
+ glGenTextures(1, &image);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_NEAREST = no smoothing
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, windowptr->wpixbuf.width,
+ windowptr->wpixbuf.height, 0, GL_RGB, GL_UNSIGNED_BYTE,
+ windowptr->wpixbuf.buf);
+
+ glEnable(GL_TEXTURE_2D);
+
+ glBegin(GL_QUADS);
+ glTexCoord2d(0.0, 0.0); glVertex2f(0.0, 0.0);
+ glTexCoord2d(0.0, 1.0); glVertex2f(0.0, windowptr->wpixbuf.height);
+ glTexCoord2d(1.0, 1.0); glVertex2f(windowptr->wpixbuf.width, windowptr->wpixbuf.height);
+ glTexCoord2d(1.0, 0.0); glVertex2f(windowptr->wpixbuf.width, 0.0);
+ glEnd();
+
+ glDeleteTextures(1, &image);
+ glDisable(GL_TEXTURE_2D);
+ glFlush();
+
+ puglPostRedisplay(view);
+}
+
+static void onMouse(PuglView* view, int button, bool press, int x, int y)
+{
+ DEBUG(nativewindow_pugl, "Mouse %d %s at (%d,%d)\n", button,
+ press? "down":"up", x, y);
+
+ GUI::ButtonEvent* e = new GUI::ButtonEvent();
+ e->x = x;
+ e->y = y;
+ e->button = button;
+ e->direction = press?1:-1;
+ e->doubleclick = false;
+
+ eventq.push_back(e);
+}
+
+static void onKeyboard(PuglView* view, bool press, uint32_t key)
+{
+ if(press) {
+ GUI::KeyEvent* e = new GUI::KeyEvent();
+ e->direction = press?-1:1;
+
+ printf("%d\n", key);
+
+ switch(key) {
+ case PUGL_KEY_LEFT: e->keycode = GUI::KeyEvent::KEY_LEFT; break;
+ case PUGL_KEY_RIGHT: e->keycode = GUI::KeyEvent::KEY_RIGHT; break;
+ case PUGL_KEY_UP: e->keycode = GUI::KeyEvent::KEY_UP; break;
+ case PUGL_KEY_DOWN: e->keycode = GUI::KeyEvent::KEY_DOWN; break;
+ case PUGL_KEY_PAGE_UP: e->keycode = GUI::KeyEvent::KEY_PGDOWN; break;
+ case PUGL_KEY_PAGE_DOWN: e->keycode = GUI::KeyEvent::KEY_PGUP; break;
+ default: e->keycode = GUI::KeyEvent::KEY_UNKNOWN; break;
+ }
+
+ // TODO: perform character type check
+ if(e->keycode == GUI::KeyEvent::KEY_UNKNOWN) {
+ e->keycode = GUI::KeyEvent::KEY_CHARACTER;
+ e->text.assign(1, (char)key);
+ }
+
+ printf("\t text: %s\n", e->text.c_str());
+
+ eventq.push_back(e);
+ }
+}
+
+GUI::NativeWindowPugl::NativeWindowPugl(GUI::Window *window)
+ : GUI::NativeWindow()
+{
+ INFO(nativewindow, "Running with PuGL native window\n");
+ this->window = window;
+ windowptr = window;
+ view = NULL;
+ init();
+}
+
+GUI::NativeWindowPugl::~NativeWindowPugl()
+{
+ puglDestroy(view);
+}
+
+void GUI::NativeWindowPugl::init() {
+ PuglView* old = view;
+ if(view) old = view;
+// view = puglCreate(0, "DrumgGizmo", window->x(), window->y(), false, true);
+ view = puglCreate(0, "DrumgGizmo", 370, 330, false, true);
+ puglSetDisplayFunc(view, onDisplay);
+ puglSetMouseFunc(view, onMouse);
+ puglSetKeyboardFunc(view, onKeyboard);
+
+ if(old) free(old);
+}
+
+void GUI::NativeWindowPugl::setFixedSize(int width, int height)
+{
+// redraw();
+}
+
+void GUI::NativeWindowPugl::resize(int width, int height)
+{
+// DEBUG(nativewindow_pugl, "Resizing to %dx%d\n", width, height);
+// init();
+// redraw();
+}
+
+void GUI::NativeWindowPugl::move(int x, int y)
+{
+// redraw();
+}
+
+void GUI::NativeWindowPugl::show()
+{
+// redraw();
+}
+
+void GUI::NativeWindowPugl::hide()
+{
+// redraw();
+}
+
+void GUI::NativeWindowPugl::handleBuffer()
+{
+ onDisplay(view);
+}
+
+void GUI::NativeWindowPugl::redraw()
+{
+// handleBuffer();
+}
+
+void GUI::NativeWindowPugl::setCaption(const std::string &caption)
+{
+// redraw();
+}
+
+void GUI::NativeWindowPugl::grabMouse(bool grab)
+{
+// redraw();
+}
+
+bool GUI::NativeWindowPugl::hasEvent()
+{
+ // dirty hack - assume that this function is called enough times to get fluent gui
+ // ^^ Bad assumption
+ puglProcessEvents(view);
+ return !eventq.empty();
+}
+
+GUI::Event *GUI::NativeWindowPugl::getNextEvent()
+{
+ Event *event = NULL;
+
+ if(!eventq.empty()) {
+ event = eventq.front();
+ eventq.pop_front();
+ }
+ return event;
+}
diff --git a/plugingui/nativewindow_pugl.h b/plugingui/nativewindow_pugl.h
new file mode 100644
index 0000000..cf761fd
--- /dev/null
+++ b/plugingui/nativewindow_pugl.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * nativewindow_pugl.h
+ *
+ * Fri Dec 28 18:45:56 CET 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_NATIVEWINDOW_PUGL_H__
+#define __DRUMGIZMO_NATIVEWINDOW_PUGL_H__
+#endif/*__DRUMGIZMO_NATIVEWINDOW_PUGL_H__*/
+
+#include "nativewindow.h"
+
+#include "window.h"
+
+#include "pugl.h"
+
+#ifdef __APPLE__
+# include <OpenGL/glu.h>
+#else
+# include <GL/glu.h>
+# include <GL/glext.h>
+# include <GL/gl.h>
+#endif
+
+namespace GUI {
+
+class Window;
+class NativeWindowPugl : public NativeWindow {
+public:
+ NativeWindowPugl(GUI::Window *window);
+ ~NativeWindowPugl();
+
+ void init();
+ void setFixedSize(int width, int height);
+ void resize(int width, int height);
+ void move(int x, int y);
+ void show();
+ void setCaption(const std::string &caption);
+ void hide();
+ void handleBuffer();
+ void redraw();
+ void grabMouse(bool grab);
+
+ bool hasEvent();
+ Event *getNextEvent();
+
+private:
+ GUI::Window *window;
+ PuglView* view;
+};
+
+};