1
0

textbar.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //PORTABLE
  2. #ifndef _TEXTBAR_H
  3. #define _TEXTBAR_H
  4. #include <bfc/virtualwnd.h>
  5. #include <bfc/autobitmap.h>
  6. #include <bfc/textalign.h>
  7. class CheckWnd;
  8. #define TEXTBAR_PARENT VirtualWnd
  9. /**
  10. TextBar uses the BaseWnd name field of the object as the text
  11. to be displayed.
  12. @short TextBar control.
  13. @author Nullsoft
  14. @ver 1.0
  15. @see LabelWnd
  16. */
  17. class TextBar : public VirtualWnd {
  18. public:
  19. /**
  20. Sets the default flags of the TextBar. Defaults to 16px fonts,
  21. no background texture, left justified text, shadowed text in
  22. the bgcolor, no outline, not box around the text.
  23. */
  24. TextBar();
  25. /**
  26. Event is triggered when the window requires a repaint.
  27. Override this to implement your own behavior.
  28. Paints the bitmap on canvas according to current
  29. options (centering, tiling, stretching, title).
  30. @ret 0 for failure, 1 for success
  31. @param canvas The canvas on which to paint.
  32. */
  33. virtual int onPaint(Canvas *canvas);
  34. /**
  35. Event is triggered when the name of the window is changed.
  36. Override this to implement your own behavior.
  37. @see BaseWnd::setName()
  38. */
  39. virtual void onSetName();
  40. /**
  41. Set the text to be displayed to an ascii representation of a numeric value.
  42. @ret 1.
  43. @param i The numeric value to be displayed.
  44. */
  45. int setInt(int i);
  46. /**
  47. Set the size of the text for the textbar.
  48. @ret 1, success; 0, failure.
  49. @param newsize The new text size, range is from 1 to 72 pixels.
  50. */
  51. int setTextSize(int newsize);
  52. /**
  53. Get the width of the text displayed, in pixels.
  54. @ret Width of the displayed text (in pixels).
  55. */
  56. int getTextWidth();
  57. /**
  58. Get the height of the text displayed, in pixels.
  59. @ret Height of the displayed text.
  60. */
  61. int getTextHeight();
  62. /**
  63. Use the base texture when rendering the TextBar?
  64. If the base texture is used, it will be rendered as
  65. the background of the textbar.
  66. @param u !0, Use base texture; 0, Do not use base texture;
  67. */
  68. void setUseBaseTexture(int u);
  69. /**
  70. Event is triggered when the left mouse button is pressed while
  71. the textbar has focus. Override this to implement your
  72. own behavior.
  73. @param x X coordinate of the mouse pointer.
  74. @param y Y coordinate of the mouse pointer.
  75. */
  76. virtual int onLeftButtonDown(int x, int y);
  77. /**
  78. Center the text in the textbar? If not,
  79. it will be left justified by default.
  80. @param center !0, Center text; 0, Do not center text;
  81. */
  82. // void setCenter(int center); //old code
  83. /**
  84. Get the center text flag.
  85. @see setCenter()
  86. @ret TRUE, Text is being centered; FALSE, No centering (left justified);
  87. */
  88. // bool getCentered();
  89. /**
  90. Sets the alignment of the text to left, center, or right aligned
  91. (possibly more later on, not too sure yet)
  92. */
  93. void setAlign(TextAlign alignment);
  94. /**
  95. @ret returns the alignment of the text
  96. */
  97. TextAlign getAlign();
  98. // The following three options have ascending overriding priority --
  99. /**
  100. Sets the shadowed text flag. If enabled, the text will be shadowed
  101. with the "bgcolor" value.
  102. @see getTextShadowed()
  103. @param settextshadowed !0, Shadow the text; 0, Do not shadow the text;
  104. */
  105. void setTextShadowed(int settextshadowed) {
  106. textshadowed = !!settextshadowed;
  107. }
  108. /**
  109. Get the shadowed text flag. If enabled, the text will be shadowed
  110. with the "bgcolor" value.
  111. @see setTextShadowed()
  112. @ret !0, Shadow the text; 0, Do not shadow the text;
  113. */
  114. int getTextShadowed() {
  115. return textshadowed;
  116. }
  117. /**
  118. Sets the outline text flag. If enabled, the text will be
  119. outlined with the "bgcolor" value.
  120. @param settextoutlined !0, Outline the text; 0, Do not outline the text;
  121. */
  122. void setTextOutlined(int settextoutlined) {
  123. textoutlined = !!settextoutlined;
  124. }
  125. /**
  126. Get the outline text flag. If enabled, the text will be
  127. outlined with the "bgcolor" value.
  128. @ret !0, Outline the text; 0, Do not outline the text;
  129. */
  130. int getTextOutlined() {
  131. return textoutlined;
  132. }
  133. /**
  134. Set the drawbox flag. If true, the drawbox flag will cause
  135. a box to be drawn around the text in the textbar.
  136. @param setdrawbox !0, Drawbox around the text; 0, No drawbox;
  137. */
  138. void setDrawBox(int setdrawbox) {
  139. drawbox = !!setdrawbox;
  140. }
  141. /**
  142. Get the drawbox flag. If true, the drawbox flag will cause
  143. a box to be drawn around the text in the textbar.
  144. @ret !0, Drawbox around the text; 0, No drawbox;
  145. */
  146. int getDrawBox() {
  147. return drawbox;
  148. }
  149. /**
  150. Associate a checkbox with the textbar. When a textbar is linked
  151. to a checkbox, it will toggle the checkbox when it receives
  152. left clicks.
  153. @param target A pointer to the CheckWnd to link.
  154. */
  155. void setAutoToggleCheckWnd(CheckWnd *target) {
  156. checkwndtarget = target;
  157. }
  158. private:
  159. int size;
  160. int usebt;
  161. TextAlign alignment; //i changed this from centered, to a set text alignment thingie
  162. int textshadowed; // display a shadow of the text in bgcolor. default: on
  163. int textoutlined; // draw an outline of the text in bgcolor. default: off
  164. int drawbox; // draw a box of bgcolor the size of the boundsrect. default: off
  165. AutoSkinBitmap bgbitmap;
  166. CheckWnd *checkwndtarget;
  167. };
  168. const int TEXTBAR_LEFTMARGIN = 2;
  169. #endif