26#if JUCE_ENABLE_LIVE_CONSTANT_EDITOR && ! defined (DOXYGEN)
34 int64 parseInt (String);
39 template <
typename Type>
40 static void setFromString (Type& v,
const String& s) { v =
static_cast<Type
> (s); }
42 inline void setFromString (
unsigned char& v,
const String& s) { v = (
unsigned char) parseInt (s); }
44 inline void setFromString (
unsigned short& v,
const String& s) { v = (
unsigned short) parseInt (s); }
45 inline void setFromString (
int& v,
const String& s) { v = (
int) parseInt (s); }
46 inline void setFromString (
unsigned int& v,
const String& s) { v = (
unsigned int) parseInt (s); }
48 inline void setFromString (
unsigned long& v,
const String& s) { v = (
unsigned long) parseInt (s); }
53 inline void setFromString (
bool& v,
const String& s) { v = (s ==
"true"); }
54 inline void setFromString (String& v,
const String& s) { v = s; }
55 inline void setFromString (Colour& v,
const String& s) { v = Colour ((
uint32) parseInt (s)); }
57 template <
typename Type>
58 inline String
getAsString (
const Type& v,
bool) {
return String (v); }
65 inline String
getAsString (
bool v,
bool) {
return v ?
"true" :
"false"; }
68 inline String
getAsString (Colour v,
bool) {
return intToString ((
int) v.getARGB(),
true); }
70 template <
typename Type>
struct isStringType {
enum { value = 0 }; };
71 template <>
struct isStringType<String> {
enum { value = 1 }; };
73 template <
typename Type>
77 inline String
getAsCode (
const char* v,
bool) {
return getAsCode (String (v),
false); }
79 template <
typename Type>
88 LiveValueBase (
const char* file,
int line);
89 virtual ~LiveValueBase();
91 virtual LivePropertyEditorBase* createPropertyComponent (CodeDocument&) = 0;
92 virtual String getStringValue (
bool preferHex)
const = 0;
93 virtual String getCodeValue (
bool preferHex)
const = 0;
94 virtual void setStringValue (
const String&) = 0;
95 virtual String getOriginalStringValue (
bool preferHex)
const = 0;
96 virtual bool isString()
const = 0;
98 String name, sourceFile;
107 LivePropertyEditorBase (LiveValueBase&, CodeDocument&);
109 void paint (Graphics&)
override;
110 void resized()
override;
112 void applyNewValue (
const String&);
113 void selectOriginalValue();
114 void findOriginalValueInCode();
116 LiveValueBase& value;
118 TextEditor valueEditor;
119 TextButton resetButton {
"reset" };
120 CodeDocument& document;
121 CPlusPlusCodeTokeniser tokeniser;
122 CodeEditorComponent sourceEditor;
123 CodeDocument::Position valueStart, valueEnd;
136 template <
typename Type>
struct CustomEditor {
static Component* create (LivePropertyEditorBase&) {
return nullptr; } };
137 template <>
struct CustomEditor<
char> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
138 template <>
struct CustomEditor<
unsigned char> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
139 template <>
struct CustomEditor<
int> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
140 template <>
struct CustomEditor<
unsigned int> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
141 template <>
struct CustomEditor<
short> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
142 template <>
struct CustomEditor<
unsigned short> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
143 template <>
struct CustomEditor<
int64> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
144 template <>
struct CustomEditor<
uint64> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
145 template <>
struct CustomEditor<
float> {
static Component* create (LivePropertyEditorBase& e) {
return createFloatSlider (e); } };
146 template <>
struct CustomEditor<
double> {
static Component* create (LivePropertyEditorBase& e) {
return createFloatSlider (e); } };
147 template <>
struct CustomEditor<Colour> {
static Component* create (LivePropertyEditorBase& e) {
return createColourEditor (e); } };
148 template <>
struct CustomEditor<
bool> {
static Component* create (LivePropertyEditorBase& e) {
return createBoolSlider (e); } };
150 template <
typename Type>
153 template <
typename ValueType>
154 LivePropertyEditor (ValueType& v, CodeDocument& d) : LivePropertyEditorBase (v, d)
156 customComp.reset (CustomEditor<Type>::create (*
this));
157 addAndMakeVisible (customComp.get());
162 template <
typename Type>
165 LiveValue (
const char* file,
int line,
const Type& initialValue)
166 : LiveValueBase (file, line), value (initialValue), originalValue (initialValue)
169 operator Type() const noexcept {
return value; }
170 Type
get() const noexcept {
return value; }
171 operator const char*()
const {
return castToCharPointer (value); }
173 LivePropertyEditorBase* createPropertyComponent (CodeDocument& doc)
override
175 return new LivePropertyEditor<Type> (*
this, doc);
178 String getStringValue (
bool preferHex)
const override {
return getAsString (value, preferHex); }
179 String getCodeValue (
bool preferHex)
const override {
return getAsCode (value, preferHex); }
180 String getOriginalStringValue (
bool preferHex)
const override {
return getAsString (originalValue, preferHex); }
181 void setStringValue (
const String& s)
override { setFromString (value, s); }
182 bool isString()
const override {
return isStringType<Type>::value; }
184 Type value, originalValue;
190 class JUCE_API
ValueList :
private AsyncUpdater,
191 private DeletedAtShutdown
195 ~ValueList()
override;
199 template <typename Type>
200 LiveValue<Type>& getValue (const
char* file,
int line, const Type& initialValue)
203 using ValueType = LiveValue<Type>;
205 for (
auto* v : values)
206 if (v->sourceLine == line && v->sourceFile == file)
207 return *static_cast<ValueType*> (v);
209 auto v =
new ValueType (file, line, initialValue);
215 OwnedArray<LiveValueBase> values;
216 OwnedArray<CodeDocument> documents;
217 Array<File> documentFiles;
219 Component::SafePointer<EditorWindow> editorWindow;
220 CriticalSection
lock;
222 CodeDocument& getDocument (
const File&);
223 void addValue (LiveValueBase*);
224 void handleAsyncUpdate()
override;
227 template <
typename Type>
236 return ValueList::getInstance()->getValue (file, line,
initialValue);
249#if JUCE_ENABLE_LIVE_CONSTANT_EDITOR || DOXYGEN
296 #define JUCE_LIVE_CONSTANT(initialValue) \
297 (juce::LiveConstantEditor::getValue (__FILE__, __LINE__ - 1, initialValue).get())
299 #define JUCE_LIVE_CONSTANT(initialValue) \
static bool isAbsolutePath(StringRef path)
Returns true if the string seems to be a fully-specified absolute path.
String paddedLeft(juce_wchar padCharacter, int minimumLength) const
Returns a copy of this string with the specified character repeatedly added to its beginning until th...
String quoted(juce_wchar quoteCharacter='"') const
Adds quotation marks around a string.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
auto & get(ProcessorChain< Processors... > &chain) noexcept
Non-member equivalent of ProcessorChain::get which avoids awkward member template syntax.
#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion)
Macro to generate the appropriate methods and boilerplate for a singleton class.
CriticalSection::ScopedLockType ScopedLock
Automatically locks and unlocks a CriticalSection object.
unsigned long long uint64
A platform-independent 64-bit unsigned integer type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.
static String addEscapeChars(const String &s)
Takes a string and returns a version of it where standard C++ escape sequences have been used to repl...