Added the new public API's Display.getX() and Display.getY(). Currently implemented for Linux and Mac. Windows implementation pending.

This commit is contained in:
kappa1 2012-02-18 16:30:38 +00:00
parent 839db549a9
commit e5ebf82c81
5 changed files with 80 additions and 4 deletions

View File

@ -1281,11 +1281,51 @@ public final class Display {
return window_resized;
}
/**
* @return this method will return the x position (top-left) of the Display window.
*
* If running in fullscreen mode it will return 0.
* If Display.setParent(Canvas parent) is being used, the x position of
* the parent will be returned.
*/
public static int getX() {
if (Display.isFullscreen()) {
return 0;
}
if (parent != null) {
return parent.getX();
}
return display_impl.getX();
}
/**
* @return this method will return the y position (top-left) of the Display window.
*
* If running in fullscreen mode it will return 0.
* If Display.setParent(Canvas parent) is being used, the y position of
* the parent will be returned.
*/
public static int getY() {
if (Display.isFullscreen()) {
return 0;
}
if (parent != null) {
return parent.getY();
}
return display_impl.getY();
}
/**
* @return this method will return the width of the Display window.
*
* If running in fullscreen mode it will return the width of the current set DisplayMode.
* If running Display.setParent(Canvas parent) is being used, the width of the parent
* If Display.setParent(Canvas parent) is being used, the width of the parent
* will be returned.
*
* This value will be updated after a call to Display.update().
@ -1307,7 +1347,7 @@ public final class Display {
* @return this method will return the height of the Display window.
*
* If running in fullscreen mode it will return the height of the current set DisplayMode.
* If running Display.setParent(Canvas parent) is being used, the height of the parent
* If Display.setParent(Canvas parent) is being used, the height of the parent
* will be returned.
*
* This value will be updated after a call to Display.update().

View File

@ -174,12 +174,22 @@ interface DisplayImplementation extends InputImplementation {
boolean wasResized();
/**
* @return this method will return a the width of the Display window.
* @return this method will return the width of the Display window.
*/
int getWidth();
/**
* @return this method will return a the height of the Display window.
* @return this method will return the height of the Display window.
*/
int getHeight();
/**
* @return this method will return the top-left x position of the Display window.
*/
int getX();
/**
* @return this method will return the top-left y position of the Display window.
*/
int getY();
}

View File

@ -473,6 +473,8 @@ final class LinuxDisplay implements DisplayImplementation {
parent_window = parent != null ? getHandle(parent) : getRootWindow(getDisplay(), getDefaultScreen());
resizable = Display.isResizable();
resized = false;
window_x = x;
window_y = y;
window_width = mode.getWidth();
window_height = mode.getHeight();
current_window = nCreateWindow(getDisplay(), getDefaultScreen(), handle, mode, current_window_mode, x, y, undecorated, parent_window, resizable);
@ -1387,6 +1389,14 @@ final class LinuxDisplay implements DisplayImplementation {
private static native void nSetWindowIcon(long display, long window, ByteBuffer icon_rgb, int icon_rgb_size, ByteBuffer icon_mask, int icon_mask_size, int width, int height);
public int getX() {
return window_x;
}
public int getY() {
return window_y;
}
public int getWidth() {
return window_width;
}

View File

@ -495,6 +495,14 @@ final class MacOSXDisplay implements DisplayImplementation {
// Don't use any icon, since Mac OS X windows don't have window icons
return 0;
}
public int getX() {
return frame.getX();
}
public int getY() {
return frame.getY();
}
public int getWidth() {
return frame.getWidth();

View File

@ -1013,6 +1013,14 @@ final class WindowsDisplay implements DisplayImplementation {
return defWindowProc(hwnd, msg, wParam, lParam);
}
}
public int getX() {
return 0; // placeholder until implemented
}
public int getY() {
return 0; // placeholder until implemented
}
public int getWidth() {
return width;