1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-23 01:44:22 +00:00

Improved the LIVE_CONSTANT classes to allow it to work on non-GUI threads.

This commit is contained in:
jules 2013-12-05 15:46:08 +00:00
parent 585164f4ad
commit 2f72bba274
2 changed files with 63 additions and 46 deletions

View file

@ -42,7 +42,8 @@ public:
void trigger()
{
startTimer (70);
if (! isTimerRunning())
startTimer (100);
}
private:
@ -101,7 +102,6 @@ LiveValueBase::~LiveValueBase()
{
}
//==============================================================================
LivePropertyEditorBase::LivePropertyEditorBase (LiveValueBase& v, CodeDocument& d)
: value (v), document (d), sourceEditor (document, &tokeniser)
@ -286,10 +286,20 @@ public:
setVisible (false);
}
void addItem (LiveValueBase& v, CodeDocument& doc)
void updateItems (ValueList& list)
{
if (ValueListHolderComponent* l = dynamic_cast<ValueListHolderComponent*> (viewport.getViewedComponent()))
l->addItem (viewport.getMaximumVisibleWidth(), v, doc);
{
while (l->getNumChildComponents() < list.values.size())
{
if (LiveValueBase* v = list.values [l->getNumChildComponents()])
l->addItem (viewport.getMaximumVisibleWidth(), *v, list.getDocument (v->sourceFile));
else
break;
}
setVisible (true);
}
}
void resized() override
@ -304,7 +314,45 @@ public:
LookAndFeel_V3 lookAndFeel;
};
//==============================================================================
ValueList::ValueList() {}
ValueList::~ValueList() {}
ValueList& ValueList::getInstance()
{
static ValueList* i = new ValueList();
return *i;
}
void ValueList::addValue (LiveValueBase* v)
{
values.add (v);
triggerAsyncUpdate();
}
void ValueList::handleAsyncUpdate()
{
if (editorWindow == nullptr)
editorWindow = new EditorWindow (*this);
editorWindow->updateItems (*this);
}
CodeDocument& ValueList::getDocument (const File& file)
{
const int index = documentFiles.indexOf (file.getFullPathName());
if (index >= 0)
return *documents.getUnchecked (index);
CodeDocument* doc = documents.add (new CodeDocument());
documentFiles.add (file);
doc->replaceAllContent (file.loadFileAsString());
doc->clearUndoHistory();
return *doc;
}
//==============================================================================
struct ColourEditorComp : public Component,
private ChangeListener
{
@ -403,42 +451,6 @@ private:
Component* createIntegerSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, false); }
Component* createFloatSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, true); }
//==============================================================================
ValueList::ValueList()
{
}
ValueList& ValueList::getInstance()
{
static ValueList* i = new ValueList();
return *i;
}
void ValueList::addValue (LiveValueBase* v)
{
values.add (v);
if (editorWindow == nullptr)
editorWindow = new EditorWindow (*this);
editorWindow->addItem (*v, getDocument (v->sourceFile));
editorWindow->setVisible (true);
}
CodeDocument& ValueList::getDocument (const File& file)
{
const int index = documentFiles.indexOf (file.getFullPathName());
if (index >= 0)
return *documents.getUnchecked (index);
CodeDocument* doc = documents.add (new CodeDocument());
documentFiles.add (file);
doc->replaceAllContent (file.loadFileAsString());
doc->clearUndoHistory();
return *doc;
}
}
#endif

View file

@ -80,7 +80,7 @@ namespace LiveConstantEditor
struct LivePropertyEditorBase;
//==============================================================================
struct LiveValueBase
struct JUCE_API LiveValueBase
{
LiveValueBase (const char* file, int line);
virtual ~LiveValueBase();
@ -97,8 +97,8 @@ namespace LiveConstantEditor
};
//==============================================================================
struct LivePropertyEditorBase : public Component,
private TextEditor::Listener
struct JUCE_API LivePropertyEditorBase : public Component,
private TextEditor::Listener
{
LivePropertyEditorBase (LiveValueBase&, CodeDocument&);
@ -176,10 +176,13 @@ namespace LiveConstantEditor
};
//==============================================================================
class ValueList : private DeletedAtShutdown
class JUCE_API ValueList : private AsyncUpdater,
private DeletedAtShutdown
{
public:
ValueList();
~ValueList();
static ValueList& getInstance();
template<typename Type>
@ -193,8 +196,7 @@ namespace LiveConstantEditor
LiveValueBase* v = values.getUnchecked(i);
if (v->sourceLine == line && v->sourceFile == file)
if (ValueType* vt = dynamic_cast<ValueType*> (v))
return *vt;
return *static_cast<ValueType*> (v);
}
ValueType* v = new ValueType (file, line, initialValue);
@ -207,11 +209,14 @@ namespace LiveConstantEditor
OwnedArray<CodeDocument> documents;
Array<File> documentFiles;
class EditorWindow;
friend class EditorWindow;
friend struct ContainerDeletePolicy<EditorWindow>;
Component::SafePointer<EditorWindow> editorWindow;
CriticalSection lock;
CodeDocument& getDocument (const File&);
void addValue (LiveValueBase*);
void handleAsyncUpdate() override;
};
template<typename Type>