Browse Source

Simplify Image class, start of making Demo test Cairo+GL compat

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
077b572d56
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
13 changed files with 275 additions and 194 deletions
  1. +6
    -5
      dgl/Cairo.hpp
  2. +30
    -3
      dgl/ImageBase.hpp
  3. +17
    -35
      dgl/OpenGL.hpp
  4. +41
    -6
      dgl/src/Cairo.cpp
  5. +30
    -6
      dgl/src/ImageBase.cpp
  6. +44
    -65
      dgl/src/OpenGL.cpp
  7. +1
    -0
      dgl/src/pugl.cpp
  8. +57
    -27
      tests/Demo.cpp
  9. +16
    -21
      tests/Makefile
  10. +2
    -0
      tests/widgets/ExampleColorWidget.hpp
  11. +23
    -26
      tests/widgets/ExampleImagesWidget.hpp
  12. +6
    -0
      tests/widgets/ExampleRectanglesWidget.hpp
  13. +2
    -0
      tests/widgets/ExampleShapesWidget.hpp

+ 6
- 5
dgl/Cairo.hpp View File

@@ -55,16 +55,13 @@ public:
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);
CairoImage(const char* rawData, uint width, uint height, ImageFormat format);

/**
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);
CairoImage(const char* rawData, const Size<uint>& size, ImageFormat format);

/**
Constructor using another image data.
@@ -80,6 +77,10 @@ public:
Draw this image at position @a pos using the graphics context @a context.
*/
void drawAt(const GraphicsContext& context, const Point<int>& pos) override;

// FIXME this should not be needed
inline void drawAt(const GraphicsContext& context, int x, int y)
{ drawAt(context, Point<int>(x, y)); };
};

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


+ 30
- 3
dgl/ImageBase.hpp View File

@@ -23,6 +23,13 @@ START_NAMESPACE_DGL

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

enum ImageFormat {
kImageFormatBGR,
kImageFormatBGRA,
kImageFormatRGB,
kImageFormatRGBA,
};

/**
Base DGL Image class.

@@ -44,13 +51,13 @@ protected:
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
ImageBase(const char* const rawData, const uint width, const uint height);
ImageBase(const char* rawData, uint width, uint height, ImageFormat format);

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

/**
Constructor using another image data.
@@ -93,6 +100,25 @@ public:
*/
const char* getRawData() const noexcept;

/**
Get the image format.
*/
ImageFormat getFormat() const noexcept;

/**
Load image data from memory.
@note @a rawData must remain valid for the lifetime of this Image.
*/
void loadFromMemory(const char* rawData, uint width, uint height, ImageFormat format = kImageFormatBGRA) noexcept;

/**
Load image data from memory.
@note @a rawData must remain valid for the lifetime of this Image.
*/
virtual void loadFromMemory(const char* rawData,
const Size<uint>& size,
ImageFormat format = kImageFormatBGRA) noexcept;

/**
Draw this image at (0, 0) point using the current OpenGL context.
*/
@@ -101,7 +127,7 @@ public:
/**
Draw this image at (x, y) point using the current OpenGL context.
*/
void drawAt(const GraphicsContext& context, const int x, const int y);
void drawAt(const GraphicsContext& context, int x, int y);

/**
Draw this image at position @a pos using the current OpenGL context.
@@ -118,6 +144,7 @@ public:
protected:
const char* rawData;
Size<uint> size;
ImageFormat format;
};

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


+ 17
- 35
dgl/OpenGL.hpp View File

@@ -141,20 +141,13 @@ public:
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
OpenGLImage(const char* const rawData,
const uint width,
const uint height,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE);
OpenGLImage(const char* rawData, uint width, uint height, ImageFormat format = kImageFormatBGRA);

/**
Constructor using raw image data.
@note @a rawData must remain valid for the lifetime of this Image.
*/
OpenGLImage(const char* const rawData,
const Size<uint>& size,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE);
OpenGLImage(const char* rawData, const Size<uint>& size, ImageFormat format = kImageFormatBGRA);

/**
Constructor using another image data.
@@ -170,30 +163,9 @@ public:
Load image data from memory.
@note @a rawData must remain valid for the lifetime of this Image.
*/
void loadFromMemory(const char* const rawData,
const uint width,
const uint height,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE) noexcept;

