mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
DocumentWindow: Implement window hit-testing API
This commit is contained in:
parent
9a91ae2ab6
commit
edd5745d7f
2 changed files with 59 additions and 2 deletions
|
|
@ -264,7 +264,7 @@ int DocumentWindow::getTitleBarHeight() const
|
|||
return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
|
||||
}
|
||||
|
||||
Rectangle<int> DocumentWindow::getTitleBarArea()
|
||||
Rectangle<int> DocumentWindow::getTitleBarArea() const
|
||||
{
|
||||
if (isKioskMode())
|
||||
return {};
|
||||
|
|
@ -273,6 +273,61 @@ Rectangle<int> DocumentWindow::getTitleBarArea()
|
|||
return { border.getLeft(), border.getTop(), getWidth() - border.getLeftAndRight(), getTitleBarHeight() };
|
||||
}
|
||||
|
||||
auto DocumentWindow::findControlAtPoint (Point<float> pt) const -> WindowControlKind
|
||||
{
|
||||
if (resizableBorder != nullptr)
|
||||
{
|
||||
using Zone = ResizableBorderComponent::Zone;
|
||||
const auto zone = Zone::fromPositionOnBorder (getLocalBounds(),
|
||||
resizableBorder->getBorderThickness(),
|
||||
pt.roundToInt());
|
||||
|
||||
switch (zone.getZoneFlags())
|
||||
{
|
||||
case Zone::top: return WindowControlKind::sizeTop;
|
||||
case Zone::left: return WindowControlKind::sizeLeft;
|
||||
case Zone::right: return WindowControlKind::sizeRight;
|
||||
case Zone::bottom: return WindowControlKind::sizeBottom;
|
||||
|
||||
case Zone::top | Zone::left: return WindowControlKind::sizeTopLeft;
|
||||
case Zone::top | Zone::right: return WindowControlKind::sizeTopRight;
|
||||
case Zone::bottom | Zone::left: return WindowControlKind::sizeBottomLeft;
|
||||
case Zone::bottom | Zone::right: return WindowControlKind::sizeBottomRight;
|
||||
}
|
||||
}
|
||||
|
||||
const auto topArea = getTitleBarArea().withTop (0);
|
||||
|
||||
if (! topArea.toFloat().contains (pt))
|
||||
return WindowControlKind::client;
|
||||
|
||||
for (const auto& [control, kind] : { std::tuple (getMinimiseButton(), WindowControlKind::minimise),
|
||||
std::tuple (getMaximiseButton(), WindowControlKind::maximise),
|
||||
std::tuple (getCloseButton(), WindowControlKind::close) })
|
||||
{
|
||||
if (control != nullptr && control->contains (control->getLocalPoint (this, pt)))
|
||||
return kind;
|
||||
}
|
||||
|
||||
// Add a few pixels for the top resizer, because Windows 11 expects the top resizer to be inside
|
||||
// the window, unlike the resizers on the bottom/left/right.
|
||||
constexpr auto topResizerSize = 4;
|
||||
const auto topResizerArea = getLocalBounds().withHeight (topResizerSize).toFloat();
|
||||
|
||||
if (topResizerArea.contains (pt))
|
||||
{
|
||||
if (pt.x <= topResizerArea.getX() + topResizerSize)
|
||||
return WindowControlKind::sizeTopLeft;
|
||||
|
||||
if (topResizerArea.getRight() - topResizerSize <= pt.x)
|
||||
return WindowControlKind::sizeTopRight;
|
||||
|
||||
return WindowControlKind::sizeTop;
|
||||
}
|
||||
|
||||
return WindowControlKind::caption;
|
||||
}
|
||||
|
||||
Button* DocumentWindow::getCloseButton() const noexcept { return titleBarButtons[2].get(); }
|
||||
Button* DocumentWindow::getMinimiseButton() const noexcept { return titleBarButtons[0].get(); }
|
||||
Button* DocumentWindow::getMaximiseButton() const noexcept { return titleBarButtons[1].get(); }
|
||||
|
|
|
|||
|
|
@ -291,7 +291,9 @@ public:
|
|||
/** @internal */
|
||||
void parentHierarchyChanged() override;
|
||||
/** @internal */
|
||||
Rectangle<int> getTitleBarArea();
|
||||
Rectangle<int> getTitleBarArea() const;
|
||||
/** @internal */
|
||||
WindowControlKind findControlAtPoint (Point<float>) const override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue