tb_atomic_widgets.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. //
  6. // Copyright (c) 2016, THUNDERBEAST GAMES LLC All rights reserved
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in
  16. // all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. //
  26. #ifndef TB_ATOMIC_WIDGETS_H
  27. #define TB_ATOMIC_WIDGETS_H
  28. #include "tb_widgets.h"
  29. #include "tb_layout.h"
  30. #include "tb_msg.h"
  31. #include "tb_widgets_listener.h"
  32. #include "tb_widgets_common.h"
  33. namespace tb {
  34. // fruxo recommends : Subclass TBWidget and override OnPaint. From
  35. // there you can paint solid colors using g_tb_skin->PaintRectFill.
  36. class TBColorWidget : public TBWidget
  37. {
  38. public:
  39. TBOBJECT_SUBCLASS(TBColorWidget, TBWidget); // For safe typecasting
  40. TBColorWidget();
  41. void SetColor ( const char * );
  42. void SetColor (float r, float g, float b, float a);
  43. void SetAlpha ( float );
  44. const TBColor& GetColor() const { return color_; }
  45. float GetAlpha() const { return alpha_; }
  46. virtual void OnInflate(const INFLATE_INFO &info);
  47. virtual void OnPaint(const PaintProps &paint_props);
  48. private:
  49. TBColor color_;
  50. float alpha_;
  51. };
  52. class TBColorWheel : public TBWidget
  53. {
  54. public:
  55. TBOBJECT_SUBCLASS(TBColorWheel, TBWidget); // For safe typecasting
  56. TBColorWheel();
  57. virtual void OnInflate(const INFLATE_INFO &info);
  58. virtual void OnPaint(const PaintProps &paint_props);
  59. virtual bool OnEvent(const TBWidgetEvent &ev);
  60. float GetHue() const { return hue_; }
  61. float GetSaturation() const { return saturation_; }
  62. void SetHueSaturation ( float hue, float saturation );
  63. void SetMarkerX ( int );
  64. void SetMarkerY( int );
  65. void SetMarkerColor ( const char * );
  66. private:
  67. void CalcHueSaturation ( int, int ); // maths.
  68. int markerx_;
  69. int markery_; // where we clicked, put a box there
  70. TBColor markercolor_; // what color box, default = black
  71. float hue_; // varies with the angle
  72. float saturation_; // varies with the radius.
  73. };
  74. class TBEventBlocker : public TBWidgetListener
  75. {
  76. public:
  77. TBEventBlocker() : TBWidgetListener() { }
  78. /** Called when a event is about to be invoked on a widget. This make it possible
  79. to intercept events before they are handled, and block it (by returning true --like here ).
  80. Note, if returning true, other global listeners will still also be notified. */
  81. virtual bool OnWidgetInvokeEvent(TBWidget *widget, const TBWidgetEvent &ev) { return true; }
  82. };
  83. /// TBBarGraph a simple bargraph, plots 0.0 to 100.0 in the selected color
  84. class TBBarGraph : public TBWidget
  85. {
  86. public:
  87. TBOBJECT_SUBCLASS(TBBarGraph, TBWidget); // For safe typecasting
  88. TBBarGraph();
  89. void SetColor ( const char * );
  90. void SetColor (float r, float g, float b, float a);
  91. const TBColor& GetColor() const { return color_; }
  92. virtual void OnInflate(const INFLATE_INFO &info);
  93. virtual void OnPaint(const PaintProps &paint_props);
  94. virtual void SetValueDouble(double value);
  95. virtual double GetValueDouble() { return m_value; }
  96. virtual void SetValue(int value) { SetValueDouble(value); }
  97. virtual int GetValue() { return (int) GetValueDouble(); }
  98. virtual void SetAxis(AXIS axis);
  99. virtual AXIS GetAxis() const { return m_axis; }
  100. virtual void SetMargin(unsigned margin) { m_margin = margin; }
  101. virtual unsigned GetMargin() const { return m_margin; }
  102. private:
  103. TBColor color_;
  104. double m_value;
  105. AXIS m_axis;
  106. unsigned m_margin;
  107. };
  108. }; // namespace tb
  109. #endif // TB_ATOMIC_WIDGETS_H