1
0

textbar.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "precomp.h"
  2. #include "textbar.h"
  3. #include <bfc/ifc_canvas.h>
  4. #include <bfc/string/string.h>
  5. #include <bfc/skinclr.h>
  6. #include <bfc/autobitmap.h>
  7. #include <common/checkwnd.h>
  8. static SkinColor bgcolor("wasabi.textBar.background", "Text backgrounds");
  9. static SkinColor fgcolor("wasabi.textBar.text");
  10. TextBar::TextBar() {
  11. size = 16;
  12. usebt = 0;
  13. alignment = TEXTALIGN_LEFT; //set default alignment
  14. checkwndtarget = NULL;
  15. textshadowed = 1; // display a shadow of the text in bgcolor. default: on
  16. textoutlined = 0; // draw an outline of the text in bgcolor. default: off
  17. drawbox = 0; // draw a box of bgcolor the size of the boundsrect. default: off
  18. // bgbitmap = "studio.textBar.background";
  19. }
  20. int TextBar::onLeftButtonDown(int x, int y) {
  21. TEXTBAR_PARENT::onLeftButtonDown(x, y);
  22. if (checkwndtarget) checkwndtarget->toggle();
  23. return 1;
  24. }
  25. void TextBar::setUseBaseTexture(int u) {
  26. usebt = u;
  27. invalidate();
  28. }
  29. int TextBar::onPaint(Canvas *canvas) {
  30. RECT r;
  31. PaintCanvas paintcanvas;
  32. if (canvas == NULL) {
  33. if (!paintcanvas.beginPaint(this)) return 0;
  34. canvas = &paintcanvas;
  35. }
  36. TEXTBAR_PARENT::onPaint(canvas);
  37. getClientRect(&r);
  38. if (!usebt) {
  39. if (drawbox) {
  40. canvas->fillRect(&r, bgcolor);
  41. }
  42. /*
  43. if (bgbitmap.getBitmap()->isInvalid())
  44. canvas->fillRect(&r, bgcolor);
  45. else {
  46. RECT br;
  47. br.left = 0;
  48. br.top = 0;
  49. br.right = bgbitmap.getWidth();
  50. br.bottom = bgbitmap.getHeight();
  51. bgbitmap.getBitmap()->blitToRect(canvas, &br, &r, 255);
  52. }
  53. */
  54. } else
  55. renderBaseTexture(canvas, r);
  56. const char *name = getName();
  57. if (name != NULL) {
  58. canvas->setTextOpaque(FALSE);
  59. canvas->pushTextSize(size);
  60. int w, h;
  61. canvas->getTextExtent(name, &w, &h);
  62. int y = (r.bottom-r.top - h) / 2;
  63. // int x = centered ? (r.right-r.left - w) / 2 : TEXTBAR_LEFTMARGIN; //teh old code
  64. int x = 0;
  65. switch (alignment) {
  66. default:
  67. case TEXTALIGN_LEFT: x = TEXTBAR_LEFTMARGIN; break;
  68. case TEXTALIGN_CENTER: x = (r.right-r.left - w) / 2; break;
  69. case TEXTALIGN_RIGHT: x = (r.right-r.left - w); break;
  70. }
  71. if (!drawbox && textoutlined) {
  72. canvas->setTextColor(bgcolor);
  73. canvas->textOut(r.left+x+1, r.top+y+1, getName());
  74. canvas->setTextColor(bgcolor);
  75. canvas->textOut(r.left+x+1, r.top+y-1, getName());
  76. canvas->setTextColor(bgcolor);
  77. canvas->textOut(r.left+x-1, r.top+y+1, getName());
  78. canvas->setTextColor(bgcolor);
  79. canvas->textOut(r.left+x-1, r.top+y-1, getName());
  80. } else if (!drawbox && textshadowed) {
  81. canvas->setTextColor(bgcolor);
  82. canvas->textOut(r.left+x+1, r.top+y+1, getName());
  83. }
  84. canvas->setTextColor(fgcolor);
  85. canvas->textOut(r.left+x, r.top+y, getName());
  86. canvas->popTextSize();
  87. }
  88. return 1;
  89. }
  90. int TextBar::setTextSize(int newsize) {
  91. if (newsize < 1 || newsize > 72) return 0;
  92. size = newsize;
  93. invalidate();
  94. return 1;
  95. }
  96. int TextBar::setInt(int i) {
  97. setName(StringPrintf(i));
  98. invalidate();
  99. return 1;
  100. }
  101. void TextBar::onSetName() {
  102. TEXTBAR_PARENT::onSetName();
  103. invalidate();
  104. }
  105. int TextBar::getTextWidth() {
  106. if (!getName()) return 0;
  107. BltCanvas *c = new BltCanvas(10, 10);
  108. c->pushTextSize(size);
  109. int r = c->getTextWidth(getName());
  110. c->popTextSize();
  111. delete c;
  112. return r+4;
  113. }
  114. int TextBar::getTextHeight() {
  115. return size;
  116. }
  117. void TextBar::setAlign(TextAlign align) {
  118. if (alignment != align) {
  119. alignment = align;
  120. invalidate();
  121. }
  122. }
  123. TextAlign TextBar::getAlign() {
  124. return alignment;
  125. }