2021-05-31 10:50:43 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UserItem.h"
|
|
|
|
|
2021-06-03 23:41:23 -05:00
|
|
|
#include <InterfaceDefs.h>
|
|
|
|
#include <View.h>
|
|
|
|
|
|
|
|
#include "CayaConstants.h"
|
2021-06-02 16:53:03 -05:00
|
|
|
#include "NotifyMessage.h"
|
2021-05-31 10:50:43 -05:00
|
|
|
#include "User.h"
|
|
|
|
|
|
|
|
|
2021-06-03 23:41:23 -05:00
|
|
|
UserItem::UserItem(const char* name, User* user, int32 status)
|
2021-05-31 10:50:43 -05:00
|
|
|
:
|
|
|
|
BStringItem(name),
|
2021-06-03 23:41:23 -05:00
|
|
|
fUser(user),
|
|
|
|
fTextColor(ui_color(B_LIST_ITEM_TEXT_COLOR))
|
2021-05-31 10:50:43 -05:00
|
|
|
{
|
2021-06-03 23:41:23 -05:00
|
|
|
_UpdateColor(status);
|
2021-05-31 10:50:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-03 23:41:23 -05:00
|
|
|
void
|
|
|
|
UserItem::DrawItem(BView* owner, BRect frame, bool complete)
|
2021-05-31 10:50:43 -05:00
|
|
|
{
|
2021-06-03 23:41:23 -05:00
|
|
|
rgb_color highColor = owner->HighColor();
|
|
|
|
owner->SetHighColor(fTextColor);
|
|
|
|
|
|
|
|
BStringItem::DrawItem(owner, frame, complete);
|
|
|
|
|
|
|
|
owner->SetHighColor(highColor);
|
2021-05-31 10:50:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UserItem::ObserveString(int32 what, BString str)
|
|
|
|
{
|
2021-06-02 16:53:03 -05:00
|
|
|
switch (what) {
|
|
|
|
case STR_CONTACT_NAME:
|
|
|
|
SetText(str);
|
|
|
|
break;
|
|
|
|
}
|
2021-05-31 10:50:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-03 23:41:23 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|