diff src/win32/OamView.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/OamView.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,668 @@
     1.4 +// OamView.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "OamView.h"
    1.10 +#include "FileDlg.h"
    1.11 +#include "Reg.h"
    1.12 +#include "WinResUtil.h"
    1.13 +#include "VBA.h"
    1.14 +
    1.15 +#include "../gba/GBAGlobals.h"
    1.16 +#include "../NLS.h"
    1.17 +#include "../common/Util.h"
    1.18 +
    1.19 +extern "C" {
    1.20 +#include <png.h>
    1.21 +}
    1.22 +
    1.23 +/////////////////////////////////////////////////////////////////////////////
    1.24 +// OamView dialog
    1.25 +
    1.26 +OamView::OamView(CWnd*pParent /*=NULL*/)
    1.27 +	: ResizeDlg(OamView::IDD, pParent)
    1.28 +{
    1.29 +	//{{AFX_DATA_INIT(OamView)
    1.30 +	m_stretch = FALSE;
    1.31 +	//}}AFX_DATA_INIT
    1.32 +	autoUpdate = false;
    1.33 +
    1.34 +	memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
    1.35 +
    1.36 +	bmpInfo.bmiHeader.biSize        = sizeof(bmpInfo.bmiHeader);
    1.37 +	bmpInfo.bmiHeader.biWidth       = 32;
    1.38 +	bmpInfo.bmiHeader.biHeight      = 32;
    1.39 +	bmpInfo.bmiHeader.biPlanes      = 1;
    1.40 +	bmpInfo.bmiHeader.biBitCount    = 24;
    1.41 +	bmpInfo.bmiHeader.biCompression = BI_RGB;
    1.42 +	data = (u8 *)calloc(1, 3 * 64 * 64);
    1.43 +
    1.44 +	oamView.setData(data);
    1.45 +	oamView.setBmpInfo(&bmpInfo);
    1.46 +
    1.47 +	number = 0;
    1.48 +}
    1.49 +
    1.50 +void OamView::DoDataExchange(CDataExchange*pDX)
    1.51 +{
    1.52 +	CDialog::DoDataExchange(pDX);
    1.53 +	//{{AFX_DATA_MAP(OamView)
    1.54 +	DDX_Control(pDX, IDC_SPRITE, m_sprite);
    1.55 +	DDX_Check(pDX, IDC_STRETCH, m_stretch);
    1.56 +	//}}AFX_DATA_MAP
    1.57 +	DDX_Control(pDX, IDC_COLOR, color);
    1.58 +	DDX_Control(pDX, IDC_OAM_VIEW, oamView);
    1.59 +	DDX_Control(pDX, IDC_OAM_VIEW_ZOOM, oamZoom);
    1.60 +}
    1.61 +
    1.62 +BEGIN_MESSAGE_MAP(OamView, CDialog)
    1.63 +//{{AFX_MSG_MAP(OamView)
    1.64 +ON_BN_CLICKED(IDC_SAVE, OnSave)
    1.65 +ON_BN_CLICKED(IDC_STRETCH, OnStretch)
    1.66 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
    1.67 +ON_EN_CHANGE(IDC_SPRITE, OnChangeSprite)
    1.68 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
    1.69 +ON_WM_HSCROLL()
    1.70 +//}}AFX_MSG_MAP
    1.71 +ON_MESSAGE(WM_MAPINFO, OnMapInfo)
    1.72 +ON_MESSAGE(WM_COLINFO, OnColInfo)
    1.73 +END_MESSAGE_MAP()
    1.74 +
    1.75 +/////////////////////////////////////////////////////////////////////////////
    1.76 +// OamView message handlers
    1.77 +
    1.78 +OamView::~OamView()
    1.79 +{
    1.80 +	free(data);
    1.81 +	data = NULL;
    1.82 +}
    1.83 +
    1.84 +void OamView::paint()
    1.85 +{
    1.86 +	if (oam == NULL || paletteRAM == NULL || vram == NULL)
    1.87 +		return;
    1.88 +
    1.89 +	render();
    1.90 +	oamView.setSize(w, h);
    1.91 +	oamView.refresh();
    1.92 +}
    1.93 +
    1.94 +void OamView::update()
    1.95 +{
    1.96 +	paint();
    1.97 +}
    1.98 +
    1.99 +void OamView::setAttributes(u16 a0, u16 a1, u16 a2)
   1.100 +{
   1.101 +	CString buffer;
   1.102 +
   1.103 +	int y        = a0 & 255;
   1.104 +	int rot      = a0 & 512;
   1.105 +	int mode     = (a0 >> 10) & 3;
   1.106 +	int mosaic   = a0 & 4096;
   1.107 +	int color    = a0 & 8192;
   1.108 +	int duple    = a0 & 1024;
   1.109 +	int shape    = (a0 >> 14) & 3;
   1.110 +	int x        = a1 & 511;
   1.111 +	int rotParam = (a1 >> 9) & 31;
   1.112 +	int flipH    = a1 & 4096;
   1.113 +	int flipV    = a1 & 8192;
   1.114 +	int size     = (a1 >> 14) & 3;
   1.115 +	int tile     = a2 & 1023;
   1.116 +	int prio     = (a2 >> 10) & 3;
   1.117 +	int pal      = (a2 >> 12) & 15;
   1.118 +
   1.119 +	buffer.Format("%d,%d", x, y);
   1.120 +	GetDlgItem(IDC_POS)->SetWindowText(buffer);
   1.121 +
   1.122 +	buffer.Format("%d", mode);
   1.123 +	GetDlgItem(IDC_MODE)->SetWindowText(buffer);
   1.124 +
   1.125 +	GetDlgItem(IDC_COLORS)->SetWindowText(color ? "256" : "16");
   1.126 +
   1.127 +	buffer.Format("%d", pal);
   1.128 +	GetDlgItem(IDC_PALETTE)->SetWindowText(buffer);
   1.129 +
   1.130 +	buffer.Format("%d", tile);
   1.131 +	GetDlgItem(IDC_TILE)->SetWindowText(buffer);
   1.132 +
   1.133 +	buffer.Format("%d", prio);
   1.134 +	GetDlgItem(IDC_PRIO)->SetWindowText(buffer);
   1.135 +
   1.136 +	buffer.Format("%d,%d", w, h);
   1.137 +	GetDlgItem(IDC_SIZE2)->SetWindowText(buffer);
   1.138 +
   1.139 +	if (rot)
   1.140 +	{
   1.141 +		buffer.Format("%d", rotParam);
   1.142 +	}
   1.143 +	else
   1.144 +		buffer.Empty();
   1.145 +	GetDlgItem(IDC_ROT)->SetWindowText(buffer);
   1.146 +
   1.147 +	buffer.Empty();
   1.148 +
   1.149 +	if (rot)
   1.150 +		buffer += 'R';
   1.151 +	else
   1.152 +		buffer += ' ';
   1.153 +	if (!rot)
   1.154 +	{
   1.155 +		if (flipH)
   1.156 +			buffer += 'H';
   1.157 +		else
   1.158 +			buffer += ' ';
   1.159 +		if (flipV)
   1.160 +			buffer += 'V';
   1.161 +		else
   1.162 +			buffer += ' ';
   1.163 +	}
   1.164 +	else
   1.165 +	{
   1.166 +		buffer += ' ';
   1.167 +		buffer += ' ';
   1.168 +	}
   1.169 +	if (mosaic)
   1.170 +		buffer += 'M';
   1.171 +	else
   1.172 +		buffer += ' ';
   1.173 +	if (duple)
   1.174 +		buffer += 'D';
   1.175 +	else
   1.176 +		buffer += ' ';
   1.177 +
   1.178 +	GetDlgItem(IDC_FLAGS)->SetWindowText(buffer);
   1.179 +}
   1.180 +
   1.181 +void OamView::render()
   1.182 +{
   1.183 +	int m = 0;
   1.184 +	if (oam == NULL || paletteRAM == NULL || vram == NULL)
   1.185 +		return;
   1.186 +
   1.187 +	u16 *sprites       = &((u16 *)oam)[4*number];
   1.188 +	u16 *spritePalette = &((u16 *)paletteRAM)[0x100];
   1.189 +	u8 * bmp = data;
   1.190 +
   1.191 +	u16 a0 = *sprites++;
   1.192 +	u16 a1 = *sprites++;
   1.193 +	u16 a2 = *sprites++;
   1.194 +
   1.195 +	int sizeY = 8;
   1.196 +	int sizeX = 8;
   1.197 +
   1.198 +	switch (((a0 >>12) & 0x0c)|(a1>>14))
   1.199 +	{
   1.200 +	case 0:
   1.201 +		break;
   1.202 +	case 1:
   1.203 +		sizeX = sizeY = 16;
   1.204 +		break;
   1.205 +	case 2:
   1.206 +		sizeX = sizeY = 32;
   1.207 +		break;
   1.208 +	case 3:
   1.209 +		sizeX = sizeY = 64;
   1.210 +		break;
   1.211 +	case 4:
   1.212 +		sizeX = 16;
   1.213 +		break;
   1.214 +	case 5:
   1.215 +		sizeX = 32;
   1.216 +		break;
   1.217 +	case 6:
   1.218 +		sizeX = 32;
   1.219 +		sizeY = 16;
   1.220 +		break;
   1.221 +	case 7:
   1.222 +		sizeX = 64;
   1.223 +		sizeY = 32;
   1.224 +		break;
   1.225 +	case 8:
   1.226 +		sizeY = 16;
   1.227 +		break;
   1.228 +	case 9:
   1.229 +		sizeY = 32;
   1.230 +		break;
   1.231 +	case 10:
   1.232 +		sizeX = 16;
   1.233 +		sizeY = 32;
   1.234 +		break;
   1.235 +	case 11:
   1.236 +		sizeX = 32;
   1.237 +		sizeY = 64;
   1.238 +		break;
   1.239 +	default:
   1.240 +		return;
   1.241 +	}
   1.242 +
   1.243 +	w = sizeX;
   1.244 +	h = sizeY;
   1.245 +
   1.246 +	setAttributes(a0, a1, a2);
   1.247 +
   1.248 +	int sy = (a0 & 255);
   1.249 +
   1.250 +	if (a0 & 0x2000)
   1.251 +	{
   1.252 +		int c = (a2 & 0x3FF);
   1.253 +		//          if((DISPCNT & 7) > 2 && (c < 512))
   1.254 +		//            return;
   1.255 +		int inc = 32;
   1.256 +		if (DISPCNT & 0x40)
   1.257 +			inc = sizeX >> 2;
   1.258 +		else
   1.259 +			c &= 0x3FE;
   1.260 +
   1.261 +		for (int y = 0; y < sizeY; y++)
   1.262 +		{
   1.263 +			for (int x = 0; x < sizeX; x++)
   1.264 +			{
   1.265 +				u32 color = vram[0x10000 + (((c + (y>>3) * inc)*
   1.266 +				                             32 + (y & 7) * 8 + (x >> 3) * 64 +
   1.267 +				                             (x & 7))&0x7FFF)];
   1.268 +				color  = spritePalette[color];
   1.269 +				*bmp++ = ((color >> 10) & 0x1f) << 3;
   1.270 +				*bmp++ = ((color >> 5) & 0x1f) << 3;
   1.271 +				*bmp++ = (color & 0x1f) << 3;
   1.272 +			}
   1.273 +		}
   1.274 +	}
   1.275 +	else
   1.276 +	{
   1.277 +		int c = (a2 & 0x3FF);
   1.278 +		//      if((DISPCNT & 7) > 2 && (c < 512))
   1.279 +		//          continue;
   1.280 +
   1.281 +		int inc = 32;
   1.282 +		if (DISPCNT & 0x40)
   1.283 +			inc = sizeX >> 3;
   1.284 +		int palette = (a2 >> 8) & 0xF0;
   1.285 +		for (int y = 0; y < sizeY; y++)
   1.286 +		{
   1.287 +			for (int x = 0; x < sizeX; x++)
   1.288 +			{
   1.289 +				u32 color = vram[0x10000 + (((c + (y>>3) * inc)*
   1.290 +				                             32 + (y & 7) * 4 + (x >> 3) * 32 +
   1.291 +				                             ((x & 7)>>1))&0x7FFF)];
   1.292 +				if (x & 1)
   1.293 +					color >>= 4;
   1.294 +				else
   1.295 +					color &= 0x0F;
   1.296 +
   1.297 +				color  = spritePalette[palette+color];
   1.298 +				*bmp++ = ((color >> 10) & 0x1f) << 3;
   1.299 +				*bmp++ = ((color >> 5) & 0x1f) << 3;
   1.300 +				*bmp++ = (color & 0x1f) << 3;
   1.301 +			}
   1.302 +		}
   1.303 +	}
   1.304 +}
   1.305 +
   1.306 +void OamView::saveBMP(const char *name)
   1.307 +{
   1.308 +	u8 writeBuffer[1024 * 3];
   1.309 +
   1.310 +	FILE *fp = fopen(name, "wb");
   1.311 +
   1.312 +	if (!fp)
   1.313 +	{
   1.314 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
   1.315 +		return;
   1.316 +	}
   1.317 +
   1.318 +	struct
   1.319 +	{
   1.320 +		u8 ident[2];
   1.321 +		u8 filesize[4];
   1.322 +		u8 reserved[4];
   1.323 +		u8 dataoffset[4];
   1.324 +		u8 headersize[4];
   1.325 +		u8 width[4];
   1.326 +		u8 height[4];
   1.327 +		u8 planes[2];
   1.328 +		u8 bitsperpixel[2];
   1.329 +		u8 compression[4];
   1.330 +		u8 datasize[4];
   1.331 +		u8 hres[4];
   1.332 +		u8 vres[4];
   1.333 +		u8 colors[4];
   1.334 +		u8 importantcolors[4];
   1.335 +		u8 pad[2];
   1.336 +	} bmpheader;
   1.337 +	memset(&bmpheader, 0, sizeof(bmpheader));
   1.338 +
   1.339 +	bmpheader.ident[0] = 'B';
   1.340 +	bmpheader.ident[1] = 'M';
   1.341 +
   1.342 +	u32 fsz = sizeof(bmpheader) + w*h*3;
   1.343 +	utilPutDword(bmpheader.filesize, fsz);
   1.344 +	utilPutDword(bmpheader.dataoffset, 0x38);
   1.345 +	utilPutDword(bmpheader.headersize, 0x28);
   1.346 +	utilPutDword(bmpheader.width, w);
   1.347 +	utilPutDword(bmpheader.height, h);
   1.348 +	utilPutDword(bmpheader.planes, 1);
   1.349 +	utilPutDword(bmpheader.bitsperpixel, 24);
   1.350 +	utilPutDword(bmpheader.datasize, 3*w*h);
   1.351 +
   1.352 +	fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
   1.353 +
   1.354 +	u8 *b = writeBuffer;
   1.355 +
   1.356 +	int sizeX = w;
   1.357 +	int sizeY = h;
   1.358 +
   1.359 +	u8 *pixU8 = (u8 *)data+3*w*(h-1);
   1.360 +	for (int y = 0; y < sizeY; y++)
   1.361 +	{
   1.362 +		for (int x = 0; x < sizeX; x++)
   1.363 +		{
   1.364 +			*b++ = *pixU8++; // B
   1.365 +			*b++ = *pixU8++; // G
   1.366 +			*b++ = *pixU8++; // R
   1.367 +		}
   1.368 +		pixU8 -= 2*3*w;
   1.369 +		fwrite(writeBuffer, 1, 3*w, fp);
   1.370 +
   1.371 +		b = writeBuffer;
   1.372 +	}
   1.373 +
   1.374 +	fclose(fp);
   1.375 +}
   1.376 +
   1.377 +void OamView::savePNG(const char *name)
   1.378 +{
   1.379 +	u8 writeBuffer[1024 * 3];
   1.380 +
   1.381 +	FILE *fp = fopen(name, "wb");
   1.382 +
   1.383 +	if (!fp)
   1.384 +	{
   1.385 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
   1.386 +		return;
   1.387 +	}
   1.388 +
   1.389 +	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
   1.390 +	                                              NULL,
   1.391 +	                                              NULL,
   1.392 +	                                              NULL);
   1.393 +	if (!png_ptr)
   1.394 +	{
   1.395 +		fclose(fp);
   1.396 +		return;
   1.397 +	}
   1.398 +
   1.399 +	png_infop info_ptr = png_create_info_struct(png_ptr);
   1.400 +
   1.401 +	if (!info_ptr)
   1.402 +	{
   1.403 +		png_destroy_write_struct(&png_ptr, NULL);
   1.404 +		fclose(fp);
   1.405 +		return;
   1.406 +	}
   1.407 +
   1.408 +	if (setjmp(png_ptr->jmpbuf))
   1.409 +	{
   1.410 +		png_destroy_write_struct(&png_ptr, NULL);
   1.411 +		fclose(fp);
   1.412 +		return;
   1.413 +	}
   1.414 +
   1.415 +	png_init_io(png_ptr, fp);
   1.416 +
   1.417 +	png_set_IHDR(png_ptr,
   1.418 +	             info_ptr,
   1.419 +	             w,
   1.420 +	             h,
   1.421 +	             8,
   1.422 +	             PNG_COLOR_TYPE_RGB,
   1.423 +	             PNG_INTERLACE_NONE,
   1.424 +	             PNG_COMPRESSION_TYPE_DEFAULT,
   1.425 +	             PNG_FILTER_TYPE_DEFAULT);
   1.426 +
   1.427 +	png_write_info(png_ptr, info_ptr);
   1.428 +
   1.429 +	u8 *b = writeBuffer;
   1.430 +
   1.431 +	int sizeX = w;
   1.432 +	int sizeY = h;
   1.433 +
   1.434 +	u8 *pixU8 = (u8 *)data;
   1.435 +	for (int y = 0; y < sizeY; y++)
   1.436 +	{
   1.437 +		for (int x = 0; x < sizeX; x++)
   1.438 +		{
   1.439 +			int blue  = *pixU8++;
   1.440 +			int green = *pixU8++;
   1.441 +			int red   = *pixU8++;
   1.442 +
   1.443 +			*b++ = red;
   1.444 +			*b++ = green;
   1.445 +			*b++ = blue;
   1.446 +		}
   1.447 +		png_write_row(png_ptr, writeBuffer);
   1.448 +
   1.449 +		b = writeBuffer;
   1.450 +	}
   1.451 +
   1.452 +	png_write_end(png_ptr, info_ptr);
   1.453 +
   1.454 +	png_destroy_write_struct(&png_ptr, &info_ptr);
   1.455 +
   1.456 +	fclose(fp);
   1.457 +}
   1.458 +
   1.459 +void OamView::OnSave()
   1.460 +{
   1.461 +	CString captureBuffer;
   1.462 +
   1.463 +	if (theApp.captureFormat == 0)
   1.464 +		captureBuffer = "oam.png";
   1.465 +	else
   1.466 +		captureBuffer = "oam.bmp";
   1.467 +
   1.468 +	LPCTSTR exts[] = {".png", ".bmp", NULL };
   1.469 +
   1.470 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
   1.471 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
   1.472 +
   1.473 +	FileDlg dlg(this,
   1.474 +	            captureBuffer,
   1.475 +	            filter,
   1.476 +	            theApp.captureFormat ? 2 : 1,
   1.477 +	            theApp.captureFormat ? "BMP" : "PNG",
   1.478 +	            exts,
   1.479 +	            "",
   1.480 +	            title,
   1.481 +	            true);
   1.482 +
   1.483 +	if (dlg.DoModal() == IDCANCEL)
   1.484 +	{
   1.485 +		return;
   1.486 +	}
   1.487 +	captureBuffer = dlg.GetPathName();
   1.488 +
   1.489 +	if (dlg.getFilterIndex() == 2)
   1.490 +		saveBMP(captureBuffer);
   1.491 +	else
   1.492 +		savePNG(captureBuffer);
   1.493 +}
   1.494 +
   1.495 +BOOL OamView::OnInitDialog()
   1.496 +{
   1.497 +	CDialog::OnInitDialog();
   1.498 +
   1.499 +	DIALOG_SIZER_START(sz)
   1.500 +	DIALOG_SIZER_ENTRY(IDC_OAM_VIEW, DS_SizeX | DS_SizeY)
   1.501 +	DIALOG_SIZER_ENTRY(IDC_OAM_VIEW_ZOOM, DS_MoveX)
   1.502 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
   1.503 +	DIALOG_SIZER_ENTRY(IDC_SAVE,  DS_MoveY)
   1.504 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
   1.505 +	DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
   1.506 +	DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
   1.507 +	DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
   1.508 +	DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
   1.509 +	DIALOG_SIZER_END()
   1.510 +	SetData(sz,
   1.511 +	        TRUE,
   1.512 +	        HKEY_CURRENT_USER,
   1.513 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\OamView",
   1.514 +	        NULL);
   1.515 +
   1.516 +	m_sprite.SetWindowText("0");
   1.517 +
   1.518 +	updateScrollInfo();
   1.519 +
   1.520 +	m_stretch = regQueryDwordValue("oamViewStretch", 0);
   1.521 +	if (m_stretch)
   1.522 +		oamView.setStretch(true);
   1.523 +	UpdateData(FALSE);
   1.524 +
   1.525 +	paint();
   1.526 +
   1.527 +	return TRUE; // return TRUE unless you set the focus to a control
   1.528 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.529 +}
   1.530 +
   1.531 +void OamView::OnStretch()
   1.532 +{
   1.533 +	oamView.setStretch(!oamView.getStretch());
   1.534 +	paint();
   1.535 +	regSetDwordValue("oamViewStretch", oamView.getStretch());
   1.536 +}
   1.537 +
   1.538 +void OamView::OnAutoUpdate()
   1.539 +{
   1.540 +	autoUpdate = !autoUpdate;
   1.541 +	if (autoUpdate)
   1.542 +	{
   1.543 +		theApp.winAddUpdateListener(this);
   1.544 +	}
   1.545 +	else
   1.546 +	{
   1.547 +		theApp.winRemoveUpdateListener(this);
   1.548 +	}
   1.549 +}
   1.550 +
   1.551 +void OamView::OnChangeSprite()
   1.552 +{
   1.553 +	CString buffer;
   1.554 +	m_sprite.GetWindowText(buffer);
   1.555 +	int n = atoi(buffer);
   1.556 +	if (n < 0 || n > 127)
   1.557 +	{
   1.558 +		buffer.Format("%d", number);
   1.559 +		m_sprite.SetWindowText(buffer);
   1.560 +		return;
   1.561 +	}
   1.562 +	number = n;
   1.563 +	paint();
   1.564 +	updateScrollInfo();
   1.565 +}
   1.566 +
   1.567 +void OamView::OnClose()
   1.568 +{
   1.569 +	theApp.winRemoveUpdateListener(this);
   1.570 +
   1.571 +	DestroyWindow();
   1.572 +}
   1.573 +
   1.574 +LRESULT OamView::OnMapInfo(WPARAM wParam, LPARAM lParam)
   1.575 +{
   1.576 +	u8 *colors = (u8 *)lParam;
   1.577 +	oamZoom.setColors(colors);
   1.578 +
   1.579 +	return TRUE;
   1.580 +}
   1.581 +
   1.582 +LRESULT OamView::OnColInfo(WPARAM wParam, LPARAM lParam)
   1.583 +{
   1.584 +	u16 c = (u16)wParam;
   1.585 +
   1.586 +	color.setColor(c);
   1.587 +
   1.588 +	int r = (c & 0x1f);
   1.589 +	int g = (c & 0x3e0) >> 5;
   1.590 +	int b = (c & 0x7c00) >> 10;
   1.591 +
   1.592 +	CString buffer;
   1.593 +	buffer.Format("R: %d", r);
   1.594 +	GetDlgItem(IDC_R)->SetWindowText(buffer);
   1.595 +
   1.596 +	buffer.Format("G: %d", g);
   1.597 +	GetDlgItem(IDC_G)->SetWindowText(buffer);
   1.598 +
   1.599 +	buffer.Format("B: %d", b);
   1.600 +	GetDlgItem(IDC_B)->SetWindowText(buffer);
   1.601 +
   1.602 +	return TRUE;
   1.603 +}
   1.604 +
   1.605 +void OamView::updateScrollInfo()
   1.606 +{
   1.607 +	SCROLLINFO si;
   1.608 +	ZeroMemory(&si, sizeof(si));
   1.609 +	si.cbSize = sizeof(si);
   1.610 +	si.fMask  = SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL | SIF_POS;
   1.611 +	si.nMin   = 0;
   1.612 +	si.nMax   = 127;
   1.613 +	si.nPage  = 1;
   1.614 +	si.nPos   = number;
   1.615 +	GetDlgItem(IDC_SCROLLBAR)->SetScrollInfo(SB_CTL,
   1.616 +	                                         &si,
   1.617 +	                                         TRUE);
   1.618 +}
   1.619 +
   1.620 +void OamView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
   1.621 +{
   1.622 +	switch (nSBCode)
   1.623 +	{
   1.624 +	case SB_BOTTOM:
   1.625 +		number = 127;
   1.626 +		break;
   1.627 +	case SB_LINEDOWN:
   1.628 +		number++;
   1.629 +		if (number > 127)
   1.630 +			number = 127;
   1.631 +		break;
   1.632 +	case SB_LINEUP:
   1.633 +		number--;
   1.634 +		if (number < 0)
   1.635 +			number = 0;
   1.636 +		break;
   1.637 +	case SB_PAGEDOWN:
   1.638 +		number += 16;
   1.639 +		if (number > 127)
   1.640 +			number = 127;
   1.641 +		break;
   1.642 +	case SB_PAGEUP:
   1.643 +		number -= 16;
   1.644 +		if (number < 0)
   1.645 +			number = 0;
   1.646 +		break;
   1.647 +	case SB_TOP:
   1.648 +		number = 0;
   1.649 +		break;
   1.650 +	case SB_THUMBTRACK:
   1.651 +		number = nPos;
   1.652 +		if (number < 0)
   1.653 +			number = 0;
   1.654 +		if (number > 127)
   1.655 +			number = 127;
   1.656 +		break;
   1.657 +	}
   1.658 +
   1.659 +	updateScrollInfo();
   1.660 +
   1.661 +	CString buffer;
   1.662 +	buffer.Format("%d", number);
   1.663 +	m_sprite.SetWindowText(buffer);
   1.664 +	paint();
   1.665 +}
   1.666 +
   1.667 +void OamView::PostNcDestroy()
   1.668 +{
   1.669 +	delete this;
   1.670 +}
   1.671 +