X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fdiagnostics%2Fgraph.cpp;h=0b4348e0bba706d3d4e389dccbf8b6eb721357cc;hb=refs%2Ftags%2F2.0.0.2;hp=db6eff7904baeb56045888a90ab7004dcb4cbde9;hpb=01d8a61541548cf535791be39d233799eefc4187;p=casparcg diff --git a/common/diagnostics/graph.cpp b/common/diagnostics/graph.cpp index db6eff790..0b4348e0b 100644 --- a/common/diagnostics/graph.cpp +++ b/common/diagnostics/graph.cpp @@ -48,7 +48,7 @@ struct drawable : public sf::Drawable class context : public drawable { - sf::RenderWindow window_; + std::unique_ptr window_; std::list> drawables_; @@ -71,31 +71,51 @@ public: get_instance().do_register_drawable(drawable); }); } - + + static void show(bool value) + { + begin_invoke([=] + { + get_instance().do_show(value); + }); + } + private: context() : executor_(L"diagnostics") { - executor_.begin_invoke([this] - { - SetThreadPriority(GetCurrentThread(), BELOW_NORMAL_PRIORITY_CLASS); - window_.Create(sf::VideoMode(600, 1000), "CasparCG Diagnostics"); - window_.SetPosition(0, 0); - window_.SetActive(); - glEnable(GL_BLEND); - glEnable(GL_LINE_SMOOTH); - glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - tick(); - }); + } + + void do_show(bool value) + { + if(value) + { + if(!window_) + { + SetThreadPriority(GetCurrentThread(), BELOW_NORMAL_PRIORITY_CLASS); + window_.reset(new sf::RenderWindow(sf::VideoMode(600, 1000), "CasparCG Diagnostics")); + window_->SetPosition(0, 0); + window_->SetActive(); + glEnable(GL_BLEND); + glEnable(GL_LINE_SMOOTH); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + tick(); + } + } + else + window_.reset(); } void tick() { + if(!window_) + return; + sf::Event e; - while(window_.GetEvent(e)){} + while(window_->GetEvent(e)){} glClear(GL_COLOR_BUFFER_BIT); - window_.Draw(*this); - window_.Display(); + window_->Draw(*this); + window_->Display(); boost::this_thread::sleep(boost::posix_time::milliseconds(20)); executor_.begin_invoke([this]{tick();}); } @@ -112,8 +132,8 @@ private: auto& drawable = *it; if(!drawable.unique()) { - drawable->SetScale(static_cast(window_.GetWidth()), static_cast(target_dy*window_.GetHeight())); - float target_y = std::max(last_y, static_cast(n * window_.GetHeight())*target_dy); + drawable->SetScale(static_cast(window_->GetWidth()), static_cast(target_dy*window_->GetHeight())); + float target_y = std::max(last_y, static_cast(n * window_->GetHeight())*target_dy); drawable->SetPosition(0.0f, target_y); target.Draw(*drawable); ++it; @@ -125,7 +145,8 @@ private: void do_register_drawable(const std::shared_ptr& drawable) { - drawables_.push_back(drawable); + if(std::find(drawables_.begin(), drawables_.end(), drawable) == drawables_.end()) + drawables_.push_back(drawable); } static context& get_instance() @@ -168,12 +189,13 @@ class line : public drawable boost::optional guide_; boost::circular_buffer> line_data_; - std::vector tick_data_; - bool tick_tag_; + boost::circular_buffer tick_data_; + bool tick_tag_; color c_; public: line(size_t res = 600) : line_data_(res) + , tick_data_(50) , tick_tag_(false) , c_(1.0f, 1.0f, 1.0f) { @@ -260,22 +282,19 @@ struct graph::implementation : public drawable std::map lines_; std::string name_; std::string text_; - - int counter_; - + implementation(const std::string& name) : name_(name) - , text_(name) - , counter_(0){} + , text_(name_){} - void update(const std::string& name, double value) + void set_text(const std::string& value) { - lines_[name].update(value); + text_ = value; } - void update_text(const std::string& value) + void update(const std::string& name, double value) { - text_ = value; + lines_[name].update(value); } void set(const std::string& name, double value) @@ -351,84 +370,74 @@ private: implementation& operator=(implementation&); }; -graph::graph(const std::string& name) : impl_(env::properties().get("configuration.diagnostics.graphs", true) ? new implementation(name) : nullptr) +graph::graph() : impl_(new implementation("")) { - if(impl_) - context::register_drawable(impl_); + } -void graph::update_value(const std::string& name, double value) +void graph::set_text(const std::string& value) { - if(impl_) + auto p = impl_; + context::begin_invoke([=] { - auto p = impl_; - context::begin_invoke([=] - { - p->update(name, value); - }); - } + p->set_text(value); + }); } -void graph::update_text(const std::string& value) +void graph::set_text(const std::wstring& value) { - if(impl_) - { - auto p = impl_; - context::begin_invoke([=] - { - p->update_text(value); - }); - } + set_text(narrow(value)); } -void graph::set_value(const std::string& name, double value) +void graph::update_value(const std::string& name, double value) { - if(impl_) - { - auto p = impl_; - context::begin_invoke([=] - { - p->set(name, value); - }); - } + auto p = impl_; + context::begin_invoke([=] + { + p->update(name, value); + }); } -void graph::set_color(const std::string& name, color c) +void graph::set_value(const std::string& name, double value) { - if(impl_) - { - auto p = impl_; - context::begin_invoke([=] - { - p->set_color(name, c); - }); - } + auto p = impl_; + context::begin_invoke([=] + { + p->set(name, value); + }); +} +void graph::set_color(const std::string& name, color c) +{ + auto p = impl_; + context::begin_invoke([=] + { + p->set_color(name, c); + }); } void graph::add_tag(const std::string& name) -{ - if(impl_) - { - auto p = impl_; - context::begin_invoke([=] - { - p->tag(name); - }); - } +{ + auto p = impl_; + context::begin_invoke([=] + { + p->tag(name); + }); } void graph::add_guide(const std::string& name, double value) { - if(impl_) - { - auto p = impl_; - context::begin_invoke([=] - { - p->guide(name, value); - }); - } + auto p = impl_; + context::begin_invoke([=] + { + p->guide(name, value); + }); +} + +void register_graph(const safe_ptr& graph) +{ + context::register_drawable(graph->impl_); } -safe_ptr create_graph(const std::string& name) +void show_graphs(bool value) { - return safe_ptr(new graph(name)); + context::show(value); } //namespace v2