Repository navigation
Expand file tree
/
Copy pathutilities.cpp
More file actions
73 lines (55 loc) · 1.51 KB
/
Copy pathutilities.cpp
File metadata and controls
73 lines (55 loc) · 1.51 KB
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
#include "utilities.h"
#include <stdexcept>
bool easyx::LoadBitmap(LPDIRECTDRAW7 pdd, LPDIRECTDRAWSURFACE7 *dest, char *file)
{
BITMAP bm;
HBITMAP hbm;
HDC hdcSurf = 0, hdcImg = 0;
HGDIOBJ old;
DDSURFACEDESC2 ddsd = {0};
bool result = false;
try
{
hbm = (HBITMAP)LoadImage(0, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if( !hbm )
throw exception("error loading bitmap\n");
GetObject(hbm, sizeof bm, &bm);
ddsd.dwSize = sizeof ddsd;
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
if( FAILED(pdd->CreateSurface(&ddsd, dest, 0)) )
throw exception("error in CreateSurface\n");
hdcImg = CreateCompatibleDC(0);
old = SelectObject(hdcImg, hbm);
if( FAILED((*dest)->GetDC(&hdcSurf)) )
throw exception("error in GetDC\n");
if( BitBlt(hdcSurf, 0, 0, bm.bmWidth, bm.bmHeight, hdcImg, 0, 0, SRCCOPY) == false )
throw exception("error in BitBlt\n");
result = true;
} catch( exception &e )
{
OutputDebugString(e.what());
}
if( hdcSurf )
(*dest)->ReleaseDC(hdcSurf);
if( hdcImg )
{
if( hbm )
DeleteObject(SelectObject(hdcImg, old));
DeleteDC(hdcImg);
}
return result;
}
U16 easyx::Convert16Bit(U8 r, U8 g, U8 b)
{
return (((U16)b) | ((U16)g << 5) | ((U16)b << 10));
}
POINT easyx::SlideMapTilePlotter(int x, int y, int tilewidth, int tileheight)
{
POINT pt;
pt.x = x * tilewidth + y * tilewidth / 2;
pt.y = y * tileheight / 2;
return pt;
}