GWindow.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "GObject.h"
  3. #include <SharedGraphics/Rect.h>
  4. #include <SharedGraphics/GraphicsBitmap.h>
  5. #include <AK/AKString.h>
  6. #include <AK/WeakPtr.h>
  7. class GWidget;
  8. class GWindow final : public GObject {
  9. public:
  10. GWindow(GObject* parent = nullptr);
  11. virtual ~GWindow() override;
  12. static GWindow* from_window_id(int);
  13. void set_has_alpha_channel(bool);
  14. void set_opacity(float);
  15. int window_id() const { return m_window_id; }
  16. String title() const;
  17. void set_title(String&&);
  18. int x() const { return rect().x(); }
  19. int y() const { return rect().y(); }
  20. int width() const { return rect().width(); }
  21. int height() const { return rect().height(); }
  22. Rect rect() const;
  23. Size size() const { return rect().size(); }
  24. void set_rect(const Rect&);
  25. void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
  26. Point position() const { return rect().location(); }
  27. void move_to(int x, int y) { move_to({ x, y }); }
  28. void move_to(const Point& point) { set_rect({ point, size() }); }
  29. virtual void event(GEvent&) override;
  30. bool is_visible() const;
  31. bool is_active() const { return m_is_active; }
  32. void show();
  33. void hide();
  34. void close();
  35. GWidget* main_widget() { return m_main_widget; }
  36. const GWidget* main_widget() const { return m_main_widget; }
  37. void set_main_widget(GWidget*);
  38. GWidget* focused_widget() { return m_focused_widget; }
  39. const GWidget* focused_widget() const { return m_focused_widget; }
  40. void set_focused_widget(GWidget*);
  41. void update(const Rect& = Rect());
  42. void set_global_cursor_tracking_widget(GWidget*);
  43. GWidget* global_cursor_tracking_widget() { return m_global_cursor_tracking_widget.ptr(); }
  44. const GWidget* global_cursor_tracking_widget() const { return m_global_cursor_tracking_widget.ptr(); }
  45. bool should_exit_app_on_close() const { return m_should_exit_app_on_close; }
  46. void set_should_exit_app_on_close(bool b) { m_should_exit_app_on_close = b; }
  47. GWidget* hovered_widget() { return m_hovered_widget.ptr(); }
  48. const GWidget* hovered_widget() const { return m_hovered_widget.ptr(); }
  49. void set_hovered_widget(GWidget*);
  50. GraphicsBitmap* backing() { return m_backing.ptr(); }
  51. Size size_increment() const { return m_size_increment; }
  52. void set_size_increment(const Size& increment) { m_size_increment = increment; }
  53. Size base_size() const { return m_base_size; }
  54. void set_base_size(const Size& size) { m_base_size = size; }
  55. private:
  56. virtual const char* class_name() const override { return "GWindow"; }
  57. RetainPtr<GraphicsBitmap> m_backing;
  58. int m_window_id { 0 };
  59. float m_opacity_when_windowless { 1.0f };
  60. GWidget* m_main_widget { nullptr };
  61. GWidget* m_focused_widget { nullptr };
  62. WeakPtr<GWidget> m_global_cursor_tracking_widget;
  63. WeakPtr<GWidget> m_hovered_widget;
  64. Rect m_rect_when_windowless;
  65. String m_title_when_windowless;
  66. Vector<Rect> m_pending_paint_event_rects;
  67. Size m_size_increment;
  68. Size m_base_size;
  69. bool m_is_active { false };
  70. bool m_should_exit_app_on_close { false };
  71. bool m_has_alpha_channel { false };
  72. };