forked from snowie2000/mactype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.h
151 lines (133 loc) · 2.88 KB
/
cache.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
template <int BUFSIZE, bool ignoreCase>
class StringHashT
{
private:
DWORD m_dwHash;
TCHAR m_szBuffer[BUFSIZE];
void UpdateHash()
{
DWORD dw = 0;
LPWSTR p, end = m_szBuffer + BUFSIZE;
for (p = m_szBuffer; *p && p < end; p++) {
dw <<= 3;
if (ignoreCase) {
dw ^= _totlower(*p);
} else {
dw ^= *p;
}
}
m_dwHash = dw;
}
public:
StringHashT()
: m_dwHash(0)
{
ZeroMemory(m_szBuffer, sizeof(m_szBuffer));
}
StringHashT(LPCTSTR psz)
{
this->StringHashT::StringHashT();
_tcsncpy(m_szBuffer, psz, BUFSIZE - 1);
UpdateHash();
}
bool operator ==(const StringHashT<BUFSIZE, ignoreCase>& x) const
{
if (ignoreCase) {
return !(m_dwHash != x.m_dwHash || _tcsicmp(m_szBuffer, x.m_szBuffer));
} else {
return !(m_dwHash != x.m_dwHash || _tcscmp(m_szBuffer, x.m_szBuffer));
}
}
DWORD Hash() const
{
return m_dwHash;
}
LPCTSTR c_str() const
{
return m_szBuffer;
}
};
typedef StringHashT<LF_FACESIZE,true> StringHashFont;
typedef StringHashT<MAX_PATH,true> StringHashModule;
//COLORREF(RR GG BB 00) を DIB32(BB GG RR 00) に変換
#define RGB2DIB(rgb) RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb))
#define DIB2RGB(dib) RGB2DIB(dib)
// ExtTextOutWのビットマップキャッシュ
class CBitmapCache
{
private:
HBRUSH m_brush;
HDC m_hdc;
HDC m_exthdc;
HBITMAP m_hbmp;
BYTE* m_lpPixels;
SIZE m_dibSize;
int m_counter;
DWORD* m_CurrentPixel;
COLORREF m_bkColor;
NOCOPY(CBitmapCache);
public:
CBitmapCache()
: m_hdc(NULL)
, m_hbmp(NULL)
, m_lpPixels(NULL)
, m_counter(0)
, m_CurrentPixel(NULL)
, m_exthdc(NULL)
, m_brush(NULL)
, m_bkColor(NULL)
{
m_dibSize.cx = m_dibSize.cy = 0;
}
~CBitmapCache()
{
if (m_hdc) {
DeleteDC(m_hdc);
}
if (m_hbmp) {
DeleteBitmap(m_hbmp);
}
if (m_brush)
DeleteObject(m_brush);
m_hdc = NULL;
m_hbmp = NULL;
m_brush = NULL;
m_dibSize.cx = 0;
m_dibSize.cy = 0;
}
const SIZE& Size() const
{
return m_dibSize;
}
BYTE* GetPixels()
{
Assert(m_lpPixels != NULL);
return m_lpPixels;
}
DWORD GetPixel(int X, int Y) {
if ((unsigned)X >= (unsigned)m_dibSize.cx || (unsigned)Y >= (unsigned)m_dibSize.cy) {
return CLR_INVALID;
}
DWORD* lpPixels = (DWORD*)m_lpPixels;
m_CurrentPixel = &lpPixels[Y * m_dibSize.cx + X];
DWORD dib = *m_CurrentPixel;
return DIB2RGB(dib);
}
void SetPixelV(int X, int Y, COLORREF rgb) {
// if ((unsigned)X >= (unsigned)m_dibSize.cx || (unsigned)Y >= (unsigned)m_dibSize.cy) {
// return;
// }
DWORD* lpPixels = (DWORD*)m_lpPixels;
m_CurrentPixel = &lpPixels[Y * m_dibSize.cx + X];
SetCurrentPixel(rgb);
}
void SetCurrentPixel(COLORREF rgb) {
*m_CurrentPixel = RGB2DIB(rgb);
}
//本体はcache.cpp
HDC CreateDC(HDC dc);
HBITMAP CreateDIB(int width, int height, BYTE** lplpPixels);
void FillSolidRect(COLORREF rgb, const RECT* lprc);
void DrawHorizontalLine(int X1, int Y1, int X2, COLORREF rgb, int width);
};