mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Minor fixes for Thread, ColourSelector, ToolbarButton.
This commit is contained in:
parent
16f5684bd9
commit
a64aa22af2
4 changed files with 94 additions and 61 deletions
|
|
@ -23,44 +23,7 @@
|
|||
==============================================================================
|
||||
*/
|
||||
|
||||
static ThreadLocalValue<Thread*>& getCurrentThreadHolder()
|
||||
{
|
||||
static ThreadLocalValue<Thread*> tls;
|
||||
return tls;
|
||||
}
|
||||
|
||||
void Thread::threadEntryPoint()
|
||||
{
|
||||
getCurrentThreadHolder() = this;
|
||||
|
||||
JUCE_TRY
|
||||
{
|
||||
if (threadName.isNotEmpty())
|
||||
setCurrentThreadName (threadName);
|
||||
|
||||
if (startSuspensionEvent.wait (10000))
|
||||
{
|
||||
jassert (getCurrentThreadId() == threadId);
|
||||
|
||||
if (affinityMask != 0)
|
||||
setCurrentThreadAffinityMask (affinityMask);
|
||||
|
||||
run();
|
||||
}
|
||||
}
|
||||
JUCE_CATCH_ALL_ASSERT
|
||||
|
||||
getCurrentThreadHolder().releaseCurrentThreadStorage();
|
||||
closeThreadHandle();
|
||||
}
|
||||
|
||||
// used to wrap the incoming call from the platform-specific code
|
||||
void JUCE_API juce_threadEntryPoint (void* userData)
|
||||
{
|
||||
static_cast <Thread*> (userData)->threadEntryPoint();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
Thread::Thread (const String& threadName_)
|
||||
: threadName (threadName_),
|
||||
threadHandle (nullptr),
|
||||
|
|
@ -85,6 +48,64 @@ Thread::~Thread()
|
|||
stopThread (100);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// Use a ref-counted object to hold this shared data, so that it can outlive its static
|
||||
// shared pointer when threads are still running during static shutdown.
|
||||
struct CurrentThreadHolder : public ReferenceCountedObject
|
||||
{
|
||||
CurrentThreadHolder() noexcept {}
|
||||
|
||||
typedef ReferenceCountedObjectPtr <CurrentThreadHolder> Ptr;
|
||||
ThreadLocalValue<Thread*> value;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE (CurrentThreadHolder);
|
||||
};
|
||||
|
||||
static char currentThreadHolderLock [sizeof (SpinLock)]; // (statically initialised to zeros).
|
||||
|
||||
static CurrentThreadHolder::Ptr getCurrentThreadHolder()
|
||||
{
|
||||
static CurrentThreadHolder::Ptr currentThreadHolder;
|
||||
SpinLock::ScopedLockType lock (*reinterpret_cast <SpinLock*> (currentThreadHolderLock));
|
||||
|
||||
if (currentThreadHolder == nullptr)
|
||||
currentThreadHolder = new CurrentThreadHolder();
|
||||
|
||||
return currentThreadHolder;
|
||||
}
|
||||
|
||||
void Thread::threadEntryPoint()
|
||||
{
|
||||
const CurrentThreadHolder::Ptr currentThreadHolder (getCurrentThreadHolder());
|
||||
currentThreadHolder->value = this;
|
||||
|
||||
JUCE_TRY
|
||||
{
|
||||
if (threadName.isNotEmpty())
|
||||
setCurrentThreadName (threadName);
|
||||
|
||||
if (startSuspensionEvent.wait (10000))
|
||||
{
|
||||
jassert (getCurrentThreadId() == threadId);
|
||||
|
||||
if (affinityMask != 0)
|
||||
setCurrentThreadAffinityMask (affinityMask);
|
||||
|
||||
run();
|
||||
}
|
||||
}
|
||||
JUCE_CATCH_ALL_ASSERT
|
||||
|
||||
currentThreadHolder->value.releaseCurrentThreadStorage();
|
||||
closeThreadHandle();
|
||||
}
|
||||
|
||||
// used to wrap the incoming call from the platform-specific code
|
||||
void JUCE_API juce_threadEntryPoint (void* userData)
|
||||
{
|
||||
static_cast <Thread*> (userData)->threadEntryPoint();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void Thread::startThread()
|
||||
{
|
||||
|
|
@ -120,6 +141,11 @@ bool Thread::isThreadRunning() const
|
|||
return threadHandle != nullptr;
|
||||
}
|
||||
|
||||
Thread* Thread::getCurrentThread()
|
||||
{
|
||||
return getCurrentThreadHolder()->value.get();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void Thread::signalThreadShouldExit()
|
||||
{
|
||||
|
|
@ -211,12 +237,6 @@ void Thread::notify() const
|
|||
defaultEvent.signal();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
Thread* Thread::getCurrentThread()
|
||||
{
|
||||
return *getCurrentThreadHolder();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void SpinLock::enter() const noexcept
|
||||
{
|
||||
|
|
|
|||
|
|
@ -54,6 +54,22 @@ void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
|
|||
buttonStateChanged();
|
||||
}
|
||||
|
||||
void ToolbarButton::setCurrentImage (Drawable* const newImage)
|
||||
{
|
||||
if (newImage != currentImage)
|
||||
{
|
||||
removeChildComponent (currentImage);
|
||||
currentImage = newImage;
|
||||
|
||||
if (currentImage != nullptr)
|
||||
{
|
||||
enablementChanged();
|
||||
addAndMakeVisible (currentImage);
|
||||
updateDrawable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ToolbarButton::updateDrawable()
|
||||
{
|
||||
if (currentImage != nullptr)
|
||||
|
|
@ -75,23 +91,18 @@ void ToolbarButton::enablementChanged()
|
|||
updateDrawable();
|
||||
}
|
||||
|
||||
void ToolbarButton::buttonStateChanged()
|
||||
Drawable* ToolbarButton::getImageToUse() const
|
||||
{
|
||||
Drawable* d = normalImage;
|
||||
if (getStyle() == Toolbar::textOnly)
|
||||
return nullptr;
|
||||
|
||||
if (getToggleState() && toggledOnImage != nullptr)
|
||||
d = toggledOnImage;
|
||||
return toggledOnImage;
|
||||
|
||||
if (d != currentImage)
|
||||
{
|
||||
removeChildComponent (currentImage);
|
||||
currentImage = d;
|
||||
|
||||
if (d != nullptr)
|
||||
{
|
||||
enablementChanged();
|
||||
addAndMakeVisible (d);
|
||||
updateDrawable();
|
||||
}
|
||||
}
|
||||
return normalImage;
|
||||
}
|
||||
|
||||
void ToolbarButton::buttonStateChanged()
|
||||
{
|
||||
setCurrentImage (getImageToUse());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,9 +74,9 @@ public:
|
|||
bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize,
|
||||
int& minSize, int& maxSize);
|
||||
/** @internal */
|
||||
void paintButtonArea (Graphics& g, int width, int height, bool isMouseOver, bool isMouseDown);
|
||||
void paintButtonArea (Graphics&, int width, int height, bool isMouseOver, bool isMouseDown);
|
||||
/** @internal */
|
||||
void contentAreaChanged (const Rectangle<int>& newBounds);
|
||||
void contentAreaChanged (const Rectangle<int>&);
|
||||
/** @internal */
|
||||
void buttonStateChanged();
|
||||
/** @internal */
|
||||
|
|
@ -90,6 +90,8 @@ private:
|
|||
Drawable* currentImage;
|
||||
|
||||
void updateDrawable();
|
||||
Drawable* getImageToUse() const;
|
||||
void setCurrentImage (Drawable*);
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarButton);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ void ColourSelector::paint (Graphics& g)
|
|||
Colour (0xffffffff).overlaidWith (currentColour));
|
||||
|
||||
g.setColour (Colours::white.overlaidWith (currentColour).contrasting());
|
||||
g.setFont (14.0f, true);
|
||||
g.setFont (14.0f, Font::bold);
|
||||
g.drawText (currentColour.toDisplayString ((flags & showAlphaChannel) != 0),
|
||||
previewArea.getX(), previewArea.getY(), previewArea.getWidth(), previewArea.getHeight(),
|
||||
Justification::centred, false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue