diff options
author | falkTX <falktx@gmail.com> | 2014-11-18 02:02:48 +0000 |
---|---|---|
committer | falkTX <falktx@gmail.com> | 2014-11-18 02:02:48 +0000 |
commit | b8471201c6b2e2ec8f2693c9e6134ef83fa24362 (patch) | |
tree | faec079ef1165032ac0bcf166fe70602ad736233 | |
parent | 9c99834f24fba894c2a282e2cea337589e015cac (diff) |
Remove CairoWidget
-rw-r--r-- | dgl/App.hpp | 3 | ||||
-rw-r--r-- | dgl/CairoWidget.hpp | 208 | ||||
-rw-r--r-- | dgl/Widget.hpp | 10 |
3 files changed, 8 insertions, 213 deletions
diff --git a/dgl/App.hpp b/dgl/App.hpp index b0622aa6..4babf1ff 100644 --- a/dgl/App.hpp +++ b/dgl/App.hpp @@ -21,6 +21,9 @@ START_NAMESPACE_DGL +// ----------------------------------------------------------------------- +// Forward class names + class Window; // ----------------------------------------------------------------------- diff --git a/dgl/CairoWidget.hpp b/dgl/CairoWidget.hpp deleted file mode 100644 index 9ebfe8ff..00000000 --- a/dgl/CairoWidget.hpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> - * - * Permission to use, copy, modify, and/or distribute this software for any purpose with - * or without fee is hereby granted, provided that the above copyright notice and this - * permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN - * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef DGL_CAIRO_WIDGET_HPP_INCLUDED -#define DGL_CAIRO_WIDGET_HPP_INCLUDED - -#include "Widget.hpp" - -#include <cairo.h> - -#include <cstdio> - -START_NAMESPACE_DGL - -// ----------------------------------------------------------------------- - -class CairoWidget : public Widget -{ -public: - CairoWidget(Window& parent) - : Widget(parent), - fContext(nullptr), - fSurface(nullptr), - fTextureId(0) - { - } - - virtual void setWidth(int width) override - { - if (fArea.getWidth() == width) - return; - - Widget::setWidth(width); - _recreateSurface(); - } - - virtual void setHeight(int height) override - { - if (fArea.getHeight() == height) - return; - - Widget::setHeight(height); - _recreateSurface(); - } - - virtual void setSize(const Size<int>& size) override - { - if (fArea.getSize() == size) - return; - - Widget::setSize(size); - _recreateSurface(); - } - - void setSize(int width, int height) - { - setSize(Size<int>(width, height)); - } - -protected: - virtual void cairoDisplay(cairo_t* const context) = 0; - -private: - void onDisplay() override - { - // wait for sizing - if (fSurface == nullptr || fContext == nullptr) - { - printf("invalid surface\n"); - return; - } - - if (fTextureId == 0) - glGenTextures(1, &fTextureId); - if (fTextureId == 0) - { - // TODO: invalidate widget - printf("invalid texture\n"); - return; - } - -#if 1 - const int x = getX(); - const int y = getY(); - const int width = getWidth(); - const int height = getHeight(); - - // draw cairo stuff - cairoDisplay(fContext); - - // get cairo surface data (RGB24) - uchar* const surfaceData = cairo_image_surface_get_data(fSurface); - - // enable GL texture - glEnable(GL_TEXTURE_RECTANGLE_ARB); - - // set texture params - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - // bind texture to surface data - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, fTextureId); - glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, surfaceData); - - // draw the texture - -// glBegin(GL_QUADS); -// glTexCoord2f(0.0f, 0.0f); -// glVertex2i(x, y); -// -// glTexCoord2f(1.0f, 0.0f); -// glVertex2i(x+width, y); -// -// glTexCoord2f(1.0f, 1.0f); -// glVertex2i(x+width, y+height); -// -// glTexCoord2f(0.0f, 1.0f); -// glVertex2i(x, y+height); -// glEnd(); - - glBegin(GL_QUADS); - //glTexCoord2i(x, y); - glTexCoord2i(0, 0); - glVertex2i(x, y); - - //glTexCoord2i(x+width, y); - glTexCoord2i(width, 0); - glVertex2i(x+width, y); - - //glTexCoord2i(x+width, y+height); - glTexCoord2i(width, height); - glVertex2i(x+width, y+height); - - //glTexCoord2i(x, y+height); - glTexCoord2i(0, height); - glVertex2i(x, y+height); - glEnd(); - - // cleanup - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - glDisable(GL_TEXTURE_RECTANGLE_ARB); -#endif - } - - void onClose() override - { - if (fContext != nullptr) - { - cairo_destroy(fContext); - fContext = nullptr; - } - - if (fSurface != nullptr) - { - cairo_surface_destroy(fSurface); - fSurface = nullptr; - } - - if (fTextureId != 0) - { - glDeleteTextures(1, &fTextureId); - fTextureId = 0; - } - } - - void _recreateSurface() - { - if (fContext != nullptr) - cairo_destroy(fContext); - - if (fSurface != nullptr) - cairo_surface_destroy(fSurface); - - fSurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, fArea.getWidth(), fArea.getHeight()); - - if (fSurface != nullptr) - fContext = cairo_create(fSurface); - else - fContext = nullptr; - } - -private: - cairo_t* fContext; - cairo_surface_t* fSurface; - GLuint fTextureId; - - DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CairoWidget) -}; - -// ----------------------------------------------------------------------- - -END_NAMESPACE_DGL - -#endif // DGL_CAIRO_WIDGET_HPP_INCLUDED diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp index 86c42d47..8c9664f7 100644 --- a/dgl/Widget.hpp +++ b/dgl/Widget.hpp @@ -26,6 +26,7 @@ START_NAMESPACE_DGL class App; class Window; +class StandaloneWindow; // ----------------------------------------------------------------------- @@ -177,22 +178,22 @@ public: /** Set width. */ - virtual void setWidth(uint width) noexcept; + void setWidth(uint width) noexcept; /** Set height. */ - virtual void setHeight(uint height) noexcept; + void setHeight(uint height) noexcept; /** Set size using @a width and @a height values. */ - virtual void setSize(uint width, uint height) noexcept; + void setSize(uint width, uint height) noexcept; /** Set size. */ - virtual void setSize(const Size<uint>& size) noexcept; + void setSize(const Size<uint>& size) noexcept; /** Get absolute X. @@ -320,7 +321,6 @@ private: Point<int> fAbsolutePos; Size<uint> fSize; - friend class CairoWidget; friend class Window; friend class StandaloneWindow; |