use resources for images

Dont crash if source is not there
makes it easier to run on win32

svn path=/trunk/gtk-sharp/; revision=32942
This commit is contained in:
John Luke 2004-08-27 19:00:00 +00:00
parent e5dde2ff7e
commit c3d54388e2
4 changed files with 40 additions and 31 deletions

View File

@ -57,16 +57,25 @@ namespace GtkDemo
private void LoadFile (string filename)
{
Stream file = File.OpenRead (filename);
StreamReader sr = new StreamReader (file);
string s = sr.ReadToEnd ();
sr.Close ();
file.Close ();
if (File.Exists (filename))
{
Stream file = File.OpenRead (filename);
StreamReader sr = new StreamReader (file);
string s = sr.ReadToEnd ();
sr.Close ();
file.Close ();
infoBuffer.Text = filename;
sourceBuffer.Text = s;
infoBuffer.Text = filename;
sourceBuffer.Text = s;
Fontify ();
Fontify ();
}
else
{
infoBuffer.Text = String.Format ("{0} was not found.", filename);
sourceBuffer.Text = String.Empty;
Fontify ();
}
}
private void Fontify ()
@ -76,7 +85,7 @@ namespace GtkDemo
// TODO: Display system error
private void SetupDefaultIcon ()
{
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf ("images/gtk-logo-rgb.gif");
Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif");
if (pixbuf != null)
{

View File

@ -59,15 +59,10 @@ namespace GtkDemo
// drawing area
DrawingArea drawingArea;
string FindFile (string name)
{
return name;
}
// Loads the images for the demo
void LoadPixbuf ()
{
background = new Pixbuf (FindFile (BackgroundName));
background = Gdk.Pixbuf.LoadFromResource (BackgroundName);
backWidth = background.Width;
backHeight = background.Height;
@ -75,7 +70,7 @@ namespace GtkDemo
images = new Pixbuf[ImageNames.Length];
for (int i = 0; i < ImageNames.Length; i++)
images[i] = new Pixbuf (FindFile (ImageNames[i]));
images[i] = Gdk.Pixbuf.LoadFromResource (ImageNames[i]);
}
// Expose callback for the drawing area

View File

@ -253,20 +253,10 @@ namespace GtkDemo
private void InsertText (TextBuffer buffer)
{
/* demo_find_file() looks in the the current directory first,
* so you can run gtk-demo without installing GTK, then looks
* in the location where the file is installed.
*/
// Error handling here, check for file existence, etc.
Pixbuf pixbuf = null;
if (File.Exists ("images/gtk-logo-rgb.gif"))
{
pixbuf = new Pixbuf ("images/gtk-logo-rgb.gif");
pixbuf.ScaleSimple (32, 32, InterpType.Bilinear);
}
// we use resources for portability and convenience
Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif");
pixbuf.ScaleSimple (32, 32, InterpType.Bilinear);
/* get start of buffer; each insertion will revalidate the
* iterator to point to just after the inserted text.
*/

View File

@ -25,8 +25,23 @@ sources = \
DemoTextView.cs \
DemoTreeStore.cs
images = \
/resource:$(srcdir)/images/gnome-foot.png,gnome-foot.png \
/resource:$(srcdir)/images/MonoIcon.png,MonoIcon.png \
/resource:$(srcdir)/images/gnome-calendar.png,gnome-calendar.png \
/resource:$(srcdir)/images/gnome-gmush.png,gnome-mush.png \
/resource:$(srcdir)/images/gnu-keys.png,gnu-keys.png \
/resource:$(srcdir)/images/gnome-applets.png,gnome-applets.png \
/resource:$(srcdir)/images/gnome-gsame.png,gnome-gsame.png \
/resource:$(srcdir)/images/alphatest.png,alphatest.png \
/resource:$(srcdir)/images/gnome-gimp.png,gnome-gimp.png \
/resource:$(srcdir)/images/apple-red.png,apple-red.png \
/resource:$(srcdir)/images/background.jpg,background.jpg \
/resource:$(srcdir)/images/gtk-logo-rgb.gif,gtk-logo-rgb.gif \
/resource:$(srcdir)/images/floppybuddy.gif,floppybuddy.gif
build_sources = $(addprefix $(srcdir)/, $(sources))
GtkDemo.exe: $(build_sources) $(assemblies)
$(CSC) /debug /out:GtkDemo.exe $(build_sources) $(references)
$(CSC) /debug /out:GtkDemo.exe $(build_sources) $(references) $(images)