1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
void TilePalette::AddTileSet(PWSTR filePath)
{
//only here for compatability
HDC hdc;
hdc = GetDC(tile);
//for the main bitmap
HDC bmpHdc;
bmpHdc = CreateCompatibleDC(hdc);
//the main bitmap
HBITMAP bmp;
bmp = (HBITMAP)::LoadImage(NULL, filePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//get a copy of the bitmaps properties
BITMAP bmpProperties;
int iReturn = GetObject(reinterpret_cast<HGDIOBJ>(bmp),
sizeof(BITMAP),
reinterpret_cast<LPVOID>(&bmpProperties));
//load the bmp into the device context
HBITMAP oldBmp = (HBITMAP)SelectObject(bmpHdc, bmp);
int xBound,yBound, tileWidth, tileHeight;
tileWidth = Map::TileWidth_;
tileHeight = Map::TileHeight_;
xBound = bmpProperties.bmWidth / tileWidth;
yBound = bmpProperties.bmHeight / tileHeight;
for (int y = 0; y < yBound; y++)
{
for (int x = 0; x < xBound; x++)
{
//the bitmap of a single tile
HBITMAP tile;
tile = CreateCompatibleBitmap(hdc, tileWidth,tileHeight);
//the device that holds the tile bitmap
HDC tileHdc;
tileHdc = CreateCompatibleDC(hdc);
//insert the tile bitmap into the device context
HBITMAP oldTile = (HBITMAP)SelectObject(tileHdc, tile);
//blit from the main bitmap onto the tile bitmap
::BitBlt(bmpHdc,
x*tileWidth,
y*tileHeight,
tileWidth,
tileHeight,
tileHdc,
0,
0,
SRCCOPY);
//select the tile bitmap
SelectObject(tileHdc, oldTile);
//assign the tile bitmap to the new Tile struct
Tile newTile(tile, transparent);
//add it onto the tile vector
tilePalette_.push_back(newTile);
//delete the device context
::DeleteDC(tileHdc);
}
}
//update the tile window
InvalidateRect(tile, NULL, TRUE);
//select the main bitmap which we no longer want
::SelectObject(bmpHdc, bmp);
//delete the main device context
::DeleteDC(bmpHdc);
//delete the main bitmap
::DeleteObject(bmp);
}
|