From 56020deb015eb6612fca6cc5074733785a1422b2 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 3 Nov 2024 15:12:11 +0100 Subject: [PATCH] better live notification --- src/app/Application.h | 2 +- src/app/Renderer.h | 1 + src/app/Shoutout.h | 43 ++++++++++++++++++++++++++++++++++++++++++- src/gfx/Position.h | 6 ++++++ src/gfx/Spacing.h | 4 ++++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/app/Application.h b/src/app/Application.h index f41c62e..b888ba5 100644 --- a/src/app/Application.h +++ b/src/app/Application.h @@ -128,7 +128,7 @@ private: ChannelInfo &info = state.GetChannelInfo(channel_id); info.Update(channel); } - //ShoutoutChannel(33); + ShoutoutChannel(33); } void HandlePusherChannel(const Json::Value &json) { diff --git a/src/app/Renderer.h b/src/app/Renderer.h index ae10c52..a632909 100644 --- a/src/app/Renderer.h +++ b/src/app/Renderer.h @@ -66,6 +66,7 @@ public: Shoutout &CreateShoutout(int channel_id, State &state) { Shoutout &shout = state.AddShoutout(channel_id, ctx); + shout.SetLiveFont(text_font); shout.SetTitleFont(text_font); shout.SetChannelFont(channel_font); shout.SetCategoryFont(channel_font); diff --git a/src/app/Shoutout.h b/src/app/Shoutout.h index 70a24fc..163778b 100644 --- a/src/app/Shoutout.h +++ b/src/app/Shoutout.h @@ -23,10 +23,13 @@ public: Shoutout(const ChannelInfo &channel, cairo::Context &ctx, State &state) : channel(channel) , state(state) + , live_layout(ctx.CreateLayout()) , title_layout(ctx.CreateLayout()) , channel_layout(ctx.CreateLayout()) , category_layout(ctx.CreateLayout()) , bg_color{ 0.1, 0.1, 0.1 } + , border_color{ 0.8, 0.1, 0.1 } + , live_color{ 0.8, 0.1, 0.1 } , title_color{ 1, 1, 1 } , channel_color{ 0.392, 0.255, 0.647 } , anchor{ 1280, 720 - 75 } @@ -37,6 +40,7 @@ public: , running(false) , done(false) , fetching_clip(false) { + live_layout.SetText("Jetzt Live"); title_layout.SetText(channel.twitch_title); channel_layout.SetText(channel.title); category_layout.SetText(channel.twitch_category); @@ -70,6 +74,10 @@ public: return done; } + void SetLiveFont(pango::Font &font) { + live_layout.SetFont(font); + } + void SetTitleFont(pango::Font &font) { title_layout.SetFont(font); } @@ -108,7 +116,7 @@ public: anchor.y = 720 - 75; } else if (ms > 59000) { anchor.x = 75; - anchor.y = runtime.InterpolateClamp(720 - 75, 720 + size.h, 59000, 59400); + anchor.y = runtime.InterpolateClamp(720 - 75, 720 + GetTotalSize().h, 59000, 59400); } else { anchor.x = 75; anchor.y = 720 - 75; @@ -118,7 +126,14 @@ public: } } + gfx::Size GetTotalSize() const { + gfx::Size total(size); + total.h += double(live_layout.GetLogicalRect().height) + padding.Vertical() + 1.0; + return total; + } + void Recalc(cairo::Context &ctx) { + ctx.UpdateLayout(live_layout); ctx.UpdateLayout(title_layout); ctx.UpdateLayout(channel_layout); ctx.UpdateLayout(category_layout); @@ -133,6 +148,29 @@ public: ctx.Rectangle(pos, size); ctx.Fill(); + ctx.SetSourceColor(border_color); + ctx.Rectangle(pos, size); + ctx.SetLineWidth(2.0); + ctx.Stroke(); + + gfx::Position live_pos = pos; + live_pos.y -= padding.Vertical() + live_layout.GetLogicalRect().height; + gfx::Size live_size = padding.Resize(gfx::Size{ double(live_layout.GetLogicalRect().width), double(live_layout.GetLogicalRect().height) }); + + ctx.SetSourceColor(bg_color); + ctx.Rectangle(live_pos, live_size); + ctx.Fill(); + + ctx.SetSourceColor(border_color); + ctx.Rectangle(live_pos, live_size); + ctx.SetLineWidth(2.0); + ctx.Stroke(); + + live_pos += padding.Offset(); + ctx.MoveTo(live_pos); + ctx.SetSourceColor(live_color); + ctx.DrawLayout(live_layout); + gfx::Position title_pos = pos + padding.InnerTL(size); ctx.MoveTo(title_pos); ctx.SetSourceColor(title_color); @@ -153,10 +191,13 @@ private: const ChannelInfo &channel; State &state; + pango::Layout live_layout; pango::Layout title_layout; pango::Layout channel_layout; pango::Layout category_layout; gfx::ColorRGB bg_color; + gfx::ColorRGB border_color; + gfx::ColorRGB live_color; gfx::ColorRGB title_color; gfx::ColorRGB channel_color; gfx::ColorRGB category_color; diff --git a/src/gfx/Position.h b/src/gfx/Position.h index 0f2909e..8a6e012 100644 --- a/src/gfx/Position.h +++ b/src/gfx/Position.h @@ -10,6 +10,12 @@ struct Position { double x = 0.0; double y = 0.0; + Position &operator +=(const Position &other) { + x += other.x; + y += other.y; + return *this; + } + }; inline gfx::Position operator +(const Position &a, const Position &b) { diff --git a/src/gfx/Spacing.h b/src/gfx/Spacing.h index c2bef09..f4bade2 100644 --- a/src/gfx/Spacing.h +++ b/src/gfx/Spacing.h @@ -38,6 +38,10 @@ struct Spacing { return top + bottom + v_inter * double(n - 1); } + Size Resize(const Size &in, int nx = 1, int ny = 1) const { + return Size{ in.w + Horizontal(nx), in.h + Vertical(ny) }; + } + Position InnerTL(const Size &bounds) const { return Position{ left, top }; } -- 2.39.2