/**
Load image data from memory.
@note @a rawData must remain valid for the lifetime of this Image.
*/
void loadFromMemory(const char* const rawData,
void loadFromMemory(const char* rawData,
const Size<uint>& size,
const GLenum format = GL_BGRA,
const GLenum type = GL_UNSIGNED_BYTE) noexcept;

/**
Get the image format.
*/
GLenum getFormat() const noexcept;

/**
Get the image type.
*/
GLenum getType() const noexcept;
ImageFormat format = kImageFormatBGRA) noexcept override;

/**
Draw this image at position @a pos using the graphics context @a context.
@@ -223,10 +195,20 @@ public:
// TODO mark as deprecated
void drawAt(const Point<int>& pos);

// FIXME this should not be needed
inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format)
{ loadFromMemory(rawData, Size<uint>(w, h), format); };
inline void drawAt(const GraphicsContext& context, int x, int y)
{ drawAt(context, Point<int>(x, y)); };

/**
Get the image type.
*/
// TODO mark as deprecated
GLenum getType() const noexcept { return GL_UNSIGNED_BYTE; }

private:
GLenum fFormat;
GLenum fType;
GLuint fTextureId;
GLuint textureId;
bool setupCalled;
};



+ 41
- 6
dgl/src/Cairo.cpp View File

@@ -15,7 +15,10 @@
*/

#include "../Cairo.hpp"

#include "SubWidgetPrivateData.hpp"
#include "TopLevelWidgetPrivateData.hpp"
#include "WidgetPrivateData.hpp"
#include "WindowPrivateData.hpp"

START_NAMESPACE_DGL
@@ -124,14 +127,14 @@ template class Rectangle<ushort>;
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 uint width, const uint height, const ImageFormat format)
: ImageBase(rawData, width, height, format) {}

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

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

CairoImage::~CairoImage()
{
@@ -171,7 +174,32 @@ void SubWidget::PrivateData::display(const uint width, const uint height, const

cairo_set_matrix(cr, &matrix);

// displaySubWidgets(width, height, autoScaleFactor);
selfw->pData->displaySubWidgets(width, height, autoScaleFactor);
}

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

void TopLevelWidget::PrivateData::display()
{
const Size<uint> size(window.getSize());
const uint width = size.getWidth();
const uint height = size.getHeight();

const double autoScaleFactor = window.pData->autoScaleFactor;

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

// main widget drawing
self->onDisplay();

// now draw subwidgets if there are any
selfw->pData->displaySubWidgets(width, height, autoScaleFactor);
}

// -----------------------------------------------------------------------
@@ -186,3 +214,10 @@ const GraphicsContext& Window::PrivateData::getGraphicsContext() const noexcept
// -----------------------------------------------------------------------

END_NAMESPACE_DGL

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

#include "ImageBaseWidgets.cpp"

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

+ 30
- 6
dgl/src/ImageBase.cpp View File

@@ -23,19 +23,23 @@ START_NAMESPACE_DGL

ImageBase::ImageBase()
: rawData(nullptr),
size(0, 0) {}
size(0, 0),
format(kImageFormatBGRA) {}

ImageBase::ImageBase(const char* const rdata, const uint width, const uint height)
ImageBase::ImageBase(const char* const rdata, const uint width, const uint height, const ImageFormat fmt)
: rawData(rdata),
size(width, height) {}
size(width, height),
format(fmt) {}

ImageBase::ImageBase(const char* const rdata, const Size<uint>& s)
ImageBase::ImageBase(const char* const rdata, const Size<uint>& s, const ImageFormat fmt)
: rawData(rdata),
size(s) {}
size(s),
format(fmt) {}

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

// --------------------------------------------------------------------------------------------------------------------
// public methods
@@ -72,6 +76,26 @@ const char* ImageBase::getRawData() const noexcept
return rawData;
}

ImageFormat ImageBase::getFormat() const noexcept
{
return format;
}

void ImageBase::loadFromMemory(const char* const rawData,
const uint width,
const uint height,
const ImageFormat format) noexcept
{
loadFromMemory(rawData, Size<uint>(width, height), format);
}

void ImageBase::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
{
rawData = rdata;
size = s;
format = fmt;
}

