Browse Source

Fixed the position of the drag image when dragging listboxes. Minor fix for mac graphics contexts, and win32 webcam latency adjustment.

tags/2021-05-28
Julian Storer 16 years ago
parent
commit
df5f73910b
7 changed files with 149 additions and 92 deletions
  1. +73
    -45
      juce_amalgamated.cpp
  2. +3
    -1
      juce_amalgamated.h
  3. +52
    -28
      src/gui/components/controls/juce_ListBox.cpp
  4. +3
    -1
      src/gui/components/controls/juce_ListBox.h
  5. +1
    -17
      src/gui/components/controls/juce_TableListBox.cpp
  6. +2
    -0
      src/native/mac/juce_mac_CoreGraphicsContext.mm
  7. +15
    -0
      src/native/windows/juce_win32_CameraDevice.cpp

+ 73
- 45
juce_amalgamated.cpp View File

@@ -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());

if (imageArea.isEmpty())
imageArea = rowRect;
else
imageArea = imageArea.getUnion (rowRect);
}
}

rowComp->paintEntireComponent (g);
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);

g.restoreState();
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 <IPin> pin;
if (getPin (filter, PINDIR_OUTPUT, &pin))
{
ComSmartPtr <IAMPushSource> 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);


+ 3
- 1
juce_amalgamated.h View File

@@ -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



+ 52
- 28
src/gui/components/controls/juce_ListBox.cpp View File

@@ -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());
if (imageArea.isEmpty())
imageArea = rowRect;
else
imageArea = imageArea.getUnion (rowRect);
}
}
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);
rowComp->paintEntireComponent (g);
if (rowComp != 0 && isRowSelected (firstRow + i))
{
int x = 0, y = 0;
rowComp->relativePositionToOtherComponent (this, x, y);
g.restoreState();
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)


+ 3
- 1
src/gui/components/controls/juce_ListBox.h View File

@@ -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


+ 1
- 17
src/gui/components/controls/juce_TableListBox.cpp View File

@@ -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);
}
}
}


+ 2
- 0
src/native/mac/juce_mac_CoreGraphicsContext.mm View File

@@ -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);


+ 15
- 0
src/native/windows/juce_win32_CameraDevice.cpp View File

@@ -191,6 +191,21 @@ public:
{
firstRecordedTime = Time::getCurrentTime();
recordNextFrameTime = false;
ComSmartPtr <IPin> pin;
if (getPin (filter, PINDIR_OUTPUT, &pin))
{
ComSmartPtr <IAMPushSource> 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();


Loading…
Cancel
Save