[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 01/13: Implement graph max value text overlay on CurveView
noreply at xfce.org
noreply at xfce.org
Wed Aug 12 18:39:05 CEST 2015
This is an automated email from the git hooks/post-receive script.
omegaphil pushed a commit to branch master
in repository panel-plugins/xfce4-hardware-monitor-plugin.
commit 0cb55cc53399371606f58a3fcee7b0c79eb54123
Author: OmegaPhil <OmegaPhil at startmail.com>
Date: Tue Jul 28 19:11:57 2015 +0100
Implement graph max value text overlay on CurveView
---
src/curve-view.cpp | 43 +++++++++++++++++++++++++++++++++++++++++--
src/curve-view.hpp | 5 ++++-
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/src/curve-view.cpp b/src/curve-view.cpp
index 90d4670..ffab1f5 100644
--- a/src/curve-view.cpp
+++ b/src/curve-view.cpp
@@ -27,6 +27,7 @@
#include "curve-view.hpp"
#include "applet.hpp"
#include "monitor.hpp"
+#include "ucompose.hpp"
#include "value-history.hpp"
@@ -134,6 +135,7 @@ double Curve::get_max_value()
return value_history.get_max_value();
}
+
//
// class CurveView
//
@@ -141,7 +143,7 @@ double Curve::get_max_value()
int const CurveView::pixels_per_sample = 2;
CurveView::CurveView()
- : CanvasView(true)
+ : CanvasView(true), text_overlay(NULL)
{
}
@@ -149,6 +151,7 @@ CurveView::~CurveView()
{
for (curve_iterator i = curves.begin(), end = curves.end(); i != end; ++i)
delete *i;
+ delete text_overlay;
}
void CurveView::do_update()
@@ -242,13 +245,49 @@ void CurveView::do_detach(Monitor *monitor)
void CurveView::do_draw_loop()
{
double max = 0;
+ Glib::ustring max_formatted;
// Obtain maximum value of all curves in the view
for (curve_iterator i = curves.begin(), end = curves.end(); i != end; ++i)
if ((*i)->get_max_value() > max)
max = (*i)->get_max_value();
- // Draw the curves with the unified max value
+ /* Draw the curves with the unified max value, use first monitor to obtain
+ * the text formatted value (with units) - this mainly makes sense if all
+ * curves belong to the same monitor type */
for (curve_iterator i = curves.begin(), end = curves.end(); i != end; ++i)
+ {
+ if (max_formatted.empty())
+ max_formatted = (*i)->monitor->format_value(max);
(*i)->draw(*canvas, width(), height(), max);
+ }
+
+ // Determination of text to overlay
+ Glib::ustring overlay_text = _("Max: ") + max_formatted;
+
+ /* Checking if overlay is already initialised
+ * Possibility that text is not shown at start up - not failing consistently
+ * now though, when it does, even resetting via switching views is not enough */
+ if (!text_overlay)
+ {
+ /* Font and colour are required to output text, anchor is used to define
+ * what point on the item (canvas thing) to take as the 'centre' to then
+ * place on the canvas - e.g. ANCHOR_NW means the top-left corner is the
+ * 'centre' and the item will be placed exactly as you would expect it to.
+ * The default is GTK_ANCHOR_CENTER, hence text gets clipped in half top
+ * and side */
+ text_overlay = new Gnome::Canvas::Text(*canvas->root());
+ text_overlay->property_anchor() = Gtk::ANCHOR_NW;
+ text_overlay->property_text() = overlay_text;
+ text_overlay->property_font() = "Sans 8";
+ text_overlay->property_fill_color() = "black";
+
+ // Positioning text at the bottom of the canvas
+ text_overlay->property_y() = applet->get_height() -
+ text_overlay->property_text_height();
+ }
+
+ // It is - updating if it has changed
+ else if (text_overlay->property_text() != overlay_text)
+ text_overlay->property_text() = overlay_text;
}
diff --git a/src/curve-view.hpp b/src/curve-view.hpp
index 5c50aa7..2613d86 100644
--- a/src/curve-view.hpp
+++ b/src/curve-view.hpp
@@ -27,6 +27,7 @@
#include <memory>
#include <libgnomecanvasmm/canvas.h>
+#include <libgnomecanvasmm/text.h>
#include <glibmm/ustring.h>
#include "canvas-view.hpp"
@@ -48,10 +49,12 @@ private:
virtual void do_detach(Monitor *monitor);
virtual void do_draw_loop();
- // must be destroyed before the canvas
+ // Must be destroyed before the canvas
typedef std::list<Curve *> curve_sequence;
typedef curve_sequence::iterator curve_iterator;
curve_sequence curves;
+
+ Gnome::Canvas::Text *text_overlay; // Text 'overlay' for the CurveView
};
#endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list