diff --git a/application/views/UserItem.cpp b/application/views/UserItem.cpp index 2787a29..1c9427e 100644 --- a/application/views/UserItem.cpp +++ b/application/views/UserItem.cpp @@ -5,22 +5,33 @@ #include "UserItem.h" +#include +#include + +#include "CayaConstants.h" #include "NotifyMessage.h" #include "User.h" -UserItem::UserItem(const char* name, User* user) +UserItem::UserItem(const char* name, User* user, int32 status) : BStringItem(name), - fUser(user) + fUser(user), + fTextColor(ui_color(B_LIST_ITEM_TEXT_COLOR)) { + _UpdateColor(status); } -User* -UserItem::GetUser() +void +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); + } +} + + diff --git a/application/views/UserItem.h b/application/views/UserItem.h index 8848968..e50fac9 100644 --- a/application/views/UserItem.h +++ b/application/views/UserItem.h @@ -5,6 +5,7 @@ #ifndef USERITEM_H #define USERITEM_H +#include #include #include "Observer.h" @@ -14,14 +15,21 @@ class User; class UserItem : public BStringItem, public Observer { 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(); protected: - void ObserveString(int32 what, BString str); + void _UpdateColor(int32 status); + rgb_color _TintColor(rgb_color color, int severity); private: + rgb_color fTextColor; User* fUser; };