home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / PaletteView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  5.3 KB  |  241 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. // PaletteView.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "vba.h"
  24. #include "FileDlg.h"
  25. #include "PaletteView.h"
  26. #include "WinResUtil.h"
  27.  
  28. #include "../System.h"
  29. #include "../GBA.h"
  30. #include "../Globals.h"
  31.  
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37.  
  38. void GBAPaletteViewControl::updatePalette()
  39. {
  40.   if(paletteRAM != NULL)
  41.     memcpy(palette, &paletteRAM[paletteAddress], 512);
  42. }
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // PaletteView dialog
  46.  
  47.  
  48. PaletteView::PaletteView(CWnd* pParent /*=NULL*/)
  49.   : ResizeDlg(PaletteView::IDD, pParent)
  50. {
  51.   //{{AFX_DATA_INIT(PaletteView)
  52.   // NOTE: the ClassWizard will add member initialization here
  53.   //}}AFX_DATA_INIT
  54.   autoUpdate = false;
  55. }
  56.  
  57. PaletteView::~PaletteView()
  58. {
  59. }
  60.  
  61.  
  62. void PaletteView::DoDataExchange(CDataExchange* pDX)
  63. {
  64.   CDialog::DoDataExchange(pDX);
  65.   //{{AFX_DATA_MAP(PaletteView)
  66.   // NOTE: the ClassWizard will add DDX and DDV calls here
  67.   //}}AFX_DATA_MAP
  68.   DDX_Control(pDX, IDC_PALETTE_VIEW, paletteView);
  69.   DDX_Control(pDX, IDC_PALETTE_VIEW_OBJ, paletteViewOBJ);
  70.   DDX_Control(pDX, IDC_COLOR, colorControl);
  71. }
  72.  
  73.  
  74. BEGIN_MESSAGE_MAP(PaletteView, CDialog)
  75.   //{{AFX_MSG_MAP(PaletteView)
  76.   ON_BN_CLICKED(IDC_SAVE_BG, OnSaveBg)
  77.   ON_BN_CLICKED(IDC_SAVE_OBJ, OnSaveObj)
  78.   ON_BN_CLICKED(IDC_REFRESH2, OnRefresh2)
  79.   ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  80.   ON_BN_CLICKED(IDC_CLOSE, OnClose)
  81.   //}}AFX_MSG_MAP
  82.   ON_MESSAGE(WM_PALINFO, OnPalInfo)
  83.   END_MESSAGE_MAP()
  84.  
  85.   /////////////////////////////////////////////////////////////////////////////
  86. // PaletteView message handlers
  87.  
  88. BOOL PaletteView::OnInitDialog() 
  89. {
  90.   CDialog::OnInitDialog();
  91.   
  92.   DIALOG_SIZER_START( sz )
  93.     DIALOG_SIZER_END()
  94.     SetData(sz,
  95.             FALSE,
  96.             HKEY_CURRENT_USER,
  97.             "Software\\Emulators\\VisualBoyAdvance\\Viewer\\PaletteView",
  98.             NULL);
  99.   
  100.   paletteView.setPaletteAddress(0);
  101.   paletteView.refresh();  
  102.   
  103.   paletteViewOBJ.setPaletteAddress(0x200);
  104.   paletteViewOBJ.refresh();  
  105.   
  106.   return TRUE;  // return TRUE unless you set the focus to a control
  107.                 // EXCEPTION: OCX Property Pages should return FALSE
  108. }
  109.  
  110. void PaletteView::save(int which)
  111. {
  112.   CString captureBuffer;
  113.  
  114.   if(which == 0)
  115.     captureBuffer = "bg.pal";
  116.   else
  117.     captureBuffer = "obj.pal";
  118.  
  119.   LPCTSTR exts[] = {".pal", ".pal", ".act" };
  120.   
  121.   CString filter = theApp.winLoadFilter(IDS_FILTER_PAL);
  122.   CString title = winResLoadString(IDS_SELECT_PALETTE_NAME);
  123.   FileDlg dlg(this,
  124.               captureBuffer,
  125.               filter,
  126.               1,
  127.               "PAL",
  128.               exts,
  129.               "",
  130.               title,
  131.               true);
  132.  
  133.   if(dlg.DoModal() == IDCANCEL) {
  134.     return;
  135.   }
  136.  
  137.   PaletteViewControl *p = NULL;
  138.  
  139.   if(which == 0)
  140.     p = &paletteView;
  141.   else
  142.     p = &paletteViewOBJ;
  143.   
  144.   switch(dlg.getFilterIndex()) {
  145.   case 0:
  146.   case 1:
  147.     p->saveMSPAL(captureBuffer);
  148.     break;
  149.   case 2:
  150.     p->saveJASCPAL(captureBuffer);
  151.     break;
  152.   case 3:
  153.     p->saveAdobe(captureBuffer);
  154.     break;
  155.   }
  156. }
  157.  
  158. void PaletteView::OnSaveBg() 
  159. {
  160.   save(0);
  161. }
  162.  
  163. void PaletteView::OnSaveObj() 
  164. {
  165.   save(1);
  166. }
  167.  
  168. void PaletteView::OnRefresh2() 
  169. {
  170.   paletteView.refresh();
  171.   paletteViewOBJ.refresh();  
  172. }
  173.  
  174. void PaletteView::update()
  175. {
  176.   OnRefresh2();
  177. }
  178.  
  179.  
  180. void PaletteView::OnAutoUpdate() 
  181. {
  182.   autoUpdate = !autoUpdate;
  183.   if(autoUpdate) {
  184.     theApp.winAddUpdateListener(this);
  185.   } else {
  186.     theApp.winRemoveUpdateListener(this);    
  187.   }  
  188. }
  189.  
  190. void PaletteView::OnClose() 
  191. {
  192.   theApp.winRemoveUpdateListener(this);
  193.   
  194.   DestroyWindow();
  195. }
  196.  
  197. LRESULT PaletteView::OnPalInfo(WPARAM wParam, LPARAM lParam)
  198. {
  199.   u16 color = (u16)wParam;
  200.   u32 address = (u32)lParam;
  201.   CString buffer;
  202.  
  203.   if(address >= 0x200)
  204.     address = 0x5000200 + 2*(address & 255);
  205.   else
  206.     address = 0x5000000 + 2*(address & 255); 
  207.   
  208.   buffer.Format("0x%08X", address);
  209.   GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
  210.  
  211.   int r = (color & 0x1f);
  212.   int g = (color & 0x3e0) >> 5;
  213.   int b = (color & 0x7c00) >> 10;
  214.  
  215.   buffer.Format("%d", r);
  216.   GetDlgItem(IDC_R)->SetWindowText(buffer);
  217.  
  218.   buffer.Format("%d", g);
  219.   GetDlgItem(IDC_G)->SetWindowText(buffer);
  220.  
  221.   buffer.Format("%d", b);
  222.   GetDlgItem(IDC_B)->SetWindowText(buffer);
  223.  
  224.   buffer.Format("0x%04X", color);
  225.   GetDlgItem(IDC_VALUE)->SetWindowText(buffer);
  226.  
  227.   colorControl.setColor(color);
  228.  
  229.   if(address >= 0x5000200) {
  230.     paletteView.setSelected(-1);
  231.   } else
  232.     paletteViewOBJ.setSelected(-1);
  233.   
  234.   return TRUE;
  235. }
  236.  
  237. void PaletteView::PostNcDestroy() 
  238. {
  239.   delete this;
  240. }
  241.