gcsx_tilesetedit.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* GCSx
  2. ** TILESETEDIT.H
  3. **
  4. ** Tileset support
  5. ** Expands basic TileSet to include editor functionality
  6. */
  7. /*****************************************************************************
  8. ** Copyright (C) 2003-2006 Janson
  9. **
  10. ** This program is free software; you can redistribute it and/or modify
  11. ** it under the terms of the GNU General Public License as published by
  12. ** the Free Software Foundation; either version 2 of the License, or
  13. ** (at your option) any later version.
  14. **
  15. ** This program is distributed in the hope that it will be useful,
  16. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ** GNU General Public License for more details.
  19. **
  20. ** You should have received a copy of the GNU General Public License
  21. ** along with this program; if not, write to the Free Software
  22. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  23. *****************************************************************************/
  24. #ifndef __GCSx_TILESETEDIT_H_
  25. #define __GCSx_TILESETEDIT_H_
  26. class TileSetEdit : public TileSet, virtual public SaveLoad {
  27. protected:
  28. // Has the tileset been modified from initial state (from empty if new)
  29. int headerModified;
  30. int contentModified;
  31. int disassociated;
  32. // Our node on the world browser
  33. TreeView* browserNode;
  34. // Set us as modified
  35. // Setting content modified also loads from cache if needed
  36. // Call these before actually making any modifications
  37. // (if header changes affect content, call both modifieds first)
  38. void setHeaderModified();
  39. void setContentModified();
  40. public:
  41. // Id of 0 = we're going to load (or create/import) immediately
  42. // Any other id = we start out modified
  43. // World and ID may be NULL/0 if in process of creating
  44. TileSetEdit(class WorldEdit* myWorld, int newIsFont, int myId = 0); // Starts with default settings
  45. virtual ~TileSetEdit();
  46. // Intended only for use after creating/importing- not in general usage
  47. void setInfo(class WorldEdit* myWorld, int newId);
  48. // Tells us to disassociate ourselves from anything, we've been "deleted"
  49. // or that we've been "readded" again
  50. // FileException means couldn't decache, and nothing was done
  51. void disassociate() throw_File;
  52. // Node is world browser node that we readd to
  53. void reassociate(TreeView* node);
  54. class WorldEdit* getWorldEdit() { return dynamic_cast<WorldEdit*>(world); }
  55. // Doesn't remove from world or erase name
  56. // Sets up to have a given number of blank tiles
  57. /* unused; doesn't affect collision maps
  58. void clear(int w, int h, int count = 0); // Must LOCK first
  59. */
  60. // Change properties; handles undo
  61. // setSize assumes you're passing a valid combination of sizes that has been verified
  62. // surfaces are used by undo/redo calling us; standard use can ignore
  63. void setSize(int newWidth, int newHeight, int newCount, int newCollisionCount, Window* srcWin = NULL, Window* exWin = NULL, SDL_Surface** undo1 = NULL, Uint32** undo2 = NULL, Uint32** undo3 = NULL) throw_Undo; // Must LOCK first
  64. void setName(const std::string& newName, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  65. // (unused) void setIsFont(int newIsFont); // Must LOCK first
  66. void setTilesPerLine(int newTilesPerLine, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  67. void setDefaultTransparent(int newDefaultTransparent, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo; // Must LOCK first
  68. // For viewing data in editor
  69. // Tile 0 displays nothing
  70. // Tile above max tiles displays debugging info (solid tile with tile number)
  71. void blitTile(int tileNum, SDL_Surface* surface, int dX, int dY) const; // Must LOCK first
  72. // Blits data with options- not optimized, intended for editor
  73. // alpha and color bitdepth taken from gcsx_imgselect.h
  74. void blitTileFx(int tileNum, SDL_Surface* surface, int dX, int dY, int alpha, int mirror, int flip, int rotate90, int color) const; // Must LOCK first
  75. void blitCollFx(int collNum, SDL_Surface* surface, int dX, int dY, int dim, int mirror, int flip, int rotate90, Uint32 color) const; // Must LOCK first
  76. // Copies a tile/collision map, assumes surface is 32bpp/same width/height (or larger) as tiles
  77. // May not respect surface clipping (assumes drawing to a scratch area)
  78. // exWin is window to exempt from resulting update event; does NOT handle undo
  79. // collision data uses white/100% as on and black/100% as off; save treats non-white as black
  80. // (tile is 1+; collision is 1+)
  81. void loadTile(int tileNum, SDL_Surface* surface); // Must LOCK first
  82. void loadColl(int collNum, SDL_Surface* surface); // Must LOCK first
  83. void saveTile(int tileNum, SDL_Surface* surface, Window* exWin); // Must LOCK first
  84. void saveColl(int collNum, SDL_Surface* surface, Window* exWin); // Must LOCK first
  85. // Font sets only; width must 0 or more
  86. void setGlyphWidth(int tileNum, int newWidth, Window* exWin); // Must LOCK first
  87. // Lets editor directly view tile data, for certain optimized uses
  88. const Uint8* viewTileData(int tile) const; // Must LOCK first
  89. const Uint32* viewCollData(int coll) const; // Must LOCK first
  90. // Pitch is number of Uint8s per line, 4x pixels plus possibly some padding
  91. int viewTilePitch() const; // Must LOCK first
  92. // Lets editor directly EDIT tile data; also uses viewTilePitch()
  93. // Must call editTileDone when complete; does NOT handle undo
  94. Uint8* editTileData(int tile); // Must LOCK first
  95. Uint32* editCollData(int coll); // Must LOCK first
  96. void editTileDone(int tile, Window* exWin = NULL); // Must LOCK first
  97. void editCollDone(int coll, Window* exWin = NULL); // Must LOCK first
  98. // Returns true if OK pressed
  99. // If newTileSet is true, and count is 0, count will reset to default
  100. // Locks and unlocks tileset
  101. int propertiesDialog(int newTileSet = 0, Window* srcWin = NULL, Window* exWin = NULL);
  102. // Browse window (editor)
  103. void openBrowseWindow();
  104. // Tile/collision paint edit window (editor)
  105. void openTilePaintWindow(int tile = 1);
  106. void openCollPaintWindow(int coll = 1);
  107. // Tells tileset to add itself to the world browser node
  108. void addToBrowser(TreeView* node, int makeCurrent = 1);
  109. void dropBrowser(); // Called if tileset gets dropped from browser
  110. // Treeview event handling
  111. int treeviewEvent(int code, int command, int check);
  112. static int treeviewEventWrap(void* ptr, int code, int command, int check);
  113. // Takes desired tile width, height, count
  114. // Determines surface width (pitch), height, num tiles per line
  115. // Returns the number of tiles that fit onto the surface, which may
  116. // be less than the requested count, but won't be more
  117. static int calculateTileSurfaceSizing(int w, int h, int count, int& sWidth, int& sHeight, int& perLine);
  118. // File access
  119. int isHeaderModified() const;
  120. int isContentModified() const;
  121. Uint32 saveHeader(FileWrite* file) throw_File;
  122. void saveContent(FileWrite* file) throw_File;
  123. void saveSuccess();
  124. void cachedContent(FileRead* file, int oldData);
  125. };
  126. #endif