Browse Source

Start splitting some image widgets into new generic file

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
84cb9db4fd
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
10 changed files with 347 additions and 203 deletions
  1. +54
    -0
      dgl/Cairo.hpp
  2. +53
    -0
      dgl/ImageBaseWidgets.hpp
  3. +2
    -27
      dgl/ImageWidgets.hpp
  4. +1
    -0
      dgl/Makefile
  5. +9
    -1
      dgl/OpenGL.hpp
  6. +8
    -1
      dgl/StandaloneWindow.hpp
  7. +64
    -0
      dgl/src/Cairo.cpp
  8. +91
    -0
      dgl/src/ImageBaseWidgets.cpp
  9. +2
    -68
      dgl/src/ImageWidgets.cpp
  10. +63
    -106
      dgl/src/OpenGL.cpp

+ 54
- 0
dgl/Cairo.hpp View File

@@ -17,6 +17,8 @@
#ifndef DGL_CAIRO_HPP_INCLUDED
#define DGL_CAIRO_HPP_INCLUDED

#include "ImageBase.hpp"
#include "ImageBaseWidgets.hpp"
#include "SubWidget.hpp"
#include "TopLevelWidget.hpp"

@@ -34,6 +36,54 @@ struct CairoGraphicsContext : GraphicsContext
cairo_t* handle;
};

// --------------------------------------------------------------------------------------------------------------------

/**
Cairo Image class.

TODO ...
*/
class CairoImage : public ImageBase
{
public:
/**
Constructor for a null Image.
*/
CairoImage();

/**
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
CairoImage(const char* const rawData,
const uint width,
const uint height);

/**
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
CairoImage(const char* const rawData,
const Size<uint>& size);

/**
Constructor using another image data.
*/
CairoImage(const CairoImage& image);

/**
Destructor.
*/
~CairoImage() override;

/**
Draw this image at position @a pos using the graphics context @a context.
*/
void drawAt(const GraphicsContext& context, const Point<int>& pos) override;
};

// --------------------------------------------------------------------------------------------------------------------

/**
Cairo SubWidget, handy class that takes graphics context during onDisplay and passes it in a new function.
*/
@@ -78,6 +128,10 @@ protected:

// --------------------------------------------------------------------------------------------------------------------

typedef ImageBaseAboutWindow<CairoImage> CairoImageAboutWindow;

// --------------------------------------------------------------------------------------------------------------------

END_NAMESPACE_DGL

#endif

+ 53
- 0
dgl/ImageBaseWidgets.hpp View File

@@ -0,0 +1,53 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 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_IMAGE_BASE_WIDGETS_HPP_INCLUDED
#define DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED

#include "StandaloneWindow.hpp"

START_NAMESPACE_DGL

// --------------------------------------------------------------------------------------------------------------------

template <class ImageType>
class ImageBaseAboutWindow : public StandaloneWindow
{
public:
explicit ImageBaseAboutWindow(Window& parentWindow, const ImageType& image = ImageType());
explicit ImageBaseAboutWindow(TopLevelWidget* parentTopLevelWidget, const ImageType& image = ImageType());

void setImage(const ImageType& image);

protected:
void onDisplay() override;
bool onKeyboard(const KeyboardEvent&) override;
bool onMouse(const MouseEvent&) override;

// FIXME needed?
void onReshape(uint width, uint height) override;

private:
ImageType img;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseAboutWindow)
};

// --------------------------------------------------------------------------------------------------------------------

END_NAMESPACE_DGL

#endif // DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED

+ 2
- 27
dgl/ImageWidgets.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2021 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
@@ -18,38 +18,13 @@
#define DGL_IMAGE_WIDGETS_HPP_INCLUDED

#include "Image.hpp"
#include "StandaloneWindow.hpp"
#include "ImageBaseWidgets.hpp"
#include "SubWidget.hpp"

START_NAMESPACE_DGL

// -----------------------------------------------------------------------

class ImageAboutWindow : public StandaloneWindow
{
public:
explicit ImageAboutWindow(Window& parentWindow, const Image& image = Image());
explicit ImageAboutWindow(TopLevelWidget* parentTopLevelWidget, const Image& image = Image());

void setImage(const Image& image);

// TODO
void exec() {}

protected:
void onDisplay() override;
bool onKeyboard(const KeyboardEvent&) override;
bool onMouse(const MouseEvent&) override;
void onReshape(uint width, uint height) override;

private:
Image fImgBackground;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageAboutWindow)
};

// -----------------------------------------------------------------------

