summaryrefslogtreecommitdiff
path: root/libs/canvas/text.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-04-04 00:32:52 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-04-04 00:32:52 -0400
commitaaea166135ace01709f7e0be64f40be80f4107ec (patch)
tree0e794ef7a723e4aaf909b841a6816e405b4ceca1 /libs/canvas/text.cc
parent1d8bac08c0c00d44e22c581768a275e1b21a99a7 (diff)
initial commit of hand merging, plus getting "ancient" waf script to work correctly
Diffstat (limited to 'libs/canvas/text.cc')
-rw-r--r--libs/canvas/text.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc
new file mode 100644
index 0000000000..541a5f7fc0
--- /dev/null
+++ b/libs/canvas/text.cc
@@ -0,0 +1,120 @@
+#include <gtkmm/label.h>
+#include "pbd/xml++.h"
+#include "canvas/text.h"
+#include "canvas/canvas.h"
+#include "canvas/utils.h"
+
+using namespace std;
+using namespace ArdourCanvas;
+
+Text::Text (Group* parent)
+ : Item (parent)
+ , _font_description (0)
+ , _color (0x000000ff)
+ , _alignment (Pango::ALIGN_LEFT)
+{
+
+}
+
+void
+Text::set (string const & text)
+{
+ begin_change ();
+
+ _text = text;
+
+ _bounding_box_dirty = true;
+ end_change ();
+}
+
+void
+Text::compute_bounding_box () const
+{
+ if (!_canvas || !_canvas->context ()) {
+ _bounding_box = boost::optional<Rect> ();
+ _bounding_box_dirty = false;
+ return;
+ }
+
+ Pango::Rectangle const r = layout (_canvas->context())->get_ink_extents ();
+
+ _bounding_box = Rect (
+ r.get_x() / Pango::SCALE,
+ r.get_y() / Pango::SCALE,
+ (r.get_x() + r.get_width()) / Pango::SCALE,
+ (r.get_y() + r.get_height()) / Pango::SCALE
+ );
+
+ _bounding_box_dirty = false;
+}
+
+Glib::RefPtr<Pango::Layout>
+Text::layout (Cairo::RefPtr<Cairo::Context> context) const
+{
+ Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
+ layout->set_text (_text);
+ if (_font_description) {
+ layout->set_font_description (*_font_description);
+ }
+ layout->set_alignment (_alignment);
+ return layout;
+}
+
+void
+Text::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
+{
+ set_source_rgba (context, _color);
+ layout (context)->show_in_cairo_context (context);
+}
+
+XMLNode *
+Text::get_state () const
+{
+ XMLNode* node = new XMLNode ("Text");
+#ifdef CANVAS_DEBUG
+ if (!name.empty ()) {
+ node->add_property ("name", name);
+ }
+#endif
+ return node;
+}
+
+void
+Text::set_state (XMLNode const * /*node*/)
+{
+ /* XXX */
+}
+
+void
+Text::set_alignment (Pango::Alignment alignment)
+{
+ begin_change ();
+
+ _alignment = alignment;
+
+ _bounding_box_dirty = true;
+ end_change ();
+}
+
+void
+Text::set_font_description (Pango::FontDescription* font_description)
+{
+ begin_change ();
+
+ _font_description = font_description;
+
+ _bounding_box_dirty = true;
+ end_change ();
+}
+
+void
+Text::set_color (Color color)
+{
+ begin_change ();
+
+ _color = color;
+
+ end_change ();
+}
+
+