Emoticor.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "Emoticor.h"
  2. #include <Resources.h>
  3. #include <Directory.h>
  4. #include <Path.h>
  5. #include "string.h"
  6. static Emoticor* fInstance = NULL;
  7. Emoticor*
  8. Emoticor::Get()
  9. {
  10. if (fInstance == NULL)
  11. fInstance = new Emoticor();
  12. return fInstance;
  13. }
  14. Emoticor::Emoticor()
  15. {
  16. fInstance = NULL;
  17. fConfig = NULL;
  18. }
  19. Emoticor::~Emoticor()
  20. {
  21. if (fConfig)
  22. delete fConfig;
  23. }
  24. Emoconfig*
  25. Emoticor::Config()
  26. {
  27. return fConfig;
  28. }
  29. void
  30. Emoticor::LoadConfig(const char* txt)
  31. {
  32. fConfig = new Emoconfig(txt);
  33. }
  34. void
  35. Emoticor::_findTokens(RunView* fTextView, BString text, int tokenstart,
  36. rgb_color cols, rgb_color font, rgb_color cols2,
  37. rgb_color font2)
  38. {
  39. //******************************************
  40. // "Iteration is human, recursion is divine"
  41. //******************************************
  42. int32 newindex = 0;
  43. BString cur;
  44. int i = tokenstart;
  45. if (fConfig != NULL) {
  46. while (fConfig->FindString("face", i, &cur) == B_OK)
  47. //for(int i=tokenstart;i<config->numfaces;i++)
  48. {
  49. i++;
  50. //if(config->FindString("face",i,&cur)!=B_OK) return;
  51. newindex = 0;
  52. while (true) {
  53. newindex = text.IFindFirst(cur.String(), 0);
  54. //printf("Try %d %s -- match %d\n",i,cur->original.String(),newindex);
  55. if (newindex != B_ERROR) {
  56. //take a walk on the left side ;)
  57. //printf("Found at %ld \n",newindex);
  58. if (newindex - 1 >= 0) {
  59. BString left;
  60. text.CopyInto(left, 0, newindex);
  61. //printf("ready to recourse! [%s]\n",left.String());
  62. _findTokens(fTextView, left, tokenstart + 1, cols, font, cols2, font2);
  63. }
  64. text.Remove(0, newindex + cur.Length());
  65. //printf("remaning [%s] printed [%s]\n",text.String(),cur->original.String());
  66. // fTextView->Append(cur.String(), cols2, cols2, font2);
  67. // TODO
  68. if (text.Length() == 0) return; //useless stack
  69. } else
  70. break;
  71. }
  72. }
  73. }
  74. // fTextView->Append(text.String(), cols, cols, font);
  75. // TODO
  76. }
  77. void
  78. Emoticor::AddText(RunView* fTextView, const char* txt, rgb_color cols,
  79. rgb_color font, rgb_color cols2, rgb_color font2)
  80. {
  81. BString left(txt);
  82. // if(!fConfig)
  83. // fTextView->Append(txt,cols,cols,font);
  84. _findTokens(fTextView, left, 0, cols, font, cols2, font2);
  85. return;
  86. }