struct graph::implementation : public drawable\r
{\r
std::map<std::string, diagnostics::line> lines_;\r
- const printer parent_printer_;\r
std::string name_;\r
+ std::string text_;\r
\r
int counter_;\r
\r
implementation(const std::string& name) \r
: name_(name)\r
+ , text_(name)\r
, counter_(0){}\r
-\r
- implementation(const printer& parent_printer) \r
- : parent_printer_(parent_printer)\r
- , name_(parent_printer_ ? narrow(parent_printer_()) : "")\r
- , counter_(0){}\r
-\r
+ \r
void update(const std::string& name, double value)\r
{\r
lines_[name].update(value);\r
}\r
\r
+ void update_text(const std::string& value)\r
+ {\r
+ text_ = value;\r
+ }\r
+\r
void set(const std::string& name, double value)\r
{\r
lines_[name].set(value);\r
private:\r
void render(sf::RenderTarget& target)\r
{\r
- if(counter_++ > 25) // Don't update name too often since print can be implemented with locks.\r
- {\r
- counter_ = 0;\r
- if(parent_printer_)\r
- name_ = narrow(parent_printer_());\r
- }\r
const size_t text_size = 15;\r
const size_t text_margin = 2;\r
const size_t text_offset = (text_size+text_margin*2)*2;\r
\r
- sf::String text(name_.c_str(), sf::Font::GetDefaultFont(), text_size);\r
+ sf::String text(text_.c_str(), sf::Font::GetDefaultFont(), text_size);\r
text.SetStyle(sf::String::Italic);\r
text.Move(text_margin, text_margin);\r
\r
context::register_drawable(impl_);\r
}\r
\r
-graph::graph(const printer& parent_printer) : impl_(env::properties().get("configuration.diagnostics.graphs", true) ? new implementation(parent_printer) : nullptr)\r
+void graph::update_value(const std::string& name, double value)\r
{\r
if(impl_)\r
- context::register_drawable(impl_);\r
+ { \r
+ auto p = impl_;\r
+ context::begin_invoke([=]\r
+ { \r
+ p->update(name, value);\r
+ });\r
+ }\r
}\r
\r
-void graph::update_value(const std::string& name, double value)\r
+void graph::update_text(const std::string& value)\r
{\r
if(impl_)\r
- { \r
+ { \r
auto p = impl_;\r
context::begin_invoke([=]\r
{ \r
- p->update(name, value);\r
+ p->update_text(value);\r
});\r
}\r
}\r
+\r
void graph::set_value(const std::string& name, double value)\r
{\r
if(impl_)\r
{\r
return safe_ptr<graph>(new graph(name));\r
}\r
-safe_ptr<graph> create_graph(const printer& parent_printer)\r
-{\r
- return safe_ptr<graph>(new graph(parent_printer));\r
-}\r
-\r
\r
//namespace v2\r
//{ \r