gcsx_tilesetpaint.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /* GCSx
  2. ** TILESETPAINT.H
  3. **
  4. ** Tileset editing- actual paint/edit window
  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_TILESETPAINT_H_
  24. #define __GCSx_TILESETPAINT_H_
  25. class TilePaintTools : public Dialog {
  26. private:
  27. ToolSelect* toolSelect;
  28. ToolSelect* dotsSelect;
  29. class TilePaint* paintArea;
  30. class FrameWindow* myFrame;
  31. enum {
  32. // For tool popup selections
  33. TOOLSELECT_NUM_TOOLS = 11,
  34. // Dots selection
  35. TOOLSELECT_NUM_DOTS = 3,
  36. };
  37. static const ToolSelect::ToolIconStruct toolIcons[TOOLSELECT_NUM_TOOLS];
  38. static const ToolSelect::ToolIconStruct dotsIcons[TOOLSELECT_NUM_DOTS];
  39. // Adjusts panel for current tool- hiding/rearranging configuration elements
  40. void adjustForTool();
  41. // Used to help resize preview area- this is
  42. // our height if preview is 0 pixels high
  43. int minHeight;
  44. public:
  45. enum {
  46. // Color select
  47. ID_COLOR = 1,
  48. // Alpha blend
  49. ID_ALPHALABEL,
  50. ID_ALPHA_S,
  51. ID_ALPHA_N,
  52. // Tool options
  53. ID_ANTIALIAS, // Actually used as "Contiguous" also
  54. ID_TOLERANCELABEL,
  55. ID_TOLERANCE_S,
  56. ID_TOLERANCE_N,
  57. // Individual buttons
  58. ID_TOOL,
  59. ID_NEXT,
  60. ID_PREV,
  61. ID_ZOOMIN,
  62. ID_ZOOMOUT,
  63. ID_COPY,
  64. ID_PASTE,
  65. // Setting buttons
  66. ID_GRID,
  67. ID_DOTS,
  68. // Preview
  69. ID_PREVIEW,
  70. };
  71. int* toolPtr;
  72. int* antiAliasPtr;
  73. int* alphaBlendPtr;
  74. int* tolerancePtr;
  75. int* gridPtr;
  76. int* dotsPtr;
  77. TilePaintTools(class TilePaint* tPaintArea, SDL_Surface** tileSource, int* tool, int* alphaBlend, int* antiAlias, int* tolerance, int* grid, int* dots);
  78. ~TilePaintTools();
  79. // Creates a FrameWindow and returns, does not add self to desktop (use ->show() to do that)
  80. class FrameWindow* createWindowed();
  81. int event(int hasFocus, const SDL_Event* event);
  82. void resize(int newWidth, int newHeight, int newViewWidth = -1, int newViewHeight = -1, int fromParent = 0);
  83. void childModified(Window* modified);
  84. void tileRedraw();
  85. int wantsToBeDeleted() const;
  86. WindowSort windowSort() const;
  87. };
  88. class TilePaint : public Window {
  89. private:
  90. FrameWindow* myFrame;
  91. TilePaintTools* tools;
  92. class ColorSelect* colorbar;
  93. int hover;
  94. int lastMouseX;
  95. int lastMouseY;
  96. int tool;
  97. int alphaBlend;
  98. int antiAlias; // Also used as "contiguous" setting
  99. int tolerance;
  100. ColorStore colors;
  101. TileSetEdit* tileset;
  102. WorldEdit* world;
  103. SDL_Surface* tile;
  104. int glyphWidth; // For font editing
  105. SDL_Surface* alphaWorkspace;
  106. // alpha0 = not selected, anything else = selected
  107. // used to store selection rectangles AND floating selection
  108. // size may differ from tile size
  109. SDL_Surface* selection;
  110. // Backs up selection during selection tool drags
  111. SDL_Surface* backupSelection; // Also (ab)used as temp storage sometimes
  112. // .w = 0 if we have no current selection
  113. // otherwise gaurunteed to not be larger than the selection surface
  114. Rect selectionRect;
  115. Rect backupSelectionRect;
  116. // Selection mode
  117. enum {
  118. SELECTION_OUTLINE = 0, // Draw outline only, no data
  119. SELECTION_OPAQUE, // Paste/ovelay as-is
  120. SELECTION_ALPHA, // Paste/overlay with alpha
  121. };
  122. int selectionMode;
  123. // Move selection; gaurunteed to be 0 if SELECTION_OUTLINE
  124. int selectionXOffs;
  125. int selectionYOffs;
  126. // If true, we're editing collision maps- everything refers to and
  127. // affects collision maps instead of tiles (including only having two colors)
  128. int isColl;
  129. int currentTile;
  130. int numTiles;
  131. int tileWidth;
  132. int tileHeight;
  133. int isFont;
  134. int pixelSize; // Only exact multiple zoom ratios
  135. int gridSize; // Considered part of pixel size; 0 or 1 only
  136. int enableGrid; // Affects gridSize to 0 or 1
  137. int drawDots;
  138. int cursorX;
  139. int cursorY;
  140. int hideCursor;
  141. int haveFocus;
  142. int partialFocus;
  143. // "virtual" cursor for dragging- where the cursor would be if no limits
  144. int virtualCursorX;
  145. int virtualCursorY;
  146. int toolStartX;
  147. int toolStartY;
  148. int toolLastX;
  149. int toolLastY;
  150. int toolFgBk;
  151. int toolActive;
  152. Uint32 toolColor;
  153. int toolAlpha;
  154. int toolAlias; // Used for "contiguous" setting also
  155. int toolTolerance;
  156. int toolCtrl;
  157. int toolAlt;
  158. int startToolOnMove;
  159. // Min and max x/y for pen tool, to save undo
  160. int toolMinX;
  161. int toolMinY;
  162. int toolMaxX;
  163. int toolMaxY;
  164. void refreshTile(); // Doesn't set any sort of dirty
  165. void applyTile();
  166. void applyGlyphWidth();
  167. enum {
  168. // Zooming
  169. MAX_ZOOM = 20, // Highest zoom
  170. MAX_ZOOMGRID = 3, // Highest zoom grid is visible
  171. // Size of glyph width pointer and margin
  172. GLYPH_SIZE_POINTER_HEIGHT = 5,
  173. GLYPH_SIZE_POINTER_MARGIN = 2,
  174. };
  175. // Move cursor, then call
  176. // "fgbk" is USE_FG or USE_BK.
  177. void startTool(int fgbk);
  178. void startToolSelectionDrag();
  179. void startToolGlyphWidthDrag();
  180. void modifyTool(); // Call if CTRL/ALT changes
  181. void dragTool(int firstTime = 0, int lastTime = 0);
  182. void finishTool();
  183. void cancelTool();
  184. // Dirty range
  185. Rect dirtyRange;
  186. // Set partial dirty- coordinates are in tile pixels, not zoomed pixels
  187. // selectionFeather, if true, will consider this a dirty rect from
  188. // modification of selection, which creates a slightly bigger dirty
  189. // area because it requires surrounding pixels to redraw also; this does
  190. // not need to be set for clearing of -entire- selection
  191. void setDirtyBox(int x1, int y1, int x2, int y2, int selectionFeather = 0);
  192. void setDirtyRect(const Rect& rect, int selectionFeather = 0);
  193. void setDirtyGlyphWidth(int x1, int x2);
  194. // Moves glyph width pointer; doesn't update tile permanently
  195. void setGlyphWidth(int gX);
  196. // Undo wrappers
  197. void undoStoreBlitBox(int x1, int y1, int x2, int y2) throw_Undo;
  198. void undoStoreBlit(int x, int y, int w, int h) throw_Undo;
  199. void undoStoreSelect(int x, int y, int w, int h) throw_Undo;
  200. void undoStoreGlyph() throw_Undo;
  201. // Clear a selection or merge a floation selection; stores undo
  202. void doneSelection() throw_Undo;
  203. // Clear selection rectangle, discard any floating selection
  204. void clearSelection(int storeUndo = 1) throw_Undo;
  205. // Take an existing outline selection and floats it; replaces
  206. // old data with background color;
  207. // Stores undo
  208. void floatSelection() throw_Undo;
  209. // Copy an outline or floating selection to clipboard, doesn't
  210. // affect tile or selection in any way
  211. void copySelection();
  212. // Paste clipboard as a new selection; first merges or removes
  213. // any existing selection
  214. // Stores undo
  215. void pasteSelection() throw_Undo;
  216. // Fill selection with bk color or delete a floating selection
  217. // Stores undo
  218. void deleteSelection() throw_Undo;
  219. // Merges a floating selection if one exists
  220. // Stores undo
  221. void mergeSelection() throw_Undo;
  222. // Rescan selection rectangle and update selectionRect bounding box
  223. void fixSelectionRect();
  224. // Returns true if a given tile pixel x/y is within the current selection area
  225. int isInSelection(int x, int y);
  226. void zoomIn();
  227. void zoomOut();
  228. void changeTile(int newTile);
  229. void changePixelSizing(int newPixelSize, int newGridSize);
  230. // (after this, you must load or reload tile!)
  231. void reloadTileStats();
  232. void moveCursor(int newX, int newY);
  233. void moveSelection(int newX, int newY);
  234. void mousePointer();
  235. void mousePointer(int mouseX, int mouseY);
  236. void updateTitlebar();
  237. public:
  238. // Opens the window
  239. TilePaint(TileSetEdit* myTileset, int myTile, int myIsColl = 0) throw_File;
  240. ~TilePaint();
  241. // Called by tool panel to tell us to refresh
  242. void refresh();
  243. // Called by tool panel to tell us tool was selected via key hold
  244. void startToolIfMove();
  245. // Used by undo system
  246. void swapSelectionParameters(int& xoffs, int& yoffs, int& mode);
  247. int event(int hasFocus, const SDL_Event* event);
  248. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  249. CommandSupport supportsCommand(int code) const;
  250. WindowType windowType() const;
  251. void undoNotify(int undoType, int undoItemId, int undoItemSubId, int uX, int uY, int uW, int uH);
  252. };
  253. #endif