gcsx_sceneeditlayer.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /* GCSx
  2. ** SCENEEDITLAYER.H
  3. **
  4. ** Scene editing- tile layers
  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_SCENEEDITLAYER_H_
  24. #define __GCSx_SCENEEDITLAYER_H_
  25. class SceneEditLayerTools : public Dialog {
  26. private:
  27. class ToolSelect* toolSelect;
  28. class SceneEditLayer* paintArea;
  29. class FrameWindow* myFrame;
  30. enum {
  31. // For tool popup selections
  32. TOOLSELECT_NUM_TOOLS = 14,
  33. };
  34. static const ToolSelect::ToolIconStruct toolIcons[TOOLSELECT_NUM_TOOLS];
  35. // enables/disables contiguous checkbox
  36. void adjustForTool();
  37. // When we switch between sprite/non-sprite tools, we remember the
  38. // previous tools so we can switch back and forth
  39. int otherModeToolL;
  40. int otherModeToolR;
  41. public:
  42. enum {
  43. // Individual buttons
  44. ID_TOOLL = 1,
  45. ID_TOOLR,
  46. ID_COPY,
  47. ID_PASTE,
  48. // Setting buttons
  49. ID_CONTIGUOUS,
  50. ID_GRID,
  51. };
  52. int* toolLPtr;
  53. int* toolRPtr;
  54. int* contiguousPtr;
  55. int* gridPtr;
  56. SceneEditLayerTools(class SceneEditLayer* tPaintArea, int* toolL, int* toolR, int* contiguous, int* grid);
  57. ~SceneEditLayerTools();
  58. int event(int hasFocus, const SDL_Event* event);
  59. void childModified(Window* modified);
  60. // Creates a FrameWindow and returns, does not add self to desktop (use ->show() to do that)
  61. class FrameWindow* createWindowed();
  62. int wantsToBeDeleted() const;
  63. WindowSort windowSort() const;
  64. };
  65. class SceneEditLayerList : public Dialog {
  66. private:
  67. class SceneEditLayer* paintArea;
  68. class FrameWindow* myFrame;
  69. public:
  70. enum {
  71. // Layer list itself
  72. ID_LAYER = 1,
  73. // Individual buttons
  74. ID_LAYERADD,
  75. };
  76. int selectedLayer;
  77. class WLayerListBox* layerList;
  78. SceneEditLayerList(class SceneEditLayer* tPaintArea);
  79. ~SceneEditLayerList();
  80. int event(int hasFocus, const SDL_Event* event);
  81. void childModified(Window* modified);
  82. // Creates a FrameWindow and returns, does not add self to desktop (use ->show() to do that)
  83. class FrameWindow* createWindowed();
  84. int wantsToBeDeleted() const;
  85. WindowSort windowSort() const;
  86. };
  87. class SceneEditSpriteList : public Dialog {
  88. private:
  89. class SceneEditLayer* paintArea;
  90. class FrameWindow* myFrame;
  91. class WorldEdit* world;
  92. int buildingList;
  93. void buildSpriteList();
  94. static int treeViewWrapScript(void* ptr, int code, int command, int check);
  95. int treeViewScript(int code, int command, int check);
  96. static int treeViewWrapOther(void* ptr, int code, int command, int check);
  97. int treeViewOther(int code, int command, int check);
  98. public:
  99. class TreeView* spriteList;
  100. SceneEditSpriteList(class SceneEditLayer* tPaintArea, class WorldEdit* tWorld);
  101. ~SceneEditSpriteList();
  102. // Creates a FrameWindow and returns, does not add self to desktop (use ->show() to do that)
  103. class FrameWindow* createWindowed();
  104. int wantsToBeDeleted() const;
  105. WindowSort windowSort() const;
  106. };
  107. class SceneEditLayer : public Window {
  108. private:
  109. class FrameWindow* myFrame;
  110. class SceneEditLayerTools* tools;
  111. class ImageSelect* imagebar;
  112. class ColorSelect* colorbar;
  113. class SceneEditLayerList* layerlist;
  114. class SceneEditSpriteList* spritelist;
  115. int hover;
  116. int lastMouseX; // Pixel-based- only tracks during hover, not drag
  117. int lastMouseY;
  118. // The last pixel-based position we've seen for the mouse,
  119. // in our client-window coordinates (may be negative)
  120. int pixelMouseX;
  121. int pixelMouseY;
  122. int toolL;
  123. int toolR;
  124. int contiguous;
  125. int enableGrid;
  126. class SceneEdit* scene;
  127. class WorldEdit* world;
  128. ColorStore colors;
  129. // Are we in sprite mode? (both tools will be sprite tools)
  130. // Spawn point being placed- temporary, owned by us
  131. int spriteMode;
  132. class SpawnEdit* spawnPlace;
  133. int spawnPropertiesDone;
  134. // (in pixels- not tiles)
  135. int spriteAtCursor; // Show placeholder at cursor or at mouse?
  136. int spriteShown; // Shows a placeholder sprite
  137. int spriteShownX;
  138. int spriteShownY;
  139. // Layers 1) viewable 2) affected 3) cursor/editing
  140. Uint32 layersView;
  141. Uint32 layersDim; // Of view, which layers are dimmed when not current
  142. Uint32 layersAffect; // All layers must have same size/tile size
  143. Uint32 layersAvailable; // All tile layers
  144. int numLayers; // Counts all layers, not just tile layers
  145. int cursorLayer;
  146. int cursorX;
  147. int cursorY;
  148. int cursorW;
  149. int cursorH;
  150. // (sprite cursor is invisible on it's own)
  151. int cursorSpriteX;
  152. int cursorSpriteY;
  153. // "virtual" cursor for dragging- where the cursor would be if no limits
  154. int virtualCursorX;
  155. int virtualCursorY;
  156. // Storage for editing- layers not being affected have NULL pointers
  157. // [0] is main storage, [1] is extended layer if in use, [2] is effects layer
  158. // Contains a copy of layer with edits OR a floating selection,
  159. // if selection mode is not SELECTION_OUTLINE
  160. Uint32* layerEdit[MAX_LAYERS][3];
  161. Uint8* selected; // Current selected area as a bitmask; when selection
  162. Uint8* backupSelected; // is floating, corresponds to data in layerEdit
  163. int selectedPitch; // (bytes wide of selected/backupSelected)
  164. Rect selectionRect;
  165. Rect backupSelectionRect;
  166. // Selection mode
  167. enum {
  168. SELECTION_OUTLINE = 0, // Draw outline only, no data
  169. SELECTION_OPAQUE, // Paste/ovelay layerEdit as-is
  170. };
  171. int selectionMode;
  172. // Move selection; gaurunteed to be 0 if SELECTION_OUTLINE
  173. int selectionXOffs;
  174. int selectionYOffs;
  175. // Selected spawns, by spawn id
  176. std::set<int> selectedSpawns;
  177. Rect selectedSpawnRect; // Bounding box for dirties, etc.
  178. std::set<int> backupSelectedSpawns;
  179. Rect backupSelectedSpawnRect;
  180. int numTiles; // Cursor layer only
  181. int tileWidth; // Affected layers only
  182. int tileHeight; // Affected layers only
  183. int layerWidth; // Affected layers only
  184. int layerHeight; // Affected layers only
  185. int layerExt; // Cursor layer only
  186. int haveFocus;
  187. int partialFocus;
  188. int toolStartX; // Normally tiles; pixels for spawn editing
  189. int toolStartY;
  190. int toolLastX; // Normally tiles; pixels for spawn editing
  191. int toolLastY;
  192. int toolActive;
  193. Uint32 toolData;
  194. Uint32 toolExt;
  195. Uint32 toolFx;
  196. Uint32 toolDataMask;
  197. Uint32 toolExtMask;
  198. Uint32 toolFxMask;
  199. int toolCtrl;
  200. int toolAlt;
  201. int toolContiguous;
  202. int startToolOnMove;
  203. // Min and max x/y for pen tool, to save undo
  204. int toolMinX;
  205. int toolMinY;
  206. int toolMaxX;
  207. int toolMaxY;
  208. // (doesn't set any sort of dirty)
  209. void refreshData(int cursorLayerOnly = 1, int x1 = 0, int y1 = 0, int x2 = MAX_LAYERTILESIZE, int y2 = MAX_LAYERTILESIZE);
  210. void applyData(int cursorLayerOnly = 1, int x1 = 0, int y1 = 0, int x2 = MAX_LAYERTILESIZE, int y2 = MAX_LAYERTILESIZE);
  211. // Move cursor, then call
  212. void startTool(int button);
  213. void startToolSelectionDrag();
  214. void modifyTool(); // Call if CTRL/ALT changes
  215. void dragTool(int firstTime = 0, int lastTime = 0);
  216. void finishTool();
  217. void cancelTool();
  218. // Enables/disables copy tool based on current situation
  219. void updateCopyTool();
  220. // Dirty range
  221. Rect dirtyRange;
  222. // Set partial dirty by tile; specifically allows ranges outside maximums
  223. void setDirtyBox(int x1, int y1, int x2, int y2, int selectionFeather = 0);
  224. void setDirtyRect(const Rect& rect, int selectionFeather = 0);
  225. // Set by pixel
  226. void setDirtyPixelBox(int x1, int y1, int x2, int y2);
  227. // Undo wrappers
  228. void undoStoreLayerBox(int x1, int y1, int x2, int y2, int cursorLayerOnly = 1) throw_Undo;
  229. void undoStoreLayer(int x, int y, int w, int h, int cursorLayerOnly = 1) throw_Undo;
  230. // If selection outline, just stores that
  231. // If selection floating, stores the data as well
  232. void undoStoreSelect(int x, int y, int w, int h, int forceStoreData = 0) throw_Undo;
  233. // Selection tools- they clip
  234. void selectRect(int x1, int y1, int x2, int y2, int set);
  235. void selectEllipse(int x, int y, int rx, int ry, int set);
  236. // Drawing tools- they clip- assumes data is layerWidth by layerHeight; &'s mask, |'s set
  237. void layerDrawLine(int x1, int y1, int x2, int y2, Uint32* data, Uint32 mask, Uint32 set) const;
  238. void layerDrawBox(int x1, int y1, int x2, int y2, Uint32* data, Uint32 mask, Uint32 set) const;
  239. void layerDrawRect(int x1, int y1, int x2, int y2, Uint32* data, Uint32 mask, Uint32 set) const;
  240. void layerDrawEllipse(int x, int y, int rx, int ry, Uint32* data, Uint32 mask, Uint32 set) const;
  241. void layerDrawEllipseFill(int x, int y, int rx, int ry, Uint32* data, Uint32 mask, Uint32 set) const;
  242. // (matchMask is what bits we pay attention to in data1 that must match to fill)
  243. Rect layerFloodFill(int x, int y, Uint32 matchMask, Uint32* data1, Uint32 mask1, Uint32 set1, Uint32* data2 = NULL, Uint32 mask2 = 0, Uint32 set2 = 0) const;
  244. // (non-contiguous flood fill)
  245. Rect layerMatchFill(int x, int y, Uint32 matchMask, Uint32* data1, Uint32 mask1, Uint32 set1, Uint32* data2 = NULL, Uint32 mask2 = 0, Uint32 set2 = 0) const;
  246. // If tools should modify the spawn selection (ie, there is a spawn
  247. // selection and current tool is a spawn tool or there is no regular selection)
  248. int useSpawnSelection() const;
  249. // Clear a selection or merge a floation selection; stores undo
  250. void doneSelection() throw_Undo;
  251. // Clear selection rectangle, discard any floating selection
  252. void clearSelection(int storeUndo = 1) throw_Undo;
  253. // Take an existing outline selection and floats it; replaces
  254. // old data with empty; Stores undo unless copyPrep is true
  255. // Doesn't apply change to data if copyPrep is true
  256. // Just deletes data if delSel is true
  257. void floatSelection(int copyPrep = 0, int delSel = 0) throw_Undo;
  258. // Copy an outline or floating selection to clipboard, doesn't
  259. // affect layer or selection in any way
  260. void copySelection();
  261. // Paste clipboard as a new selection; first merges or removes
  262. // any existing selection; Stores undo; returns TOOLS_SELECT or TOOLS_SELECTIEM
  263. // if paste successful
  264. int pasteSelection() throw_Undo;
  265. // Fill selection with empty or delete a floating selection
  266. // Stores undo
  267. void deleteSelection() throw_Undo;
  268. // Merges a floating selection if one exists
  269. // Stores undo
  270. void mergeSelection() throw_Undo;
  271. // Optionally deselects empties (only if empty on all affected layers)
  272. void fixSelectionRect(int deselEmpty = 0);
  273. // Returns true if a given tile x/y is within the current selection area
  274. int isInSelection(int x, int y) const;
  275. // (after this, you should call reloadLayerStats())
  276. void initAvailableLayers();
  277. // (after this, you must load or reload layer data!)
  278. void reloadLayerStats(int resizeView = 0);
  279. void moveCursor(int newX, int newY); // IN PIXELS
  280. void moveSelection(int newX, int newY); // In tiles
  281. void mousePointer();
  282. void mousePointer(int mouseX, int mouseY);
  283. void updateTitlebar();
  284. void setUsesExt(int usesExt);
  285. // Scans in a given direction for a blank or non-blank
  286. // based on what's under the cursor currently (like in textmode)
  287. void scanCursor(int xDir, int yDir);
  288. // Updates sprite-shown variables to match current mouse/cursor/tool settings
  289. // Sets dirty as necessary
  290. void updateSpriteShown();
  291. // Spawn editing- each function similar to non-spawn function
  292. void setDirtySelectedSpawns();
  293. void copySpawnSelection();
  294. void deleteSpawnSelection() throw_Undo;
  295. // (just unselects everything, no modifications)
  296. void clearSpawnSelection(int storeUndo = 1) throw_Undo;
  297. // Deselect any selected spawn that isn't on one of our affected layers
  298. // Then fix spawn selection rectangle to match
  299. void recheckSpawnSelection();
  300. void undoStoreSpawnSelect() throw_Undo;
  301. // (as a bonus, returns spawn ID)
  302. int isInSpawnSelection(int x, int y);
  303. void startToolSpawnSelectionDrag();
  304. void selectSpawnRect(int x1, int y1, int x2, int y2, int select = 1, int selectAll = 0);
  305. void moveSpawnSelection(int byX, int byY, int skipUndo = 1);
  306. public:
  307. // Opens the window
  308. SceneEditLayer(SceneEdit* myScene) throw_File;
  309. ~SceneEditLayer();
  310. // Called by tool panel to tell us to refresh view or visible/affected layers
  311. void refresh();
  312. void refreshLayers(Uint32 newLayersAffect = 0, Uint32 newLayersView = 0, Uint32 newLayersDim = 0);
  313. // Called by tool panel to tell us tool was selected via key hold
  314. void startToolIfMove();
  315. // Called by tool panel when new tool(s) are selected
  316. void newToolSelected();
  317. // Called by sprite panel (takes ownership)
  318. void setSpawnPlace(class SpawnEdit* newSpawn);
  319. // Used by undo system
  320. void swapSelectionParameters(int& xoffs, int& yoffs, int& mode);
  321. void updatedSpawnSelection();
  322. CommandSupport supportsCommand(int code) const;
  323. int event(int hasFocus, const SDL_Event* event);
  324. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  325. WindowType windowType() const;
  326. void siblingModified(Window* modified);
  327. // @TODO: void undoNotify(int undoType, int undoItemId, int undoItemSubId, int uX, int uY, int uW, int uH);
  328. // (attempt to move cursor to an affected layer and scroll to view an affected area)
  329. };
  330. #endif