@ modified constructor usage of ResourceImage class for more versatile use

This commit is contained in:
codeimp 2009-08-02 18:21:53 +00:00
parent ed5c468fec
commit 696b067095
4 changed files with 24 additions and 13 deletions

View file

@ -147,19 +147,19 @@ namespace CodeImp.DoomBuilder.Data
GC.SuppressFinalize(this);
// Load special images
missingtexture3d = new ResourceImage("MissingTexture3D.png");
missingtexture3d = new ResourceImage("CodeImp.DoomBuilder.Resources.MissingTexture3D.png");
missingtexture3d.LoadImage();
unknowntexture3d = new ResourceImage("UnknownTexture3D.png");
unknowntexture3d = new ResourceImage("CodeImp.DoomBuilder.Resources.UnknownTexture3D.png");
unknowntexture3d.LoadImage();
hourglass3d = new ResourceImage("Hourglass3D.png");
hourglass3d = new ResourceImage("CodeImp.DoomBuilder.Resources.Hourglass3D.png");
hourglass3d.LoadImage();
crosshair = new ResourceImage("Crosshair.png");
crosshair = new ResourceImage("CodeImp.DoomBuilder.Resources.Crosshair.png");
crosshair.LoadImage();
crosshairbusy = new ResourceImage("CrosshairBusy.png");
crosshairbusy = new ResourceImage("CodeImp.DoomBuilder.Resources.CrosshairBusy.png");
crosshairbusy.LoadImage();
thingbox = new ResourceImage("ThingBox.png");
thingbox = new ResourceImage("CodeImp.DoomBuilder.Resources.ThingBox.png");
thingbox.LoadImage();
whitetexture = new ResourceImage("White.png");
whitetexture = new ResourceImage("CodeImp.DoomBuilder.Resources.White.png");
whitetexture.UseColorCorrection = false;
whitetexture.LoadImage();
whitetexture.CreateTexture();
@ -1091,14 +1091,14 @@ namespace CodeImp.DoomBuilder.Data
// Add some internal resources
if(!internalsprites.ContainsKey("nothing"))
{
ImageData img = new ResourceImage("Nothing.png");
ImageData img = new ResourceImage("CodeImp.DoomBuilder.Resources.Nothing.png");
img.LoadImage();
internalsprites.Add("nothing", img);
}
if(!internalsprites.ContainsKey("unknownthing"))
{
ImageData img = new ResourceImage("UnknownThing.png");
ImageData img = new ResourceImage("CodeImp.DoomBuilder.Resources.UnknownThing.png");
img.LoadImage();
internalsprites.Add("unknownthing", img);
}

View file

@ -20,6 +20,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
@ -33,16 +34,26 @@ namespace CodeImp.DoomBuilder.Data
{
public class ResourceImage : ImageData
{
#region ================== Variables
// Image source
private Assembly assembly;
private string resourcename;
#endregion
#region ================== Constructor / Disposer
// Constructor
public ResourceImage(string resourcename)
{
// Initialize
this.assembly = Assembly.GetCallingAssembly();
this.resourcename = resourcename;
SetName(resourcename);
// Temporarily load resource from memory
Stream bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name);
Stream bitmapdata = assembly.GetManifestResourceStream(resourcename);
Bitmap bmp = (Bitmap)Image.FromStream(bitmapdata);
// Get width and height from image
@ -74,7 +85,7 @@ namespace CodeImp.DoomBuilder.Data
// because the resources this loads are in the assembly.
// Get resource from memory
bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name);
bitmapdata = assembly.GetManifestResourceStream(resourcename);
if(bitmap != null) bitmap.Dispose();
bitmap = (Bitmap)Image.FromStream(bitmapdata);
bitmapdata.Dispose();

View file

@ -319,7 +319,7 @@ namespace CodeImp.DoomBuilder.Rendering
// Font
postfilter = Filter.Box;
font = new TextFont();
fonttexture = new ResourceImage("Font.png");
fonttexture = new ResourceImage("CodeImp.DoomBuilder.Resources.Font.png");
fonttexture.LoadImage();
fonttexture.MipMapLevels = 2;
fonttexture.CreateTexture();

View file

@ -154,7 +154,7 @@ namespace CodeImp.DoomBuilder.Rendering
thingtexture = new ResourceImage[NUM_THING_TEXTURES];
for(int i = 0; i < NUM_THING_TEXTURES; i++)
{
thingtexture[i] = new ResourceImage("Thing2D_" + i.ToString(CultureInfo.InvariantCulture) + ".png");
thingtexture[i] = new ResourceImage("CodeImp.DoomBuilder.Resources.Thing2D_" + i.ToString(CultureInfo.InvariantCulture) + ".png");
thingtexture[i].UseColorCorrection = false;
thingtexture[i].LoadImage();
thingtexture[i].CreateTexture();