-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathC64Palette.cpp
204 lines (152 loc) · 4.21 KB
/
C64Palette.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
Pixcen - A windows platform low level pixel editor for C64
Copyright (C) 2013 John Hammarberg ([email protected])
This file is part of Pixcen.
Pixcen is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pixcen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pixcen. If not, see <http://www.gnu.org/licenses/>.
*/
// C64Palette.cpp : implementation file
//
#include "stdafx.h"
#include "Pixcen.h"
#include "C64Palette.h"
#include "afxdialogex.h"
#include "C64Col.h"
// C64Palette dialog
IMPLEMENT_DYNAMIC(C64Palette, CToolDialog)
C64Palette::C64Palette(CWnd* pParent /*=NULL*/)
: CToolDialog(C64Palette::IDD, pParent)
{
col1=1;
col2=0;
}
C64Palette::~C64Palette()
{
}
void C64Palette::DoDataExchange(CDataExchange* pDX)
{
CToolDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(C64Palette, CToolDialog)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
// ON_MESSAGE(UM_SEL_COL1, &C64Palette::OnUmSelCol1)
END_MESSAGE_MAP()
// C64Palette message handlers
void C64Palette::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CToolDialog::OnPaint() for painting messages
CRect rc;
GetClientRect(rc);
int x,y;
int h=rc.bottom/8;
int w=rc.right/2;
for(x=0;x<2;x++)
{
for(y=0;y<8;y++)
{
dc.FillSolidRect(x*w,y*h,w,h,g_Vic2[x*8+y]);
if(x*8+y == col1)
{
DrawSquare(dc,x*w,y*h,w,h,col1);
}
if(x*8+y == col2)
{
DrawEx(dc,x*w,y*h,w,h,col2);
}
}
}
}
void C64Palette::DrawSquare(CPaintDC &dc, int x, int y, int w, int h, int c)
{
CPen *old=dc.SelectObject(c==0?&(m_wpen):(&m_bpen));
dc.MoveTo(x+3,y+3);
dc.LineTo(x+w-3,y+3);
dc.LineTo(x+w-3,y+h-3);
dc.LineTo(x+3,y+h-3);
dc.LineTo(x+3,y+2);
dc.SelectObject(old);
}
void C64Palette::DrawEx(CPaintDC &dc, int x, int y, int w, int h, int c)
{
CPen *old=dc.SelectObject(c==0?&(m_wpen):(&m_bpen));
dc.MoveTo(x+8,y+8);
dc.LineTo(x+w-8,y+h-8);
dc.MoveTo(x+w-8,y+8);
dc.LineTo(x+8,y+h-8);
dc.SelectObject(old);
}
void C64Palette::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Mail(MSG_PAL_SEL_COL,GetIndex(point),0);
CToolDialog::OnLButtonDown(nFlags, point);
}
void C64Palette::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Mail(MSG_PAL_SEL_COL,GetIndex(point),1);
CToolDialog::OnRButtonDown(nFlags, point);
}
int C64Palette::GetIndex(CPoint &point)
{
CRect rc;
GetClientRect(rc);
int h=rc.bottom/8;
int w=rc.right/2;
int x=point.x/w;
int y=point.y/h;
return x*8+y;
}
//void C64Palette::PreInitDialog()
//{
// // TODO: Add your specialized code here and/or call the base class
//
// CToolDialog::PreInitDialog();
//}
BOOL C64Palette::OnInitDialog()
{
CToolDialog::OnInitDialog();
// TODO: Add extra initialization here
m_wpen.CreatePen(PS_SOLID,2,COLORREF(0x00ffffff));
m_bpen.CreatePen(PS_SOLID,2,COLORREF(0x00000000));
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//Incomming message to force set col1
//afx_msg LRESULT C64Palette::OnUmSelCol1(WPARAM wParam, LPARAM lParam)
//{
// col1 = int(wParam);
// m_pParent->PostMessage(UM_SEL_COL1,WPARAM(col1),NULL);
// Invalidate();
// return 0;
//}
void C64Palette::Receive(unsigned short message, UINT_PTR data, unsigned short extra)
{
switch(message)
{
case MSG_PAL_SEL_COL:
if(!extra)
col1 = int(data);
else
col2 = int(data);
Invalidate();
break;
case MSG_REFRESH:
Invalidate();
break;
default:
break;
}
}