Mercurial > vba-linux
view src/win32/GBPaletteView.cpp @ 2:3549bbe597ed
adding makefile.am
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:47 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 // GBPaletteView.cpp : implementation file2 //4 #include "stdafx.h"5 #include "resource.h"6 #include "GBPaletteView.h"7 #include "FileDlg.h"8 #include "WinResUtil.h"9 #include "VBA.h"11 #include "../gb/gbGlobals.h"13 void GBPaletteViewControl::updatePalette()14 {15 if (gbRom)16 {17 memcpy(palette, &gbPalette[paletteAddress], 64);18 }19 }21 /////////////////////////////////////////////////////////////////////////////22 // GBPaletteView dialog24 GBPaletteView::GBPaletteView(CWnd*pParent /*=NULL*/)25 : ResizeDlg(GBPaletteView::IDD, pParent)26 {27 //{{AFX_DATA_INIT(GBPaletteView)28 // NOTE: the ClassWizard will add member initialization here29 //}}AFX_DATA_INIT30 autoUpdate = false;31 }33 GBPaletteView::~GBPaletteView()34 {}36 void GBPaletteView::DoDataExchange(CDataExchange*pDX)37 {38 CDialog::DoDataExchange(pDX);39 //{{AFX_DATA_MAP(GBPaletteView)40 // NOTE: the ClassWizard will add DDX and DDV calls here41 //}}AFX_DATA_MAP42 DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView);43 DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ);44 DDX_Control(pDX, IDC_COLOR, colorControl);45 }47 BEGIN_MESSAGE_MAP(GBPaletteView, CDialog)48 //{{AFX_MSG_MAP(GBPaletteView)49 ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg)50 ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj)51 ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2)52 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)53 ON_BN_CLICKED(IDC_CLOSE, OnClose)54 //}}AFX_MSG_MAP55 ON_MESSAGE(WM_PALINFO, OnPalInfo)56 END_MESSAGE_MAP()58 /////////////////////////////////////////////////////////////////////////////59 // GBPaletteView message handlers61 BOOL GBPaletteView::OnInitDialog()62 {63 CDialog::OnInitDialog();65 DIALOG_SIZER_START(sz)66 DIALOG_SIZER_END()67 SetData(sz,68 FALSE,69 HKEY_CURRENT_USER,70 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBPaletteView",71 NULL);73 paletteView.init(32, 64, 128);74 paletteViewOBJ.init(32, 64, 128);76 paletteView.setPaletteAddress(0);77 paletteView.refresh();79 paletteViewOBJ.setPaletteAddress(32);80 paletteViewOBJ.refresh();82 return TRUE; // return TRUE unless you set the focus to a control83 // EXCEPTION: OCX Property Pages should return FALSE84 }86 void GBPaletteView::save(int which)87 {88 CString captureBuffer;90 if (which == 0)91 captureBuffer = "bg.pal";92 else93 captureBuffer = "obj.pal";95 LPCTSTR exts[] = {".pal", ".pal", ".act", NULL };97 CString filter = winResLoadFilter(IDS_FILTER_PAL);98 CString title = winResLoadString(IDS_SELECT_PALETTE_NAME);99 FileDlg dlg(this,100 captureBuffer,101 filter,102 1,103 "PAL",104 exts,105 "",106 title,107 true);109 if (dlg.DoModal() == IDCANCEL)110 {111 return;112 }114 PaletteViewControl *p = NULL;116 if (which == 0)117 p = &paletteView;118 else119 p = &paletteViewOBJ;121 switch (dlg.getFilterIndex())122 {123 case 0:124 case 1:125 p->saveMSPAL(captureBuffer);126 break;127 case 2:128 p->saveJASCPAL(captureBuffer);129 break;130 case 3:131 p->saveAdobe(captureBuffer);132 break;133 }134 }136 void GBPaletteView::OnSaveBg()137 {138 save(0);139 }141 void GBPaletteView::OnSaveObj()142 {143 save(1);144 }146 void GBPaletteView::OnRefresh2()147 {148 paletteView.refresh();149 paletteViewOBJ.refresh();150 }152 void GBPaletteView::update()153 {154 OnRefresh2();155 }157 void GBPaletteView::OnAutoUpdate()158 {159 autoUpdate = !autoUpdate;160 if (autoUpdate)161 {162 theApp.winAddUpdateListener(this);163 }164 else165 {166 theApp.winRemoveUpdateListener(this);167 }168 }170 void GBPaletteView::OnClose()171 {172 theApp.winRemoveUpdateListener(this);174 DestroyWindow();175 }177 LRESULT GBPaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam)178 {179 u16 color = (u16)wParam;180 u32 address = (u32)lParam;181 CString buffer;183 bool isOBJ = address >= 32;184 address &= 31;186 buffer.Format("%d", address);187 GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);189 int r = (color & 0x1f);190 int g = (color & 0x3e0) >> 5;191 int b = (color & 0x7c00) >> 10;193 buffer.Format("%d", r);194 GetDlgItem(IDC_R)->SetWindowText(buffer);196 buffer.Format("%d", g);197 GetDlgItem(IDC_G)->SetWindowText(buffer);199 buffer.Format("%d", b);200 GetDlgItem(IDC_B)->SetWindowText(buffer);202 buffer.Format("0x%04X", color);203 GetDlgItem(IDC_VALUE)->SetWindowText(buffer);205 colorControl.setColor(color);207 if (isOBJ)208 paletteView.setSelected(-1);209 else210 paletteViewOBJ.setSelected(-1);212 return TRUE;213 }215 void GBPaletteView::PostNcDestroy()216 {217 delete this;218 }