tb_style_edit_content.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_STYLE_EDIT_CONTENT_H
  6. #define TB_STYLE_EDIT_CONTENT_H
  7. #include "tb_core.h"
  8. namespace tb {
  9. class TBTextFragment;
  10. /** Content for a non-text TBTextFragment. */
  11. class TBTextFragmentContent
  12. {
  13. public:
  14. virtual ~TBTextFragmentContent() {}
  15. /** Update the position of the content, relative to the first line of text (no scrolling applied). */
  16. virtual void UpdatePos(int x, int y) {}
  17. virtual void Paint(TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props) {}
  18. virtual void Click(TBTextFragment *fragment, int button, uint32 modifierkeys) {}
  19. virtual int32 GetWidth(TBFontFace *font, TBTextFragment *fragment) { return 0; }
  20. virtual int32 GetHeight(TBFontFace *font, TBTextFragment *fragment) { return 0; }
  21. virtual int32 GetBaseline(TBFontFace *font, TBTextFragment *fragment) { return GetHeight(font, fragment); }
  22. virtual bool GetAllowBreakBefore() { return true; }
  23. virtual bool GetAllowBreakAfter() { return true; }
  24. /** Get type of fragment content. All standard fragments return 0. */
  25. virtual uint32 GetType() { return 0; }
  26. };
  27. /** A horizontal line for TBStyleEdit. */
  28. class TBTextFragmentContentHR : public TBTextFragmentContent
  29. {
  30. public:
  31. TBTextFragmentContentHR(int32 width_in_percent, int32 height);
  32. virtual void Paint(TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props);
  33. virtual int32 GetWidth(TBFontFace *font, TBTextFragment *fragment);
  34. virtual int32 GetHeight(TBFontFace *font, TBTextFragment *fragment);
  35. private:
  36. int32 width_in_percent, height;
  37. };
  38. /** Fragment content that enables underline in a TBStyleEdit */
  39. class TBTextFragmentContentUnderline : public TBTextFragmentContent
  40. {
  41. public:
  42. TBTextFragmentContentUnderline() {}
  43. virtual void Paint(TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props);
  44. virtual bool GetAllowBreakBefore() { return true; }
  45. virtual bool GetAllowBreakAfter() { return false; }
  46. };
  47. /** Fragment content that changes color in a TBStyleEdit */
  48. class TBTextFragmentContentTextColor : public TBTextFragmentContent
  49. {
  50. public:
  51. TBColor color;
  52. TBTextFragmentContentTextColor(const TBColor &color) : color(color) {}
  53. virtual void Paint(TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props);
  54. virtual bool GetAllowBreakBefore() { return true; }
  55. virtual bool GetAllowBreakAfter() { return false; }
  56. };
  57. /** Fragment content that ends a change of style in a TBStyleEdit */
  58. class TBTextFragmentContentStylePop : public TBTextFragmentContent
  59. {
  60. public:
  61. virtual void Paint(TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props);
  62. virtual bool GetAllowBreakBefore() { return false; }
  63. virtual bool GetAllowBreakAfter() { return true; }
  64. };
  65. }; // namespace tb
  66. #endif // TB_STYLE_EDIT_CONTENT_H