mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
Let the window frame keep its cursor
The GUI sets the cursor of the hovered widget every frame, and over the window that widget is usually the background with a plain arrow. The frame sets its resize cursors on pointer motion, so the GUI replaced them on the next frame: hovering a window edge did not show a resize cursor, it flickered and stayed an arrow. The window now reports whether the frame owns the cursor, and the GUI only sets the hovered cursor when it does not. The GLFW backend claims it inside the frame and gives it back in the client area together with the arrow, since the GUI sets a cursor only while a widget is hovered. Wayland keeps returning false, so the GUI behaves exactly as before there.
This commit is contained in:
parent
7126158d68
commit
f13b75475f
3 changed files with 22 additions and 1 deletions
|
|
@ -310,7 +310,7 @@ void GUI::draw(const DrawContext& pctx, Assets& assets) {
|
|||
frame->draw(ctx, assets);
|
||||
}
|
||||
|
||||
if (hover) {
|
||||
if (hover && !engine.getWindow().ownsCursor()) {
|
||||
engine.getWindow().setCursor(hover->getCursor());
|
||||
}
|
||||
if (hover && debug) {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,14 @@ public:
|
|||
}
|
||||
|
||||
virtual void setCursor(CursorShape shape) = 0;
|
||||
|
||||
/// @brief Whether the engine drawn window frame owns the cursor now
|
||||
///
|
||||
/// The frame puts the resize cursors of its edges and of the bar, and the
|
||||
/// GUI must not override them with the cursor of the hovered widget.
|
||||
virtual bool ownsCursor() const {
|
||||
return false;
|
||||
}
|
||||
virtual void setMode(WindowMode mode) = 0;
|
||||
virtual WindowMode getMode() const = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -361,6 +361,10 @@ public:
|
|||
return hoveredButton;
|
||||
}
|
||||
|
||||
bool ownsCursor() const override {
|
||||
return frameCursorActive;
|
||||
}
|
||||
|
||||
/// @brief What the pointer is over, in client coordinates
|
||||
frame::Hit hitTestFrame(int x, int y) const {
|
||||
const int height = barHeight();
|
||||
|
|
@ -396,6 +400,7 @@ public:
|
|||
void handleFrameMotion(double x, double y) {
|
||||
if (input.isCursorLocked() || barHeight() <= 0) {
|
||||
hoveredButton = -1;
|
||||
frameCursorActive = false;
|
||||
return;
|
||||
}
|
||||
if (dragging || resizeEdges != 0) {
|
||||
|
|
@ -641,8 +646,15 @@ private:
|
|||
)
|
||||
: 0;
|
||||
if (edges != 0) {
|
||||
frameCursorActive = true;
|
||||
setCursor(edgeCursor(edges));
|
||||
} else if (y < height) {
|
||||
frameCursorActive = true;
|
||||
setCursor(CursorShape::ARROW);
|
||||
} else if (frameCursorActive) {
|
||||
// the client area below the bar belongs to the GUI, which only
|
||||
// sets a cursor when a widget is hovered
|
||||
frameCursorActive = false;
|
||||
setCursor(CursorShape::ARROW);
|
||||
}
|
||||
}
|
||||
|
|
@ -779,6 +791,7 @@ private:
|
|||
};
|
||||
mutable std::vector<DecorationButtonLayout> buttonRects;
|
||||
int hoveredButton = -1;
|
||||
bool frameCursorActive = false;
|
||||
int pressedButton = -1;
|
||||
bool dragging = false;
|
||||
bool frameMoved = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue