Added window position parameter to device creation params. For now, window is not programmatically movable. This patch is merely intended for restoring the device in the same location as with last run. Patch provided by Auria

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4472 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2013-03-07 12:44:11 +00:00
parent b53e949e6e
commit a36cdf072b
13 changed files with 111 additions and 8 deletions

View File

@ -236,6 +236,9 @@ namespace irr
//! Restore the window to normal size if possible. //! Restore the window to normal size if possible.
virtual void restoreWindow() =0; virtual void restoreWindow() =0;
//! Get the position of the frame on-screen
virtual core::position2di getWindowPosition() = 0;
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
/** Irrlicht contains support for joysticks, but does not generate joystick events by default, /** Irrlicht contains support for joysticks, but does not generate joystick events by default,
as this would consume joystick info that 3rd party libraries might rely on. Call this method to as this would consume joystick info that 3rd party libraries might rely on. Call this method to

View File

@ -9,6 +9,7 @@
#include "EDeviceTypes.h" #include "EDeviceTypes.h"
#include "dimension2d.h" #include "dimension2d.h"
#include "ILogger.h" #include "ILogger.h"
#include "position2d.h"
namespace irr namespace irr
{ {
@ -23,6 +24,7 @@ namespace irr
DeviceType(EIDT_BEST), DeviceType(EIDT_BEST),
DriverType(video::EDT_BURNINGSVIDEO), DriverType(video::EDT_BURNINGSVIDEO),
WindowSize(core::dimension2d<u32>(800, 600)), WindowSize(core::dimension2d<u32>(800, 600)),
WindowPosition(core::position2di(-1,-1)),
Bits(16), Bits(16),
ZBufferBits(16), ZBufferBits(16),
Fullscreen(false), Fullscreen(false),
@ -58,6 +60,7 @@ namespace irr
DeviceType = other.DeviceType; DeviceType = other.DeviceType;
DriverType = other.DriverType; DriverType = other.DriverType;
WindowSize = other.WindowSize; WindowSize = other.WindowSize;
WindowPosition = other.WindowPosition;
Bits = other.Bits; Bits = other.Bits;
ZBufferBits = other.ZBufferBits; ZBufferBits = other.ZBufferBits;
Fullscreen = other.Fullscreen; Fullscreen = other.Fullscreen;
@ -102,6 +105,9 @@ namespace irr
//! Size of the window or the video mode in fullscreen mode. Default: 800x600 //! Size of the window or the video mode in fullscreen mode. Default: 800x600
core::dimension2d<u32> WindowSize; core::dimension2d<u32> WindowSize;
//! Position of the window on-screen. Default: (-1, -1) or centered.
core::position2di WindowPosition;
//! Minimum Bits per pixel of the color buffer in fullscreen mode. Ignored if windowed mode. Default: 16. //! Minimum Bits per pixel of the color buffer in fullscreen mode. Ignored if windowed mode. Default: 16.
u8 Bits; u8 Bits;

View File

@ -68,6 +68,12 @@ namespace irr
//! returns if window is minimized //! returns if window is minimized
virtual bool isWindowMinimized() const; virtual bool isWindowMinimized() const;
//! returns current window position (not supported for this device)
virtual core::position2di getWindowPosition()
{
return core::position2di(-1, -1);
}
//! presents a surface in the client area //! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0); virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0);

View File

@ -63,6 +63,12 @@ namespace irr
//! Restores original window size //! Restores original window size
virtual void restoreWindow(); virtual void restoreWindow();
//! returns current window position (not supported for this device)
virtual core::position2di getWindowPosition()
{
return core::position2di(-1, -1);
}
//! presents a surface in the client area //! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId = 0, core::rect<s32>* src=0 ); virtual bool present(video::IImage* surface, void* windowId = 0, core::rect<s32>* src=0 );

View File

@ -662,15 +662,25 @@ bool CIrrDeviceLinux::createWindow()
if (!CreationParams.WindowId) if (!CreationParams.WindowId)
{ {
int x = 0;
int y = 0;
if (!CreationParams.Fullscreen)
{
if (CreationParams.WindowPosition.X > 0) x = CreationParams.WindowPosition.X;
if (CreationParams.WindowPosition.Y > 0) y = CreationParams.WindowPosition.Y;
}
// create new Window // create new Window
// Remove window manager decoration in fullscreen // Remove window manager decoration in fullscreen
attributes.override_redirect = CreationParams.Fullscreen; attributes.override_redirect = CreationParams.Fullscreen;
window = XCreateWindow(display, window = XCreateWindow(display,
RootWindow(display, visual->screen), RootWindow(display, visual->screen),
0, 0, Width, Height, 0, visual->depth, x, y, Width, Height, 0, visual->depth,
InputOutput, visual->visual, InputOutput, visual->visual,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect,
&attributes); &attributes);
XMapRaised(display, window); XMapRaised(display, window);
CreationParams.WindowId = (void*)window; CreationParams.WindowId = (void*)window;
Atom wmDelete; Atom wmDelete;
@ -1435,6 +1445,13 @@ void CIrrDeviceLinux::restoreWindow()
#endif #endif
} }
core::position2di CIrrDeviceLinux::getWindowPosition()
{
int wx = 0, wy = 0;
Window child;
XTranslateCoordinates(display, window, DefaultRootWindow(display), 0, 0, &wx, &wy, &child);
return core::position2di(wx, wy);
}
void CIrrDeviceLinux::createKeyMap() void CIrrDeviceLinux::createKeyMap()
{ {

View File

@ -101,6 +101,9 @@ namespace irr
//! Restores the window size. //! Restores the window size.
virtual void restoreWindow(); virtual void restoreWindow();
//! Get the position of this window on screen
virtual core::position2di getWindowPosition();
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -753,6 +753,12 @@ void CIrrDeviceSDL::maximizeWindow()
// do nothing // do nothing
} }
//! Get the position of this window on screen
core::position2di getWindowPosition()
{
return core::position2di(-1, -1);
}
//! Restore original window size //! Restore original window size
void CIrrDeviceSDL::restoreWindow() void CIrrDeviceSDL::restoreWindow()

View File

@ -77,6 +77,9 @@ namespace irr
//! Restores the window size. //! Restores the window size.
virtual void restoreWindow(); virtual void restoreWindow();
//! Get the position of this window on screen
virtual core::position2di getWindowPosition();
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -976,8 +976,12 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
const s32 realWidth = clientSize.right - clientSize.left; const s32 realWidth = clientSize.right - clientSize.left;
const s32 realHeight = clientSize.bottom - clientSize.top; const s32 realHeight = clientSize.bottom - clientSize.top;
s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2; s32 windowLeft = (CreationParams.WindowPosition.X == -1 ?
s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2; (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2 :
CreationParams.WindowPosition.X);
s32 windowTop = (CreationParams.WindowPosition.Y == -1 ?
(GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2 :
CreationParams.WindowPosition.Y);
if ( windowLeft < 0 ) if ( windowLeft < 0 )
windowLeft = 0; windowLeft = 0;
@ -1735,6 +1739,22 @@ void CIrrDeviceWin32::restoreWindow()
SetWindowPlacement(HWnd, &wndpl); SetWindowPlacement(HWnd, &wndpl);
} }
core::position2di CIrrDeviceWin32::getWindowPosition()
{
WINDOWPLACEMENT wndpl;
wndpl.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(HWnd, &wndpl))
{
return core::position2di((int)wndpl.rcNormalPosition.left,
(int)wndpl.rcNormalPosition.top);
}
else
{
// No reason for this to happen
os::Printer::log("Failed to retrieve window location", ELL_ERROR);
return core::position2di(-1, -1);
}
}
bool CIrrDeviceWin32::activateJoysticks(core::array<SJoystickInfo> & joystickInfo) bool CIrrDeviceWin32::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
{ {

View File

@ -85,6 +85,9 @@ namespace irr
//! Restores the window size. //! Restores the window size.
virtual void restoreWindow(); virtual void restoreWindow();
//! Get the position of the window on screen
virtual core::position2di getWindowPosition();
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -53,6 +53,12 @@ namespace irr
//! returns if window is minimized //! returns if window is minimized
virtual bool isWindowMinimized() const; virtual bool isWindowMinimized() const;
//! returns current window position (not supported for this device)
virtual core::position2di getWindowPosition()
{
return core::position2di(-1, -1);
}
//! presents a surface in the client area //! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId = 0, core::rect<s32>* src=0 ); virtual bool present(video::IImage* surface, void* windowId = 0, core::rect<s32>* src=0 );

View File

@ -84,6 +84,9 @@ namespace irr
//! Restore the window to normal size if possible. //! Restore the window to normal size if possible.
virtual void restoreWindow(); virtual void restoreWindow();
//! Get the position of this window on screen
virtual core::position2di getWindowPosition();
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -26,7 +26,7 @@
#include "COSOperator.h" #include "COSOperator.h"
#include "CColorConverter.h" #include "CColorConverter.h"
#include "irrlicht.h" #include "irrlicht.h"
#include <algorithm>
#import <wchar.h> #import <wchar.h>
#import <time.h> #import <time.h>
@ -623,9 +623,18 @@ bool CIrrDeviceMacOSX::createWindow()
{ {
if(!CreationParams.WindowId) //create another window when WindowId is null if(!CreationParams.WindowId) //create another window when WindowId is null
{ {
NSBackingStoreType type = (CreationParams.DriverType == video::EDT_OPENGL) ? NSBackingStoreBuffered : NSBackingStoreNonretained; const NSBackingStoreType type = (CreationParams.DriverType == video::EDT_OPENGL) ? NSBackingStoreBuffered : NSBackingStoreNonretained;
Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:type defer:FALSE]; int x = std::max(0, CreationParams.WindowPosition.X);
int y = std::max(0, CreationParams.WindowPosition.Y);
if (CreationParams.WindowPosition.Y > -1)
{
int screenHeight = [[[NSScreen screens] objectAtIndex:0] frame].size.height;
y = screenHeight - y - CreationParams.WindowSize.Height;
}
Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(x,y,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:type defer:FALSE];
} }
if (Window != NULL || CreationParams.WindowId) if (Window != NULL || CreationParams.WindowId)
@ -718,7 +727,10 @@ bool CIrrDeviceMacOSX::createWindow()
{ {
if (!CreationParams.WindowId) if (!CreationParams.WindowId)
{ {
[Window center]; if (CreationParams.WindowPosition.X == -1 && CreationParams.WindowPosition.Y == -1)
{
[Window center];
}
[Window setDelegate:[NSApp delegate]]; [Window setDelegate:[NSApp delegate]];
if(CreationParams.DriverType == video::EDT_OPENGL) if(CreationParams.DriverType == video::EDT_OPENGL)
@ -1497,11 +1509,20 @@ void CIrrDeviceMacOSX::maximizeWindow()
} }
//! Restore the window to normal size if possible. //! get the window to normal size if possible.
void CIrrDeviceMacOSX::restoreWindow() void CIrrDeviceMacOSX::restoreWindow()
{ {
[Window deminiaturize:[NSApp self]]; [Window deminiaturize:[NSApp self]];
} }
//! Get the position of this window on screen
core::position2di CIrrDeviceMacOSX::getWindowPosition()
{
NSRect rect = [Window frame];
int screenHeight = [[[NSScreen screens] objectAtIndex:0] frame].size.height;
return core::position2di(rect.origin.x, screenHeight - rect.origin.y - rect.size.height);
}
bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src ) bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src )