Merge remote-tracking branch 'holtrop/master'
This commit is contained in:
commit
0a34f6044f
@ -75,6 +75,7 @@ bool Client::create_window(bool fullscreen, int width, int height)
|
||||
OPENGL_CONTEXT_MAJOR, OPENGL_CONTEXT_MINOR);
|
||||
m_window = new sf::Window(mode, "Treacherous Terrain", style, cs);
|
||||
m_window->setMouseCursorVisible(false);
|
||||
grab_mouse(true);
|
||||
if (!initgl())
|
||||
return false;
|
||||
resize_window(m_window->getSize().x, m_window->getSize().y);
|
||||
@ -235,7 +236,7 @@ void Client::resize_window(int width, int height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
sf::Mouse::setPosition(sf::Vector2i(m_width / 2, m_height / 2), *m_window);
|
||||
recenter_cursor();
|
||||
glViewport(0, 0, width, height);
|
||||
float aspect = (float)width / (float)height;
|
||||
m_projection.load_identity();
|
||||
|
@ -114,6 +114,9 @@ void Client::run(bool fullscreen, int width, int height, std::string pname)
|
||||
case sf::Keyboard::Escape:
|
||||
m_window->close();
|
||||
break;
|
||||
case sf::Keyboard::F1:
|
||||
grab_mouse(!m_mouse_grabbed);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -158,6 +161,19 @@ void Client::run(bool fullscreen, int width, int height, std::string pname)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::recenter_cursor()
|
||||
{
|
||||
sf::Mouse::setPosition(sf::Vector2i(m_width / 2, m_height / 2), *m_window);
|
||||
}
|
||||
|
||||
void Client::grab_mouse(bool grab)
|
||||
{
|
||||
m_mouse_grabbed = grab;
|
||||
m_window->setMouseCursorVisible(!grab);
|
||||
if (grab)
|
||||
recenter_cursor();
|
||||
}
|
||||
|
||||
void Client::update(double elapsed_time)
|
||||
{
|
||||
static bool registered_player = false;
|
||||
@ -268,8 +284,11 @@ void Client::update(double elapsed_time)
|
||||
{
|
||||
s_pressed = KEY_PRESSED;
|
||||
}
|
||||
rel_mouse_movement = sf::Mouse::getPosition(*m_window).x - m_width / 2;
|
||||
sf::Mouse::setPosition(sf::Vector2i(m_width / 2, m_height / 2), *m_window);
|
||||
if (m_mouse_grabbed)
|
||||
{
|
||||
rel_mouse_movement = sf::Mouse::getPosition(*m_window).x - m_width / 2;
|
||||
recenter_cursor();
|
||||
}
|
||||
|
||||
if (m_left_button_pressed)
|
||||
{
|
||||
|
@ -24,6 +24,8 @@ class Client
|
||||
void resize_window(int width, int height);
|
||||
void update(double elapsed_time);
|
||||
void redraw();
|
||||
void grab_mouse(bool grab);
|
||||
void recenter_cursor();
|
||||
void draw_player(refptr<Player> player);
|
||||
void draw_map();
|
||||
void draw_overlay();
|
||||
@ -32,6 +34,7 @@ class Client
|
||||
void draw_shot_ring();
|
||||
void draw_shot_ring_instance();
|
||||
|
||||
bool m_mouse_grabbed;
|
||||
double m_player_dir_x;
|
||||
double m_player_dir_y;
|
||||
refptr<sf::Window> m_window;
|
||||
|
Loading…
x
Reference in New Issue
Block a user