@@ -27,10 +27,10 @@ class Image | |||
{ | |||
public: | |||
Image(); | |||
Image(const char* data, const Size<int>& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); | |||
Image(const char* rawData, const Size<int>& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); | |||
Image(const Image& image); | |||
void loadFromMemory(const char* data, const Size<int>& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); | |||
void loadFromMemory(const char* rawData, const Size<int>& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); | |||
bool isValid() const; | |||
@@ -38,12 +38,14 @@ public: | |||
int getHeight() const; | |||
const Size<int>& getSize() const; | |||
const char* getData() const; | |||
const char* getRawData() const; | |||
GLenum getFormat() const; | |||
GLenum getType() const; | |||
Image& operator=(const Image& image); | |||
private: | |||
const char* fData; | |||
const char* fRawData; | |||
Size<int> fSize; | |||
GLenum fFormat; | |||
GLenum fType; | |||
@@ -28,22 +28,35 @@ class Window; | |||
class Widget | |||
{ | |||
public: | |||
Widget(Window* parent = nullptr); | |||
Widget(Window* parent); | |||
virtual ~Widget(); | |||
bool isVisible(); | |||
void setVisible(bool yesNo); | |||
void show() | |||
{ | |||
setVisible(true); | |||
} | |||
void hide() | |||
{ | |||
setVisible(false); | |||
} | |||
protected: | |||
void onDisplay(); | |||
void onKeyboard(bool press, uint32_t key); | |||
void onMouse(int button, bool press, int x, int y); | |||
void onMotion(int x, int y); | |||
void onScroll(float dx, float dy); | |||
void onSpecial(bool press, Key key); | |||
void onReshape(int width, int height); | |||
void onClose(); | |||
virtual void onDisplay(); | |||
virtual void onKeyboard(bool press, uint32_t key); | |||
virtual void onMouse(int button, bool press, int x, int y); | |||
virtual void onMotion(int x, int y); | |||
virtual void onScroll(float dx, float dy); | |||
virtual void onSpecial(bool press, Key key); | |||
virtual void onReshape(int width, int height); | |||
virtual void onClose(); | |||
private: | |||
class Private; | |||
Private* const kPrivate; | |||
Window* fParent; | |||
bool fVisible; | |||
friend class Window; | |||
}; | |||
@@ -24,6 +24,7 @@ START_NAMESPACE_DISTRHO | |||
// ------------------------------------------------- | |||
class App; | |||
class Widget; | |||
class Window | |||
{ | |||
@@ -39,10 +40,15 @@ public: | |||
bool isVisible(); | |||
void setVisible(bool yesNo); | |||
void setResizable(bool yesNo); | |||
void setSize(unsigned int width, unsigned int height); | |||
void setWindowTitle(const char* title); | |||
intptr_t getWindowId(); | |||
void addWidget(Widget* widget); | |||
void removeWidget(Widget* widget); | |||
void show() | |||
{ | |||
setVisible(true); | |||
@@ -0,0 +1,101 @@ | |||
/* | |||
* DISTRHO Plugin Toolkit (DPT) | |||
* Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation. | |||
* | |||
* This program 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 Lesser General Public License for more details. | |||
* | |||
* For a full copy of the license see the LGPL.txt file | |||
*/ | |||
#include "../Image.hpp" | |||
START_NAMESPACE_DISTRHO | |||
// ------------------------------------------------- | |||
Image::Image() | |||
: fRawData(nullptr), | |||
fSize(0, 0), | |||
fFormat(0), | |||
fType(0) | |||
{ | |||
} | |||
Image::Image(const char* rawData, const Size<int>& size, GLenum format, GLenum type) | |||
: fRawData(rawData), | |||
fSize(size), | |||
fFormat(format), | |||
fType(type) | |||
{ | |||
} | |||
Image::Image(const Image& image) | |||
: fRawData(image.fRawData), | |||
fSize(image.fSize), | |||
fFormat(image.fFormat), | |||
fType(image.fType) | |||
{ | |||
} | |||
void Image::loadFromMemory(const char* rawData, const Size<int>& size, GLenum format, GLenum type) | |||
{ | |||
fRawData = rawData; | |||
fSize = size; | |||
fFormat = format; | |||
fType = type; | |||
} | |||
bool Image::isValid() const | |||
{ | |||
return (fRawData != nullptr && getWidth() > 0 && getHeight() > 0); | |||
} | |||
int Image::getWidth() const | |||
{ | |||
return fSize.getWidth(); | |||
} | |||
int Image::getHeight() const | |||
{ | |||
return fSize.getHeight(); | |||
} | |||
const Size<int>& Image::getSize() const | |||
{ | |||
return fSize; | |||
} | |||
const char* Image::getRawData() const | |||
{ | |||
return fRawData; | |||
} | |||
GLenum Image::getFormat() const | |||
{ | |||
return fFormat; | |||
} | |||
GLenum Image::getType() const | |||
{ | |||
return fType; | |||
} | |||
Image& Image::operator=(const Image& image) | |||
{ | |||
fRawData = image.fRawData; | |||
fSize = image.fSize; | |||
fFormat = image.fFormat; | |||
fType = image.fType; | |||
return *this; | |||
} | |||
// ------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -18,58 +18,40 @@ | |||
#include "../Widget.hpp" | |||
#include "../Window.hpp" | |||
START_NAMESPACE_DISTRHO | |||
// ------------------------------------------------- | |||
// Window Private | |||
#include <cstdio> | |||
class Widget::Private | |||
{ | |||
public: | |||
Private(Window* parent) | |||
: fApp(nullptr), | |||
fWindow(nullptr) | |||
{ | |||
if (parent == nullptr) | |||
{ | |||
fApp = new App; | |||
fWindow = new Window(fApp); | |||
} | |||
} | |||
~Private() | |||
{ | |||
if (fWindow != nullptr) | |||
delete fWindow; | |||
if (fApp != nullptr) | |||
delete fApp; | |||
} | |||
private: | |||
App* fApp; | |||
Window* fWindow; | |||
}; | |||
START_NAMESPACE_DISTRHO | |||
// ------------------------------------------------- | |||
// Widget | |||
Widget::Widget(Window* parent) | |||
: kPrivate(new Private(parent)) | |||
: fParent(parent), | |||
fVisible(true) | |||
{ | |||
parent->addWidget(this); | |||
} | |||
Widget::~Widget() | |||
{ | |||
} | |||
void Widget::onDisplay() | |||
bool Widget::isVisible() | |||
{ | |||
//if (fParent == nullptr) | |||
// glColor3f(0.0f, 1.0f, 0.0f); | |||
//else | |||
glColor3f(0.0f, 0.0f, 1.0f); | |||
glRectf(-0.75f, 0.75f, 0.75f, -0.75f); | |||
return fVisible; | |||
} | |||
void Widget::setVisible(bool yesNo) | |||
{ | |||
if (yesNo == fVisible) | |||
return; | |||
fVisible = yesNo; | |||
fParent->repaint(); | |||
} | |||
void Widget::onDisplay() | |||
{ | |||
} | |||
void Widget::onKeyboard(bool, uint32_t) | |||
@@ -58,7 +58,7 @@ public: | |||
Private(Window* self, App::Private* app, Private* parent, intptr_t parentId = 0) | |||
: kApp(app), | |||
kSelf(self), | |||
kView(puglCreate(parentId, "test", 300, 100, false, false)), | |||
kView(puglCreate(parentId, "Window", 600, 500, false, false)), | |||
fParent(parent), | |||
fChildFocus(nullptr), | |||
fVisible(false), | |||
@@ -75,6 +75,12 @@ public: | |||
if (kView == nullptr) | |||
return; | |||
// we can't have both | |||
if (parent != nullptr) | |||
{ | |||
assert(parentId != 0); | |||
} | |||
puglSetHandle(kView, this); | |||
puglSetDisplayFunc(kView, onDisplayCallback); | |||
puglSetKeyboardFunc(kView, onKeyboardCallback); | |||
@@ -85,21 +91,13 @@ public: | |||
puglSetReshapeFunc(kView, onReshapeCallback); | |||
puglSetCloseFunc(kView, onCloseCallback); | |||
#if DISTRHO_OS_LINUX | |||
PuglInternals* impl = kView->impl; | |||
#if DISTRHO_OS_WINDOWS | |||
//hwnd = impl->hwnd; | |||
if (parent != nullptr) | |||
{ | |||
//PuglInternals* parentImpl = parent->kView->impl; | |||
//SetParent(parentImpl->hwnd, hwnd); | |||
} | |||
#elif DISTRHO_OS_LINUX | |||
xDisplay = impl->display; | |||
xWindow = impl->win; | |||
if (parent != nullptr) | |||
if (parent != nullptr && parentId == 0) | |||
{ | |||
PuglInternals* parentImpl = parent->kView->impl; | |||
bool parentWasVisible = parent->isVisible(); | |||
@@ -232,18 +230,10 @@ public: | |||
UpdateWindow(hwnd); | |||
#elif DISTRHO_OS_LINUX | |||
XEvent event; | |||
if (yesNo) | |||
{ | |||
XMapRaised(xDisplay, xWindow); | |||
XIfEvent(xDisplay, &event, &isMapNotify, (XPointer)&xWindow); | |||
} | |||
else | |||
{ | |||
XUnmapWindow(xDisplay, xWindow); | |||
XIfEvent(xDisplay, &event, &isUnmapNotify, (XPointer)&xWindow); | |||
} | |||
XFlush(xDisplay); | |||
#endif | |||
@@ -254,6 +244,24 @@ public: | |||
kApp->oneHidden(); | |||
} | |||
void setSize(unsigned int width, unsigned int height) | |||
{ | |||
#if DISTRHO_OS_LINUX | |||
XSizeHints sizeHints; | |||
memset(&sizeHints, 0, sizeof(sizeHints)); | |||
sizeHints.flags = PMinSize|PMaxSize; | |||
sizeHints.min_width = width; | |||
sizeHints.min_height = height; | |||
sizeHints.max_width = width; | |||
sizeHints.max_height = height; | |||
XSetNormalHints(xDisplay, xWindow, &sizeHints); | |||
XFlush(xDisplay); | |||
#endif | |||
repaint(); | |||
} | |||
void setWindowTitle(const char* title) | |||
{ | |||
#if DISTRHO_OS_WINDOWS | |||
@@ -269,6 +277,16 @@ public: | |||
return puglGetNativeWindow(kView); | |||
} | |||
void addWidget(Widget* widget) | |||
{ | |||
fWidgets.push_back(widget); | |||
} | |||
void removeWidget(Widget* widget) | |||
{ | |||
fWidgets.remove(widget); | |||
} | |||
protected: | |||
void onDisplay() | |||
{ | |||
@@ -277,7 +295,8 @@ protected: | |||
FOR_EACH_WIDGET(it) | |||
{ | |||
Widget* widget = *it; | |||
widget->onDisplay(); | |||
if (widget->isVisible()) | |||
widget->onDisplay(); | |||
} | |||
} | |||
@@ -289,7 +308,8 @@ protected: | |||
FOR_EACH_WIDGET(it) | |||
{ | |||
Widget* widget = *it; | |||
widget->onKeyboard(press, key); | |||
if (widget->isVisible()) | |||
widget->onKeyboard(press, key); | |||
} | |||
} | |||
@@ -301,7 +321,8 @@ protected: | |||
FOR_EACH_WIDGET(it) | |||
{ | |||
Widget* widget = *it; | |||
widget->onMouse(button, press, x, y); | |||
if (widget->isVisible()) | |||
widget->onMouse(button, press, x, y); | |||
} | |||
} | |||
@@ -313,7 +334,8 @@ protected: | |||
FOR_EACH_WIDGET(it) | |||
{ | |||
Widget* widget = *it; | |||
widget->onMotion(x, y); | |||
if (widget->isVisible()) | |||
widget->onMotion(x, y); | |||
} | |||
} | |||
@@ -325,7 +347,8 @@ protected: | |||
FOR_EACH_WIDGET(it) | |||
{ | |||
Widget* widget = *it; | |||
widget->onScroll(dx, dy); | |||
if (widget->isVisible()) | |||
widget->onScroll(dx, dy); | |||
} | |||
} | |||
@@ -337,13 +360,13 @@ protected: | |||
FOR_EACH_WIDGET(it) | |||
{ | |||
Widget* widget = *it; | |||
widget->onSpecial(press, key); | |||
if (widget->isVisible()) | |||
widget->onSpecial(press, key); | |||
} | |||
} | |||
void onReshape(int width, int height) | |||
{ | |||
FOR_EACH_WIDGET(it) | |||
{ | |||
Widget* widget = *it; | |||
@@ -482,6 +505,11 @@ void Window::setVisible(bool yesNo) | |||
kPrivate->setVisible(yesNo); | |||
} | |||
void Window::setSize(unsigned int width, unsigned int height) | |||
{ | |||
kPrivate->setSize(width, height); | |||
} | |||
void Window::setWindowTitle(const char* title) | |||
{ | |||
kPrivate->setWindowTitle(title); | |||
@@ -492,6 +520,16 @@ intptr_t Window::getWindowId() | |||
return kPrivate->getWindowId(); | |||
} | |||
void Window::addWidget(Widget* widget) | |||
{ | |||
kPrivate->addWidget(widget); | |||
} | |||
void Window::removeWidget(Widget* widget) | |||
{ | |||
kPrivate->removeWidget(widget); | |||
} | |||
// ------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |