Canvas::Rect::contains() should treat its right/left coordinates as exclusive
[ardour.git] / libs / canvas / text.cc
index 4c2077a70b03dbb9a5daad8ed2ef1bfa316049b0..8744a7fd77d973b545a72abfc5d7bbdc740efefb 100644 (file)
@@ -27,6 +27,7 @@
 #include "canvas/text.h"
 #include "canvas/canvas.h"
 #include "canvas/utils.h"
+#include "canvas/colors.h"
 
 using namespace std;
 using namespace ArdourCanvas;
@@ -41,10 +42,11 @@ Text::Text (Canvas* c)
        , _need_redraw (false)
        , _clamped_width (COORD_MAX)
 {
+       _outline = false;
 }
 
-Text::Text (Group* g)
-       : Item (g)
+Text::Text (Item* parent)
+       : Item (parent)
        , _color (0x000000ff)
        , _font_description (0)
        , _alignment (Pango::ALIGN_LEFT)
@@ -53,6 +55,7 @@ Text::Text (Group* g)
        , _need_redraw (false)
        , _clamped_width (COORD_MAX)
 {
+       _outline = false;
 }
 
 Text::~Text ()
@@ -121,9 +124,17 @@ Text::_redraw (Glib::RefPtr<Pango::Layout> layout) const
 
        /* and draw, in the appropriate color of course */
 
-       set_source_rgba (img_context, _color);
-
-       layout->show_in_cairo_context (img_context);
+       if (_outline) {
+               set_source_rgba (img_context, _outline_color);
+               layout->update_from_cairo_context (img_context);
+               pango_cairo_layout_path (img_context->cobj(), layout->gobj());
+               img_context->stroke_preserve ();
+               set_source_rgba (img_context, _color);
+               img_context->fill ();
+       } else {
+               set_source_rgba (img_context, _color);
+               layout->show_in_cairo_context (img_context);
+       }
 
        /* text has now been rendered in _image and is ready for blit in
         * ::render 
@@ -160,7 +171,10 @@ Text::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
 void
 Text::clamp_width (double w)
 {
+        begin_change ();
        _clamped_width = w;
+        _bounding_box_dirty = true;
+        end_change ();
 }
 
 void
@@ -211,6 +225,9 @@ Text::set_color (Color color)
        begin_change ();
 
        _color = color;
+       if (_outline) {
+               set_outline_color (contrasting_text_color (_color));
+       }
        _need_redraw = true;
 
        end_change ();