X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fdiagnostics%2Fgraph.cpp;h=db6eff7904baeb56045888a90ab7004dcb4cbde9;hb=11e9ee9363a33cee4f3433c83b1f5fd76b95b57e;hp=5378f515642683b7f30d24d2ef7dcb515cbc18f7;hpb=77c5e19de35d9d3d9b470113e9f194ebe83b0f0b;p=casparcg diff --git a/common/diagnostics/graph.cpp b/common/diagnostics/graph.cpp index 5378f5156..db6eff790 100644 --- a/common/diagnostics/graph.cpp +++ b/common/diagnostics/graph.cpp @@ -258,25 +258,26 @@ public: struct graph::implementation : public drawable { std::map lines_; - const printer parent_printer_; std::string name_; + std::string text_; int counter_; implementation(const std::string& name) : name_(name) + , text_(name) , counter_(0){} - - implementation(const printer& parent_printer) - : parent_printer_(parent_printer) - , name_(parent_printer_ ? narrow(parent_printer_()) : "") - , counter_(0){} - + void update(const std::string& name, double value) { lines_[name].update(value); } + void update_text(const std::string& value) + { + text_ = value; + } + void set(const std::string& name, double value) { lines_[name].set(value); @@ -300,17 +301,11 @@ struct graph::implementation : public drawable private: void render(sf::RenderTarget& target) { - if(counter_++ > 25) // Don't update name too often since print can be implemented with locks. - { - counter_ = 0; - if(parent_printer_) - name_ = narrow(parent_printer_()); - } const size_t text_size = 15; const size_t text_margin = 2; const size_t text_offset = (text_size+text_margin*2)*2; - sf::String text(name_.c_str(), sf::Font::GetDefaultFont(), text_size); + sf::String text(text_.c_str(), sf::Font::GetDefaultFont(), text_size); text.SetStyle(sf::String::Italic); text.Move(text_margin, text_margin); @@ -362,23 +357,30 @@ graph::graph(const std::string& name) : impl_(env::properties().get("configurati context::register_drawable(impl_); } -graph::graph(const printer& parent_printer) : impl_(env::properties().get("configuration.diagnostics.graphs", true) ? new implementation(parent_printer) : nullptr) +void graph::update_value(const std::string& name, double value) { if(impl_) - context::register_drawable(impl_); + { + auto p = impl_; + context::begin_invoke([=] + { + p->update(name, value); + }); + } } -void graph::update_value(const std::string& name, double value) +void graph::update_text(const std::string& value) { if(impl_) - { + { auto p = impl_; context::begin_invoke([=] { - p->update(name, value); + p->update_text(value); }); } } + void graph::set_value(const std::string& name, double value) { if(impl_) @@ -428,11 +430,6 @@ safe_ptr create_graph(const std::string& name) { return safe_ptr(new graph(name)); } -safe_ptr create_graph(const printer& parent_printer) -{ - return safe_ptr(new graph(parent_printer)); -} - //namespace v2 //{