From 4a6716e39c0d1ab18cd9dc3e371e1c11c55d4303 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 19 May 2025 14:55:55 -0600 Subject: [PATCH] add option for a minor/micro tick font description to ArdourCanvas::Ruler --- libs/canvas/canvas/ruler.h | 6 +++--- libs/canvas/ruler.cc | 44 ++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/libs/canvas/canvas/ruler.h b/libs/canvas/canvas/ruler.h index c17084db85..12ee986b3e 100644 --- a/libs/canvas/canvas/ruler.h +++ b/libs/canvas/canvas/ruler.h @@ -61,12 +61,11 @@ public: Ruler (Item*, const Metric* m); Ruler (Item*, const Metric* m, Rect const&); - virtual ~Ruler () { - delete _font_description; - } + virtual ~Ruler (); void set_range (int64_t lower, int64_t upper); void set_font_description (Pango::FontDescription); + void set_minor_font_description (Pango::FontDescription); void set_metric (const Metric *); void render (Rect const & area, Cairo::RefPtr) const; @@ -85,6 +84,7 @@ private: Gtkmm2ext::Color _divider_color_bottom; Pango::FontDescription* _font_description; + Pango::FontDescription* _minor_font_description; mutable std::vector marks; mutable bool _need_marks; }; diff --git a/libs/canvas/ruler.cc b/libs/canvas/ruler.cc index e426e8b61b..92b76f35f8 100644 --- a/libs/canvas/ruler.cc +++ b/libs/canvas/ruler.cc @@ -37,7 +37,8 @@ Ruler::Ruler (Canvas* c, const Metric* m) , _lower (0) , _upper (0) , _divide_height (-1.0) - , _font_description (0) + , _font_description (nullptr) + , _minor_font_description (nullptr) , _need_marks (true) { } @@ -48,7 +49,8 @@ Ruler::Ruler (Canvas* c, const Metric* m, Rect const& r) , _lower (0) , _upper (0) , _divide_height (-1.0) - , _font_description (0) + , _font_description (nullptr) + , _minor_font_description (nullptr) , _need_marks (true) { } @@ -59,7 +61,8 @@ Ruler::Ruler (Item* parent, const Metric* m) , _lower (0) , _upper (0) , _divide_height (-1.0) - , _font_description (0) + , _font_description (nullptr) + , _minor_font_description (nullptr) , _need_marks (true) { } @@ -70,11 +73,18 @@ Ruler::Ruler (Item* parent, const Metric* m, Rect const& r) , _lower (0) , _upper (0) , _divide_height (-1.0) - , _font_description (0) + , _font_description (nullptr) + , _minor_font_description (nullptr) , _need_marks (true) { } +Ruler::~Ruler() +{ + delete _font_description; + delete _minor_font_description; +} + void Ruler::set_range (int64_t l, int64_t u) { @@ -94,6 +104,15 @@ Ruler::set_font_description (Pango::FontDescription fd) end_visual_change (); } +void +Ruler::set_minor_font_description (Pango::FontDescription fd) +{ + begin_visual_change (); + delete _minor_font_description; + _minor_font_description = new Pango::FontDescription (fd); + end_visual_change (); +} + void Ruler::render (Rect const & area, Cairo::RefPtr cr) const { @@ -148,12 +167,25 @@ Ruler::render (Rect const & area, Cairo::RefPtr cr) const Glib::RefPtr layout = Pango::Layout::create (cr); - Pango::FontDescription* last_font_description = 0; + Pango::FontDescription* last_font_description = nullptr; Coord prev = -1; for (vector::const_iterator m = marks.begin(); m != marks.end(); ++m) { Duple pos; - Pango::FontDescription* fd = _font_description; + Pango::FontDescription* fd; + + switch (m->style) { + case Mark::Major: + fd = _font_description; + break; + default: + if (_minor_font_description) { + fd = _minor_font_description; + } else { + fd = _font_description; + } + break; + } pos.x = round (m->position/_metric->units_per_pixel) + self.x0; pos.y = self.y1; /* bottom edge */