You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.0KB

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