18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 00:22:42 +01:00
Files
maszyna/application/uilayer.h
T
maj00r fef7eaac11 feat(editor): one card for the tools, one layout of the fields, windows of their own, one name for each thing
The consistency pass of the editor's interface after its first steps (P2 of the plan of the editor's interface):

- One card for the tool in use in every field of work. The card of the track tools (its icon, name, family and key, what
  the tool is for, the mouse and the keys drawing its gestures, the link to all the shortcuts) is a component of its own,
  render_tool_card, fed by the tracks as before and now by the surroundings, the roads and the terrain: their tools, kept in
  one table each with their icons, keys, tooltips and gestures for the toolbar and the card, had a plain heading and a line
  of keys or a few rows of gestures there. The tool options of the surroundings are headed by the field of work as the
  others are. The card is folded to its title row unless the user opened it, for all the tools: what the tool is for shows
  over the title, a click opens the gestures, which are in the strip under the view of the tracks as well. Kept with the
  settings of the editor under the key tool_card_folded, so the open card the tracks had by default before stays behind.
- One layout of the fields: the name on the left, the field on the right (begin_fields and field_row, as in the inspector of
  the tracks) in the inspector of the surroundings (the name, the position, the rotation, the scale), Weather and time,
  Change history, the settings of the orthophoto and the settings of the editor. The square buttons of the download area go
  on to the next line at the edge, the last one was cut off.
- Windows of their own, which don't hide the inspector: Editor settings, Weather and time and the orthophoto settings float
  over the view, opened in its top left corner below the rows of the tools and kept between them and the status line, as
  the window of a lesson is. They were tabs over the inspector, and the orthophoto settings unfolded inside the layers; Map >
  Orthophoto settings..., the button of the terrain tools and the button in the layers open the window now.
- One list of the objects of the scenery: Windows > Scene Hierarchy, a plain list of the same nodes, is gone; Windows >
  Scene opens the Scene tab (by layer and group, with the filter) and brings it forward when it lies behind the layers.
