summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/Makefile.am.plugingui4
-rw-r--r--plugingui/nativewindow_pugl.cc273
-rw-r--r--plugingui/nativewindow_pugl.h58
3 files changed, 178 insertions, 157 deletions
diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui
index 3f2e15d..62ddd19 100644
--- a/plugingui/Makefile.am.plugingui
+++ b/plugingui/Makefile.am.plugingui
@@ -51,6 +51,8 @@ PLUGIN_GUI_SOURCES += $(top_srcdir)/plugingui/nativewindow_win32.cc
endif
if ENABLE_PUGL
-PLUGIN_GUI_SOURCES += $(top_srcdir)/plugingui/nativewindow_pugl.cc
+PLUGIN_GUI_SOURCES += \
+ $(top_srcdir)/plugingui/nativewindow_pugl.cc \
+ $(top_srcdir)/pugl/pugl/pugl_x11.c
PLUGIN_GUI_CFLAGS += -I$(top_srcdir)/pugl/pugl
endif
diff --git a/plugingui/nativewindow_pugl.cc b/plugingui/nativewindow_pugl.cc
index df21925..0864c2b 100644
--- a/plugingui/nativewindow_pugl.cc
+++ b/plugingui/nativewindow_pugl.cc
@@ -29,197 +29,218 @@
#include <stdlib.h>
#include <list>
-#include "hugin.hpp"
+#ifdef __APPLE__
+#include <OpenGL/glu.h>
+#else
+#include <GL/glu.h>
+#include <GL/glext.h>
+#include <GL/gl.h>
+#endif
+
+#include "window.h"
#include "guievent.h"
-static GUI::Window* windowptr;
-static std::list<GUI::Event*> eventq;
+#include <hugin.hpp>
-static void onDisplay(PuglView* view)
+namespace GUI {
+
+void NativeWindowPugl::onDisplay(PuglView* view)
{
+ NativeWindowPugl* native = (NativeWindowPugl*)puglGetHandle(view);
+ Window* windowptr = native->window;
+
+ glDisable(GL_DEPTH_TEST);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ GLuint image;
- glDisable(GL_DEPTH_TEST);
- glClear(GL_COLOR_BUFFER_BIT);
+ glGenTextures(1, &image);
- GLuint image;
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glGenTextures(1, &image);
+ 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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ 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);
- 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);
+ glEnable(GL_TEXTURE_2D);
- 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);
+ 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();
- 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();
- glDeleteTextures(1, &image);
- glDisable(GL_TEXTURE_2D);
- glFlush();
-
- puglPostRedisplay(view);
+ puglPostRedisplay(view);
}
-static void onMouse(PuglView* view, int button, bool press, int x, int y)
+void NativeWindowPugl::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);
+ NativeWindowPugl* native = (NativeWindowPugl*)puglGetHandle(view);
- GUI::ButtonEvent* e = new GUI::ButtonEvent();
- e->x = x;
- e->y = y;
+ DEBUG(nativewindow_pugl, "Mouse %d %s at (%d,%d)\n", button,
+ press? "down":"up", x, y);
- switch(button) {
- case 1:
- e->button = GUI::MouseButton::left;
- break;
- case 2:
- e->button = GUI::MouseButton::right;
- break;
- case 3:
- default:
- e->button = GUI::MouseButton::middle;
- break;
- }
+ ButtonEvent* e = new ButtonEvent();
+ e->x = x;
+ e->y = y;
- e->direction = press ? GUI::Direction::down : GUI::Direction::up;
- e->doubleClick = false;
+ switch(button) {
+ case 1:
+ e->button = MouseButton::left;
+ break;
+ case 2:
+ e->button = MouseButton::middle;
+ break;
+ case 3:
+ default:
+ e->button = MouseButton::right;
+ break;
+ }
- eventq.push_back(e);
+ e->direction = press ? Direction::down : Direction::up;
+ e->doubleClick = false;
+
+ native->eventq.push_back(e);
}
-static void onKeyboard(PuglView* view, bool press, uint32_t key)
+void NativeWindowPugl::onKeyboard(PuglView* view, bool press, uint32_t key)
{
- if(press) {
- GUI::KeyEvent* e = new GUI::KeyEvent();
- e->direction = press ? GUI::Direction::down : GUI::Direction::up;
+ NativeWindowPugl* native = (NativeWindowPugl*)puglGetHandle(view);
+
+ KeyEvent* e = new KeyEvent();
+ e->direction = press ? Direction::down : Direction::up;
- printf("%d\n", key);
-
- switch(key) {
- case PUGL_KEY_LEFT: e->keycode = GUI::Key::left; break;
- case PUGL_KEY_RIGHT: e->keycode = GUI::Key::right; break;
- case PUGL_KEY_UP: e->keycode = GUI::Key::up; break;
- case PUGL_KEY_DOWN: e->keycode = GUI::Key::down; break;
- case PUGL_KEY_PAGE_UP: e->keycode = GUI::Key::pageDown; break;
- case PUGL_KEY_PAGE_DOWN: e->keycode = GUI::Key::pageUp; break;
- default: e->keycode = GUI::Key::unknown; break;
- }
+ printf("%d\n", key);
- // TODO: perform character type check
- if(e->keycode == GUI::Key::unknown) {
- e->keycode = GUI::Key::character;
- e->text.assign(1, (char)key);
- }
+ switch(key) {
+ case PUGL_KEY_LEFT: e->keycode = Key::left; break;
+ case PUGL_KEY_RIGHT: e->keycode = Key::right; break;
+ case PUGL_KEY_UP: e->keycode = Key::up; break;
+ case PUGL_KEY_DOWN: e->keycode = Key::down; break;
+ case PUGL_KEY_PAGE_UP: e->keycode = Key::pageDown; break;
+ case PUGL_KEY_PAGE_DOWN: e->keycode = Key::pageUp; break;
+ default: e->keycode = Key::unknown; break;
+ }
- printf("\t text: %s\n", e->text.c_str());
-
- eventq.push_back(e);
- }
+ // TODO: perform character type check
+ if(e->keycode == Key::unknown)
+ {
+ e->keycode = Key::character;
+ e->text.assign(1, (char)key);
+ }
+
+ printf("\t text: %s\n", e->text.c_str());
+
+ native->eventq.push_back(e);
}
-GUI::NativeWindowPugl::NativeWindowPugl(GUI::Window *window)
- : GUI::NativeWindow()
+NativeWindowPugl::NativeWindowPugl(Window *window)
+ : window(window)
{
- INFO(nativewindow, "Running with PuGL native window\n");
- this->window = window;
- windowptr = window;
- view = NULL;
- init();
+ INFO(nativewindow, "Running with PuGL native window\n");
+ init();
}
-GUI::NativeWindowPugl::~NativeWindowPugl()
+NativeWindowPugl::~NativeWindowPugl()
{
- puglDestroy(view);
+ 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);
+void NativeWindowPugl::init() {
+ PuglView* oldView = view;
+ if(view)
+ {
+ oldView = view;
+ }
+
+// view = puglCreate(0, "DrumgGizmo", window->x(), window->y(), false, true);
+ view = puglCreate(0, "DrumgGizmo", 370, 330, false, true);
+ puglSetHandle(view, (PuglHandle)this);
+ puglSetDisplayFunc(view, onDisplay);
+ puglSetMouseFunc(view, onMouse);
+ puglSetKeyboardFunc(view, onKeyboard);
- if(old) free(old);
+ if(oldView)
+ {
+ free(oldView);
+ }
}
-void GUI::NativeWindowPugl::setFixedSize(int width, int height)
+void NativeWindowPugl::setFixedSize(int width, int height)
{
-// redraw();
+// redraw();
}
-void GUI::NativeWindowPugl::resize(int width, int height)
+void NativeWindowPugl::resize(int width, int height)
{
-// DEBUG(nativewindow_pugl, "Resizing to %dx%d\n", width, height);
-// init();
-// redraw();
+// DEBUG(nativewindow_pugl, "Resizing to %dx%d\n", width, height);
+// init();
+// redraw();
}
-void GUI::NativeWindowPugl::move(int x, int y)
+void NativeWindowPugl::move(int x, int y)
{
-// redraw();
+// redraw();
}
-void GUI::NativeWindowPugl::show()
+void NativeWindowPugl::show()
{
-// redraw();
+// redraw();
}
-void GUI::NativeWindowPugl::hide()
+void NativeWindowPugl::hide()
{
-// redraw();
+// redraw();
}
-void GUI::NativeWindowPugl::handleBuffer()
+void NativeWindowPugl::handleBuffer()
{
- onDisplay(view);
+ onDisplay(view);
}
-void GUI::NativeWindowPugl::redraw()
+void NativeWindowPugl::redraw()
{
-// handleBuffer();
+// handleBuffer();
}
-void GUI::NativeWindowPugl::setCaption(const std::string &caption)
+void NativeWindowPugl::setCaption(const std::string &caption)
{
-// redraw();
+// redraw();
}
-void GUI::NativeWindowPugl::grabMouse(bool grab)
+void NativeWindowPugl::grabMouse(bool grab)
{
-// redraw();
+// redraw();
}
-bool GUI::NativeWindowPugl::hasEvent()
+bool NativeWindowPugl::hasEvent()
{
- // dirty hack - assume that this function is called enough times to get fluent gui
- // ^^ Bad assumption
- puglProcessEvents(view);
- return !eventq.empty();
+ // 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 *NativeWindowPugl::getNextEvent()
{
- Event *event = NULL;
-
- if(!eventq.empty()) {
- event = eventq.front();
- eventq.pop_front();
- }
- return event;
+ Event *event = nullptr;
+
+ if(!eventq.empty()) {
+ event = eventq.front();
+ eventq.pop_front();
+ }
+ return event;
}
+
+} // GUI::
diff --git a/plugingui/nativewindow_pugl.h b/plugingui/nativewindow_pugl.h
index cf761fd..f5d89ab 100644
--- a/plugingui/nativewindow_pugl.h
+++ b/plugingui/nativewindow_pugl.h
@@ -24,49 +24,47 @@
* 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__*/
+#pragma once
#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
+#include <list>
namespace GUI {
+class Event;
class Window;
+
class NativeWindowPugl : public NativeWindow {
public:
- NativeWindowPugl(GUI::Window *window);
- ~NativeWindowPugl();
+ NativeWindowPugl(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);
+ 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();
+ bool hasEvent();
+ Event *getNextEvent();
private:
- GUI::Window *window;
- PuglView* view;
-};
+ Window* window{nullptr};
+ PuglView* view{nullptr};
+
+ std::list<Event*> eventq;
+ // Internal pugl c-callbacks
+ static void onDisplay(PuglView* view);
+ static void onMouse(PuglView* view, int button, bool press, int x, int y);
+ static void onKeyboard(PuglView* view, bool press, uint32_t key);
};
+
+} // GUI::