* Rewrite the Cairo example in matching code style * Use of ScopedPointer in the Cairo examplepull/128/head
@@ -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 |
@@ -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 |
@@ -14,12 +14,12 @@ | |||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
*/ | */ | ||||
#include "DemoWidgetBanner.h" | |||||
#include "DemoWidgetBanner.hpp" | |||||
#include "Cairo.hpp" | #include "Cairo.hpp" | ||||
#include "Window.hpp" | #include "Window.hpp" | ||||
static const char *banner = | |||||
static const char* banner = | |||||
" " | " " | ||||
" * * * * * " | " * * * * * " | ||||
" ** ** * * * * " | " ** ** * * * * " | ||||
@@ -44,19 +44,20 @@ static const char *banner = | |||||
" ***** * * " | " ***** * * " | ||||
" "; | " "; | ||||
enum { | |||||
enum | |||||
{ | |||||
rows = 23, | rows = 23, | ||||
columns = 72, | columns = 72, | ||||
}; | }; | ||||
DemoWidgetBanner::DemoWidgetBanner(Widget *group) | |||||
DemoWidgetBanner::DemoWidgetBanner(Widget* group) | |||||
: Widget(group) | : Widget(group) | ||||
{ | { | ||||
} | } | ||||
void DemoWidgetBanner::onDisplay() | void DemoWidgetBanner::onDisplay() | ||||
{ | { | ||||
cairo_t *cr = getParentWindow().getGraphicsContext().cairo; | |||||
cairo_t* cr = getParentWindow().getGraphicsContext().cairo; | |||||
Point<int> pt = getAbsolutePos(); | Point<int> pt = getAbsolutePos(); | ||||
Size<uint> sz = getSize(); | Size<uint> sz = getSize(); | ||||
@@ -70,8 +71,10 @@ void DemoWidgetBanner::onDisplay() | |||||
double radius = 0.5 * diameter; | double radius = 0.5 * diameter; | ||||
double xoff = 0; | double xoff = 0; | ||||
double yoff = 0.5 * (h - rows * diameter); | 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 cx = x + xoff + radius + c * diameter; | ||||
double cy = y + yoff + radius + r * diameter; | double cy = y + yoff + radius + r * diameter; | ||||
@@ -16,8 +16,9 @@ | |||||
#include "Widget.hpp" | #include "Widget.hpp" | ||||
class DemoWidgetBanner : public Widget { | |||||
class DemoWidgetBanner : public Widget | |||||
{ | |||||
public: | public: | ||||
explicit DemoWidgetBanner(Widget *group); | |||||
explicit DemoWidgetBanner(Widget* group); | |||||
void onDisplay() override; | void onDisplay() override; | ||||
}; | }; |
@@ -14,19 +14,19 @@ | |||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
*/ | */ | ||||
#include "DemoWidgetClickable.h" | |||||
#include "DemoWidgetClickable.hpp" | |||||
#include "Cairo.hpp" | #include "Cairo.hpp" | ||||
#include "Window.hpp" | #include "Window.hpp" | ||||
DemoWidgetClickable::DemoWidgetClickable(Widget *group) | |||||
DemoWidgetClickable::DemoWidgetClickable(Widget* group) | |||||
: Widget(group) | : Widget(group) | ||||
{ | { | ||||
} | } | ||||
void DemoWidgetClickable::onDisplay() | void DemoWidgetClickable::onDisplay() | ||||
{ | { | ||||
cairo_t *cr = getParentWindow().getGraphicsContext().cairo; | |||||
cairo_t* cr = getParentWindow().getGraphicsContext().cairo; | |||||
Point<int> pt = getAbsolutePos(); | Point<int> pt = getAbsolutePos(); | ||||
Size<uint> sz = getSize(); | Size<uint> sz = getSize(); | ||||
@@ -36,7 +36,8 @@ void DemoWidgetClickable::onDisplay() | |||||
int w = sz.getWidth(); | int w = sz.getWidth(); | ||||
int h = sz.getHeight(); | int h = sz.getHeight(); | ||||
switch (colorid_) { | |||||
switch (fColorId) | |||||
{ | |||||
case 0: | case 0: | ||||
cairo_set_source_rgb(cr, 0.75, 0.0, 0.0); | cairo_set_source_rgb(cr, 0.75, 0.0, 0.0); | ||||
break; | break; | ||||
@@ -61,17 +62,19 @@ void DemoWidgetClickable::onDisplay() | |||||
cairo_stroke(cr); | 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 w = getWidth(); | ||||
int h = getHeight(); | int h = getHeight(); | ||||
int mx = event.pos.getX(); | int mx = event.pos.getX(); | ||||
int my = event.pos.getY(); | int my = event.pos.getY(); | ||||
bool inside = mx >= 0 && my >= 0 && mx < w && my < h; | bool inside = mx >= 0 && my >= 0 && mx < w && my < h; | ||||
if (inside) { | |||||
colorid_ = (colorid_ + 1) % 3; | |||||
if (inside) | |||||
{ | |||||
fColorId = (fColorId + 1) % 3; | |||||
repaint(); | repaint(); | ||||
} | } | ||||
} | } |
@@ -16,12 +16,13 @@ | |||||
#include "Widget.hpp" | #include "Widget.hpp" | ||||
class DemoWidgetClickable : public Widget { | |||||
class DemoWidgetClickable : public Widget | |||||
{ | |||||
public: | public: | ||||
explicit DemoWidgetClickable(Widget *group); | |||||
explicit DemoWidgetClickable(Widget* group); | |||||
void onDisplay() override; | void onDisplay() override; | ||||
bool onMouse(const MouseEvent &event) override; | |||||
bool onMouse(const MouseEvent& event) override; | |||||
private: | private: | ||||
unsigned colorid_ = 0; | |||||
unsigned fColorId = 0; | |||||
}; | }; |
@@ -13,12 +13,12 @@ NAME = d_cairoui | |||||
# Files to build | # Files to build | ||||
FILES_DSP = \ | FILES_DSP = \ | ||||
PluginMain.cc | |||||
CairoExamplePlugin.cpp | |||||
FILES_UI = \ | FILES_UI = \ | ||||
DemoWidgetBanner.cc \ | |||||
DemoWidgetClickable.cc \ | |||||
PluginUI.cc | |||||
DemoWidgetBanner.cpp \ | |||||
DemoWidgetClickable.cpp \ | |||||
CairoExampleUI.cpp | |||||
# -------------------------------------------------------------- | # -------------------------------------------------------------- | ||||
# Do some magic | # Do some magic | ||||
@@ -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; | |||||
} |
@@ -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 ¶meter) 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; | |||||
}; |
@@ -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; | |||||
} |
@@ -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_; | |||||
}; |