]> git.sesse.net Git - casparcg/blobdiff - core/diagnostics/osd_graph.cpp
[framerate_producer] Fixed bug where second frame instead of first frame was shown...
[casparcg] / core / diagnostics / osd_graph.cpp
index 7847f76bfeb529ac1452b0df61a159ee19ac3c9f..fefc74403b3a2c20e8d469e8080e99a10656dbab 100644 (file)
@@ -31,7 +31,8 @@
 #include <common/lock.h>
 #include <common/env.h>
 #include <common/prec_timer.h>
-#include <common/os/scheduling.h>
+#include <common/os/threading.h>
+#include <common/timer.h>
 
 #include <SFML/Graphics.hpp>
 
@@ -60,10 +61,10 @@ sf::Color get_sfml_color(int color)
        auto c = caspar::diagnostics::color(color);
 
        return {
-               (color >> 24) & 255,
-               (color >> 16) & 255,
-               (color >> 8) & 255,
-               (color >> 0) & 255
+               static_cast<sf::Uint8>((color >> 24) & 255),
+               static_cast<sf::Uint8>((color >> 16) & 255),
+               static_cast<sf::Uint8>((color >> 8) & 255),
+               static_cast<sf::Uint8>((color >> 0) & 255)
        };
 }
 
@@ -73,7 +74,7 @@ sf::Font& get_default_font()
        {
                sf::Font font;
                if (!font.loadFromFile("LiberationSans-Regular.ttf"))
-                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("LiberationSans-Regular.ttf not found"));
+                       CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("LiberationSans-Regular.ttf not found"));
                return font;
        }();
 
@@ -98,7 +99,7 @@ class context : public drawable
        
        std::list<std::weak_ptr<drawable>>      drawables_;
        int64_t                                                         refresh_rate_millis_            = 16;
-       boost::timer                                            display_time_;
+       caspar::timer                                           display_time_;
        bool                                                            calculate_view_                         = true;
        int                                                                     scroll_position_                        = 0;
        bool                                                            dragging_                                       = false;
@@ -206,13 +207,22 @@ private:
 
                if (calculate_view_)
                {
+                       int content_height              = static_cast<int>(RENDERING_HEIGHT * drawables_.size());
+                       int window_height               = static_cast<int>(window_->getSize().y);
+                       int not_visible                 = std::max(0, content_height - window_height);
+                       int min_scroll_position = -not_visible;
+                       int max_scroll_position = 0;
+
+                       scroll_position_ = std::min(max_scroll_position, std::max(min_scroll_position, scroll_position_));
                        view_.setViewport(sf::FloatRect(0, 0, 1.0, 1.0));
-                       view_.setSize(RENDERING_WIDTH, window_->getSize().y);
-                       view_.setCenter(RENDERING_WIDTH / 2, window_->getSize().y / 2 - scroll_position_);
+                       view_.setSize(RENDERING_WIDTH, window_height);
+                       view_.setCenter(RENDERING_WIDTH / 2, window_height / 2 - scroll_position_);
                        window_->setView(view_);
+
                        calculate_view_ = false;
                }
 
+               CASPAR_LOG_CALL(trace) << "osd_graph::tick()";
                window_->draw(*this);
 
                static const auto THRESHOLD = 1;
@@ -324,9 +334,18 @@ public:
                for (auto& vertex : line_data_)
                        vertex.position.x -= x_delta_;
 
+               for (auto& tag : line_tags_)
+               {
+                       if (tag)
+                       {
+                               (*tag)[0].position.x -= x_delta_;
+                               (*tag)[1].position.x -= x_delta_;
+                       }
+               }
+
                auto color = get_sfml_color(color_);
                color.a = 255 * 0.8;
-               line_data_.push_back(sf::Vertex(sf::Vector2f(get_insertion_xcoord(), std::max(0.05, std::min(0.95, (1.0f - tick_data_) * 0.8 + 0.1f))), color));
+               line_data_.push_back(sf::Vertex(sf::Vector2f(get_insertion_xcoord(), std::max(0.1f, std::min(0.9f, (1.0f - tick_data_) * 0.8f + 0.1f))), color));
 
                if (tick_tag_)
                {
@@ -412,7 +431,7 @@ struct graph : public drawable, public caspar::diagnostics::spi::graph_sink, pub
                lines_[name].set_value(value);
        }
 
-       void set_tag(const std::string& name) override
+       void set_tag(caspar::diagnostics::tag_severity /*severity*/, const std::string& name) override
        {
                lines_[name].set_tag();
        }