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 ) { void window_resize_callback( GLFWwindow *, int w, int h ) {
Global.window_size = glm::ivec2(w, h); Global.window_size = glm::ivec2(w, h);
Application.on_window_resize(w, h);
} }
void cursor_pos_callback( GLFWwindow *window, double x, double y ) { void cursor_pos_callback( GLFWwindow *window, double x, double y ) {
@@ -603,19 +604,19 @@ eu07_application::pop_mode() {
} }
bool 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; return false;
if (!m_modes[Mode]) { if (!m_modes[Mode]) {
if (Mode == mode::launcher) if (Mode == launcher)
m_modes[Mode] = std::make_shared<launcher_mode>(); m_modes[Mode] = std::make_shared<launcher_mode>();
if (Mode == mode::scenarioloader) if (Mode == scenarioloader)
m_modes[Mode] = std::make_shared<scenarioloader_mode>(); m_modes[Mode] = std::make_shared<scenarioloader_mode>();
if (Mode == mode::driver) if (Mode == driver)
m_modes[Mode] = std::make_shared<driver_mode>(); m_modes[Mode] = std::make_shared<driver_mode>();
if (Mode == mode::editor) if (Mode == editor)
m_modes[Mode] = std::make_shared<editor_mode>(); m_modes[Mode] = std::make_shared<editor_mode>();
if (!m_modes[Mode]->init()) 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 * GLFWwindow *
eu07_application::window(int const Windowindex, bool visible, int width, int height, GLFWmonitor *monitor, bool keep_ownership , bool share_ctx) { 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 ); set_cursor_pos( double const Horizontal, double const Vertical );
void queue_screenshot(); void queue_screenshot();
// input handlers // input handlers
void void on_key( int const Key, int const Scancode, int const Action, int const Mods );
on_key( int const Key, int const Scancode, int const Action, int const Mods ); void on_char( unsigned int const Char );
void void on_cursor_pos( double const Horizontal, double const Vertical );
on_char( unsigned int const Char ); void on_mouse_button( int const Button, int const Action, int const Mods );
void void on_scroll( double const Xoffset, double const Yoffset );
on_cursor_pos( double const Horizontal, double const Vertical ); void on_focus_change(bool focus);
void void on_window_resize(int w, int h);
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);
// gives access to specified window, creates a new window if index == -1 // gives access to specified window, creates a new window if index == -1
GLFWwindow * 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 ); 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: public:
// destructor // destructor
virtual virtual ~application_mode() = default;
~application_mode() = default;
// methods; // methods;
// initializes internal data structures of the mode. returns: true on success, false otherwise // initializes internal data structures of the mode. returns: true on success, false otherwise
virtual virtual bool init() = 0;
bool
init() = 0;
// mode-specific update of simulation data. returns: false on error, true otherwise // mode-specific update of simulation data. returns: false on error, true otherwise
virtual virtual bool update() = 0;
bool
update() = 0;
// draws mode-specific user interface // draws mode-specific user interface
inline inline
void void render_ui() {
render_ui() {
if( m_userinterface != nullptr ) { if( m_userinterface != nullptr ) {
m_userinterface->render(); } } m_userinterface->render(); } }
inline inline
void void begin_ui_frame() {
begin_ui_frame() {
if( m_userinterface != nullptr ) { if( m_userinterface != nullptr ) {
m_userinterface->begin_ui_frame(); } } m_userinterface->begin_ui_frame(); } }
inline inline
void void set_progress( float const Progress = 0.f, float const Subtaskprogress = 0.f ) {
set_progress( float const Progress = 0.f, float const Subtaskprogress = 0.f ) {
if( m_userinterface != nullptr ) { if( m_userinterface != nullptr ) {
m_userinterface->set_progress( Progress, Subtaskprogress ); } } m_userinterface->set_progress( Progress, Subtaskprogress ); } }
inline inline
void void set_tooltip( std::string const &Tooltip ) {
set_tooltip( std::string const &Tooltip ) {
if( m_userinterface != nullptr ) { if( m_userinterface != nullptr ) {
m_userinterface->set_tooltip( Tooltip ); } } m_userinterface->set_tooltip( Tooltip ); } }
// maintenance method, called when the mode is activated // maintenance method, called when the mode is activated
virtual virtual void enter() = 0;
void
enter() = 0;
// maintenance method, called when the mode is deactivated // maintenance method, called when the mode is deactivated
virtual virtual void exit() = 0;
void
exit() = 0;
// input handlers // input handlers
virtual virtual void on_key( int Key, int Scancode, int Action, int Mods ) = 0;
void virtual void on_cursor_pos( double X, double Y ) = 0;
on_key( int const Key, int const Scancode, int const Action, int const Mods ) = 0; virtual void on_mouse_button( int Button, int Action, int Mods ) = 0;
virtual virtual void on_scroll( double Xoffset, double Yoffset ) = 0;
void virtual void on_window_resize( int w, int h ) = 0;
on_cursor_pos( double const X, double const Y ) = 0; virtual void on_event_poll() = 0;
virtual virtual bool is_command_processor() const = 0;
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;
protected: protected:
// members // members

View File

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

View File

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

View File

@@ -3,8 +3,7 @@
#include "application.h" #include "application.h"
#include "translation.h" #include "translation.h"
launcher_ui::launcher_ui() launcher_ui::launcher_ui() : m_scenery_scanner(m_vehicles_bank), m_scenerylist_panel(m_scenery_scanner)
: m_scenery_scanner(m_vehicles_bank), m_scenerylist_panel(m_scenery_scanner)
{ {
m_vehicles_bank.scan_textures(); m_vehicles_bank.scan_textures();
m_scenery_scanner.scan(); 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); 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_() void launcher_ui::render_()
{ {
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove; 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->size = glm::vec2(Global.window_size.x, Global.window_size.y - topbar_height);
panel->no_title_bar = true; panel->no_title_bar = true;
panel->is_open = true; panel->is_open = true;
m_current_panel = panel;
} }

View File

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

View File

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

View File

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