void ImageBase::draw(const GraphicsContext& context)
{
drawAt(context, Point<int>(0, 0));


+ 44
- 65
dgl/src/OpenGL.cpp View File

@@ -171,6 +171,23 @@ template class Rectangle<ushort>;

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

static GLenum asOpenGLImageFormat(const ImageFormat format)
{
switch (format)
{
case kImageFormatBGR:
return GL_BGR;
case kImageFormatBGRA:
return GL_BGRA;
case kImageFormatRGB:
return GL_RGB;
case kImageFormatRGBA:
return GL_RGBA;
}

return GL_BGRA;
}

static void setupOpenGLImage(const OpenGLImage& image, GLuint textureId)
{
DISTRHO_SAFE_ASSERT_RETURN(image.isValid(),);
@@ -192,7 +209,7 @@ static void setupOpenGLImage(const OpenGLImage& image, GLuint textureId)
static_cast<GLsizei>(image.getWidth()),
static_cast<GLsizei>(image.getHeight()),
0,
image.getFormat(), image.getType(), image.getRawData());
asOpenGLImageFormat(image.getFormat()), GL_UNSIGNED_BYTE, image.getRawData());

glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
@@ -200,85 +217,52 @@ static void setupOpenGLImage(const OpenGLImage& image, GLuint textureId)

OpenGLImage::OpenGLImage()
: ImageBase(),
fFormat(0),
fType(0),
fTextureId(0),
textureId(0),
setupCalled(false)
{
glGenTextures(1, &fTextureId);
DISTRHO_SAFE_ASSERT(fTextureId != 0);
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
}

OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint height, const GLenum format, const GLenum type)
: ImageBase(rawData, width, height),
fFormat(format),
fType(type),
fTextureId(0),
OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint height, const ImageFormat format)
: ImageBase(rawData, width, height, format),
textureId(0),
setupCalled(false)
{
glGenTextures(1, &fTextureId);
DISTRHO_SAFE_ASSERT(fTextureId != 0);
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
}

OpenGLImage::OpenGLImage(const char* const rawData, const Size<uint>& size, const GLenum format, const GLenum type)
: ImageBase(rawData, size),
fFormat(format),
fType(type),
fTextureId(0),
OpenGLImage::OpenGLImage(const char* const rawData, const Size<uint>& size, const ImageFormat format)
: ImageBase(rawData, size, format),
textureId(0),
setupCalled(false)
{
glGenTextures(1, &fTextureId);
DISTRHO_SAFE_ASSERT(fTextureId != 0);
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
}

OpenGLImage::OpenGLImage(const OpenGLImage& image)
: ImageBase(image),
fFormat(image.fFormat),
fType(image.fType),
fTextureId(0),
textureId(0),
setupCalled(false)
{
glGenTextures(1, &fTextureId);
DISTRHO_SAFE_ASSERT(fTextureId != 0);
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
}

OpenGLImage::~OpenGLImage()
{
if (fTextureId != 0)
glDeleteTextures(1, &fTextureId);
if (textureId != 0)
glDeleteTextures(1, &textureId);
}

void OpenGLImage::loadFromMemory(const char* const rawData,
const uint width,
const uint height,
const GLenum format,
const GLenum type) noexcept
void OpenGLImage::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
{
loadFromMemory(rawData, Size<uint>(width, height), format, type);
}

void OpenGLImage::loadFromMemory(const char* const rdata,
const Size<uint>& s,
const GLenum format,
const GLenum type) noexcept
{
rawData = rdata;
size = s;
fFormat = format;
fType = type;
ImageBase::loadFromMemory(rdata, s, fmt);
setupCalled = false;
}

GLenum OpenGLImage::getFormat() const noexcept
{
return fFormat;
}

GLenum OpenGLImage::getType() const noexcept
{
return fType;
}

void OpenGLImage::drawAt(const GraphicsContext&, const Point<int>& pos)
{
drawAt(pos);
@@ -288,8 +272,7 @@ OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept
{
rawData = image.rawData;
size = image.size;
fFormat = image.fFormat;
fType = image.fType;
format = image.format;
setupCalled = false;
return *this;
}
@@ -306,17 +289,17 @@ void OpenGLImage::drawAt(const int x, const int y)

void OpenGLImage::drawAt(const Point<int>& pos)
{
if (fTextureId == 0 || isInvalid())
if (textureId == 0 || isInvalid())
return;

if (! setupCalled)
{
setupOpenGLImage(*this, fTextureId);
setupOpenGLImage(*this, textureId);
setupCalled = true;
}

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, fTextureId);
glBindTexture(GL_TEXTURE_2D, textureId);

glBegin(GL_QUADS);

@@ -353,6 +336,8 @@ void ImageBaseAboutWindow<OpenGLImage>::onDisplay()
img.draw();
}

