-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ugly little mention indicator to classic guild listing
- Loading branch information
Showing
9 changed files
with
122 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "mentionoverlay.hpp" | ||
|
||
#include "misc/cairo.hpp" | ||
|
||
#include "abaddon.hpp" | ||
|
||
MentionOverlay::MentionOverlay(Snowflake guild_id) | ||
: m_guild_id(guild_id) { | ||
m_font.set_family("sans 14"); | ||
m_layout = create_pango_layout("12"); | ||
m_layout->set_font_description(m_font); | ||
m_layout->set_alignment(Pango::ALIGN_RIGHT); | ||
|
||
get_style_context()->add_class("classic-mention-overlay"); // fuck you | ||
|
||
set_hexpand(false); | ||
set_vexpand(false); | ||
|
||
signal_draw().connect(sigc::mem_fun(*this, &MentionOverlay::OnDraw)); | ||
|
||
Abaddon::Get().GetDiscordClient().signal_message_ack().connect([this](const MessageAckData &data) { | ||
// fetching and checking guild id is probably more expensive than just forcing a redraw anyways | ||
queue_draw(); | ||
}); | ||
|
||
Abaddon::Get().GetDiscordClient().signal_message_create().connect([this](const Message &msg) { | ||
if (msg.GuildID.has_value() && *msg.GuildID != m_guild_id) return; | ||
if (!msg.DoesMentionEveryone && msg.Mentions.empty() && msg.MentionRoles.empty()) return; | ||
queue_draw(); | ||
}); | ||
} | ||
|
||
bool MentionOverlay::OnDraw(const Cairo::RefPtr<Cairo::Context> &cr) { | ||
int mentions; | ||
Abaddon::Get().GetDiscordClient().GetUnreadStateForGuild(m_guild_id, mentions); | ||
if (mentions == 0) return true; | ||
m_layout->set_text(std::to_string(mentions)); | ||
|
||
const int width = get_allocated_width(); | ||
const int height = get_allocated_height(); | ||
|
||
int lw, lh; | ||
m_layout->get_pixel_size(lw, lh); | ||
{ | ||
static const auto badge_setting = Gdk::RGBA(Abaddon::Get().GetSettings().MentionBadgeColor); | ||
static const auto text_setting = Gdk::RGBA(Abaddon::Get().GetSettings().MentionBadgeTextColor); | ||
|
||
auto bg = badge_setting.get_alpha_u() > 0 ? badge_setting : get_style_context()->get_background_color(Gtk::STATE_FLAG_SELECTED); | ||
auto text = text_setting.get_alpha_u() > 0 ? text_setting : get_style_context()->get_color(Gtk::STATE_FLAG_SELECTED); | ||
|
||
const auto x = width - lw - 5; | ||
const auto y = height - lh - 1; | ||
CairoUtil::PathRoundedRect(cr, x - 4, y + 2, lw + 8, lh, 5); | ||
cr->set_source_rgb(bg.get_red(), bg.get_green(), bg.get_blue()); | ||
cr->fill(); | ||
cr->set_source_rgb(text.get_red(), text.get_green(), text.get_blue()); | ||
cr->move_to(x, y); | ||
m_layout->show_in_cairo_context(cr); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <gtkmm/drawingarea.h> | ||
#include <pangomm/fontdescription.h> | ||
|
||
#include "discord/snowflake.hpp" | ||
|
||
class MentionOverlay : public Gtk::DrawingArea { | ||
public: | ||
MentionOverlay(Snowflake guild_id); | ||
|
||
private: | ||
bool OnDraw(const Cairo::RefPtr<Cairo::Context> &cr); | ||
|
||
Snowflake m_guild_id; | ||
|
||
Pango::FontDescription m_font; | ||
Glib::RefPtr<Pango::Layout> m_layout; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "cairo.hpp" | ||
|
||
#include <cairomm/context.h> | ||
|
||
constexpr static double M_PI_H = M_PI / 2.0; | ||
constexpr static double M_PI_3_2 = M_PI * 3.0 / 2.0; | ||
|
||
void CairoUtil::PathRoundedRect(const Cairo::RefPtr<Cairo::Context> &cr, double x, double y, double w, double h, double r) { | ||
const double degrees = M_PI / 180.0; | ||
|
||
cr->begin_new_sub_path(); | ||
cr->arc(x + w - r, y + r, r, -M_PI_H, 0); | ||
cr->arc(x + w - r, y + h - r, r, 0, M_PI_H); | ||
cr->arc(x + r, y + h - r, r, M_PI_H, M_PI); | ||
cr->arc(x + r, y + r, r, M_PI, M_PI_3_2); | ||
cr->close_path(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
namespace CairoUtil { | ||
void PathRoundedRect(const Cairo::RefPtr<Cairo::Context> &cr, double x, double y, double w, double h, double r); | ||
} // namespace CairoUtil |