gcsx_colorselect.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* GCSx
  2. ** COLORSELECT.H
  3. **
  4. ** Color selection toolbar
  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_COLORSELECT_H_
  24. #define __GCSx_COLORSELECT_H_
  25. struct ColorStore {
  26. struct {
  27. Uint8 r;
  28. Uint8 g;
  29. Uint8 b;
  30. Uint8 a;
  31. } fg;
  32. struct {
  33. Uint8 r;
  34. Uint8 g;
  35. Uint8 b;
  36. Uint8 a;
  37. } bk;
  38. };
  39. class ColorSelect : public Window {
  40. private:
  41. class FrameWindow* myFrame;
  42. ColorStore* storage;
  43. enum {
  44. // Number of colors to make available
  45. NUM_COLORS = 11,
  46. // Size of color tiles (width)
  47. COLOR_SIZE = 14,
  48. // Separation between color tiles
  49. COLOR_SEPARATION = 1,
  50. // Bevel size on tiles
  51. COLOR_BEVEL = 1,
  52. // Tile height
  53. COLOR_HEIGHT = 20,
  54. };
  55. // Colors (R G B A)
  56. Uint8 color[NUM_COLORS][4];
  57. // Do we support fg or fg+bk?
  58. int numColors;
  59. int bitDepthAlpha;
  60. int bitDepth;
  61. int maxComponent;
  62. int maxAlpha;
  63. // Selected
  64. int selected[2];
  65. int selectedFirst[2]; // (can select a range)
  66. int selectedLast[2];
  67. // Default colors (R G B A)
  68. static Uint8 defaultColors[NUM_COLORS][4];
  69. static int defaultSelected[2];
  70. // Fg/Bk markers
  71. static const std::string wtArrowUp;
  72. static const std::string wtArrowDown;
  73. static int arrowHeight;
  74. static int arrowXOffset;
  75. // Save state to storage
  76. void apply();
  77. public:
  78. enum {
  79. // Selected types
  80. SELECTED_FG = 0,
  81. SELECTED_BK = 1,
  82. };
  83. ColorSelect(ColorStore* cStorage, int defaultTransparent, int allowBk = 1, int alphaBitDepth = 8, int myBitDepth = 8);
  84. // Creates a FrameWindow and returns, does not add self to desktop (use ->show() to do that)
  85. class FrameWindow* createWindowed();
  86. int event(int hasFocus, const SDL_Event* event);
  87. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  88. Window::CommandSupport supportsCommand(int code) const;
  89. const char* tooltip(int xPos, int yPos) const;
  90. // Returns a position
  91. int colorSelection(int which) const;
  92. int colorSelection(int which, int newPos, int drag = 0);
  93. // Edits a color at a given position
  94. void editColor(int pos);
  95. // Adds a color, to the next logical position to put it at, or to
  96. // current position if 'putInCurrent' true
  97. // Moves selection to point to it and returns position it was added at
  98. int addColor(int which, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int putInCurrent);
  99. // Changes settings
  100. void alphaDepth(int newAlphaDepth);
  101. void changeDefaultTransparent(int defaultTransparent);
  102. };
  103. inline int scaleComponent(int from, int fromMax, int toMax) { assert(fromMax); return (from * toMax + (fromMax / 2)) / fromMax; }
  104. #endif