Browse Source

Small fixes for Viewport and Identifier.

tags/2021-05-28
Julian Storer 13 years ago
parent
commit
c65c07312d
8 changed files with 55 additions and 21 deletions
  1. +1
    -1
      modules/juce_core/memory/juce_ScopedPointer.h
  2. +1
    -1
      modules/juce_core/text/juce_Identifier.cpp
  3. +6
    -1
      modules/juce_gui_basics/components/juce_Component.cpp
  4. +15
    -0
      modules/juce_gui_basics/components/juce_Component.h
  5. +29
    -16
      modules/juce_gui_basics/layout/juce_Viewport.cpp
  6. +1
    -0
      modules/juce_gui_basics/layout/juce_Viewport.h
  7. +1
    -1
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp
  8. +1
    -1
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp

+ 1
- 1
modules/juce_core/memory/juce_ScopedPointer.h View File

@@ -47,7 +47,7 @@
If you need to get a pointer out of a ScopedPointer without it being deleted, you
can use the release() method.
Something to note is the main difference between this class and the std::auto_ptr class,
which is that ScopedPointer provides a cast-to-object operator, wheras std::auto_ptr
requires that you always call get() to retrieve the pointer. The advantages of providing


+ 1
- 1
modules/juce_core/text/juce_Identifier.cpp View File

@@ -71,7 +71,7 @@ Identifier::~Identifier()
bool Identifier::isValidIdentifier (const String& possibleIdentifier) noexcept
{
return possibleIdentifier.isNotEmpty()
&& possibleIdentifier.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-:");
&& possibleIdentifier.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-:#@$%");
}
END_JUCE_NAMESPACE

+ 6
- 1
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -593,7 +593,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
removeFromDesktop();
setTopLeftPosition (topLeft.getX(), topLeft.getY());
setTopLeftPosition (topLeft);
}
if (parentComponent != nullptr)
@@ -1063,6 +1063,11 @@ void Component::setTopLeftPosition (const int x, const int y)
setBounds (x, y, getWidth(), getHeight());
}
void Component::setTopLeftPosition (const Point<int>& pos)
{
setBounds (pos.getX(), pos.getY(), getWidth(), getHeight());
}
void Component::setTopRightPosition (const int x, const int y)
{
setTopLeftPosition (x - getWidth(), y);


+ 15
- 0
modules/juce_gui_basics/components/juce_Component.h View File

@@ -415,6 +415,21 @@ public:
*/
void setTopLeftPosition (int x, int y);
/** Moves the component to a new position.
Changes the component's top-left position (without changing its size).
The position is relative to the top-left of the component's parent.
If the component actually moves, this method will make a synchronous call to moved().
Note that if you've used setTransform() to apply a transform, then the component's
bounds will no longer be a direct reflection of the position at which it appears within
its parent, as the transform will be applied to whatever bounds you set for it.
@see setBounds, ComponentListener::componentMovedOrResized
*/
void setTopLeftPosition (const Point<int>& newTopLeftPosition);
/** Moves the component to a new position.
Changes the position of the component's top-right corner (keeping it the same size).


+ 29
- 16
modules/juce_gui_basics/layout/juce_Viewport.cpp View File

@@ -88,7 +88,7 @@ void Viewport::setViewedComponent (Component* const newViewedComponent, const bo
if (contentComp != nullptr)
{
contentHolder.addAndMakeVisible (contentComp);
setViewPosition (0, 0);
setViewPosition (Point<int>());
contentComp->addComponentListener (this);
}
@@ -99,22 +99,28 @@ void Viewport::setViewedComponent (Component* const newViewedComponent, const bo
int Viewport::getMaximumVisibleWidth() const { return contentHolder.getWidth(); }
int Viewport::getMaximumVisibleHeight() const { return contentHolder.getHeight(); }
Point<int> Viewport::viewportPosToCompPos (const Point<int>& pos) const
{
jassert (contentComp != nullptr);
return Point<int> (jmax (jmin (0, contentHolder.getWidth() - contentComp->getWidth()), jmin (0, -pos.getX())),
jmax (jmin (0, contentHolder.getHeight() - contentComp->getHeight()), jmin (0, -pos.getY())));
}
void Viewport::setViewPosition (const int xPixelsOffset, const int yPixelsOffset)
{
if (contentComp != nullptr)
contentComp->setTopLeftPosition (jmax (jmin (0, contentHolder.getWidth() - contentComp->getWidth()), jmin (0, -xPixelsOffset)),
jmax (jmin (0, contentHolder.getHeight() - contentComp->getHeight()), jmin (0, -yPixelsOffset)));
setViewPosition (Point<int> (xPixelsOffset, yPixelsOffset));
}
void Viewport::setViewPosition (const Point<int>& newPosition)
{
setViewPosition (newPosition.getX(), newPosition.getY());
if (contentComp != nullptr)
contentComp->setTopLeftPosition (viewportPosToCompPos (newPosition));
}
void Viewport::setViewPositionProportionately (const double x, const double y)
{
if (contentComp != nullptr)
setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
}
@@ -247,20 +253,27 @@ void Viewport::updateVisibleArea()
horizontalScrollBar.setVisible (hBarVisible);
verticalScrollBar.setVisible (vBarVisible);
setViewPosition (visibleOrigin);
const Rectangle<int> visibleArea (visibleOrigin.getX(), visibleOrigin.getY(),
jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()),
jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight()));
const Point<int> newContentCompPos (viewportPosToCompPos (visibleOrigin));
if (lastVisibleArea != visibleArea)
if (contentComp != nullptr && contentComp->getBounds().getPosition() != newContentCompPos)
{
lastVisibleArea = visibleArea;
visibleAreaChanged (visibleArea);
contentComp->setTopLeftPosition (newContentCompPos); // (this will re-entrantly call updateVisibleArea again)
}
else
{
const Rectangle<int> visibleArea (visibleOrigin.getX(), visibleOrigin.getY(),
jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()),
jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight()));
if (lastVisibleArea != visibleArea)
{
lastVisibleArea = visibleArea;
visibleAreaChanged (visibleArea);
}
horizontalScrollBar.handleUpdateNowIfNeeded();
verticalScrollBar.handleUpdateNowIfNeeded();
horizontalScrollBar.handleUpdateNowIfNeeded();
verticalScrollBar.handleUpdateNowIfNeeded();
}
}
//==============================================================================


+ 1
- 0
modules/juce_gui_basics/layout/juce_Viewport.h View File

@@ -263,6 +263,7 @@ private:
Component contentHolder;
ScrollBar verticalScrollBar;
ScrollBar horizontalScrollBar;
Point<int> viewportPosToCompPos (const Point<int>&) const;
void updateVisibleArea();
void deleteContentComp();


+ 1
- 1
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -273,7 +273,7 @@ public:
items.add (new PopupMenu::ItemComponent (*menu.items.getUnchecked(i), standardItemHeight, this));
calculateWindowPos (target, alignToRectangle);
setTopLeftPosition (windowPos.getX(), windowPos.getY());
setTopLeftPosition (windowPos.getPosition());
updateYPositions();
if (itemIdThatMustBeVisible != 0)


+ 1
- 1
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp View File

@@ -193,7 +193,7 @@ public:
//if (newX != getX() || newY != getY())
{
setTopLeftPosition (newPos.getX(), newPos.getY());
setTopLeftPosition (newPos);
Point<int> relPos;
DragAndDropTarget* const newTarget = findTarget (screenPos, relPos);


Loading…
Cancel
Save