axmol/core/base/EventMouse.h

208 lines
5.6 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
https://axmol.dev/
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
#ifndef _AX_MOUSEEVENT_H_
#define _AX_MOUSEEVENT_H_
2019-11-23 20:27:39 +08:00
#include "base/Event.h"
#include "math/Math.h"
2019-11-23 20:27:39 +08:00
/**
* @addtogroup base
* @{
*/
namespace ax
{
2019-11-23 20:27:39 +08:00
/** @class EventMouse
* @brief The mouse event.
*/
2022-07-16 10:43:05 +08:00
class AX_DLL EventMouse : public Event
2019-11-23 20:27:39 +08:00
{
public:
/**
2021-12-25 10:04:45 +08:00
* MouseEventType Different types of MouseEvent.
* @js NA
*/
2019-11-23 20:27:39 +08:00
enum class MouseEventType
{
MOUSE_NONE,
MOUSE_DOWN,
MOUSE_UP,
MOUSE_MOVE,
MOUSE_SCROLL,
};
enum class MouseButton
{
2021-12-25 10:04:45 +08:00
BUTTON_UNSET = -1,
BUTTON_LEFT = 0,
BUTTON_RIGHT = 1,
BUTTON_MIDDLE = 2,
BUTTON_4 = 3,
BUTTON_5 = 4,
BUTTON_6 = 5,
BUTTON_7 = 6,
BUTTON_8 = 7
2019-11-23 20:27:39 +08:00
};
/** Constructor.
*
* @param mouseEventCode A given mouse event type.
* @js ctor
*/
EventMouse(MouseEventType mouseEventCode);
/** Set mouse scroll data.
2021-12-25 10:04:45 +08:00
*
2019-11-23 20:27:39 +08:00
* @param scrollX The scroll data of x axis.
* @param scrollY The scroll data of y axis.
*/
2021-12-25 10:04:45 +08:00
void setScrollData(float scrollX, float scrollY)
{
_scrollX = scrollX;
_scrollY = scrollY;
}
2019-11-23 20:27:39 +08:00
/** Get mouse scroll data of x axis.
2021-12-25 10:04:45 +08:00
*
2019-11-23 20:27:39 +08:00
* @return The scroll data of x axis.
*/
float getScrollX() const { return _scrollX; }
/** Get mouse scroll data of y axis.
*
* @return The scroll data of y axis.
*/
float getScrollY() const { return _scrollY; }
/** Set the cursor position.
*
* @param x The x coordinate of cursor position.
* @param y The y coordinate of cursor position.
* @js setLocation
*/
2021-12-25 10:04:45 +08:00
void setCursorPosition(float x, float y)
{
_x = x;
_y = y;
2019-11-23 20:27:39 +08:00
_prevPoint = _point;
2021-12-25 10:04:45 +08:00
_point.x = x;
_point.y = y;
2019-11-23 20:27:39 +08:00
if (!_startPointCaptured)
{
2021-12-25 10:04:45 +08:00
_startPoint = _point;
2019-11-23 20:27:39 +08:00
_startPointCaptured = true;
}
}
/** Set mouse button.
2021-12-25 10:04:45 +08:00
*
2019-11-23 20:27:39 +08:00
* @param button a given mouse button.
* @js setButton
*/
void setMouseButton(MouseButton button) { _mouseButton = button; }
/** Get mouse button.
*
* @return The mouse button.
* @js getButton
*/
MouseButton getMouseButton() const { return _mouseButton; }
/** Get the cursor position of x axis.
*
* @return The x coordinate of cursor position.
* @js getLocationX
*/
float getCursorX() const { return _x; }
/** Get the cursor position of y axis.
*
* @return The y coordinate of cursor position.
* @js getLocationY
*/
float getCursorY() const { return _y; }
/** Returns the current touch location in OpenGL coordinates.
*
* @return The current touch location in OpenGL coordinates.
*/
Vec2 getLocation() const;
/** Returns the previous touch location in OpenGL coordinates.
*
* @return The previous touch location in OpenGL coordinates.
* @js NA
*/
Vec2 getPreviousLocation() const;
/** Returns the start touch location in OpenGL coordinates.
*
* @return The start touch location in OpenGL coordinates.
* @js NA
*/
Vec2 getStartLocation() const;
/** Returns the delta of 2 current touches locations in screen coordinates.
*
* @return The delta of 2 current touches locations in screen coordinates.
*/
Vec2 getDelta() const;
/** Returns the current touch location in screen coordinates.
*
* @return The current touch location in screen coordinates.
*/
Vec2 getLocationInView() const;
/** Returns the previous touch location in screen coordinates.
*
* @return The previous touch location in screen coordinates.
* @js NA
*/
Vec2 getPreviousLocationInView() const;
/** Returns the start touch location in screen coordinates.
*
* @return The start touch location in screen coordinates.
* @js NA
*/
Vec2 getStartLocationInView() const;
private:
MouseEventType _mouseEventType;
MouseButton _mouseButton;
float _x;
float _y;
float _scrollX;
float _scrollY;
bool _startPointCaptured;
Vec2 _startPoint;
Vec2 _point;
Vec2 _prevPoint;
friend class EventListenerMouse;
};
}
2019-11-23 20:27:39 +08:00
// end of base group
/// @}
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
#endif /* defined(_AX_MOUSEEVENT_H_) */