annotate src/win32/ColorControl.cpp @ 2:3549bbe597ed

adding makefile.am
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:47 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // ColorControl.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "ColorControl.h"
rlm@1 6
rlm@1 7 bool ColorControl::isRegistered = false;
rlm@1 8
rlm@1 9 /////////////////////////////////////////////////////////////////////////////
rlm@1 10 // ColorControl
rlm@1 11
rlm@1 12 ColorControl::ColorControl()
rlm@1 13 {
rlm@1 14 color = 0;
rlm@1 15 registerClass();
rlm@1 16 }
rlm@1 17
rlm@1 18 ColorControl::~ColorControl()
rlm@1 19 {
rlm@1 20 }
rlm@1 21
rlm@1 22
rlm@1 23 BEGIN_MESSAGE_MAP(ColorControl, CWnd)
rlm@1 24 //{{AFX_MSG_MAP(ColorControl)
rlm@1 25 ON_WM_PAINT()
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 /////////////////////////////////////////////////////////////////////////////
rlm@1 32 // ColorControl message handlers
rlm@1 33
rlm@1 34 void ColorControl::OnPaint()
rlm@1 35 {
rlm@1 36 CPaintDC dc(this); // device context for painting
rlm@1 37 }
rlm@1 38
rlm@1 39 BOOL ColorControl::OnEraseBkgnd(CDC* pDC)
rlm@1 40 {
rlm@1 41 int r = (color & 0x1f) << 3;
rlm@1 42 int g = (color & 0x3e0) >> 2;
rlm@1 43 int b = (color & 0x7c00) >> 7;
rlm@1 44
rlm@1 45 CBrush br;
rlm@1 46 br.CreateSolidBrush(RGB(r,g,b));
rlm@1 47
rlm@1 48 RECT rect;
rlm@1 49 GetClientRect(&rect);
rlm@1 50 pDC->FillRect(&rect,&br);
rlm@1 51 pDC->DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
rlm@1 52 br.DeleteObject();
rlm@1 53 return TRUE;
rlm@1 54 }
rlm@1 55
rlm@1 56 void ColorControl::setColor(u16 c)
rlm@1 57 {
rlm@1 58 color = c;
rlm@1 59 Invalidate();
rlm@1 60 }
rlm@1 61
rlm@1 62 void ColorControl::registerClass()
rlm@1 63 {
rlm@1 64 if(!isRegistered) {
rlm@1 65 WNDCLASS wc;
rlm@1 66 ZeroMemory(&wc, sizeof(wc));
rlm@1 67 wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
rlm@1 68 wc.lpfnWndProc = (WNDPROC)::DefWindowProc;
rlm@1 69 wc.hInstance = AfxGetInstanceHandle();
rlm@1 70 wc.hIcon = NULL;
rlm@1 71 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
rlm@1 72 wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
rlm@1 73 wc.lpszMenuName = NULL;
rlm@1 74 wc.lpszClassName = "VbaColorControl";
rlm@1 75 AfxRegisterClass(&wc);
rlm@1 76 isRegistered = true;
rlm@1 77 }
rlm@1 78 }