git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1070 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
bob
2007-06-24 14:46:57 +00:00
parent 0b773950a9
commit b83b17385d
11 changed files with 146 additions and 30 deletions

View File

@@ -19,7 +19,7 @@ namespace ShpViewer
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "SHP Files|*.shp";
ofd.Filter = "SHP Files (*.shp)|*.shp|Terrain Files (*.tem; *.sno; *.int)|*.tem;*.sno;*.int|All Files (*.*)|*.*";
ofd.RestoreDirectory = true;
if( ofd.ShowDialog() == DialogResult.OK )
Application.Run( new ShpViewForm( ofd.FileName ) );

View File

@@ -34,20 +34,20 @@ namespace ShpViewer
// flowLayoutPanel1
//
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Location = new System.Drawing.Point( 0, 0 );
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(292, 273);
this.flowLayoutPanel1.Size = new System.Drawing.Size( 292, 273 );
this.flowLayoutPanel1.TabIndex = 0;
//
// ShpViewForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.flowLayoutPanel1);
this.ClientSize = new System.Drawing.Size( 292, 273 );
this.Controls.Add( this.flowLayoutPanel1 );
this.Name = "ShpViewForm";
this.Text = "Form1";
this.ResumeLayout(false);
this.ResumeLayout( false );
}

View File

@@ -13,28 +13,47 @@ namespace ShpViewer
{
public partial class ShpViewForm : Form
{
ShpReader shpReader;
List<Bitmap> bitmaps = new List<Bitmap>();
public ShpViewForm( string filename )
{
shpReader = new ShpReader( File.OpenRead( filename ) );
foreach( ImageHeader h in shpReader )
{
byte[] imageBytes = h.Image;
Palette pal = new Palette(File.OpenRead("../../../temperat.pal"));
Bitmap bitmap = new Bitmap( shpReader.Width, shpReader.Height );
for( int x = 0 ; x < shpReader.Width ; x++ )
for( int y = 0 ; y < shpReader.Height ; y++ )
bitmap.SetPixel( x, y, pal.GetColor(imageBytes[ x + shpReader.Width * y ]) );
bitmaps.Add( bitmap );
}
InitializeComponent();
string ext = Path.GetExtension( filename );
if( ext == ".shp" )
{
ShpReader shpReader = new ShpReader( File.OpenRead( filename ) );
Palette pal = new Palette( File.OpenRead( "../../../temperat.pal" ) );
foreach( ImageHeader h in shpReader )
bitmaps.Add( BitmapBuilder.FromBytes( h.Image, shpReader.Width, shpReader.Height, pal ) );
}
else if( ext == ".tem" || ext == ".sno" || ext == ".int" )
{
Palette pal = new Palette( File.OpenRead( "../../../temperat.pal" ) );
switch( ext )
{
case ".sno":
pal = new Palette( File.OpenRead( "../../../snow.pal" ) );
break;
case ".int":
pal = new Palette( File.OpenRead( "../../../interior.pal" ) );
break;
}
Terrain t = new Terrain( File.OpenRead( filename ), pal );
Bitmap bigTile = new Bitmap( 24 * t.XDim, 24 * t.YDim );
using( Graphics g = Graphics.FromImage( bigTile ) )
{
for( int x = 0 ; x < t.XDim ; x++ )
for( int y = 0 ; y < t.YDim ; y++ )
g.DrawImageUnscaled( t.GetTile( x + y * t.XDim ) ?? new Bitmap( 24, 24 ), x * 24, y * 24 );
}
bitmaps.Add( bigTile );
}
foreach (Bitmap b in bitmaps)
{
PictureBox p = new PictureBox();
@@ -44,6 +63,7 @@ namespace ShpViewer
}
Focus();
BringToFront();
}
}
}
}