Mercurial > vba-linux
comparison src/win32/ZoomControl.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // ZoomControl.cpp : implementation file | |
2 // | |
3 | |
4 #include "stdafx.h" | |
5 #include "ZoomControl.h" | |
6 | |
7 bool ZoomControl::isRegistered = false; | |
8 | |
9 ///////////////////////////////////////////////////////////////////////////// | |
10 // ZoomControl | |
11 | |
12 ZoomControl::ZoomControl() | |
13 { | |
14 ZeroMemory(colors, 3*64); | |
15 selected = -1; | |
16 registerClass(); | |
17 } | |
18 | |
19 ZoomControl::~ZoomControl() | |
20 {} | |
21 | |
22 BEGIN_MESSAGE_MAP(ZoomControl, CWnd) | |
23 //{{AFX_MSG_MAP(ZoomControl) | |
24 ON_WM_PAINT() | |
25 ON_WM_LBUTTONDOWN() | |
26 ON_WM_ERASEBKGND() | |
27 //}}AFX_MSG_MAP | |
28 END_MESSAGE_MAP() | |
29 | |
30 ///////////////////////////////////////////////////////////////////////////// | |
31 // ZoomControl message handlers | |
32 | |
33 void ZoomControl::registerClass() | |
34 { | |
35 if (!isRegistered) | |
36 { | |
37 WNDCLASS wc; | |
38 ZeroMemory(&wc, sizeof(wc)); | |
39 wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS; | |
40 wc.lpfnWndProc = (WNDPROC) ::DefWindowProc; | |
41 wc.hInstance = AfxGetInstanceHandle(); | |
42 wc.hIcon = NULL; | |
43 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
44 wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); | |
45 wc.lpszMenuName = NULL; | |
46 wc.lpszClassName = "VbaZoomControl"; | |
47 AfxRegisterClass(&wc); | |
48 isRegistered = true; | |
49 } | |
50 } | |
51 | |
52 void ZoomControl::OnPaint() | |
53 { | |
54 CPaintDC dc(this); // device context for painting | |
55 | |
56 RECT rect; | |
57 GetClientRect(&rect); | |
58 | |
59 int w = rect.right - rect.left; | |
60 int h = rect.bottom - rect.top; | |
61 | |
62 CDC memDC ; | |
63 memDC.CreateCompatibleDC(&dc); | |
64 CBitmap bitmap, *pOldBitmap; | |
65 bitmap.CreateCompatibleBitmap(&dc, w, h); | |
66 | |
67 pOldBitmap = memDC.SelectObject(&bitmap); | |
68 | |
69 int multX = w / 8; | |
70 int multY = h / 8; | |
71 | |
72 int i; | |
73 for (i = 0; i < 64; i++) | |
74 { | |
75 CBrush b; | |
76 b.CreateSolidBrush(RGB(colors[i*3+2], colors[i*3+1], colors[i*3])); | |
77 | |
78 RECT r; | |
79 int x = i & 7; | |
80 int y = i / 8; | |
81 r.top = y*multY; | |
82 r.left = x*multX; | |
83 r.bottom = r.top + multY; | |
84 r.right = r.left + multX; | |
85 memDC.FillRect(&r, &b); | |
86 b.DeleteObject(); | |
87 } | |
88 | |
89 CPen pen; | |
90 pen.CreatePen(PS_SOLID, 1, RGB(192, 192, 192)); | |
91 CPen *old = (CPen *)memDC.SelectObject(&pen); | |
92 | |
93 for (i = 0; i < 8; i++) | |
94 { | |
95 memDC.MoveTo(0, i * multY); | |
96 memDC.LineTo(w, i * multY); | |
97 memDC.MoveTo(i * multX, 0); | |
98 memDC.LineTo(i * multX, h); | |
99 } | |
100 | |
101 if (selected != -1) | |
102 { | |
103 CPen pen2; | |
104 pen2.CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); | |
105 CPen *old2 = (CPen *)memDC.SelectObject(&pen2); | |
106 | |
107 int startX = (selected & 7)*multX+1; | |
108 int startY = (selected / 8)*multY+1; | |
109 int endX = startX + multX-2; | |
110 int endY = startY + multY-2; | |
111 | |
112 memDC.MoveTo(startX, startY); | |
113 memDC.LineTo(endX, startY); | |
114 memDC.LineTo(endX, endY); | |
115 memDC.LineTo(startX, endY); | |
116 memDC.LineTo(startX, startY-1); | |
117 memDC.SelectObject(old2); | |
118 pen2.DeleteObject(); | |
119 } | |
120 memDC.SelectObject(old); | |
121 pen.DeleteObject(); | |
122 | |
123 dc.BitBlt(0, 0, w, h, | |
124 &memDC, 0, 0, SRCCOPY); | |
125 | |
126 memDC.SelectObject(pOldBitmap); | |
127 bitmap.DeleteObject(); | |
128 memDC.DeleteDC(); | |
129 } | |
130 | |
131 void ZoomControl::OnLButtonDown(UINT nFlags, CPoint point) | |
132 { | |
133 RECT rect; | |
134 GetClientRect(&rect); | |
135 | |
136 int height = rect.bottom - rect.top; | |
137 int width = rect.right - rect.left; | |
138 | |
139 int multX = width / 8; | |
140 int multY = height / 8; | |
141 | |
142 selected = point.x / multX + 8 * (point.y / multY); | |
143 | |
144 int c = point.x / multX + 8 * (point.y/multY); | |
145 u16 color = colors[c*3] << 7 | | |
146 colors[c*3+1] << 2 | | |
147 (colors[c*3+2] >> 3); | |
148 | |
149 GetParent()->PostMessage(WM_COLINFO, | |
150 color, | |
151 0); | |
152 | |
153 Invalidate(); | |
154 } | |
155 | |
156 BOOL ZoomControl::OnEraseBkgnd(CDC*pDC) | |
157 { | |
158 return TRUE; | |
159 } | |
160 | |
161 void ZoomControl::setColors(const u8 *c) | |
162 { | |
163 memcpy(colors, c, 3*64); | |
164 selected = -1; | |
165 Invalidate(); | |
166 } |