2015-07-01 23:17:14 -04:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
2016-01-17 14:21:31 -05:00
using System.IO ;
2015-07-01 23:17:14 -04:00
using System.Linq ;
2016-01-17 14:21:31 -05:00
using System.Runtime.InteropServices ;
2015-07-01 23:17:14 -04:00
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
2015-07-23 23:16:31 -04:00
using Mesen.GUI.Config ;
2015-07-01 23:17:14 -04:00
namespace Mesen.GUI.Forms.Config
{
2015-07-03 00:12:02 -04:00
public partial class frmVideoConfig : BaseConfigForm
2015-07-01 23:17:14 -04:00
{
2016-01-17 14:21:31 -05:00
private Int32 [ ] _paletteData ;
2015-07-01 23:17:14 -04:00
public frmVideoConfig ( )
{
InitializeComponent ( ) ;
2015-07-23 23:16:31 -04:00
Entity = ConfigManager . Config . VideoInfo ;
2015-08-24 20:27:07 -04:00
AddBinding ( "EmulationSpeed" , nudEmulationSpeed ) ;
2015-07-23 23:16:31 -04:00
AddBinding ( "ShowFPS" , chkShowFps ) ;
2016-01-06 20:34:45 -05:00
AddBinding ( "VerticalSync" , chkVerticalSync ) ;
2016-01-16 09:50:33 -05:00
AddBinding ( "UseHdPacks" , chkUseHdPacks ) ;
2016-01-06 20:34:45 -05:00
2016-02-07 13:43:42 -05:00
AddBinding ( "VideoScale" , nudScale ) ;
2016-01-06 20:34:45 -05:00
AddBinding ( "AspectRatio" , cboAspectRatio ) ;
AddBinding ( "VideoFilter" , cboFilter ) ;
2015-07-23 23:16:31 -04:00
AddBinding ( "OverscanLeft" , nudOverscanLeft ) ;
AddBinding ( "OverscanRight" , nudOverscanRight ) ;
AddBinding ( "OverscanTop" , nudOverscanTop ) ;
AddBinding ( "OverscanBottom" , nudOverscanBottom ) ;
2016-01-16 09:50:33 -05:00
2016-01-17 14:21:31 -05:00
_paletteData = InteropEmu . GetRgbPalette ( ) ;
RefreshPalette ( ) ;
2016-01-16 09:50:33 -05:00
toolTip . SetToolTip ( picHdNesTooltip , "This option allows Mesen to load HDNes-format HD packs if they are found." + Environment . NewLine + Environment . NewLine + "HD Packs should be placed in the \"HdPacks\" folder in a subfolder matching the name of the ROM." + Environment . NewLine + "e.g: MyRom.nes should have their HD Pack in \"HdPacks\\MyRom\\hires.txt\"." + Environment . NewLine + Environment . NewLine + "Note: Support for HD Packs is a work in progress and some limitations remain." ) ;
2015-07-23 23:16:31 -04:00
}
2016-01-17 14:21:31 -05:00
2015-07-23 23:16:31 -04:00
protected override void OnFormClosed ( FormClosedEventArgs e )
{
2016-01-17 14:21:31 -05:00
if ( DialogResult = = System . Windows . Forms . DialogResult . OK ) {
( ( VideoInfo ) Entity ) . Palette = _paletteData ;
}
2015-07-23 23:16:31 -04:00
base . OnFormClosed ( e ) ;
VideoInfo . ApplyConfig ( ) ;
2015-07-01 23:17:14 -04:00
}
2016-01-17 14:21:31 -05:00
private void RefreshPalette ( )
{
GCHandle handle = GCHandle . Alloc ( _paletteData , GCHandleType . Pinned ) ;
try {
Bitmap source = new Bitmap ( 16 , 4 , 16 * 4 , System . Drawing . Imaging . PixelFormat . Format32bppArgb , handle . AddrOfPinnedObject ( ) ) ;
Bitmap target = new Bitmap ( 384 , 96 ) ;
using ( Graphics g = Graphics . FromImage ( target ) ) {
g . InterpolationMode = System . Drawing . Drawing2D . InterpolationMode . NearestNeighbor ;
g . SmoothingMode = System . Drawing . Drawing2D . SmoothingMode . None ;
g . PixelOffsetMode = System . Drawing . Drawing2D . PixelOffsetMode . Half ;
g . DrawImage ( source , new Rectangle ( 0 , 0 , 384 , 96 ) , new Rectangle ( 0 , 0 , 16 , 4 ) , GraphicsUnit . Pixel ) ;
}
this . picPalette . Image = target ;
} finally {
handle . Free ( ) ;
}
}
private void picPalette_MouseDown ( object sender , MouseEventArgs e )
{
int offset = ( e . X / 24 ) + ( e . Y / 24 * 16 ) ;
colorDialog . SolidColorOnly = true ;
colorDialog . AllowFullOpen = true ;
colorDialog . FullOpen = true ;
colorDialog . Color = Color . FromArgb ( _paletteData [ offset ] ) ;
if ( colorDialog . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
_paletteData [ offset ] = colorDialog . Color . ToArgb ( ) ;
}
RefreshPalette ( ) ;
}
private void btnResetPalette_Click ( object sender , EventArgs e )
{
_paletteData = ( Int32 [ ] ) ( ( object ) ( new UInt32 [ ] {
0xFF666666 , 0xFF002A88 , 0xFF1412A7 , 0xFF3B00A4 , 0xFF5C007E ,
0xFF6E0040 , 0xFF6C0600 , 0xFF561D00 , 0xFF333500 , 0xFF0B4800 ,
0xFF005200 , 0xFF004F08 , 0xFF00404D , 0xFF000000 , 0xFF000000 ,
0xFF000000 , 0xFFADADAD , 0xFF155FD9 , 0xFF4240FF , 0xFF7527FE ,
0xFFA01ACC , 0xFFB71E7B , 0xFFB53120 , 0xFF994E00 , 0xFF6B6D00 ,
0xFF388700 , 0xFF0C9300 , 0xFF008F32 , 0xFF007C8D , 0xFF000000 ,
0xFF000000 , 0xFF000000 , 0xFFFFFEFF , 0xFF64B0FF , 0xFF9290FF ,
0xFFC676FF , 0xFFF36AFF , 0xFFFE6ECC , 0xFFFE8170 , 0xFFEA9E22 ,
0xFFBCBE00 , 0xFF88D800 , 0xFF5CE430 , 0xFF45E082 , 0xFF48CDDE ,
0xFF4F4F4F , 0xFF000000 , 0xFF000000 , 0xFFFFFEFF , 0xFFC0DFFF ,
0xFFD3D2FF , 0xFFE8C8FF , 0xFFFBC2FF , 0xFFFEC4EA , 0xFFFECCC5 ,
0xFFF7D8A5 , 0xFFE4E594 , 0xFFCFEF96 , 0xFFBDF4AB , 0xFFB3F3CC ,
0xFFB5EBF2 , 0xFFB8B8B8 , 0xFF000000 , 0xFF000000
} ) ) ;
RefreshPalette ( ) ;
}
private void btnLoadPalFile_Click ( object sender , EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Palette Files (*.pal)|*.pal|All Files (*.*)|*.*" ;
if ( ofd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
using ( FileStream paletteFile = File . OpenRead ( ofd . FileName ) ) {
byte [ ] paletteFileData = new byte [ 64 * 3 ] ;
if ( paletteFile . Read ( paletteFileData , 0 , 64 * 3 ) = = 64 * 3 ) {
for ( int i = 0 ; i < 64 ; i + + ) {
int fileOffset = i * 3 ;
_paletteData [ i ] = ( Int32 ) ( ( UInt32 ) 0xFF000000 | ( UInt32 ) paletteFileData [ fileOffset + 2 ] | ( UInt32 ) ( paletteFileData [ fileOffset + 1 ] < < 8 ) | ( UInt32 ) ( paletteFileData [ fileOffset ] < < 16 ) ) ;
}
RefreshPalette ( ) ;
}
paletteFile . Close ( ) ;
}
}
}
2015-07-01 23:17:14 -04:00
}
}