summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJP Cimalando <jp-dev@inbox.ru>2019-01-12 23:36:50 +0100
committerFilipe Coelho <falktx@falktx.com>2019-01-12 23:36:50 +0100
commit943d9cdc1f8fba284b8063bb17e28440929590e2 (patch)
tree571a595a3aab1ea4c6cdb0094f1f06ec4039aea8
parent1f1302c319c8a0543e48b84da3918b605712730c (diff)
Cairo example (#108)
* Rewrite the Cairo example in matching code style * Use of ScopedPointer in the Cairo example
-rw-r--r--examples/CairoUI/CairoExamplePlugin.cpp89
-rw-r--r--examples/CairoUI/CairoExampleUI.cpp70
-rw-r--r--examples/CairoUI/DemoWidgetBanner.cpp (renamed from examples/CairoUI/DemoWidgetBanner.cc)17
-rw-r--r--examples/CairoUI/DemoWidgetBanner.hpp (renamed from examples/CairoUI/DemoWidgetBanner.h)5
-rw-r--r--examples/CairoUI/DemoWidgetClickable.cpp (renamed from examples/CairoUI/DemoWidgetClickable.cc)19
-rw-r--r--examples/CairoUI/DemoWidgetClickable.hpp (renamed from examples/CairoUI/DemoWidgetClickable.h)9
-rw-r--r--examples/CairoUI/Makefile8
-rw-r--r--examples/CairoUI/PluginMain.cc71
-rw-r--r--examples/CairoUI/PluginMain.h31
-rw-r--r--examples/CairoUI/PluginUI.cc56
-rw-r--r--examples/CairoUI/PluginUI.h32
11 files changed, 192 insertions, 215 deletions
diff --git a/examples/CairoUI/CairoExamplePlugin.cpp b/examples/CairoUI/CairoExamplePlugin.cpp
new file mode 100644
index 00000000..b6df8799
--- /dev/null
+++ b/examples/CairoUI/CairoExamplePlugin.cpp
@@ -0,0 +1,89 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2019 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 "DistrhoPlugin.hpp"
+
+#include <string.h>
+
+START_NAMESPACE_DISTRHO
+
+class CairoExamplePlugin : public Plugin
+{
+public:
+ CairoExamplePlugin()
+ : Plugin(0, 0, 0)
+ {
+ }
+
+ const char* getLabel() const
+ {
+ return "Cairo DPF Example";
+ }
+
+ const char* getMaker() const
+ {
+ return "Jean Pierre Cimalando";
+ }
+
+ const char* getLicense() const
+ {
+ return "ISC";
+ }
+
+ uint32_t getVersion() const
+ {
+ return 0;
+ }
+
+ int64_t getUniqueId() const
+ {
+ return 0;
+ }
+
+ void initParameter(uint32_t index, Parameter& parameter)
+ {
+ // unused
+ (void)index;
+ (void)parameter;
+ }
+
+ float getParameterValue(uint32_t index) const
+ {
+ return 0;
+
+ // unused
+ (void)index;
+ }
+
+ void setParameterValue(uint32_t index, float value)
+ {
+ // unused
+ (void)index;
+ (void)value;
+ }
+
+ void run(const float** inputs, float** outputs, uint32_t frames)
+ {
+ memcpy(outputs[0], inputs[0], frames * sizeof(float));
+ }
+};
+
+Plugin* createPlugin()
+{
+ return new CairoExamplePlugin;
+}
+
+END_NAMESPACE_DISTRHO
diff --git a/examples/CairoUI/CairoExampleUI.cpp b/examples/CairoUI/CairoExampleUI.cpp
new file mode 100644
index 00000000..cd80d10e
--- /dev/null
+++ b/examples/CairoUI/CairoExampleUI.cpp
@@ -0,0 +1,70 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2019 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 "DistrhoUI.hpp"
+#include "DemoWidgetBanner.hpp"
+#include "DemoWidgetClickable.hpp"
+#include "Window.hpp"
+
+START_NAMESPACE_DISTRHO
+
+class CairoExampleUI : public UI
+{
+public:
+ CairoExampleUI()
+ : UI(200, 200)
+ {
+ DemoWidgetClickable* widgetClickable = new DemoWidgetClickable(this);
+ fWidgetClickable = widgetClickable;
+ widgetClickable->setSize(50, 50);
+ widgetClickable->setAbsolutePos(100, 100);
+
+ DemoWidgetBanner* widgetBanner = new DemoWidgetBanner(this);
+ fWidgetBanner = widgetBanner;
+ widgetBanner->setSize(180, 80);
+ widgetBanner->setAbsolutePos(10, 10);
+ }
+
+ ~CairoExampleUI()
+ {
+ }
+
+ void onDisplay()
+ {
+ cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
+
+ cairo_set_source_rgb(cr, 1.0, 0.8, 0.5);
+ cairo_paint(cr);
+ }
+
+ void parameterChanged(uint32_t index, float value)
+ {
+ // unused
+ (void)index;
+ (void)value;
+ }
+
+private:
+ ScopedPointer<DemoWidgetClickable> fWidgetClickable;
+ ScopedPointer<DemoWidgetBanner> fWidgetBanner;
+};
+
+UI* createUI()
+{
+ return new CairoExampleUI;
+}
+
+END_NAMESPACE_DISTRHO
diff --git a/examples/CairoUI/DemoWidgetBanner.cc b/examples/CairoUI/DemoWidgetBanner.cpp
index 7ed1cd6c..56a631dd 100644
--- a/examples/CairoUI/DemoWidgetBanner.cc
+++ b/examples/CairoUI/DemoWidgetBanner.cpp
@@ -14,12 +14,12 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "DemoWidgetBanner.h"
+#include "DemoWidgetBanner.hpp"
#include "Cairo.hpp"
#include "Window.hpp"
-static const char *banner =
+static const char* banner =
" "
" * * * * * "
" ** ** * * * * "
@@ -44,19 +44,20 @@ static const char *banner =
" ***** * * "
" ";
-enum {
+enum
+{
rows = 23,
columns = 72,
};
-DemoWidgetBanner::DemoWidgetBanner(Widget *group)
+DemoWidgetBanner::DemoWidgetBanner(Widget* group)
: Widget(group)
{
}
void DemoWidgetBanner::onDisplay()
{
- cairo_t *cr = getParentWindow().getGraphicsContext().cairo;
+ cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
Point<int> pt = getAbsolutePos();
Size<uint> sz = getSize();
@@ -70,8 +71,10 @@ void DemoWidgetBanner::onDisplay()
double radius = 0.5 * diameter;
double xoff = 0;
double yoff = 0.5 * (h - rows * diameter);
- for (int r = 0; r < rows; ++r) {
- for (int c = 0; c < columns; ++c) {
+ for (int r = 0; r < rows; ++r)
+ {
+ for (int c = 0; c < columns; ++c)
+ {
double cx = x + xoff + radius + c * diameter;
double cy = y + yoff + radius + r * diameter;
diff --git a/examples/CairoUI/DemoWidgetBanner.h b/examples/CairoUI/DemoWidgetBanner.hpp
index f6cbe442..86ad496a 100644
--- a/examples/CairoUI/DemoWidgetBanner.h
+++ b/examples/CairoUI/DemoWidgetBanner.hpp
@@ -16,8 +16,9 @@
#include "Widget.hpp"
-class DemoWidgetBanner : public Widget {
+class DemoWidgetBanner : public Widget
+{
public:
- explicit DemoWidgetBanner(Widget *group);
+ explicit DemoWidgetBanner(Widget* group);
void onDisplay() override;
};
diff --git a/examples/CairoUI/DemoWidgetClickable.cc b/examples/CairoUI/DemoWidgetClickable.cpp
index 4af38f95..98ad4d6c 100644
--- a/examples/CairoUI/DemoWidgetClickable.cc
+++ b/examples/CairoUI/DemoWidgetClickable.cpp
@@ -14,19 +14,19 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "DemoWidgetClickable.h"
+#include "DemoWidgetClickable.hpp"
#include "Cairo.hpp"
#include "Window.hpp"
-DemoWidgetClickable::DemoWidgetClickable(Widget *group)
+DemoWidgetClickable::DemoWidgetClickable(Widget* group)
: Widget(group)
{
}
void DemoWidgetClickable::onDisplay()
{
- cairo_t *cr = getParentWindow().getGraphicsContext().cairo;
+ cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
Point<int> pt = getAbsolutePos();
Size<uint> sz = getSize();
@@ -36,7 +36,8 @@ void DemoWidgetClickable::onDisplay()
int w = sz.getWidth();
int h = sz.getHeight();
- switch (colorid_) {
+ switch (fColorId)
+ {
case 0:
cairo_set_source_rgb(cr, 0.75, 0.0, 0.0);
break;
@@ -61,17 +62,19 @@ void DemoWidgetClickable::onDisplay()
cairo_stroke(cr);
}
-bool DemoWidgetClickable::onMouse(const MouseEvent &event)
+bool DemoWidgetClickable::onMouse(const MouseEvent& event)
{
- if (event.press) {
+ if (event.press)
+ {
int w = getWidth();
int h = getHeight();
int mx = event.pos.getX();
int my = event.pos.getY();
bool inside = mx >= 0 && my >= 0 && mx < w && my < h;
- if (inside) {
- colorid_ = (colorid_ + 1) % 3;
+ if (inside)
+ {
+ fColorId = (fColorId + 1) % 3;
repaint();
}
}
diff --git a/examples/CairoUI/DemoWidgetClickable.h b/examples/CairoUI/DemoWidgetClickable.hpp
index 39b6afc6..425e773b 100644
--- a/examples/CairoUI/DemoWidgetClickable.h
+++ b/examples/CairoUI/DemoWidgetClickable.hpp
@@ -16,12 +16,13 @@
#include "Widget.hpp"
-class DemoWidgetClickable : public Widget {
+class DemoWidgetClickable : public Widget
+{
public:
- explicit DemoWidgetClickable(Widget *group);
+ explicit DemoWidgetClickable(Widget* group);
void onDisplay() override;
- bool onMouse(const MouseEvent &event) override;
+ bool onMouse(const MouseEvent& event) override;
private:
- unsigned colorid_ = 0;
+ unsigned fColorId = 0;
};
diff --git a/examples/CairoUI/Makefile b/examples/CairoUI/Makefile
index fc339040..5a954bdb 100644
--- a/examples/CairoUI/Makefile
+++ b/examples/CairoUI/Makefile
@@ -13,12 +13,12 @@ NAME = d_cairoui
# Files to build
FILES_DSP = \
- PluginMain.cc
+ CairoExamplePlugin.cpp
FILES_UI = \
- DemoWidgetBanner.cc \
- DemoWidgetClickable.cc \
- PluginUI.cc
+ DemoWidgetBanner.cpp \
+ DemoWidgetClickable.cpp \
+ CairoExampleUI.cpp
# --------------------------------------------------------------
# Do some magic
diff --git a/examples/CairoUI/PluginMain.cc b/examples/CairoUI/PluginMain.cc
deleted file mode 100644
index 5d9cf12f..00000000
--- a/examples/CairoUI/PluginMain.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2019 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 "PluginMain.h"
-#include <string.h>
-
-ExamplePlugin::ExamplePlugin()
- : Plugin(0, 0, 0)
-{
-}
-
-const char *ExamplePlugin::getLabel() const
-{
- return "Cairo DPF Example";
-}
-
-const char *ExamplePlugin::getMaker() const
-{
- return "Jean Pierre Cimalando";
-}
-
-const char *ExamplePlugin::getLicense() const
-{
- return "ISC";
-}
-
-uint32_t ExamplePlugin::getVersion() const
-{
- return 0;
-}
-
-int64_t ExamplePlugin::getUniqueId() const
-{
- return 0;
-}
-
-void ExamplePlugin::initParameter(uint32_t, Parameter &)
-{
-}
-
-float ExamplePlugin::getParameterValue(uint32_t) const
-{
- return 0;
-}
-
-void ExamplePlugin::setParameterValue(uint32_t, float)
-{
-}
-
-void ExamplePlugin::run(const float **inputs, float **outputs, uint32_t frames)
-{
- memcpy(outputs[0], inputs[0], frames * sizeof(float));
-}
-
-Plugin *DISTRHO::createPlugin()
-{
- return new ExamplePlugin;
-}
diff --git a/examples/CairoUI/PluginMain.h b/examples/CairoUI/PluginMain.h
deleted file mode 100644
index c444bc21..00000000
--- a/examples/CairoUI/PluginMain.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2019 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 "DistrhoPlugin.hpp"
-
-class ExamplePlugin : public Plugin {
-public:
- ExamplePlugin();
- const char *getLabel() const override;
- const char *getMaker() const override;
- const char *getLicense() const override;
- uint32_t getVersion() const override;
- int64_t getUniqueId() const override;
- void initParameter(uint32_t index, Parameter &parameter) override;
- float getParameterValue(uint32_t index) const override;
- void setParameterValue(uint32_t index, float value) override;
- void run(const float **inputs, float **outputs, uint32_t frames) override;
-};
diff --git a/examples/CairoUI/PluginUI.cc b/examples/CairoUI/PluginUI.cc
deleted file mode 100644
index 8b666f3e..00000000
--- a/examples/CairoUI/PluginUI.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2019 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 "PluginUI.h"
-#include "DemoWidgetClickable.h"
-#include "DemoWidgetBanner.h"
-
-#include "Window.hpp"
-
-ExampleUI::ExampleUI()
- : UI(200, 200)
-{
- DemoWidgetClickable *widget_clickable = new DemoWidgetClickable(this);
- widget_clickable_.reset(widget_clickable);
- widget_clickable->setSize(50, 50);
- widget_clickable->setAbsolutePos(100, 100);
-
- DemoWidgetBanner *widget_banner = new DemoWidgetBanner(this);
- widget_banner_.reset(widget_banner);
- widget_banner->setSize(180, 80);
- widget_banner->setAbsolutePos(10, 10);
-}
-
-ExampleUI::~ExampleUI()
-{
-}
-
-void ExampleUI::onDisplay()
-{
- cairo_t *cr = getParentWindow().getGraphicsContext().cairo;
-
- cairo_set_source_rgb(cr, 1.0, 0.8, 0.5);
- cairo_paint(cr);
-}
-
-void ExampleUI::parameterChanged(uint32_t, float)
-{
-}
-
-UI *DISTRHO::createUI()
-{
- return new ExampleUI;
-}
diff --git a/examples/CairoUI/PluginUI.h b/examples/CairoUI/PluginUI.h
deleted file mode 100644
index d296c46f..00000000
--- a/examples/CairoUI/PluginUI.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2019 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 "DistrhoUI.hpp"
-#include <memory>
-class DemoWidgetClickable;
-class DemoWidgetBanner;
-
-class ExampleUI : public UI {
-public:
- ExampleUI();
- ~ExampleUI();
- void onDisplay() override;
- void parameterChanged(uint32_t index, float value) override;
-
-private:
- std::unique_ptr<DemoWidgetClickable> widget_clickable_;
- std::unique_ptr<DemoWidgetBanner> widget_banner_;
- };