Make UI code cairo compatible

This commit is contained in:
falkTX 2021-05-22 03:02:55 +01:00
parent 8c00761c4e
commit 3fce1eb8b0
5 changed files with 80 additions and 69 deletions

2
dpf

@ -1 +1 @@
Subproject commit 4281406e68aeef25c5e8a9dff5542f0e0eee337a Subproject commit 4e84c35a098b31b1f33d24d995e0edbe4dadf974

View File

@ -1,6 +1,6 @@
/* /*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. * DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com> * Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@ -26,17 +26,17 @@ namespace Art = DistrhoArtworkNekobi;
DistrhoUINekobi::DistrhoUINekobi() DistrhoUINekobi::DistrhoUINekobi()
: UI(Art::backgroundWidth, Art::backgroundHeight), : UI(Art::backgroundWidth, Art::backgroundHeight),
fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, GL_BGR), fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, kImageFormatBGR),
fAboutWindow(this) fAboutWindow(this)
{ {
// about // about
Image aboutImage(Art::aboutData, Art::aboutWidth, Art::aboutHeight, GL_BGR); NekoImage aboutImage(Art::aboutData, Art::aboutWidth, Art::aboutHeight, kImageFormatBGR);
fAboutWindow.setImage(aboutImage); fAboutWindow.setImage(aboutImage);
// slider // slider
Image sliderImage(Art::sliderData, Art::sliderWidth, Art::sliderHeight); NekoImage sliderImage(Art::sliderData, Art::sliderWidth, Art::sliderHeight, kImageFormatBGRA);
fSliderWaveform = new ImageSlider(this, sliderImage); fSliderWaveform = new NekoImageSlider(this, sliderImage);
fSliderWaveform->setId(DistrhoPluginNekobi::paramWaveform); fSliderWaveform->setId(DistrhoPluginNekobi::paramWaveform);
fSliderWaveform->setStartPos(133, 40); fSliderWaveform->setStartPos(133, 40);
fSliderWaveform->setEndPos(133, 60); fSliderWaveform->setEndPos(133, 60);
@ -46,10 +46,10 @@ DistrhoUINekobi::DistrhoUINekobi()
fSliderWaveform->setCallback(this); fSliderWaveform->setCallback(this);
// knobs // knobs
Image knobImage(Art::knobData, Art::knobWidth, Art::knobHeight); NekoImage knobImage(Art::knobData, Art::knobWidth, Art::knobHeight, kImageFormatBGRA);
// knob Tuning // knob Tuning
fKnobTuning = new ImageKnob(this, knobImage, ImageKnob::Vertical); fKnobTuning = new NekoImageKnob(this, knobImage, NekoImageKnob::Vertical);
fKnobTuning->setId(DistrhoPluginNekobi::paramTuning); fKnobTuning->setId(DistrhoPluginNekobi::paramTuning);
fKnobTuning->setAbsolutePos(41, 43); fKnobTuning->setAbsolutePos(41, 43);
fKnobTuning->setRange(-12.0f, 12.0f); fKnobTuning->setRange(-12.0f, 12.0f);
@ -59,7 +59,7 @@ DistrhoUINekobi::DistrhoUINekobi()
fKnobTuning->setCallback(this); fKnobTuning->setCallback(this);
// knob Cutoff // knob Cutoff
fKnobCutoff = new ImageKnob(this, knobImage, ImageKnob::Vertical); fKnobCutoff = new NekoImageKnob(this, knobImage, NekoImageKnob::Vertical);
fKnobCutoff->setId(DistrhoPluginNekobi::paramCutoff); fKnobCutoff->setId(DistrhoPluginNekobi::paramCutoff);
fKnobCutoff->setAbsolutePos(185, 43); fKnobCutoff->setAbsolutePos(185, 43);
fKnobCutoff->setRange(0.0f, 100.0f); fKnobCutoff->setRange(0.0f, 100.0f);
@ -69,7 +69,7 @@ DistrhoUINekobi::DistrhoUINekobi()
fKnobCutoff->setCallback(this); fKnobCutoff->setCallback(this);
// knob Resonance // knob Resonance
fKnobResonance = new ImageKnob(this, knobImage, ImageKnob::Vertical); fKnobResonance = new NekoImageKnob(this, knobImage, NekoImageKnob::Vertical);
fKnobResonance->setId(DistrhoPluginNekobi::paramResonance); fKnobResonance->setId(DistrhoPluginNekobi::paramResonance);
fKnobResonance->setAbsolutePos(257, 43); fKnobResonance->setAbsolutePos(257, 43);
fKnobResonance->setRange(0.0f, 95.0f); fKnobResonance->setRange(0.0f, 95.0f);
@ -79,7 +79,7 @@ DistrhoUINekobi::DistrhoUINekobi()
fKnobResonance->setCallback(this); fKnobResonance->setCallback(this);
// knob Env Mod // knob Env Mod
fKnobEnvMod = new ImageKnob(this, knobImage, ImageKnob::Vertical); fKnobEnvMod = new NekoImageKnob(this, knobImage, NekoImageKnob::Vertical);
fKnobEnvMod->setId(DistrhoPluginNekobi::paramEnvMod); fKnobEnvMod->setId(DistrhoPluginNekobi::paramEnvMod);
fKnobEnvMod->setAbsolutePos(329, 43); fKnobEnvMod->setAbsolutePos(329, 43);
fKnobEnvMod->setRange(0.0f, 100.0f); fKnobEnvMod->setRange(0.0f, 100.0f);
@ -89,7 +89,7 @@ DistrhoUINekobi::DistrhoUINekobi()
fKnobEnvMod->setCallback(this); fKnobEnvMod->setCallback(this);
// knob Decay // knob Decay
fKnobDecay = new ImageKnob(this, knobImage, ImageKnob::Vertical); fKnobDecay = new NekoImageKnob(this, knobImage, NekoImageKnob::Vertical);
fKnobDecay->setId(DistrhoPluginNekobi::paramDecay); fKnobDecay->setId(DistrhoPluginNekobi::paramDecay);
fKnobDecay->setAbsolutePos(400, 43); fKnobDecay->setAbsolutePos(400, 43);
fKnobDecay->setRange(0.0f, 100.0f); fKnobDecay->setRange(0.0f, 100.0f);
@ -99,7 +99,7 @@ DistrhoUINekobi::DistrhoUINekobi()
fKnobDecay->setCallback(this); fKnobDecay->setCallback(this);
// knob Accent // knob Accent
fKnobAccent = new ImageKnob(this, knobImage, ImageKnob::Vertical); fKnobAccent = new NekoImageKnob(this, knobImage, NekoImageKnob::Vertical);
fKnobAccent->setId(DistrhoPluginNekobi::paramAccent); fKnobAccent->setId(DistrhoPluginNekobi::paramAccent);
fKnobAccent->setAbsolutePos(473, 43); fKnobAccent->setAbsolutePos(473, 43);
fKnobAccent->setRange(0.0f, 100.0f); fKnobAccent->setRange(0.0f, 100.0f);
@ -109,7 +109,7 @@ DistrhoUINekobi::DistrhoUINekobi()
fKnobAccent->setCallback(this); fKnobAccent->setCallback(this);
// knob Volume // knob Volume
fKnobVolume = new ImageKnob(this, knobImage, ImageKnob::Vertical); fKnobVolume = new NekoImageKnob(this, knobImage, NekoImageKnob::Vertical);
fKnobVolume->setId(DistrhoPluginNekobi::paramVolume); fKnobVolume->setId(DistrhoPluginNekobi::paramVolume);
fKnobVolume->setAbsolutePos(545, 43); fKnobVolume->setAbsolutePos(545, 43);
fKnobVolume->setRange(0.0f, 100.0f); fKnobVolume->setRange(0.0f, 100.0f);
@ -119,9 +119,9 @@ DistrhoUINekobi::DistrhoUINekobi()
fKnobVolume->setCallback(this); fKnobVolume->setCallback(this);
// about button // about button
Image aboutImageNormal(Art::aboutButtonNormalData, Art::aboutButtonNormalWidth, Art::aboutButtonNormalHeight); NekoImage aboutImageNormal(Art::aboutButtonNormalData, Art::aboutButtonNormalWidth, Art::aboutButtonNormalHeight, kImageFormatBGRA);
Image aboutImageHover(Art::aboutButtonHoverData, Art::aboutButtonHoverWidth, Art::aboutButtonHoverHeight); NekoImage aboutImageHover(Art::aboutButtonHoverData, Art::aboutButtonHoverWidth, Art::aboutButtonHoverHeight, kImageFormatBGRA);
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover); fButtonAbout = new NekoImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
fButtonAbout->setAbsolutePos(505, 5); fButtonAbout->setAbsolutePos(505, 5);
fButtonAbout->setCallback(this); fButtonAbout->setCallback(this);
@ -166,48 +166,50 @@ void DistrhoUINekobi::parameterChanged(uint32_t index, float value)
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Widget Callbacks // Widget Callbacks
void DistrhoUINekobi::imageButtonClicked(ImageButton* button, int) void DistrhoUINekobi::imageButtonClicked(NekoImageButton* button, int)
{ {
if (button != fButtonAbout) if (button != fButtonAbout)
return; return;
fAboutWindow.exec(); fAboutWindow.runAsModal();
} }
void DistrhoUINekobi::imageKnobDragStarted(ImageKnob* knob) void DistrhoUINekobi::imageKnobDragStarted(NekoImageKnob* knob)
{ {
editParameter(knob->getId(), true); editParameter(knob->getId(), true);
} }
void DistrhoUINekobi::imageKnobDragFinished(ImageKnob* knob) void DistrhoUINekobi::imageKnobDragFinished(NekoImageKnob* knob)
{ {
editParameter(knob->getId(), false); editParameter(knob->getId(), false);
} }
void DistrhoUINekobi::imageKnobValueChanged(ImageKnob* knob, float value) void DistrhoUINekobi::imageKnobValueChanged(NekoImageKnob* knob, float value)
{ {
setParameterValue(knob->getId(), value); setParameterValue(knob->getId(), value);
} }
void DistrhoUINekobi::imageSliderDragStarted(ImageSlider* slider) void DistrhoUINekobi::imageSliderDragStarted(NekoImageSlider* slider)
{ {
editParameter(slider->getId(), true); editParameter(slider->getId(), true);
} }
void DistrhoUINekobi::imageSliderDragFinished(ImageSlider* slider) void DistrhoUINekobi::imageSliderDragFinished(NekoImageSlider* slider)
{ {
editParameter(slider->getId(), false); editParameter(slider->getId(), false);
} }
void DistrhoUINekobi::imageSliderValueChanged(ImageSlider* slider, float value) void DistrhoUINekobi::imageSliderValueChanged(NekoImageSlider* slider, float value)
{ {
setParameterValue(slider->getId(), value); setParameterValue(slider->getId(), value);
} }
void DistrhoUINekobi::onDisplay() void DistrhoUINekobi::onDisplay()
{ {
fImgBackground.draw(); const GraphicsContext& context(getGraphicsContext());
fNeko.draw();
fImgBackground.draw(context);
fNeko.draw(context);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
/* /*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. * DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com> * Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@ -20,24 +20,29 @@
#include "DistrhoUI.hpp" #include "DistrhoUI.hpp"
#include "ImageWidgets.hpp"
#include "DistrhoArtworkNekobi.hpp" #include "DistrhoArtworkNekobi.hpp"
#include "NekoWidget.hpp" #include "NekoWidget.hpp"
#include "ImageBaseWidgets.hpp"
using DGL_NAMESPACE::ImageAboutWindow; #ifdef DGL_CAIRO
using DGL_NAMESPACE::ImageButton; typedef DGL_NAMESPACE::CairoImage NekoImage;
using DGL_NAMESPACE::ImageKnob; #else
using DGL_NAMESPACE::ImageSlider; typedef DGL_NAMESPACE::OpenGLImage NekoImage;
#endif
typedef DGL_NAMESPACE::ImageBaseAboutWindow<NekoImage> NekoImageAboutWindow;
typedef DGL_NAMESPACE::ImageBaseButton<NekoImage> NekoImageButton;
typedef DGL_NAMESPACE::ImageBaseKnob<NekoImage> NekoImageKnob;
typedef DGL_NAMESPACE::ImageBaseSlider<NekoImage> NekoImageSlider;
START_NAMESPACE_DISTRHO START_NAMESPACE_DISTRHO
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
class DistrhoUINekobi : public UI, class DistrhoUINekobi : public UI,
public ImageButton::Callback, public NekoImageButton::Callback,
public ImageKnob::Callback, public NekoImageKnob::Callback,
public ImageSlider::Callback, public NekoImageSlider::Callback,
public IdleCallback public IdleCallback
{ {
public: public:
@ -52,13 +57,13 @@ protected:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Widget Callbacks // Widget Callbacks
void imageButtonClicked(ImageButton* button, int) override; void imageButtonClicked(NekoImageButton* button, int) override;
void imageKnobDragStarted(ImageKnob* knob) override; void imageKnobDragStarted(NekoImageKnob* knob) override;
void imageKnobDragFinished(ImageKnob* knob) override; void imageKnobDragFinished(NekoImageKnob* knob) override;
void imageKnobValueChanged(ImageKnob* knob, float value) override; void imageKnobValueChanged(NekoImageKnob* knob, float value) override;
void imageSliderDragStarted(ImageSlider* slider) override; void imageSliderDragStarted(NekoImageSlider* slider) override;
void imageSliderDragFinished(ImageSlider* slider) override; void imageSliderDragFinished(NekoImageSlider* slider) override;
void imageSliderValueChanged(ImageSlider* slider, float value) override; void imageSliderValueChanged(NekoImageSlider* slider, float value) override;
void onDisplay() override; void onDisplay() override;
@ -68,14 +73,14 @@ protected:
void idleCallback() override; void idleCallback() override;
private: private:
Image fImgBackground; NekoImage fImgBackground;
ImageAboutWindow fAboutWindow; NekoImageAboutWindow fAboutWindow;
NekoWidget fNeko; NekoWidget fNeko;
ScopedPointer<ImageButton> fButtonAbout; ScopedPointer<NekoImageButton> fButtonAbout;
ScopedPointer<ImageSlider> fSliderWaveform; ScopedPointer<NekoImageSlider> fSliderWaveform;
ScopedPointer<ImageKnob> fKnobTuning, fKnobCutoff, fKnobResonance; ScopedPointer<NekoImageKnob> fKnobTuning, fKnobCutoff, fKnobResonance;
ScopedPointer<ImageKnob> fKnobEnvMod, fKnobDecay, fKnobAccent, fKnobVolume; ScopedPointer<NekoImageKnob> fKnobEnvMod, fKnobDecay, fKnobAccent, fKnobVolume;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUINekobi) DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUINekobi)
}; };

View File

@ -22,6 +22,7 @@ FILES_UI = \
# -------------------------------------------------------------- # --------------------------------------------------------------
# Do some magic # Do some magic
# UI_TYPE = cairo
include ../../dpf/Makefile.plugins.mk include ../../dpf/Makefile.plugins.mk
# -------------------------------------------------------------- # --------------------------------------------------------------

View File

@ -1,6 +1,6 @@
/* /*
* Neko widget animation * Neko widget animation
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com> * Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@ -20,13 +20,16 @@
#include "DistrhoArtworkNekobi.hpp" #include "DistrhoArtworkNekobi.hpp"
#include "Image.hpp" #ifdef DGL_CAIRO
#include "Widget.hpp" #include "Cairo.hpp"
typedef DGL_NAMESPACE::CairoImage NekoImage;
#else
#include "OpenGL.hpp"
typedef DGL_NAMESPACE::OpenGLImage NekoImage;
#endif
#include <cstdlib> // rand #include <cstdlib> // rand
using DGL_NAMESPACE::Image;
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
class NekoWidget class NekoWidget
@ -61,7 +64,7 @@ public:
} }
} }
void draw() void draw(const GraphicsContext& context)
{ {
int x = fPos+108; int x = fPos+108;
int y = -2; int y = -2;
@ -72,7 +75,7 @@ public:
y += 12; y += 12;
} }
fCurImage->drawAt(x, y); fCurImage->drawAt(context, x, y);
} }
// returns true if needs repaint // returns true if needs repaint
@ -167,23 +170,23 @@ private:
}; };
struct Images { struct Images {
Image sit; NekoImage sit;
Image tail; NekoImage tail;
Image claw1; NekoImage claw1;
Image claw2; NekoImage claw2;
Image scratch1; NekoImage scratch1;
Image scratch2; NekoImage scratch2;
Image run1; NekoImage run1;
Image run2; NekoImage run2;
Image run3; NekoImage run3;
Image run4; NekoImage run4;
} fImages; } fImages;
int fPos; int fPos;
int fTimer; int fTimer;
Action fCurAction; Action fCurAction;
Image* fCurImage; NekoImage* fCurImage;
}; };
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------