class ImageButton : public SubWidget
{
public:


+ 1
- 0
dgl/Makefile View File

@@ -29,6 +29,7 @@ OBJS_common = \
../build/dgl/Color.cpp.o \
../build/dgl/Geometry.cpp.o \
../build/dgl/ImageBase.cpp.o \
../build/dgl/ImageBaseWidgets.cpp.o \
../build/dgl/Resources.cpp.o \
../build/dgl/SubWidget.cpp.o \
../build/dgl/SubWidgetPrivateData.cpp.o \


+ 9
- 1
dgl/OpenGL.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2021 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
@@ -18,6 +18,7 @@
#define DGL_OPENGL_HPP_INCLUDED

#include "ImageBase.hpp"
#include "ImageBaseWidgets.hpp"

// -----------------------------------------------------------------------
// Fix OpenGL includes for Windows, based on glfw code (part 1)
@@ -241,6 +242,13 @@ private:

// -----------------------------------------------------------------------

typedef ImageBaseAboutWindow<OpenGLImage> OpenGLImageAboutWindow;

// TODO deprecated
typedef OpenGLImageAboutWindow ImageAboutWindow;

// -----------------------------------------------------------------------

END_NAMESPACE_DGL

#endif

+ 8
- 1
dgl/StandaloneWindow.hpp View File

@@ -29,12 +29,19 @@ class StandaloneWindow : public Window,
{
public:
/**
Constructor.
Constructor without parent.
*/
StandaloneWindow(Application& app)
: Window(app),
TopLevelWidget((Window&)*this) {}

/**
Constructor with parent window, typically used to run as modal.
*/
StandaloneWindow(Application& app, Window& parent)
: Window(app, parent),
TopLevelWidget((Window&)*this) {}

/**
Overloaded functions to ensure they apply to the Window class.
*/


+ 64
- 0
dgl/src/Cairo.cpp View File

@@ -63,6 +63,37 @@ void Rectangle<T>::_draw(const bool outline)
notImplemented("Rectangle::draw");
}

// -----------------------------------------------------------------------
// CairoImage

CairoImage::CairoImage()
: ImageBase() {}

CairoImage::CairoImage(const char* const rawData, const uint width, const uint height)
: ImageBase(rawData, width, height) {}

CairoImage::CairoImage(const char* const rawData, const Size<uint>& size)
: ImageBase(rawData, size) {}

CairoImage::CairoImage(const CairoImage& image)
: ImageBase(image.rawData, image.size) {}

CairoImage::~CairoImage()
{
}

void CairoImage::drawAt(const GraphicsContext&, const Point<int>&)
{
}

// -----------------------------------------------------------------------

template <>
void ImageBaseAboutWindow<CairoImage>::onDisplay()
{
img.draw(getGraphicsContext());
}

// -----------------------------------------------------------------------

void SubWidget::PrivateData::display(const uint width, const uint height, const double autoScaleFactor)
@@ -97,6 +128,39 @@ const GraphicsContext& Window::PrivateData::getGraphicsContext() const noexcept
return context;
}

// -----------------------------------------------------------------------
// Possible template data types

template class Line<double>;
template class Line<float>;
template class Line<int>;
template class Line<uint>;
template class Line<short>;
template class Line<ushort>;

template class Circle<double>;
template class Circle<float>;
template class Circle<int>;
template class Circle<uint>;
template class Circle<short>;
template class Circle<ushort>;

template class Triangle<double>;
template class Triangle<float>;
template class Triangle<int>;
template class Triangle<uint>;
template class Triangle<short>;
template class Triangle<ushort>;

template class Rectangle<double>;
template class Rectangle<float>;
template class Rectangle<int>;
template class Rectangle<uint>;
template class Rectangle<short>;
template class Rectangle<ushort>;

template class ImageBaseAboutWindow<CairoImage>;

// -----------------------------------------------------------------------

END_NAMESPACE_DGL

+ 91
- 0
dgl/src/ImageBaseWidgets.cpp View File

@@ -0,0 +1,91 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 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.
*/

#include "../ImageBaseWidgets.hpp"

START_NAMESPACE_DGL

// --------------------------------------------------------------------------------------------------------------------

template <class ImageType>
ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(Window& parentWindow, const ImageType& image)
: StandaloneWindow(parentWindow.getApp(), parentWindow),
img(image)
{
setResizable(false);
setTitle("About");

if (image.isValid())
setSize(image.getSize());
}

