Mercurial > vba-clojure
view src/win32/PaletteView.cpp @ 4:5f6f2134e8ce
apu appears to not be used
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:35:58 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 // PaletteView.cpp : implementation file2 //4 #include "stdafx.h"5 #include "FileDlg.h"6 #include "PaletteView.h"7 #include "WinResUtil.h"8 #include "VBA.h" // for theApp10 #include "../gba/GBAGlobals.h"12 void GBAPaletteViewControl::updatePalette()13 {14 if (paletteRAM != NULL)15 memcpy(palette, &paletteRAM[paletteAddress], 512);16 }18 /////////////////////////////////////////////////////////////////////////////19 // PaletteView dialog21 PaletteView::PaletteView(CWnd*pParent /*=NULL*/)22 : ResizeDlg(PaletteView::IDD, pParent)23 {24 //{{AFX_DATA_INIT(PaletteView)25 // NOTE: the ClassWizard will add member initialization here26 //}}AFX_DATA_INIT27 autoUpdate = false;28 }30 PaletteView::~PaletteView()31 {}33 void PaletteView::DoDataExchange(CDataExchange*pDX)34 {35 CDialog::DoDataExchange(pDX);36 //{{AFX_DATA_MAP(PaletteView)37 // NOTE: the ClassWizard will add DDX and DDV calls here38 //}}AFX_DATA_MAP39 DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView);40 DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ);41 DDX_Control(pDX, IDC_COLOR, colorControl);42 }44 BEGIN_MESSAGE_MAP(PaletteView, CDialog)45 //{{AFX_MSG_MAP(PaletteView)46 ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg)47 ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj)48 ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2)49 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)50 ON_BN_CLICKED(IDC_CLOSE, OnClose)51 //}}AFX_MSG_MAP52 ON_MESSAGE(WM_PALINFO, OnPalInfo)53 END_MESSAGE_MAP()55 /////////////////////////////////////////////////////////////////////////////56 // PaletteView message handlers58 BOOL PaletteView::OnInitDialog()59 {60 CDialog::OnInitDialog();62 DIALOG_SIZER_START(sz)63 DIALOG_SIZER_END()64 SetData(sz,65 FALSE,66 HKEY_CURRENT_USER,67 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\PaletteView",68 NULL);70 paletteView.setPaletteAddress(0);71 paletteView.refresh();73 paletteViewOBJ.setPaletteAddress(0x200);74 paletteViewOBJ.refresh();76 return TRUE; // return TRUE unless you set the focus to a control77 // EXCEPTION: OCX Property Pages should return FALSE78 }80 void PaletteView::save(int which)81 {82 CString captureBuffer;84 if (which == 0)85 captureBuffer = "bg.pal";86 else87 captureBuffer = "obj.pal";89 LPCTSTR exts[] = {".pal", ".pal", ".act", NULL };91 CString filter = winResLoadFilter(IDS_FILTER_PAL);92 CString title = winResLoadString(IDS_SELECT_PALETTE_NAME);93 FileDlg dlg(this,94 captureBuffer,95 filter,96 1,97 "PAL",98 exts,99 "",100 title,101 true);103 if (dlg.DoModal() == IDCANCEL)104 {105 return;106 }108 PaletteViewControl *p = NULL;110 if (which == 0)111 p = &paletteView;112 else113 p = &paletteViewOBJ;115 switch (dlg.getFilterIndex())116 {117 case 0:118 case 1:119 p->saveMSPAL(captureBuffer);120 break;121 case 2:122 p->saveJASCPAL(captureBuffer);123 break;124 case 3:125 p->saveAdobe(captureBuffer);126 break;127 }128 }130 void PaletteView::OnSaveBg()131 {132 save(0);133 }135 void PaletteView::OnSaveObj()136 {137 save(1);138 }140 void PaletteView::OnRefresh2()141 {142 paletteView.refresh();143 paletteViewOBJ.refresh();144 }146 void PaletteView::update()147 {148 OnRefresh2();149 }151 void PaletteView::OnAutoUpdate()152 {153 autoUpdate = !autoUpdate;154 if (autoUpdate)155 {156 theApp.winAddUpdateListener(this);157 }158 else159 {160 theApp.winRemoveUpdateListener(this);161 }162 }164 void PaletteView::OnClose()165 {166 theApp.winRemoveUpdateListener(this);168 DestroyWindow();169 }171 LRESULT PaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam)172 {173 u16 color = (u16)wParam;174 u32 address = (u32)lParam;175 CString buffer;177 if (address >= 0x200)178 address = 0x5000200 + 2*(address & 255);179 else180 address = 0x5000000 + 2*(address & 255);182 buffer.Format("0x%08X", address);183 GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);185 int r = (color & 0x1f);186 int g = (color & 0x3e0) >> 5;187 int b = (color & 0x7c00) >> 10;189 buffer.Format("%d", r);190 GetDlgItem(IDC_R)->SetWindowText(buffer);192 buffer.Format("%d", g);193 GetDlgItem(IDC_G)->SetWindowText(buffer);195 buffer.Format("%d", b);196 GetDlgItem(IDC_B)->SetWindowText(buffer);198 buffer.Format("0x%04X", color);199 GetDlgItem(IDC_VALUE)->SetWindowText(buffer);201 colorControl.setColor(color);203 if (address >= 0x5000200)204 {205 paletteView.setSelected(-1);206 }207 else208 paletteViewOBJ.setSelected(-1);210 return TRUE;211 }213 void PaletteView::PostNcDestroy()214 {215 delete this;216 }