1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 #ifndef DRAGONS_BACKGROUND_H 23 #define DRAGONS_BACKGROUND_H 24 25 #include "common/rect.h" 26 #include "common/system.h" 27 #include "dragons/bigfile.h" 28 #include "dragons/dragonrms.h" 29 #include "dragons/screen.h" 30 31 namespace Dragons { 32 class PriorityLayer; 33 class Background; 34 35 void drawTileToSurface(Graphics::Surface *surface, byte *palette, byte *tile, uint32 x, uint32 y); 36 37 class BackgroundResourceLoader { 38 private: 39 BigfileArchive *_bigFileArchive; 40 DragonRMS *_dragonRMS; 41 public: 42 BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS); 43 Background *load(uint32 sceneId); 44 Background *load(const char *filename); 45 }; 46 47 typedef struct { 48 int16 _y; 49 int16 _priority; 50 } ScaleBand; 51 52 class ScaleLayer { 53 public: 54 ScaleLayer(); 55 ~ScaleLayer(); 56 void load(Common::SeekableReadStream &stream); 57 uint16 getScale(uint16 y); 58 void backup(); 59 void restore(); 60 void clearAll(); 61 void setValue(uint8 index, int16 y, int16 value); 62 63 private: 64 ScaleBand _bands[32]; 65 ScaleBand *_savedBands; 66 }; 67 68 struct TileMap { 69 uint16 w; 70 uint16 h; 71 uint32 size; 72 byte *map; 73 uint16 tileIndexOffset; 74 TileMapTileMap75 TileMap() { 76 w = 0; 77 h = 0; 78 size = 0; 79 map = nullptr; 80 tileIndexOffset = 0; 81 } 82 }; 83 84 class Background { 85 private: 86 byte *_data; 87 byte *_tileDataOffset; 88 TileMap _tileMap[4]; 89 PriorityLayer *_priorityLayer; 90 ScaleLayer _scaleLayer; 91 byte _palette[512]; 92 Graphics::Surface *_layerSurface[3]; 93 Common::Point *_points2; 94 uint8 _layerPriority[3]; 95 Common::Point _layerOffset[3]; 96 AlphaBlendMode _layerAlphaMode[3]; 97 98 public: 99 Background(); 100 ~Background(); 101 102 bool load(byte *dataStart, uint32 size); 103 uint16 getWidth(); 104 uint16 getHeight(); getBgLayer()105 Graphics::Surface *getBgLayer() { return _layerSurface[0]; } getMgLayer()106 Graphics::Surface *getMgLayer() { return _layerSurface[1]; } getFgLayer()107 Graphics::Surface *getFgLayer() { return _layerSurface[2]; } getBgLayerPriority()108 uint8 getBgLayerPriority() { return _layerPriority[0]; } getMgLayerPriority()109 uint8 getMgLayerPriority() { return _layerPriority[1]; } getFgLayerPriority()110 uint8 getFgLayerPriority() { return _layerPriority[2]; } 111 setBgLayerPriority(uint8 newPriority)112 void setBgLayerPriority(uint8 newPriority) { _layerPriority[0] = newPriority; } setMgLayerPriority(uint8 newPriority)113 void setMgLayerPriority(uint8 newPriority) { _layerPriority[1] = newPriority; } setFgLayerPriority(uint8 newPriority)114 void setFgLayerPriority(uint8 newPriority) { _layerPriority[2] = newPriority; } 115 116 int16 getPriorityAtPoint(Common::Point pos); 117 Common::Point getPoint2(uint32 pointIndex); getPalette()118 byte *getPalette() { return _palette; } 119 120 void overlayPriorityTileMap(byte *data, int16 x, int16 y, int16 w, int16 h); 121 void restorePriorityTileMap(int16 x, int16 y, int16 w, int16 h); 122 void overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h); 123 void restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h); 124 void setPalette(byte *newPalette); 125 void setLayerOffset(uint8 layerNumber, Common::Point offset); 126 Common::Point getLayerOffset(uint8 layerNumber); getScaleLayer()127 ScaleLayer *getScaleLayer() { return &_scaleLayer; } 128 129 Dragons::AlphaBlendMode getLayerAlphaMode(uint8 layerNumber); 130 void setLayerAlphaMode(uint8 layerNumber, Dragons::AlphaBlendMode mode); 131 132 private: 133 Common::Point *loadPoints(Common::SeekableReadStream &stream); 134 Graphics::Surface *initGfxLayer(TileMap &tileMap); 135 void loadGfxLayer(Graphics::Surface *surface, TileMap &tileMap, byte *tiles); 136 137 }; 138 139 class PriorityLayer { 140 public: 141 void load(TileMap &tileMap, byte *tiles); 142 int16 getPriority(Common::Point pos); 143 void overlayTileMap(byte *data, int16 x, int16 y, int16 w, int16 h); 144 void restoreTileMap(int16 x, int16 y, int16 w, int16 h); 145 protected: 146 int16 _width, _height; 147 int16 _mapWidth, _mapHeight; 148 byte *_map, *_values; 149 byte *_mapBase; 150 }; 151 152 } // End of namespace Dragons 153 154 #endif //DRAGONS_BACKGROUND_H 155