Commit 29610f5d authored by bitplane's avatar bitplane

added reference rect to linux and osx devices (untested)

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@700 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 26175546
...@@ -96,9 +96,8 @@ namespace irr ...@@ -96,9 +96,8 @@ namespace irr
public: public:
CCursorControl(CIrrDeviceLinux* dev, bool null) CCursorControl(CIrrDeviceLinux* dev, bool null)
: Device(dev), IsVisible(true), Null(null) : Device(dev), IsVisible(true), Null(null), UseReferenceRect(false)
{ {
Device->grab();
#ifdef _IRR_COMPILE_WITH_X11_ #ifdef _IRR_COMPILE_WITH_X11_
if (!null) if (!null)
{ {
...@@ -136,7 +135,6 @@ namespace irr ...@@ -136,7 +135,6 @@ namespace irr
#ifdef _IRR_COMPILE_WITH_X11_ #ifdef _IRR_COMPILE_WITH_X11_
XFreeGC(Device->display, gc); XFreeGC(Device->display, gc);
#endif #endif
Device->drop();
} }
//! Changes the visible state of the mouse cursor. //! Changes the visible state of the mouse cursor.
...@@ -182,16 +180,33 @@ namespace irr ...@@ -182,16 +180,33 @@ namespace irr
virtual void setPosition(s32 x, s32 y) virtual void setPosition(s32 x, s32 y)
{ {
#ifdef _IRR_COMPILE_WITH_X11_ #ifdef _IRR_COMPILE_WITH_X11_
if (!Null) if (!Null)
{
if (UseReferenceRect)
{
XWarpPointer(Device->display,
None,
Device->window, 0, 0,
Device->Width,
Device->Height,
ReferenceRect.UpperLeftCorner.X + x,
ReferenceRect.UpperLeftCorner.Y + y);
}
else
{ {
XWarpPointer(Device->display, XWarpPointer(Device->display,
None, None,
Device->window, 0, 0, Device->window, 0, 0,
Device->Width, Device->Width,
Device->Height, x, y); Device->Height, x, y);
}
XFlush(Device->display); XFlush(Device->display);
} }
#endif #endif
CursorPos.X = x;
CursorPos.Y = y;
} }
//! Returns the current position of the mouse cursor. //! Returns the current position of the mouse cursor.
...@@ -205,12 +220,34 @@ namespace irr ...@@ -205,12 +220,34 @@ namespace irr
virtual core::position2d<f32> getRelativePosition() virtual core::position2d<f32> getRelativePosition()
{ {
updateCursorPos(); updateCursorPos();
if (!UseReferenceRect)
{
return core::position2d<f32>(CursorPos.X / (f32)Device->Width, return core::position2d<f32>(CursorPos.X / (f32)Device->Width,
CursorPos.Y / (f32)Device->Height); CursorPos.Y / (f32)Device->Height);
} }
return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(),
CursorPos.Y / (f32)ReferenceRect.getHeight());
}
virtual void setReferenceRect(core::rect<s32>* rect=0) virtual void setReferenceRect(core::rect<s32>* rect=0)
{ {
if (rect)
{
ReferenceRect = *rect;
UseReferenceRect = true;
// prevent division through zero and uneven sizes
if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2)
ReferenceRect.LowerRightCorner.Y += 1;
if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2)
ReferenceRect.LowerRightCorner.X += 1;
}
else
UseReferenceRect = false;
} }
private: private:
...@@ -244,6 +281,8 @@ namespace irr ...@@ -244,6 +281,8 @@ namespace irr
CIrrDeviceLinux* Device; CIrrDeviceLinux* Device;
bool IsVisible; bool IsVisible;
bool Null; bool Null;
bool UseReferenceRect;
core::rect<s32> ReferenceRect;
#ifdef _IRR_COMPILE_WITH_X11_ #ifdef _IRR_COMPILE_WITH_X11_
GC gc; GC gc;
Cursor invisCursor; Cursor invisCursor;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment