tb_atomic_widgets.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. #include "tb_window.h"
  34. #define UIPROMPTMESSAGEID 1
  35. #define UIPROMPTEDITID 2
  36. #define UIFINDEREDITPATHID 1
  37. #define UIFINDERUPBUTTONID 2
  38. #define UIFINDERBOOKBUTTONID 3
  39. #define UIFINDERFOLDERBUTTONID 4
  40. #define UIFINDERBOOKLISTID 5
  41. #define UIFINDERFILELISTID 6
  42. #define UIFINDEREDITFILEID 7
  43. #define UIFINDEROKBUTTONID 8
  44. #define UIFINDERCANCELBUTTONID 9
  45. namespace tb {
  46. // fruxo recommends : Subclass TBWidget and override OnPaint. From
  47. // there you can paint solid colors using g_tb_skin->PaintRectFill.
  48. class TBColorWidget : public TBWidget
  49. {
  50. public:
  51. TBOBJECT_SUBCLASS(TBColorWidget, TBWidget); // For safe typecasting
  52. TBColorWidget();
  53. void SetColor ( const char * );
  54. void SetColor (float r, float g, float b, float a);
  55. void SetAlpha ( float );
  56. const TBColor& GetColor() const { return color_; }
  57. float GetAlpha() const { return alpha_; }
  58. virtual void OnInflate(const INFLATE_INFO &info);
  59. virtual void OnPaint(const PaintProps &paint_props);
  60. private:
  61. TBColor color_;
  62. float alpha_;
  63. };
  64. class TBColorWheel : public TBWidget
  65. {
  66. public:
  67. TBOBJECT_SUBCLASS(TBColorWheel, TBWidget); // For safe typecasting
  68. TBColorWheel();
  69. virtual void OnInflate(const INFLATE_INFO &info);
  70. virtual void OnPaint(const PaintProps &paint_props);
  71. virtual bool OnEvent(const TBWidgetEvent &ev);
  72. float GetHue() const { return hue_; }
  73. float GetSaturation() const { return saturation_; }
  74. void SetHueSaturation ( float hue, float saturation );
  75. void SetMarkerX ( int );
  76. void SetMarkerY( int );
  77. void SetMarkerColor ( const char * );
  78. private:
  79. void CalcHueSaturation ( int, int ); // maths.
  80. int markerx_;
  81. int markery_; // where we clicked, put a box there
  82. TBColor markercolor_; // what color box, default = black
  83. float hue_; // varies with the angle
  84. float saturation_; // varies with the radius.
  85. };
  86. class TBEventBlocker : public TBWidgetListener
  87. {
  88. public:
  89. TBEventBlocker() : TBWidgetListener() { }
  90. /** Called when a event is about to be invoked on a widget. This make it possible
  91. to intercept events before they are handled, and block it (by returning true --like here ).
  92. Note, if returning true, other global listeners will still also be notified. */
  93. virtual bool OnWidgetInvokeEvent(TBWidget *widget, const TBWidgetEvent &ev) { return true; }
  94. };
  95. /// TBBarGraph a simple bargraph, plots 0.0 to 100.0 in the selected color
  96. class TBBarGraph : public TBWidget
  97. {
  98. public:
  99. TBOBJECT_SUBCLASS(TBBarGraph, TBWidget); // For safe typecasting
  100. TBBarGraph();
  101. void SetColor ( const char * );
  102. void SetColor (float r, float g, float b, float a);
  103. const TBColor& GetColor() const { return color_; }
  104. virtual void OnInflate(const INFLATE_INFO &info);
  105. virtual void OnPaint(const PaintProps &paint_props);
  106. virtual void SetValueDouble(double value);
  107. virtual double GetValueDouble() { return m_value; }
  108. virtual void SetValue(int value) { SetValueDouble(value); }
  109. virtual int GetValue() { return (int) GetValueDouble(); }
  110. virtual void SetAxis(AXIS axis);
  111. virtual AXIS GetAxis() const { return m_axis; }
  112. virtual void SetMargin(unsigned margin) { m_margin = margin; }
  113. virtual unsigned GetMargin() const { return m_margin; }
  114. private:
  115. TBColor color_;
  116. double m_value;
  117. AXIS m_axis;
  118. unsigned m_margin;
  119. };
  120. /** TBPromptWindow is a window for requesting a string. */
  121. class TBPromptWindow : public TBWindow, private TBWidgetListener
  122. {
  123. public:
  124. // For safe typecasting
  125. TBOBJECT_SUBCLASS(TBPromptWindow, TBWindow);
  126. TBPromptWindow(TBWidget *target, TBID id);
  127. virtual ~TBPromptWindow();
  128. bool Show(const char *title, const char *message,
  129. const char *preset = nullptr, int dimmer = 0,
  130. int width = 0, int height = 0);
  131. virtual TBWidget *GetEventDestination() { return m_target.Get(); }
  132. virtual bool OnEvent(const TBWidgetEvent &ev);
  133. virtual void OnDie();
  134. private:
  135. // TBWidgetListener
  136. virtual void OnWidgetDelete(TBWidget *widget);
  137. virtual bool OnWidgetDying(TBWidget *widget);
  138. TBWidgetSafePointer m_dimmer;
  139. TBWidgetSafePointer m_target;
  140. };
  141. // file, path finder
  142. class TBFinderWindow : public TBWindow, private TBWidgetListener
  143. {
  144. public:
  145. // For safe typecasting
  146. TBOBJECT_SUBCLASS(TBFinderWindow, TBWindow);
  147. TBFinderWindow(TBWidget *target, TBID id);
  148. virtual ~TBFinderWindow();
  149. bool Show(const char *title,
  150. const char *preset = nullptr, int dimmer = 0,
  151. int width = 0, int height = 0);
  152. virtual TBWidget *GetEventDestination() { return m_target.Get(); }
  153. virtual bool OnEvent(const TBWidgetEvent &ev);
  154. virtual void OnDie();
  155. private:
  156. // TBWidgetListener
  157. virtual void OnWidgetDelete(TBWidget *widget);
  158. virtual bool OnWidgetDying(TBWidget *widget);
  159. TBWidget *FindParentList( TBWidget *widget); // utility for dealing with menus.
  160. TBWidgetSafePointer m_dimmer;
  161. TBWidgetSafePointer m_target;
  162. TBWidget *rightMenuParent; // information for context menus
  163. TBWidget *rightMenuChild;
  164. };
  165. }; // namespace tb
  166. #endif // TB_ATOMIC_WIDGETS_H