-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseEvents.cpp
More file actions
43 lines (37 loc) · 1.51 KB
/
Copy pathMouseEvents.cpp
File metadata and controls
43 lines (37 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Created by jonng on 4/11/2021.
//
#ifndef TYPINGINSFML_MOUSEEVENTS_CPP
#define TYPINGINSFML_MOUSEEVENTS_CPP
#include "MouseEvents.h"
template <class T>
bool MouseEvents<T>::mouseClicked(T& object, sf::RenderWindow& aWindow) {
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
return hovered(object,aWindow);
}
else
return false;
}
template<class T>
bool MouseEvents<T>::mouseClicked(sf::RenderWindow &window, sf::Event event) {
sf::IntRect windowBounds = {0, 0, static_cast<int>(window.getSize().x), static_cast<int>(window.getSize().y)};
return (event.type == sf::Event::MouseButtonPressed && windowBounds.contains(static_cast<sf::Vector2i>(sf::Mouse::getPosition(window))));
}
template<class T>
bool MouseEvents<T>::hovered(T &object, sf::RenderWindow &window) {
return (object.getGlobalBounds().contains(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window))));
}
template<class T>
bool MouseEvents<T>::mouseReleased(T &object, sf::RenderWindow &aWindow) {
if(!sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
return hovered(object,aWindow);
}
else
return false;
}
template<class T>
bool MouseEvents<T>::mouseReleased(sf::RenderWindow &window, sf::Event event) {
sf::IntRect windowBounds = {0, 0, static_cast<int>(window.getSize().x), static_cast<int>(window.getSize().y)};
return (event.type == sf::Event::MouseButtonReleased && windowBounds.contains(static_cast<sf::Vector2i>(sf::Mouse::getPosition(window))));
}
#endif //TYPINGINSFML_MOUSEEVENTS_CPP