template class ImageBaseAboutWindow<OpenGLImage>;

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

void SubWidget::PrivateData::display(const uint width, const uint height, const double autoScaleFactor)
@@ -444,10 +429,4 @@ END_NAMESPACE_DGL

#include "ImageBaseWidgets.cpp"

START_NAMESPACE_DGL

template class ImageBaseAboutWindow<OpenGLImage>;

END_NAMESPACE_DGL

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

+ 1
- 0
dgl/src/pugl.cpp View File

@@ -72,6 +72,7 @@ START_NAMESPACE_DGL
#elif defined(DISTRHO_OS_WINDOWS)
#else
# include "pugl-upstream/src/x11.c"
# include "pugl-upstream/src/x11_stub.c"
# ifdef DGL_CAIRO
# include "pugl-upstream/src/x11_cairo.c"
# endif


+ 57
- 27
tests/Demo.cpp View File

@@ -14,33 +14,49 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef DGL_OPENGL
#error OpenGL build required for Demo
#endif
// #ifndef DGL_OPENGL
// #error OpenGL build required for Demo
// #endif

#include "tests.hpp"

// TODO backend agnostic
#include "../dgl/OpenGL.hpp"

#include "widgets/ExampleColorWidget.hpp"
#include "widgets/ExampleImagesWidget.hpp"
#include "widgets/ExampleRectanglesWidget.hpp"
#include "widgets/ExampleTextWidget.hpp"
#include "widgets/ExampleShapesWidget.hpp"
#ifdef DGL_OPENGL
#include "widgets/ExampleTextWidget.hpp"
#endif

#include "demo_res/DemoArtwork.cpp"
#include "images_res/CatPics.cpp"

#ifdef DGL_CAIRO
#include "../dgl/Cairo.hpp"
typedef DGL_NAMESPACE::CairoImage DemoImage;
#endif
#ifdef DGL_OPENGL
#include "../dgl/OpenGL.hpp"
typedef DGL_NAMESPACE::OpenGLImage DemoImage;
#endif

START_NAMESPACE_DGL

typedef ExampleImagesWidget<SubWidget, DemoImage> ExampleImagesSubWidget;
typedef ExampleImagesWidget<TopLevelWidget, DemoImage> ExampleImagesTopLevelWidget;
typedef ExampleImagesWidget<StandaloneWindow, DemoImage> ExampleImagesStandaloneWindow;

// --------------------------------------------------------------------------------------------------------------------
// Left side tab-like widget

class LeftSideWidget : public SubWidget
{
public:
#ifdef DGL_OPENGL
static const int kPageCount = 5;
#else
static const int kPageCount = 4;
#endif

class Callback
{
@@ -55,22 +71,26 @@ public:
curPage(0),
curHover(-1)
{
#ifdef DGL_OPENGL
// for text
nvg.loadSharedResources();
#endif

using namespace DemoArtwork;
img1.loadFromMemory(ico1Data, ico1Width, ico1Height, GL_BGR);
img2.loadFromMemory(ico2Data, ico2Width, ico2Height, GL_BGR);
img3.loadFromMemory(ico3Data, ico3Width, ico2Height, GL_BGR);
img4.loadFromMemory(ico4Data, ico4Width, ico4Height, GL_BGR);
img5.loadFromMemory(ico5Data, ico5Width, ico5Height, GL_BGR);
img1.loadFromMemory(ico1Data, ico1Width, ico1Height, kImageFormatBGR);
img2.loadFromMemory(ico2Data, ico2Width, ico2Height, kImageFormatBGR);
img3.loadFromMemory(ico3Data, ico3Width, ico2Height, kImageFormatBGR);
img4.loadFromMemory(ico4Data, ico4Width, ico4Height, kImageFormatBGR);
img5.loadFromMemory(ico5Data, ico5Width, ico5Height, kImageFormatBGR);
}

protected:
void onDisplay() override
{
const GraphicsContext& context(getGraphicsContext());
const int iconSize = bgIcon.getWidth();

#if 0 /* TODO make generic */
glColor3f(0.027f, 0.027f, 0.027f);
Rectangle<uint>(0, 0, getSize()).draw();

@@ -99,15 +119,17 @@ protected:

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

const int pad = iconSize/2 - DemoArtwork::ico1Width/2;

img1.drawAt(pad, pad);
img2.drawAt(pad, pad + 3 + iconSize);
img3.drawAt(pad, pad + 6 + iconSize*2);
img4.drawAt(pad, pad + 9 + iconSize*3);
img5.drawAt(pad, pad + 12 + iconSize*4);
img1.drawAt(context, pad, pad);
img2.drawAt(context, pad, pad + 3 + iconSize);
img3.drawAt(context, pad, pad + 6 + iconSize*2);
img4.drawAt(context, pad, pad + 9 + iconSize*3);
img5.drawAt(context, pad, pad + 12 + iconSize*4);

#ifdef DGL_OPENGL
// draw some text
nvg.beginFrame(this);

@@ -120,6 +142,7 @@ protected:
nvg.textBox(15, 440, iconSize, "Look!", nullptr);

nvg.endFrame();
#endif
}

bool onMouse(const MouseEvent& ev) override
@@ -203,10 +226,12 @@ private:
int curPage, curHover;
Rectangle<double> bgIcon;
Line<int> lineSep;
OpenGLImage img1, img2, img3, img4, img5;
DemoImage img1, img2, img3, img4, img5;

#ifdef DGL_OPENGL
// for text
NanoVG nvg;
#endif
};

// --------------------------------------------------------------------------------------------------------------------
@@ -226,7 +251,9 @@ public:
wImages(this),
wRects(this),
wShapes(this),
#ifdef DGL_OPENGL
wText(this),
#endif
wLeft(this, this),
curWidget(nullptr)
{
@@ -234,16 +261,18 @@ public:
wImages.hide();
wRects.hide();
wShapes.hide();
#ifdef DGL_OPENGL
wText.hide();
// //wPerf.hide();
#endif

wColor.setAbsoluteX(kSidebarWidth);
wImages.setAbsoluteX(kSidebarWidth);
wRects.setAbsoluteX(kSidebarWidth);
wShapes.setAbsoluteX(kSidebarWidth);
#ifdef DGL_OPENGL
wText.setAbsoluteX(kSidebarWidth);
#endif
wLeft.setAbsolutePos(2, 2);
// wPerf.setAbsoluteY(5);

setSize(600, 500);
setTitle("DGL Demo");
@@ -271,9 +300,11 @@ protected:
case 3:
curWidget = &wShapes;
break;
#ifdef DGL_OPENGL
case 4:
curWidget = &wText;
break;
#endif
default:
curWidget = nullptr;
break;
@@ -299,13 +330,10 @@ protected:
wImages.setSize(size);
wRects.setSize(size);
wShapes.setSize(size);
#ifdef DGL_OPENGL
wText.setSize(size);
#endif
wLeft.setSize(kSidebarWidth-4, height-4);
//wRezHandle.setAbsoluteX(width-wRezHandle.getWidth());
//wRezHandle.setAbsoluteY(height-wRezHandle.getHeight());

// wPerf.setAbsoluteX(width-wPerf.getWidth()-5);
}

private:
@@ -313,10 +341,10 @@ private:
ExampleImagesSubWidget wImages;
ExampleRectanglesSubWidget wRects;
ExampleShapesSubWidget wShapes;
#ifdef DGL_OPENGL
ExampleTextSubWidget wText;
#endif
LeftSideWidget wLeft;
//ResizeHandle wRezHandle;
// NanoPerfWidget wPerf;

Widget* curWidget;
};
@@ -357,8 +385,10 @@ int main(int argc, char* argv[])
createAndShowExampleWidgetStandaloneWindow<ExampleRectanglesStandaloneWindow>(app);
else if (std::strcmp(argv[1], "shapes") == 0)
createAndShowExampleWidgetStandaloneWindow<ExampleShapesStandaloneWindow>(app);
#ifdef DGL_OPENGL
else if (std::strcmp(argv[1], "text") == 0)
createAndShowExampleWidgetStandaloneWindow<ExampleTextStandaloneWindow>(app);
#endif
else
d_stderr2("Invalid demo mode, must be one of: color, rectangles, shapes");
}


+ 16
- 21
tests/Makefile View File

@@ -22,11 +22,12 @@ BUILD_CXX_FLAGS += -Wno-missing-field-initializers -Wno-extra

