MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / update

Method update

src/Core/System/Cursor.cpp:121–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119 }
120
121 void Cursor::update()
122 {
123 const sf::Vector2i mousePos = sf::Mouse::getPosition(m_window.getWindow());
124 m_x = mousePos.x;
125 m_y = mousePos.y;
126 if (mousePos != m_saveOldPos)
127 {
128 m_cursorTriggers->pushParameter("Move", "x", m_x);
129 m_cursorTriggers->pushParameter("Move", "y", m_y);
130 m_cursorTriggers->pushParameter("Move", "oldX", m_saveOldPos.x);
131 m_cursorTriggers->pushParameter("Move", "oldY", m_saveOldPos.y);
132 m_cursorTriggers->trigger("Move");
133 m_saveOldPos = mousePos;
134 }
135 std::pair<int, int> constrainedPosition;
136 if (m_constraintCondition())
137 constrainedPosition = m_constraint(this);
138 else
139 constrainedPosition = std::make_pair(m_x, m_y);
140 m_constrainedX = constrainedPosition.first;
141 m_constrainedY = constrainedPosition.second;
142
143 bool hold = false;
144 bool press = false;
145 bool release = false;
146
147 for (auto& state : m_buttonState)
148 {
149 if (sf::Mouse::isButtonPressed(state.first) && state.second)
150 {
151 m_cursorTriggers->pushParameter(
152 "Hold", MouseButtonToString(state.first), true);
153 m_cursorTriggers->pushParameter("Hold", "x", m_x);
154 m_cursorTriggers->pushParameter("Hold", "y", m_y);
155 hold = true;
156 }
157 if (sf::Mouse::isButtonPressed(state.first) && !state.second)
158 {
159 m_cursorTriggers->pushParameter(
160 "Press", MouseButtonToString(state.first), true);
161 m_cursorTriggers->pushParameter("Press", "x", m_x);
162 m_cursorTriggers->pushParameter("Press", "y", m_y);
163 state.second = true;
164 press = true;
165 }
166 if (!sf::Mouse::isButtonPressed(state.first) && state.second)
167 {
168 m_cursorTriggers->pushParameter(
169 "Release", MouseButtonToString(state.first), true);
170 m_cursorTriggers->pushParameter("Release", "x", m_x);
171 m_cursorTriggers->pushParameter("Release", "y", m_y);
172 state.second = false;
173 release = true;
174 }
175 m_buttonState[state.first] = sf::Mouse::isButtonPressed(state.first);
176 }
177
178 if (hold)

Callers

nothing calls this directly

Calls 2

MouseButtonToStringFunction · 0.85
pushParameterMethod · 0.45

Tested by

no test coverage detected