Chat-O-Matic/libs/librunview/Emoticor.cpp
Jaidyn Ann 242d29c3a6 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.
2021-06-08 07:34:10 -05:00

125 lines
2.2 KiB
C++

#include "Emoticor.h"
#include <Resources.h>
#include <Directory.h>
#include <Path.h>
#include "string.h"
static Emoticor* fInstance = NULL;
Emoticor*
Emoticor::Get()
{
if (fInstance == NULL)
fInstance = new Emoticor();
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,
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;
if (fConfig != NULL) {
while (fConfig->FindString("face", i, &cur) == B_OK)
//for(int i=tokenstart;i<config->numfaces;i++)
{
i++;
//if(config->FindString("face",i,&cur)!=B_OK) return;
newindex = 0;
while (true) {
newindex = text.IFindFirst(cur.String(), 0);
//printf("Try %d %s -- match %d\n",i,cur->original.String(),newindex);
if (newindex != B_ERROR) {
//take a walk on the left side ;)
//printf("Found at %ld \n",newindex);
if (newindex - 1 >= 0) {
BString left;
text.CopyInto(left, 0, newindex);
//printf("ready to recourse! [%s]\n",left.String());
_findTokens(fTextView, left, tokenstart + 1, cols, font, cols2, font2);
}
text.Remove(0, newindex + cur.Length());
//printf("remaning [%s] printed [%s]\n",text.String(),cur->original.String());
// fTextView->Append(cur.String(), cols2, cols2, font2);
// TODO
if (text.Length() == 0) return; //useless stack
} else
break;
}
}
}
// fTextView->Append(text.String(), cols, cols, font);
// TODO
}
void
Emoticor::AddText(RunView* fTextView, const char* txt, rgb_color cols,
rgb_color font, rgb_color cols2, rgb_color font2)
{
BString left(txt);
// if(!fConfig)
// fTextView->Append(txt,cols,cols,font);
_findTokens(fTextView, left, 0, cols, font, cols2, font2);
return;
}