The UI codebase was suffering with complexity due to the need to manually convert between two different coordinate systems: - Top-down "screen coordinates" used by SDL for input and windowing. - Bottom-up "GL coordinates" used by low-level renderers. This was making layout calculations diffucult and is bug prone. With this commit, I'm introducing a 'UIRenderer' abstraction layer that wraps the low-level 'ShapeRenderer' and 'TextRenderer'. This is responsible for centralising all coordinate system conversations. All UI components has been refactored to use the 'UIRenderer' so the entire UI code opeates exclusively in a single, top-down screen coordinate system as one would expect.
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include "client_network.h"
|
|
#include "gfx/types.h"
|
|
#include "ui/text_buffer.h"
|
|
#include "ui/text_view.h"
|
|
#include "ui/i_window_content.h"
|
|
#include "ui/window_action.h"
|
|
|
|
class Terminal : public IWindowContent {
|
|
public:
|
|
Terminal(ClientNetwork* network);
|
|
~Terminal(void);
|
|
|
|
void update(void) override;
|
|
void handle_input(SDL_Event* event, int window_x, int window_y, int window_gl_y) override;
|
|
void render(const RenderContext& context, int x, int y_screen, int y_gl,
|
|
int width, int height) override;
|
|
void scroll(int amount, int content_height) override;
|
|
void add_history(const std::string& line);
|
|
void set_prompt(const std::string& prompt);
|
|
bool should_close(void) override;
|
|
WindowAction get_pending_action(void) override;
|
|
|
|
private:
|
|
void _on_ret_press(void);
|
|
|
|
bool _should_close;
|
|
std::vector<std::string> _history;
|
|
int _scroll_offset;
|
|
std::string _prompt;
|
|
ClientNetwork* _network;
|
|
TextBuffer _input_buffer;
|
|
WindowAction _pending_action;
|
|
std::unique_ptr<TextView> _input_view;
|
|
};
|