gtk_renderer.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. private:
  34. EditorCore& core_;
  35. Gtk::DrawingArea& main_drawing_area_;
  36. Pango::FontDescription font_desc_;
  37. bool font_initialized_ = false;
  38. double char_width_ = 0;
  39. double line_height_ = 0;
  40. double ascent_ = 0;
  41. };
  42. } // namespace lumacs