-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.cpp
55 lines (46 loc) · 1.63 KB
/
mouse.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
// Ixte - a temporal structure editor for musical composition and analysis
// Copyright (C) 2014 Raphael Sousa Santos, http://www.raphaelss.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mouse.hpp"
#include "config.hpp"
namespace ixte {
static constexpr unsigned mouse_text_size = 12;
mouse::mouse(const ruler &ruler_arg, sf::Font &font)
: _ruler(&ruler_arg), _x(0), _y(0), _t_pos(0), _on(false), _in_line(false),
_str(), _text(_str, font, mouse_text_size) {
_text.setColor(quasi_black);
}
void mouse::update_t() {
_t_pos = _ruler->get_time_at(_x);
_str = std::to_string(_t_pos);
_str.erase(_str.find_last_not_of('0') + 1, std::string::npos);
_text.setString(_str);
}
void mouse::update_position(double x, double y) {
_x = x;
_y = y;
_in_line = _x >= _ruler->line_begin_x() && _x <= _ruler->line_end_x();
update_t();
}
void mouse::on(bool x) {
_on = x;
}
void mouse::draw(sf::RenderTarget &target) {
if (_on && _in_line) {
_text.setPosition(_x + 7, _y - 7);
target.draw(_text);
}
}
}