gcsx_color.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* GCSx
  2. ** COLOR.H
  3. **
  4. ** Color conversion and selection widget
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_COLOR_H_
  24. #define __GCSx_COLOR_H_
  25. // Color structure
  26. class color {
  27. private:
  28. float H; // 0.0 to 1.0
  29. float S; // 0.0 to 1.0
  30. float L; // 0.0 to 1.0
  31. public:
  32. int max;
  33. int maxAlpha;
  34. int R; // 0 to max
  35. int G; // 0 to max
  36. int B; // 0 to max
  37. int Hi; // 0 to 255
  38. int Si; // 0 to 255
  39. int Li; // 0 to 255
  40. int A; // 0 to max independant of all other items
  41. // Call one of these whenever you change rgb or hsl
  42. void RGBtoHSL();
  43. void HSLtoRGB();
  44. };
  45. // RGBHSL selection widget
  46. class WRGBSelect : public Widget {
  47. private:
  48. enum {
  49. // Border
  50. WRGBSELECT_BORDER = 1,
  51. // Gutter between xy and z panels, in addition to borders
  52. WRGBSELECT_GUTTER = 8,
  53. // Width of z panel
  54. WRGBSELECT_ZWIDTH = 15,
  55. // XY panel cursor- thickness and length of each crosshair
  56. WRGBSELECT_CURSOR_THICK = 3,
  57. WRGBSELECT_CURSOR_LENGTH = 8,
  58. };
  59. int maxComponent;
  60. // x/y and z areas
  61. SDL_Surface* xyPanel;
  62. SDL_Surface* zPanel;
  63. // Partial dirties
  64. int dirtyXY;
  65. int dirtyZ;
  66. color currentColor;
  67. // What makes up each axis
  68. int aX;
  69. int aY;
  70. int aZ;
  71. // (axises flipped?)
  72. int fX;
  73. int fY;
  74. int fZ;
  75. // Does Z depend on XY? (if not, XY depends on Z)
  76. int dependXYtoZ;
  77. // (actual pixel location)
  78. int xSelected;
  79. int ySelected;
  80. int zSelected;
  81. int innerWidth;
  82. int innerHeight;
  83. int zPanelX;
  84. enum {
  85. WRGBSELECT_DRAG_NONE = 0,
  86. WRGBSELECT_DRAG_XY,
  87. WRGBSELECT_DRAG_Z,
  88. } dragMode;
  89. void locateColor(int fullredraw = 0);
  90. void redrawXYPanel();
  91. void redrawZPanel();
  92. static int* convertAxis(color* src, int axis);
  93. static int convertMax(const color* src, int axis);
  94. void displayCursor(SDL_Surface* destSurface, int xCenter, int yCenter);
  95. // (actual pixel location)
  96. void setXY(int newX, int newY);
  97. void setZ(int newZ);
  98. public:
  99. // w/h of primary selection area; actual w/h may differ
  100. WRGBSelect(int wId, int w, int h, color* wSetting, int rgbBitDepth);
  101. ~WRGBSelect();
  102. // Set the X, Y, and Z (slider) axis
  103. // Must be either r/g/b in any order or h/s/l in any order
  104. enum {
  105. AXIS_R = 1,
  106. AXIS_G,
  107. AXIS_B,
  108. AXIS_H,
  109. AXIS_S,
  110. AXIS_L
  111. };
  112. void setMode(int axisX, int axisY, int axisZ, int flipX, int flipY, int flipZ, int setDependXYtoZ = 1);
  113. int event(int hasFocus, const SDL_Event* event);
  114. void load();
  115. void apply();
  116. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  117. void resolutionChange(int fromW, int fromH, int fromBpp, int toW, int toH, int toBpp);
  118. };
  119. // Color display widget
  120. class WShowColor : public Widget {
  121. private:
  122. enum {
  123. // Border
  124. SHOWCOLOR_BORDER = 1,
  125. };
  126. color currentColor;
  127. public:
  128. WShowColor(int wId, int w, int h, color* wSetting);
  129. ~WShowColor();
  130. int event(int hasFocus, const SDL_Event* event);
  131. int refuseAll() const;
  132. void load();
  133. void apply();
  134. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  135. };
  136. // RGB selection dialog
  137. class RGBSelect : public Dialog {
  138. private:
  139. int initializedH; // The window height we initialized for
  140. color theColor;
  141. int rgbBitDepth;
  142. int alphaBitDepth;
  143. int method;
  144. enum {
  145. // Demo color
  146. ID_DEMOCOLOR,
  147. // Change RGB/HSL method; these IDs must all be in this order
  148. ID_METHOD,
  149. ID_METHOD_HS,
  150. ID_METHOD_LH,
  151. ID_METHOD_SL,
  152. ID_METHOD_RG,
  153. ID_METHOD_GB,
  154. ID_METHOD_BR,
  155. // RGB/HSL selector
  156. ID_RGBSELECT,
  157. // RGBRGB HSLHSL Must be here and in this numerical order
  158. ID_R_N,
  159. ID_G_N,
  160. ID_B_N,
  161. ID_R_S,
  162. ID_G_S,
  163. ID_B_S,
  164. ID_H_N,
  165. ID_S_N,
  166. ID_L_N,
  167. ID_H_S,
  168. ID_S_S,
  169. ID_L_S,
  170. ID_A_N,
  171. ID_A_S,
  172. // Labels
  173. ID_R_LABEL,
  174. ID_G_LABEL,
  175. ID_B_LABEL,
  176. ID_H_LABEL,
  177. ID_S_LABEL,
  178. ID_L_LABEL,
  179. ID_A_LABEL,
  180. ID_OK,
  181. ID_CANCEL,
  182. };
  183. void applyRGBMethod();
  184. SDL_Surface* iconSurface;
  185. static const std::string resourceError;
  186. static class RGBSelect* dialog;
  187. public:
  188. RGBSelect();
  189. static class RGBSelect* create();
  190. static void destroy();
  191. void childModified(Window* modified);
  192. // Returns true if OK (false if cancelled)
  193. int run(unsigned char& r, unsigned char& g, unsigned char& b, unsigned char& a, int bitDepthAlpha = 8, int bitDepth = 8);
  194. };
  195. #endif