Fl_Color_Chooser.H 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // "$Id: Fl_Color_Chooser.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  3. //
  4. // Color chooser header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /** \file
  19. Fl_Color_Chooser widget . */
  20. // The color chooser object and the color chooser popup. The popup
  21. // is just a window containing a single color chooser and some boxes
  22. // to indicate the current and cancelled color.
  23. #ifndef Fl_Color_Chooser_H
  24. #define Fl_Color_Chooser_H
  25. #include <FL/Fl_Group.H>
  26. #include <FL/Fl_Box.H>
  27. #include <FL/Fl_Return_Button.H>
  28. #include <FL/Fl_Choice.H>
  29. #include <FL/Fl_Value_Input.H>
  30. #ifndef FL_DOXYGEN
  31. /** For internal use only */
  32. class FL_EXPORT Flcc_HueBox : public Fl_Widget {
  33. int px, py;
  34. protected:
  35. void draw();
  36. int handle_key(int);
  37. public:
  38. int handle(int);
  39. Flcc_HueBox(int X, int Y, int W, int H) : Fl_Widget(X,Y,W,H) {
  40. px = py = 0;}
  41. DECLARE_CLASS_CHEAP_RTTI_2(Flcc_HueBox, Fl_Widget)
  42. };
  43. /** For internal use only */
  44. class FL_EXPORT Flcc_ValueBox : public Fl_Widget {
  45. int py;
  46. protected:
  47. void draw();
  48. int handle_key(int);
  49. public:
  50. int handle(int);
  51. Flcc_ValueBox(int X, int Y, int W, int H) : Fl_Widget(X,Y,W,H) {
  52. py = 0;}
  53. DECLARE_CLASS_CHEAP_RTTI_2(Flcc_ValueBox, Fl_Widget)
  54. };
  55. /** For internal use only */
  56. class FL_EXPORT Flcc_Value_Input : public Fl_Value_Input {
  57. public:
  58. int format(char*);
  59. Flcc_Value_Input(int X, int Y, int W, int H) : Fl_Value_Input(X,Y,W,H) {}
  60. DECLARE_CLASS_CHEAP_RTTI_2(Flcc_Value_Input, Fl_Value_Input)
  61. };
  62. #endif // !FL_DOXYGEN
  63. /** \addtogroup group_comdlg
  64. @{ */
  65. /**
  66. \class Fl_Color_Chooser
  67. \brief The Fl_Color_Chooser widget provides a standard RGB color chooser.
  68. \image html fl_color_chooser.jpg
  69. \image latex fl_color_chooser.jpg "fl_color_chooser()" width=5cm
  70. You can place any number of the widgets into a panel of your own design.
  71. The diagram shows the widget as part of a color chooser dialog created by
  72. the fl_color_chooser() function. The Fl_Color_Chooser widget contains the
  73. hue box, value slider, and rgb input fields from the above diagram (it
  74. does not have the color chips or the Cancel or OK buttons).
  75. The callback is done every time the user changes the rgb value. It is not
  76. done if they move the hue control in a way that produces the \e same rgb
  77. value, such as when saturation or value is zero.
  78. The fl_color_chooser() function pops up a window to let the user pick an
  79. arbitrary RGB color. They can pick the hue and saturation in the "hue box"
  80. on the left (hold down CTRL to just change the saturation), and the
  81. brightness using the vertical slider. Or they can type the 8-bit numbers
  82. into the RGB Fl_Value_Input fields, or drag the mouse across them to adjust
  83. them. The pull-down menu lets the user set the input fields to show RGB,
  84. HSV, or 8-bit RGB (0 to 255).
  85. fl_color_chooser() returns non-zero if the user picks ok, and updates the
  86. RGB values. If the user picks cancel or closes the window this returns
  87. zero and leaves RGB unchanged.
  88. If you use the color chooser on an 8-bit screen, it will allocate all the
  89. available colors, leaving you no space to exactly represent the color the
  90. user picks! You can however use fl_rectf() to fill a region with a simulated
  91. color using dithering.
  92. */
  93. /** @} */
  94. class FL_EXPORT Fl_Color_Chooser : public Fl_Group {
  95. Flcc_HueBox huebox;
  96. Flcc_ValueBox valuebox;
  97. Fl_Choice choice;
  98. Flcc_Value_Input rvalue;
  99. Flcc_Value_Input gvalue;
  100. Flcc_Value_Input bvalue;
  101. Fl_Box resize_box;
  102. double hue_, saturation_, value_;
  103. double r_, g_, b_;
  104. void set_valuators();
  105. static void rgb_cb(Fl_Widget*, void*);
  106. static void mode_cb(Fl_Widget*, void*);
  107. public:
  108. /**
  109. Returns which Fl_Color_Chooser variant is currently active
  110. \return color modes are rgb(0), byte(1), hex(2), or hsv(3)
  111. */
  112. int mode() {return choice.value();}
  113. /**
  114. Set which Fl_Color_Chooser variant is currently active
  115. \param[in] newMode color modes are rgb(0), byte(1), hex(2), or hsv(3)
  116. */
  117. void mode(int newMode);
  118. /**
  119. Returns the current hue.
  120. 0 <= hue < 6. Zero is red, one is yellow, two is green, etc.
  121. <em>This value is convenient for the internal calculations - some other
  122. systems consider hue to run from zero to one, or from 0 to 360.</em>
  123. */
  124. double hue() const {return hue_;}
  125. /**
  126. Returns the saturation.
  127. 0 <= saturation <= 1.
  128. */
  129. double saturation() const {return saturation_;}
  130. /**
  131. Returns the value/brightness.
  132. 0 <= value <= 1.
  133. */
  134. double value() const {return value_;}
  135. /**
  136. Returns the current red value.
  137. 0 <= r <= 1.
  138. */
  139. double r() const {return r_;}
  140. /**
  141. Returns the current green value.
  142. 0 <= g <= 1.
  143. */
  144. double g() const {return g_;}
  145. /**
  146. Returns the current blue value.
  147. 0 <= b <= 1.
  148. */
  149. double b() const {return b_;}
  150. int hsv(double H, double S, double V);
  151. int rgb(double R, double G, double B);
  152. static void hsv2rgb(double H, double S, double V, double& R, double& G, double& B);
  153. static void rgb2hsv(double R, double G, double B, double& H, double& S, double& V);
  154. Fl_Color_Chooser(int X, int Y, int W, int H, const char *L = 0);
  155. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Color_Chooser, Fl_Group)
  156. };
  157. FL_EXPORT int fl_color_chooser(const char* name, double& r, double& g, double& b, int m=-1);
  158. FL_EXPORT int fl_color_chooser(const char* name, uchar& r, uchar& g, uchar& b, int m=-1);
  159. #endif
  160. //
  161. // End of "$Id: Fl_Color_Chooser.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
  162. //