Custom rgb_colors for use with RunView
Allows custom colors to be dictated to RunView directly from CayaRenderView. Some colors that were reliant on hard-coded theme have been replaced with system colors.
This commit is contained in:
parent
2d34b4edde
commit
242d29c3a6
|
@ -15,11 +15,6 @@ CayaRenderView::CayaRenderView(const char *name, const char* smileyConfig)
|
|||
|
||||
PrepareTheme(fTheme);
|
||||
|
||||
SetViewColor(245, 245, 245, 0);
|
||||
SetLowColor(245, 245, 245, 0);
|
||||
SetHighColor(0, 0, 0, 0);
|
||||
|
||||
|
||||
SetTimeStampFormat(NULL);
|
||||
if ( IsHidden() )
|
||||
Show();
|
||||
|
@ -28,22 +23,17 @@ CayaRenderView::CayaRenderView(const char *name, const char* smileyConfig)
|
|||
|
||||
|
||||
void
|
||||
CayaRenderView::AppendOtherMessage(const char* otherNick, const char* message)
|
||||
CayaRenderView::AppendMessage(const char* nick, const char* message,
|
||||
rgb_color nameColor)
|
||||
{
|
||||
Append(otherNick, COL_OTHERNICK, COL_OTHERNICK, R_TEXT);
|
||||
Append(": ", COL_OTHERNICK, COL_OTHERNICK, R_TEXT);
|
||||
AddEmoticText(message, COL_TEXT, R_TEXT, COL_TEXT,R_EMOTICON);
|
||||
Append("\n", COL_TEXT, COL_TEXT, R_TEXT);
|
||||
ScrollToSelection();
|
||||
}
|
||||
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
|
||||
|
||||
|
||||
void
|
||||
CayaRenderView::AppendOwnMessage(const char* message)
|
||||
{
|
||||
Append("You: ", COL_OWNNICK, COL_OWNNICK, R_TEXT);
|
||||
AddEmoticText(message, COL_TEXT, R_TEXT,COL_TEXT,R_EMOTICON);
|
||||
Append("\n", COL_TEXT, COL_TEXT, R_TEXT);
|
||||
Append(nick, nameColor, bg, nameColor);
|
||||
Append(": ", nameColor, bg, nameColor);
|
||||
// AddEmoticText(message, fg, bg);
|
||||
Append(message, fg, bg, fg);
|
||||
Append("\n", fg, bg, fg);
|
||||
ScrollToSelection();
|
||||
}
|
||||
|
||||
|
@ -51,18 +41,21 @@ CayaRenderView::AppendOwnMessage(const char* message)
|
|||
void
|
||||
CayaRenderView::AppendGenericMessage(const char* message)
|
||||
{
|
||||
Append(message, COL_TEXT, COL_TEXT, R_TEXT);
|
||||
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
|
||||
|
||||
Append(message, fg, bg, fg);
|
||||
ScrollToSelection();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CayaRenderView::AddEmoticText(const char * txt, int16 cols , int16 font , int16 cols2 , int16 font2)
|
||||
CayaRenderView::AddEmoticText(const char * txt, rgb_color fore, rgb_color bg)
|
||||
{
|
||||
if (CayaPreferences::Item()->IgnoreEmoticons)
|
||||
Append(txt,cols,cols,font);
|
||||
Append(txt, fore, bg, fore);
|
||||
else
|
||||
Emoticor::Get()->AddText(this, txt, cols, font, cols2, font2);
|
||||
Emoticor::Get()->AddText(this, txt, fore, fore, bg, fore);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,10 +37,9 @@ class CayaRenderView : public RunView
|
|||
public:
|
||||
CayaRenderView(const char* name, const char* smileyConfig = NULL);
|
||||
|
||||
void AppendOtherMessage(const char* otherNick, const char* message);
|
||||
void AppendOwnMessage(const char* message);
|
||||
void AppendMessage(const char* nick, const char* message, rgb_color nameColor);
|
||||
void AppendGenericMessage(const char* message);
|
||||
void AddEmoticText(const char * txt, int16 cols , int16 font , int16 cols2 , int16 font2);
|
||||
void AddEmoticText(const char * txt, rgb_color fore, rgb_color bg);
|
||||
|
||||
protected:
|
||||
void PrepareTheme(Theme* theme);
|
||||
|
|
|
@ -306,18 +306,21 @@ ConversationView::_AppendMessage(BMessage* msg)
|
|||
|
||||
for (int i = bodies.CountStrings(); i >= 0; i--) {
|
||||
User* sender = fConversation->UserById(users.StringAt(i));
|
||||
BString sender_name;
|
||||
BString sender_name = users.StringAt(i);
|
||||
BString body = bodies.StringAt(i);
|
||||
rgb_color userColor = ui_color(B_PANEL_TEXT_COLOR);
|
||||
|
||||
if (sender != NULL)
|
||||
if (sender != NULL) {
|
||||
sender_name = sender->GetName();
|
||||
userColor = sender->fItemColor;
|
||||
}
|
||||
|
||||
if (sender_name.IsEmpty() == true) {
|
||||
fReceiveView->AppendGenericMessage(body.String());
|
||||
continue;
|
||||
}
|
||||
|
||||
fReceiveView->AppendOtherMessage(sender_name.String(), body.String());
|
||||
fReceiveView->AppendMessage(sender_name.String(), body.String(), userColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <Path.h>
|
||||
#include "string.h"
|
||||
|
||||
|
||||
static Emoticor* fInstance = NULL;
|
||||
|
||||
|
||||
|
@ -16,38 +17,44 @@ Emoticor::Get()
|
|||
return fInstance;
|
||||
}
|
||||
|
||||
|
||||
Emoticor::Emoticor()
|
||||
{
|
||||
fInstance = NULL;
|
||||
fConfig = NULL;
|
||||
}
|
||||
|
||||
|
||||
Emoticor::~Emoticor()
|
||||
{
|
||||
if (fConfig)
|
||||
delete fConfig;
|
||||
}
|
||||
|
||||
|
||||
Emoconfig*
|
||||
Emoticor::Config()
|
||||
{
|
||||
return fConfig;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Emoticor::LoadConfig(const char* txt)
|
||||
{
|
||||
fConfig = new Emoconfig(txt);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Emoticor::_findTokens(RunView* fTextView, BString text, int tokenstart, int16 cols , int16 font , int16 cols2 , int16 font2)
|
||||
Emoticor::_findTokens(RunView* fTextView, BString text, int tokenstart,
|
||||
rgb_color cols, rgb_color font, rgb_color cols2,
|
||||
rgb_color font2)
|
||||
{
|
||||
//******************************************
|
||||
// "Iteration is human, recursion is divine"
|
||||
//******************************************
|
||||
|
||||
|
||||
int32 newindex = 0;
|
||||
BString cur;
|
||||
int i = tokenstart;
|
||||
|
@ -82,7 +89,8 @@ Emoticor::_findTokens(RunView* fTextView, BString text, int tokenstart, int16 co
|
|||
|
||||
//printf("remaning [%s] printed [%s]\n",text.String(),cur->original.String());
|
||||
|
||||
fTextView->Append(cur.String(), cols2, cols2, font2);
|
||||
// fTextView->Append(cur.String(), cols2, cols2, font2);
|
||||
// TODO
|
||||
|
||||
if (text.Length() == 0) return; //useless stack
|
||||
} else
|
||||
|
@ -92,12 +100,14 @@ Emoticor::_findTokens(RunView* fTextView, BString text, int tokenstart, int16 co
|
|||
}
|
||||
}
|
||||
|
||||
fTextView->Append(text.String(), cols, cols, font);
|
||||
|
||||
// fTextView->Append(text.String(), cols, cols, font);
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Emoticor::AddText(RunView* fTextView, const char* txt, int16 cols , int16 font , int16 cols2 , int16 font2 )
|
||||
Emoticor::AddText(RunView* fTextView, const char* txt, rgb_color cols,
|
||||
rgb_color font, rgb_color cols2, rgb_color font2)
|
||||
{
|
||||
|
||||
BString left(txt);
|
||||
|
@ -111,3 +121,4 @@ Emoticor::AddText(RunView* fTextView, const char* txt, int16 cols , int16 font
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ public:
|
|||
static Emoticor* Get(); //singleton
|
||||
|
||||
|
||||
void AddText(RunView* fTextView, const char* text, int16 cols , int16 font , int16 cols2 , int16 font2 );
|
||||
void AddText(RunView* fTextView, const char* text, rgb_color cols,
|
||||
rgb_color font, rgb_color cols2, rgb_color font2);
|
||||
void LoadConfig(const char*);
|
||||
|
||||
Emoconfig* Config();
|
||||
|
@ -23,7 +24,9 @@ public:
|
|||
private:
|
||||
Emoticor();
|
||||
Emoconfig* fConfig;
|
||||
void _findTokens(RunView* fTextView, BString text, int tokenstart, int16 cols , int16 font , int16 cols2 , int16 font2);
|
||||
void _findTokens(RunView* fTextView, BString text, int tokenstart,
|
||||
rgb_color cols, rgb_color font, rgb_color cols2,
|
||||
rgb_color font2);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ struct FontColor {
|
|||
int fOffset;
|
||||
int fWhich;
|
||||
int fIndex;
|
||||
rgb_color fColor;
|
||||
};
|
||||
|
||||
|
||||
|
@ -128,16 +129,18 @@ struct Line {
|
|||
int fSoftie_used;
|
||||
|
||||
Line(const char* buffer, int fLength, float top, float width, Theme* fTheme,
|
||||
const char* fStamp_format, int fore, int back, int font);
|
||||
const char* fStamp_format, rgb_color fore, rgb_color back, rgb_color font);
|
||||
|
||||
~Line ();
|
||||
|
||||
void Append(const char* buffer, int len, float width,
|
||||
Theme* fTheme, int fore, int back, int font);
|
||||
Theme* fTheme, rgb_color fore, rgb_color back,
|
||||
rgb_color font);
|
||||
|
||||
void FigureSpaces();
|
||||
|
||||
void FigureFontColors(int pos, int fore, int back, int font);
|
||||
void FigureFontColors(int pos, rgb_color fore, rgb_color back,
|
||||
rgb_color font);
|
||||
void FigureEdges(Theme* fTheme, float width);
|
||||
void SoftBreaks(Theme* fTheme, float width);
|
||||
void AddSoftBreak(SoftBreakEnd, float&, int&, int16&, float&,
|
||||
|
@ -346,7 +349,7 @@ RunView::Draw(BRect frame)
|
|||
if (line->fFcs[fore].fOffset > place)
|
||||
break;
|
||||
|
||||
hi_color = fTheme->ForegroundAt(line->fFcs[fore].fIndex);
|
||||
hi_color = line->fFcs[fore].fColor;
|
||||
}
|
||||
|
||||
++fore;
|
||||
|
@ -358,8 +361,7 @@ RunView::Draw(BRect frame)
|
|||
if (line->fFcs[back].fOffset > place)
|
||||
break;
|
||||
|
||||
low_color = fTheme->BackgroundAt(
|
||||
line->fFcs[back].fIndex);
|
||||
low_color = line->fFcs[back].fColor;
|
||||
}
|
||||
|
||||
++back;
|
||||
|
@ -1234,26 +1236,22 @@ RunView::RecalcScrollBar(bool constrain)
|
|||
|
||||
|
||||
void
|
||||
RunView::Append(const char* buffer, int fore, int back, int font)
|
||||
RunView::Append(const char* buffer, rgb_color fore, rgb_color back,
|
||||
rgb_color font)
|
||||
{
|
||||
Append(buffer, strlen(buffer), fore, back, font);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RunView::Append(const char* buffer, int32 len, int fore, int back, int font)
|
||||
RunView::Append(const char* buffer, int32 len, rgb_color fore, rgb_color back,
|
||||
rgb_color font)
|
||||
{
|
||||
if (buffer == NULL)
|
||||
return;
|
||||
float width(Bounds().Width() - 10);
|
||||
int32 place(0);
|
||||
|
||||
assert(back != Theme::TimestampBack);
|
||||
assert(font != Theme::TimestampFont);
|
||||
assert(back != Theme::TimespaceBack);
|
||||
assert(font != Theme::TimespaceFont);
|
||||
assert(back != Theme::SelectionBack);
|
||||
|
||||
fTheme->ReadLock();
|
||||
|
||||
while (place < len) {
|
||||
|
@ -1276,15 +1274,15 @@ RunView::Append(const char* buffer, int32 len, int fore, int back, int font)
|
|||
width, fTheme, fore, back, font);
|
||||
|
||||
fWorking->Append(temp.String(), temp.Length(), width, fTheme,
|
||||
C_URL, back, F_URL);
|
||||
ui_color(B_LINK_TEXT_COLOR), back, fore);
|
||||
|
||||
place += (url_offset - last_offset) + temp.Length();
|
||||
last_offset = url_offset + temp.Length();
|
||||
}
|
||||
|
||||
if (place < end)
|
||||
fWorking->Append(buffer + place, end - place, width,
|
||||
fTheme, fore, back, font);
|
||||
fWorking->Append(buffer + place, end - place, width, fTheme,
|
||||
fore, back, font);
|
||||
}
|
||||
else {
|
||||
float top(0.0);
|
||||
|
@ -1304,8 +1302,8 @@ RunView::Append(const char* buffer, int32 len, int fore, int back, int font)
|
|||
while ((url_offset = crunch.Crunch(&temp)) != B_ERROR) {
|
||||
fWorking->Append(buffer + place, (url_offset - last_offset),
|
||||
width, fTheme, fore, back, font);
|
||||
fWorking->Append(temp.String(), temp.Length(),
|
||||
width, fTheme, C_URL, back, F_URL);
|
||||
fWorking->Append(temp.String(), temp.Length(), width, fTheme,
|
||||
ui_color(B_LINK_TEXT_COLOR), back, fore);
|
||||
|
||||
place += (url_offset - last_offset) + temp.Length();
|
||||
last_offset = url_offset + temp.Length();
|
||||
|
@ -1747,7 +1745,7 @@ void RunView::ScrollToSelection()
|
|||
|
||||
|
||||
Line::Line(const char* buffer, int len, float top, float width, Theme* theme,
|
||||
const char* stamp_format, int fore, int back, int font)
|
||||
const char* stamp_format, rgb_color fore, rgb_color back, rgb_color font)
|
||||
:
|
||||
fText(NULL),
|
||||
fStamp(time(NULL)),
|
||||
|
@ -1789,7 +1787,7 @@ Line::~Line()
|
|||
|
||||
void
|
||||
Line::Append(const char* buffer, int len, float width, Theme* theme,
|
||||
int fore, int back, int font)
|
||||
rgb_color fore, rgb_color back, rgb_color font)
|
||||
{
|
||||
int save (fLength);
|
||||
char* new_fText;
|
||||
|
@ -1818,7 +1816,7 @@ Line::Append(const char* buffer, int len, float width, Theme* theme,
|
|||
|
||||
FigureFontColors(save, fore, back, font);
|
||||
|
||||
if (fore == C_URL) {
|
||||
if (fore == ui_color(B_LINK_TEXT_COLOR)) {
|
||||
if (!fUrls)
|
||||
fUrls = new urllist;
|
||||
fUrls->AddItem (new URL (buffer, save, len));
|
||||
|
@ -1857,7 +1855,7 @@ Line::FigureSpaces()
|
|||
|
||||
|
||||
void
|
||||
Line::FigureFontColors(int pos, int fore, int back, int font)
|
||||
Line::FigureFontColors(int pos, rgb_color fore, rgb_color back, rgb_color font)
|
||||
{
|
||||
if (fFc_count) {
|
||||
int last_fore = -1;
|
||||
|
@ -1867,29 +1865,24 @@ Line::FigureFontColors(int pos, int fore, int back, int font)
|
|||
|
||||
// we have fFcs, so we backtrack for last of each fWhich
|
||||
for (i = fFc_count - 1; i >= 0; --i) {
|
||||
if (last_fore < 0
|
||||
&& fFcs[i].fWhich == FORE_WHICH)
|
||||
if (last_fore < 0 && fFcs[i].fWhich == FORE_WHICH)
|
||||
last_fore = i;
|
||||
else if (last_back < 0
|
||||
&& fFcs[i].fWhich == BACK_WHICH)
|
||||
else if (last_back < 0 && fFcs[i].fWhich == BACK_WHICH)
|
||||
last_back = i;
|
||||
else if (last_font < 0
|
||||
&& fFcs[i].fWhich == FONT_WHICH)
|
||||
else if (last_font < 0 && fFcs[i].fWhich == FONT_WHICH)
|
||||
last_font = i;
|
||||
|
||||
if (last_fore >= 0
|
||||
&& last_back >= 0
|
||||
&& last_font >= 0)
|
||||
if (last_fore >= 0 && last_back >= 0 && last_font >= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
// now figure out how many more we need
|
||||
int16 count = 0;
|
||||
if (fFcs[last_fore].fIndex != fore)
|
||||
if (fFcs[last_fore].fColor != fore)
|
||||
++count;
|
||||
if (fFcs[last_back].fIndex != back)
|
||||
if (fFcs[last_back].fColor != back)
|
||||
++count;
|
||||
if (fFcs[last_font].fIndex != font)
|
||||
if (fFcs[last_font].fColor != font)
|
||||
++count;
|
||||
|
||||
if (count) {
|
||||
|
@ -1899,24 +1892,24 @@ Line::FigureFontColors(int pos, int fore, int back, int font)
|
|||
delete [] fFcs;
|
||||
fFcs = new_fFcs;
|
||||
|
||||
if (fFcs[last_fore].fIndex != fore) {
|
||||
if (fFcs[last_fore].fColor != fore) {
|
||||
fFcs[fFc_count].fWhich = FORE_WHICH;
|
||||
fFcs[fFc_count].fOffset = pos;
|
||||
fFcs[fFc_count].fIndex = fore;
|
||||
fFcs[fFc_count].fColor = fore;
|
||||
++fFc_count;
|
||||
}
|
||||
|
||||
if (fFcs[last_back].fIndex != back) {
|
||||
if (fFcs[last_back].fColor != back) {
|
||||
fFcs[fFc_count].fWhich = BACK_WHICH;
|
||||
fFcs[fFc_count].fOffset = pos;
|
||||
fFcs[fFc_count].fIndex = back;
|
||||
fFcs[fFc_count].fColor = back;
|
||||
++fFc_count;
|
||||
}
|
||||
|
||||
if (fFcs[last_font].fIndex != font) {
|
||||
if (fFcs[last_font].fColor != font) {
|
||||
fFcs[fFc_count].fWhich = FONT_WHICH;
|
||||
fFcs[fFc_count].fOffset = pos;
|
||||
fFcs[fFc_count].fIndex = font;
|
||||
fFcs[fFc_count].fColor = font;
|
||||
++fFc_count;
|
||||
}
|
||||
}
|
||||
|
@ -1924,13 +1917,13 @@ Line::FigureFontColors(int pos, int fore, int back, int font)
|
|||
fFcs = new FontColor [fFc_count = 3];
|
||||
fFcs[0].fWhich = FORE_WHICH;
|
||||
fFcs[0].fOffset = 0;
|
||||
fFcs[0].fIndex = fore;
|
||||
fFcs[0].fColor = fore;
|
||||
fFcs[1].fWhich = BACK_WHICH;
|
||||
fFcs[1].fOffset = 0;
|
||||
fFcs[1].fIndex = back;
|
||||
fFcs[1].fColor = back;
|
||||
fFcs[2].fWhich = FONT_WHICH;
|
||||
fFcs[2].fOffset = 0;
|
||||
fFcs[2].fIndex = font;
|
||||
fFcs[2].fColor = font;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1988,7 +1981,7 @@ Line::FigureEdges(Theme* theme, float width)
|
|||
seglen = fFcs[next_fFcs].fOffset - fFcs[cur_fFcs].fOffset;
|
||||
}
|
||||
|
||||
// const BFont &f (theme->FontAt (fFcs[cur_font].fIndex));
|
||||
// const BFont &f (theme->FontAt (fFcs[cur_font].fIndex))
|
||||
TextRender* tr = theme->TextRenderAt (fFcs[cur_font].fIndex);
|
||||
|
||||
#ifdef __INTEL__
|
||||
|
|
|
@ -158,8 +158,8 @@ public:
|
|||
virtual void MouseUp (BPoint);
|
||||
|
||||
|
||||
void Append (const char*, int32, int, int, int);
|
||||
void Append (const char*, int, int, int);
|
||||
void Append (const char*, int32, rgb_color, rgb_color, rgb_color);
|
||||
void Append (const char*, rgb_color, rgb_color, rgb_color);
|
||||
|
||||
void Clear (void);
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue