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:
Jaidyn Ann 2021-06-07 20:01:14 -05:00
parent 2d34b4edde
commit 242d29c3a6
7 changed files with 111 additions and 109 deletions

View File

@ -15,11 +15,6 @@ CayaRenderView::CayaRenderView(const char *name, const char* smileyConfig)
PrepareTheme(fTheme); PrepareTheme(fTheme);
SetViewColor(245, 245, 245, 0);
SetLowColor(245, 245, 245, 0);
SetHighColor(0, 0, 0, 0);
SetTimeStampFormat(NULL); SetTimeStampFormat(NULL);
if ( IsHidden() ) if ( IsHidden() )
Show(); Show();
@ -28,22 +23,17 @@ CayaRenderView::CayaRenderView(const char *name, const char* smileyConfig)
void 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); rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
Append(": ", COL_OTHERNICK, COL_OTHERNICK, R_TEXT); rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
AddEmoticText(message, COL_TEXT, R_TEXT, COL_TEXT,R_EMOTICON);
Append("\n", COL_TEXT, COL_TEXT, R_TEXT);
ScrollToSelection();
}
Append(nick, nameColor, bg, nameColor);
void Append(": ", nameColor, bg, nameColor);
CayaRenderView::AppendOwnMessage(const char* message) // AddEmoticText(message, fg, bg);
{ Append(message, fg, bg, fg);
Append("You: ", COL_OWNNICK, COL_OWNNICK, R_TEXT); Append("\n", fg, bg, fg);
AddEmoticText(message, COL_TEXT, R_TEXT,COL_TEXT,R_EMOTICON);
Append("\n", COL_TEXT, COL_TEXT, R_TEXT);
ScrollToSelection(); ScrollToSelection();
} }
@ -51,18 +41,21 @@ CayaRenderView::AppendOwnMessage(const char* message)
void void
CayaRenderView::AppendGenericMessage(const char* message) 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(); ScrollToSelection();
} }
void 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) if (CayaPreferences::Item()->IgnoreEmoticons)
Append(txt,cols,cols,font); Append(txt, fore, bg, fore);
else else
Emoticor::Get()->AddText(this, txt, cols, font, cols2, font2); Emoticor::Get()->AddText(this, txt, fore, fore, bg, fore);
} }

View File

@ -37,10 +37,9 @@ class CayaRenderView : public RunView
public: public:
CayaRenderView(const char* name, const char* smileyConfig = NULL); CayaRenderView(const char* name, const char* smileyConfig = NULL);
void AppendOtherMessage(const char* otherNick, const char* message); void AppendMessage(const char* nick, const char* message, rgb_color nameColor);
void AppendOwnMessage(const char* message);
void AppendGenericMessage(const char* message); 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: protected:
void PrepareTheme(Theme* theme); void PrepareTheme(Theme* theme);

View File

@ -306,18 +306,21 @@ ConversationView::_AppendMessage(BMessage* msg)
for (int i = bodies.CountStrings(); i >= 0; i--) { for (int i = bodies.CountStrings(); i >= 0; i--) {
User* sender = fConversation->UserById(users.StringAt(i)); User* sender = fConversation->UserById(users.StringAt(i));
BString sender_name; BString sender_name = users.StringAt(i);
BString body = bodies.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(); sender_name = sender->GetName();
userColor = sender->fItemColor;
}
if (sender_name.IsEmpty() == true) { if (sender_name.IsEmpty() == true) {
fReceiveView->AppendGenericMessage(body.String()); fReceiveView->AppendGenericMessage(body.String());
continue; continue;
} }
fReceiveView->AppendOtherMessage(sender_name.String(), body.String()); fReceiveView->AppendMessage(sender_name.String(), body.String(), userColor);
} }
} }

View File

@ -4,6 +4,7 @@
#include <Path.h> #include <Path.h>
#include "string.h" #include "string.h"
static Emoticor* fInstance = NULL; static Emoticor* fInstance = NULL;
@ -16,38 +17,44 @@ Emoticor::Get()
return fInstance; return fInstance;
} }
Emoticor::Emoticor() Emoticor::Emoticor()
{ {
fInstance = NULL; fInstance = NULL;
fConfig = NULL; fConfig = NULL;
} }
Emoticor::~Emoticor() Emoticor::~Emoticor()
{ {
if (fConfig) if (fConfig)
delete fConfig; delete fConfig;
} }
Emoconfig* Emoconfig*
Emoticor::Config() Emoticor::Config()
{ {
return fConfig; return fConfig;
} }
void void
Emoticor::LoadConfig(const char* txt) Emoticor::LoadConfig(const char* txt)
{ {
fConfig = new Emoconfig(txt); fConfig = new Emoconfig(txt);
} }
void 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" // "Iteration is human, recursion is divine"
//****************************************** //******************************************
int32 newindex = 0; int32 newindex = 0;
BString cur; BString cur;
int i = tokenstart; 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()); //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 if (text.Length() == 0) return; //useless stack
} else } 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 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); BString left(txt);
@ -111,3 +121,4 @@ Emoticor::AddText(RunView* fTextView, const char* txt, int16 cols , int16 font
} }

View File

@ -13,7 +13,8 @@ public:
static Emoticor* Get(); //singleton 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*); void LoadConfig(const char*);
Emoconfig* Config(); Emoconfig* Config();
@ -23,7 +24,9 @@ public:
private: private:
Emoticor(); Emoticor();
Emoconfig* fConfig; 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);
}; };

View File

@ -106,6 +106,7 @@ struct FontColor {
int fOffset; int fOffset;
int fWhich; int fWhich;
int fIndex; int fIndex;
rgb_color fColor;
}; };
@ -128,16 +129,18 @@ struct Line {
int fSoftie_used; int fSoftie_used;
Line(const char* buffer, int fLength, float top, float width, Theme* fTheme, 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 (); ~Line ();
void Append(const char* buffer, int len, float width, 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 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 FigureEdges(Theme* fTheme, float width);
void SoftBreaks(Theme* fTheme, float width); void SoftBreaks(Theme* fTheme, float width);
void AddSoftBreak(SoftBreakEnd, float&, int&, int16&, float&, void AddSoftBreak(SoftBreakEnd, float&, int&, int16&, float&,
@ -267,18 +270,18 @@ RunView::Draw(BRect frame)
Window()->BeginViewTransaction(); Window()->BeginViewTransaction();
rgb_color low_color, hi_color, view_color, sel_color, sel_fText; rgb_color low_color, hi_color, view_color, sel_color, sel_fText;
float height (frame.bottom); float height(frame.bottom);
BRect bounds (Bounds()); BRect bounds(Bounds());
BRegion clipper; BRegion clipper;
bool drawSelection (false); bool drawSelection(false);
bool checkSelection (fSp_start != fSp_end); bool checkSelection(fSp_start != fSp_end);
clipper.Set (frame); clipper.Set (frame);
ConstrainClippingRegion (&clipper); ConstrainClippingRegion (&clipper);
fTheme->ReadLock(); fTheme->ReadLock();
view_color = fTheme->BackgroundAt (Theme::NormalBack); view_color = fTheme->BackgroundAt(Theme::NormalBack);
sel_color = fTheme->BackgroundAt (Theme::SelectionBack); sel_color = fTheme->BackgroundAt(Theme::SelectionBack);
if (((sel_color.red + sel_color.blue + sel_color.green) / 3) >= 127) { if (((sel_color.red + sel_color.blue + sel_color.green) / 3) >= 127) {
sel_fText.red = sel_fText.green = sel_fText.blue = 0; sel_fText.red = sel_fText.green = sel_fText.blue = 0;
@ -301,7 +304,7 @@ RunView::Draw(BRect frame)
} }
for (int i = fLine_count - 1; i >= 0; --i) { for (int i = fLine_count - 1; i >= 0; --i) {
Line* line (fLines[i]); Line* line(fLines[i]);
if (line->fBottom < frame.top) if (line->fBottom < frame.top)
break; break;
@ -346,7 +349,7 @@ RunView::Draw(BRect frame)
if (line->fFcs[fore].fOffset > place) if (line->fFcs[fore].fOffset > place)
break; break;
hi_color = fTheme->ForegroundAt(line->fFcs[fore].fIndex); hi_color = line->fFcs[fore].fColor;
} }
++fore; ++fore;
@ -358,8 +361,7 @@ RunView::Draw(BRect frame)
if (line->fFcs[back].fOffset > place) if (line->fFcs[back].fOffset > place)
break; break;
low_color = fTheme->BackgroundAt( low_color = line->fFcs[back].fColor;
line->fFcs[back].fIndex);
} }
++back; ++back;
@ -1234,26 +1236,22 @@ RunView::RecalcScrollBar(bool constrain)
void 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); Append(buffer, strlen(buffer), fore, back, font);
} }
void 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) if (buffer == NULL)
return; return;
float width(Bounds().Width() - 10); float width(Bounds().Width() - 10);
int32 place(0); 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(); fTheme->ReadLock();
while (place < len) { 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); width, fTheme, fore, back, font);
fWorking->Append(temp.String(), temp.Length(), width, fTheme, 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(); place += (url_offset - last_offset) + temp.Length();
last_offset = url_offset + temp.Length(); last_offset = url_offset + temp.Length();
} }
if (place < end) if (place < end)
fWorking->Append(buffer + place, end - place, width, fWorking->Append(buffer + place, end - place, width, fTheme,
fTheme, fore, back, font); fore, back, font);
} }
else { else {
float top(0.0); 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) { while ((url_offset = crunch.Crunch(&temp)) != B_ERROR) {
fWorking->Append(buffer + place, (url_offset - last_offset), fWorking->Append(buffer + place, (url_offset - last_offset),
width, fTheme, fore, back, font); width, fTheme, fore, back, font);
fWorking->Append(temp.String(), temp.Length(), fWorking->Append(temp.String(), temp.Length(), width, fTheme,
width, fTheme, C_URL, back, F_URL); ui_color(B_LINK_TEXT_COLOR), back, fore);
place += (url_offset - last_offset) + temp.Length(); place += (url_offset - last_offset) + temp.Length();
last_offset = url_offset + temp.Length(); last_offset = url_offset + temp.Length();
@ -1747,27 +1745,27 @@ void RunView::ScrollToSelection()
Line::Line(const char* buffer, int len, float top, float width, Theme* theme, 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), fText(NULL),
fStamp (time(NULL)), fStamp(time(NULL)),
fUrls (NULL), fUrls(NULL),
fSpaces (NULL), fSpaces(NULL),
fEdges (NULL), fEdges(NULL),
fFcs (NULL), fFcs(NULL),
fSofties (NULL), fSofties(NULL),
fTop (top), fTop(top),
fBottom (0.0), fBottom(0.0),
fLength (len), fLength(len),
fSpace_count (0), fSpace_count(0),
fEdge_count (0), fEdge_count(0),
fFc_count (0), fFc_count(0),
fSoftie_size (0), fSoftie_size(0),
fSoftie_used (0) fSoftie_used(0)
{ {
// Very important to call SetStamp before Append, It would look real funny otherwise! // Very important to call SetStamp before Append, It would look real funny otherwise!
SetStamp(stamp_format, false ); SetStamp(stamp_format, false );
Append(buffer, len, width, theme, fore, back, font ); Append(buffer, len, width, theme, fore, back, font);
} }
@ -1789,7 +1787,7 @@ Line::~Line()
void void
Line::Append(const char* buffer, int len, float width, Theme* theme, 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); int save (fLength);
char* new_fText; char* new_fText;
@ -1816,9 +1814,9 @@ Line::Append(const char* buffer, int len, float width, Theme* theme,
fText = new_fText; fText = new_fText;
FigureFontColors (save, fore, back, font); FigureFontColors(save, fore, back, font);
if (fore == C_URL) { if (fore == ui_color(B_LINK_TEXT_COLOR)) {
if (!fUrls) if (!fUrls)
fUrls = new urllist; fUrls = new urllist;
fUrls->AddItem (new URL (buffer, save, len)); fUrls->AddItem (new URL (buffer, save, len));
@ -1857,7 +1855,7 @@ Line::FigureSpaces()
void 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) { if (fFc_count) {
int last_fore = -1; int last_fore = -1;
@ -1867,56 +1865,51 @@ Line::FigureFontColors(int pos, int fore, int back, int font)
// we have fFcs, so we backtrack for last of each fWhich // we have fFcs, so we backtrack for last of each fWhich
for (i = fFc_count - 1; i >= 0; --i) { for (i = fFc_count - 1; i >= 0; --i) {
if (last_fore < 0 if (last_fore < 0 && fFcs[i].fWhich == FORE_WHICH)
&& fFcs[i].fWhich == FORE_WHICH)
last_fore = i; last_fore = i;
else if (last_back < 0 else if (last_back < 0 && fFcs[i].fWhich == BACK_WHICH)
&& fFcs[i].fWhich == BACK_WHICH)
last_back = i; last_back = i;
else if (last_font < 0 else if (last_font < 0 && fFcs[i].fWhich == FONT_WHICH)
&& fFcs[i].fWhich == FONT_WHICH)
last_font = i; last_font = i;
if (last_fore >= 0 if (last_fore >= 0 && last_back >= 0 && last_font >= 0)
&& last_back >= 0
&& last_font >= 0)
break; break;
} }
// now figure out how many more we need // now figure out how many more we need
int16 count = 0; int16 count = 0;
if (fFcs[last_fore].fIndex != fore) if (fFcs[last_fore].fColor != fore)
++count; ++count;
if (fFcs[last_back].fIndex != back) if (fFcs[last_back].fColor != back)
++count; ++count;
if (fFcs[last_font].fIndex != font) if (fFcs[last_font].fColor != font)
++count; ++count;
if (count) { if (count) {
FontColor* new_fFcs; FontColor* new_fFcs;
new_fFcs = new FontColor [fFc_count + count]; new_fFcs = new FontColor[fFc_count + count];
memcpy (new_fFcs, fFcs, fFc_count * sizeof (FontColor)); memcpy (new_fFcs, fFcs, fFc_count * sizeof (FontColor));
delete [] fFcs; delete [] fFcs;
fFcs = new_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].fWhich = FORE_WHICH;
fFcs[fFc_count].fOffset = pos; fFcs[fFc_count].fOffset = pos;
fFcs[fFc_count].fIndex = fore; fFcs[fFc_count].fColor = fore;
++fFc_count; ++fFc_count;
} }
if (fFcs[last_back].fIndex != back) { if (fFcs[last_back].fColor != back) {
fFcs[fFc_count].fWhich = BACK_WHICH; fFcs[fFc_count].fWhich = BACK_WHICH;
fFcs[fFc_count].fOffset = pos; fFcs[fFc_count].fOffset = pos;
fFcs[fFc_count].fIndex = back; fFcs[fFc_count].fColor = back;
++fFc_count; ++fFc_count;
} }
if (fFcs[last_font].fIndex != font) { if (fFcs[last_font].fColor != font) {
fFcs[fFc_count].fWhich = FONT_WHICH; fFcs[fFc_count].fWhich = FONT_WHICH;
fFcs[fFc_count].fOffset = pos; fFcs[fFc_count].fOffset = pos;
fFcs[fFc_count].fIndex = font; fFcs[fFc_count].fColor = font;
++fFc_count; ++fFc_count;
} }
} }
@ -1924,13 +1917,13 @@ Line::FigureFontColors(int pos, int fore, int back, int font)
fFcs = new FontColor [fFc_count = 3]; fFcs = new FontColor [fFc_count = 3];
fFcs[0].fWhich = FORE_WHICH; fFcs[0].fWhich = FORE_WHICH;
fFcs[0].fOffset = 0; fFcs[0].fOffset = 0;
fFcs[0].fIndex = fore; fFcs[0].fColor = fore;
fFcs[1].fWhich = BACK_WHICH; fFcs[1].fWhich = BACK_WHICH;
fFcs[1].fOffset = 0; fFcs[1].fOffset = 0;
fFcs[1].fIndex = back; fFcs[1].fColor = back;
fFcs[2].fWhich = FONT_WHICH; fFcs[2].fWhich = FONT_WHICH;
fFcs[2].fOffset = 0; 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; 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); TextRender* tr = theme->TextRenderAt (fFcs[cur_font].fIndex);
#ifdef __INTEL__ #ifdef __INTEL__

View File

@ -158,8 +158,8 @@ public:
virtual void MouseUp (BPoint); virtual void MouseUp (BPoint);
void Append (const char*, int32, int, int, int); void Append (const char*, int32, rgb_color, rgb_color, rgb_color);
void Append (const char*, int, int, int); void Append (const char*, rgb_color, rgb_color, rgb_color);
void Clear (void); void Clear (void);