-
Notifications
You must be signed in to change notification settings - Fork 488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8271557: Undecorated interactive stage style #594
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
modules/javafx.graphics/src/main/java/com/sun/glass/ui/MoveResizeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package com.sun.glass.ui; | ||
|
||
import com.sun.glass.events.MouseEvent; | ||
import javafx.scene.Node; | ||
import javafx.stage.WindowRegion; | ||
import javafx.stage.WindowRegionClassifier; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class MoveResizeHelper { | ||
|
||
private static final Map<WindowRegion, Cursor> RESIZE_CURSORS = new HashMap<>(); | ||
|
||
static { | ||
Application application = Application.GetApplication(); | ||
RESIZE_CURSORS.put(WindowRegion.TOP_LEFT, application.createCursor(Cursor.CURSOR_RESIZE_NORTHWEST)); | ||
RESIZE_CURSORS.put(WindowRegion.TOP_RIGHT, application.createCursor(Cursor.CURSOR_RESIZE_NORTHEAST)); | ||
RESIZE_CURSORS.put(WindowRegion.BOTTOM_LEFT, application.createCursor(Cursor.CURSOR_RESIZE_SOUTHWEST)); | ||
RESIZE_CURSORS.put(WindowRegion.BOTTOM_RIGHT, application.createCursor(Cursor.CURSOR_RESIZE_SOUTHEAST)); | ||
RESIZE_CURSORS.put(WindowRegion.LEFT, application.createCursor(Cursor.CURSOR_RESIZE_LEFTRIGHT)); | ||
RESIZE_CURSORS.put(WindowRegion.RIGHT, application.createCursor(Cursor.CURSOR_RESIZE_LEFTRIGHT)); | ||
RESIZE_CURSORS.put(WindowRegion.TOP, application.createCursor(Cursor.CURSOR_RESIZE_UPDOWN)); | ||
RESIZE_CURSORS.put(WindowRegion.BOTTOM, application.createCursor(Cursor.CURSOR_RESIZE_UPDOWN)); | ||
} | ||
|
||
private final View view; | ||
private final Window window; | ||
private final WindowRegionClassifier regionClassifier; | ||
private int mouseDownX, mouseDownY; | ||
private int mouseDownWindowX, mouseDownWindowY; | ||
private int mouseDownWindowWidth, mouseDownWindowHeight; | ||
private WindowRegion currentWindowRegion; | ||
private Cursor lastCursor; | ||
|
||
public MoveResizeHelper(View view, Window window) { | ||
this.view = view; | ||
this.window = window; | ||
this.regionClassifier = window.regionClassifier; | ||
} | ||
|
||
public final boolean handleMouseEvent(int type, int button, int x, int y, int xAbs, int yAbs) { | ||
int wx = (int)(x / window.getPlatformScaleX()); | ||
int wy = (int)(y / window.getPlatformScaleY()); | ||
|
||
if (type != MouseEvent.DRAG) { | ||
var eventHandler = view.getEventHandler(); | ||
Node pickedNode = eventHandler != null ? eventHandler.pickNode(wx, wy) : null; | ||
currentWindowRegion = regionClassifier.classify(wx, wy, pickedNode); | ||
updateCursor(currentWindowRegion); | ||
|
||
if (currentWindowRegion == WindowRegion.CLIENT) { | ||
return false; | ||
} | ||
} | ||
|
||
switch (type) { | ||
case MouseEvent.DRAG: | ||
handleMouseDrag(button, xAbs, yAbs, currentWindowRegion); | ||
break; | ||
case MouseEvent.DOWN: | ||
handleMouseDown(xAbs, yAbs); | ||
break; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected boolean shouldStartMoveDrag(int button, WindowRegion region) { | ||
return button == MouseEvent.BUTTON_LEFT && region == WindowRegion.TITLE; | ||
} | ||
|
||
protected boolean shouldStartResizeDrag(int button, WindowRegion region) { | ||
return button == MouseEvent.BUTTON_LEFT && RESIZE_CURSORS.get(region) != null; | ||
} | ||
|
||
private void handleMouseDrag(int button, int xAbs, int yAbs, WindowRegion region) { | ||
if (shouldStartMoveDrag(button, region)) { | ||
handleMoveWindow(xAbs, yAbs); | ||
} else if (shouldStartResizeDrag(button, region)) { | ||
handleResizeWindow(xAbs, yAbs, region); | ||
} | ||
} | ||
|
||
private void handleMouseDown(int xAbs, int yAbs) { | ||
mouseDownX = xAbs; | ||
mouseDownY = yAbs; | ||
mouseDownWindowX = window.getX(); | ||
mouseDownWindowY = window.getY(); | ||
mouseDownWindowWidth = window.getWidth(); | ||
mouseDownWindowHeight = window.getHeight(); | ||
} | ||
|
||
private void handleMoveWindow(int xAbs, int yAbs) { | ||
window.setPosition(mouseDownWindowX + xAbs - mouseDownX, mouseDownWindowY + yAbs - mouseDownY); | ||
} | ||
|
||
private void handleResizeWindow(int xAbs, int yAbs, WindowRegion region) { | ||
int dx = xAbs - mouseDownX; | ||
int dy = yAbs - mouseDownY; | ||
|
||
switch (region) { | ||
case LEFT: | ||
adjustWindowPosition(dx, 0); | ||
adjustWindowSize(-dx, 0); | ||
break; | ||
case RIGHT: | ||
adjustWindowSize(dx, 0); | ||
break; | ||
case TOP: | ||
adjustWindowPosition(0, dy); | ||
adjustWindowSize(0, -dy); | ||
break; | ||
case BOTTOM: | ||
adjustWindowSize(0, dy); | ||
break; | ||
case TOP_LEFT: | ||
adjustWindowPosition(dx, dy); | ||
adjustWindowSize(-dx, -dy); | ||
break; | ||
case TOP_RIGHT: | ||
adjustWindowPosition(0, dy); | ||
adjustWindowSize(dx, -dy); | ||
break; | ||
case BOTTOM_LEFT: | ||
adjustWindowPosition(dx, 0); | ||
adjustWindowSize(-dx, dy); | ||
break; | ||
case BOTTOM_RIGHT: | ||
adjustWindowSize(dx, dy); | ||
break; | ||
} | ||
} | ||
|
||
private void adjustWindowPosition(int dx, int dy) { | ||
int unclampedWidth = mouseDownWindowWidth - dx; | ||
int unclampedHeight = mouseDownWindowHeight - dy; | ||
int clampedWidth = dx != 0 ? clampWidth(unclampedWidth) : unclampedWidth; | ||
int clampedHeight = dy != 0 ? clampHeight(unclampedHeight) : unclampedHeight; | ||
int cx = unclampedWidth - clampedWidth; | ||
int cy = unclampedHeight - clampedHeight; | ||
window.setPosition(mouseDownWindowX + dx + cx, mouseDownWindowY + dy + cy); | ||
} | ||
|
||
private void adjustWindowSize(int dx, int dy) { | ||
int width = dx != 0 ? clampWidth(mouseDownWindowWidth + dx) : mouseDownWindowWidth; | ||
int height = dy != 0 ? clampHeight(mouseDownWindowHeight + dy) : mouseDownWindowHeight; | ||
window.setSize(width, height); | ||
} | ||
|
||
private int clampWidth(int width) { | ||
return Math.max(window.getMinimumWidth(), Math.min(window.getMaximumWidth(), width)); | ||
} | ||
|
||
private int clampHeight(int height) { | ||
return Math.max(window.getMinimumHeight(), Math.min(window.getMaximumHeight(), height)); | ||
} | ||
|
||
private void updateCursor(WindowRegion region) { | ||
Cursor newCursor = RESIZE_CURSORS.get(region); | ||
|
||
if (lastCursor == null && newCursor != null) { | ||
lastCursor = window.getCursor(); | ||
} else if (lastCursor != null && newCursor == null) { | ||
window.setCursor(lastCursor); | ||
lastCursor = null; | ||
} | ||
|
||
if (newCursor != null) { | ||
window.setCursor(newCursor); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Linux this will be constrained by the window manager, so it's not possible to move the window outside of the desktop bounds, including panels.
This can be done by implementing a
beginMoveDrag
on glass that will call (on linux):gdk_window_begin_move_drag