TESTS = Application Color Point
ifeq ($(HAVE_CAIRO),true)
WTESTS = Window.cairo
TESTS += Demo.cairo
WTESTS += Window.cairo
endif
ifeq ($(HAVE_OPENGL),true)
TESTS += Demo
WTESTS = Window.opengl
TESTS += Demo.opengl
WTESTS += Window.opengl
endif
ifeq ($(HAVE_VULKAN),true)
WTESTS = Window.vulkan
@@ -88,16 +89,6 @@ clean:
@echo "Compiling $< (Cairo)"
$(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) $(CAIRO_FLAGS) -DDGL_CAIRO -c -o $@

../build/tests/Demo.cpp.o: Demo.cpp
-@mkdir -p ../build/tests
@echo "Compiling $< (OpenGL)"
$(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) $(OPENGL_FLAGS) -DDGL_OPENGL -c -o $@

../build/tests/Testing.cpp.o: Testing.cpp
-@mkdir -p ../build/tests
@echo "Compiling $< (OpenGL)"
$(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) $(OPENGL_FLAGS) -DDGL_OPENGL -c -o $@

../build/tests/%.cpp.opengl.o: %.cpp
-@mkdir -p ../build/tests
@echo "Compiling $< (OpenGL)"
@@ -119,14 +110,6 @@ clean:
@echo "Linking $*"
$(SILENT)$(CXX) $< $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(CAIRO_LIBS) -o $@

../build/tests/Demo: ../build/tests/Demo.cpp.o ../build/libdgl-opengl.a
@echo "Linking Demo"
$(SILENT)$(CXX) $^ $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(OPENGL_LIBS) -o $@

../build/tests/Testing: ../build/tests/Testing.cpp.o
@echo "Linking Testing"
$(SILENT)$(CXX) $< $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(OPENGL_LIBS) -o $@

../build/tests/%.opengl: ../build/tests/%.cpp.opengl.o
@echo "Linking $*"
$(SILENT)$(CXX) $< $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(OPENGL_LIBS) -o $@
@@ -135,6 +118,18 @@ clean:
@echo "Linking $*"
$(SILENT)$(CXX) $< $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(VULKAN_LIBS) -o $@

../build/tests/Demo.cairo: ../build/tests/Demo.cpp.cairo.o ../build/libdgl-cairo.a
@echo "Linking Demo (Cairo)"
$(SILENT)$(CXX) $^ $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(CAIRO_LIBS) -o $@

../build/tests/Demo.opengl: ../build/tests/Demo.cpp.opengl.o ../build/libdgl-opengl.a
@echo "Linking Demo (OpenGL)"
$(SILENT)$(CXX) $^ $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(OPENGL_LIBS) -o $@

../build/tests/Demo.vulkan: ../build/tests/Demo.cpp.vulkan.o ../build/libdgl-vulkan.a
@echo "Linking Demo (OpenGL)"
$(SILENT)$(CXX) $^ $(LINK_FLAGS) $(DGL_SYSTEM_LIBS) $(VULKAN_LIBS) -o $@

# ---------------------------------------------------------------------------------------------------------------------

-include $(OBJS:%.o=%.d)


+ 2
- 0
tests/widgets/ExampleColorWidget.hpp View File

@@ -108,6 +108,7 @@ protected:
{
const GraphicsContext& context(BaseWidget::getGraphicsContext());

#if 0 /* TODO make generic */
// paint bg color (in full size)
glColor3b(r, g, b);
bgFull.draw(context);
@@ -115,6 +116,7 @@ protected:
// paint inverted color (in 2/3 size)
glColor3b(100-r, 100-g, 100-b);
bgSmall.draw();
#endif
}

void onResize(const ResizeEvent& ev) override


+ 23
- 26
tests/widgets/ExampleImagesWidget.hpp View File

@@ -20,11 +20,10 @@
// ------------------------------------------------------
// DGL Stuff

#include "../../dgl/Image.hpp"
#include "../../dgl/ImageBase.hpp"
#include "../../dgl/SubWidget.hpp"
#include "../../dgl/TopLevelWidget.hpp"


// ------------------------------------------------------
// Images

@@ -35,7 +34,7 @@ START_NAMESPACE_DGL
// ------------------------------------------------------
// our widget

