From df5f73910b7a6c558209900a1a47fc22da006c21 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Thu, 24 Dec 2009 12:30:25 +0000 Subject: [PATCH] Fixed the position of the drag image when dragging listboxes. Minor fix for mac graphics contexts, and win32 webcam latency adjustment. --- juce_amalgamated.cpp | 118 +++++++++++------- juce_amalgamated.h | 4 +- src/gui/components/controls/juce_ListBox.cpp | 80 +++++++----- src/gui/components/controls/juce_ListBox.h | 4 +- .../components/controls/juce_TableListBox.cpp | 18 +-- .../mac/juce_mac_CoreGraphicsContext.mm | 2 + .../windows/juce_win32_CameraDevice.cpp | 15 +++ 7 files changed, 149 insertions(+), 92 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index a3534f64e9..2b5338cf09 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -47841,23 +47841,7 @@ public: if (dragDescription.isNotEmpty()) { isDragging = true; - - DragAndDropContainer* const dragContainer - = DragAndDropContainer::findParentDragContainerFor (this); - - if (dragContainer != 0) - { - Image* dragImage = owner.createSnapshotOfSelectedRows(); - dragImage->multiplyAllAlphas (0.6f); - - dragContainer->startDragging (dragDescription, &owner, dragImage, true); - } - else - { - // to be able to do a drag-and-drop operation, the listbox needs to - // be inside a component which is also a DragAndDropContainer. - jassertfalse - } + owner.startDragAndDrop (e, dragDescription); } } } @@ -48596,36 +48580,77 @@ void ListBox::repaintRow (const int rowNumber) throw() repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight()); } -Image* ListBox::createSnapshotOfSelectedRows() +Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY) { - Image* snapshot = Image::createNativeImage (Image::ARGB, getWidth(), getHeight(), true); - Graphics g (*snapshot); - + Rectangle imageArea; const int firstRow = getRowContainingPosition (0, 0); - for (int i = getNumRowsOnScreen() + 2; --i >= 0;) + int i; + for (i = getNumRowsOnScreen() + 2; --i >= 0;) { Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i); if (rowComp != 0 && isRowSelected (firstRow + i)) { - g.saveState(); - int x = 0, y = 0; rowComp->relativePositionToOtherComponent (this, x, y); - g.setOrigin (x, y); - g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()); + const Rectangle rowRect (x, y, rowComp->getWidth(), rowComp->getHeight()); - rowComp->paintEntireComponent (g); + if (imageArea.isEmpty()) + imageArea = rowRect; + else + imageArea = imageArea.getUnion (rowRect); + } + } - g.restoreState(); + imageArea = imageArea.getIntersection (Rectangle (0, 0, getWidth(), getHeight())); + imageX = imageArea.getX(); + imageY = imageArea.getY(); + Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true); + + for (i = getNumRowsOnScreen() + 2; --i >= 0;) + { + Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i); + + if (rowComp != 0 && isRowSelected (firstRow + i)) + { + int x = 0, y = 0; + rowComp->relativePositionToOtherComponent (this, x, y); + + Graphics g (*snapshot); + g.setOrigin (x - imageX, y - imageY); + if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight())) + rowComp->paintEntireComponent (g); } } return snapshot; } +void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription) +{ + DragAndDropContainer* const dragContainer + = DragAndDropContainer::findParentDragContainerFor (this); + + if (dragContainer != 0) + { + int x, y; + Image* dragImage = createSnapshotOfSelectedRows (x, y); + dragImage->multiplyAllAlphas (0.6f); + + MouseEvent e2 (e.getEventRelativeTo (this)); + const Point p ((float) (x - e2.x), (float) (y - e2.y)); + dragContainer->startDragging (dragDescription, this, dragImage, true, &p); + } + else + { + // to be able to do a drag-and-drop operation, the listbox needs to + // be inside a component which is also a DragAndDropContainer. + jassertfalse + } +} + Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate) { (void) existingComponentToUpdate; @@ -51215,23 +51240,7 @@ public: if (dragDescription.isNotEmpty()) { isDragging = true; - - DragAndDropContainer* const dragContainer - = DragAndDropContainer::findParentDragContainerFor (this); - - if (dragContainer != 0) - { - Image* dragImage = owner.createSnapshotOfSelectedRows(); - dragImage->multiplyAllAlphas (0.6f); - - dragContainer->startDragging (dragDescription, &owner, dragImage, true); - } - else - { - // to be able to do a drag-and-drop operation, the listbox needs to - // be inside a component which is also a DragAndDropContainer. - jassertfalse - } + owner.startDragAndDrop (e, dragDescription); } } } @@ -250242,6 +250251,21 @@ public: { firstRecordedTime = Time::getCurrentTime(); recordNextFrameTime = false; + + ComSmartPtr pin; + if (getPin (filter, PINDIR_OUTPUT, &pin)) + { + ComSmartPtr pushSource; + hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource); + + if (pushSource != 0) + { + REFERENCE_TIME latency = 0; + hr = ps->GetLatency (&latency); + + firstRecordedTime -= RelativeTime ((double) latency); + } + } } imageSwapLock.enter(); @@ -262505,6 +262529,7 @@ public: numGradientLookupEntries (0) { CGContextRetain (context); + CGContextSaveGState(context); CGContextSetShouldSmoothFonts (context, true); CGContextSetShouldAntialias (context, true); CGContextSetBlendMode (context, kCGBlendModeNormal); @@ -262518,6 +262543,7 @@ public: ~CoreGraphicsContext() { + CGContextRestoreGState (context); CGContextRelease (context); CGColorSpaceRelease (rgbColourSpace); CGColorSpaceRelease (greyColourSpace); @@ -266973,6 +266999,7 @@ public: numGradientLookupEntries (0) { CGContextRetain (context); + CGContextSaveGState(context); CGContextSetShouldSmoothFonts (context, true); CGContextSetShouldAntialias (context, true); CGContextSetBlendMode (context, kCGBlendModeNormal); @@ -266986,6 +267013,7 @@ public: ~CoreGraphicsContext() { + CGContextRestoreGState (context); CGContextRelease (context); CGColorSpaceRelease (rgbColourSpace); CGColorSpaceRelease (greyColourSpace); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 6f5e7d243a..f4e30cdaa2 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -37244,7 +37244,7 @@ public: @see Component::createComponentSnapshot */ - Image* createSnapshotOfSelectedRows(); + Image* createSnapshotOfSelectedRows (int& x, int& y); /** Returns the viewport that this ListBox uses. @@ -37275,6 +37275,8 @@ public: void mouseUp (const MouseEvent&); /** @internal */ void colourChanged(); + /** @internal */ + void startDragAndDrop (const MouseEvent& e, const String& dragDescription); juce_UseDebuggingNewOperator diff --git a/src/gui/components/controls/juce_ListBox.cpp b/src/gui/components/controls/juce_ListBox.cpp index 4b204f6b30..eb79fd61dc 100644 --- a/src/gui/components/controls/juce_ListBox.cpp +++ b/src/gui/components/controls/juce_ListBox.cpp @@ -137,23 +137,7 @@ public: if (dragDescription.isNotEmpty()) { isDragging = true; - - DragAndDropContainer* const dragContainer - = DragAndDropContainer::findParentDragContainerFor (this); - - if (dragContainer != 0) - { - Image* dragImage = owner.createSnapshotOfSelectedRows(); - dragImage->multiplyAllAlphas (0.6f); - - dragContainer->startDragging (dragDescription, &owner, dragImage, true); - } - else - { - // to be able to do a drag-and-drop operation, the listbox needs to - // be inside a component which is also a DragAndDropContainer. - jassertfalse - } + owner.startDragAndDrop (e, dragDescription); } } } @@ -904,36 +888,76 @@ void ListBox::repaintRow (const int rowNumber) throw() repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight()); } -Image* ListBox::createSnapshotOfSelectedRows() +Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY) { - Image* snapshot = Image::createNativeImage (Image::ARGB, getWidth(), getHeight(), true); - Graphics g (*snapshot); - + Rectangle imageArea; const int firstRow = getRowContainingPosition (0, 0); - for (int i = getNumRowsOnScreen() + 2; --i >= 0;) + int i; + for (i = getNumRowsOnScreen() + 2; --i >= 0;) { Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i); if (rowComp != 0 && isRowSelected (firstRow + i)) { - g.saveState(); - int x = 0, y = 0; rowComp->relativePositionToOtherComponent (this, x, y); - g.setOrigin (x, y); - g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()); + const Rectangle rowRect (x, y, rowComp->getWidth(), rowComp->getHeight()); - rowComp->paintEntireComponent (g); + if (imageArea.isEmpty()) + imageArea = rowRect; + else + imageArea = imageArea.getUnion (rowRect); + } + } - g.restoreState(); + imageArea = imageArea.getIntersection (Rectangle (0, 0, getWidth(), getHeight())); + imageX = imageArea.getX(); + imageY = imageArea.getY(); + Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true); + + for (i = getNumRowsOnScreen() + 2; --i >= 0;) + { + Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i); + + if (rowComp != 0 && isRowSelected (firstRow + i)) + { + int x = 0, y = 0; + rowComp->relativePositionToOtherComponent (this, x, y); + + Graphics g (*snapshot); + g.setOrigin (x - imageX, y - imageY); + if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight())) + rowComp->paintEntireComponent (g); } } return snapshot; } +void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription) +{ + DragAndDropContainer* const dragContainer + = DragAndDropContainer::findParentDragContainerFor (this); + + if (dragContainer != 0) + { + int x, y; + Image* dragImage = createSnapshotOfSelectedRows (x, y); + dragImage->multiplyAllAlphas (0.6f); + + MouseEvent e2 (e.getEventRelativeTo (this)); + const Point p ((float) (x - e2.x), (float) (y - e2.y)); + dragContainer->startDragging (dragDescription, this, dragImage, true, &p); + } + else + { + // to be able to do a drag-and-drop operation, the listbox needs to + // be inside a component which is also a DragAndDropContainer. + jassertfalse + } +} //============================================================================== Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate) diff --git a/src/gui/components/controls/juce_ListBox.h b/src/gui/components/controls/juce_ListBox.h index da6c378be8..e9f4504005 100644 --- a/src/gui/components/controls/juce_ListBox.h +++ b/src/gui/components/controls/juce_ListBox.h @@ -525,7 +525,7 @@ public: @see Component::createComponentSnapshot */ - Image* createSnapshotOfSelectedRows(); + Image* createSnapshotOfSelectedRows (int& x, int& y); /** Returns the viewport that this ListBox uses. @@ -558,6 +558,8 @@ public: void mouseUp (const MouseEvent&); /** @internal */ void colourChanged(); + /** @internal */ + void startDragAndDrop (const MouseEvent& e, const String& dragDescription); juce_UseDebuggingNewOperator diff --git a/src/gui/components/controls/juce_TableListBox.cpp b/src/gui/components/controls/juce_TableListBox.cpp index 52f64ed9cc..41c79a26bd 100644 --- a/src/gui/components/controls/juce_TableListBox.cpp +++ b/src/gui/components/controls/juce_TableListBox.cpp @@ -200,23 +200,7 @@ public: if (dragDescription.isNotEmpty()) { isDragging = true; - - DragAndDropContainer* const dragContainer - = DragAndDropContainer::findParentDragContainerFor (this); - - if (dragContainer != 0) - { - Image* dragImage = owner.createSnapshotOfSelectedRows(); - dragImage->multiplyAllAlphas (0.6f); - - dragContainer->startDragging (dragDescription, &owner, dragImage, true); - } - else - { - // to be able to do a drag-and-drop operation, the listbox needs to - // be inside a component which is also a DragAndDropContainer. - jassertfalse - } + owner.startDragAndDrop (e, dragDescription); } } } diff --git a/src/native/mac/juce_mac_CoreGraphicsContext.mm b/src/native/mac/juce_mac_CoreGraphicsContext.mm index 6cf7c9b8e1..bca8f41a77 100644 --- a/src/native/mac/juce_mac_CoreGraphicsContext.mm +++ b/src/native/mac/juce_mac_CoreGraphicsContext.mm @@ -136,6 +136,7 @@ public: numGradientLookupEntries (0) { CGContextRetain (context); + CGContextSaveGState(context); CGContextSetShouldSmoothFonts (context, true); CGContextSetShouldAntialias (context, true); CGContextSetBlendMode (context, kCGBlendModeNormal); @@ -149,6 +150,7 @@ public: ~CoreGraphicsContext() { + CGContextRestoreGState (context); CGContextRelease (context); CGColorSpaceRelease (rgbColourSpace); CGColorSpaceRelease (greyColourSpace); diff --git a/src/native/windows/juce_win32_CameraDevice.cpp b/src/native/windows/juce_win32_CameraDevice.cpp index 0f91722a6a..c84524e6e3 100644 --- a/src/native/windows/juce_win32_CameraDevice.cpp +++ b/src/native/windows/juce_win32_CameraDevice.cpp @@ -191,6 +191,21 @@ public: { firstRecordedTime = Time::getCurrentTime(); recordNextFrameTime = false; + + ComSmartPtr pin; + if (getPin (filter, PINDIR_OUTPUT, &pin)) + { + ComSmartPtr pushSource; + hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource); + + if (pushSource != 0) + { + REFERENCE_TIME latency = 0; + hr = ps->GetLatency (&latency); + + firstRecordedTime -= RelativeTime ((double) latency); + } + } } imageSwapLock.enter();