-
Notifications
You must be signed in to change notification settings - Fork 17
/
PaletteView.cpp
154 lines (126 loc) · 3.29 KB
/
PaletteView.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
//
// パターンビュークラス
//
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
#include <string>
using namespace std;
#include "VirtuaNESres.h"
#include "DebugOut.h"
#include "App.h"
#include "Pathlib.h"
#include "Wnd.h"
#include "PaletteView.h"
#include "EmuThread.h"
#include "MMU.h"
#include "DirectDraw.h"
WND_MESSAGE_BEGIN(CPaletteView)
WND_ON_MESSAGE( WM_CREATE, OnCreate )
WND_ON_MESSAGE( WM_CLOSE, OnClose )
WND_ON_MESSAGE( WM_DESTROY, OnDestroy )
WND_ON_MESSAGE( WM_TIMER, OnTimer )
WND_COMMAND_BEGIN()
WND_COMMAND_END()
WND_MESSAGE_END()
CPaletteView::CPaletteView()
{
m_lpPattern = NULL;
if( !(m_lpPattern = (LPBYTE)::malloc( 256*32 )) ) {
throw CApp::GetErrorString( IDS_ERROR_OUTOFMEMORY );
}
}
CPaletteView::~CPaletteView()
{
FREE( m_lpPattern );
}
BOOL CPaletteView::Create( HWND hWndParent )
{
HWND hWnd = CreateWindowEx(
WS_EX_TOOLWINDOW,
VIRTUANES_WNDCLASS,
"PaletteView",
WS_OVERLAPPEDWINDOW, // Window拡大縮小可能
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hWndParent,
NULL,
CApp::GetInstance(),
(LPVOID)this // This を埋め込む為
);
if( !hWnd ) {
DEBUGOUT( "CreateWindow faild.\n" );
return FALSE;
}
m_hWnd = hWnd;
//
::ZeroMemory( &m_BitmapHdr, sizeof(m_BitmapHdr) );
m_BitmapHdr.bih.biSize = sizeof(BITMAPINFOHEADER);
m_BitmapHdr.bih.biWidth = 256;
m_BitmapHdr.bih.biHeight = -32;
m_BitmapHdr.bih.biPlanes = 1;
m_BitmapHdr.bih.biBitCount = 8;
m_BitmapHdr.bih.biCompression = BI_RGB;
m_BitmapHdr.bih.biClrUsed = 32;
DirectDraw.GetPaletteData( m_Palette );
for( INT y = 0; y < 32; y++ ) {
for( INT x = 0; x < 256; x++ ) {
m_lpPattern[x+y*256] = (y>>4)*0x10+(x>>4);
}
}
return TRUE;
}
void CPaletteView::Destroy()
{
if( m_hWnd && IsWindow(m_hWnd) ) {
::DestroyWindow( m_hWnd );
m_hWnd = NULL;
}
}
WNDMSG CPaletteView::OnCreate( WNDMSGPARAM )
{
DEBUGOUT( "CPaletteView::OnCreate\n" );
// 位置修正
RECT rw, rc;
::GetWindowRect( m_hWnd, &rw );
::GetClientRect( m_hWnd, &rc );
INT x = rw.right - rw.left - rc.right + 256;
INT y = rw.bottom - rw.top - rc.bottom + 32;
::MoveWindow( m_hWnd, Config.general.rcPaletteViewPos.left, Config.general.rcPaletteViewPos.top, x, y, FALSE );
::SetTimer( m_hWnd, 1, 50, NULL );
::ShowWindow( m_hWnd, SW_SHOW );
return TRUE;
}
WNDMSG CPaletteView::OnClose( WNDMSGPARAM )
{
DEBUGOUT( "CPaletteView::OnClose\n" );
::KillTimer( m_hWnd, 1 );
::DestroyWindow( m_hWnd );
return TRUE;
}
WNDMSG CPaletteView::OnDestroy( WNDMSGPARAM )
{
DEBUGOUT( "CPaletteView::OnDestroy\n" );
// 位置保存
::GetWindowRect( m_hWnd, &Config.general.rcPaletteViewPos );
m_hWnd = NULL;
return TRUE;
}
WNDMSG CPaletteView::OnTimer( WNDMSGPARAM )
{
if( !Emu.IsRunning() )
return TRUE;
// パレット
for( INT i = 0; i < 16; i++ ) {
m_BitmapHdr.rgb[i] = m_Palette[BGPAL[i]];
m_BitmapHdr.rgb[i+16] = m_Palette[SPPAL[i]];
}
RECT rc;
::GetClientRect( hWnd, &rc );
HDC hDC = ::GetDC( hWnd );
::StretchDIBits( hDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, 0, 0, 256, 32, m_lpPattern, (BITMAPINFO*)&m_BitmapHdr, DIB_RGB_COLORS, SRCCOPY );
::ReleaseDC( hWnd, hDC );
return TRUE;
}