template <class BaseWidget>
template <class BaseWidget, class BaseImage>
class ExampleImagesWidget : public BaseWidget,
public IdleCallback
{
@@ -50,7 +49,7 @@ class ExampleImagesWidget : public BaseWidget,
int imgTop1st, imgTop2nd, imgTop3rd;
int img1x, img2x, img3y;
bool img1rev, img2rev, img3rev;
Image img1, img2, img3;
BaseImage img1, img2, img3;

public:
static constexpr const char* kExampleWidgetName = "Images";
@@ -67,9 +66,9 @@ public:
img1rev(false),
img2rev(true),
img3rev(true),
img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, GL_BGR),
img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, GL_BGR),
img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR)
img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, kImageFormatBGR),
img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, kImageFormatBGR),
img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, kImageFormatBGR)
{
BaseWidget::setSize(500, 400);

@@ -88,9 +87,9 @@ public:
img1rev(false),
img2rev(true),
img3rev(true),
img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, GL_BGR),
img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, GL_BGR),
img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR)
img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, kImageFormatBGR),
img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, kImageFormatBGR),
img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, kImageFormatBGR)
{
BaseWidget::setSize(500, 400);

@@ -109,9 +108,9 @@ public:
img1rev(false),
img2rev(true),
img3rev(true),
img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, GL_BGR),
img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, GL_BGR),
img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR)
img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, kImageFormatBGR),
img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, kImageFormatBGR),
img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, kImageFormatBGR)
{
BaseWidget::setSize(500, 400);

@@ -183,42 +182,44 @@ protected:

void onDisplay() override
{
const GraphicsContext& context(BaseWidget::getGraphicsContext());

switch (imgTop3rd)
{
case 1:
img1.drawAt(img1x, kImg1y);
img1.drawAt(context, img1x, kImg1y);
break;
case 2:
img2.drawAt(img2x, kImg2y);
img2.drawAt(context, img2x, kImg2y);
break;
case 3:
img3.drawAt(kImg3x, img3y);
img3.drawAt(context, kImg3x, img3y);
break;
};

switch (imgTop2nd)
{
case 1:
img1.drawAt(img1x, kImg1y);
img1.drawAt(context, img1x, kImg1y);
break;
case 2:
img2.drawAt(img2x, kImg2y);
img2.drawAt(context, img2x, kImg2y);
break;
case 3:
img3.drawAt(kImg3x, img3y);
img3.drawAt(context, kImg3x, img3y);
break;
};

switch (imgTop1st)
{
case 1:
img1.drawAt(img1x, kImg1y);
img1.drawAt(context, img1x, kImg1y);
break;
case 2:
img2.drawAt(img2x, kImg2y);
img2.drawAt(context, img2x, kImg2y);
break;
case 3:
img3.drawAt(kImg3x, img3y);
img3.drawAt(context, kImg3x, img3y);
break;
};
}
@@ -242,10 +243,6 @@ private:
}
};

typedef ExampleImagesWidget<SubWidget> ExampleImagesSubWidget;
typedef ExampleImagesWidget<TopLevelWidget> ExampleImagesTopLevelWidget;
typedef ExampleImagesWidget<StandaloneWindow> ExampleImagesStandaloneWindow;

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

END_NAMESPACE_DGL


+ 6
- 0
tests/widgets/ExampleRectanglesWidget.hpp View File

@@ -81,30 +81,36 @@ protected:
// 1st
r.setY(3);

#if 0 /* TODO make generic */
if (clicked[0+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);
#endif

r.draw();

// 2nd
r.setY(3 + height/3);

#if 0 /* TODO make generic */
if (clicked[3+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);
#endif

r.draw();

// 3rd
r.setY(3 + height*2/3);

#if 0 /* TODO make generic */
if (clicked[6+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);
#endif

r.draw();
}


+ 2
- 0
tests/widgets/ExampleShapesWidget.hpp View File

@@ -69,6 +69,7 @@ protected:
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
#endif

#if 0 /* TODO make generic */
glLineWidth(1.0f);
glColor3f(0.302f, 0.337f, 0.361f);
bg.draw();
@@ -92,6 +93,7 @@ protected:
glLineWidth(2.0f);
glColor3f(0.176f/4, 0.212f/4, 0.235f/4);
cir.drawOutline();
#endif
}

void onResize(const ResizeEvent& ev) override


Loading…
Cancel
Save