本文整理汇总了C++中WeakReference类的典型用法代码示例。如果您正苦于以下问题:C++ WeakReference类的具体用法?C++ WeakReference怎么用?C++ WeakReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WeakReference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: checkForExternalDrag
void checkForExternalDrag (DragAndDropTarget::SourceDetails& details, const Point<int>& screenPos)
{
if (! hasCheckedForExternalDrag)
{
if (Desktop::getInstance().findComponentAt (screenPos) == nullptr)
{
hasCheckedForExternalDrag = true;
StringArray files;
bool canMoveFiles = false;
if (owner.shouldDropFilesWhenDraggedExternally (details, files, canMoveFiles)
&& files.size() > 0)
{
WeakReference<Component> thisWeakRef (this);
setVisible (false);
isDoingExternalDrag = true;
if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
delete thisWeakRef.get();
return;
}
}
}
}
开发者ID:adscum,项目名称:MoogLadders,代码行数:26,代码来源:juce_DragAndDropContainer.cpp
示例2: useTimeslice
bool useTimeslice (const int elapsed)
{
if (auto* c = proxy != nullptr ? static_cast<Component*> (proxy)
: static_cast<Component*> (component))
{
msElapsed += elapsed;
double newProgress = msElapsed / (double) msTotal;
if (newProgress >= 0 && newProgress < 1.0)
{
const WeakReference<AnimationTask> weakRef (this);
newProgress = timeToDistance (newProgress);
const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
jassert (newProgress >= lastProgress);
lastProgress = newProgress;
if (delta < 1.0)
{
bool stillBusy = false;
if (isMoving)
{
left += (destination.getX() - left) * delta;
top += (destination.getY() - top) * delta;
right += (destination.getRight() - right) * delta;
bottom += (destination.getBottom() - bottom) * delta;
const Rectangle<int> newBounds (roundToInt (left),
roundToInt (top),
roundToInt (right - left),
roundToInt (bottom - top));
if (newBounds != destination)
{
c->setBounds (newBounds);
stillBusy = true;
}
}
// Check whether the animation was cancelled/deleted during
// a callback during the setBounds method
if (weakRef.wasObjectDeleted())
return false;
if (isChangingAlpha)
{
alpha += (destAlpha - alpha) * delta;
c->setAlpha ((float) alpha);
stillBusy = true;
}
if (stillBusy)
return true;
}
}
}
moveToFinalDestination();
return false;
}
开发者ID:Neknail,项目名称:JUCE,代码行数:60,代码来源:juce_ComponentAnimator.cpp
示例3: jassert
int ModalComponentManager::runEventLoopForCurrentComponent()
{
// This can only be run from the message thread!
jassert (MessageManager::getInstance()->isThisTheMessageThread());
Component* currentlyModal = getModalComponent (0);
if (currentlyModal == nullptr)
return 0;
WeakReference<Component> prevFocused (Component::getCurrentlyFocusedComponent());
int returnValue = 0;
bool finished = false;
attachCallback (currentlyModal, new ReturnValueRetriever (returnValue, finished));
JUCE_TRY
{
while (! finished)
{
if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
break;
}
}
JUCE_CATCH_EXCEPTION
if (prevFocused != nullptr)
prevFocused->grabKeyboardFocus();
return returnValue;
}
开发者ID:Amcut,项目名称:pizmidi,代码行数:31,代码来源:juce_ModalComponentManager.cpp
示例4: moveToFinalDestination
void moveToFinalDestination()
{
if (component != nullptr)
{
const WeakReference<AnimationTask> weakRef (this);
component->setAlpha ((float) destAlpha);
component->setBounds (destination);
if (! weakRef.wasObjectDeleted())
if (proxy != nullptr)
component->setVisible (destAlpha > 0);
}
}
开发者ID:Neknail,项目名称:JUCE,代码行数:13,代码来源:juce_ComponentAnimator.cpp
示例5:
ConvexHullShape& ConvexHullShape::getDefault()
{
static WeakReference<ConvexHullShape> defShape;
if (defShape.expired())
{
defShape = static_ref_cast<ConvexHullShape>(ResourceManager::getEmpty<ConvexHullShape>("jop_default_staticmeshshape").getReference());
defShape->m_shape = std::make_unique<btCapsuleShape>(0.5f, 2.f);
defShape->setPersistence(0);
}
return *defShape;
}
开发者ID:Jopnal,项目名称:Jopnal,代码行数:14,代码来源:ConvexHullShape.cpp
示例6: setter
void DropShadower::updateShadows()
{
if (reentrant)
return;
const ScopedValueSetter<bool> setter (reentrant, true, false);
if (owner == nullptr)
{
shadowWindows.clear();
return;
}
if (owner->isShowing()
&& owner->getWidth() > 0 && owner->getHeight() > 0
&& (Desktop::canUseSemiTransparentWindows() || owner->getParentComponent() != nullptr))
{
while (shadowWindows.size() < 4)
shadowWindows.add (new ShadowWindow (owner, shadow));
const int shadowEdge = jmax (shadow.offset.x, shadow.offset.y) + shadow.radius;
const int x = owner->getX();
const int y = owner->getY() - shadowEdge;
const int w = owner->getWidth();
const int h = owner->getHeight() + shadowEdge + shadowEdge;
for (int i = 4; --i >= 0;)
{
// there seem to be rare situations where the dropshadower may be deleted by
// callbacks during this loop, so use a weak ref to watch out for this..
WeakReference<Component> sw (shadowWindows[i]);
if (sw != nullptr)
{
sw->setAlwaysOnTop (owner->isAlwaysOnTop());
if (sw == nullptr)
return;
switch (i)
{
case 0: sw->setBounds (x - shadowEdge, y, shadowEdge, h); break;
case 1: sw->setBounds (x + w, y, shadowEdge, h); break;
case 2: sw->setBounds (x, y, w, shadowEdge); break;
case 3: sw->setBounds (x, owner->getBottom(), w, shadowEdge); break;
default: break;
}
if (sw == nullptr)
return;
sw->toBehind (i == 3 ? owner : shadowWindows.getUnchecked (i + 1));
}
}
}
else
{
shadowWindows.clear();
}
}
开发者ID:DISTRHO,项目名称:DISTRHO-Ports,代码行数:60,代码来源:juce_DropShadower.cpp
示例7: lock
/**
* Retrieve a requires file that might be loaded for this
* instance.
*
* @param name The name used for the requires file.
*
* @return The loaded requires file, or OREF_NULL if this instance
* has not used the file yet.
*/
PackageClass *InterpreterInstance::getRequiresFile(RexxActivity *activity, RexxString *name)
{
WeakReference *ref = (WeakReference *)requiresFiles->get(name);
if (ref != OREF_NULL)
{
PackageClass *resolved = (PackageClass *)ref->get();
if (resolved != OREF_NULL)
{
// get the guard lock on this...this will ensure that
// the initializer is run before we grab this from the cache
GuardLock lock(activity, resolved, ThePackageClass);
return resolved;
}
// this was garbage collected, remove it from the table
requiresFiles->remove(name);
}
return OREF_NULL;
}
开发者ID:jlfaucher,项目名称:executor,代码行数:27,代码来源:InterpreterInstance.cpp
示例8: testWeakRefs
static void testWeakRefs() {
assertEquals( TestObject::count, 0 );
Reference<TestObject> ref( new TestObject() );
WeakReference<TestObject> wref = ref;
assertEquals( TestObject::count, 1 );
assertTrue( ref );
assertTrue( wref );
assertTrue( wref.lock() );
ref = Reference<TestObject>();
assertEquals( TestObject::count, 0 );
assertFalse( ref );
assertFalse( wref );
assertFalse( wref.lock() );
}
开发者ID:alesapin,项目名称:lspl,代码行数:18,代码来源:RefCountObjectsTest.cpp
示例9:
/**
* Check for a package already in the requires cache.
*
* @param name The name of the target.
*
* @return The PackageClass instance, if any.
*/
RoutineClass *PackageManager::checkRequiresCache(RexxString *name, ProtectedObject &result)
{
// first check this using the specified name. Since we need to perform checks in the
// macro space, it's possible this will be loaded under the simple name. We'll need to check
// table again using the fully resolved name afterward.
WeakReference *requiresRef = (WeakReference *)loadedRequires->get(name);
if (requiresRef != OREF_NULL)
{
RoutineClass *resolved = (RoutineClass *)requiresRef->get();
if (resolved != OREF_NULL)
{
result = resolved;
return resolved;
}
// this was garbage collected, remove it from the table
loadedRequires->remove(name);
}
return OREF_NULL;
}
开发者ID:jlfaucher,项目名称:executor,代码行数:26,代码来源:PackageManager.cpp
示例10: previousFrontWindow
bool MainWindowList::openFile (const File& file, bool openInBackground)
{
for (auto* w : windows)
{
if (w->getProject() != nullptr && w->getProject()->getFile() == file)
{
w->toFront (true);
return true;
}
}
if (file.hasFileExtension (Project::projectFileExtension))
{
WeakReference<Component> previousFrontWindow (getFrontmostWindow());
auto* w = getOrCreateEmptyWindow();
bool ok = w->openFile (file);
if (ok)
{
w->makeVisible();
avoidSuperimposedWindows (w);
}
else
{
closeWindow (w);
}
if (openInBackground && previousFrontWindow != nullptr)
previousFrontWindow->toFront (true);
return ok;
}
if (getFrontmostWindow()->tryToOpenPIP (file))
return true;
if (! isPIPFile (file) && file.exists())
return getFrontmostWindow()->openFile (file);
return false;
}
开发者ID:julianstorer,项目名称:JUCE,代码行数:42,代码来源:jucer_MainWindow.cpp
示例11: dump_socket
static int
dump_socket(int argc, char** argv)
{
if (argc < 2) {
kprintf("usage: %s [address]\n", argv[0]);
return 0;
}
net_socket_private* socket = (net_socket_private*)parse_expression(argv[1]);
kprintf("SOCKET %p\n", socket);
kprintf(" family.type.protocol: %d.%d.%d\n",
socket->family, socket->type, socket->protocol);
WeakReference<net_socket_private> parent = socket->parent;
kprintf(" parent: %p (%p)\n", parent.Get(), socket->parent);
kprintf(" first protocol: %p\n", socket->first_protocol);
kprintf(" first module_info: %p\n", socket->first_info);
kprintf(" options: %x\n", socket->options);
kprintf(" linger: %d\n", socket->linger);
kprintf(" bound to device: %d\n", socket->bound_to_device);
kprintf(" owner: %ld\n", socket->owner);
kprintf(" max backlog: %ld\n", socket->max_backlog);
kprintf(" is connected: %d\n", socket->is_connected);
kprintf(" child_count: %lu\n", socket->child_count);
if (socket->child_count == 0)
return 0;
kprintf(" pending children:\n");
SocketList::Iterator iterator = socket->pending_children.GetIterator();
while (net_socket_private* child = iterator.Next()) {
print_socket_line(child, " ");
}
kprintf(" connected children:\n");
iterator = socket->connected_children.GetIterator();
while (net_socket_private* child = iterator.Next()) {
print_socket_line(child, " ");
}
return 0;
}
开发者ID:mmanley,项目名称:Antares,代码行数:42,代码来源:net_socket.cpp
示例12: socket_connected
/*! The socket has been connected. It will be moved to the connected queue
of its parent socket.
*/
status_t
socket_connected(net_socket* _socket)
{
net_socket_private* socket = (net_socket_private*)_socket;
WeakReference<net_socket_private> parent = socket->parent;
if (parent.Get() == NULL)
return B_BAD_VALUE;
MutexLocker _(parent->lock);
parent->pending_children.Remove(socket);
parent->connected_children.Add(socket);
socket->is_connected = true;
// notify parent
if (parent->select_pool)
notify_select_event_pool(parent->select_pool, B_SELECT_READ);
return B_OK;
}
开发者ID:mmanley,项目名称:Antares,代码行数:24,代码来源:net_socket.cpp
示例13: socket_aborted
/*! The socket has been aborted. Steals the parent's reference, and releases
it.
*/
status_t
socket_aborted(net_socket* _socket)
{
net_socket_private* socket = (net_socket_private*)_socket;
WeakReference<net_socket_private> parent = socket->parent;
if (parent.Get() == NULL)
return B_BAD_VALUE;
MutexLocker _(parent->lock);
if (socket->is_connected)
parent->connected_children.Remove(socket);
else
parent->pending_children.Remove(socket);
parent->child_count--;
socket->RemoveFromParent();
return B_OK;
}
开发者ID:mmanley,项目名称:Antares,代码行数:24,代码来源:net_socket.cpp
示例14: setter
void DropShadower::updateShadows()
{
if (reentrant || owner == nullptr)
return;
ComponentPeer* const peer = owner->getPeer();
const bool isOwnerVisible = owner->isVisible() && (peer == nullptr || ! peer->isMinimised());
const bool createShadowWindows = shadowWindows.size() == 0
&& owner->getWidth() > 0
&& owner->getHeight() > 0
&& isOwnerVisible
&& (Desktop::canUseSemiTransparentWindows()
|| owner->getParentComponent() != nullptr);
{
const ScopedValueSetter<bool> setter (reentrant, true, false);
const int shadowEdge = jmax (shadow.offset.x, shadow.offset.y) + shadow.radius;
if (createShadowWindows)
{
const int shadowEdge2 = shadowEdge * 2;
const int imageSize = shadowEdge * 5;
// keep a cached version of the image to save doing the gaussian too often
int64 hash = shadow.radius ^ 0x2342dfa7;
hash = hash * 101 + shadow.offset.x;
hash = hash * 101 + shadow.offset.y;
hash = hash * 65537 + shadow.colour.getARGB();
Image bigIm (ImageCache::getFromHashCode (hash));
if (bigIm.isNull())
{
bigIm = Image (Image::ARGB, imageSize, imageSize, true);
Graphics g (bigIm);
Path p;
p.addRectangle ((float) (shadowEdge + shadow.offset.x),
(float) (shadowEdge + shadow.offset.y),
(float) (imageSize - shadowEdge2),
(float) (imageSize - shadowEdge2));
shadow.drawForPath (g, p);
ImageCache::addImageToCache (bigIm, hash);
}
jassert (imageSize == bigIm.getWidth() && imageSize == bigIm.getHeight());
setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, imageSize - shadowEdge2);
setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, imageSize - shadowEdge, 0);
setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, imageSize - shadowEdge, imageSize - shadowEdge2);
setShadowImage (bigIm, 5, shadowEdge, shadowEdge, imageSize - shadowEdge, shadowEdge2);
setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
setShadowImage (bigIm, 7, shadowEdge, shadowEdge, imageSize - shadowEdge2, 0);
setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, imageSize - shadowEdge);
setShadowImage (bigIm, 10, shadowEdge, shadowEdge, imageSize - shadowEdge2, imageSize - shadowEdge);
setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, imageSize - shadowEdge);
for (int i = 0; i < 4; ++i)
shadowWindows.add (new ShadowWindow (*owner, i, shadowImageSections));
}
if (shadowWindows.size() >= 4)
{
const int x = owner->getX();
const int y = owner->getY() - shadowEdge;
const int w = owner->getWidth();
const int h = owner->getHeight() + shadowEdge + shadowEdge;
for (int i = shadowWindows.size(); --i >= 0;)
{
// there seem to be rare situations where the dropshadower may be deleted by
// callbacks during this loop, so use a weak ref to watch out for this..
WeakReference<Component> sw (shadowWindows[i]);
if (sw != nullptr)
sw->setAlwaysOnTop (owner->isAlwaysOnTop());
if (sw != nullptr)
sw->setVisible (isOwnerVisible);
if (sw != nullptr)
{
switch (i)
{
case 0: sw->setBounds (x - shadowEdge, y, shadowEdge, h); break;
case 1: sw->setBounds (x + w, y, shadowEdge, h); break;
case 2: sw->setBounds (x, y, w, shadowEdge); break;
case 3: sw->setBounds (x, owner->getBottom(), w, shadowEdge); break;
default: break;
}
}
if (sw == nullptr)
//.........这里部分代码省略.........
开发者ID:Amcut,项目名称:pizmidi,代码行数:101,代码来源:juce_DropShadower.cpp
示例15: updateLocation
void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
{
// (note: use a local copy of this in case a callback runs a modal loop and deletes
// this object before it returns)
DragAndDropTarget::SourceDetails details (sourceDetails);
Point<int> newPos (screenPos + imageOffset);
if (getParentComponent() != nullptr)
newPos = getParentComponent()->getLocalPoint (nullptr, newPos);
//if (newX != getX() || newY != getY())
{
setTopLeftPosition (newPos.getX(), newPos.getY());
Point<int> relPos;
DragAndDropTarget* const newTarget = findTarget (screenPos, relPos);
Component* newTargetComp = dynamic_cast <Component*> (newTarget);
drawImage = (newTarget == nullptr) || newTarget->shouldDrawDragImageWhenOver();
if (newTargetComp != currentlyOverComp)
{
DragAndDropTarget* const lastTarget = getCurrentlyOver();
if (lastTarget != nullptr && details.sourceComponent != nullptr
&& lastTarget->isInterestedInDragSource (details))
lastTarget->itemDragExit (details);
currentlyOverComp = newTargetComp;
if (newTarget != nullptr)
{
details.localPosition = relPos;
if (newTarget->isInterestedInDragSource (details))
newTarget->itemDragEnter (details);
}
}
{
DragAndDropTarget* const target = getCurrentlyOver();
if (target != nullptr)
{
details.localPosition = relPos;
if (target->isInterestedInDragSource (details))
target->itemDragMove (details);
}
}
if (getCurrentlyOver() == nullptr && canDoExternalDrag && ! hasCheckedForExternalDrag)
{
if (Desktop::getInstance().findComponentAt (screenPos) == nullptr)
{
hasCheckedForExternalDrag = true;
StringArray files;
bool canMoveFiles = false;
if (owner->shouldDropFilesWhenDraggedExternally (details, files, canMoveFiles)
&& files.size() > 0)
{
WeakReference<Component> thisWeakRef (this);
setVisible (false);
if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
delete thisWeakRef.get();
return;
}
}
}
}
}
开发者ID:baeksanchang,项目名称:juce,代码行数:75,代码来源:juce_DragAndDropContainer.cpp
示例16: TEST
// LIVE -> DEINITING -> DEINITED -> FREED -> DEAD, with side table
TEST(LongRefcountingTest, lifecycle_live_deiniting_deinited_freed_with_side_DeathTest) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
size_t deinited = 0;
auto object = allocTestObject(&deinited, 1);
object->CheckLifecycle = true;
// Object is LIVE
EXPECT_ALLOCATED(object);
// RC tested elsewhere
// URC load OK
// URC increment OK
// URC decrement OK
swift_unownedCheck(object);
swift_unownedRetain(object); swift_unownedCheck(object);
swift_unownedRetain(object); swift_unownedCheck(object);
swift_unownedRetain(object); swift_unownedCheck(object);
swift_unownedRelease(object); swift_unownedCheck(object);
// Remaining releases are performed during DEINITED.
// WRC load can't happen
// WRC increment adds side table
// WRC decrement can't happen
WeakReference w;
swift_weakInit(&w, object);
// Object is LIVE with side table
void *side = w.getSideTable();
EXPECT_ALLOCATED(side);
WeakReference w_deinit;
swift_weakInit(&w_deinit, object);
object->WeakRef = &w_deinit;
// destroyed during deinit
// RC increment ok
// RC decrement ok
swift_retain(object);
swift_retain(object);
swift_retain(object);
swift_release(object);
swift_release(object);
swift_release(object);
// URC load OK
// URC increment OK
// URC decrement OK
swift_unownedCheck(object);
swift_unownedRetain(object); swift_unownedCheck(object);
swift_unownedRetain(object); swift_unownedCheck(object);
swift_unownedRetain(object); swift_unownedCheck(object);
swift_unownedRelease(object); swift_unownedCheck(object);
swift_unownedRelease(object); swift_unownedCheck(object);
swift_unownedRelease(object); swift_unownedCheck(object);
// WRC load OK
// WRC increment OK
// WRC decrement OK
WeakReference w2;
swift_weakInit(&w2, object);
HeapObject *weakValue = swift_weakLoadStrong(&w2);
EXPECT_EQ(weakValue, object);
swift_release(weakValue);
weakValue = swift_weakLoadStrong(&w);
EXPECT_EQ(weakValue, object);
swift_release(weakValue);
// RC == 1
// URC == 3
// WRC == 3
swift_release(object); // DEINITING is in here
// Object is DEINITED
// RC == 0
// URC == 2
// WRC == 3
EXPECT_EQ(1u, deinited);
EXPECT_ALLOCATED(object);
EXPECT_ALLOCATED(side);
// RC can't happen
// WRC load is nil
// WRC increment can't happen
// WRC decrement OK
weakValue = swift_weakTakeStrong(&w2);
EXPECT_EQ(0, weakValue);
// URC load crashes
// URC increment can't happen
//.........这里部分代码省略.........
开发者ID:Nirma,项目名称:swift,代码行数:101,代码来源:LongRefcounting.cpp
示例17: getValueFromScript
var Parameter::getValueFromScript(const juce::var::NativeFunctionArgs & a)
{
WeakReference<Parameter> c = getObjectFromJS<Parameter>(a);
if (c == nullptr || c.wasObjectDeleted()) return var();
return c->getValue();
}
开发者ID:haskellstudio,项目名称:juce_organicui,代码行数:6,代码来源:Parameter.cpp
示例18: previouslyFocused
bool FileChooser::showDialog (const bool selectsDirectories,
const bool selectsFiles,
const bool isSave,
const bool warnAboutOverwritingExistingFiles,
const bool selectMultipleFiles,
FilePreviewComponent* const previewComponent)
{
WeakReference<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
results.clear();
// the preview component needs to be the right size before you pass it in here..
jassert (previewComponent == nullptr || (previewComponent->getWidth() > 10
&& previewComponent->getHeight() > 10));
#if JUCE_WINDOWS
if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
#elif JUCE_MAC || JUCE_LINUX
if (useNativeDialogBox && (previewComponent == nullptr))
#else
if (false)
#endif
{
showPlatformDialog (results, title, startingFile, filters,
selectsDirectories, selectsFiles, isSave,
warnAboutOverwritingExistingFiles,
selectMultipleFiles,
previewComponent);
}
else
{
WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
selectsDirectories ? "*" : String::empty,
String::empty);
int flags = isSave ? FileBrowserComponent::saveMode
: FileBrowserComponent::openMode;
if (selectsFiles)
flags |= FileBrowserComponent::canSelectFiles;
if (selectsDirectories)
{
flags |= FileBrowserComponent::canSelectDirectories;
if (! isSave)
flags |= FileBrowserComponent::filenameBoxIsReadOnly;
}
if (selectMultipleFiles)
flags |= FileBrowserComponent::canSelectMultipleItems;
FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
FileChooserDialogBox box (title, String::empty,
browserComponent,
warnAboutOverwritingExistingFiles,
browserComponent.findColour (AlertWindow::backgroundColourId));
if (box.show())
{
for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
results.add (browserComponent.getSelectedFile (i));
}
}
if (previouslyFocused != nullptr)
previouslyFocused->grabKeyboardFocus();
return results.size() > 0;
}
开发者ID:0x4d52,项目名称:ugen,代码行数:71,代码来源:juce_FileChooser.cpp
示例19: treeViewMenuItemChosen
static void treeViewMenuItemChosen (int resultCode, WeakReference<JucerTreeViewBase> item)
{
if (item != nullptr)
item->handlePopupMenuResult (resultCode);
}
开发者ID:Neknail,项目名称:JUCE,代码行数:5,代码来源:jucer_JucerTreeViewBase.cpp
示例20: setter
void DropShadower::updateShadows()
{
if (reentrant || owner == nullptr)
return;
ComponentPeer* const peer = owner->getPeer();
const bool isOwnerVisible = owner->isVisible() && (peer == nullptr || ! peer->isMinimised());
const bool createShadowWindows = shadowWindows.size() == 0
&& owner->getWidth() > 0
&& owner->getHeight() > 0
&& isOwnerVisible
&& (Desktop::canUseSemiTransparentWindows()
|| owner->getParentComponent() != nullptr);
{
const ScopedValueSetter<bool> setter (reentrant, true, false);
const int shadowEdge = jmax (xOffset, yOffset) + (int) blurRadius;
if (createShadowWindows)
{
// keep a cached version of the image to save doing the gaussian too often
String imageId;
imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
const int hash = imageId.hashCode();
Image bigIm (ImageCache::getFromHashCode (hash));
if (bigIm.isNull())
{
bigIm = Image (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true, Image::NativeImage);
Graphics bigG (bigIm);
bigG.setColour (Colours::black.withAlpha (alpha));
bigG.fillRect (shadowEdge + xOffset,
shadowEdge + yOffset,
bigIm.getWidth() - (shadowEdge * 2),
bigIm.getHeight() - (shadowEdge * 2));
ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
blurKernel.createGaussianBlur (blurRadius);
blurKernel.applyToImage (bigIm, bigIm,
Rectangle<int> (xOffset, yOffset,
bigIm.getWidth(), bigIm.getHeight()));
ImageCache::addImageToCache (bigIm, hash);
}
const int iw = bigIm.getWidth();
const int ih = bigIm.getHeight();
const int shadowEdge2 = shadowEdge * 2;
setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
for (int i = 0; i < 4; ++i)
shadowWindows.add (new ShadowWindow (*owner, i, shadowImageSections));
}
if (shadowWindows.size() >= 4)
{
const int x = owner->getX();
const int y = owner->getY() - shadowEdge;
const int w = owner->getWidth();
const int h = owner->getHeight() + shadowEdge + shadowEdge;
for (int i = shadowWindows.size(); --i >= 0;)
{
// there seem to be rare situations where the dropshadower may be deleted by
// callbacks during this loop, so use a weak ref to watch out for this..
WeakReference<Component> sw (shadowWindows[i]);
if (sw != nullptr)
sw->setAlwaysOnTop (owner->isAlwaysOnTop());
if (sw != nullptr)
sw->setVisible (isOwnerVisible);
if (sw != nullptr)
{
switch (i)
{
case 0: sw->setBounds (x - shadowEdge, y, shadowEdge, h); break;
case 1: sw->setBounds (x + w, y, shadowEdge, h); break;
case 2: sw->setBounds (x, y, w, shadowEdge); break;
case 3: sw->setBounds (x, owner->getBottom(), w, shadowEdge); break;
default: break;
//.........这里部分代码省略.........
开发者ID:sonic59,项目名称:JuceText,代码行数:101,代码来源:juce_DropShadower.cpp
注:本文中的WeakReference类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论