123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #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;
- }
|