Norbert's Game Engine v200
Loading...
Searching...
No Matches
eMouse Class Reference

#include <Mouse.hpp>

Inheritance diagram for eMouse:
eInput eBase

Public Member Functions

void SetPositionCallback (NGE_MOUSE_POSCALLBACK callback)
 
void GetPosition (real6 &xpos, real6 &ypos)
 
void DisableCursor ()
 
void HideCursor ()
 
void NormalCursor ()
 
void CheckRawMouseMotionSupport ()
 
void SetEnterCallback (NGE_MOUSE_ENTERCALLBACK callback)
 
const bool IsHovering ()
 
void SetMouseButtonCallback (NGE_MOUSE_BUTTONCALLBACK callback)
 
const int GetButtonState (const int button)
 
void SetStickyMode (const int vl)
 
void SetScrollCallback (NGE_MOUSE_SCROLLCALLBACK callback)
 
const bool GetButtonPressed (const int button)
 
const bool GetButtonDown (const int button)
 
const bool GetButtonReleased (const int button)
 
void CreateCursor (eMouseCursor *cursor, int type)
 
eMouseCursor * CreateImageCursor (eMouseCursor *cursor, eString filename, bool flipV=false, vec2i xyhot=vec2i(0))
 
void SetCursor (eMouseCursor *cursor)
 
eMouseCursor * DestroyCursor (eMouseCursor *cursor)
 
- Public Member Functions inherited from eInput
void SetWindow (eWindow *window)
 
eWindow * GetWindow ()
 
GLFWwindow * GetGLFWwindow ()
 
void SetInputMode (const int mode, const int value)
 
- Public Member Functions inherited from eBase
template<typename T >
T * Cast (eBase *obj)
 Cast class to base.
 

Detailed Description

Mouse input

Definition at line 48 of file Mouse.hpp.

Member Function Documentation

◆ CheckRawMouseMotionSupport()

void eMouse::CheckRawMouseMotionSupport ( )

Definition at line 34 of file Mouse.cpp.

