25 #ifndef JUCE_LIVECONSTANTEDITOR_H_INCLUDED 26 #define JUCE_LIVECONSTANTEDITOR_H_INCLUDED 28 #if JUCE_ENABLE_LIVE_CONSTANT_EDITOR && ! DOXYGEN 34 namespace LiveConstantEditor
37 double parseDouble (
const String&);
38 String intToString (
int,
bool preferHex);
41 template <
typename Type>
42 static void setFromString (Type& v,
const String& s) { v =
static_cast<Type
> (s); }
43 inline void setFromString (
char& v,
const String& s) { v = (char) parseInt (s); }
44 inline void setFromString (
unsigned char& v,
const String& s) { v = (
unsigned char) parseInt (s); }
45 inline void setFromString (
short& v,
const String& s) { v = (short) parseInt (s); }
46 inline void setFromString (
unsigned short& v,
const String& s) { v = (
unsigned short) parseInt (s); }
47 inline void setFromString (
int& v,
const String& s) { v = (int) parseInt (s); }
48 inline void setFromString (
unsigned int& v,
const String& s) { v = (
unsigned int) parseInt (s); }
49 inline void setFromString (
long& v,
const String& s) { v = (long) parseInt (s); }
50 inline void setFromString (
unsigned long& v,
const String& s) { v = (
unsigned long) parseInt (s); }
51 inline void setFromString (
int64& v,
const String& s) { v = (
int64) parseInt (s); }
53 inline void setFromString (
double& v,
const String& s) { v = parseDouble (s); }
54 inline void setFromString (
float& v,
const String& s) { v = (float) parseDouble (s); }
55 inline void setFromString (
String& v,
const String& s) { v = s; }
58 template <
typename Type>
59 inline String getAsString (
const Type& v,
bool) {
return String (v); }
60 inline String getAsString (
char v,
bool preferHex) {
return intToString ((
int) v, preferHex); }
61 inline String getAsString (
unsigned char v,
bool preferHex) {
return intToString ((
int) v, preferHex); }
62 inline String getAsString (
short v,
bool preferHex) {
return intToString ((
int) v, preferHex); }
63 inline String getAsString (
unsigned short v,
bool preferHex) {
return intToString ((
int) v, preferHex); }
64 inline String getAsString (
int v,
bool preferHex) {
return intToString ((
int) v, preferHex); }
65 inline String getAsString (
unsigned int v,
bool preferHex) {
return intToString ((
int) v, preferHex); }
66 inline String getAsString (
int64 v,
bool preferHex) {
return intToString ((
int64) v, preferHex); }
67 inline String getAsString (
uint64 v,
bool preferHex) {
return intToString ((
int64) v, preferHex); }
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>
74 inline String getAsCode (Type& v,
bool preferHex) {
return getAsString (v, preferHex); }
77 inline String getAsCode (
const char* v,
bool) {
return getAsCode (
String (v),
false); }
79 template <
typename Type>
80 inline const char* castToCharPointer (
const Type&) {
return ""; }
81 inline const char* castToCharPointer (
const String& s) {
return s.
toRawUTF8(); }
83 struct LivePropertyEditorBase;
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;
112 void resized()
override;
113 void textEditorTextChanged (
TextEditor&)
override;
114 void buttonClicked (
Button*)
override;
116 void applyNewValue (
const String&);
117 void selectOriginalValue();
118 void findOriginalValueInCode();
120 LiveValueBase& value;
135 Component* createColourEditor (LivePropertyEditorBase&);
136 Component* createIntegerSlider (LivePropertyEditorBase&);
137 Component* createFloatSlider (LivePropertyEditorBase&);
139 template <
typename Type>
struct CustomEditor {
static Component* create (LivePropertyEditorBase&) {
return nullptr; } };
140 template<>
struct CustomEditor<char> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
141 template<>
struct CustomEditor<unsigned char> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
142 template<>
struct CustomEditor<int> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
143 template<>
struct CustomEditor<unsigned int> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
144 template<>
struct CustomEditor<short> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
145 template<>
struct CustomEditor<unsigned short> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
146 template<>
struct CustomEditor<
int64> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
147 template<>
struct CustomEditor<
uint64> {
static Component* create (LivePropertyEditorBase& e) {
return createIntegerSlider (e); } };
148 template<>
struct CustomEditor<float> {
static Component* create (LivePropertyEditorBase& e) {
return createFloatSlider (e); } };
149 template<>
struct CustomEditor<double> {
static Component* create (LivePropertyEditorBase& e) {
return createFloatSlider (e); } };
150 template<>
struct CustomEditor<
Colour> {
static Component* create (LivePropertyEditorBase& e) {
return createColourEditor (e); } };
152 template <
typename Type>
153 struct LivePropertyEditor :
public LivePropertyEditorBase
155 template <
typename ValueType>
156 LivePropertyEditor (ValueType& v,
CodeDocument& d) : LivePropertyEditorBase (v, d)
158 addAndMakeVisible (customComp = CustomEditor<Type>::create (*
this));
163 template <
typename Type>
164 struct LiveValue :
public LiveValueBase
166 LiveValue (
const char* file,
int line,
const Type& initialValue)
167 : LiveValueBase (file, line), value (initialValue), originalValue (initialValue)
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;
199 template <typename Type>
200 LiveValue<Type>& getValue (
const char* file,
int line,
const Type& initialValue)
203 typedef LiveValue<Type> ValueType;
205 for (
int i = 0; i < values.size(); ++i)
207 LiveValueBase* v = values.getUnchecked(i);
209 if (v->sourceLine == line && v->sourceFile == file)
210 return *
static_cast<ValueType*
> (v);
213 ValueType* v =
new ValueType (file, line, initialValue);
223 friend class EditorWindow;
229 void addValue (LiveValueBase*);
230 void handleAsyncUpdate()
override;
233 template <
typename Type>
234 inline LiveValue<Type>& getValue (
const char* file,
int line,
const Type& initialValue)
236 return ValueList::getInstance()->getValue (file, line, initialValue);
239 inline LiveValue<String>& getValue (
const char* file,
int line,
const char* initialValue)
241 return getValue (file, line,
String (initialValue));
248 #if JUCE_ENABLE_LIVE_CONSTANT_EDITOR || DOXYGEN 295 #define JUCE_LIVE_CONSTANT(initialValue) \ 296 (juce::LiveConstantEditor::getValue (__FILE__, __LINE__ - 1, initialValue)) 298 #define JUCE_LIVE_CONSTANT(initialValue) \ 303 #endif // JUCE_LIVECONSTANTEDITOR_H_INCLUDED Definition: juce_TextEditor.h:280
Definition: juce_CPlusPlusCodeTokeniser.h:35
static String toHexString(int number)
Definition: juce_String.cpp:1925
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_Component.h:2092
Definition: juce_ScopedLock.h:59
Definition: juce_CodeDocument.h:59
Definition: juce_DeletedAtShutdown.h:40
Definition: juce_TextButton.h:36
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_AsyncUpdater.h:39
Definition: juce_CriticalSection.h:47
#define juce_DeclareSingleton(classname, doNotRecreateAfterDeletion)
Definition: juce_Label.h:34
unsigned long long uint64
Definition: juce_MathsFunctions.h:62
static String addEscapeChars(const String &s)
Definition: juce_CPlusPlusCodeTokeniserFunctions.h:632
unsigned int uint32
Definition: juce_MathsFunctions.h:51
Definition: juce_Colour.h:35
Definition: juce_CodeDocument.h:42
Definition: juce_Component.h:33
String quoted(juce_wchar quoteCharacter='"') const
Definition: juce_String.cpp:1640
Definition: juce_TextEditor.h:38
long long int64
Definition: juce_MathsFunctions.h:60
Definition: juce_ContainerDeletePolicy.h:44
uint32 getARGB() const noexcept
Definition: juce_Colour.cpp:238
Definition: juce_OwnedArray.h:55
Definition: juce_CodeEditorComponent.h:38
Definition: juce_GraphicsContext.h:42
Definition: juce_File.h:45
const char * toRawUTF8() const
Definition: juce_String.cpp:2061