1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
////////////////////////////////////////////////////////////////////////////////////////
//
// Nestopia - NES/Famicom emulator written in C++
//
// Copyright (C) 2003-2008 Martin Freij
//
// This file is part of Nestopia.
//
// Nestopia is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Nestopia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Nestopia; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
////////////////////////////////////////////////////////////////////////////////////////
#include "NstApplicationInstance.hpp"
#include "NstWindowParam.hpp"
#include "NstManagerEmulator.hpp"
#include "NstDialogVideoDecoder.hpp"
namespace Nestopia
{
namespace Window
{
NST_COMPILE_ASSERT
(
IDC_VIDEO_DECODER_GY_VALUE == IDC_VIDEO_DECODER_RY_VALUE + 1 &&
IDC_VIDEO_DECODER_BY_VALUE == IDC_VIDEO_DECODER_RY_VALUE + 2
);
NST_COMPILE_ASSERT
(
IDC_VIDEO_DECODER_GY_NUM == IDC_VIDEO_DECODER_RY_NUM + 1 &&
IDC_VIDEO_DECODER_BY_NUM == IDC_VIDEO_DECODER_RY_NUM + 2
);
NST_COMPILE_ASSERT
(
IDC_VIDEO_DECODER_GY_GAIN == IDC_VIDEO_DECODER_RY_GAIN + 1 &&
IDC_VIDEO_DECODER_BY_GAIN == IDC_VIDEO_DECODER_RY_GAIN + 2
);
struct VideoDecoder::Handlers
{
static const MsgHandler::Entry<VideoDecoder> messages[];
static const MsgHandler::Entry<VideoDecoder> commands[];
};
const MsgHandler::Entry<VideoDecoder> VideoDecoder::Handlers::messages[] =
{
{ WM_INITDIALOG, &VideoDecoder::OnInitDialog },
{ WM_HSCROLL, &VideoDecoder::OnHScroll }
};
const MsgHandler::Entry<VideoDecoder> VideoDecoder::Handlers::commands[] =
{
{ IDC_VIDEO_DECODER_RY_GAIN, &VideoDecoder::OnCmdGain },
{ IDC_VIDEO_DECODER_GY_GAIN, &VideoDecoder::OnCmdGain },
{ IDC_VIDEO_DECODER_BY_GAIN, &VideoDecoder::OnCmdGain },
{ IDC_VIDEO_DECODER_BOOST_YELLOW, &VideoDecoder::OnCmdBoostYellow },
{ IDC_VIDEO_DECODER_CANONICAL , &VideoDecoder::OnCmdPreset },
{ IDC_VIDEO_DECODER_CONSUMER, &VideoDecoder::OnCmdPreset },
{ IDC_VIDEO_DECODER_ALTERNATIVE, &VideoDecoder::OnCmdPreset },
{ IDOK, &VideoDecoder::OnCmdOk }
};
VideoDecoder::VideoDecoder(Nes::Video e)
:
dialog (IDD_VIDEO_DECODER,this,Handlers::messages,Handlers::commands),
nes (e),
final (e.GetDecoder())
{
}
VideoDecoder::~VideoDecoder()
{
nes.SetDecoder( final );
}
void VideoDecoder::Load(const Configuration& cfg,Nes::Video nes)
{
Configuration::ConstSection decoder( cfg["video"]["decoder"] );
Nes::Video::Decoder nesDecoder( Nes::Video::DECODER_CANONICAL );
nesDecoder.boostYellow = decoder[ "yellow-boost" ].Yes();
for (uint i=0; i < 3; ++i)
{
static const char types[3][3] = {"ry","gy","by"};
Configuration::ConstSection axis( decoder[types[i]] );
GenericString string( axis[ "angle" ].Str() );
if (string.Length())
string >> nesDecoder.axes[i].angle;
string = axis[ "gain" ].Str();
if (string.Length())
{
nesDecoder.axes[i].gain = std::atof( String::Heap<char>(string).Ptr() );
nesDecoder.axes[i].gain = NST_CLAMP(nesDecoder.axes[i].gain,0.0f,2.0f);
}
}
nes.SetDecoder( nesDecoder );
}
void VideoDecoder::Save(Configuration& cfg,const Nes::Video nes)
{
Configuration::Section decoder( cfg["video"]["decoder"] );
const Nes::Video::Decoder& nesDecoder = nes.GetDecoder();
decoder[ "yellow-boost" ].YesNo() = nesDecoder.boostYellow;
for (uint i=0; i < 3; ++i)
{
static const char types[3][3] = {"ry","gy","by"};
Configuration::Section axis( decoder[types[i]] );
axis[ "angle" ].Int() = nesDecoder.axes[i].angle;
axis[ "gain" ].Str() = RealString( nesDecoder.axes[i].gain, 3, true );
}
}
ibool VideoDecoder::OnInitDialog(Param&)
{
for (uint i=0; i < 3; ++i)
{
dialog.Slider( IDC_VIDEO_DECODER_RY_VALUE+i ).SetRange( 0, 60 );
dialog.Edit( IDC_VIDEO_DECODER_RY_GAIN+i ).Limit( 5 );
}
Update();
return true;
}
ibool VideoDecoder::OnHScroll(Param& param)
{
const uint i = param.Slider().GetId() - IDC_VIDEO_DECODER_RY_VALUE;
if (i < 3)
{
Nes::Video::Decoder decoder( nes.GetDecoder() );
static const ushort offsets[3] = {60, 200, 330};
uint angle = param.Slider().Scroll() + offsets[i];
if (angle >= 360)
angle -= 360;
if (decoder.axes[i].angle != angle)
{
decoder.axes[i].angle = angle;
nes.SetDecoder( decoder );
dialog.Edit( IDC_VIDEO_DECODER_RY_NUM+i ) << angle;
Application::Instance::GetMainWindow().Redraw();
}
}
return true;
}
ibool VideoDecoder::OnCmdGain(Param& param)
{
if (param.Edit().Changed())
{
String::Heap<char> string;
dialog.Edit( param.Edit().GetId() ) >> string;
float gain = std::atof( string.Ptr() );
gain = NST_CLAMP(gain,0.0f,2.0f);
Nes::Video::Decoder decoder( nes.GetDecoder() );
decoder.axes[param.Edit().GetId() - IDC_VIDEO_DECODER_RY_GAIN].gain = gain;
if (nes.SetDecoder( decoder ) != Nes::RESULT_NOP)
Application::Instance::GetMainWindow().Redraw();
}
return true;
}
ibool VideoDecoder::OnCmdBoostYellow(Param& param)
{
if (param.Button().Clicked())
{
Nes::Video::Decoder decoder( nes.GetDecoder() );
decoder.boostYellow = dialog.CheckBox(IDC_VIDEO_DECODER_BOOST_YELLOW).Checked();
nes.SetDecoder( decoder );
Application::Instance::GetMainWindow().Redraw();
}
return true;
}
ibool VideoDecoder::OnCmdPreset(Param& param)
{
if (param.Button().Clicked())
{
Nes::Video::DecoderPreset preset;
switch (param.Button().GetId())
{
case IDC_VIDEO_DECODER_CONSUMER: preset = Nes::Video::DECODER_CONSUMER; break;
case IDC_VIDEO_DECODER_ALTERNATIVE: preset = Nes::Video::DECODER_ALTERNATIVE; break;
default: preset = Nes::Video::DECODER_CANONICAL; break;
}
nes.SetDecoder( preset );
Update();
Application::Instance::GetMainWindow().Redraw();
}
return true;
}
ibool VideoDecoder::OnCmdOk(Param& param)
{
if (param.Button().Clicked())
{
final = nes.GetDecoder();
dialog.Close();
}
return true;
}
void VideoDecoder::Update() const
{
Nes::Video::Decoder decoder( nes.GetDecoder() );
for (uint i=0; i < 3; ++i)
{
int angle = decoder.axes[i].angle;
dialog.Edit( IDC_VIDEO_DECODER_RY_NUM+i ) << uint(angle);
static const short offsets[3] = {60, 200, 330};
angle -= offsets[i];
if (angle < 0)
angle += 360;
dialog.Slider( IDC_VIDEO_DECODER_RY_VALUE+i ).Position() = uint(angle);
dialog.Edit( IDC_VIDEO_DECODER_RY_GAIN+i ).Text() << RealString( decoder.axes[i].gain, 3, true ).Ptr();
}
dialog.CheckBox( IDC_VIDEO_DECODER_BOOST_YELLOW ).Check( decoder.boostYellow );
}
}
}
|