35{
36 if (glfwRawMouseMotionSupported()) {
37 eConsole::PrintLog("INFO::eMouse::CheckRawMouseMotionSupport", "Current machine does support raw mouse motion");
38 glfwSetInputMode(GetGLFWwindow(), GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
39 return;
40 }
41 eConsole::PrintLog("INFO::eMouse::CheckRawMouseMotionSupport", "Current machine does not support raw mouse motion");
42 glfwSetInputMode(GetGLFWwindow(), GLFW_RAW_MOUSE_MOTION, GLFW_FALSE);
43}
static void PrintLog(eString head, eString msg)
Print a log.
Definition Console.cpp:22

◆ CreateCursor()

void eMouse::CreateCursor ( eMouseCursor * cursor,
int type )

Definition at line 120 of file Mouse.cpp.

121{
122 if (cursor != nullptr)
123 glfwDestroyCursor(cursor);
124 cursor = glfwCreateStandardCursor(type);
125}

◆ CreateImageCursor()

eMouseCursor * eMouse::CreateImageCursor ( eMouseCursor * cursor,
eString filename,
bool flipV = false,
vec2i xyhot = vec2i(0) )

Definition at line 127 of file Mouse.cpp.

128{
129 if (cursor != nullptr)
130 glfwDestroyCursor(cursor);
131
132 stbi_set_flip_vertically_on_load(flipV);
133 int width, height, nrComponents;
134 unsigned char* data = stbi_load(filename.Get(), &width, &height, &nrComponents, 0);
135 if (data != nullptr)
136 {
137 GLFWimage image;
138 image.width = width;
139 image.height = height;
140 image.pixels = data;
141 cursor = glfwCreateCursor(&image, xyhot.x, xyhot.y);
142 stbi_image_free(data);
143 }
144 stbi_set_flip_vertically_on_load(false);
145 return cursor;
146}
const char * Get()
Return text as c-string.
Definition String.cpp:64

◆ DestroyCursor()

eMouseCursor * eMouse::DestroyCursor ( eMouseCursor * cursor)

Definition at line 153 of file Mouse.cpp.

154{
155 if (cursor != nullptr)
156 {
157 glfwDestroyCursor(cursor);
158 cursor = nullptr;
159 }
160 return nullptr;
161}

◆ DisableCursor()

void eMouse::DisableCursor ( )

Definition at line 19 of file Mouse.cpp.

20{
21 glfwSetInputMode(GetGLFWwindow(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
22}

◆ GetButtonDown()

const bool eMouse::GetButtonDown ( const int button)

Definition at line 106 of file Mouse.cpp.

107{
108 if (glfwGetMouseButton(GetGLFWwindow(), button) == GLFW_PRESS)
109 return true;
110 return false;
111}

◆ GetButtonPressed()

const bool eMouse::GetButtonPressed ( const int button)

Definition at line 75 of file Mouse.cpp.

76{
77 bool isDown = false;
78 int location = 0;
79 for (int i = 0; i < mButtonPressed.size(); i++)
80 {
81 if (mButtonPressed[i] == button)
82 {
83 location = i;
84 isDown = true;
85 break;
86 }
87 }
88
89 if (isDown)
90 {
91 if (GetButtonReleased(button))
92 mButtonPressed.erase(mButtonPressed.begin() + location);
93 return false;
94 }
95 else
96 {
97 if (GetButtonDown(button))
98 {
99 mButtonPressed.push_back(button);
100 return true;
101 }
102 }
103 return false;
104}

◆ GetButtonReleased()

const bool eMouse::GetButtonReleased ( const int button)

Definition at line 113 of file Mouse.cpp.

114{
115 if (glfwGetMouseButton(GetGLFWwindow(), button) == GLFW_RELEASE)
116 return true;
117 return false;
118}

◆ GetButtonState()

const int eMouse::GetButtonState ( const int button)

Definition at line 60 of file Mouse.cpp.

61{
62 return glfwGetMouseButton(GetGLFWwindow(), button);
63}

◆ GetPosition()

void eMouse::GetPosition ( real6 & xpos,
real6 & ypos )

Definition at line 14 of file Mouse.cpp.

15{
16 glfwGetCursorPos(GetGLFWwindow(), &xpos, &ypos);
17}

◆ HideCursor()

void eMouse::HideCursor ( )

Definition at line 24 of file Mouse.cpp.

25{
26 glfwSetInputMode(GetGLFWwindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
27}

◆ IsHovering()

const bool eMouse::IsHovering ( )

Definition at line 50 of file Mouse.cpp.

51{
52 return glfwGetWindowAttrib(GetGLFWwindow(), GLFW_HOVERED);
53}

◆ NormalCursor()

void eMouse::NormalCursor ( )

Definition at line 29 of file Mouse.cpp.

30{
31 glfwSetInputMode(GetGLFWwindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
32}

◆ SetCursor()

void eMouse::SetCursor ( eMouseCursor * cursor)

Definition at line 148 of file Mouse.cpp.

149{
150 glfwSetCursor(GetGLFWwindow(), cursor);
151}

◆ SetEnterCallback()

void eMouse::SetEnterCallback ( NGE_MOUSE_ENTERCALLBACK callback)

Definition at line 45 of file Mouse.cpp.

46{
47 glfwSetCursorEnterCallback(GetGLFWwindow(), callback);
48}

◆ SetMouseButtonCallback()

void eMouse::SetMouseButtonCallback ( NGE_MOUSE_BUTTONCALLBACK callback)

Definition at line 55 of file Mouse.cpp.

56{
57 glfwSetMouseButtonCallback(GetGLFWwindow(), callback);
58}

◆ SetPositionCallback()

void eMouse::SetPositionCallback ( NGE_MOUSE_POSCALLBACK callback)

Definition at line 9 of file Mouse.cpp.

10{
11 glfwSetCursorPosCallback(GetGLFWwindow(), callback);
12}

◆ SetScrollCallback()

void eMouse::SetScrollCallback ( NGE_MOUSE_SCROLLCALLBACK callback)

Definition at line 70 of file Mouse.cpp.

71{
72 glfwSetScrollCallback(GetGLFWwindow(), callback);
73}

◆ SetStickyMode()

void eMouse::SetStickyMode ( const int vl)

Definition at line 65 of file Mouse.cpp.

66{
67 glfwSetInputMode(GetGLFWwindow(), GLFW_STICKY_MOUSE_BUTTONS, vl);
68}

The documentation for this class was generated from the following files: