2010-05-07 04:47:10 -05:00
|
|
|
#include "Emoticor.h"
|
|
|
|
#include <Resources.h>
|
|
|
|
#include <Directory.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#include "string.h"
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
static Emoticor* fInstance = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
Emoticor*
|
|
|
|
Emoticor::Get()
|
|
|
|
{
|
|
|
|
if (fInstance == NULL)
|
|
|
|
fInstance = new Emoticor();
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
return fInstance;
|
|
|
|
}
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
Emoticor::Emoticor()
|
|
|
|
{
|
|
|
|
fInstance = NULL;
|
|
|
|
fConfig = NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
Emoticor::~Emoticor()
|
|
|
|
{
|
|
|
|
if (fConfig)
|
|
|
|
delete fConfig;
|
|
|
|
}
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
Emoconfig*
|
2010-05-07 04:47:10 -05:00
|
|
|
Emoticor::Config()
|
|
|
|
{
|
|
|
|
return fConfig;
|
|
|
|
}
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
Emoticor::LoadConfig(const char* txt)
|
|
|
|
{
|
|
|
|
fConfig = new Emoconfig(txt);
|
|
|
|
}
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
2021-06-07 20:01:14 -05:00
|
|
|
Emoticor::_findTokens(RunView* fTextView, BString text, int tokenstart,
|
|
|
|
rgb_color cols, rgb_color font, rgb_color cols2,
|
|
|
|
rgb_color font2)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
//******************************************
|
|
|
|
// "Iteration is human, recursion is divine"
|
|
|
|
//******************************************
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
int32 newindex = 0;
|
|
|
|
BString cur;
|
|
|
|
int i = tokenstart;
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
if (fConfig != NULL) {
|
|
|
|
while (fConfig->FindString("face", i, &cur) == B_OK)
|
|
|
|
//for(int i=tokenstart;i<config->numfaces;i++)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
i++;
|
2010-05-07 04:47:10 -05:00
|
|
|
//if(config->FindString("face",i,&cur)!=B_OK) return;
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
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());
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
// fTextView->Append(cur.String(), cols2, cols2, font2);
|
|
|
|
// TODO
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
if (text.Length() == 0) return; //useless stack
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
// fTextView->Append(text.String(), cols, cols, font);
|
|
|
|
// TODO
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
2021-06-07 20:01:14 -05:00
|
|
|
Emoticor::AddText(RunView* fTextView, const char* txt, rgb_color cols,
|
|
|
|
rgb_color font, rgb_color cols2, rgb_color font2)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
BString left(txt);
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
// if(!fConfig)
|
|
|
|
// fTextView->Append(txt,cols,cols,font);
|
|
|
|
|
|
|
|
_findTokens(fTextView, left, 0, cols, font, cols2, font2);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-07 20:01:14 -05:00
|
|
|
|