- One name for each thing, in the menus, the toolbar, the panels, the tutorial and F1: the orthophoto ("Ortofotomapa
  (zdjęcia lotnicze z geoportal.gov.pl)" where it's introduced, "ortofotomapa" in the rest, for "zdjęcia lotnicze",
  "ortofoto" and "zdjęcie"), the terrain model ("Teren z map (NMT)" for "Prawdziwy teren z map", "model terenu", "prawdziwy
  teren", "Teren z NMT"), the plan tool ("Plan", the lesson "Correcting a curve" and the section of F1 "Plan of a curve"
  before), the area fill (the terrain's "Fill" is "Area fill" as in the surroundings, with the icon of it, Water without).
  The texts of the laying, whose panel is to be redone, are left as they are.
- The node bank: a model clicked with the select tool of the surroundings arms the insert tool with it (the click did
  nothing before), the random model of a set is left off then. A model inserted where there's no ground under the cursor
  stands at the height 0 where the cursor points, or in front of the camera when it points above the horizon, and the
  status says where; it stood at the point the renderer last had under the cursor, out of sight. The search field of the
  bank has no name beside it, which was cut to its first letter.
- The settings in one place: Editor settings holds the movement and the speed of the camera (as View > Camera speed), the
  gizmo and the colours, the terrain made of the terrain model by itself (as in the layers and the download area) and the
  maximum placement distance (as in Change history).
- F1 and the menus: Esc closes the window of the shortcuts, before anything else; the window stays in the work area as the
  window of a lesson; the menus are opaque, the windows under them showed through.
- What the first steps left: with an empty scenery the panel in the middle of the view gives way to the inspector, which
  says the same with the button of the lay tool and the first steps; it's drawn only while the inspector isn't seen. A
  switch whose speed limits its diverging track alone shows that speed under its empty speed field ("The diverging track
  40 km/h, the main one no limit"), read only; the field alone said no limit.
- Self-tests: the command bankpick, the expectations tool, window and selected, the cases c_1_bank_card_arms_insert and
  c_2_esc_closes_shortcuts.

lang/editor_pl.po: the Polish of the new texts (the cards of the tools, the windows, the fields, the notices), the entries of
the texts renamed given their new English, those no longer used taken out, and the names unified in the Polish of the
orthophoto and of the terrain model.
2026-11-23 13:35:56 +01:00

192 lines
6.8 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string>
#include "model/Texture.h"
#include "widgets/popup.h"
// GuiLayer -- basic user interface class. draws requested information on top of openGL screen
class ui_panel {
public:
// constructor
ui_panel( std::string Identifier, bool Isopen );
virtual ~ui_panel() = default;
// methods
virtual void update() {}
virtual void on_window_resize(int w, int h) {}
virtual void render();
virtual void render_contents();
// temporary access
// types
struct text_line {
std::string data;
glm::vec4 color;
text_line( std::string const &Data, glm::vec4 const &Color) : data(Data), color(Color) {}
};
// members
std::string title;
bool is_open;
glm::ivec2 pos { -1, -1 };
glm::ivec2 size { -1, -1 };
glm::ivec2 size_min { -1, -1 };
glm::ivec2 size_max { -1, -1 };
std::deque<text_line> text_lines;
int window_flags = -1;
bool no_title_bar = false;
const std::string& name() { return m_name; }
void register_popup(std::unique_ptr<ui::popup> &&popup);
protected:
// members
std::string m_name;
std::list<std::unique_ptr<ui::popup>> popups;
};
class ui_expandable_panel : public ui_panel {
public:
using ui_panel::ui_panel;
bool is_expanded { false };
void render_contents() override;
};
class ui_log_panel : public ui_panel {
using ui_panel::ui_panel;
void render_contents() override;
};
struct ImFont;
class ui_layer {
public:
// constructors
ui_layer();
// destructor
virtual ~ui_layer();
// methods
static bool init( GLFWwindow *Window );
static void imgui_style();
// colours of the user interface: 0 the green ones shared with the starter, 1 the amber ones of the editor
static void imgui_colors(int const Palette);
// assign texturing hardware unit
static void set_unit( GLint const Textureunit ) { m_textureunit = GL_TEXTURE0 + Textureunit; }
static void shutdown();
virtual void showDebugUI() {};
// potentially processes provided input key. returns: true if the input was processed, false otherwise
virtual bool on_key( int Key, int Action );
// potentially processes provided mouse movement. returns: true if the input was processed, false otherwise
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
void render();
static void render_internal();
// begins new UI frame
// (this is separate from render() to allow for debug GUI outside of proper UI framework)
void begin_ui_frame();
static void begin_ui_frame_internal();
//
static void set_cursor( int Mode );
// the cursor drawn into the picture by the interface instead of the system: seen in a stream or a recording of the window
static void draw_cursor( bool Draw );
static bool drawn_cursor() { return m_drawcursor; }
// loading
void set_progress(std::string const &Text);
void set_progress(float progress, float subtaskprogress);
// sets the ui background texture, if any
void set_background( std::string const &Filename = "" );
void set_tooltip( std::string const &Tooltip ) { m_tooltip = Tooltip; }
void clear_panels();
void add_external_panel( ui_panel *Panel ) { m_panels.emplace_back( Panel ); }
void add_owned_panel( ui_panel *Panel );
// callback functions for imgui input
// returns true if input is consumed
static bool key_callback(int key, int scancode, int action, int mods);
static bool char_callback(unsigned int c);
static bool scroll_callback(double xoffset, double yoffset);
static bool mouse_button_callback(int button, int action, int mods);
// state updates only, nothing to consume
static void cursor_pos_callback(double x, double y);
static void cursor_enter_callback(int entered);
static void focus_callback(int focused);
// key presses in windows of the ui outside of the main window, passed on to the simulator like those of the main window
static void viewport_key_callback(GLFWwindow *Window, int key, int scancode, int action, int mods);
static ImFont *font_default;
static ImFont *font_mono;
static ImFont *font_loading;
// bigger and bold, for headings like the fields of work of the editor; nullptr if the font isn't there
static ImFont *font_bold;
protected:
// members
static GLFWwindow *m_window;
static GLFWwindow *m_keywindow; // window of the key event being handled
static ImGuiIO *m_imguiio;
static bool m_cursorvisible;
static inline bool m_drawcursor{ false };
virtual void render_menu_contents();
// items of the windows menu which belong to the ui of a mode, after the common ones
virtual void render_windows_menu() {}
// items of the tools menu which belong to the ui of a mode, after the common ones
virtual void render_tools_menu() {}
// colours this ui is drawn in, see imgui_colors()
virtual int palette() const
{
return 0;
}
static int m_palette; // colours set at the moment
ui_log_panel m_logpanel { "Log", true };
bool m_suppress_menu = false; // if `true`, the menu at the top of the window will not be present
bool m_menu_always = false; // if `true`, the menu is shown all the time, not only when the mouse is at the top of the window
int m_dockspaceframe{-1}; // frame the dockspace was last submitted in
// progress bar config
float m_progress { 0.0f }; // percentage of filled progres bar, to indicate lengthy operations.
float m_subtaskprogress{ 0.0f }; // percentage of filled progres bar, to indicate lengthy operations.
std::string m_progresstext; // label placed over the progress bar
private:
// methods
// render() subclass details
virtual void render_() {}
// submitted right after the start of the frame, before any window that may be docked in it
virtual void render_dockspace() {}
// draws background quad with specified earlier texture
void render_background();
void render_tooltip();
void render_panels();
void render_menu();
void render_quit_widget();
// draws a quad between coordinates x,y and z,w with uv-coordinates spanning 0-1
void quad( glm::vec4 const &Coordinates, glm::vec4 const &Color );
// members
static GLint m_textureunit;
texture_handle m_background { null_handle }; // path to texture used as the background. size depends on mAspect.
std::vector<ui_panel *> m_panels;
std::vector<std::unique_ptr<ui_panel>> m_ownedpanels;
std::string m_tooltip;
bool m_quit_active = false;
bool m_imgui_demo = false;
bool m_editor_change_history = false;
};