svn path=/trunk/winforms-tools/; revision=51343

This commit is contained in:
Alexander Olk 2005-10-06 15:23:55 +00:00
Родитель 50d513611d
Коммит e33d9476e2
14 изменённых файлов: 367 добавлений и 257 удалений

Просмотреть файл

@ -83,31 +83,40 @@ namespace MWFResourceEditor
protected override void OnPaint( PaintEventArgs pea )
{
base.OnPaint( pea );
Bitmap bmp = new Bitmap( pea.ClipRectangle.Width, pea.ClipRectangle.Height, pea.Graphics );
Graphics gr = Graphics.FromImage( bmp );
if ( formsDrawn )
using ( Bitmap bmp = new Bitmap( pea.ClipRectangle.Width, pea.ClipRectangle.Height, pea.Graphics ) )
{
gr.DrawString( "Managed", paintFont, shadowBrush, new Point( 75, 15 ) );
gr.DrawString( "Windows", paintFont, shadowBrush, new Point( 75, 65 ) );
gr.DrawString( "Forms", paintFont, shadowBrush, new Point( 75, 115 ) );
gr.DrawString( "Resource Editor", smallFont, new SolidBrush( Color.Black ), new Point( 80, 185 ) );
managedPaintBrush = new SolidBrush( Color.Red );
windowsPaintBrush = new SolidBrush( Color.Red );
formsPaintBrush = new SolidBrush( Color.Red );
using ( Graphics gr = Graphics.FromImage( bmp ) )
{
if ( formsDrawn )
{
gr.DrawString( "Managed", paintFont, shadowBrush, new Point( 75, 15 ) );
gr.DrawString( "Windows", paintFont, shadowBrush, new Point( 75, 65 ) );
gr.DrawString( "Forms", paintFont, shadowBrush, new Point( 75, 115 ) );
gr.DrawString( "Resource Editor", smallFont, new SolidBrush( Color.Black ), new Point( 80, 185 ) );
if ( managedPaintBrush != null )
managedPaintBrush.Dispose();
managedPaintBrush = new SolidBrush( Color.Red );
if ( windowsPaintBrush != null )
windowsPaintBrush.Dispose();
windowsPaintBrush = new SolidBrush( Color.Red );
if ( formsPaintBrush != null )
formsPaintBrush.Dispose();
formsPaintBrush = new SolidBrush( Color.Red );
}
gr.DrawString( "Managed", paintFont, managedPaintBrush, new Point( 70, 10 ) );
gr.DrawString( "Windows", paintFont, windowsPaintBrush, new Point( 70, 60 ) );
gr.DrawString( "Forms", paintFont, formsPaintBrush, new Point( 70, 110 ) );
pea.Graphics.DrawImage( bmp, pea.ClipRectangle.X, pea.ClipRectangle.Y );
}
}
gr.DrawString( "Managed", paintFont, managedPaintBrush, new Point( 70, 10 ) );
gr.DrawString( "Windows", paintFont, windowsPaintBrush, new Point( 70, 60 ) );
gr.DrawString( "Forms", paintFont, formsPaintBrush, new Point( 70, 110 ) );
pea.Graphics.DrawImage( bmp, pea.ClipRectangle.X, pea.ClipRectangle.Y );
base.OnPaint( pea );
}
protected override void OnVisibleChanged( EventArgs e )
@ -125,6 +134,8 @@ namespace MWFResourceEditor
if ( !managedDrawn )
{
paintColor = Color.FromArgb( counter++, Color.Red );
if ( managedPaintBrush != null )
managedPaintBrush.Dispose();
managedPaintBrush = new SolidBrush( paintColor );
if ( counter == alphaMax )
{
@ -136,6 +147,8 @@ namespace MWFResourceEditor
if ( !windowsDrawn )
{
paintColor = Color.FromArgb( counter++, Color.Red );
if ( windowsPaintBrush != null )
windowsPaintBrush.Dispose();
windowsPaintBrush = new SolidBrush( paintColor );
if ( counter == alphaMax )
{
@ -147,6 +160,8 @@ namespace MWFResourceEditor
if ( !formsDrawn )
{
paintColor = Color.FromArgb( counter++, Color.Red );
if ( formsPaintBrush != null )
formsPaintBrush.Dispose();
formsPaintBrush = new SolidBrush( paintColor );
if ( counter == alphaMax )
{

Просмотреть файл

@ -42,7 +42,7 @@ namespace MWFResourceEditor
| System.Windows.Forms.AnchorStyles.Left )
| System.Windows.Forms.AnchorStyles.Right ) ) );
textBox.Size = new Size( 586, 180 );
textBox.ScrollBars = ScrollBars.Vertical | ScrollBars.Horizontal;
// textBox.ScrollBars = ScrollBars.Vertical;
textBox.Font = new Font( FontFamily.GenericMonospace, 8 );
Controls.Add( textBox );
@ -84,13 +84,17 @@ namespace MWFResourceEditor
{
bool new_line = false;
int show_how_many_bytes = byteArray.Length > 1024 ? 1024 : byteArray.Length;
StringBuilder back_string = back_string = new StringBuilder( 19 );
sb_hex.Append( "00000000 " );
for ( int i = 0; i < byteArray.Length; i++ )
for ( int i = 0; i < show_how_many_bytes; i++ )
{
sb_text.Append( Convert.ToChar( byteArray[ i ] ) );
char c = Convert.ToChar( byteArray[ i ] );
sb_text.Append( c );
if ( new_line )
{
@ -109,8 +113,8 @@ namespace MWFResourceEditor
sb_hex.Append( byteArray[ i ].ToString( "X2" ) + " " );
if ( byteArray[ i ] != 9 && byteArray[ i ] != 10 && byteArray[ i ] != 13 )
back_string.Append( Convert.ToChar( byteArray[ i ] ) );
if ( Char.IsLetterOrDigit( c ) )
back_string.Append( c );
else
back_string.Append( "." );

Просмотреть файл

@ -1,3 +1,21 @@
2005-10-06 Alexander Olk <alex.olk@googlemail.com>
* AboutDialog.cs, ByteArrayPanel.cs, ImagePanel.cs, MainForm.cs,
ResourceBase.cs, ResourceByteArray.cs, ResourceColor.cs, ResourceCursor.cs,
ResourceIcon.cs, ResourceImage.cs, ResourceListBox.cs, ResourceString.cs,
TextPanel.cs:
- Use "Dispose" or "using" for graphics objects wherever it is possible
- Disable TextBox ScrollBars until they are fixed
- Reduce number of shown bytes in ByteArrayPanel to 1024
- Draw Button in ImagePanel after PictureBox
- Give a little hint in the titlebar if a file isn't saved
- On exit ask if an unsaved file should be saved
- During runtime FileDialog remembers the recently used path now and doesn't
delete the currently used resources if you press cancel in OpenFileDialog
- Moved some code from the ResourceXXX classes to ResourceBase
- Use Image.GetThumbnailImage to get a thumbnail for an image or an icon
- Keep aspect ratio in thumbnails
2005-09-21 Alexander Olk <xenomorph2@onlinehome.de>
* ResourceListBox.cs: Add cursor here, too

Просмотреть файл

@ -12,6 +12,7 @@ namespace MWFResourceEditor
{
private Image image;
private Icon icon;
private Icon old_icon;
private string imageOrIconName;
private PictureBox pictureBox;
private Button button;
@ -27,6 +28,7 @@ namespace MWFResourceEditor
SuspendLayout( );
BackColor = Color.LightSlateGray;
pictureBox.BackColor = Color.LightSlateGray;
button.Location = new Point( 10, 10 );
button.Size = new Size( 120, 21 );
@ -36,8 +38,8 @@ namespace MWFResourceEditor
Dock = DockStyle.Fill;
DockPadding.All = 5;
Controls.Add( button );
Controls.Add( pictureBox );
Controls.Add( button );
ResumeLayout( false );
}
@ -73,6 +75,11 @@ namespace MWFResourceEditor
set {
icon = value;
if ( old_icon != null )
old_icon.Dispose();
old_icon = icon;
pictureBox.Image = icon.ToBitmap( );
pictureBox.Size = pictureBox.Image.Size;
pictureBox.Location = new Point( ( Width / 2 ) - ( icon.Width / 2 ), ( Height / 2 ) - ( icon.Height / 2 ) );

Просмотреть файл

@ -51,6 +51,13 @@ namespace MWFResourceEditor
private string fullFileName = "New Resource.resx";
private string last_load_resx_directory = String.Empty;
private string last_add_files_directory = String.Empty;
private string last_save_as_directory = String.Empty;
private bool fileSaved = true;
private bool first_time_saved = false;
public MainForm( )
{
InitializeComponent( );
@ -170,16 +177,16 @@ namespace MWFResourceEditor
menuItemAddColor.Click += new EventHandler( OnMenuItemAddColorClick );
// menuItemDash2
menuItemDash2.Index = 11;
menuItemDash2.Index = 12;
menuItemDash2.Text = "-";
// menuItemDelete
menuItemDelete.Index = 12;
menuItemDelete.Index = 13;
menuItemDelete.Text = "&Delete";
menuItemDelete.Click += new EventHandler( OnMenuItemDeleteClick );
// menuItemCopy
menuItemCopy.Index = 13;
menuItemCopy.Index = 14;
menuItemCopy.Text = "&Copy";
menuItemCopy.Click += new EventHandler( OnMenuItemCopyClick );
@ -267,7 +274,7 @@ namespace MWFResourceEditor
ClientSize = new Size( 592, 541 );
Menu = mainMenu;
Text = "MWF ResourceEditor";
Text = "New Resource.resx";
Controls.Add( contentControl );
Controls.Add( splitter );
@ -281,12 +288,50 @@ namespace MWFResourceEditor
resourceListBox.SelectedIndexChanged += new EventHandler( OnResourceListBoxSelectedIndexChanged );
}
public bool FileSaved
{
set {
fileSaved = value;
if ( !fileSaved )
{
string title = Text;
if ( !title.EndsWith( " *" ) )
{
title += " *";
Text = title;
}
}
else
{
string title = Text;
if ( title.EndsWith( " *" ) )
{
title = title.Replace( " *", "" );
Text = title;
}
}
}
get {
return fileSaved;
}
}
void OnMenuItemNewClick( object sender, EventArgs e )
{
fullFileName = "New Resource.resx";
Text = fullFileName;
FileSaved = false;
first_time_saved = false;
ResetListBox( );
}
@ -309,20 +354,26 @@ namespace MWFResourceEditor
void OnMenuItemLoadClick( object sender, EventArgs e )
{
ResetListBox( );
OpenFileDialog ofd = new OpenFileDialog( );
ofd.CheckFileExists = true;
ofd.Filter = "resx files (*.resx)|*.resx|All files (*.*)|*.*";
if ( last_load_resx_directory != String.Empty )
if ( Directory.Exists( last_load_resx_directory ) )
ofd.InitialDirectory = last_load_resx_directory;
if ( DialogResult.OK == ofd.ShowDialog( ) )
{
ResetListBox( );
resXResourceReader = new ResXResourceReader( ofd.FileName );
Text = Path.GetFileName( ofd.FileName );
fullFileName = ofd.FileName;
last_load_resx_directory = Path.GetDirectoryName( ofd.FileName );
FillListBox( );
resXResourceReader.Close( );
@ -334,25 +385,53 @@ namespace MWFResourceEditor
if ( resourceListBox.Items.Count == 0 )
return;
if ( !first_time_saved )
{
OnMenuItemSaveAsClick( sender, e );
return;
}
File.Delete( fullFileName );
WriteResourceFile( );
FileSaved = true;
}
void OnMenuItemSaveAsClick( object sender, EventArgs e )
{
if ( resourceListBox.Items.Count == 0 )
return;
SaveFileDialog sfd = new SaveFileDialog( );
sfd.CheckFileExists = true;
sfd.DefaultExt = "resx";
sfd.Filter = "resx files (*.resx)|*.resx|All files (*.*)|*.*";
if ( last_save_as_directory == String.Empty )
if ( last_load_resx_directory != String.Empty )
last_save_as_directory = last_load_resx_directory;
if ( last_save_as_directory != String.Empty )
if ( Directory.Exists( last_save_as_directory ) )
sfd.InitialDirectory = last_save_as_directory;
if ( DialogResult.OK == sfd.ShowDialog( ) )
{
fullFileName = sfd.FileName;
Text = Path.GetFileName( fullFileName );
last_save_as_directory = Path.GetDirectoryName( sfd.FileName );
if ( File.Exists( fullFileName ) )
File.Delete( fullFileName );
WriteResourceFile( );
FileSaved = true;
first_time_saved = true;
}
}
@ -428,7 +507,29 @@ namespace MWFResourceEditor
void OnMenuItemExitClick( object sender, EventArgs e )
{
Close( );
if ( !FileSaved )
{
string filename_short = Path.GetFileName( fullFileName );
DialogResult result = MessageBox.Show( "File " + filename_short + " not saved.\n\n" + "Save ?",
"Exit...",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question );
switch ( result )
{
case DialogResult.Yes:
OnMenuItemSaveClick( null, EventArgs.Empty );
if ( FileSaved )
Close( );
break;
case DialogResult.No:
Close( );
break;
default:
break;
}
}
}
void OnMenuItemAddStringClick( object sender, EventArgs e )
@ -453,6 +554,8 @@ namespace MWFResourceEditor
resourceListBox.TopIndex = 0;
resourceListBox.Invalidate( );
FileSaved = false;
}
}
@ -464,6 +567,10 @@ namespace MWFResourceEditor
ofd.Filter = "Images (*.png;*.jpg;*.gif;*.bmp)|*.png;*.jpg;*.gif;*.bmp|Icons (*.ico)|*.ico|Cursors (*.cur)|*.cur|All files (*.*)|*.*";
if ( last_add_files_directory != String.Empty )
if ( Directory.Exists( last_add_files_directory ) )
ofd.InitialDirectory = last_add_files_directory;
if ( DialogResult.OK == ofd.ShowDialog( ) )
{
foreach ( string file_name in ofd.FileNames )
@ -481,7 +588,8 @@ namespace MWFResourceEditor
resourceListBox.AddResourceDirect( resIcon );
resourceListBox.EndUpdate( );
}
else if ( upper_file_name.EndsWith( ".CUR" ) ) {
else if ( upper_file_name.EndsWith( ".CUR" ) )
{
ResourceCursor resCursor = new ResourceCursor( Path.GetFileName( file_name ), new Cursor( file_name ) );
resourceListBox.BeginUpdate( );
@ -489,7 +597,7 @@ namespace MWFResourceEditor
resourceListBox.EndUpdate( );
}
else
// images
// images
if ( upper_file_name.EndsWith( ".PNG" ) || upper_file_name.EndsWith( ".JPG" ) ||
upper_file_name.EndsWith( ".GIF" ) || upper_file_name.EndsWith( ".BMP" ) )
{
@ -526,6 +634,8 @@ namespace MWFResourceEditor
if ( ofd.FileNames.Length > 0 )
{
last_add_files_directory = Path.GetDirectoryName( ofd.FileNames[0] );
if ( resourceListBox.Items.Count > 0 )
{
resourceListBox.SelectedIndex = 0;
@ -536,6 +646,8 @@ namespace MWFResourceEditor
resourceListBox.Invalidate( );
}
FileSaved = false;
}
}
}
@ -551,6 +663,8 @@ namespace MWFResourceEditor
resourceListBox.AddResource( resource_name, cd.Color );
resourceListBox.Invalidate( );
FileSaved = false;
}
}
@ -562,6 +676,8 @@ namespace MWFResourceEditor
resourceListBox.RemoveResource( (IResource)resourceListBox.SelectedItems[ 0 ] );
resourceListBox.Invalidate( );
FileSaved = false;
}
void OnMenuItemCopyClick( object sender, EventArgs e )
@ -587,6 +703,8 @@ namespace MWFResourceEditor
resourceListBox.AddResourceDirect( resourceCopy );
resourceListBox.Invalidate( );
FileSaved = false;
}
void OnMenuItemRenameClick( object sender, EventArgs e )
@ -604,6 +722,8 @@ namespace MWFResourceEditor
resourceListBox.RenameResource( resource, new_resource_name );
resourceListBox.Invalidate( );
FileSaved = false;
}
}
@ -645,9 +765,10 @@ namespace MWFResourceEditor
ResourceString resString = (ResourceString)resource;
textPanel.ContentTextBox.Text = resString.Text;
break;
case ResourceType.TypeCursor:
if ( activePanel != imagePanel ) {
if ( activePanel != imagePanel )
{
activePanel.Hide( );
contentControl.Controls.Remove( activePanel );
contentControl.Controls.Add( imagePanel );
@ -660,7 +781,7 @@ namespace MWFResourceEditor
imagePanel.Image = resCursor.RenderContent;
break;
case ResourceType.TypeIcon:
if ( activePanel != imagePanel )
{
@ -775,6 +896,8 @@ namespace MWFResourceEditor
resourceListBox.EndUpdate( );
resourceListBox.Invalidate( );
FileSaved = false;
}
}

Просмотреть файл

@ -6,7 +6,7 @@ using System.Drawing;
namespace MWFResourceEditor
{
public abstract class ResourceBase
public abstract class ResourceBase : IResourceRenderer, ICloneable
{
protected string resource_name = null;
@ -30,6 +30,13 @@ namespace MWFResourceEditor
protected int all_data_for_rendering_available = 0;
public Bitmap RenderContent
{
get {
return renderBitmap;
}
}
public string ResourceName
{
get {
@ -50,6 +57,9 @@ namespace MWFResourceEditor
protected Graphics CreateNewRenderBitmap( )
{
if ( renderBitmap != null )
renderBitmap.Dispose( );
renderBitmap = new Bitmap( renderBitmap_size.Width, renderBitmap_size.Height );
Graphics gr = Graphics.FromImage( renderBitmap );
@ -63,6 +73,25 @@ namespace MWFResourceEditor
}
protected abstract void CreateRenderBitmap( );
public Object Clone( )
{
return this.MemberwiseClone( );
}
public bool DummyThumbnailCallback( )
{
return false;
}
public Image GetThumbNail( Image image, int new_width, int new_height )
{
Image.GetThumbnailImageAbort thumbnailCallback = new Image.GetThumbnailImageAbort( DummyThumbnailCallback );
Image thumbnail = image.GetThumbnailImage( new_width, new_height, thumbnailCallback, IntPtr.Zero );
return thumbnail;
}
}
}

Просмотреть файл

@ -6,7 +6,7 @@ using System.Drawing;
namespace MWFResourceEditor
{
public class ResourceByteArray : ResourceBase, IResource, IResourceRenderer
public class ResourceByteArray : ResourceBase, IResource
{
private byte[] byteArray = null;
@ -45,9 +45,6 @@ namespace MWFResourceEditor
}
}
public ResourceByteArray( )
{}
public ResourceByteArray( string name, byte[] byteArray )
{
ResourceName = name;
@ -80,18 +77,6 @@ namespace MWFResourceEditor
}
}
public object Clone( )
{
return this.MemberwiseClone( );
}
public Bitmap RenderContent
{
get {
return renderBitmap;
}
}
public string ContentString( )
{
return byteArray.ToString( );
@ -99,17 +84,16 @@ namespace MWFResourceEditor
protected override void CreateRenderBitmap( )
{
Graphics gr = CreateNewRenderBitmap( );
gr.DrawImage( one_and_zero, thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + byteArray.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Size: " + byteArray.Length, smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
gr.Dispose( );
using ( Graphics gr = CreateNewRenderBitmap( ) )
{
gr.DrawImage( one_and_zero, thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + byteArray.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Size: " + byteArray.Length, smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
}
}
}
}

Просмотреть файл

@ -6,13 +6,10 @@ using System.Drawing;
namespace MWFResourceEditor
{
public class ResourceColor : ResourceBase, IResource, IResourceRenderer
public class ResourceColor : ResourceBase, IResource
{
private Color color;
public ResourceColor( )
{}
public ResourceColor( string name, Color color )
{
ResourceName = name;
@ -26,11 +23,6 @@ namespace MWFResourceEditor
}
}
public object Clone( )
{
return this.MemberwiseClone( );
}
public Color Color
{
set {
@ -50,13 +42,6 @@ namespace MWFResourceEditor
}
}
public Bitmap RenderContent
{
get {
return renderBitmap;
}
}
public string ContentString( )
{
return color.ToString( );
@ -64,17 +49,16 @@ namespace MWFResourceEditor
protected override void CreateRenderBitmap( )
{
Graphics gr = CreateNewRenderBitmap( );
gr.FillRectangle( new SolidBrush( color ), thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + color.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Color: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
gr.Dispose( );
using ( Graphics gr = CreateNewRenderBitmap( ) )
{
gr.FillRectangle( new SolidBrush( color ), thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + color.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Color: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
}
}
}
}

Просмотреть файл

@ -8,13 +8,10 @@ using System.Windows.Forms;
namespace MWFResourceEditor
{
public class ResourceCursor : ResourceBase, IResource, IResourceRenderer
public class ResourceCursor : ResourceBase, IResource
{
private Cursor cursor = null;
public ResourceCursor( )
{}
public ResourceCursor( string name, Cursor cursor )
{
ResourceName = name;
@ -28,11 +25,6 @@ namespace MWFResourceEditor
}
}
public object Clone( )
{
return this.MemberwiseClone( );
}
public Cursor Cursor
{
set {
@ -51,13 +43,6 @@ namespace MWFResourceEditor
return cursor;
}
}
public Bitmap RenderContent
{
get {
return renderBitmap;
}
}
public string ContentString( )
{
@ -71,27 +56,26 @@ namespace MWFResourceEditor
protected override void CreateRenderBitmap( )
{
Graphics gr = CreateNewRenderBitmap( );
if ( cursor.Size.Width > thumb_size.Width || cursor.Size.Height > thumb_size.Height )
using ( Graphics gr = CreateNewRenderBitmap( ) )
{
cursor.DrawStretched(gr, new Rectangle(thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height));
}
else
{
int x = ( thumb_size.Width / 2 ) - ( cursor.Size.Width / 2 );
int y = ( thumb_size.Height / 2 ) - ( cursor.Size.Height / 2 );
if ( cursor.Size.Width > thumb_size.Width || cursor.Size.Height > thumb_size.Height )
{
cursor.DrawStretched( gr, new Rectangle( thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height ) );
}
else
{
int x = ( thumb_size.Width / 2 ) - ( cursor.Size.Width / 2 );
int y = ( thumb_size.Height / 2 ) - ( cursor.Size.Height / 2 );
cursor.Draw( gr, new Rectangle( x, y, cursor.Size.Width, cursor.Size.Height ) );
}
cursor.Draw(gr, new Rectangle(x, y, cursor.Size.Width, cursor.Size.Height));
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + cursor.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
}
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + cursor.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
gr.Dispose( );
}
}
}

Просмотреть файл

@ -6,13 +6,10 @@ using System.Drawing;
namespace MWFResourceEditor
{
public class ResourceIcon : ResourceBase, IResource, IResourceRenderer
public class ResourceIcon : ResourceBase, IResource
{
private Icon icon = null;
public ResourceIcon( )
{}
public ResourceIcon( string name, Icon icon )
{
ResourceName = name;
@ -26,11 +23,6 @@ namespace MWFResourceEditor
}
}
public object Clone( )
{
return this.MemberwiseClone( );
}
public Icon Icon
{
set {
@ -50,13 +42,6 @@ namespace MWFResourceEditor
}
}
public Bitmap RenderContent
{
get {
return renderBitmap;
}
}
public string ContentString( )
{
string imagesize = "Width = ";
@ -69,37 +54,35 @@ namespace MWFResourceEditor
protected override void CreateRenderBitmap( )
{
Graphics gr = CreateNewRenderBitmap( );
if ( icon.Width > thumb_size.Width || icon.Height > thumb_size.Height )
using ( Graphics gr = CreateNewRenderBitmap( ) )
{
Bitmap reformated = new Bitmap( thumb_size.Width, thumb_size.Height );
if ( icon.Width >= thumb_size.Width || icon.Height >= thumb_size.Height )
{
int new_width = icon.Width < thumb_size.Width - 1 ? icon.Width : thumb_size.Width - 1;
int new_height = icon.Height < thumb_size.Height - 1 ? icon.Height : thumb_size.Height - 1;
using ( Image thumbnail = GetThumbNail( icon.ToBitmap( ) , new_width, new_height ) )
{
int x = ( thumb_size.Width / 2 ) - ( thumbnail.Width / 2 ) - 1;
int y = ( thumb_size.Height / 2 ) - ( thumbnail.Height / 2 );
gr.DrawImage( thumbnail, thumb_location.X + x, thumb_location.Y + y );
}
}
else
{
int x = ( thumb_size.Width / 2 ) - ( icon.Width / 2 );
int y = ( thumb_size.Height / 2 ) - ( icon.Height / 2 );
gr.DrawImage( icon.ToBitmap( ), thumb_location.X + x, thumb_location.Y + y );
}
Graphics gb = Graphics.FromImage( reformated );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
Image image = icon.ToBitmap( );
gr.DrawString( "Type: " + icon.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gb.DrawImage( image, new Rectangle( 0, 0, thumb_size.Width, thumb_size.Height ), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel );
gr.DrawImage( reformated, thumb_location.X, thumb_location.Y );
gb.Dispose( );
gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
}
else
{
int x = ( thumb_size.Width / 2 ) - ( icon.Width / 2 );
int y = ( thumb_size.Height / 2 ) - ( icon.Height / 2 );
gr.DrawIcon( icon, x, y );
}
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + icon.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
gr.Dispose( );
}
}
}

Просмотреть файл

@ -6,12 +6,10 @@ using System.Drawing;
namespace MWFResourceEditor
{
public class ResourceImage : ResourceBase, IResource, IResourceRenderer
public class ResourceImage : ResourceBase, IResource
{
private Image image = null;
public ResourceImage( )
{}
private Image old_image = null;
public ResourceImage( string name, Image image )
{
@ -26,18 +24,17 @@ namespace MWFResourceEditor
}
}
public Object Clone( )
{
return this.MemberwiseClone( );
}
public Image Image
{
set {
if ( old_image != null )
old_image.Dispose( );
if ( image != null )
all_data_for_rendering_available = 1;
image = value;
old_image = image;
all_data_for_rendering_available++;
@ -50,13 +47,6 @@ namespace MWFResourceEditor
}
}
public Bitmap RenderContent
{
get {
return renderBitmap;
}
}
public string ContentString( )
{
string imagesize = "Width = ";
@ -69,35 +59,35 @@ namespace MWFResourceEditor
protected override void CreateRenderBitmap( )
{
Graphics gr = CreateNewRenderBitmap( );
if ( image.Width > thumb_size.Width || image.Height > thumb_size.Height )
using ( Graphics gr = CreateNewRenderBitmap( ) )
{
Bitmap reformated = new Bitmap( thumb_size.Width, thumb_size.Height );
if ( image.Width >= thumb_size.Width || image.Height >= thumb_size.Height )
{
int new_width = image.Width < thumb_size.Width - 1 ? image.Width : thumb_size.Width - 1;
int new_height = image.Height < thumb_size.Height - 1 ? image.Height : thumb_size.Height - 1;
using ( Image thumbnail = GetThumbNail( image , new_width, new_height ) )
{
int x = ( thumb_size.Width / 2 ) - ( thumbnail.Width / 2 ) - 1;
int y = ( thumb_size.Height / 2 ) - ( thumbnail.Height / 2 );
gr.DrawImage( thumbnail, thumb_location.X + x, thumb_location.Y + y );
}
}
else
{
int x = ( thumb_size.Width / 2 ) - ( image.Width / 2 );
int y = ( thumb_size.Height / 2 ) - ( image.Height / 2 );
gr.DrawImage( image, thumb_location.X + x, thumb_location.Y + y );
}
Graphics gb = Graphics.FromImage( reformated );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gb.DrawImage( image, new Rectangle( 0, 0, thumb_size.Width, thumb_size.Height ), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel );
gr.DrawString( "Type: " + image.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawImage( reformated, thumb_location.X, thumb_location.Y );
gb.Dispose( );
gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
}
else
{
int x = ( thumb_size.Width / 2 ) - ( image.Width / 2 );
int y = ( thumb_size.Height / 2 ) - ( image.Height / 2 );
gr.DrawImage( image, x, y );
}
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + image.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
gr.Dispose( );
}
}
}

Просмотреть файл

@ -14,6 +14,9 @@ namespace MWFResourceEditor
private static int newResourceCounter = 1;
private SolidBrush lightBlueBrush = new SolidBrush( Color.LightBlue );
private SolidBrush beigeBrush = new SolidBrush( Color.Beige );
public ResourceListBox( )
{
Size = new Size( 500, 300 );
@ -29,9 +32,9 @@ namespace MWFResourceEditor
IResourceRenderer renderer = (IResourceRenderer)Items[ e.Index ];
if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
e.Graphics.FillRectangle( new SolidBrush( Color.LightBlue ), e.Bounds );
e.Graphics.FillRectangle( lightBlueBrush, e.Bounds );
else
e.Graphics.FillRectangle( new SolidBrush( Color.Beige ), e.Bounds );
e.Graphics.FillRectangle( beigeBrush, e.Bounds );
e.Graphics.DrawImage( renderer.RenderContent, e.Bounds.X + 3, e.Bounds.Y + 1 );

Просмотреть файл

@ -6,13 +6,10 @@ using System.Drawing;
namespace MWFResourceEditor
{
public class ResourceString : ResourceBase, IResource, IResourceRenderer
public class ResourceString : ResourceBase, IResource
{
private string text = null;
public ResourceString( )
{}
public ResourceString( string name, string text )
{
ResourceName = name;
@ -26,11 +23,6 @@ namespace MWFResourceEditor
}
}
public Object Clone( )
{
return this.MemberwiseClone( );
}
public string Text
{
set {
@ -50,13 +42,6 @@ namespace MWFResourceEditor
}
}
public Bitmap RenderContent
{
get {
return renderBitmap;
}
}
public string ContentString( )
{
return text;
@ -64,33 +49,34 @@ namespace MWFResourceEditor
protected override void CreateRenderBitmap( )
{
Graphics gr = CreateNewRenderBitmap( );
SizeF fontSizeF = gr.MeasureString( text, smallFont );
int text_width = (int)fontSizeF.Width;
int text_height = (int)fontSizeF.Height;
int x = ( thumb_size.Width / 2 ) - ( text_width / 2 );
if ( x < 0 ) x = 0;
int y = ( thumb_size.Height / 2 ) - ( text_height / 2 );
Bitmap bmp = new Bitmap( thumb_size.Width, thumb_size.Height );
Graphics gr_bmp = Graphics.FromImage( bmp );
gr_bmp.DrawString( text, smallFont, solidBrushAqua, x, y );
gr.DrawImage( bmp, thumb_location.X, thumb_location.Y );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + text.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Content: " + text, smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
gr.Dispose( );
using ( Graphics gr = CreateNewRenderBitmap( ) )
{
SizeF fontSizeF = gr.MeasureString( text, smallFont );
int text_width = (int)fontSizeF.Width;
int text_height = (int)fontSizeF.Height;
int x = ( thumb_size.Width / 2 ) - ( text_width / 2 );
if ( x < 0 ) x = 0;
int y = ( thumb_size.Height / 2 ) - ( text_height / 2 );
using ( Bitmap bmp = new Bitmap( thumb_size.Width, thumb_size.Height ) )
{
using ( Graphics gr_bmp = Graphics.FromImage( bmp ) )
{
gr_bmp.DrawString( text, smallFont, solidBrushAqua, x, y );
}
gr.DrawImage( bmp, thumb_location.X, thumb_location.Y );
gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
gr.DrawString( "Type: " + text.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
gr.DrawString( "Content: " + text, smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
}
}
}
}
}

Просмотреть файл

@ -34,7 +34,7 @@ namespace MWFResourceEditor
contentTextBox.Multiline = true;
contentTextBox.AcceptsReturn = true;
contentTextBox.AcceptsTab = true;
contentTextBox.ScrollBars = ScrollBars.Vertical | ScrollBars.Horizontal;
// contentTextBox.ScrollBars = ScrollBars.Both;
acceptButton.Text = "Accept Changes";
acceptButton.Location = new Point( 3, 3 );