1 /*
2 * Copyright (C) 2015-2020, by Laszlo Szeremi under the Boost license.
3 *
4 * Pixel Perfect Engine, graphics.layers.base module
5 */6 7 modulepixelperfectengine.graphics.layers.interfaces;
8 9 importpixelperfectengine.graphics.layers.base;
10 11 /**
12 * Tile interface, defines common functions shared between tile layers.
13 */14 publicinterfaceITileLayer {
15 /// Retrieves the mapping from the tile layer.16 /// Can be used to retrieve data, e.g. for editors, saving game states17 publicMappingElement[] getMapping() @nogc @safepurenothrow;
18 /**
19 * Reads the mapping element from the given area, while accounting for warp mode.
20 * Params:
21 * x: x offset of the tile.
22 * y: y offset of the tile.
23 * Returns: The tile at the given point.
24 */25 publicMappingElementreadMapping(intx, inty) @nogc @safepurenothrowconst;
26 /**
27 * Writes the given element into the mapping at the given location.
28 * Params:
29 * x: x offset of the tile.
30 * y: y offset of the tile.
31 */32 publicvoidwriteMapping(intx, inty, MappingElementw) @nogc @safepurenothrow;
33 /**
34 * Loads a mapping into the layer.
35 * Params:
36 * x = width of the map.
37 * y = height of the map.
38 * mapping = an array representing the map.
39 * Throws: MapFormatException if width and height doesn't represent the map.
40 */41 publicvoidloadMapping(intx, inty, MappingElement[] mapping) @safepure;
42 /// Removes the tile from the display list with the given ID.43 publicvoidremoveTile(wcharid) pure;
44 /// .45 /**
46 * Reads the mapping element from the given area, while accounting for warp mode.
47 * Params:
48 * x: x offset of the tile.
49 * y: y offset of the tile.
50 * Returns: The tile at the given point.
51 */52 publicMappingElementtileByPixel(intx, inty) @nogc @safepurenothrowconst;
53 /// Returns the width of the tiles.54 publicintgetTileWidth() @nogc @safepurenothrowconst;
55 /// Returns the height of the tiles.56 publicintgetTileHeight() @nogc @safepurenothrowconst;
57 /// Returns the width of the mapping.58 publicintgetMX() @nogc @safepurenothrowconst;
59 /// Returns the height of the mapping.60 publicintgetMY() @nogc @safepurenothrowconst;
61 /// Returns the total width of the tile layer.62 publicsize_tgetTX() @nogc @safepurenothrowconst;
63 /// Returns the total height of the tile layer.64 publicsize_tgetTY() @nogc @safepurenothrowconst;
65 /**
66 * Adds a new tile to the layer.
67 * Params:
68 * tile: the bitmap representing the tile. Must be the same size as all the others. Some tilelayers might require
69 * an exact format of tiles.
70 * id: the character ID of the tile represented on the map.
71 * paletteSh: palette shift amount, or how many bits are actually used of the bitmap. This enables less than 16
72 * or 256 color chunks on the palette to be selected.
73 * Throws: TileFormatException if size or format is wrong.
74 */75 publicvoidaddTile(ABitmaptile, wcharid, ubytepaletteSh = 0) pure;
76 /// Returns the bitmap associated with the tile ID.77 publicABitmapgetTile(wcharid) @nogc @safepurenothrow;
78 /// Sets the warp mode.79 /// Returns the new warp mode that is being used.80 publicWarpModesetWarpMode(WarpModemode) @nogc @safepurenothrow;
81 /// Returns the currently used warp mode.82 publicWarpModegetWarpMode() @nogc @safepurenothrowconst;
83 ///Clears the tilemap84 publicvoidclearTilemap() @nogc @safepurenothrow;
85 }
86 /**
87 * Defines functions specific to transformable tile layers.
88 * All transform parameters (A, B, C, D) are 256-based "fractional integers".
89 */90 publicinterfaceITTL {
91 ///Returns the horizontal scaling amount.92 ///256 means no scaling, negative values flip everything horizontally.93 public @propertyshortA() @nogc @safenothrowpureconst;
94 ///Returns the shearing amount on the X axis.95 ///256 means one pixel moved downwards for each horizontal scanline.96 public @propertyshortB() @nogc @safenothrowpureconst;
97 ///Returns the shearing amount on the Y axis.98 ///256 means one pixel moved right for each vertical scanline.99 public @propertyshortC() @nogc @safenothrowpureconst;
100 ///Returns the vertical scaling amount.101 ///256 means no scaling, negative values flip everything vertically.102 public @propertyshortD() @nogc @safenothrowpureconst;
103 ///Returns the x origin point of the transformation relative to the screen.104 public @propertyshortx_0() @nogc @safenothrowpureconst;
105 ///Returns the y origin point of the transformation relative to the screen.106 public @propertyshorty_0() @nogc @safenothrowpureconst;
107 ///Sets the horizontal scaling amount.108 ///256 means no scaling, negative values flip everything horizontally.109 public @propertyshortA(shortnewval) @nogc @safenothrowpure;
110 ///Sets the shearing amount on the X axis.111 ///256 means one pixel moved downwards for each horizontal scanline.112 public @propertyshortB(shortnewval) @nogc @safenothrowpure;
113 ///Sets the shearing amount on the Y axis.114 ///256 means one pixel moved right for each vertical scanline.115 public @propertyshortC(shortnewval) @nogc @safenothrowpure;
116 ///Sets the vertical scaling amount.117 ///256 means no scaling, negative values flip everything vertically.118 public @propertyshortD(shortnewval) @nogc @safenothrowpure;
119 ///Returns the x origin point of the transformation relative to the screen.120 public @propertyshortx_0(shortnewval) @nogc @safenothrowpure;
121 ///Returns the y origin point of the transformation relative to the screen.122 public @propertyshorty_0(shortnewval) @nogc @safenothrowpure;
123 }
124 /**
125 *General SpriteLayer interface.
126 */127 publicinterfaceISpriteLayer {
128 ///Clears all sprite from the layer.129 publicvoidclear() @trustednothrow;
130 ///Removes the sprite with the given ID.131 publicvoidremoveSprite(intn) @trustednothrow;
132 /**
133 * Moves the sprite to the exact location.
134 * Params:
135 * n = The identifier of the sprite.
136 * x = New x position of the sprite.
137 * y = New y position of the sprite.
138 */139 publicvoidmoveSprite(intn, intx, inty) @trustednothrow;
140 /**
141 * Relatively moves the sprite by the given values.
142 * Params:
143 * n = The identifier of the sprite.
144 * x = New x position of the sprite.
145 * y = New y position of the sprite.
146 */147 publicvoidrelMoveSprite(intn, intx, inty) @trustednothrow;
148 ///Gets the coordinate of the sprite.149 publicBoxgetSpriteCoordinate(intn) @nogc @trustednothrow;
150 /**
151 * Creates a sprite from a bitmap with the given data, then places it to the display list. (New architecture)
152 * Params:
153 * sprt = The bitmap to be used as the sprite.
154 * n = Priority ID of the sprite. Both identifies the sprite and decides it's display priority. Larger numbers will be drawn first,
155 * and thus will appear behind of smaller numbers, which also include negatives.
156 * x = X position of the sprite (top-left corner).
157 * y = Y position of the sprite (top-left corner).
158 * paletteSel = Selects a given palette.
159 * paletteSh = Determines how many bits are being used, and thus the palette size for selection.
160 * alpha = The transparency of the sprite.
161 * scaleHoriz = Horizontal scaling of the sprite. 1024 is the base value, anything less will stretch, greater will shrink the sprite.
162 * scaleVert = Ditto for vertical.
163 * renderMode = Determines the rendering mode of the sprite. By default, it's determined by the layer itself. Any of the default
164 * other methods can be selected here, or a specially written rendering function can be specified with a different function.
165 * Returns: The current area of the sprite.
166 */167 publicBoxaddSprite(ABitmapsprt, intn, intx, inty, ushortpaletteSel = 0, ubytepaletteSh = 0,
168 ubytealpha = ubyte.max, intscaleHoriz = 1024, intscaleVert = 1024, RenderingModerenderMode = RenderingMode.init)
169 @trustednothrow;
170 /+
171 /**
172 * Places a new sprite onto the layer with the given parameters.
173 * Params:
174 * s = The bitmap to be displayed as the sprite.
175 * n = Priority ID. Lower number (including negatives) get to drawn last, thus appearing on top.
176 * c = The box that sets the position of the sprite.
177 * paletteSel = The ID of the selected palette.
178 * scaleHoriz = Horizontal scaling.
179 * scaleVert = Vertical scaling.
180 */
181 public void addSprite(ABitmap s, int n, Box c, ushort paletteSel = 0, int scaleHoriz = 1024,
182 int scaleVert = 1024) @safe nothrow;
183 ///Adds a sprite to the layer.
184 public void addSprite(ABitmap s, int n, int x, int y, ushort paletteSel = 0, int scaleHoriz = 1024,
185 int scaleVert = 1024) @safe nothrow;+/186 ///Sets the rendering function for the sprite (defaults to the layer's rendering function)187 publicRenderFuncsetSpriteRenderingMode(intn, RenderingModemode) @nogc @trustedpurenothrow;
188 ///Replaces the sprite. If the new sprite has a different dimension, the old sprite's upper-left corner will be used.189 publicvoidreplaceSprite(ABitmaps, intn) @trustednothrow;
190 ///Replaces the sprite and moves to the given position.191 publicvoidreplaceSprite(ABitmaps, intn, intx, inty) @trustednothrow;
192 ///Replaces the sprite and moves to the given position.193 publicvoidreplaceSprite(ABitmaps, intn, Boxc) @trustednothrow;
194 ///Returns the displayed portion of the sprite.195 public @nogcBoxgetSlice(intn) @trustednothrow;
196 ///Writes the displayed portion of the sprite.197 ///Returns the new slice, if invalid (greater than the bitmap, etc.) returns the old one.198 publicBoxsetSlice(intn, Boxslice) @trustednothrow;
199 ///Returns the selected paletteID of the sprite.200 public @nogcushortgetPaletteID(intn) @trustednothrow;
201 ///Sets the paletteID of the sprite. Returns the new ID, which is truncated to the possible values with a simple binary and operation202 ///Palette must exist in the parent Raster, otherwise AccessError might happen203 public @nogcushortsetPaletteID(intn, ushortpaletteID) @trustednothrow;
204 ///Scales bitmap horizontally205 publicintscaleSpriteHoriz(intn, inthScl) @trustednothrow;
206 ///Scales bitmap vertically207 publicintscaleSpriteVert(intn, intvScl) @trustednothrow;
208 ///Gets the sprite's current horizontal scale value209 publicintgetScaleSpriteHoriz(intn) @nogc @trustednothrow;
210 ///Gets the sprite's current vertical scale value211 publicintgetScaleSpriteVert(intn) @nogc @trustednothrow;
212 }