1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/**
bespoke synth, a software modular synthesizer
Copyright (C) 2021 Ryan Challinor (contact: awwbees@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
//
// RadioButton.h
// modularSynth
//
// Created by Ryan Challinor on 12/5/12.
//
//
#pragma once
#include "IPulseReceiver.h"
#include "IUIControl.h"
#include "PatchCableSource.h"
struct RadioButtonElement
{
std::string mLabel;
int mValue{ 0 };
};
enum RadioDirection
{
kRadioVertical,
kRadioHorizontal
};
class RadioButton;
class DropdownList;
class IRadioButtonListener
{
public:
virtual ~IRadioButtonListener() {}
virtual void RadioButtonUpdated(RadioButton* radio, int oldVal, double time) = 0;
};
class RadioButton : public IUIControl, public IPulseReceiver
{
public:
RadioButton(IRadioButtonListener* owner, const char* name, int x, int y, int* var, RadioDirection direction = kRadioVertical);
RadioButton(IRadioButtonListener* owner, const char* name, IUIControl* anchor, AnchorDirection anchorDirection, int* var, RadioDirection direction = kRadioVertical);
void AddLabel(const char* label, int value);
void SetLabel(const char* label, int value);
void RemoveLabel(int value);
void Render() override;
void SetMultiSelect(bool on) { mMultiSelect = on; }
void Clear();
EnumMap GetEnumMap();
void SetForcedWidth(int width) { mForcedWidth = width; }
void CopyContentsTo(DropdownList* list) const;
bool MouseMoved(float x, float y) override;
static int GetSpacing();
//IUIControl
void SetFromMidiCC(float slider, double time, bool setViaModulator) override;
float GetValueForMidiCC(float slider) const override;
void SetValue(float value, double time, bool forceUpdate = false) override;
void SetValueDirect(float value, double time) override;
float GetValue() const override;
float GetMidiValue() const override;
int GetNumValues() override { return (int)mElements.size(); }
std::string GetDisplayValue(float val) const override;
bool IsBitmask() override { return mMultiSelect; }
bool InvertScrollDirection() override { return mDirection == kRadioVertical; }
void Increment(float amount) override;
void Poll() override;
void SaveState(FileStreamOut& out) override;
void LoadState(FileStreamIn& in, bool shouldSetValue = true) override;
bool CanBeTargetedBy(PatchCableSource* source) const override;
void GetDimensions(float& width, float& height) override
{
width = mWidth;
height = mHeight;
}
ofVec2f GetOptionPosition(int optionIndex);
//IPulseReceiver
void OnPulse(double time, float velocity, int flags) override;
protected:
~RadioButton(); //protected so that it can't be created on the stack
private:
void SetIndex(int i, double time);
void CalcSliderVal();
void UpdateDimensions();
void SetValueDirect(float value, double time, bool forceUpdate);
void OnClicked(float x, float y, bool right) override;
int mWidth{ 15 };
int mHeight{ 15 };
float mElementWidth{ 8 };
std::vector<RadioButtonElement> mElements;
int* mVar;
IRadioButtonListener* mOwner;
bool mMultiSelect{ false }; //makes this... not a radio button. mVar becomes a bitmask
RadioDirection mDirection;
float mSliderVal{ 0 };
int mLastSetValue{ 0 };
int mForcedWidth{ -1 };
};
|