Browse Source

Added SetWindowPosition() / GetWindowPosition() to Graphics.

Lasse Öörni 12 years ago
parent
commit
2fbe931cee

+ 5 - 1
Docs/LuaScriptAPI.dox

@@ -1529,6 +1529,8 @@ Properties:
 Methods:
 
 - void SetWindowTitle(const String windowTitle)
+- void SetWindowPosition(const IntVector2& position)
+- void SetWindowPosition(int x, int y)
 - bool SetMode(int width, int height, bool fullscreen, bool resizable, bool vsync, bool tripleBuffer, int multiSample)
 - bool SetMode(int width, int height)
 - void SetSRGB(bool enable)
@@ -1538,6 +1540,7 @@ Methods:
 - bool IsInitialized() const
 - void* GetExternalWindow() const
 - const String& GetWindowTitle() const
+- IntVector2 GetWindowPosition() const
 - int GetWidth() const
 - int GetHeight() const
 - int GetMultiSample() const
@@ -1565,7 +1568,8 @@ Methods:
 Properties:
 
 - bool initialized (readonly)
-- const String windowTitle
+- String windowTitle
+- IntVector2 windowPosition
 - int width (readonly)
 - int height (readonly)
 - int multiSample (readonly)

+ 2 - 0
Docs/ScriptAPI.dox

@@ -3665,6 +3665,7 @@ Methods:
 - void SendEvent(const String&, VariantMap& = VariantMap ( ))
 - bool SetMode(int, int, bool, bool, bool, bool, int)
 - bool SetMode(int, int)
+- void SetWindowPosition(int, int)
 - bool ToggleFullscreen()
 - void Close()
 - bool TakeScreenShot(Image@)
@@ -3677,6 +3678,7 @@ Properties:
 - String typeName (readonly)
 - String category (readonly)
 - String windowTitle
+- IntVector2 windowPosition
 - bool sRGB
 - int width (readonly)
 - int height (readonly)

+ 21 - 2
Source/Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -173,8 +173,6 @@ Graphics::Graphics(Context* context) :
     width_(0),
     height_(0),
     multiSample_(1),
-    windowPosX_(0),
-    windowPosY_(0),
     fullscreen_(false),
     resizable_(false),
     vsync_(false),
@@ -261,6 +259,17 @@ void Graphics::SetWindowTitle(const String& windowTitle)
         SDL_SetWindowTitle(impl_->window_, windowTitle_.CString());
 }
 
+void Graphics::SetWindowPosition(const IntVector2& position)
+{
+    if (impl_->window_)
+        SDL_SetWindowPosition(impl_->window_, position.x_, position.y_);
+}
+
+void Graphics::SetWindowPosition(int x, int y)
+{
+    SetWindowPosition(IntVector2(x, y));
+}
+
 bool Graphics::SetMode(int width, int height, bool fullscreen, bool resizable, bool vsync, bool tripleBuffer, int multiSample)
 {
     PROFILE(SetScreenMode);
@@ -1781,6 +1790,16 @@ bool Graphics::IsInitialized() const
     return impl_->window_ != 0 && impl_->GetDevice() != 0;
 }
 
