72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "gfx/types.h"
|
|
#include "i_window_content.h"
|
|
|
|
enum class WindowState {
|
|
NORMAL,
|
|
MINIMIZED,
|
|
MAXIMIZED
|
|
};
|
|
|
|
enum class WindowButtonAction {
|
|
CLOSE,
|
|
MAXIMIZE,
|
|
MINIMIZE
|
|
};
|
|
|
|
struct TitleBarButton {
|
|
WindowButtonAction action;
|
|
Color color;
|
|
};
|
|
|
|
class UIWindow {
|
|
public:
|
|
UIWindow(const char* title, int x, int y, int width, int height);
|
|
~UIWindow(void);
|
|
|
|
void update(void);
|
|
void render(const RenderContext& context);
|
|
void handle_event(SDL_Event* event, int screen_width, int screen_height,
|
|
int taskbar_height);
|
|
void minimize(void);
|
|
void restore(void);
|
|
void close(void) { _should_close = true; }
|
|
bool is_minimized(void) const;
|
|
bool should_close(void) const;
|
|
void set_focused(bool focused);
|
|
bool is_point_inside(int x, int y);
|
|
void set_content(std::unique_ptr<IWindowContent> content);
|
|
IWindowContent* get_content(void);
|
|
bool is_mouse_over_resize_handle(int mouse_x, int mouse_y) const;
|
|
const std::string& get_title(void) const;
|
|
Rect get_rect(void) const;
|
|
void set_session_id(uint32_t id) { _session_id = id; }
|
|
uint32_t get_session_id(void) const { return _session_id; }
|
|
|
|
private:
|
|
friend class Taskbar; /* Allow taskbar to access private members. */
|
|
int _x, _y, _width, _height;
|
|
Rect _pre_maximize_rect;
|
|
std::string _title;
|
|
std::unique_ptr<IWindowContent> _content;
|
|
bool _is_focused; /* Managed by desktop. */
|
|
bool _is_hovered; /* Send scroll events even if not focused. */
|
|
bool _should_close;
|
|
|
|
std::vector<TitleBarButton> _title_bar_buttons;
|
|
WindowState _state;
|
|
|
|
bool _is_dragging;
|
|
int _drag_offset_x, _drag_offset_y;
|
|
|
|
bool _is_resizing;
|
|
int _resize_margin;
|
|
|
|
uint32_t _session_id;
|
|
};
|