gcsx_imgselect.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* GCSx
  2. ** IMGSELECT.H
  3. **
  4. ** Image/tile/sprite 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_IMGSELECT_H_
  24. #define __GCSx_IMGSELECT_H_
  25. // One image
  26. // Tile/Image set is specifically not included
  27. class Image {
  28. public:
  29. Uint16 index;
  30. Uint16 color; // 4 bits each RGB (see gcsx_layer.h)
  31. Uint8 alpha; // 4 bits (see gcsx_layer.h)
  32. Uint8 effects; // See enum
  33. enum {
  34. EFFECTS_FLIP = 0x01,
  35. EFFECTS_MIRROR = 0x02,
  36. EFFECTS_ROTATE = 0x04,
  37. // (see gcsx_layer.h)
  38. COLOR_BITDEPTH = 4,
  39. COLOR_DEFAULT = 0xFFF,
  40. ALPHA_BITDEPTH = 4,
  41. ALPHA_DEFAULT = 0xF,
  42. };
  43. Image();
  44. };
  45. // One or more images form a pattern
  46. // Tile/Image set is specifically not included
  47. class Pattern {
  48. public:
  49. struct PatternEntry {
  50. Image image;
  51. int x;
  52. int y;
  53. };
  54. std::vector<PatternEntry> images;
  55. int count;
  56. int width;
  57. int height;
  58. Pattern();
  59. };
  60. // A set of images shown by ImageSelect
  61. class ShownImages {
  62. public:
  63. enum {
  64. // How many recent patterns we remember
  65. PATTERN_RECENT_MAX = 32,
  66. };
  67. // Top image for strip
  68. Image strip;
  69. // Recently selected images/patterns
  70. Pattern recent[PATTERN_RECENT_MAX];
  71. ShownImages(const class TileSetEdit* tiles);
  72. };
  73. class ImageSelect : public Window {
  74. private:
  75. class FrameWindow* myFrame;
  76. enum {
  77. // Number of images to show in strip, default
  78. IMAGE_COUNT = 7,
  79. IMAGE_ACROSS = 3,
  80. // Maximum size of images (scaled if needed)
  81. IMAGE_MAX_SIZE = 64,
  82. // Minimum size of images (because also used for button height)
  83. IMAGE_MIN_SIZE = 16,
  84. // Separation between images AND bordering images- used to denote selection
  85. // Also separation between images and related buttons
  86. // Also border on top/bottom of rows
  87. IMAGE_SEPARATION = 4,
  88. // Bevel size on images
  89. IMAGE_BEVEL = 1,
  90. // Gutter between row types (this is instead of any other separation)
  91. IMAGE_GUTTER = 4,
  92. // Selected/drag types
  93. SELECTED_STRIP = 1, // an item on the main strip is selected
  94. SELECTED_NONE = 2, // the "none" item is selected
  95. SELECTED_RECENT = 3, // a "recent" item is selected
  96. DRAG_NONE = 0,
  97. DRAG_STRIP_PREV = 5,
  98. DRAG_RECENT_MORE = 6,
  99. DRAG_STRIP_NEXT = 7,
  100. DRAG_STRIP_MORE = 8,
  101. };
  102. // Where the images are coming from
  103. class TileSetEdit* tileset; // Not const- markLock/Unlock is not const
  104. const class ColorStore* colors;
  105. int useAlpha;
  106. int numImages;
  107. int imageWidth; // Actual
  108. int imageHeight;
  109. int zoomWidth; // Displayed size
  110. int zoomHeight;
  111. int paddedWidth; // Size of area zoomed tile is shown in
  112. int paddedHeight;
  113. int showVertical; // Vertically align?
  114. int numImagesShownCount; // Number along main axis
  115. int numImagesShownAcross; // Number across axis
  116. int numPatternsShown;
  117. int blankTileCenter;
  118. // Have "none" and "recent" items?
  119. int extendedFeatures;
  120. // Currently shown images
  121. ShownImages shown;
  122. // Remembers the most recently shown items on a
  123. // tileset-by-tileset basis
  124. static std::map<const void*,ShownImages>* shownBank;
  125. // Selected
  126. int selectedType;
  127. int selectedIndex; // Not valid for 'none' item
  128. int dragType;
  129. int prevDrag;
  130. // Buttons
  131. static const std::string wtButtonPrevV;
  132. static const std::string wtButtonNextV;
  133. static const std::string wtButtonPrevH;
  134. static const std::string wtButtonNextH;
  135. static const std::string wtButtonExpand;
  136. int buttonHeight;
  137. static int buttonWidth;
  138. void dragLocation(int mX, int mY, int& type, int& index) const;
  139. // Helpers for display; return suggested advancement height
  140. int drawButton(SDL_Surface* destSurface, int baseX, int baseY, int offsX, int offsY, const std::string& wText, int pressed) const;
  141. int drawBlankImage(SDL_Surface* destSurface, int baseX, int baseY, int offsX, int offsY, int selected) const;
  142. // pattern OR image, NULL = none
  143. int drawPattern(SDL_Surface* destSurface, int baseX, int baseY, int offsX, int offsY, int selected, Image* image, Pattern* pattern) const;
  144. void saveDef();
  145. public:
  146. ImageSelect(TileSetEdit* tiles, const class ColorStore* cStorage, int useExtendedFeatures = 1) throw_File;
  147. ~ImageSelect();
  148. // Creates a FrameWindow and returns, does not add self to desktop (use ->show() to do that)
  149. class FrameWindow* createWindowed();
  150. // Changes settings
  151. void changeSet(class TileSetEdit* tiles, int oldDeleted = 0) throw_File;
  152. void allowAlpha(int newUseAlpha);
  153. // Alert that color has changed
  154. void colorRefresh();
  155. // next/prev on main strip
  156. void nextImage();
  157. void prevImage();
  158. // select specific image centered on main strip
  159. void selectImage(int tile);
  160. // get data/fx/ext for currently selected item
  161. void getDataExt(Uint32& data, Uint32& ext, Uint32& fx) const;
  162. int event(int hasFocus, const SDL_Event* event);
  163. void resize(int newWidth, int newHeight, int newViewWidth = -1, int newViewHeight = -1, int fromParent = 0);
  164. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  165. const char* tooltip(int xPos, int yPos) const;
  166. WindowType windowType() const;
  167. static void destroyGlobals();
  168. };
  169. #endif