annotate src/win32/OamView.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 // OamView.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "resource.h"
rlm@1 6 #include "OamView.h"
rlm@1 7 #include "FileDlg.h"
rlm@1 8 #include "Reg.h"
rlm@1 9 #include "WinResUtil.h"
rlm@1 10 #include "VBA.h"
rlm@1 11
rlm@1 12 #include "../gba/GBAGlobals.h"
rlm@1 13 #include "../NLS.h"
rlm@1 14 #include "../common/Util.h"
rlm@1 15
rlm@1 16 extern "C" {
rlm@1 17 #include <png.h>
rlm@1 18 }
rlm@1 19
rlm@1 20 /////////////////////////////////////////////////////////////////////////////
rlm@1 21 // OamView dialog
rlm@1 22
rlm@1 23 OamView::OamView(CWnd*pParent /*=NULL*/)
rlm@1 24 : ResizeDlg(OamView::IDD, pParent)
rlm@1 25 {
rlm@1 26 //{{AFX_DATA_INIT(OamView)
rlm@1 27 m_stretch = FALSE;
rlm@1 28 //}}AFX_DATA_INIT
rlm@1 29 autoUpdate = false;
rlm@1 30
rlm@1 31 memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
rlm@1 32
rlm@1 33 bmpInfo.bmiHeader.biSize = sizeof(bmpInfo.bmiHeader);
rlm@1 34 bmpInfo.bmiHeader.biWidth = 32;
rlm@1 35 bmpInfo.bmiHeader.biHeight = 32;
rlm@1 36 bmpInfo.bmiHeader.biPlanes = 1;
rlm@1 37 bmpInfo.bmiHeader.biBitCount = 24;
rlm@1 38 bmpInfo.bmiHeader.biCompression = BI_RGB;
rlm@1 39 data = (u8 *)calloc(1, 3 * 64 * 64);
rlm@1 40
rlm@1 41 oamView.setData(data);
rlm@1 42 oamView.setBmpInfo(&bmpInfo);
rlm@1 43
rlm@1 44 number = 0;
rlm@1 45 }
rlm@1 46
rlm@1 47 void OamView::DoDataExchange(CDataExchange*pDX)
rlm@1 48 {
rlm@1 49 CDialog::DoDataExchange(pDX);
rlm@1 50 //{{AFX_DATA_MAP(OamView)
rlm@1 51 DDX_Control(pDX, IDC_SPRITE, m_sprite);
rlm@1 52 DDX_Check(pDX, IDC_STRETCH, m_stretch);
rlm@1 53 //}}AFX_DATA_MAP
rlm@1 54 DDX_Control(pDX, IDC_COLOR, color);
rlm@1 55 DDX_Control(pDX, IDC_OAM_VIEW, oamView);
rlm@1 56 DDX_Control(pDX, IDC_OAM_VIEW_ZOOM, oamZoom);
rlm@1 57 }
rlm@1 58
rlm@1 59 BEGIN_MESSAGE_MAP(OamView, CDialog)
rlm@1 60 //{{AFX_MSG_MAP(OamView)
rlm@1 61 ON_BN_CLICKED(IDC_SAVE, OnSave)
rlm@1 62 ON_BN_CLICKED(IDC_STRETCH, OnStretch)
rlm@1 63 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
rlm@1 64 ON_EN_CHANGE(IDC_SPRITE, OnChangeSprite)
rlm@1 65 ON_BN_CLICKED(IDC_CLOSE, OnClose)
rlm@1 66 ON_WM_HSCROLL()
rlm@1 67 //}}AFX_MSG_MAP
rlm@1 68 ON_MESSAGE(WM_MAPINFO, OnMapInfo)
rlm@1 69 ON_MESSAGE(WM_COLINFO, OnColInfo)
rlm@1 70 END_MESSAGE_MAP()
rlm@1 71
rlm@1 72 /////////////////////////////////////////////////////////////////////////////
rlm@1 73 // OamView message handlers
rlm@1 74
rlm@1 75 OamView::~OamView()
rlm@1 76 {
rlm@1 77 free(data);
rlm@1 78 data = NULL;
rlm@1 79 }
rlm@1 80
rlm@1 81 void OamView::paint()
rlm@1 82 {
rlm@1 83 if (oam == NULL || paletteRAM == NULL || vram == NULL)
rlm@1 84 return;
rlm@1 85
rlm@1 86 render();
rlm@1 87 oamView.setSize(w, h);
rlm@1 88 oamView.refresh();
rlm@1 89 }
rlm@1 90
rlm@1 91 void OamView::update()
rlm@1 92 {
rlm@1 93 paint();
rlm@1 94 }
rlm@1 95
rlm@1 96 void OamView::setAttributes(u16 a0, u16 a1, u16 a2)
rlm@1 97 {
rlm@1 98 CString buffer;
rlm@1 99
rlm@1 100 int y = a0 & 255;
rlm@1 101 int rot = a0 & 512;
rlm@1 102 int mode = (a0 >> 10) & 3;
rlm@1 103 int mosaic = a0 & 4096;
rlm@1 104 int color = a0 & 8192;
rlm@1 105 int duple = a0 & 1024;
rlm@1 106 int shape = (a0 >> 14) & 3;
rlm@1 107 int x = a1 & 511;
rlm@1 108 int rotParam = (a1 >> 9) & 31;
rlm@1 109 int flipH = a1 & 4096;
rlm@1 110 int flipV = a1 & 8192;
rlm@1 111 int size = (a1 >> 14) & 3;
rlm@1 112 int tile = a2 & 1023;
rlm@1 113 int prio = (a2 >> 10) & 3;
rlm@1 114 int pal = (a2 >> 12) & 15;
rlm@1 115
rlm@1 116 buffer.Format("%d,%d", x, y);
rlm@1 117 GetDlgItem(IDC_POS)->SetWindowText(buffer);
rlm@1 118
rlm@1 119 buffer.Format("%d", mode);
rlm@1 120 GetDlgItem(IDC_MODE)->SetWindowText(buffer);
rlm@1 121
rlm@1 122 GetDlgItem(IDC_COLORS)->SetWindowText(color ? "256" : "16");
rlm@1 123
rlm@1 124 buffer.Format("%d", pal);
rlm@1 125 GetDlgItem(IDC_PALETTE)->SetWindowText(buffer);
rlm@1 126
rlm@1 127 buffer.Format("%d", tile);
rlm@1 128 GetDlgItem(IDC_TILE)->SetWindowText(buffer);
rlm@1 129
rlm@1 130 buffer.Format("%d", prio);
rlm@1 131 GetDlgItem(IDC_PRIO)->SetWindowText(buffer);
rlm@1 132
rlm@1 133 buffer.Format("%d,%d", w, h);
rlm@1 134 GetDlgItem(IDC_SIZE2)->SetWindowText(buffer);
rlm@1 135
rlm@1 136 if (rot)
rlm@1 137 {
rlm@1 138 buffer.Format("%d", rotParam);
rlm@1 139 }
rlm@1 140 else
rlm@1 141 buffer.Empty();
rlm@1 142 GetDlgItem(IDC_ROT)->SetWindowText(buffer);
rlm@1 143
rlm@1 144 buffer.Empty();
rlm@1 145
rlm@1 146 if (rot)
rlm@1 147 buffer += 'R';
rlm@1 148 else
rlm@1 149 buffer += ' ';
rlm@1 150 if (!rot)
rlm@1 151 {
rlm@1 152 if (flipH)
rlm@1 153 buffer += 'H';
rlm@1 154 else
rlm@1 155 buffer += ' ';
rlm@1 156 if (flipV)
rlm@1 157 buffer += 'V';
rlm@1 158 else
rlm@1 159 buffer += ' ';
rlm@1 160 }
rlm@1 161 else
rlm@1 162 {
rlm@1 163 buffer += ' ';
rlm@1 164 buffer += ' ';
rlm@1 165 }
rlm@1 166 if (mosaic)
rlm@1 167 buffer += 'M';
rlm@1 168 else
rlm@1 169 buffer += ' ';
rlm@1 170 if (duple)
rlm@1 171 buffer += 'D';
rlm@1 172 else
rlm@1 173 buffer += ' ';
rlm@1 174
rlm@1 175 GetDlgItem(IDC_FLAGS)->SetWindowText(buffer);
rlm@1 176 }
rlm@1 177
rlm@1 178 void OamView::render()
rlm@1 179 {
rlm@1 180 int m = 0;
rlm@1 181 if (oam == NULL || paletteRAM == NULL || vram == NULL)
rlm@1 182 return;
rlm@1 183
rlm@1 184 u16 *sprites = &((u16 *)oam)[4*number];
rlm@1 185 u16 *spritePalette = &((u16 *)paletteRAM)[0x100];
rlm@1 186 u8 * bmp = data;
rlm@1 187
rlm@1 188 u16 a0 = *sprites++;
rlm@1 189 u16 a1 = *sprites++;
rlm@1 190 u16 a2 = *sprites++;
rlm@1 191
rlm@1 192 int sizeY = 8;
rlm@1 193 int sizeX = 8;
rlm@1 194
rlm@1 195 switch (((a0 >>12) & 0x0c)|(a1>>14))
rlm@1 196 {
rlm@1 197 case 0:
rlm@1 198 break;
rlm@1 199 case 1:
rlm@1 200 sizeX = sizeY = 16;
rlm@1 201 break;
rlm@1 202 case 2:
rlm@1 203 sizeX = sizeY = 32;
rlm@1 204 break;
rlm@1 205 case 3:
rlm@1 206 sizeX = sizeY = 64;
rlm@1 207 break;
rlm@1 208 case 4:
rlm@1 209 sizeX = 16;
rlm@1 210 break;
rlm@1 211 case 5:
rlm@1 212 sizeX = 32;
rlm@1 213 break;
rlm@1 214 case 6:
rlm@1 215 sizeX = 32;
rlm@1 216 sizeY = 16;
rlm@1 217 break;
rlm@1 218 case 7:
rlm@1 219 sizeX = 64;
rlm@1 220 sizeY = 32;
rlm@1 221 break;
rlm@1 222 case 8:
rlm@1 223 sizeY = 16;
rlm@1 224 break;
rlm@1 225 case 9:
rlm@1 226 sizeY = 32;
rlm@1 227 break;
rlm@1 228 case 10:
rlm@1 229 sizeX = 16;
rlm@1 230 sizeY = 32;
rlm@1 231 break;
rlm@1 232 case 11:
rlm@1 233 sizeX = 32;
rlm@1 234 sizeY = 64;
rlm@1 235 break;
rlm@1 236 default:
rlm@1 237 return;
rlm@1 238 }
rlm@1 239
rlm@1 240 w = sizeX;
rlm@1 241 h = sizeY;
rlm@1 242
rlm@1 243 setAttributes(a0, a1, a2);
rlm@1 244
rlm@1 245 int sy = (a0 & 255);
rlm@1 246
rlm@1 247 if (a0 & 0x2000)
rlm@1 248 {
rlm@1 249 int c = (a2 & 0x3FF);
rlm@1 250 // if((DISPCNT & 7) > 2 && (c < 512))
rlm@1 251 // return;
rlm@1 252 int inc = 32;
rlm@1 253 if (DISPCNT & 0x40)
rlm@1 254 inc = sizeX >> 2;
rlm@1 255 else
rlm@1 256 c &= 0x3FE;
rlm@1 257
rlm@1 258 for (int y = 0; y < sizeY; y++)
rlm@1 259 {
rlm@1 260 for (int x = 0; x < sizeX; x++)
rlm@1 261 {
rlm@1 262 u32 color = vram[0x10000 + (((c + (y>>3) * inc)*
rlm@1 263 32 + (y & 7) * 8 + (x >> 3) * 64 +
rlm@1 264 (x & 7))&0x7FFF)];
rlm@1 265 color = spritePalette[color];
rlm@1 266 *bmp++ = ((color >> 10) & 0x1f) << 3;
rlm@1 267 *bmp++ = ((color >> 5) & 0x1f) << 3;
rlm@1 268 *bmp++ = (color & 0x1f) << 3;
rlm@1 269 }
rlm@1 270 }
rlm@1 271 }
rlm@1 272 else
rlm@1 273 {
rlm@1 274 int c = (a2 & 0x3FF);
rlm@1 275 // if((DISPCNT & 7) > 2 && (c < 512))
rlm@1 276 // continue;
rlm@1 277
rlm@1 278 int inc = 32;
rlm@1 279 if (DISPCNT & 0x40)
rlm@1 280 inc = sizeX >> 3;
rlm@1 281 int palette = (a2 >> 8) & 0xF0;
rlm@1 282 for (int y = 0; y < sizeY; y++)
rlm@1 283 {
rlm@1 284 for (int x = 0; x < sizeX; x++)
rlm@1 285 {
rlm@1 286 u32 color = vram[0x10000 + (((c + (y>>3) * inc)*
rlm@1 287 32 + (y & 7) * 4 + (x >> 3) * 32 +
rlm@1 288 ((x & 7)>>1))&0x7FFF)];
rlm@1 289 if (x & 1)
rlm@1 290 color >>= 4;
rlm@1 291 else
rlm@1 292 color &= 0x0F;
rlm@1 293
rlm@1 294 color = spritePalette[palette+color];
rlm@1 295 *bmp++ = ((color >> 10) & 0x1f) << 3;
rlm@1 296 *bmp++ = ((color >> 5) & 0x1f) << 3;
rlm@1 297 *bmp++ = (color & 0x1f) << 3;
rlm@1 298 }
rlm@1 299 }
rlm@1 300 }
rlm@1 301 }
rlm@1 302
rlm@1 303 void OamView::saveBMP(const char *name)
rlm@1 304 {
rlm@1 305 u8 writeBuffer[1024 * 3];
rlm@1 306
rlm@1 307 FILE *fp = fopen(name, "wb");
rlm@1 308
rlm@1 309 if (!fp)
rlm@1 310 {
rlm@1 311 systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
rlm@1 312 return;
rlm@1 313 }
rlm@1 314
rlm@1 315 struct
rlm@1 316 {
rlm@1 317 u8 ident[2];
rlm@1 318 u8 filesize[4];
rlm@1 319 u8 reserved[4];
rlm@1 320 u8 dataoffset[4];
rlm@1 321 u8 headersize[4];
rlm@1 322 u8 width[4];
rlm@1 323 u8 height[4];
rlm@1 324 u8 planes[2];
rlm@1 325 u8 bitsperpixel[2];
rlm@1 326 u8 compression[4];
rlm@1 327 u8 datasize[4];
rlm@1 328 u8 hres[4];
rlm@1 329 u8 vres[4];
rlm@1 330 u8 colors[4];
rlm@1 331 u8 importantcolors[4];
rlm@1 332 u8 pad[2];
rlm@1 333 } bmpheader;
rlm@1 334 memset(&bmpheader, 0, sizeof(bmpheader));
rlm@1 335
rlm@1 336 bmpheader.ident[0] = 'B';
rlm@1 337 bmpheader.ident[1] = 'M';
rlm@1 338
rlm@1 339 u32 fsz = sizeof(bmpheader) + w*h*3;
rlm@1 340 utilPutDword(bmpheader.filesize, fsz);
rlm@1 341 utilPutDword(bmpheader.dataoffset, 0x38);
rlm@1 342 utilPutDword(bmpheader.headersize, 0x28);
rlm@1 343 utilPutDword(bmpheader.width, w);
rlm@1 344 utilPutDword(bmpheader.height, h);
rlm@1 345 utilPutDword(bmpheader.planes, 1);
rlm@1 346 utilPutDword(bmpheader.bitsperpixel, 24);
rlm@1 347 utilPutDword(bmpheader.datasize, 3*w*h);
rlm@1 348
rlm@1 349 fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
rlm@1 350
rlm@1 351 u8 *b = writeBuffer;
rlm@1 352
rlm@1 353 int sizeX = w;
rlm@1 354 int sizeY = h;
rlm@1 355
rlm@1 356 u8 *pixU8 = (u8 *)data+3*w*(h-1);
rlm@1 357 for (int y = 0; y < sizeY; y++)
rlm@1 358 {
rlm@1 359 for (int x = 0; x < sizeX; x++)
rlm@1 360 {
rlm@1 361 *b++ = *pixU8++; // B
rlm@1 362 *b++ = *pixU8++; // G
rlm@1 363 *b++ = *pixU8++; // R
rlm@1 364 }
rlm@1 365 pixU8 -= 2*3*w;
rlm@1 366 fwrite(writeBuffer, 1, 3*w, fp);
rlm@1 367
rlm@1 368 b = writeBuffer;
rlm@1 369 }
rlm@1 370
rlm@1 371 fclose(fp);
rlm@1 372 }
rlm@1 373
rlm@1 374 void OamView::savePNG(const char *name)
rlm@1 375 {
rlm@1 376 u8 writeBuffer[1024 * 3];
rlm@1 377
rlm@1 378 FILE *fp = fopen(name, "wb");
rlm@1 379
rlm@1 380 if (!fp)
rlm@1 381 {
rlm@1 382 systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
rlm@1 383 return;
rlm@1 384 }
rlm@1 385
rlm@1 386 png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
rlm@1 387 NULL,
rlm@1 388 NULL,
rlm@1 389 NULL);
rlm@1 390 if (!png_ptr)
rlm@1 391 {
rlm@1 392 fclose(fp);
rlm@1 393 return;
rlm@1 394 }
rlm@1 395
rlm@1 396 png_infop info_ptr = png_create_info_struct(png_ptr);
rlm@1 397
rlm@1 398 if (!info_ptr)
rlm@1 399 {
rlm@1 400 png_destroy_write_struct(&png_ptr, NULL);
rlm@1 401 fclose(fp);
rlm@1 402 return;
rlm@1 403 }
rlm@1 404
rlm@1 405 if (setjmp(png_ptr->jmpbuf))
rlm@1 406 {
rlm@1 407 png_destroy_write_struct(&png_ptr, NULL);
rlm@1 408 fclose(fp);
rlm@1 409 return;
rlm@1 410 }
rlm@1 411
rlm@1 412 png_init_io(png_ptr, fp);
rlm@1 413
rlm@1 414 png_set_IHDR(png_ptr,
rlm@1 415 info_ptr,
rlm@1 416 w,
rlm@1 417 h,
rlm@1 418 8,
rlm@1 419 PNG_COLOR_TYPE_RGB,
rlm@1 420 PNG_INTERLACE_NONE,
rlm@1 421 PNG_COMPRESSION_TYPE_DEFAULT,
rlm@1 422 PNG_FILTER_TYPE_DEFAULT);
rlm@1 423
rlm@1 424 png_write_info(png_ptr, info_ptr);
rlm@1 425
rlm@1 426 u8 *b = writeBuffer;
rlm@1 427
rlm@1 428 int sizeX = w;
rlm@1 429 int sizeY = h;
rlm@1 430
rlm@1 431 u8 *pixU8 = (u8 *)data;
rlm@1 432 for (int y = 0; y < sizeY; y++)
rlm@1 433 {
rlm@1 434 for (int x = 0; x < sizeX; x++)
rlm@1 435 {
rlm@1 436 int blue = *pixU8++;
rlm@1 437 int green = *pixU8++;
rlm@1 438 int red = *pixU8++;
rlm@1 439
rlm@1 440 *b++ = red;
rlm@1 441 *b++ = green;
rlm@1 442 *b++ = blue;
rlm@1 443 }
rlm@1 444 png_write_row(png_ptr, writeBuffer);
rlm@1 445
rlm@1 446 b = writeBuffer;
rlm@1 447 }
rlm@1 448
rlm@1 449 png_write_end(png_ptr, info_ptr);
rlm@1 450
rlm@1 451 png_destroy_write_struct(&png_ptr, &info_ptr);
rlm@1 452
rlm@1 453 fclose(fp);
rlm@1 454 }
rlm@1 455
rlm@1 456 void OamView::OnSave()
rlm@1 457 {
rlm@1 458 CString captureBuffer;
rlm@1 459
rlm@1 460 if (theApp.captureFormat == 0)
rlm@1 461 captureBuffer = "oam.png";
rlm@1 462 else
rlm@1 463 captureBuffer = "oam.bmp";
rlm@1 464
rlm@1 465 LPCTSTR exts[] = {".png", ".bmp", NULL };
rlm@1 466
rlm@1 467 CString filter = winResLoadFilter(IDS_FILTER_PNG);
rlm@1 468 CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);
rlm@1 469
rlm@1 470 FileDlg dlg(this,
rlm@1 471 captureBuffer,
rlm@1 472 filter,
rlm@1 473 theApp.captureFormat ? 2 : 1,
rlm@1 474 theApp.captureFormat ? "BMP" : "PNG",
rlm@1 475 exts,
rlm@1 476 "",
rlm@1 477 title,
rlm@1 478 true);
rlm@1 479
rlm@1 480 if (dlg.DoModal() == IDCANCEL)
rlm@1 481 {
rlm@1 482 return;
rlm@1 483 }
rlm@1 484 captureBuffer = dlg.GetPathName();
rlm@1 485
rlm@1 486 if (dlg.getFilterIndex() == 2)
rlm@1 487 saveBMP(captureBuffer);
rlm@1 488 else
rlm@1 489 savePNG(captureBuffer);
rlm@1 490 }
rlm@1 491
rlm@1 492 BOOL OamView::OnInitDialog()
rlm@1 493 {
rlm@1 494 CDialog::OnInitDialog();
rlm@1 495
rlm@1 496 DIALOG_SIZER_START(sz)
rlm@1 497 DIALOG_SIZER_ENTRY(IDC_OAM_VIEW, DS_SizeX | DS_SizeY)
rlm@1 498 DIALOG_SIZER_ENTRY(IDC_OAM_VIEW_ZOOM, DS_MoveX)
rlm@1 499 DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
rlm@1 500 DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
rlm@1 501 DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
rlm@1 502 DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
rlm@1 503 DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
rlm@1 504 DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
rlm@1 505 DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
rlm@1 506 DIALOG_SIZER_END()
rlm@1 507 SetData(sz,
rlm@1 508 TRUE,
rlm@1 509 HKEY_CURRENT_USER,
rlm@1 510 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\OamView",
rlm@1 511 NULL);
rlm@1 512
rlm@1 513 m_sprite.SetWindowText("0");
rlm@1 514
rlm@1 515 updateScrollInfo();
rlm@1 516
rlm@1 517 m_stretch = regQueryDwordValue("oamViewStretch", 0);
rlm@1 518 if (m_stretch)
rlm@1 519 oamView.setStretch(true);
rlm@1 520 UpdateData(FALSE);
rlm@1 521
rlm@1 522 paint();
rlm@1 523
rlm@1 524 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 525 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 526 }
rlm@1 527
rlm@1 528 void OamView::OnStretch()
rlm@1 529 {
rlm@1 530 oamView.setStretch(!oamView.getStretch());
rlm@1 531 paint();
rlm@1 532 regSetDwordValue("oamViewStretch", oamView.getStretch());
rlm@1 533 }
rlm@1 534
rlm@1 535 void OamView::OnAutoUpdate()
rlm@1 536 {
rlm@1 537 autoUpdate = !autoUpdate;
rlm@1 538 if (autoUpdate)
rlm@1 539 {
rlm@1 540 theApp.winAddUpdateListener(this);
rlm@1 541 }
rlm@1 542 else
rlm@1 543 {
rlm@1 544 theApp.winRemoveUpdateListener(this);
rlm@1 545 }
rlm@1 546 }
rlm@1 547
rlm@1 548 void OamView::OnChangeSprite()
rlm@1 549 {
rlm@1 550 CString buffer;
rlm@1 551 m_sprite.GetWindowText(buffer);
rlm@1 552 int n = atoi(buffer);
rlm@1 553 if (n < 0 || n > 127)
rlm@1 554 {
rlm@1 555 buffer.Format("%d", number);
rlm@1 556 m_sprite.SetWindowText(buffer);
rlm@1 557 return;
rlm@1 558 }
rlm@1 559 number = n;
rlm@1 560 paint();
rlm@1 561 updateScrollInfo();
rlm@1 562 }
rlm@1 563
rlm@1 564 void OamView::OnClose()
rlm@1 565 {
rlm@1 566 theApp.winRemoveUpdateListener(this);
rlm@1 567
rlm@1 568 DestroyWindow();
rlm@1 569 }
rlm@1 570
rlm@1 571 LRESULT OamView::OnMapInfo(WPARAM wParam, LPARAM lParam)
rlm@1 572 {
rlm@1 573 u8 *colors = (u8 *)lParam;
rlm@1 574 oamZoom.setColors(colors);
rlm@1 575
rlm@1 576 return TRUE;
rlm@1 577 }
rlm@1 578
rlm@1 579 LRESULT OamView::OnColInfo(WPARAM wParam, LPARAM lParam)
rlm@1 580 {
rlm@1 581 u16 c = (u16)wParam;
rlm@1 582
rlm@1 583 color.setColor(c);
rlm@1 584
rlm@1 585 int r = (c & 0x1f);
rlm@1 586 int g = (c & 0x3e0) >> 5;
rlm@1 587 int b = (c & 0x7c00) >> 10;
rlm@1 588
rlm@1 589 CString buffer;
rlm@1 590 buffer.Format("R: %d", r);
rlm@1 591 GetDlgItem(IDC_R)->SetWindowText(buffer);
rlm@1 592
rlm@1 593 buffer.Format("G: %d", g);
rlm@1 594 GetDlgItem(IDC_G)->SetWindowText(buffer);
rlm@1 595
rlm@1 596 buffer.Format("B: %d", b);
rlm@1 597 GetDlgItem(IDC_B)->SetWindowText(buffer);
rlm@1 598
rlm@1 599 return TRUE;
rlm@1 600 }
rlm@1 601
rlm@1 602 void OamView::updateScrollInfo()
rlm@1 603 {
rlm@1 604 SCROLLINFO si;
rlm@1 605 ZeroMemory(&si, sizeof(si));
rlm@1 606 si.cbSize = sizeof(si);
rlm@1 607 si.fMask = SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL | SIF_POS;
rlm@1 608 si.nMin = 0;
rlm@1 609 si.nMax = 127;
rlm@1 610 si.nPage = 1;
rlm@1 611 si.nPos = number;
rlm@1 612 GetDlgItem(IDC_SCROLLBAR)->SetScrollInfo(SB_CTL,
rlm@1 613 &si,
rlm@1 614 TRUE);
rlm@1 615 }
rlm@1 616
rlm@1 617 void OamView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
rlm@1 618 {
rlm@1 619 switch (nSBCode)
rlm@1 620 {
rlm@1 621 case SB_BOTTOM:
rlm@1 622 number = 127;
rlm@1 623 break;
rlm@1 624 case SB_LINEDOWN:
rlm@1 625 number++;
rlm@1 626 if (number > 127)
rlm@1 627 number = 127;
rlm@1 628 break;
rlm@1 629 case SB_LINEUP:
rlm@1 630 number--;
rlm@1 631 if (number < 0)
rlm@1 632 number = 0;
rlm@1 633 break;
rlm@1 634 case SB_PAGEDOWN:
rlm@1 635 number += 16;
rlm@1 636 if (number > 127)
rlm@1 637 number = 127;
rlm@1 638 break;
rlm@1 639 case SB_PAGEUP:
rlm@1 640 number -= 16;
rlm@1 641 if (number < 0)
rlm@1 642 number = 0;
rlm@1 643 break;
rlm@1 644 case SB_TOP:
rlm@1 645 number = 0;
rlm@1 646 break;
rlm@1 647 case SB_THUMBTRACK:
rlm@1 648 number = nPos;
rlm@1 649 if (number < 0)
rlm@1 650 number = 0;
rlm@1 651 if (number > 127)
rlm@1 652 number = 127;
rlm@1 653 break;
rlm@1 654 }
rlm@1 655
rlm@1 656 updateScrollInfo();
rlm@1 657
rlm@1 658 CString buffer;
rlm@1 659 buffer.Format("%d", number);
rlm@1 660 m_sprite.SetWindowText(buffer);
rlm@1 661 paint();
rlm@1 662 }
rlm@1 663
rlm@1 664 void OamView::PostNcDestroy()
rlm@1 665 {
rlm@1 666 delete this;
rlm@1 667 }
rlm@1 668