]> git.localhorst.tv Git - ffmpeg-test.git/commitdiff
show channel below quote
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 29 Sep 2024 22:02:50 +0000 (00:02 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 29 Sep 2024 22:02:50 +0000 (00:02 +0200)
src/app/Renderer.h
src/main.cpp
src/pango/Layout.h

index bb81c79df77f6d65cf0f239d4ee7e65500799191..b31c73c2f58f25f648c2b062493f48a9e72a40a7 100644 (file)
@@ -2,6 +2,7 @@
 #define TEST_APP_RENDERER_H_
 
 #include <cstdint>
+#include <iostream>
 extern "C" {
 #include "cairo.h"
 }
@@ -16,16 +17,22 @@ class Renderer {
 
 public:
        Renderer(uint8_t *plane, int linesize, int width, int height)
-       : font("DejaVu Sans 32px")
+       : text_font("DejaVu Sans 32px")
+       , channel_font("DejaVu Sans 24px")
        , surface(plane, linesize, CAIRO_FORMAT_ARGB32, width, height)
        , ctx(surface.CreateContext())
        , width(width)
        , height(height)
        , text()
-       , text_layout(ctx.CreateLayout()) {
-               text_layout.SetFont(font);
+       , text_layout(ctx.CreateLayout())
+       , channel()
+       , channel_layout(ctx.CreateLayout()) {
+               text_layout.SetFont(text_font);
                text_layout.SetWidth(width / 2);
+               channel_layout.SetFont(channel_font);
+               channel_layout.SetWidth(width / 2);
                SetText("Hello, I am a long text that should wrap eventually when it gets long enough to cross the halfway point of the total width available (not including the offset which is added afterwards).");
+               SetChannel("");
        }
        ~Renderer() {
        }
@@ -42,6 +49,10 @@ public:
                ctx.SetSourceRGB(1, 1, 1);
                text_layout.Render();
 
+               ctx.MoveTo(50, 50 + text_layout.GetLogicalRect().height + 10);
+               ctx.SetSourceRGB(0.392, 0.255, 0.647);
+               channel_layout.Render();
+
                surface.Flush();
        }
 
@@ -51,9 +62,16 @@ public:
                text_layout.Update();
        }
 
+       void SetChannel(const std::string &c) {
+               channel = c;
+               channel_layout.SetText(channel);
+               channel_layout.Update();
+       }
+
 
 private:
-       pango::Font font;
+       pango::Font text_font;
+       pango::Font channel_font;
        cairo::Surface surface;
        cairo::Context ctx;
 
@@ -62,6 +80,8 @@ private:
 
        std::string text;
        pango::Layout text_layout;
+       std::string channel;
+       pango::Layout channel_layout;
 
 };
 
index 36f0cac6c2561107f93e749a70707f10e0fc317c..31cfa98136bf9433ea04e89fead81194df1008a5 100644 (file)
@@ -37,10 +37,12 @@ void ws_handler(void *user, const Json::Value &json) {
        Json::Value data;
        Json::Reader json_reader;
        json_reader.parse(data_string, data);
-       const std::string text = data["model"]["text"].asString();
        app::Renderer *renderer = static_cast<app::Renderer *>(user);
+       const std::string text = data["model"]["text"].asString();
+       const std::string channel = data["model"]["channel"]["title"].asString();
        if (text.length() > 0) {
                renderer->SetText(text);
+               renderer->SetChannel(channel);
        }
 }
 
index 3e52df9d5869296b4f6feaa222974f9dba65bcbd..c465da79dcf64ec02b7820a516eb2723c40f3c58 100644 (file)
@@ -9,6 +9,8 @@
 #include <utility>
 
 #include "Font.h"
+#include "pango/pango-layout.h"
+#include "pango/pango-types.h"
 
 namespace pango {
 
@@ -40,6 +42,18 @@ public:
        }
 
 public:
+       const PangoRectangle &GetInkRect() const {
+               return ink_rect;
+       }
+
+       int GetLineCount() {
+               return pango_layout_get_line_count(l);
+       }
+
+       const PangoRectangle &GetLogicalRect() const {
+               return logical_rect;
+       }
+
        void Render() {
                pango_cairo_show_layout(c, l);
        }
@@ -58,11 +72,14 @@ public:
 
        void Update() {
                pango_cairo_update_layout(c, l);
+               pango_layout_get_pixel_extents(l, &ink_rect, &logical_rect);
        }
 
 private:
        cairo_t *c;
        PangoLayout *l;
+       PangoRectangle ink_rect;
+       PangoRectangle logical_rect;
 
 };