rlm@1: // GBPaletteView.cpp : implementation file rlm@1: // rlm@1: rlm@1: #include "stdafx.h" rlm@1: #include "resource.h" rlm@1: #include "GBPaletteView.h" rlm@1: #include "FileDlg.h" rlm@1: #include "WinResUtil.h" rlm@1: #include "VBA.h" rlm@1: rlm@1: #include "../gb/gbGlobals.h" rlm@1: rlm@1: void GBPaletteViewControl::updatePalette() rlm@1: { rlm@1: if (gbRom) rlm@1: { rlm@1: memcpy(palette, &gbPalette[paletteAddress], 64); rlm@1: } rlm@1: } rlm@1: rlm@1: ///////////////////////////////////////////////////////////////////////////// rlm@1: // GBPaletteView dialog rlm@1: rlm@1: GBPaletteView::GBPaletteView(CWnd*pParent /*=NULL*/) rlm@1: : ResizeDlg(GBPaletteView::IDD, pParent) rlm@1: { rlm@1: //{{AFX_DATA_INIT(GBPaletteView) rlm@1: // NOTE: the ClassWizard will add member initialization here rlm@1: //}}AFX_DATA_INIT rlm@1: autoUpdate = false; rlm@1: } rlm@1: rlm@1: GBPaletteView::~GBPaletteView() rlm@1: {} rlm@1: rlm@1: void GBPaletteView::DoDataExchange(CDataExchange*pDX) rlm@1: { rlm@1: CDialog::DoDataExchange(pDX); rlm@1: //{{AFX_DATA_MAP(GBPaletteView) rlm@1: // NOTE: the ClassWizard will add DDX and DDV calls here rlm@1: //}}AFX_DATA_MAP rlm@1: DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView); rlm@1: DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ); rlm@1: DDX_Control(pDX, IDC_COLOR, colorControl); rlm@1: } rlm@1: rlm@1: BEGIN_MESSAGE_MAP(GBPaletteView, CDialog) rlm@1: //{{AFX_MSG_MAP(GBPaletteView) rlm@1: ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg) rlm@1: ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj) rlm@1: ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2) rlm@1: ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate) rlm@1: ON_BN_CLICKED(IDC_CLOSE, OnClose) rlm@1: //}}AFX_MSG_MAP rlm@1: ON_MESSAGE(WM_PALINFO, OnPalInfo) rlm@1: END_MESSAGE_MAP() rlm@1: rlm@1: ///////////////////////////////////////////////////////////////////////////// rlm@1: // GBPaletteView message handlers rlm@1: rlm@1: BOOL GBPaletteView::OnInitDialog() rlm@1: { rlm@1: CDialog::OnInitDialog(); rlm@1: rlm@1: DIALOG_SIZER_START(sz) rlm@1: DIALOG_SIZER_END() rlm@1: SetData(sz, rlm@1: FALSE, rlm@1: HKEY_CURRENT_USER, rlm@1: "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBPaletteView", rlm@1: NULL); rlm@1: rlm@1: paletteView.init(32, 64, 128); rlm@1: paletteViewOBJ.init(32, 64, 128); rlm@1: rlm@1: paletteView.setPaletteAddress(0); rlm@1: paletteView.refresh(); rlm@1: rlm@1: paletteViewOBJ.setPaletteAddress(32); rlm@1: paletteViewOBJ.refresh(); rlm@1: rlm@1: return TRUE; // return TRUE unless you set the focus to a control rlm@1: // EXCEPTION: OCX Property Pages should return FALSE rlm@1: } rlm@1: rlm@1: void GBPaletteView::save(int which) rlm@1: { rlm@1: CString captureBuffer; rlm@1: rlm@1: if (which == 0) rlm@1: captureBuffer = "bg.pal"; rlm@1: else rlm@1: captureBuffer = "obj.pal"; rlm@1: rlm@1: LPCTSTR exts[] = {".pal", ".pal", ".act", NULL }; rlm@1: rlm@1: CString filter = winResLoadFilter(IDS_FILTER_PAL); rlm@1: CString title = winResLoadString(IDS_SELECT_PALETTE_NAME); rlm@1: FileDlg dlg(this, rlm@1: captureBuffer, rlm@1: filter, rlm@1: 1, rlm@1: "PAL", rlm@1: exts, rlm@1: "", rlm@1: title, rlm@1: true); rlm@1: rlm@1: if (dlg.DoModal() == IDCANCEL) rlm@1: { rlm@1: return; rlm@1: } rlm@1: rlm@1: PaletteViewControl *p = NULL; rlm@1: rlm@1: if (which == 0) rlm@1: p = &paletteView; rlm@1: else rlm@1: p = &paletteViewOBJ; rlm@1: rlm@1: switch (dlg.getFilterIndex()) rlm@1: { rlm@1: case 0: rlm@1: case 1: rlm@1: p->saveMSPAL(captureBuffer); rlm@1: break; rlm@1: case 2: rlm@1: p->saveJASCPAL(captureBuffer); rlm@1: break; rlm@1: case 3: rlm@1: p->saveAdobe(captureBuffer); rlm@1: break; rlm@1: } rlm@1: } rlm@1: rlm@1: void GBPaletteView::OnSaveBg() rlm@1: { rlm@1: save(0); rlm@1: } rlm@1: rlm@1: void GBPaletteView::OnSaveObj() rlm@1: { rlm@1: save(1); rlm@1: } rlm@1: rlm@1: void GBPaletteView::OnRefresh2() rlm@1: { rlm@1: paletteView.refresh(); rlm@1: paletteViewOBJ.refresh(); rlm@1: } rlm@1: rlm@1: void GBPaletteView::update() rlm@1: { rlm@1: OnRefresh2(); rlm@1: } rlm@1: rlm@1: void GBPaletteView::OnAutoUpdate() rlm@1: { rlm@1: autoUpdate = !autoUpdate; rlm@1: if (autoUpdate) rlm@1: { rlm@1: theApp.winAddUpdateListener(this); rlm@1: } rlm@1: else rlm@1: { rlm@1: theApp.winRemoveUpdateListener(this); rlm@1: } rlm@1: } rlm@1: rlm@1: void GBPaletteView::OnClose() rlm@1: { rlm@1: theApp.winRemoveUpdateListener(this); rlm@1: rlm@1: DestroyWindow(); rlm@1: } rlm@1: rlm@1: LRESULT GBPaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam) rlm@1: { rlm@1: u16 color = (u16)wParam; rlm@1: u32 address = (u32)lParam; rlm@1: CString buffer; rlm@1: rlm@1: bool isOBJ = address >= 32; rlm@1: address &= 31; rlm@1: rlm@1: buffer.Format("%d", address); rlm@1: GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer); rlm@1: rlm@1: int r = (color & 0x1f); rlm@1: int g = (color & 0x3e0) >> 5; rlm@1: int b = (color & 0x7c00) >> 10; rlm@1: rlm@1: buffer.Format("%d", r); rlm@1: GetDlgItem(IDC_R)->SetWindowText(buffer); rlm@1: rlm@1: buffer.Format("%d", g); rlm@1: GetDlgItem(IDC_G)->SetWindowText(buffer); rlm@1: rlm@1: buffer.Format("%d", b); rlm@1: GetDlgItem(IDC_B)->SetWindowText(buffer); rlm@1: rlm@1: buffer.Format("0x%04X", color); rlm@1: GetDlgItem(IDC_VALUE)->SetWindowText(buffer); rlm@1: rlm@1: colorControl.setColor(color); rlm@1: rlm@1: if (isOBJ) rlm@1: paletteView.setSelected(-1); rlm@1: else rlm@1: paletteViewOBJ.setSelected(-1); rlm@1: rlm@1: return TRUE; rlm@1: } rlm@1: rlm@1: void GBPaletteView::PostNcDestroy() rlm@1: { rlm@1: delete this; rlm@1: } rlm@1: