forked from OpenGamers/abaddon
render total mentions on guild, redraw on message create
This commit is contained in:
parent
0b0135268e
commit
46ab760a56
@ -176,7 +176,7 @@ ChannelList::ChannelList()
|
||||
discord.signal_message_ack().connect(sigc::mem_fun(*this, &ChannelList::OnMessageAck));
|
||||
}
|
||||
|
||||
void ChannelList::UsePanedHack(Gtk::Paned& paned) {
|
||||
void ChannelList::UsePanedHack(Gtk::Paned &paned) {
|
||||
paned.property_position().signal_changed().connect(sigc::mem_fun(*this, &ChannelList::OnPanedPositionChanged));
|
||||
}
|
||||
|
||||
@ -718,12 +718,16 @@ void ChannelList::OnMessageAck(const MessageAckData &data) {
|
||||
|
||||
void ChannelList::OnMessageCreate(const Message &msg) {
|
||||
auto iter = GetIteratorForChannelFromID(msg.ChannelID);
|
||||
m_model->row_changed(m_model->get_path(iter), iter); // redraw
|
||||
if (iter) m_model->row_changed(m_model->get_path(iter), iter); // redraw
|
||||
const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(msg.ChannelID);
|
||||
if (!channel.has_value()) return;
|
||||
if (channel->Type != ChannelType::DM && channel->Type != ChannelType::GROUP_DM) return;
|
||||
if (iter)
|
||||
(*iter)[m_columns.m_sort] = -msg.ID;
|
||||
if (channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM) {
|
||||
if (iter)
|
||||
(*iter)[m_columns.m_sort] = -msg.ID;
|
||||
}
|
||||
if (channel->GuildID.has_value())
|
||||
if ((iter = GetIteratorForGuildFromID(*channel->GuildID)))
|
||||
m_model->row_changed(m_model->get_path(iter), iter);
|
||||
}
|
||||
|
||||
bool ChannelList::OnButtonPressEvent(GdkEventButton *ev) {
|
||||
|
@ -1,15 +1,56 @@
|
||||
#include "unreadrenderer.hpp"
|
||||
#include "abaddon.hpp"
|
||||
|
||||
constexpr static int MentionsRightPad = 7;
|
||||
constexpr static double M_PI = 3.14159265358979;
|
||||
constexpr static double M_PI_H = M_PI / 2.0;
|
||||
constexpr static double M_PI_3_2 = M_PI * 3.0 / 2.0;
|
||||
|
||||
void CairoPathRoundedRect(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();
|
||||
}
|
||||
|
||||
void RenderMentionsCount(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, int mentions, int edge, const Gdk::Rectangle &cell_area) {
|
||||
Pango::FontDescription font;
|
||||
font.set_family("sans 14");
|
||||
//font.set_weight(Pango::WEIGHT_BOLD);
|
||||
|
||||
auto layout = widget.create_pango_layout(std::to_string(mentions));
|
||||
layout->set_font_description(font);
|
||||
layout->set_alignment(Pango::ALIGN_RIGHT);
|
||||
|
||||
int width, height;
|
||||
layout->get_pixel_size(width, height);
|
||||
{
|
||||
const auto x = cell_area.get_x() + edge - width - MentionsRightPad;
|
||||
const auto y = cell_area.get_y() + cell_area.get_height() / 2.0 - height / 2.0;
|
||||
CairoPathRoundedRect(cr, x - 4, y + 2, width + 8, height, 5);
|
||||
cr->set_source_rgb(184.0 / 255.0, 37.0 / 255.0, 37.0 / 255.0);
|
||||
cr->fill();
|
||||
cr->set_source_rgb(1.0, 1.0, 1.0);
|
||||
cr->move_to(x, y);
|
||||
layout->show_in_cairo_context(cr);
|
||||
}
|
||||
}
|
||||
|
||||
void UnreadRenderer::RenderUnreadOnGuild(Snowflake id, Gtk::Widget &widget, const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area) {
|
||||
// maybe have DiscordClient track this?
|
||||
int total_mentions = 0;
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto channels = discord.GetChannelsInGuild(id);
|
||||
bool has_unread = false;
|
||||
for (const auto &id : channels) {
|
||||
if (Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id) >= 0) {
|
||||
const int state = Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id);
|
||||
if (state >= 0) {
|
||||
has_unread = true;
|
||||
break;
|
||||
total_mentions += state;
|
||||
}
|
||||
}
|
||||
if (!has_unread) return;
|
||||
@ -21,6 +62,14 @@ void UnreadRenderer::RenderUnreadOnGuild(Snowflake id, Gtk::Widget &widget, cons
|
||||
const auto h = background_area.get_height();
|
||||
cr->rectangle(x, y + h / 2 - 24 / 2, 3, 24);
|
||||
cr->fill();
|
||||
|
||||
if (total_mentions < 1) return;
|
||||
auto *paned = static_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type()));
|
||||
if (paned != nullptr) {
|
||||
const auto edge = std::min(paned->get_position(), cell_area.get_width());
|
||||
|
||||
RenderMentionsCount(cr, widget, total_mentions, edge, cell_area);
|
||||
}
|
||||
}
|
||||
|
||||
void UnreadRenderer::RenderUnreadOnChannel(Snowflake id, Gtk::Widget &widget, const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area) {
|
||||
@ -36,25 +85,9 @@ void UnreadRenderer::RenderUnreadOnChannel(Snowflake id, Gtk::Widget &widget, co
|
||||
|
||||
if (state < 1) return;
|
||||
auto *paned = static_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type()));
|
||||
const auto edge = paned->get_position();
|
||||
if (paned != nullptr) {
|
||||
const auto edge = std::min(paned->get_position(), cell_area.get_width());
|
||||
|
||||
// surely this shouldnt be run every draw?
|
||||
// https://developer-old.gnome.org/gtkmm-tutorial/3.22/sec-drawing-text.html.en
|
||||
|
||||
Pango::FontDescription font;
|
||||
font.set_family("sans 14");
|
||||
font.set_weight(Pango::WEIGHT_BOLD);
|
||||
|
||||
auto layout = widget.create_pango_layout(std::to_string(state));
|
||||
layout->set_font_description(font);
|
||||
layout->set_alignment(Pango::ALIGN_RIGHT);
|
||||
|
||||
int width, height;
|
||||
layout->get_pixel_size(width, height);
|
||||
{
|
||||
const auto x = cell_area.get_x() + std::min(edge, cell_area.get_width()) - 14 - 2;
|
||||
const auto y = cell_area.get_y() + cell_area.get_height() / 2.0 - height / 2.0;
|
||||
cr->move_to(x, y);
|
||||
layout->show_in_cairo_context(cr);
|
||||
RenderMentionsCount(cr, widget, state, edge, cell_area);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user