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
master
bitplane 2007-06-09 03:01:58 +00:00
parent 2617554681
commit 29610f5d51
2 changed files with 75 additions and 12 deletions

View File

@ -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
#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
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)
{ {
XWarpPointer(Device->display, if (UseReferenceRect)
None, {
Device->window, 0, 0, XWarpPointer(Device->display,
Device->Width, None,
Device->Height, x, y); Device->window, 0, 0,
Device->Width,
Device->Height,
ReferenceRect.UpperLeftCorner.X + x,
ReferenceRect.UpperLeftCorner.Y + y);
}
else
{
XWarpPointer(Device->display,
None,
Device->window, 0, 0,
Device->Width,
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
virtual core::position2d<f32> getRelativePosition() virtual core::position2d<f32> getRelativePosition()
{ {
updateCursorPos(); updateCursorPos();
return core::position2d<f32>(CursorPos.X / (f32)Device->Width,
CursorPos.Y / (f32)Device->Height); if (!UseReferenceRect)
{
return core::position2d<f32>(CursorPos.X / (f32)Device->Width,
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
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;

View File

@ -1,2 +1,26 @@
// Copyright (C) 2005 Etienne Petitjean // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h #ifndef __C_IRR_DEVICE_MACOSX_H_INCLUDED__ #define __C_IRR_DEVICE_MACOSX_H_INCLUDED__ #include "IrrCompileConfig.h" #ifdef MACOSX #include "CIrrDeviceStub.h" #include "IrrlichtDevice.h" #include "IImagePresenter.h" #include "IGUIEnvironment.h" #include "ICursorControl.h" #include <OpenGL/OpenGL.h> #include <map> namespace irr { class CIrrDeviceMacOSX : public CIrrDeviceStub, video::IImagePresenter { public: //! constructor CIrrDeviceMacOSX(video::E_DRIVER_TYPE driverType, const core::dimension2d<s32>& windowSize, u32 bits, bool fullscreen, bool sbuffer, bool vsync, bool antiAlias, IEventReceiver* receiver, const char* version); //! destructor virtual ~CIrrDeviceMacOSX(); //! runs the device. Returns false if device wants to be deleted virtual bool run(); //! Cause the device to temporarily pause execution and let other processes to run // This should bring down processor usage without major performance loss for Irrlicht virtual void yield(); //! Pause execution and let other processes to run for a specified amount of time. // Copyright (C) 2005 Etienne Petitjean // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h #ifndef __C_IRR_DEVICE_MACOSX_H_INCLUDED__ #define __C_IRR_DEVICE_MACOSX_H_INCLUDED__ #include "IrrCompileConfig.h" #ifdef MACOSX #include "CIrrDeviceStub.h" #include "IrrlichtDevice.h" #include "IImagePresenter.h" #include "IGUIEnvironment.h" #include "ICursorControl.h" #include <OpenGL/OpenGL.h> #include <map> namespace irr { class CIrrDeviceMacOSX : public CIrrDeviceStub, video::IImagePresenter { public: //! constructor CIrrDeviceMacOSX(video::E_DRIVER_TYPE driverType, const core::dimension2d<s32>& windowSize, u32 bits, bool fullscreen, bool sbuffer, bool vsync, bool antiAlias, IEventReceiver* receiver, const char* version); //! destructor virtual ~CIrrDeviceMacOSX(); //! runs the device. Returns false if device wants to be deleted virtual bool run(); //! Cause the device to temporarily pause execution and let other processes to run // This should bring down processor usage without major performance loss for Irrlicht virtual void yield(); //! Pause execution and let other processes to run for a specified amount of time. virtual void sleep(u32 timeMs, bool pauseTimer); //! sets the caption of the window virtual void setWindowCaption(const wchar_t* text); //! returns if window is active. if not, nothing need to be drawn virtual bool isWindowActive(); //! presents a surface in the client area virtual void present(video::IImage* surface, s32 windowId = 0, core::rect<s32>* src=0 ); //! notifies the device that it should close itself virtual void closeDevice(); void flush(); void setMouseLocation(int x,int y); void setResize(int width,int height); void setCursorVisible(bool visible); private: //! create the driver void createDriver(video::E_DRIVER_TYPE driverType, const core::dimension2d<s32>& windowSize, u32 bits, bool fullscreen, bool stencilbuffer, bool vsync, bool antiAlias); //! Implementation of the macos x cursor control class CCursorControl : public gui::ICursorControl { public: CCursorControl(const core::dimension2d<s32>& wsize, CIrrDeviceMacOSX *device) : WindowSize(wsize), IsVisible(true), InvWindowSize(0.0f, 0.0f), _device(device), UseReferenceRect(false) { CursorPos.X = CursorPos.Y = 0; if (WindowSize.Width!=0) InvWindowSize.Width = 1.0f / WindowSize.Width; if (WindowSize.Height!=0) InvWindowSize.Height = 1.0f / WindowSize.Height; } //! Changes the visible state of the mouse cursor. virtual void setVisible(bool visible) { IsVisible = visible; _device->setCursorVisible(visible); } //! Returns if the cursor is currently visible. virtual bool isVisible() { return IsVisible; } //! Sets the new position of the cursor. virtual void setPosition(const core::position2d<f32> &pos) { setPosition(pos.X, pos.Y); } //! Sets the new position of the cursor. virtual void setPosition(f32 x, f32 y) { setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height)); } //! Sets the new position of the cursor. virtual void setPosition(const core::position2d<s32> &pos) { if (CursorPos.X != pos.X || CursorPos.Y != pos.Y) setPosition(pos.X, pos.Y); } //! Sets the new position of the cursor. virtual void setPosition(s32 x, s32 y) { if (UseReferenceRect) { _device->setMouseLocation(ReferenceRect.UpperLeftCorner.X + x, ReferenceRect.UpperLeftCorner.Y + y); } else { _device->setMouseLocation(x,y); } } //! Returns the current position of the mouse cursor. virtual core::position2d<s32> getPosition() { return CursorPos; } //! Returns the current position of the mouse cursor. virtual core::position2d<f32> getRelativePosition() { if (!UseReferenceRect)
virtual void sleep(u32 timeMs, bool pauseTimer); //! sets the caption of the window virtual void setWindowCaption(const wchar_t* text); //! returns if window is active. if not, nothing need to be drawn virtual bool isWindowActive(); //! presents a surface in the client area virtual void present(video::IImage* surface, s32 windowId = 0, core::rect<s32>* src=0 ); //! notifies the device that it should close itself virtual void closeDevice(); void flush(); void setMouseLocation(int x,int y); void setResize(int width,int height); void setCursorVisible(bool visible); private: //! create the driver void createDriver(video::E_DRIVER_TYPE driverType, const core::dimension2d<s32>& windowSize, u32 bits, bool fullscreen, bool stencilbuffer, bool vsync, bool antiAlias); //! Implementation of the macos x cursor control class CCursorControl : public gui::ICursorControl { public: CCursorControl(const core::dimension2d<s32>& wsize, CIrrDeviceMacOSX *device) : WindowSize(wsize), IsVisible(true), InvWindowSize(0.0f, 0.0f), _device(device) { CursorPos.X = CursorPos.Y = 0; if (WindowSize.Width!=0) InvWindowSize.Width = 1.0f / WindowSize.Width; if (WindowSize.Height!=0) InvWindowSize.Height = 1.0f / WindowSize.Height; } //! Changes the visible state of the mouse cursor. virtual void setVisible(bool visible) { IsVisible = visible; _device->setCursorVisible(visible); } //! Returns if the cursor is currently visible. virtual bool isVisible() { return IsVisible; } //! Sets the new position of the cursor. virtual void setPosition(const core::position2d<f32> &pos) { setPosition(pos.X, pos.Y); } //! Sets the new position of the cursor. virtual void setPosition(f32 x, f32 y) { setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height)); } //! Sets the new position of the cursor. virtual void setPosition(const core::position2d<s32> &pos) { if (CursorPos.X != pos.X || CursorPos.Y != pos.Y) setPosition(pos.X, pos.Y); } //! Sets the new position of the cursor. virtual void setPosition(s32 x, s32 y) { _device->setMouseLocation(x,y); } //! Returns the current position of the mouse cursor. virtual core::position2d<s32> getPosition() { return CursorPos; } //! Returns the current position of the mouse cursor. virtual core::position2d<f32> getRelativePosition() { return core::position2d<f32>(CursorPos.X * InvWindowSize.Width,CursorPos.Y * InvWindowSize.Height); } //! Updates the internal cursor position void updateInternalCursorPosition(int x,int y) { CursorPos.X = x; CursorPos.Y = y; } private: core::position2d<s32> CursorPos; core::dimension2d<s32> WindowSize; core::dimension2d<float> InvWindowSize; CIrrDeviceMacOSX *_device; bool IsVisible; }; bool createWindow(const irr::core::dimension2d<irr::s32>& windowSize, irr::u32 bits, bool fullscreen, bool vsync, bool stencilBuffer); void initKeycodes(); void storeMouseLocation(); void postMouseEvent(void *event,irr::SEvent &ievent); void postKeyEvent(void *event,irr::SEvent &ievent,bool pressed); video::E_DRIVER_TYPE DriverType; bool stencilbuffer; void *_window; CGLContextObj _cglcontext; void *_oglcontext; int _width; int _height; std::map<int,int> _keycodes; int _screenWidth; int _screenHeight; bool _active; }; } // end namespace irr #endif // MACOSX #endif // __C_IRR_DEVICE_MACOSX_H_INCLUDED__ {
return core::position2d<f32>(CursorPos.X * InvWindowSize.Width,
CursorPos.Y * InvWindowSize.Height);
}
return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(),
CursorPos.Y / (f32)ReferenceRect.getHeight()); } //! Sets an absolute reference rect for calculating the cursor position.
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;
} //! Updates the internal cursor position void updateInternalCursorPosition(int x,int y) { CursorPos.X = x; CursorPos.Y = y; } private: core::position2d<s32> CursorPos; core::dimension2d<s32> WindowSize; core::dimension2d<float> InvWindowSize; CIrrDeviceMacOSX *_device; bool IsVisible; bool UseReferenceRect; core::rect<s32> ReferenceRect; }; bool createWindow(const irr::core::dimension2d<irr::s32>& windowSize, irr::u32 bits, bool fullscreen, bool vsync, bool stencilBuffer); void initKeycodes(); void storeMouseLocation(); void postMouseEvent(void *event,irr::SEvent &ievent); void postKeyEvent(void *event,irr::SEvent &ievent,bool pressed); video::E_DRIVER_TYPE DriverType; bool stencilbuffer; void *_window; CGLContextObj _cglcontext; void *_oglcontext; int _width; int _height; std::map<int,int> _keycodes; int _screenWidth; int _screenHeight; bool _active; }; } // end namespace irr #endif // MACOSX #endif // __C_IRR_DEVICE_MACOSX_H_INCLUDED__