-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bitmap.cpp
76 lines (64 loc) · 3.16 KB
/
Bitmap.cpp
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
#include "stdafx.h"
#include <assert.h>
#include "Bitmap.h"
Bitmap::Bitmap () {}
Bitmap::Bitmap (LPCWSTR sprite_path)
{
sprite = (HBITMAP) LoadImage (NULL, sprite_path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
assert (sprite != NULL);
get_size (sprite, sprite_width, sprite_height);
}
Bitmap::Bitmap (LPCWSTR sprite_path, LPCWSTR mask_path)
{
sprite = (HBITMAP) LoadImage (NULL, sprite_path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
mask = (HBITMAP) LoadImage (NULL, mask_path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
assert (sprite != NULL);
assert (mask != NULL);
int mask_width, mask_height;
get_size (sprite, sprite_width, sprite_height);
get_size (mask, mask_width, mask_height);
assert (sprite_width == mask_width);
assert (sprite_height == mask_height);
is_transparent = true;
}
Bitmap::~Bitmap () {}
void Bitmap::render (HDC temp_hdc, HDC dest_hdc, int dest_x, int dest_y)
{
BITMAP temp_bitmap;
GetObject (sprite, sizeof (temp_bitmap), &temp_bitmap);
SelectObject (temp_hdc, sprite);
BitBlt (dest_hdc, dest_x, dest_y, temp_bitmap.bmWidth, temp_bitmap.bmHeight, temp_hdc, 0, 0, SRCINVERT);
SelectObject (temp_hdc, mask);
BitBlt (dest_hdc, dest_x, dest_y, temp_bitmap.bmWidth, temp_bitmap.bmHeight, temp_hdc, 0, 0, SRCAND);
SelectObject (temp_hdc, sprite);
BitBlt (dest_hdc, dest_x, dest_y, temp_bitmap.bmWidth, temp_bitmap.bmHeight, temp_hdc, 0, 0, SRCINVERT);
}
void Bitmap::render (HDC temp_hdc, HDC dest_hdc, int dest_x, int dest_y, float scale)
{
BITMAP temp_bitmap;
GetObject (sprite, sizeof (temp_bitmap), &temp_bitmap);
SelectObject (temp_hdc, sprite);
StretchBlt (dest_hdc, dest_x * scale, dest_y * scale, temp_bitmap.bmWidth * scale, temp_bitmap.bmHeight * scale, temp_hdc, 0, 0, temp_bitmap.bmWidth, temp_bitmap.bmHeight, SRCINVERT);
SelectObject (temp_hdc, mask);
StretchBlt (dest_hdc, dest_x * scale, dest_y * scale, temp_bitmap.bmWidth * scale, temp_bitmap.bmHeight * scale, temp_hdc, 0, 0, temp_bitmap.bmWidth, temp_bitmap.bmHeight, SRCAND);
SelectObject (temp_hdc, sprite);
StretchBlt (dest_hdc, dest_x * scale, dest_y * scale, temp_bitmap.bmWidth * scale, temp_bitmap.bmHeight * scale, temp_hdc, 0, 0, temp_bitmap.bmWidth, temp_bitmap.bmHeight, SRCINVERT);
}
void Bitmap::render (HDC temp_hdc, HDC dest_hdc, int source_x, int source_y, int width, int height, int dest_x, int dest_y, float scale)
{
BITMAP temp_bitmap;
GetObject (sprite, sizeof (temp_bitmap), &temp_bitmap);
SelectObject (temp_hdc, sprite);
StretchBlt (dest_hdc, dest_x * scale, dest_y * scale, width * scale, height * scale, temp_hdc, source_x, source_y, width, height, SRCINVERT);
SelectObject (temp_hdc, mask);
StretchBlt (dest_hdc, dest_x * scale, dest_y * scale, width * scale, height * scale, temp_hdc, source_x, source_y, width, height, SRCAND);
SelectObject (temp_hdc, sprite);
StretchBlt (dest_hdc, dest_x * scale, dest_y * scale, width * scale, height * scale, temp_hdc, source_x, source_y, width, height, SRCINVERT);
}
void Bitmap::get_size (HBITMAP hbitmap, int &width, int &height)
{
BITMAP temp_bitmap;
GetObject (hbitmap, sizeof (temp_bitmap), &temp_bitmap);
width = temp_bitmap.bmWidth;
height = temp_bitmap.bmHeight;
}