mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-04 11:33:27 +03:00
make status indicator colors customizable
This commit is contained in:
@@ -11,10 +11,12 @@ StatusIndicator::StatusIndicator(Snowflake user_id)
|
||||
: Glib::ObjectBase("statusindicator")
|
||||
, Gtk::Widget()
|
||||
, m_id(user_id)
|
||||
, m_color(OfflineColor) {
|
||||
, m_status(static_cast<PresenceStatus>(-1)) {
|
||||
set_has_window(true);
|
||||
set_name("status-indicator");
|
||||
|
||||
get_style_context()->add_class("status-indicator");
|
||||
|
||||
Abaddon::Get().GetDiscordClient().signal_guild_member_list_update().connect(sigc::hide(sigc::mem_fun(*this, &StatusIndicator::CheckStatus)));
|
||||
auto cb = [this](Snowflake id, PresenceStatus status) {
|
||||
if (id == m_id) CheckStatus();
|
||||
@@ -29,26 +31,21 @@ StatusIndicator::~StatusIndicator() {
|
||||
|
||||
void StatusIndicator::CheckStatus() {
|
||||
const auto status = Abaddon::Get().GetDiscordClient().GetUserStatus(m_id);
|
||||
const auto last_status = m_status;
|
||||
get_style_context()->remove_class("online");
|
||||
get_style_context()->remove_class("dnd");
|
||||
get_style_context()->remove_class("idle");
|
||||
get_style_context()->remove_class("offline");
|
||||
if (status.has_value()) {
|
||||
switch (*status) {
|
||||
case PresenceStatus::Online:
|
||||
m_color = OnlineColor;
|
||||
break;
|
||||
case PresenceStatus::Offline:
|
||||
m_color = OfflineColor;
|
||||
break;
|
||||
case PresenceStatus::DND:
|
||||
m_color = DNDColor;
|
||||
break;
|
||||
case PresenceStatus::Idle:
|
||||
m_color = IdleColor;
|
||||
break;
|
||||
}
|
||||
get_style_context()->add_class(GetPresenceString(*status));
|
||||
m_status = *status;
|
||||
} else {
|
||||
m_color = OfflineColor;
|
||||
m_status = PresenceStatus::Offline;
|
||||
get_style_context()->add_class("offline");
|
||||
}
|
||||
|
||||
queue_draw();
|
||||
if (last_status != m_status)
|
||||
queue_draw();
|
||||
}
|
||||
|
||||
Gtk::SizeRequestMode StatusIndicator::get_request_mode_vfunc() const {
|
||||
@@ -126,7 +123,9 @@ bool StatusIndicator::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
|
||||
const auto width = allocation.get_width();
|
||||
const auto height = allocation.get_height();
|
||||
|
||||
cr->set_source_rgb(m_color.get_red(), m_color.get_green(), m_color.get_blue());
|
||||
const auto color = get_style_context()->get_color(Gtk::STATE_FLAG_NORMAL);
|
||||
|
||||
cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue());
|
||||
cr->arc(width / 2, height / 2, width / 3, 0.0, 2 * (4 * std::atan(1)));
|
||||
cr->close_path();
|
||||
cr->fill_preserve();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <gtkmm.h>
|
||||
#include "../discord/snowflake.hpp"
|
||||
#include "../discord/activity.hpp"
|
||||
|
||||
class StatusIndicator : public Gtk::Widget {
|
||||
public:
|
||||
@@ -22,9 +23,8 @@ protected:
|
||||
|
||||
Glib::RefPtr<Gdk::Window> m_window;
|
||||
|
||||
private:
|
||||
void CheckStatus();
|
||||
|
||||
Snowflake m_id;
|
||||
Gdk::RGBA m_color;
|
||||
PresenceStatus m_status;
|
||||
};
|
||||
|
||||
16
css/bare.css
16
css/bare.css
@@ -17,3 +17,19 @@
|
||||
border: 1px solid #aaaaaa;
|
||||
padding: 2px 5px 2px 5px;
|
||||
}
|
||||
|
||||
.status-indicator.dnd {
|
||||
color: #982929;
|
||||
}
|
||||
|
||||
.status-indicator.online {
|
||||
color: #43B581;
|
||||
}
|
||||
|
||||
.status-indicator.offline {
|
||||
color: #808080;
|
||||
}
|
||||
|
||||
.status-indicator.idle {
|
||||
color: #FAA61A;
|
||||
}
|
||||
|
||||
16
css/main.css
16
css/main.css
@@ -217,3 +217,19 @@
|
||||
background: @background_color;
|
||||
color: #cccccc;
|
||||
}
|
||||
|
||||
.status-indicator.dnd {
|
||||
color: #982929;
|
||||
}
|
||||
|
||||
.status-indicator.online {
|
||||
color: #43B581;
|
||||
}
|
||||
|
||||
.status-indicator.offline {
|
||||
color: #808080;
|
||||
}
|
||||
|
||||
.status-indicator.idle {
|
||||
color: #FAA61A;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,20 @@ enum class PresenceStatus : uint8_t {
|
||||
DND,
|
||||
};
|
||||
|
||||
constexpr inline const char *GetPresenceString(PresenceStatus s) {
|
||||
switch (s) {
|
||||
case PresenceStatus::Online:
|
||||
return "online";
|
||||
case PresenceStatus::Offline:
|
||||
return "offline";
|
||||
case PresenceStatus::Idle:
|
||||
return "idle";
|
||||
case PresenceStatus::DND:
|
||||
return "dnd";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
enum class ActivityType : int {
|
||||
Game = 0,
|
||||
Streaming = 1,
|
||||
|
||||
Reference in New Issue
Block a user