| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #pragma once
- #include "lumacs/editor_core.hpp"
- #include "lumacs/window.hpp"
- #include "lumacs/theme.hpp"
- #include <gtkmm.h>
- #include <pangomm.h>
- #include <memory>
- #include <optional>
- namespace lumacs {
- // Forward declarations
- class EditorCore;
- class Window;
- // Constants for padding
- static constexpr double PADDING_LEFT = 8.0;
- static constexpr double PADDING_TOP = 8.0;
- static constexpr double PADDING_RIGHT = 8.0;
- static constexpr double PADDING_BOTTOM = 8.0;
- class GtkRenderer {
- public:
- GtkRenderer(EditorCore& core, Gtk::Widget& context_widget);
- void initialize_font_metrics();
- void apply_face_attributes(Pango::AttrList& attr_list, const FaceAttributes& face, int start_index, int end_index);
- std::optional<Position> resolve_screen_pos(std::shared_ptr<Window> window, double x, double y);
- void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
- std::shared_ptr<Window> active_window_cache, bool cursor_visible_state);
- void draw_window(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
- std::shared_ptr<Window> window, Gtk::Widget* widget,
- std::shared_ptr<Window> active_window_cache, bool cursor_visible_state);
- void render_modeline_for_window(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
- std::shared_ptr<Window> window,
- std::shared_ptr<Window> active_window_cache);
-
- void render_minibuffer(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
- /// @brief Gets the screen coordinates and dimensions of the minibuffer area.
- /// @param x Output parameter for the X coordinate.
- /// @param y Output parameter for the Y coordinate.
- /// @param width Output parameter for the width.
- /// @param height Output parameter for the height.
- /// @return True if the coordinates could be determined, false otherwise.
- bool get_minibuffer_coords(int& x, int& y, int& width, int& height) const;
- /// @brief Clears the internal render cache, forcing a full redraw.
- /// Useful when the theme changes.
- void invalidate_cache();
- /// @brief Set the font size in points.
- void set_font_size(int size);
- /// @brief Get the current font size in points.
- [[nodiscard]] int font_size() const { return font_size_; }
- /// @brief Get the current line height in pixels.
- [[nodiscard]] double line_height() const { return line_height_; }
- /// @brief Get the current scale factor (for HiDPI).
- [[nodiscard]] int scale_factor() const { return scale_factor_; }
- private:
- /// @brief Convert character position to byte index for UTF-8 string.
- static size_t char_to_byte_index(const std::string& str, size_t char_pos);
- struct LineCacheEntry {
- std::string text_content;
- std::vector<StyledRange> styles; // Check if styles changed
- Cairo::RefPtr<Cairo::ImageSurface> surface;
- int width = 0;
- int height = 0;
- int scale = 1; // Scale factor when surface was created
- };
- // Map Window ID (or ptr) -> (Line Index -> Cache Entry)
- std::unordered_map<Window*, std::unordered_map<size_t, LineCacheEntry>> render_cache_;
- EditorCore& core_;
- Gtk::Widget& context_widget_;
- Pango::FontDescription font_desc_;
- bool font_initialized_ = false;
- int font_size_ = 12;
- int scale_factor_ = 1; // HiDPI scale factor
- double char_width_ = 0;
- double line_height_ = 0;
- double ascent_ = 0;
- double descent_ = 0;
- };
- } // namespace lumacs
|