-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextSquiggle.cpp
88 lines (67 loc) · 2.61 KB
/
TextSquiggle.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
77
78
79
80
81
82
83
84
85
86
87
88
// TextSquiggle.cpp
#include "TextSquiggle.h"
// These are the raw RGB values for the squiggle, with the alpha pre-multiplied.
static DWORD squiggle[18] =
{
0xfbfb5555, 0xe2e24d4d, 0x0d0d0404, 0x01010000, 0x35351212, 0xf4f45353,
0x21210b0b, 0xbdbd4040, 0xd7d74949, 0x3f3f1515, 0xe0e04c4c, 0xadad3b3b,
0x00000000, 0x24240c0c, 0xc8c84444, 0xffff5757, 0xb0b03c3c, 0x03030101,
};
static int squiggleWidth = 6;
static int squiggleHeight = 3;
TextSquiggle::TextSquiggle()
: m_squiggleDC( 0 )
, m_squiggleSourceBitmap( 0 )
, m_squiggleRepeatedBitmap( 0 )
, m_width( 0 )
{
HDC windowDC = GetDC( NULL );
m_squiggleDC = CreateCompatibleDC( windowDC );
m_squiggleSourceBitmap = CreateCompatibleBitmap( windowDC, squiggleWidth, squiggleHeight );
BITMAPINFO info = {};
info.bmiHeader.biSize = sizeof( info.bmiHeader );
info.bmiHeader.biWidth = squiggleWidth;
info.bmiHeader.biHeight = squiggleHeight;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = 32;
info.bmiHeader.biCompression = BI_RGB;
info.bmiHeader.biSizeImage = sizeof( squiggle );
SetDIBits( m_squiggleDC, m_squiggleSourceBitmap, 0, squiggleHeight, squiggle, &info, DIB_RGB_COLORS );
ReleaseDC( NULL, windowDC );
}
TextSquiggle::~TextSquiggle()
{
if ( m_squiggleDC )
DeleteDC( m_squiggleDC );
if ( m_squiggleSourceBitmap )
DeleteObject( m_squiggleSourceBitmap );
if ( m_squiggleRepeatedBitmap )
DeleteObject( m_squiggleRepeatedBitmap );
}
void TextSquiggle::Resize( int width ) const
{
if ( m_width >= width )
return;
m_width = width;
HDC windowDC = GetDC( NULL );
HDC sourceDC = CreateCompatibleDC( windowDC );
if ( m_squiggleRepeatedBitmap )
DeleteObject( m_squiggleRepeatedBitmap );
m_squiggleRepeatedBitmap = CreateCompatibleBitmap( windowDC, width, squiggleHeight );
SelectObject( sourceDC, m_squiggleSourceBitmap );
SelectObject( m_squiggleDC, m_squiggleRepeatedBitmap );
for ( int i = 0; i < width; i += squiggleWidth )
BitBlt( m_squiggleDC, i, 0, squiggleWidth, squiggleHeight, sourceDC, 0, 0, SRCCOPY );
DeleteDC( sourceDC );
ReleaseDC( NULL, windowDC );
}
void TextSquiggle::Draw( HDC target, int xStart, int xEnd, int y ) const
{
Resize( xEnd - xStart );
if ( m_squiggleDC == 0 || m_squiggleRepeatedBitmap == 0 )
return;
BLENDFUNCTION blendFunction = {};
blendFunction.SourceConstantAlpha = 255;
blendFunction.AlphaFormat = AC_SRC_ALPHA;
AlphaBlend( target, xStart, y - squiggleHeight, xEnd - xStart, squiggleHeight, m_squiggleDC, 0, 0, xEnd - xStart, 3, blendFunction );
}