summaryrefslogtreecommitdiff
path: root/win/Colorlst.cpp
blob: e2ede8443fe8409df7b41e7ab14e49f053674916 (plain)
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
// ColorLst.cpp : implementation file
//

#include "stdafx.h"
#include "leocad.h"
#include "ColorLst.h"
#include "globals.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CColorsList

CColorsList::CColorsList()
{
	m_bLowRes = FALSE;
}

CColorsList::~CColorsList()
{
}


BEGIN_MESSAGE_MAP(CColorsList, CListBox)
	//{{AFX_MSG_MAP(CColorsList)
	ON_WM_CREATE()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorsList message handlers

void CColorsList::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	int x = lpDIS->itemID;
	if (x%2 == 0)
		x/=2;
	else
		x = ((x-1)/2)+14;

	if ((!(lpDIS->itemState & ODS_SELECTED) &&
		(lpDIS->itemAction & ODA_SELECT)) ||
		(lpDIS->itemAction & ODA_DRAWENTIRE))
	{
		if (m_bLowRes)
		{
			HBRUSH hbr = CreateSolidBrush(RGB(FlatColorArray[x][0], FlatColorArray[x][1], FlatColorArray[x][2]));
			FillRect(lpDIS->hDC, &lpDIS->rcItem, hbr);
			DeleteObject (hbr);
		}
		else
		{
			SetBkColor(lpDIS->hDC, RGB(FlatColorArray[x][0], FlatColorArray[x][1], FlatColorArray[x][2]));
			ExtTextOut(lpDIS->hDC, 0, 0, ETO_OPAQUE, &lpDIS->rcItem, NULL, 0, NULL);
		}

		if (x > 13 && x < 22)
		for (x = lpDIS->rcItem.left; x < lpDIS->rcItem.right; x++)
		{
			for (int y = lpDIS->rcItem.top; y < lpDIS->rcItem.bottom; y+=4)
			{
				if (y == lpDIS->rcItem.top) y += x%4;
				SetPixelV (lpDIS->hDC, x,y,RGB(255,255,255));
			}
			for (int y = lpDIS->rcItem.bottom; y > lpDIS->rcItem.top; y-=4)
			{
				if (y == lpDIS->rcItem.bottom) y-= x%4;
				SetPixelV (lpDIS->hDC, x,y,RGB(255,255,255));
			}
		}
	}
	
	// item has been selected - hilite frame
	if ((lpDIS->itemState & ODS_SELECTED) &&
		(lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
	{
		HBRUSH hbr = CreateSolidBrush(RGB(255-FlatColorArray[x][0], 255-FlatColorArray[x][1], 255-FlatColorArray[x][2]));
		FrameRect(lpDIS->hDC, &lpDIS->rcItem, hbr);
		DeleteObject (hbr);
	}
}

void CColorsList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	lpMeasureItemStruct->itemHeight = 12;
	lpMeasureItemStruct->itemWidth = 15;
}

BOOL CColorsList::PreTranslateMessage(MSG* pMsg) 
{
	if (m_ToolTip.m_hWnd)
		m_ToolTip.RelayEvent(pMsg);

	return CListBox::PreTranslateMessage(pMsg);
}

int CColorsList::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListBox::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	m_ToolTip.Create(this);
//	m_ToolTip.Activate(TRUE);

	for (int i = 0; i < 14; i++)
	{
		CRect rect (i*15,0,(i+1)*15,12);
		m_ToolTip.AddTool(this, IDS_COLOR01+i, rect, 1);
		rect.OffsetRect (0,12);
		m_ToolTip.AddTool(this, IDS_COLOR15+i, rect, 1);
	}
	
	return 0;
}

void CColorsList::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar == VK_INSERT)
	{
//		project->HandleCommand(LC_PIECE_INSERT, 0);

		CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
		pFrame->PostMessage(WM_COMMAND, ID_PIECE_INSERT, 0);

		CView* pView = pFrame->GetActiveView();
		pView->SetFocus();
	}
	else
		CListBox::OnKeyDown(nChar, nRepCnt, nFlags);
}