From 5ddc5963ce06ecea574e90ca503a3ee598522d8f Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Fri, 4 Dec 2009 13:08:01 +0100 Subject: support multiline data output from scripts run under the grapher This is accompanied by support for multiline output in hover text. * grapher/StapParser.cxx (ioCallback): Read data 'til the end of line character, not just '\n'. Be careful to use I/O functions that don't treat '\n' specially. * grapher/StapParser.hxx: ditto * grapher/CairoWidget.cxx (CairoTextBox::draw): Perform line breaks for hover text. * testsuite/systemtap.examples/general/grapher.stp: Do multiline output of keyboard events. Also, fix longstanding breaking in the pty probe. --- grapher/CairoWidget.cxx | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'grapher/CairoWidget.cxx') diff --git a/grapher/CairoWidget.cxx b/grapher/CairoWidget.cxx index f627dfaa..db0e464e 100644 --- a/grapher/CairoWidget.cxx +++ b/grapher/CairoWidget.cxx @@ -1,9 +1,15 @@ #include "CairoWidget.hxx" #include +#include + +#include namespace systemtap { + using namespace std; + using namespace boost; + void CairoPlayButton::draw(Cairo::RefPtr cr) { if (!_visible) @@ -44,10 +50,22 @@ namespace systemtap { if (!_visible) return; + vector lines; + split(lines, contents, is_any_of("\n")); + vector extents; + double width = 0.0, height = 0.0; + for (vector::iterator itr = lines.begin(), end = lines.end(); + itr != end; + ++itr) + { + Cairo::TextExtents extent; + cr->get_text_extents(*itr, extent); + extents.push_back(extent); + width = max(width, extent.width); + height += extent.height; + } + cr->save(); - Cairo::TextExtents extents; - cr->get_text_extents(contents, extents); - double width = extents.width, height = extents.height; cr->move_to(_x0 - 2, _y0 - 2); cr->line_to(_x0 + width + 2, _y0 - 2); cr->line_to(_x0 + width + 2, _y0 + height + 2); @@ -56,8 +74,16 @@ namespace systemtap cr->set_source_rgba(1.0, 1.0, 1.0, .8); cr->fill(); cr->set_source_rgba(0.0, 0.0, 0.0, 1.0); - cr->move_to(_x0, _y0 + height); - cr->show_text(contents); + vector::iterator titr = extents.begin(); + double texty = _y0; + for (vector::iterator itr = lines.begin(), end = lines.end(); + itr != end; + ++itr,++titr) + { + cr->move_to(_x0, texty + titr->height); + cr->show_text(*itr); + texty += titr->height; + } cr->restore(); } } -- cgit From 52cf0905d93c33f7d6f768478572ea08df4c8af0 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Fri, 4 Dec 2009 14:11:25 +0100 Subject: tweak multiline hover text to have proper interline spacing * grapher/CairoWidget.cxx (CairoTextBox::draw): Use font information to caculate legible spacing. Also change the font to something more readable. * testsuite/systemtap.examples/general/grapher.stp: Put carriage returns in the right spots. --- grapher/CairoWidget.cxx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'grapher/CairoWidget.cxx') diff --git a/grapher/CairoWidget.cxx b/grapher/CairoWidget.cxx index db0e464e..eefe3d28 100644 --- a/grapher/CairoWidget.cxx +++ b/grapher/CairoWidget.cxx @@ -50,6 +50,15 @@ namespace systemtap { if (!_visible) return; + cr->save(); + cr->select_font_face("Sans", Cairo::FONT_SLANT_NORMAL, + Cairo::FONT_WEIGHT_BOLD); + cr->set_font_size(10.0); + Cairo::FontExtents fontExtent; + cr->get_font_extents(fontExtent); + // Some naughty fonts have a height less than ascent + descent + double fontHeight = max(fontExtent.ascent + fontExtent.descent + 1.0, + fontExtent.height); vector lines; split(lines, contents, is_any_of("\n")); vector extents; @@ -62,10 +71,8 @@ namespace systemtap cr->get_text_extents(*itr, extent); extents.push_back(extent); width = max(width, extent.width); - height += extent.height; + height += fontHeight; } - - cr->save(); cr->move_to(_x0 - 2, _y0 - 2); cr->line_to(_x0 + width + 2, _y0 - 2); cr->line_to(_x0 + width + 2, _y0 + height + 2); @@ -74,15 +81,14 @@ namespace systemtap cr->set_source_rgba(1.0, 1.0, 1.0, .8); cr->fill(); cr->set_source_rgba(0.0, 0.0, 0.0, 1.0); - vector::iterator titr = extents.begin(); double texty = _y0; for (vector::iterator itr = lines.begin(), end = lines.end(); itr != end; - ++itr,++titr) + ++itr) { - cr->move_to(_x0, texty + titr->height); + cr->move_to(_x0, texty + fontExtent.ascent); cr->show_text(*itr); - texty += titr->height; + texty += fontHeight; } cr->restore(); } -- cgit From f669d095ba7fe5a623b31abc05b4f6664059803b Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 7 Dec 2009 19:19:45 +0100 Subject: add copyright and license to grapher files --- grapher/CairoWidget.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'grapher/CairoWidget.cxx') diff --git a/grapher/CairoWidget.cxx b/grapher/CairoWidget.cxx index eefe3d28..26c2d029 100644 --- a/grapher/CairoWidget.cxx +++ b/grapher/CairoWidget.cxx @@ -1,3 +1,11 @@ +// systemtap grapher +// Copyright (C) 2009 Red Hat Inc. +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. + #include "CairoWidget.hxx" #include -- cgit