#include #include "Tileset.h" #include #define mini_width 20 #define mini_height 28 static unsigned char mini_bits[] = { 0xfc, 0xff, 0x0f, 0xfe, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x07, 0xff, 0xff, 0x03, }; #define mask_width 40 #define mask_height 56 static unsigned char mask_bits[] = { 0xf0, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x0f, }; // --------------------------------------------------------- Tileset::Tileset(bool scale): maskBits(mask_width, mask_height, mask_bits, true), maskBitsMini(mini_width, mini_height, mini_bits, true) { isScaled = scale; divisor = (isScaled) ? 2 : 1; // set up tile metrics (fixed for now) ss = 4; // left/bottom shadow width bs = 1; // tile boarder width w = 40; // tile width (inc boarder & shadow) h = 56; // tile height (inc boarder and shadow) s = w*h; // RGBA's required per tile // Allocate memory for the 9*5 tile arrays tiles = new TQRgb [9*5*s]; selectedTiles = new TQRgb [9*5*s]; // allocate memory for single tile storage selectedFace = new TQRgb [s]; unselectedFace = new TQRgb [s]; // quarter widths are used as an offset when // overlaying tiles in 3 dimensions. qw = ((w-ss)/2) ; qh = ((h-ss)/2) ; filename = ""; } // --------------------------------------------------------- Tileset::~Tileset() { // deallocate all memory delete [] tiles; delete [] selectedTiles; delete [] selectedFace; delete [] unselectedFace; } // --------------------------------------------------------- // copy a tile from a qimage into a linear array of bytes. This // method returns the address of the byte after the copied image // and can be used to fill a larger array of tiles. TQRgb *Tileset::copyTileImage(short tileX, short tileY, TQRgb *to, TQImage &from) { TQRgb *dest = to; TQRgb *src; src = (TQRgb *) from.scanLine(tileY * h) +(tileX * w); for (short pos=0; pos < h; pos++) { memcpy(dest, src, w*sizeof(TQRgb)); dest+=w; src += from.width(); } return(dest); } // ---------------------------------------------------------- // Create a tile. Take a specified tile background a tile face // (specified as an x,y coord) and a destination buffer (location // in which is calculated from the x,y) and copy in the // tile background, overlaying the foreground with transparency // (the foregrounds top/left pixel is taken as the transparent // color). TQRgb *Tileset::createTile(short x, short y, TQRgb *det, TQImage &allTiles , TQRgb *face) { TQRgb *image ; TQRgb *to = det; // Alloc the space image = new TQRgb[s]; // copy in the background memcpy(to, face, s*sizeof(TQRgb)); // get the tile gylph copyTileImage(x, y , image, allTiles); // copy the image over the background using the // top left colour as the transparency. We step over // the shadow and the boarder TQRgb* src = image+ // image ss+ // past the left shadow bs+ // then the tile border (bs * w); // then step past the top border to += (((ss+bs))+(bs*w)); TQRgb trans = *src; // start after the top border rows and go through all rows for( short YP=0; YP < h-ss - (2*bs); YP++) { // start after the shadow and border and iterate over x for (short xpos=0; xpos < w-ss -(2*bs) ; xpos++) { // skip transparent pixels if (*src != trans) *to = *src; src++; to++; } // step over the border to get to the next row src += ss + (2 * bs); to += ss + (2 * bs); } // Free allocated space delete [] image; // calculate the address of the next tile return(det+s); } // -------------------------------------------------------- // create a pixmap for a tile. Optionally create a scalled // version, which can be used for mini tile requirements. // this gives us a small tile for previews and showing // removed tiles. void Tileset::createPixmap(TQRgb *src, TQPixmap &dest, bool scale, bool shadow) { TQImage buff; TQRgb *line; buff.create(w, h, 32); for (int y=0; y