annotate src/win32/TileView.cpp @ 8:08a8e09ca414

add files required by automake
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:54:39 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // TileView.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 "FileDlg.h"
rlm@1 7 #include "Reg.h"
rlm@1 8 #include "TileView.h"
rlm@1 9 #include "WinResUtil.h"
rlm@1 10 #include "VBA.h" // for theApp
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 // TileView dialog
rlm@1 22
rlm@1 23 TileView::TileView(CWnd*pParent /*=NULL*/)
rlm@1 24 : ResizeDlg(TileView::IDD, pParent)
rlm@1 25 {
rlm@1 26 //{{AFX_DATA_INIT(TileView)
rlm@1 27 m_colors = -1;
rlm@1 28 m_charBase = -1;
rlm@1 29 m_stretch = FALSE;
rlm@1 30 //}}AFX_DATA_INIT
rlm@1 31 autoUpdate = false;
rlm@1 32
rlm@1 33 memset(&bmpInfo, 0, sizeof(bmpInfo));
rlm@1 34
rlm@1 35 bmpInfo.bmiHeader.biSize = sizeof(bmpInfo.bmiHeader);
rlm@1 36 bmpInfo.bmiHeader.biWidth = 32*8;
rlm@1 37 bmpInfo.bmiHeader.biHeight = 32*8;
rlm@1 38 bmpInfo.bmiHeader.biPlanes = 1;
rlm@1 39 bmpInfo.bmiHeader.biBitCount = 24;
rlm@1 40 bmpInfo.bmiHeader.biCompression = BI_RGB;
rlm@1 41 data = (u8 *)calloc(1, 3 * 32*32 * 64);
rlm@1 42
rlm@1 43 tileView.setData(data);
rlm@1 44 tileView.setBmpInfo(&bmpInfo);
rlm@1 45
rlm@1 46 charBase = 0;
rlm@1 47 is256Colors = 0;
rlm@1 48 palette = 0;
rlm@1 49 w = h = 0;
rlm@1 50 }
rlm@1 51
rlm@1 52 TileView::~TileView()
rlm@1 53 {
rlm@1 54 free(data);
rlm@1 55 data = NULL;
rlm@1 56 }
rlm@1 57
rlm@1 58 void TileView::DoDataExchange(CDataExchange*pDX)
rlm@1 59 {
rlm@1 60 CDialog::DoDataExchange(pDX);
rlm@1 61 //{{AFX_DATA_MAP(TileView)
rlm@1 62 DDX_Control(pDX, IDC_PALETTE_SLIDER, m_slider);
rlm@1 63 DDX_Radio(pDX, IDC_16_COLORS, m_colors);
rlm@1 64 DDX_Radio(pDX, IDC_CHARBASE_0, m_charBase);
rlm@1 65 DDX_Check(pDX, IDC_STRETCH, m_stretch);
rlm@1 66 //}}AFX_DATA_MAP
rlm@1 67 DDX_Control(pDX, IDC_TILE_VIEW, tileView);
rlm@1 68 DDX_Control(pDX, IDC_MAP_VIEW_ZOOM, zoom);
rlm@1 69 DDX_Control(pDX, IDC_COLOR, color);
rlm@1 70 }
rlm@1 71
rlm@1 72 BEGIN_MESSAGE_MAP(TileView, CDialog)
rlm@1 73 //{{AFX_MSG_MAP(TileView)
rlm@1 74 ON_BN_CLICKED(IDC_SAVE, OnSave)
rlm@1 75 ON_BN_CLICKED(IDC_CLOSE, OnClose)
rlm@1 76 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
rlm@1 77 ON_BN_CLICKED(IDC_16_COLORS, On16Colors)
rlm@1 78 ON_BN_CLICKED(IDC_256_COLORS, On256Colors)
rlm@1 79 ON_BN_CLICKED(IDC_CHARBASE_0, OnCharbase0)
rlm@1 80 ON_BN_CLICKED(IDC_CHARBASE_1, OnCharbase1)
rlm@1 81 ON_BN_CLICKED(IDC_CHARBASE_2, OnCharbase2)
rlm@1 82 ON_BN_CLICKED(IDC_CHARBASE_3, OnCharbase3)
rlm@1 83 ON_BN_CLICKED(IDC_CHARBASE_4, OnCharbase4)
rlm@1 84 ON_BN_CLICKED(IDC_STRETCH, OnStretch)
rlm@1 85 ON_WM_HSCROLL()
rlm@1 86 //}}AFX_MSG_MAP
rlm@1 87 ON_MESSAGE(WM_MAPINFO, OnMapInfo)
rlm@1 88 ON_MESSAGE(WM_COLINFO, OnColInfo)
rlm@1 89 END_MESSAGE_MAP()
rlm@1 90
rlm@1 91 /////////////////////////////////////////////////////////////////////////////
rlm@1 92 // TileView message handlers
rlm@1 93
rlm@1 94 void TileView::saveBMP(const char *name)
rlm@1 95 {
rlm@1 96 u8 writeBuffer[1024 * 3];
rlm@1 97
rlm@1 98 FILE *fp = fopen(name, "wb");
rlm@1 99
rlm@1 100 if (!fp)
rlm@1 101 {
rlm@1 102 systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
rlm@1 103 return;
rlm@1 104 }
rlm@1 105
rlm@1 106 struct
rlm@1 107 {
rlm@1 108 u8 ident[2];
rlm@1 109 u8 filesize[4];
rlm@1 110 u8 reserved[4];
rlm@1 111 u8 dataoffset[4];
rlm@1 112 u8 headersize[4];
rlm@1 113 u8 width[4];
rlm@1 114 u8 height[4];
rlm@1 115 u8 planes[2];
rlm@1 116 u8 bitsperpixel[2];
rlm@1 117 u8 compression[4];
rlm@1 118 u8 datasize[4];
rlm@1 119 u8 hres[4];
rlm@1 120 u8 vres[4];
rlm@1 121 u8 colors[4];
rlm@1 122 u8 importantcolors[4];
rlm@1 123 u8 pad[2];
rlm@1 124 } bmpheader;
rlm@1 125 memset(&bmpheader, 0, sizeof(bmpheader));
rlm@1 126
rlm@1 127 bmpheader.ident[0] = 'B';
rlm@1 128 bmpheader.ident[1] = 'M';
rlm@1 129
rlm@1 130 u32 fsz = sizeof(bmpheader) + w*h*3;
rlm@1 131 utilPutDword(bmpheader.filesize, fsz);
rlm@1 132 utilPutDword(bmpheader.dataoffset, 0x38);
rlm@1 133 utilPutDword(bmpheader.headersize, 0x28);
rlm@1 134 utilPutDword(bmpheader.width, w);
rlm@1 135 utilPutDword(bmpheader.height, h);
rlm@1 136 utilPutDword(bmpheader.planes, 1);
rlm@1 137 utilPutDword(bmpheader.bitsperpixel, 24);
rlm@1 138 utilPutDword(bmpheader.datasize, 3*w*h);
rlm@1 139
rlm@1 140 fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
rlm@1 141
rlm@1 142 u8 *b = writeBuffer;
rlm@1 143
rlm@1 144 int sizeX = w;
rlm@1 145 int sizeY = h;
rlm@1 146
rlm@1 147 u8 *pixU8 = (u8 *)data+3*w*(h-1);
rlm@1 148 for (int y = 0; y < sizeY; y++)
rlm@1 149 {
rlm@1 150 for (int x = 0; x < sizeX; x++)
rlm@1 151 {
rlm@1 152 *b++ = *pixU8++; // B
rlm@1 153 *b++ = *pixU8++; // G
rlm@1 154 *b++ = *pixU8++; // R
rlm@1 155 }
rlm@1 156 pixU8 -= 2*3*w;
rlm@1 157 fwrite(writeBuffer, 1, 3*w, fp);
rlm@1 158
rlm@1 159 b = writeBuffer;
rlm@1 160 }
rlm@1 161
rlm@1 162 fclose(fp);
rlm@1 163 }
rlm@1 164
rlm@1 165 void TileView::savePNG(const char *name)
rlm@1 166 {
rlm@1 167 u8 writeBuffer[1024 * 3];
rlm@1 168
rlm@1 169 FILE *fp = fopen(name, "wb");
rlm@1 170
rlm@1 171 if (!fp)
rlm@1 172 {
rlm@1 173 systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
rlm@1 174 return;
rlm@1 175 }
rlm@1 176
rlm@1 177 png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
rlm@1 178 NULL,
rlm@1 179 NULL,
rlm@1 180 NULL);
rlm@1 181 if (!png_ptr)
rlm@1 182 {
rlm@1 183 fclose(fp);
rlm@1 184 return;
rlm@1 185 }
rlm@1 186
rlm@1 187 png_infop info_ptr = png_create_info_struct(png_ptr);
rlm@1 188
rlm@1 189 if (!info_ptr)
rlm@1 190 {
rlm@1 191 png_destroy_write_struct(&png_ptr, NULL);
rlm@1 192 fclose(fp);
rlm@1 193 return;
rlm@1 194 }
rlm@1 195
rlm@1 196 if (setjmp(png_ptr->jmpbuf))
rlm@1 197 {
rlm@1 198 png_destroy_write_struct(&png_ptr, NULL);
rlm@1 199 fclose(fp);
rlm@1 200 return;
rlm@1 201 }
rlm@1 202
rlm@1 203 png_init_io(png_ptr, fp);
rlm@1 204
rlm@1 205 png_set_IHDR(png_ptr,
rlm@1 206 info_ptr,
rlm@1 207 w,
rlm@1 208 h,
rlm@1 209 8,
rlm@1 210 PNG_COLOR_TYPE_RGB,
rlm@1 211 PNG_INTERLACE_NONE,
rlm@1 212 PNG_COMPRESSION_TYPE_DEFAULT,
rlm@1 213 PNG_FILTER_TYPE_DEFAULT);
rlm@1 214
rlm@1 215 png_write_info(png_ptr, info_ptr);
rlm@1 216
rlm@1 217 u8 *b = writeBuffer;
rlm@1 218
rlm@1 219 int sizeX = w;
rlm@1 220 int sizeY = h;
rlm@1 221
rlm@1 222 u8 *pixU8 = (u8 *)data;
rlm@1 223 for (int y = 0; y < sizeY; y++)
rlm@1 224 {
rlm@1 225 for (int x = 0; x < sizeX; x++)
rlm@1 226 {
rlm@1 227 int blue = *pixU8++;
rlm@1 228 int green = *pixU8++;
rlm@1 229 int red = *pixU8++;
rlm@1 230
rlm@1 231 *b++ = red;
rlm@1 232 *b++ = green;
rlm@1 233 *b++ = blue;
rlm@1 234 }
rlm@1 235 png_write_row(png_ptr, writeBuffer);
rlm@1 236
rlm@1 237 b = writeBuffer;
rlm@1 238 }
rlm@1 239
rlm@1 240 png_write_end(png_ptr, info_ptr);
rlm@1 241
rlm@1 242 png_destroy_write_struct(&png_ptr, &info_ptr);
rlm@1 243
rlm@1 244 fclose(fp);
rlm@1 245 }
rlm@1 246
rlm@1 247 void TileView::OnSave()
rlm@1 248 {
rlm@1 249 CString captureBuffer;
rlm@1 250
rlm@1 251 if (theApp.captureFormat == 0)
rlm@1 252 captureBuffer = "tiles.png";
rlm@1 253 else
rlm@1 254 captureBuffer = "tiles.bmp";
rlm@1 255
rlm@1 256 LPCTSTR exts[] = {".png", ".bmp", NULL };
rlm@1 257
rlm@1 258 CString filter = winResLoadFilter(IDS_FILTER_PNG);
rlm@1 259 CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);
rlm@1 260
rlm@1 261 FileDlg dlg(this,
rlm@1 262 captureBuffer,
rlm@1 263 filter,
rlm@1 264 theApp.captureFormat ? 2 : 1,
rlm@1 265 theApp.captureFormat ? "BMP" : "PNG",
rlm@1 266 exts,
rlm@1 267 "",
rlm@1 268 title,
rlm@1 269 true);
rlm@1 270
rlm@1 271 if (dlg.DoModal() == IDCANCEL)
rlm@1 272 {
rlm@1 273 return;
rlm@1 274 }
rlm@1 275
rlm@1 276 captureBuffer = dlg.GetPathName();
rlm@1 277
rlm@1 278 if (dlg.getFilterIndex() == 2)
rlm@1 279 saveBMP(captureBuffer);
rlm@1 280 else
rlm@1 281 savePNG(captureBuffer);
rlm@1 282 }
rlm@1 283
rlm@1 284 void TileView::renderTile256(int tile, int x, int y, u8 *charBase, u16 *palette)
rlm@1 285 {
rlm@1 286 u8 *bmp = &data[24*x + 8*32*24*y];
rlm@1 287
rlm@1 288 for (int j = 0; j < 8; j++)
rlm@1 289 {
rlm@1 290 for (int i = 0; i < 8; i++)
rlm@1 291 {
rlm@1 292 u8 c = charBase[tile*64 + j * 8 + i];
rlm@1 293
rlm@1 294 u16 color = palette[c];
rlm@1 295
rlm@1 296 *bmp++ = ((color >> 10) & 0x1f) << 3;
rlm@1 297 *bmp++ = ((color >> 5) & 0x1f) << 3;
rlm@1 298 *bmp++ = (color & 0x1f) << 3;
rlm@1 299 }
rlm@1 300 bmp += 31*24; // advance line
rlm@1 301 }
rlm@1 302 }
rlm@1 303
rlm@1 304 void TileView::renderTile16(int tile, int x, int y, u8 *charBase, u16 *palette)
rlm@1 305 {
rlm@1 306 u8 *bmp = &data[24*x + 8*32*24*y];
rlm@1 307
rlm@1 308 int pal = this->palette;
rlm@1 309
rlm@1 310 if (this->charBase == 4)
rlm@1 311 pal += 16;
rlm@1 312
rlm@1 313 for (int j = 0; j < 8; j++)
rlm@1 314 {
rlm@1 315 for (int i = 0; i < 8; i++)
rlm@1 316 {
rlm@1 317 u8 c = charBase[tile*32 + j * 4 + (i>>1)];
rlm@1 318
rlm@1 319 if (i & 1)
rlm@1 320 c = c>>4;
rlm@1 321 else
rlm@1 322 c = c & 15;
rlm@1 323
rlm@1 324 u16 color = palette[pal*16+c];
rlm@1 325
rlm@1 326 *bmp++ = ((color >> 10) & 0x1f) << 3;
rlm@1 327 *bmp++ = ((color >> 5) & 0x1f) << 3;
rlm@1 328 *bmp++ = (color & 0x1f) << 3;
rlm@1 329 }
rlm@1 330 bmp += 31*24; // advance line
rlm@1 331 }
rlm@1 332 }
rlm@1 333
rlm@1 334 void TileView::render()
rlm@1 335 {
rlm@1 336 u16 *palette = (u16 *)paletteRAM;
rlm@1 337 u8 * charBase = &vram[this->charBase * 0x4000];
rlm@1 338
rlm@1 339 int maxY;
rlm@1 340
rlm@1 341 if (is256Colors)
rlm@1 342 {
rlm@1 343 int tile = 0;
rlm@1 344 maxY = 16;
rlm@1 345 for (int y = 0; y < maxY; y++)
rlm@1 346 {
rlm@1 347 for (int x = 0; x < 32; x++)
rlm@1 348 {
rlm@1 349 if (this->charBase == 4)
rlm@1 350 renderTile256(tile, x, y, charBase, &palette[256]);
rlm@1 351 else
rlm@1 352 renderTile256(tile, x, y, charBase, palette);
rlm@1 353 tile++;
rlm@1 354 }
rlm@1 355 }
rlm@1 356 tileView.setSize(32*8, maxY*8);
rlm@1 357 w = 32*8;
rlm@1 358 h = maxY*8;
rlm@1 359 SIZE s;
rlm@1 360 s.cx = 32*8;
rlm@1 361 s.cy = maxY*8;
rlm@1 362 if (tileView.getStretch())
rlm@1 363 {
rlm@1 364 s.cx = s.cy = 1;
rlm@1 365 }
rlm@1 366 tileView.SetScrollSizes(MM_TEXT, s);
rlm@1 367 }
rlm@1 368 else
rlm@1 369 {
rlm@1 370 int tile = 0;
rlm@1 371 maxY = 32;
rlm@1 372 if (this->charBase == 3)
rlm@1 373 maxY = 16;
rlm@1 374 for (int y = 0; y < maxY; y++)
rlm@1 375 {
rlm@1 376 for (int x = 0; x < 32; x++)
rlm@1 377 {
rlm@1 378 renderTile16(tile, x, y, charBase, palette);
rlm@1 379 tile++;
rlm@1 380 }
rlm@1 381 }
rlm@1 382 tileView.setSize(32*8, maxY*8);
rlm@1 383 w = 32*8;
rlm@1 384 h = maxY*8;
rlm@1 385 SIZE s;
rlm@1 386 s.cx = 32*8;
rlm@1 387 s.cy = maxY*8;
rlm@1 388 if (tileView.getStretch())
rlm@1 389 {
rlm@1 390 s.cx = s.cy = 1;
rlm@1 391 }
rlm@1 392 tileView.SetScrollSizes(MM_TEXT, s);
rlm@1 393 }
rlm@1 394 }
rlm@1 395
rlm@1 396 void TileView::update()
rlm@1 397 {
rlm@1 398 paint();
rlm@1 399 }
rlm@1 400
rlm@1 401 BOOL TileView::OnInitDialog()
rlm@1 402 {
rlm@1 403 CDialog::OnInitDialog();
rlm@1 404
rlm@1 405 DIALOG_SIZER_START(sz)
rlm@1 406 DIALOG_SIZER_ENTRY(IDC_TILE_VIEW, DS_SizeX | DS_SizeY)
rlm@1 407 DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
rlm@1 408 DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
rlm@1 409 DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
rlm@1 410 DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
rlm@1 411 DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
rlm@1 412 DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
rlm@1 413 DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
rlm@1 414 DIALOG_SIZER_END()
rlm@1 415 SetData(sz,
rlm@1 416 TRUE,
rlm@1 417 HKEY_CURRENT_USER,
rlm@1 418 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\TileView",
rlm@1 419 NULL);
rlm@1 420
rlm@1 421 m_colors = is256Colors;
rlm@1 422 m_charBase = charBase;
rlm@1 423
rlm@1 424 m_slider.SetRange(0, 15);
rlm@1 425 m_slider.SetPageSize(4);
rlm@1 426 m_slider.SetTicFreq(1);
rlm@1 427
rlm@1 428 paint();
rlm@1 429
rlm@1 430 m_stretch = regQueryDwordValue("tileViewStretch", 0);
rlm@1 431 if (m_stretch)
rlm@1 432 tileView.setStretch(true);
rlm@1 433 UpdateData(FALSE);
rlm@1 434
rlm@1 435 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 436 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 437 }
rlm@1 438
rlm@1 439 void TileView::OnClose()
rlm@1 440 {
rlm@1 441 theApp.winRemoveUpdateListener(this);
rlm@1 442
rlm@1 443 DestroyWindow();
rlm@1 444 }
rlm@1 445
rlm@1 446 void TileView::OnAutoUpdate()
rlm@1 447 {
rlm@1 448 autoUpdate = !autoUpdate;
rlm@1 449 if (autoUpdate)
rlm@1 450 {
rlm@1 451 theApp.winAddUpdateListener(this);
rlm@1 452 }
rlm@1 453 else
rlm@1 454 {
rlm@1 455 theApp.winRemoveUpdateListener(this);
rlm@1 456 }
rlm@1 457 }
rlm@1 458
rlm@1 459 void TileView::paint()
rlm@1 460 {
rlm@1 461 if (vram != NULL && paletteRAM != NULL)
rlm@1 462 {
rlm@1 463 render();
rlm@1 464 tileView.refresh();
rlm@1 465 }
rlm@1 466 }
rlm@1 467
rlm@1 468 void TileView::On16Colors()
rlm@1 469 {
rlm@1 470 is256Colors = 0;
rlm@1 471 paint();
rlm@1 472 }
rlm@1 473
rlm@1 474 void TileView::On256Colors()
rlm@1 475 {
rlm@1 476 is256Colors = 1;
rlm@1 477 paint();
rlm@1 478 }
rlm@1 479
rlm@1 480 void TileView::OnCharbase0()
rlm@1 481 {
rlm@1 482 charBase = 0;
rlm@1 483 paint();
rlm@1 484 }
rlm@1 485
rlm@1 486 void TileView::OnCharbase1()
rlm@1 487 {
rlm@1 488 charBase = 1;
rlm@1 489 paint();
rlm@1 490 }
rlm@1 491
rlm@1 492 void TileView::OnCharbase2()
rlm@1 493 {
rlm@1 494 charBase = 2;
rlm@1 495 paint();
rlm@1 496 }
rlm@1 497
rlm@1 498 void TileView::OnCharbase3()
rlm@1 499 {
rlm@1 500 charBase = 3;
rlm@1 501 paint();
rlm@1 502 }
rlm@1 503
rlm@1 504 void TileView::OnCharbase4()
rlm@1 505 {
rlm@1 506 charBase = 4;
rlm@1 507 paint();
rlm@1 508 }
rlm@1 509
rlm@1 510 void TileView::OnStretch()
rlm@1 511 {
rlm@1 512 tileView.setStretch(!tileView.getStretch());
rlm@1 513 paint();
rlm@1 514 regSetDwordValue("tileViewStretch", tileView.getStretch());
rlm@1 515 }
rlm@1 516
rlm@1 517 LRESULT TileView::OnMapInfo(WPARAM wParam, LPARAM lParam)
rlm@1 518 {
rlm@1 519 u8 *colors = (u8 *)lParam;
rlm@1 520 zoom.setColors(colors);
rlm@1 521
rlm@1 522 int x = (wParam & 0xFFFF)/8;
rlm@1 523 int y = ((wParam >> 16) & 0xFFFF)/8;
rlm@1 524
rlm@1 525 u32 address = 0x6000000 + 0x4000 * charBase;
rlm@1 526 int tile = 32 * y + x;
rlm@1 527 if (is256Colors)
rlm@1 528 tile *= 2;
rlm@1 529 address += 32 * tile;
rlm@1 530
rlm@1 531 CString buffer;
rlm@1 532 buffer.Format("%d", tile);
rlm@1 533 GetDlgItem(IDC_TILE_NUMBER)->SetWindowText(buffer);
rlm@1 534
rlm@1 535 buffer.Format("%08x", address);
rlm@1 536 GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
rlm@1 537
rlm@1 538 return TRUE;
rlm@1 539 }
rlm@1 540
rlm@1 541 LRESULT TileView::OnColInfo(WPARAM wParam, LPARAM)
rlm@1 542 {
rlm@1 543 u16 c = (u16)wParam;
rlm@1 544
rlm@1 545 color.setColor(c);
rlm@1 546
rlm@1 547 int r = (c & 0x1f);
rlm@1 548 int g = (c & 0x3e0) >> 5;
rlm@1 549 int b = (c & 0x7c00) >> 10;
rlm@1 550
rlm@1 551 CString buffer;
rlm@1 552 buffer.Format("R: %d", r);
rlm@1 553 GetDlgItem(IDC_R)->SetWindowText(buffer);
rlm@1 554
rlm@1 555 buffer.Format("G: %d", g);
rlm@1 556 GetDlgItem(IDC_G)->SetWindowText(buffer);
rlm@1 557
rlm@1 558 buffer.Format("B: %d", b);
rlm@1 559 GetDlgItem(IDC_B)->SetWindowText(buffer);
rlm@1 560
rlm@1 561 return TRUE;
rlm@1 562 }
rlm@1 563
rlm@1 564 void TileView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
rlm@1 565 {
rlm@1 566 switch (nSBCode)
rlm@1 567 {
rlm@1 568 case TB_THUMBPOSITION:
rlm@1 569 palette = nPos;
rlm@1 570 break;
rlm@1 571 default:
rlm@1 572 palette = m_slider.GetPos();
rlm@1 573 break;
rlm@1 574 }
rlm@1 575 paint();
rlm@1 576 }
rlm@1 577
rlm@1 578 void TileView::PostNcDestroy()
rlm@1 579 {
rlm@1 580 delete this;
rlm@1 581 }
rlm@1 582