gcsx_layeredit.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* GCSx
  2. ** LAYEREDIT.H
  3. **
  4. ** Layer editor-only functionality
  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_LAYEREDIT_H_
  24. #define __GCSx_LAYEREDIT_H_
  25. // (should never be used as a SaveLoad item- always called from a scene;
  26. // doesn't follow spec exactly- cachedContent(), etc.)
  27. class LayerEdit : public Layer /* , virtual public SaveLoad */ {
  28. protected:
  29. // Has the scene been modified from initial state (from empty if new)
  30. int headerModified;
  31. int contentModified;
  32. int disassociated;
  33. // Set us (and our scene) as modified
  34. void setHeaderModified();
  35. // Sets any tiles above a given number to 0; must be uncached/locked
  36. void clearTilesAbove(int code);
  37. // In edit mode, spawns get locked too
  38. int doLock(int play) throw_File;
  39. int doUnlock(int play);
  40. public:
  41. // Sets us (and scene) as modified; called by our spawn points
  42. void setContentModified();
  43. // Creates a default properties (empty) layer
  44. // World and ID may be NULL/0 if in process of creating (but scene is required)
  45. LayerEdit(class WorldEdit* myWorld, class Scene* myScene, int myId = 0);
  46. ~LayerEdit();
  47. // Intended only for use after creating/importing- not in general usage
  48. void setInfo(class WorldEdit* myWorld, int newId);
  49. void loadHeader(class FileRead* file) throw_File;
  50. void disassociate() throw_File;
  51. void reassociate();
  52. class WorldEdit* getWorldEdit() { return dynamic_cast<WorldEdit*>(world); }
  53. const class WorldEdit* getWorldEdit() const { return dynamic_cast<WorldEdit*>(world); }
  54. class SceneEdit* getSceneEdit() { return dynamic_cast<SceneEdit*>(scene); }
  55. class TileSetEdit* getTileSetEdit() { return dynamic_cast<TileSetEdit*>(tileset); }
  56. int getSpawnCount() const { return spawns.size(); }
  57. class SpawnEdit* getSpawn(int pos); // NOT an ID
  58. // Change properties
  59. void setName(const std::string& newName, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  60. // (changing to another type deletes all data)
  61. // Must be uncached (scene must therefore be uncached/locked)
  62. void setType(LayerType newType, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  63. // Works for ANY type of layer; works even if not allocated
  64. // Must be uncached (scene must therefore be uncached/locked)
  65. // ptrs are used by undo/redo calling us; standard use can ignore
  66. void setSize(int newX, int newY, Window* srcWin = NULL, Window* exWin = NULL, Uint32** undo1 = NULL, Uint32** undo2 = NULL, Uint32** undo3 = NULL) throw_Undo;
  67. // Pointer becomes owned by us
  68. void addSpawn(class SpawnEdit* newSpawn, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo throw_File;
  69. void deleteSpawn(class SpawnEdit* delSpawn, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  70. // Intended for display in editor; coordinates are the chunk to display, in pixels
  71. // and the offset on the surface to display to; handles all layer types; assumes
  72. // appropriate clipping rectangle is set, as pixels outside the given area MAY be
  73. // drawn; dim blits at 50% alpha; must be uncached/locked
  74. void blit(int pX, int pY, int pW, int pH, int offsetX, int offsetY, struct SDL_Surface* dest, int dim = 0);
  75. // Display sprites (call after blit*())
  76. void blitSpawns(int pX, int pY, int pW, int pH, int offsetX, int offsetY, struct SDL_Surface* dest, const std::set<int>* selected = NULL, int dim = 0);
  77. // LAYER_TILE layers
  78. // Must be uncached (scene must therefore be uncached/locked)
  79. // Throws file exceptions if new tileset err'd when uncaching
  80. void setTileset(int newTilesetId, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  81. // Must be uncached (scene must therefore be uncached/locked)
  82. void setExtended(int newUsesExtended, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  83. // Must be uncached (scene must therefore be uncached/locked)
  84. void setEffects(int newUsesEffects, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  85. // Must be uncached (scene must therefore be uncached/locked)
  86. // Gets raw data
  87. const Uint32* getTileData() const { return tileData; }
  88. const Uint32* getExtendedData() const { return extendedData; }
  89. const Uint32* getEffectsData() const { return effectsData; }
  90. // Copies tile layer (or partial) asserts rect is clipped to layer size already
  91. // exWin is window to exempt from resulting update event; does NOT handle undo
  92. // Must be uncached (scene must therefore be uncached/locked)
  93. // Fx pointers may be NULL; pitch is number of Uint32s, usually same as layer width
  94. // dest/fx ptrs point directly to destination- x/y from rect is not added in
  95. void loadLayer(Uint32* dest, Uint32* destExt, Uint32* destFx, int destPitch, const Rect& rect) const;
  96. void saveLayer(const Uint32* source, const Uint32* sourceExt, const Uint32* sourceFx, int sourcePitch, const Rect& rect, Window* exWin);
  97. // (all three ptrs are optional, but at least one is required; no exempt window as always called from undo anyway)
  98. void swapLayer(Uint32* data, Uint32* dataExt, Uint32* dataFx, int dataPitch, const Rect& rect);
  99. // Helper function for displaying a tile layer in editor
  100. // see blit() for parameters; made public so editor can use it's own data
  101. // NULL dataExt for no extended; width/height are layer size
  102. // Selection parameters are optional, allows editor to overlay a floating selection
  103. static void blitTileLayer(const TileSetEdit* tileset, const Uint32* data, const Uint32* dataExt, int width, int height, int pX, int pY, int pW, int pH, int offsetX, int offsetY, struct SDL_Surface* dest, int dim = 0, const Uint32* selData = NULL, const Uint32* selDataExt = NULL, int selXOffs = 0, int selYOffs = 0, int selWidth = -1);
  104. // Returns true if OK pressed
  105. // Only allows changing of layer type if isNew
  106. // Handles locking/uncaching scene
  107. int propertiesDialog(int isNew, LayerType defaultType = LAYER_TILE, Window* srcWin = NULL, Window* exWin = NULL);
  108. // Modified?
  109. int isHeaderModified() const;
  110. int isContentModified() const;
  111. void saveSuccess(); // (merely clears modified flags)
  112. // Save data to file
  113. Uint32 saveHeader(class FileWrite* file) throw_File;
  114. void saveContent(class FileWrite* file) throw_File;
  115. void cachedContent(FileRead* file, int oldData);
  116. };
  117. #endif