tb_atomic_widgets.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. virtual void SetColor ( const char * );
  42. virtual void SetAlpha ( float );
  43. virtual void OnInflate(const INFLATE_INFO &info);
  44. virtual void OnPaint(const PaintProps &paint_props);
  45. private:
  46. TBColor color_;
  47. float alpha_;
  48. };
  49. class TBColorWheel : public TBWidget
  50. {
  51. public:
  52. TBOBJECT_SUBCLASS(TBColorWheel, TBWidget); // For safe typecasting
  53. TBColorWheel();
  54. virtual void OnInflate(const INFLATE_INFO &info);
  55. virtual void OnPaint(const PaintProps &paint_props);
  56. virtual bool OnEvent(const TBWidgetEvent &ev);
  57. float GetHue() const { return hue_; }
  58. float GetSaturation() const { return saturation_; }
  59. void SetHueSaturation ( float hue, float saturation );
  60. void SetMarkerX ( int );
  61. void SetMarkerY( int );
  62. void SetMarkerColor ( const char * );
  63. private:
  64. void CalcHueSaturation ( int, int ); // maths.
  65. int markerx_;
  66. int markery_; // where we clicked, put a box there
  67. TBColor markercolor_; // what color box, default = black
  68. float hue_; // varies with the angle
  69. float saturation_; // varies with the radius.
  70. };
  71. class TBEventBlocker : public TBWidgetListener
  72. {
  73. public:
  74. TBEventBlocker() : TBWidgetListener() { }
  75. /** Called when a event is about to be invoked on a widget. This make it possible
  76. to intercept events before they are handled, and block it (by returning true --like here ).
  77. Note, if returning true, other global listeners will still also be notified. */
  78. virtual bool OnWidgetInvokeEvent(TBWidget *widget, const TBWidgetEvent &ev) { return true; }
  79. };
  80. }; // namespace tb
  81. #endif // TB_ATOMIC_WIDGETS_H