gtk_renderer.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include "lumacs/editor_core.hpp"
  3. #include "lumacs/window.hpp"
  4. #include "lumacs/theme.hpp"
  5. #include <gtkmm.h>
  6. #include <pangomm.h>
  7. #include <memory>
  8. #include <optional>
  9. namespace lumacs {
  10. // Forward declarations
  11. class EditorCore;
  12. class Window;
  13. // Constants for padding
  14. static constexpr double PADDING_LEFT = 8.0;
  15. static constexpr double PADDING_TOP = 8.0;
  16. static constexpr double PADDING_RIGHT = 8.0;
  17. static constexpr double PADDING_BOTTOM = 8.0;
  18. class GtkRenderer {
  19. public:
  20. GtkRenderer(EditorCore& core, Gtk::DrawingArea& main_drawing_area);
  21. void initialize_font_metrics();
  22. void apply_face_attributes(Pango::AttrList& attr_list, const FaceAttributes& face, int start_index, int end_index);
  23. std::optional<Position> resolve_screen_pos(std::shared_ptr<Window> window, double x, double y);
  24. void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
  25. std::shared_ptr<Window> active_window_cache, bool cursor_visible_state);
  26. void draw_window(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
  27. std::shared_ptr<Window> window, Gtk::DrawingArea* widget,
  28. std::shared_ptr<Window> active_window_cache, bool cursor_visible_state);
  29. void render_modeline_for_window(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
  30. std::shared_ptr<Window> window,
  31. std::shared_ptr<Window> active_window_cache);
  32. void render_minibuffer(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
  33. /// @brief Gets the screen coordinates and dimensions of the minibuffer area.
  34. /// @param x Output parameter for the X coordinate.
  35. /// @param y Output parameter for the Y coordinate.
  36. /// @param width Output parameter for the width.
  37. /// @param height Output parameter for the height.
  38. /// @return True if the coordinates could be determined, false otherwise.
  39. bool get_minibuffer_coords(int& x, int& y, int& width, int& height) const;
  40. private:
  41. EditorCore& core_;
  42. Gtk::DrawingArea& main_drawing_area_;
  43. Pango::FontDescription font_desc_;
  44. bool font_initialized_ = false;
  45. double char_width_ = 0;
  46. double line_height_ = 0;
  47. double ascent_ = 0;
  48. };
  49. } // namespace lumacs