+IntVector2 Graphics::GetWindowPosition() const
+{
+    IntVector2 ret(IntVector2::ZERO);
+    
+    if (impl_->window_)
+        SDL_GetWindowPosition(impl_->window_, &ret.x_, &ret.y_);
+    
+    return ret;
+}
+
 PODVector<IntVector2> Graphics::GetResolutions() const
 {
     PODVector<IntVector2> ret;

+ 6 - 4
Source/Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -83,6 +83,10 @@ public:
     void SetExternalWindow(void* window);
     /// Set window title.
     void SetWindowTitle(const String& windowTitle);
+    /// Set window position.
+    void SetWindowPosition(const IntVector2& position);
+    /// Set window position.
+    void SetWindowPosition(int x, int y);
     /// Set screen mode. Return true if successful.
     bool SetMode(int width, int height, bool fullscreen, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
     /// Set screen resolution only. Return true if successful.
@@ -214,6 +218,8 @@ public:
     void* GetExternalWindow() const { return externalWindow_; }
     /// Return window title.
     const String& GetWindowTitle() const { return windowTitle_; }
+    /// Return window position.
+    IntVector2 GetWindowPosition() const;
     /// Return window width.
     int GetWidth() const { return width_; }
     /// Return window height.
@@ -411,10 +417,6 @@ private:
     int height_;
     /// Multisampling mode.
     int multiSample_;
-    /// Stored window X-position.
-    int windowPosX_;
-    /// Stored window Y-position.
-    int windowPosY_;
     /// Fullscreen flag.
     bool fullscreen_;
     /// Resizable flag.

+ 21 - 0
Source/Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -212,6 +212,17 @@ void Graphics::SetWindowTitle(const String& windowTitle)
         SDL_SetWindowTitle(impl_->window_, windowTitle_.CString());
 }
 
+void Graphics::SetWindowPosition(const IntVector2& position)
+{
+    if (impl_->window_)
+        SDL_SetWindowPosition(impl_->window_, position.x_, position.y_);
+}
+
+void Graphics::SetWindowPosition(int x, int y)
+{
+    SetWindowPosition(IntVector2(x, y));
+}
+
 bool Graphics::SetMode(int width, int height, bool fullscreen, bool resizable, bool vsync, bool tripleBuffer, int multiSample)
 {
     PROFILE(SetScreenMode);
@@ -1803,6 +1814,16 @@ bool Graphics::IsDeviceLost() const
     return impl_->context_ == 0;
 }
 
+IntVector2 Graphics::GetWindowPosition() const
+{
+    IntVector2 ret(IntVector2::ZERO);
+    
+    if (impl_->window_)
+        SDL_GetWindowPosition(impl_->window_, &ret.x_, &ret.y_);
+    
+    return ret;
+}
+
 PODVector<IntVector2> Graphics::GetResolutions() const
 {
     PODVector<IntVector2> ret;

+ 7 - 1
Source/Engine/Graphics/OpenGL/OGLGraphics.h

@@ -83,11 +83,15 @@ public:
     Graphics(Context* context_);
     /// Destruct. Release the OpenGL context and close the window.
     virtual ~Graphics();
-    
+
     /// Set external window handle. Only effective before setting the initial screen mode. On Windows it is necessary to set up OpenGL pixel format manually for the window.
     void SetExternalWindow(void* window);
     /// Set window title.
     void SetWindowTitle(const String& windowTitle);
+    /// Set window position.
+    void SetWindowPosition(const IntVector2& position);
+    /// Set window position.
+    void SetWindowPosition(int x, int y);
     /// Set screen mode. Return true if successful.
     bool SetMode(int width, int height, bool fullscreen, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
     /// Set screen resolution only. Return true if successful.
@@ -221,6 +225,8 @@ public:
     void* GetExternalWindow() const { return externalWindow_; }
     /// Return window title.
     const String& GetWindowTitle() const { return windowTitle_; }
+    /// Return window position.
+    IntVector2 GetWindowPosition() const;
     /// Return window width.
     int GetWidth() const { return width_; }
     /// Return window height.

+ 3 - 0
Source/Engine/Script/GraphicsAPI.cpp

@@ -1177,11 +1177,14 @@ static void RegisterGraphics(asIScriptEngine* engine)
     RegisterObject<Graphics>(engine, "Graphics");
     engine->RegisterObjectMethod("Graphics", "bool SetMode(int, int, bool, bool, bool, bool, int)", asMETHODPR(Graphics, SetMode, (int, int, bool, bool, bool, bool, int), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool SetMode(int, int)", asMETHODPR(Graphics, SetMode, (int, int), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Graphics", "void SetWindowPosition(int, int)", asMETHODPR(Graphics, SetWindowPosition, (int, int), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool ToggleFullscreen()", asMETHOD(Graphics, ToggleFullscreen), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "void Close()", asMETHOD(Graphics, Close), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool TakeScreenShot(Image@+)", asMETHOD(Graphics, TakeScreenShot), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "void set_windowTitle(const String&in)", asMETHOD(Graphics, SetWindowTitle), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "const String& get_windowTitle() const", asMETHOD(Graphics, GetWindowTitle), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Graphics", "void set_windowPosition(const IntVector2&in)", asMETHODPR(Graphics, SetWindowPosition, (const IntVector2&), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Graphics", "IntVector2 get_windowPosition() const", asMETHOD(Graphics, GetWindowPosition), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "void set_sRGB(bool)", asMETHOD(Graphics, SetSRGB), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_sRGB() const", asMETHOD(Graphics, GetSRGB), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "int get_width() const", asMETHOD(Graphics, GetWidth), asCALL_THISCALL);

+ 6 - 2
Source/Extras/LuaScript/pkgs/Graphics/Graphics.pkg

@@ -3,7 +3,9 @@ $#include "Graphics.h"
 class Graphics : public Object
 {
     void SetWindowTitle(const String windowTitle);
-    
+    void SetWindowPosition(const IntVector2& position);
+    void SetWindowPosition(int x, int y);
+
     bool SetMode(int width, int height, bool fullscreen, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
     bool SetMode(int width, int height);
     
@@ -15,6 +17,7 @@ class Graphics : public Object
     bool IsInitialized() const;
     void* GetExternalWindow() const;
     const String& GetWindowTitle() const;
+    IntVector2 GetWindowPosition() const;
     int GetWidth() const;
     int GetHeight() const;
     int GetMultiSample() const;
@@ -41,7 +44,8 @@ class Graphics : public Object
     static unsigned GetRGBFormat();
     
     tolua_readonly tolua_property__is_set bool initialized;
-    tolua_property__get_set const String windowTitle;
+    tolua_property__get_set String windowTitle;
+    tolua_property__get_set IntVector2 windowPosition;
     tolua_readonly tolua_property__get_set int width;
     tolua_readonly tolua_property__get_set int height;
     tolua_readonly tolua_property__get_set int multiSample;