1 ////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Nestopia - NES/Famicom emulator written in C++
4 //
5 // Copyright (C) 2003-2008 Martin Freij
6 //
7 // This file is part of Nestopia.
8 //
9 // Nestopia is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Nestopia is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Nestopia; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 //
23 ////////////////////////////////////////////////////////////////////////////////////////
24 
25 #ifndef NST_DIALOG_PALETTEEDITOR_H
26 #define NST_DIALOG_PALETTEEDITOR_H
27 
28 #pragma once
29 
30 #include "NstWindowDialog.hpp"
31 
32 namespace Nestopia
33 {
34 	namespace Window
35 	{
36 		class PaletteEditor
37 		{
38 		public:
39 
40 			PaletteEditor(Nes::Video&,const Managers::Paths&,const Path&);
41 			~PaletteEditor();
42 
43 		private:
44 
45 			struct Handlers;
46 
47 			enum
48 			{
49 				BMP_START_X = 8,
50 				BMP_START_Y = 8,
51 				BMP_COLOR_WIDTH = 24,
52 				BMP_COLOR_HEIGHT = 24,
53 				BMP_ROWS = 16,
54 				BMP_COLUMNS = 4,
55 				BMP_END_X = BMP_START_X + BMP_COLOR_WIDTH * BMP_ROWS,
56 				BMP_END_Y = BMP_START_Y + BMP_COLOR_HEIGHT * BMP_COLUMNS,
57 				BMP_COLOR_SELECT = 0xFF,
58 				BMP_COLOR_UNSELECT = 0x50
59 			};
60 
61 			struct Settings
62 			{
63 				explicit Settings(Nes::Video);
64 
65 				void Restore(Nes::Video) const;
66 
67 				Nes::Video::Palette::Mode mode;
68 				Nes::Video::Palette::CustomType customType;
69 				uint brightness;
70 				uint saturation;
71 				uint hue;
72 				uchar palette[8*64][3];
73 			};
74 
75 			class History
76 			{
77 			public:
78 
79 				History();
80 
81 				void Reset();
82 				void Add(uint,uint);
83 				bool CanUndo() const;
84 				bool CanRedo() const;
85 				uint Undo(Nes::Video);
86 				uint Redo(Nes::Video);
87 
88 			private:
89 
90 				enum
91 				{
92 					LENGTH = 128,
93 					STOP = 0xFF
94 				};
95 
96 				uint pos;
97 				uchar data[LENGTH][2];
98 			};
99 
100 			void UpdateMode(bool=false);
101 			void UpdateColor();
102 			void UpdateColors();
103 
104 			ibool OnInitDialog  (Param&);
105 			ibool OnPaint       (Param&);
106 			ibool OnLButtonDown (Param&);
107 			ibool OnHScroll     (Param&);
108 			ibool OnCmdHex      (Param&);
109 			ibool OnCmdUndo     (Param&);
110 			ibool OnCmdRedo     (Param&);
111 			ibool OnCmdReset    (Param&);
112 			ibool OnCmdSave     (Param&);
113 			ibool OnCmdMode     (Param&);
114 
115 			Dialog dialog;
116 			uint colorSelect;
117 			Nes::Video emulator;
118 			const Managers::Paths& paths;
119 			Path path;
120 			ibool sliderDragging;
121 			History history;
122 			const Settings settings;
123 
124 			static bool showHex;
125 
126 		public:
127 
Open()128 			const Path& Open()
129 			{
130 				dialog.Open();
131 				return path;
132 			}
133 		};
134 	}
135 }
136 
137 #endif
138