ICursorControl was never implemented for Mobile.....
So, here is my contribution.
---------------------------------------------
CMobileCursorControl.h:
Code: Select all
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
// Jonathan Frisch : Sep. 15, 2014
#ifndef __C_MOBILE_CURSOR_CONTROL_H_INCLUDED__
#define __C_MOBILE_CURSOR_CONTROL_H_INCLUDED__
#include "IrrlichtDevice.h"
#include "ICursorControl.h"
#include "position2d.h"
#include "dimension2d.h"
#include "rect.h"
namespace irr
{
namespace gui
{
//! The type of motion that the touch event will emulate.
enum ECURSOR_TOUCH_MOTION_TYPE
{
ECTMT_DRAG, // getPosition returns difference between relative center and current touch point
ECTMT_TRACE, // getPosition returns difference between last touch point and current touch point
ECTMT_COUNT // maximum : for consistency
};
//! Mobile fake mouse cursor control.
class CMobileCursorControl : public ICursorControl
{
public:
CMobileCursorControl(IrrlichtDevice* device);
virtual ~CMobileCursorControl();
//! Manually update touch point.
virtual void updateTouchPoint(core::position2di touch);
//! Mobile device -- does nothing
virtual void setVisible(bool visible) _IRR_OVERRIDE_;
//! Mobile device -- return false
virtual bool isVisible() _IRR_OVERRIDE_;
//! Sets the new position of the cursor.
/** The position must be
between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
the top left corner and (1.0f, 1.0f) is the bottom right corner of the
render window.
\param pos New position of the cursor. */
virtual void setPosition(const core::position2df &pos) _IRR_OVERRIDE_;
//! Sets the new position of the cursor.
/** The position must be
between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
the top left corner and (1.0f, 1.0f) is the bottom right corner of the
render window.
\param x New x-coord of the cursor.
\param y New x-coord of the cursor. */
virtual void setPosition(f32 x, f32 y) _IRR_OVERRIDE_;
//! Sets the new position of the cursor.
/** \param pos: New position of the cursor. The coordinates are pixel units. */
virtual void setPosition(const core::position2di &pos) _IRR_OVERRIDE_;
//! Sets the new position of the cursor.
/** \param x New x-coord of the cursor. The coordinates are pixel units.
\param y New y-coord of the cursor. The coordinates are pixel units. */
virtual void setPosition(s32 x, s32 y) _IRR_OVERRIDE_;
//! Returns the current position of the mouse cursor.
/** \return Returns the current position of the cursor. The returned position
is the position of the mouse cursor in pixel units. */
virtual const core::position2di& getPosition() _IRR_OVERRIDE_;
//! Returns the current position of the mouse cursor.
/** \return Returns the current position of the cursor. The returned position
is a value between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
the top left corner and (1.0f, 1.0f) is the bottom right corner of the
render window. */
virtual core::position2df getRelativePosition() _IRR_OVERRIDE_;
//! Sets an absolute reference rect for setting and retrieving the cursor position.
/** If this rect is set, the cursor position is not being calculated relative to
the rendering window but to this rect. You can set the rect pointer to 0 to disable
this feature again. This feature is useful when rendering into parts of foreign windows
for example in an editor.
\param rect: A pointer to an reference rectangle or 0 to disable the reference rectangle.*/
virtual void setReferenceRect(core::recti* rect=0) _IRR_OVERRIDE_;
//! Set the touch motion behavior type.
virtual void setTouchMotionType(ECURSOR_TOUCH_MOTION_TYPE type);
//! Get the touch motion behavior type.
virtual ECURSOR_TOUCH_MOTION_TYPE getTouchMotionType();
//! Set the factor to scale the movement.
virtual void setMovementScaleFactor(f32 scale);
//! Get the scaling factor for movement.
virtual f32 getMovementScaleFactor();
private:
ECURSOR_TOUCH_MOTION_TYPE mtype;
core::recti* ref;
f32 factor;
core::position2di relCenter, ctouch, ltouch;
IrrlichtDevice* iDevice;
};
} // end namespace gui
} // end namespace irr
#endif // __C_MOBILE_CURSOR_CONTROL_H_INCLUDED__
-------------------------------------------
CMobileCursorControl.cpp
Code: Select all
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
// Jonathan Frisch : Sep. 15, 2014
#include "CMobileCursorControl.h"
namespace irr
{
namespace gui
{
CMobileCursorControl::CMobileCursorControl(IrrlichtDevice* device) : mtype(ECTMT_DRAG),
ref(0), relCenter(0, 0),
iDevice(device), ctouch(0, 0), ltouch(0, 0)
{
iDevice->grab();
#if defined(_DEBUG) || defined(DEBUG)
setDebugName("CMobileCursorControl");
#endif // DEBUG
setReferenceRect();
}
CMobileCursorControl::~CMobileCursorControl()
{
iDevice->drop();
if(ref) delete ref;
}
//! Manually update touch point.
void CMobileCursorControl::updateTouchPoint(core::position2di touch)
{
ltouch = ctouch;
ctouch = touch;
}
//! Mobile device -- does nothing
void CMobileCursorControl::setVisible(bool visible)
{
}
//! Mobile device -- return false
bool CMobileCursorControl::isVisible()
{
return false;
}
//! Sets the new position of the cursor.
/** The position must be
between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
the top left corner and (1.0f, 1.0f) is the bottom right corner of the
render window.
\param pos New position of the cursor. */
void CMobileCursorControl::setPosition(const core::position2df &pos)
{
setPosition(pos.X, pos.Y);
}
//! Sets the new position of the cursor.
/** The position must be
between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
the top left corner and (1.0f, 1.0f) is the bottom right corner of the
render window.
\param x New x-coord of the cursor.
\param y New x-coord of the cursor. */
void CMobileCursorControl::setPosition(f32 x, f32 y)
{
setPosition(s32(x * (ref->LowerRightCorner.X - ref->UpperLeftCorner.X)), s32(y * (ref->LowerRightCorner.Y - ref->UpperLeftCorner.Y)));
}
//! Sets the new position of the cursor.
/** \param pos: New position of the cursor. The coordinates are pixel units. */
void CMobileCursorControl::setPosition(const core::position2di &pos)
{
relCenter = pos;
}
//! Sets the new position of the cursor.
/** \param x New x-coord of the cursor. The coordinates are pixel units.
\param y New y-coord of the cursor. The coordinates are pixel units. */
void CMobileCursorControl::setPosition(s32 x, s32 y)
{
setPosition(core::position2di(x, y));
}
//! Returns the current position of the mouse cursor.
/** \return Returns the current position of the cursor. The returned position
is the position of the mouse cursor in pixel units. */
const core::position2di& CMobileCursorControl::getPosition()
{
if(ref->isPointInside(ctouch))
{
core::position2di p;
switch(mtype)
{
case ECTMT_DRAG:
p.X = (relCenter.X - ctouch.X) * factor;
p.Y = (relCenter.Y - ctouch.Y) * factor;
break;
case ECTMT_TRACE:
p.X = (ltouch.X - ctouch.X) * factor;
p.Y = (ltouch.Y - ctouch.Y) * factor;
break;
default:
p.X = relCenter.X;
p.Y = relCenter.Y;
break;
}
return p;
}
return relCenter;
}
//! Returns the current position of the mouse cursor.
/** \return Returns the current position of the cursor. The returned position
is a value between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
the top left corner and (1.0f, 1.0f) is the bottom right corner of the
render window. */
core::position2df CMobileCursorControl::getRelativePosition()
{
core::position2di t(getPosition());
return core::position2df(t.X / (ref->LowerRightCorner.X - ref->UpperLeftCorner.X), t.Y / (ref->LowerRightCorner.Y - ref->UpperLeftCorner.Y));
}
//! Sets an absolute reference rect for setting and retrieving the cursor position.
/** If this rect is set, the cursor position is not being calculated relative to
the rendering window but to this rect. You can set the rect pointer to 0 to disable
this feature again. This feature is useful when rendering into parts of foreign windows
for example in an editor.
\param rect: A pointer to an reference rectangle or 0 to disable the reference rectangle.*/
void CMobileCursorControl::setReferenceRect(core::recti* rect)
{
if(!rect) rect = new core::recti(core::position2di(0, 0), iDevice->getVideoDriver()->getScreenSize());
if(ref) delete ref;
ref = rect;
}
//! Set the touch motion behavior type.
void CMobileCursorControl::setTouchMotionType(ECURSOR_TOUCH_MOTION_TYPE type)
{
mtype = type;
}
//! Get the touch motion behavior type.
ECURSOR_TOUCH_MOTION_TYPE CMobileCursorControl::getTouchMotionType()
{
return mtype;
}
//! Set the factor to scale the movement.
void CMobileCursorControl::setMovementScaleFactor(f32 scale)
{
factor = scale;
}
//! Get the scaling factor for movement.
f32 CMobileCursorControl::getMovementScaleFactor()
{
return factor;
}
} // end namespace gui
} // end namespace irr