16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

Make launcher respond to window resize

This commit is contained in:
jakubg1
2025-09-09 17:08:23 +02:00
parent c217081823
commit 9fa22d81e5
12 changed files with 105 additions and 133 deletions

View File

@@ -74,6 +74,7 @@ void framebuffer_resize_callback( GLFWwindow *, int w, int h ) {
void window_resize_callback( GLFWwindow *, int w, int h ) {
Global.window_size = glm::ivec2(w, h);
Application.on_window_resize(w, h);
}
void cursor_pos_callback( GLFWwindow *window, double x, double y ) {
@@ -603,19 +604,19 @@ eu07_application::pop_mode() {
}
bool
eu07_application::push_mode( eu07_application::mode const Mode ) {
eu07_application::push_mode( mode const Mode ) {
if( Mode >= mode::count_ )
if( Mode >= count_ )
return false;
if (!m_modes[Mode]) {
if (Mode == mode::launcher)
if (Mode == launcher)
m_modes[Mode] = std::make_shared<launcher_mode>();
if (Mode == mode::scenarioloader)
if (Mode == scenarioloader)
m_modes[Mode] = std::make_shared<scenarioloader_mode>();
if (Mode == mode::driver)
if (Mode == driver)
m_modes[Mode] = std::make_shared<driver_mode>();
if (Mode == mode::editor)
if (Mode == editor)
m_modes[Mode] = std::make_shared<editor_mode>();
if (!m_modes[Mode]->init())
@@ -733,6 +734,14 @@ void eu07_application::on_focus_change(bool focus) {
}
}
void eu07_application::on_window_resize(int w, int h)
{
if (m_modestack.empty())
return;
m_modes[m_modestack.top()]->on_window_resize(w, h);
}
GLFWwindow *
eu07_application::window(int const Windowindex, bool visible, int width, int height, GLFWmonitor *monitor, bool keep_ownership , bool share_ctx) {

View File

@@ -70,18 +70,13 @@ public:
set_cursor_pos( double const Horizontal, double const Vertical );
void queue_screenshot();
// input handlers
void
on_key( int const Key, int const Scancode, int const Action, int const Mods );
void
on_char( unsigned int const Char );
void
on_cursor_pos( double const Horizontal, double const Vertical );
void
on_mouse_button( int const Button, int const Action, int const Mods );
void
on_scroll( double const Xoffset, double const Yoffset );
void
on_focus_change(bool focus);
void on_key( int const Key, int const Scancode, int const Action, int const Mods );
void on_char( unsigned int const Char );
void on_cursor_pos( double const Horizontal, double const Vertical );
void on_mouse_button( int const Button, int const Action, int const Mods );
void on_scroll( double const Xoffset, double const Yoffset );
void on_focus_change(bool focus);
void on_window_resize(int w, int h);
// gives access to specified window, creates a new window if index == -1
GLFWwindow *
window( int const Windowindex = 0, bool visible = false, int width = 1, int height = 1, GLFWmonitor *monitor = nullptr, bool keep_ownership = true, bool share_ctx = true );

View File

@@ -17,65 +17,41 @@ class application_mode {
public:
// destructor
virtual
~application_mode() = default;
virtual ~application_mode() = default;
// methods;
// initializes internal data structures of the mode. returns: true on success, false otherwise
virtual
bool
init() = 0;
virtual bool init() = 0;
// mode-specific update of simulation data. returns: false on error, true otherwise
virtual
bool
update() = 0;
virtual bool update() = 0;
// draws mode-specific user interface
inline
void
render_ui() {
void render_ui() {
if( m_userinterface != nullptr ) {
m_userinterface->render(); } }
inline
void
begin_ui_frame() {
void begin_ui_frame() {
if( m_userinterface != nullptr ) {
m_userinterface->begin_ui_frame(); } }
inline
void
set_progress( float const Progress = 0.f, float const Subtaskprogress = 0.f ) {
void set_progress( float const Progress = 0.f, float const Subtaskprogress = 0.f ) {
if( m_userinterface != nullptr ) {
m_userinterface->set_progress( Progress, Subtaskprogress ); } }
inline
void
set_tooltip( std::string const &Tooltip ) {
void set_tooltip( std::string const &Tooltip ) {
if( m_userinterface != nullptr ) {
m_userinterface->set_tooltip( Tooltip ); } }
// maintenance method, called when the mode is activated
virtual
void
enter() = 0;
virtual void enter() = 0;
// maintenance method, called when the mode is deactivated
virtual
void
exit() = 0;
virtual void exit() = 0;
// input handlers
virtual
void
on_key( int const Key, int const Scancode, int const Action, int const Mods ) = 0;
virtual
void
on_cursor_pos( double const X, double const Y ) = 0;
virtual
void
on_mouse_button( int const Button, int const Action, int const Mods ) = 0;
virtual
void
on_scroll( double const Xoffset, double const Yoffset ) = 0;
virtual
void
on_event_poll() = 0;
virtual
bool
is_command_processor() const = 0;
virtual void on_key( int Key, int Scancode, int Action, int Mods ) = 0;
virtual void on_cursor_pos( double X, double Y ) = 0;
virtual void on_mouse_button( int Button, int Action, int Mods ) = 0;
virtual void on_scroll( double Xoffset, double Yoffset ) = 0;
virtual void on_window_resize( int w, int h ) = 0;
virtual void on_event_poll() = 0;
virtual bool is_command_processor() const = 0;
protected:
// members

View File

@@ -32,30 +32,21 @@ public:
// methods
// initializes internal data structures of the mode. returns: true on success, false otherwise
bool
init() override;
bool init() override;
// mode-specific update of simulation data. returns: false on error, true otherwise
bool
update() override;
bool update() override;
// maintenance method, called when the mode is activated
void
enter() override;
void enter() override;
// maintenance method, called when the mode is deactivated
void
exit() override;
void exit() override;
// input handlers
void
on_key( int const Key, int const Scancode, int const Action, int const Mods ) override;
void
on_cursor_pos( double const Horizontal, double const Vertical ) override;
void
on_mouse_button( int const Button, int const Action, int const Mods ) override;
void
on_scroll( double const Xoffset, double const Yoffset ) override;
void
on_event_poll() override;
bool
is_command_processor() const override;
void on_key( int Key, int Scancode, int Action, int Mods ) override;
void on_cursor_pos( double Horizontal, double Vertical ) override;
void on_mouse_button( int Button, int Action, int Mods ) override;
void on_scroll( double Xoffset, double Yoffset ) override;
void on_window_resize( int w, int h ) override { ; }
void on_event_poll() override;
bool is_command_processor() const override;
private:
// types

View File

@@ -23,30 +23,21 @@ public:
editor_mode();
// methods
// initializes internal data structures of the mode. returns: true on success, false otherwise
bool
init() override;
bool init() override;
// mode-specific update of simulation data. returns: false on error, true otherwise
bool
update() override;
bool update() override;
// maintenance method, called when the mode is activated
void
enter() override;
void enter() override;
// maintenance method, called when the mode is deactivated
void
exit() override;
void exit() override;
// input handlers
void
on_key( int const Key, int const Scancode, int const Action, int const Mods ) override;
void
on_cursor_pos( double const Horizontal, double const Vertical ) override;
void
on_mouse_button( int const Button, int const Action, int const Mods ) override;
void
on_scroll( double const Xoffset, double const Yoffset ) override { ; }
void
on_event_poll() override;
bool
is_command_processor() const override;
void on_key( int Key, int Scancode, int Action, int Mods ) override;
void on_cursor_pos( double Horizontal, double Vertical ) override;
void on_mouse_button( int Button, int Action, int Mods ) override;
void on_scroll( double const Xoffset, double const Yoffset ) override { ; }
void on_window_resize( int w, int h ) override { ; }
void on_event_poll() override;
bool is_command_processor() const override;
private:
// types

View File

@@ -38,3 +38,8 @@ void launcher_mode::on_key(const int Key, const int Scancode, const int Action,
{
m_userinterface->on_key(Key, Action);
}
void launcher_mode::on_window_resize(const int w, const int h)
{
m_userinterface->on_window_resize(w, h);
}

View File

@@ -30,16 +30,11 @@ public:
void
exit() override;
// input handlers
void
on_key( int const Key, int const Scancode, int const Action, int const Mods );
void
on_cursor_pos( double const Horizontal, double const Vertical ) override { ; }
void
on_mouse_button( int const Button, int const Action, int const Mods ) override { ; }
void
on_scroll( double const Xoffset, double const Yoffset ) override { ; }
void
on_event_poll() override { ; }
bool
is_command_processor() const override { return false; }
void on_key( int Key, int Scancode, int Action, int Mods ) override;
void on_cursor_pos( double const Horizontal, double const Vertical ) override { ; }
void on_mouse_button( int const Button, int const Action, int const Mods ) override { ; }
void on_scroll( double const Xoffset, double const Yoffset ) override { ; }
void on_window_resize( int w, int h ) override;
void on_event_poll() override { ; }
bool is_command_processor() const override { return false; }
};

View File

@@ -3,8 +3,7 @@
#include "application.h"
#include "translation.h"
launcher_ui::launcher_ui()
: m_scenery_scanner(m_vehicles_bank), m_scenerylist_panel(m_scenery_scanner)
launcher_ui::launcher_ui() : m_scenery_scanner(m_vehicles_bank), m_scenerylist_panel(m_scenery_scanner)
{
m_vehicles_bank.scan_textures();
m_scenery_scanner.scan();
@@ -29,6 +28,11 @@ bool launcher_ui::on_key(const int Key, const int Action)
return ui_layer::on_key(Key, Action);
}
void launcher_ui::on_window_resize(int w, int h)
{
open_panel(m_current_panel);
}
void launcher_ui::render_()
{
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove;
@@ -68,4 +72,6 @@ void launcher_ui::open_panel(ui_panel* panel)
panel->size = glm::vec2(Global.window_size.x, Global.window_size.y - topbar_height);
panel->no_title_bar = true;
panel->is_open = true;
m_current_panel = panel;
}

View File

@@ -20,6 +20,7 @@ class launcher_ui : public ui_layer {
public:
launcher_ui();
bool on_key(const int Key, const int Action) override;
void on_window_resize(int w, int h) override;
private:
void render_() override;
@@ -32,4 +33,6 @@ private:
ui::scenerylist_panel m_scenerylist_panel;
ui::keymapper_panel m_keymapper_panel;
ui::vehiclepicker_panel m_vehiclepicker_panel;
ui_panel *m_current_panel;
};

View File

@@ -21,28 +21,19 @@ public:
scenarioloader_mode();
// methods
// initializes internal data structures of the mode. returns: true on success, false otherwise
bool
init() override;
bool init() override;
// mode-specific update of simulation data. returns: false on error, true otherwise
bool
update() override;
bool update() override;
// maintenance method, called when the mode is activated
void
enter() override;
void enter() override;
// maintenance method, called when the mode is deactivated
void
exit() override;
void exit() override;
// input handlers
void
on_key( int const Key, int const Scancode, int const Action, int const Mods ) override { ; }
void
on_cursor_pos( double const Horizontal, double const Vertical ) override { ; }
void
on_mouse_button( int const Button, int const Action, int const Mods ) override { ; }
void
on_scroll( double const Xoffset, double const Yoffset ) override { ; }
void
on_event_poll() override { ; }
bool
is_command_processor() const override;
void on_key( int const Key, int const Scancode, int const Action, int const Mods ) override { ; }
void on_cursor_pos( double const Horizontal, double const Vertical ) override { ; }
void on_mouse_button( int const Button, int const Action, int const Mods ) override { ; }
void on_scroll( double const Xoffset, double const Yoffset ) override { ; }
void on_window_resize( int w, int h ) override { ; }
void on_event_poll() override { ; }
bool is_command_processor() const override;
};

View File

@@ -314,6 +314,13 @@ bool ui_layer::on_mouse_button(int const Button, int const Action)
return false;
}
void ui_layer::on_window_resize(int w, int h)
{
for (auto *panel : m_panels)
panel->on_window_resize(w, h);
}
void ui_layer::update()
{
for (auto *panel : m_panels)

View File

@@ -23,7 +23,8 @@ public:
ui_panel( std::string Identifier, bool Isopen );
virtual ~ui_panel() = default;
// methods
virtual void update() {};
virtual void update() {}
virtual void on_window_resize(int w, int h) {}
virtual void render();
virtual void render_contents();
// temporary access
@@ -88,6 +89,8 @@ public:
virtual bool on_cursor_pos( double Horizontal, double Vertical );
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
virtual bool on_mouse_button( int Button, int Action );
// processes window resize.
virtual void on_window_resize(int w, int h);
// updates state of UI elements
virtual void update();
// draws requested UI elements