Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 8b5d14d

Browse files
committed
add new mouse position and scroll
1 parent 99bc4d5 commit 8b5d14d

2 files changed

Lines changed: 54 additions & 9 deletions

File tree

module/includes/window/Window.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,26 @@ namespace sw
179179
SW_GRAPH_MODULE_EXPORT bool isMouseButtonUp(const int &btn);
180180

181181
////////////////////////////////////////////////////////////
182-
/// @brief Return true if given scroll direction is correct
182+
/// @brief Return current x and y position of mouse cursor
183183
///
184-
/// @param std::pair<double,double>&
184+
/// @param none
185185
///
186-
/// @return bool
186+
/// @return Vector2f
187+
///
188+
/// @throw none
189+
////////////////////////////////////////////////////////////
190+
SW_GRAPH_MODULE_EXPORT sw::Vector2f getMousePosition(void);
191+
192+
////////////////////////////////////////////////////////////
193+
/// @brief Return current scroll of x and y axis
194+
///
195+
/// @param none
196+
///
197+
/// @return Vector2f
187198
///
188199
/// @throw none
189200
////////////////////////////////////////////////////////////
190-
SW_GRAPH_MODULE_EXPORT bool mouseScrolled(const std::pair<double,double>&);
201+
SW_GRAPH_MODULE_EXPORT sw::Vector2f getMouseScroll(void);
191202

192203
////////////////////////////////////////////////////////////
193204
/// @brief Return True if mouse moved

module/sources/window/WindowCallBack.cpp

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,30 @@
99
#include "Buffer.hpp"
1010
#include "Inputs.hpp"
1111

12-
sw::Input_buffer event_buffer;
12+
//sw::Input_buffer event_buffer;
1313

1414
SW_GRAPH_MODULE_EXPORT char current_key_flags[sw::Keyboard::LAST];
1515
SW_GRAPH_MODULE_EXPORT char previous_key_flags[sw::Keyboard::LAST];
1616

1717
SW_GRAPH_MODULE_EXPORT char current_mouse_flags[sw::MouseBtn::Button_last];
1818
SW_GRAPH_MODULE_EXPORT char previous_mouse_flags[sw::MouseBtn::Button_last];
1919

20+
SW_GRAPH_MODULE_EXPORT sw::Vector2f current_mouse_position;
21+
SW_GRAPH_MODULE_EXPORT sw::Vector2f previous_mouse_position;
22+
23+
SW_GRAPH_MODULE_EXPORT sw::Vector2f current_mouse_scroll;
24+
SW_GRAPH_MODULE_EXPORT sw::Vector2f previous_mouse_scroll;
25+
2026
GLFWwindow *sw::Window::UpdateWindow()
2127
{
2228
for (int i = 0; i < sw::Keyboard::LAST; ++i)
2329
previous_key_flags[i] = current_key_flags[i];
2430
for (int i = 0; i < sw::MouseBtn::Button_last; ++i)
2531
previous_mouse_flags[i] = current_mouse_flags[i];
26-
event_buffer.clear();
32+
33+
previous_mouse_position = current_mouse_position;
34+
previous_mouse_scroll = current_mouse_scroll;
35+
//event_buffer.clear();
2736
glfwSwapBuffers(m_window);
2837
return (m_window);
2938
}
@@ -54,20 +63,27 @@ void sw::Window::mouse_button_callback(GLFWwindow*, int button, int action, int)
5463

5564
void sw::Window::position_callback(GLFWwindow*, double xpos, double ypos)
5665
{
66+
/*
5767
std::pair<int,int> kys{};
5868
std::pair<double,double> ipt{xpos,ypos};
5969
sw::Type tpe = sw::Position;
6070
6171
event_buffer.push(tpe, kys, ipt);
72+
*/
73+
74+
current_mouse_position = {xpos, ypos};
6275
}
6376

6477
void sw::Window::scroll_callback(GLFWwindow*, double x, double y)
6578
{
79+
/*
6680
std::pair<int,int> kys{};
6781
std::pair<double,double> ipt{x,y};
6882
sw::Type tpe = sw::Scroll;
6983
7084
event_buffer.push(tpe, kys, ipt);
85+
*/
86+
current_mouse_scroll = {x, y};
7187
}
7288

7389
void sw::Window::resizeCallBack(GLFWwindow *window, int width, int height)
@@ -134,26 +150,44 @@ bool sw::isMouseButtonUp(const int &btn)
134150
return !sw::isMouseButtonDown(btn);
135151
}
136152

153+
//DEPRECATED DO NOT USE
137154
bool sw::mouseMoved()
138155
{
156+
/*
139157
const auto &tmp = event_buffer.get();
140158
141159
for (size_t i = 0; i < event_buffer.getIdx(); ++i)
142160
{
143161
if (tmp[i].m_t == sw::Position)
144162
return true;
145-
}
163+
}*/
146164
return false;
147165
}
148166

149-
bool sw::mouseScrolled(const std::pair<double, double> &evt)
167+
sw::Vector2f sw::getMouseScroll(void)
150168
{
169+
/*
151170
const auto& tmp = event_buffer.get();
152171
153172
for (size_t i = 0; i < event_buffer.getIdx(); ++i)
154173
{
155174
if (tmp[i].m_t == sw::Scroll && tmp[i].m_os == evt)
156175
return true;
157176
}
158-
return false;
177+
*/
178+
return current_mouse_scroll;
179+
}
180+
181+
sw::Vector2f sw::getMousePosition(void)
182+
{
183+
/*
184+
const auto& tmp = event_buffer.get();
185+
186+
for (size_t i = 0; i < event_buffer.getIdx(); ++i)
187+
{
188+
if (tmp[i].m_t == sw::Scroll && tmp[i].m_os == evt)
189+
return true;
190+
}
191+
*/
192+
return current_mouse_position;
159193
}

0 commit comments

Comments
 (0)