Recolor user's item when status changes

This commit is contained in:
Jaidyn Ann 2021-06-03 23:41:23 -05:00
parent dd298281e2
commit e00164c1aa
2 changed files with 97 additions and 7 deletions

View File

@ -5,22 +5,33 @@
#include "UserItem.h" #include "UserItem.h"
#include <InterfaceDefs.h>
#include <View.h>
#include "CayaConstants.h"
#include "NotifyMessage.h" #include "NotifyMessage.h"
#include "User.h" #include "User.h"
UserItem::UserItem(const char* name, User* user) UserItem::UserItem(const char* name, User* user, int32 status)
: :
BStringItem(name), BStringItem(name),
fUser(user) fUser(user),
fTextColor(ui_color(B_LIST_ITEM_TEXT_COLOR))
{ {
_UpdateColor(status);
} }
User* void
UserItem::GetUser() UserItem::DrawItem(BView* owner, BRect frame, bool complete)
{ {
return fUser; rgb_color highColor = owner->HighColor();
owner->SetHighColor(fTextColor);
BStringItem::DrawItem(owner, frame, complete);
owner->SetHighColor(highColor);
} }
@ -35,3 +46,74 @@ UserItem::ObserveString(int32 what, BString str)
} }
void
UserItem::ObserveInteger(int32 what, int32 value)
{
switch (what) {
case INT_CONTACT_STATUS:
{
_UpdateColor(value);
break;
}
}
}
User*
UserItem::GetUser()
{
return fUser;
}
void
UserItem::_UpdateColor(int32 status)
{
switch (status)
{
case CAYA_AWAY:
fTextColor = _TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 1);
break;
case CAYA_INVISIBLE:
case CAYA_DO_NOT_DISTURB:
fTextColor = _TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 2);
break;
case CAYA_OFFLINE:
fTextColor = _TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 3);
break;
default:
fTextColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
}
}
rgb_color
UserItem::_TintColor(rgb_color color, int severity)
{
bool dark = false;
if (color.Brightness() < 127)
dark = true;
switch (severity)
{
case 0:
return color;
case 1:
if (dark == true)
return tint_color(color, B_LIGHTEN_1_TINT + 0.2f);
else
return tint_color(color, B_DARKEN_1_TINT);
case 2:
if (dark == true)
return tint_color(color, B_LIGHTEN_1_TINT);
else
return tint_color(color, B_DARKEN_2_TINT);
case 3:
if (dark == true)
return tint_color(color, B_LIGHTEN_2_TINT + 0.1f);
else
return tint_color(color, B_DARKEN_3_TINT);
}
}

View File

@ -5,6 +5,7 @@
#ifndef USERITEM_H #ifndef USERITEM_H
#define USERITEM_H #define USERITEM_H
#include <GraphicsDefs.h>
#include <StringItem.h> #include <StringItem.h>
#include "Observer.h" #include "Observer.h"
@ -14,14 +15,21 @@ class User;
class UserItem : public BStringItem, public Observer { class UserItem : public BStringItem, public Observer {
public: public:
UserItem(const char* name, User* user); UserItem(const char* name, User* user, int32 status);
void DrawItem(BView* owner, BRect frame, bool complete);
void ObserveString(int32 what, BString str);
void ObserveInteger(int32 what, int32 value);
User* GetUser(); User* GetUser();
protected: protected:
void ObserveString(int32 what, BString str); void _UpdateColor(int32 status);
rgb_color _TintColor(rgb_color color, int severity);
private: private:
rgb_color fTextColor;
User* fUser; User* fUser;
}; };