template <class ImageType>
ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(TopLevelWidget* const parentTopLevelWidget, const ImageType& image)
: StandaloneWindow(parentTopLevelWidget->getApp(), parentTopLevelWidget->getWindow()),
img(image)
{
setResizable(false);
setTitle("About");

if (image.isValid())
setSize(image.getSize());
}

template <class ImageType>
void ImageBaseAboutWindow<ImageType>::setImage(const ImageType& image)
{
if (img == image)
return;

img = image;
setSize(image.getSize());
}

template <class ImageType>
bool ImageBaseAboutWindow<ImageType>::onKeyboard(const KeyboardEvent& ev)
{
if (ev.press && ev.key == kCharEscape)
{
close();
return true;
}

return false;
}

template <class ImageType>
bool ImageBaseAboutWindow<ImageType>::onMouse(const MouseEvent& ev)
{
if (ev.press)
{
close();
return true;
}

return false;
}

template <class ImageType>
void ImageBaseAboutWindow<ImageType>::onReshape(uint width, uint height)
{
// FIXME needed?
TopLevelWidget::setSize(width, height);
StandaloneWindow::onReshape(width, height);
}

// --------------------------------------------------------------------------------------------------------------------

END_NAMESPACE_DGL

+ 2
- 68
dgl/src/ImageWidgets.cpp View File

@@ -15,6 +15,8 @@
*/

#include "../Image.hpp"
#include "../ImageBaseWidgets.hpp"

#include "Common.hpp"
#include "WidgetPrivateData.hpp"

@@ -25,74 +27,6 @@ START_NAMESPACE_DGL

// -----------------------------------------------------------------------

ImageAboutWindow::ImageAboutWindow(Window& parentWindow, const Image& image)
: StandaloneWindow(parentWindow.getApp()),
fImgBackground(image)
{
// TODO set transient
Window::setResizable(false);
Window::setTitle("About");

if (image.isValid())
Window::setSize(image.getSize());
}

ImageAboutWindow::ImageAboutWindow(TopLevelWidget* const parentTopLevelWidget, const Image& image)
: StandaloneWindow(parentTopLevelWidget->getApp()),
fImgBackground(image)
{
// TODO set transient
Window::setResizable(false);
Window::setTitle("About");

if (image.isValid())
Window::setSize(image.getSize());
}

void ImageAboutWindow::setImage(const Image& image)
{
if (fImgBackground == image)
return;

fImgBackground = image;
Window::setSize(image.getSize());
}

void ImageAboutWindow::onDisplay()
{
fImgBackground.draw();
}

bool ImageAboutWindow::onKeyboard(const KeyboardEvent& ev)
{
if (ev.press && ev.key == kCharEscape)
{
Window::close();
return true;
}

return false;
}

bool ImageAboutWindow::onMouse(const MouseEvent& ev)
{
if (ev.press)
{
Window::close();
return true;
}

return false;
}

void ImageAboutWindow::onReshape(uint width, uint height)
{
Widget::setSize(width, height);
Window::onReshape(width, height);
}

// -----------------------------------------------------------------------

struct ImageButton::PrivateData {
ButtonImpl impl;
Image imageNormal;


+ 63
- 106
dgl/src/OpenGL.cpp View File

@@ -15,6 +15,8 @@
*/

#include "../OpenGL.hpp"
#include "../ImageWidgets.hpp"

#include "SubWidgetPrivateData.hpp"
#include "TopLevelWidgetPrivateData.hpp"
#include "WidgetPrivateData.hpp"
@@ -110,39 +112,6 @@ void Rectangle<T>::_draw(const bool outline)
glEnd();
}

// -----------------------------------------------------------------------
// Possible template data types

#ifndef DPF_TEST_DEMO
template class Line<double>;
template class Line<float>;
template class Line<int>;
template class Line<uint>;
template class Line<short>;
template class Line<ushort>;

template class Circle<double>;
template class Circle<float>;
template class Circle<int>;
template class Circle<uint>;
template class Circle<short>;
template class Circle<ushort>;

template class Triangle<double>;
template class Triangle<float>;
template class Triangle<int>;
template class Triangle<uint>;
template class Triangle<short>;
template class Triangle<ushort>;

template class Rectangle<double>;
template class Rectangle<float>;
template class Rectangle<int>;
template class Rectangle<uint>;
template class Rectangle<short>;
template class Rectangle<ushort>;
#endif

// -----------------------------------------------------------------------

OpenGLImage::OpenGLImage()
@@ -152,13 +121,6 @@ OpenGLImage::OpenGLImage()
fTextureId(0),
setupCalled(false) {}

