commit 7611f937ee41e0da34716933af0039b4d2d13e54
parent 87986a6f343a937dea4f3db3a591beacea8251e2
Author: falkTX <falktx@falktx.com>
Date: Wed, 13 Oct 2021 10:15:00 +0100
Add NanoVG::globalTint, some code comments
Diffstat:
5 files changed, 64 insertions(+), 9 deletions(-)
diff --git a/dgl/ImageBase.hpp b/dgl/ImageBase.hpp
@@ -39,7 +39,7 @@ enum ImageFormat {
It is an abstract class that provides the common methods to build on top.
Cairo and OpenGL Image classes are based upon this one.
- @see Image
+ @see CairoImage, OpenGLImage
*/
class ImageBase
{
diff --git a/dgl/ImageBaseWidgets.hpp b/dgl/ImageBaseWidgets.hpp
@@ -25,13 +25,36 @@ START_NAMESPACE_DGL
// --------------------------------------------------------------------------------------------------------------------
+/**
+ DGL Image About Window class.
+
+ This is a Window attached (transient) to another Window that simply shows an Image as its content.
+ It is typically used for "about this project" style pop-up Windows.
+
+ Pressing 'Esc' or clicking anywhere on the window will automatically close it.
+
+ @see CairoImageAboutWindow, OpenGLImageAboutWindow, Window::runAsModal(bool)
+ */
template <class ImageType>
class ImageBaseAboutWindow : public StandaloneWindow
{
public:
- explicit ImageBaseAboutWindow(Window& parentWindow, const ImageType& image = ImageType());
- explicit ImageBaseAboutWindow(TopLevelWidget* parentTopLevelWidget, const ImageType& image = ImageType());
-
+ /**
+ Constructor taking an existing Window as the parent transient window and an optional image.
+ If @a image is valid, the about window size will match the image size.
+ */
+ explicit ImageBaseAboutWindow(Window& transientParentWindow, const ImageType& image = ImageType());
+
+ /**
+ Constructor taking a top-level-widget's Window as the parent transient window and an optional image.
+ If @a image is valid, the about window size will match the image size.
+ */
+ explicit ImageBaseAboutWindow(TopLevelWidget* topLevelWidget, const ImageType& image = ImageType());
+
+ /**
+ Set a new image to use as background for this window.
+ Window size will adjust to match the image size.
+ */
void setImage(const ImageType& image);
protected:
@@ -47,6 +70,16 @@ private:
// --------------------------------------------------------------------------------------------------------------------
+/**
+ DGL Image Button class.
+
+ This is a typical button, where the drawing comes from a pregenerated set of images.
+ The button can be under "normal", "hover" and "down" states, with one separate image possible for each.
+
+ The event logic for this button comes from the ButtonEventHandler class.
+
+ @see CairoImageButton, OpenGLImageButton
+ */
template <class ImageType>
class ImageBaseButton : public SubWidget,
public ButtonEventHandler
@@ -81,6 +114,18 @@ private:
// --------------------------------------------------------------------------------------------------------------------
+/**
+ DGL Image Knob class.
+
+ This is a typical knob/dial, where the drawing comes from a pregenerated image "filmstrip".
+ The knob's "filmstrip" image can be either horizontal or vertical,
+ with the number of steps automatically based on the largest value (ie, horizontal if width>height, vertical if height>width).
+ There are no different images for "hover" or "down" states.
+
+ The event logic for this knob comes from the KnobEventHandler class.
+
+ @see CairoImageKnob, OpenGLImageKnob
+ */
template <class ImageType>
class ImageBaseKnob : public SubWidget,
public KnobEventHandler
diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp
@@ -444,6 +444,11 @@ public:
*/
void globalAlpha(float alpha);
+ /**
+ Sets the color tint applied to all rendered shapes.
+ */
+ void globalTint(Color tint);
+
/* --------------------------------------------------------------------
* Transforms */
@@ -943,7 +948,6 @@ private:
inline void onDisplay() override
{
// NOTE maybe should use BaseWidget::getWindow().getScaleFactor() as 3rd arg ?
- NanoVG::reset();
NanoVG::beginFrame(BaseWidget::getWidth(), BaseWidget::getHeight());
onNanoDisplay();
NanoVG::endFrame();
diff --git a/dgl/src/ImageBaseWidgets.cpp b/dgl/src/ImageBaseWidgets.cpp
@@ -22,8 +22,8 @@ START_NAMESPACE_DGL
// --------------------------------------------------------------------------------------------------------------------
template <class ImageType>
-ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(Window& parentWindow, const ImageType& image)
- : StandaloneWindow(parentWindow.getApp(), parentWindow),
+ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(Window& transientParentWindow, const ImageType& image)
+ : StandaloneWindow(transientParentWindow.getApp(), transientParentWindow),
img(image)
{
setResizable(false);
@@ -39,8 +39,8 @@ ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(Window& parentWindow, cons
}
template <class ImageType>
-ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(TopLevelWidget* const parentTopLevelWidget, const ImageType& image)
- : StandaloneWindow(parentTopLevelWidget->getApp(), parentTopLevelWidget->getWindow()),
+ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(TopLevelWidget* const topLevelWidget, const ImageType& image)
+ : StandaloneWindow(topLevelWidget->getApp(), topLevelWidget->getWindow()),
img(image)
{
setResizable(false);
diff --git a/dgl/src/NanoVG.cpp b/dgl/src/NanoVG.cpp
@@ -513,6 +513,12 @@ void NanoVG::globalAlpha(float alpha)
nvgGlobalAlpha(fContext, alpha);
}
+void NanoVG::globalTint(Color tint)
+{
+ if (fContext != nullptr)
+ nvgGlobalTint(fContext, tint);
+}
+
// -----------------------------------------------------------------------
// Transforms