annotate src/win32/ZoomControl.cpp @ 8:08a8e09ca414

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