OpenGLImage::OpenGLImage(const OpenGLImage& image)
: ImageBase(image),
fFormat(image.fFormat),
fType(image.fType),
fTextureId(0),
setupCalled(false) {}

OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint height, const GLenum format, const GLenum type)
: ImageBase(rawData, width, height),
fFormat(format),
@@ -173,6 +135,13 @@ OpenGLImage::OpenGLImage(const char* const rawData, const Size<uint>& size, cons
fTextureId(0),
setupCalled(false) {}

OpenGLImage::OpenGLImage(const OpenGLImage& image)
: ImageBase(image),
fFormat(image.fFormat),
fType(image.fType),
fTextureId(0),
setupCalled(false) {}

OpenGLImage::~OpenGLImage()
{
if (setupCalled) {
@@ -324,72 +293,13 @@ void OpenGLImage::drawAt(const Point<int>& pos)

// -----------------------------------------------------------------------

#if 0
void Widget::PrivateData::display(const uint width,
const uint height,
const double autoScaleFactor,
const bool renderingSubWidget)
template <>
void ImageBaseAboutWindow<OpenGLImage>::onDisplay()
{
printf("Widget::PrivateData::display INIT\n");

if (/*(skipDisplay && ! renderingSubWidget) ||*/ size.isInvalid() || ! visible)
return;

bool needsDisableScissor = false;

// reset color
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

#if 0
if (/*needsFullViewport ||*/ (absolutePos.isZero() && size == Size<uint>(width, height)))
#endif
{
// full viewport size
glViewport(0,
-(height * autoScaleFactor - height),
width * autoScaleFactor,
height * autoScaleFactor);
}
#if 0
else if (needsScaling)
{
// limit viewport to widget bounds
glViewport(absolutePos.getX(),
height - self->getHeight() - absolutePos.getY(),
self->getWidth(),
self->getHeight());
}
else
{
// only set viewport pos
glViewport(absolutePos.getX() * autoScaleFactor,
-std::round((height * autoScaleFactor - height) + (absolutePos.getY() * autoScaleFactor)),
std::round(width * autoScaleFactor),
std::round(height * autoScaleFactor));

// then cut the outer bounds
glScissor(absolutePos.getX() * autoScaleFactor,
height - std::round((self->getHeight() + absolutePos.getY()) * autoScaleFactor),
std::round(self->getWidth() * autoScaleFactor),
std::round(self->getHeight() * autoScaleFactor));

glEnable(GL_SCISSOR_TEST);
needsDisableScissor = true;
}
#endif

// display widget
self->onDisplay();

if (needsDisableScissor)
{
glDisable(GL_SCISSOR_TEST);
needsDisableScissor = false;
}

displaySubWidgets(width, height, autoScaleFactor);
img.draw();
}
#endif

// -----------------------------------------------------------------------

void SubWidget::PrivateData::display(const uint width, const uint height, const double autoScaleFactor)
{
@@ -453,9 +363,9 @@ void TopLevelWidget::PrivateData::display()

// full viewport size
if (window.pData->autoScaling)
glViewport(0, -height, width, height);
else
glViewport(0, -(height * autoScaleFactor - height), width * autoScaleFactor, height * autoScaleFactor);
else
glViewport(0, -height, width, height);

// main widget drawing
self->onDisplay();
@@ -472,5 +382,52 @@ const GraphicsContext& Window::PrivateData::getGraphicsContext() const noexcept
}

// -----------------------------------------------------------------------
// Possible template data types

#ifndef DPF_TEST_DEMO
// // FIXME
// template class Line<double>;
// template class Line<float>;
// template class Line<int>;
// template class Line<uint>;
// template class Line<short>;
// template class Line<ushort>;
//
// template class Circle<double>;
// template class Circle<float>;
// template class Circle<int>;
// template class Circle<uint>;
// template class Circle<short>;
// template class Circle<ushort>;
//
// template class Triangle<double>;
// template class Triangle<float>;
// template class Triangle<int>;
// template class Triangle<uint>;
// template class Triangle<short>;
// template class Triangle<ushort>;
//
template class Rectangle<double>;
template class Rectangle<float>;
template class Rectangle<int>;
template class Rectangle<uint>;
template class Rectangle<short>;
template class Rectangle<ushort>;
#endif

// -----------------------------------------------------------------------

END_NAMESPACE_DGL

// -----------------------------------------------------------------------
// templated classes

#include "ImageBaseWidgets.cpp"

START_NAMESPACE_DGL

template class ImageBaseAboutWindow<OpenGLImage>;

END_NAMESPACE_DGL

// -----------------------------------------------------------------------

Loading…
Cancel
Save