From c3d54388e219822ec7eb4a59d839f2dc9cda5df1 Mon Sep 17 00:00:00 2001 From: John Luke Date: Fri, 27 Aug 2004 19:00:00 +0000 Subject: [PATCH] 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 --- sample/GtkDemo/DemoMain.cs | 27 ++++++++++++++++++--------- sample/GtkDemo/DemoPixbuf.cs | 9 ++------- sample/GtkDemo/DemoTextView.cs | 18 ++++-------------- sample/GtkDemo/Makefile.am | 17 ++++++++++++++++- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/sample/GtkDemo/DemoMain.cs b/sample/GtkDemo/DemoMain.cs index ed248225a..8875d2cec 100644 --- a/sample/GtkDemo/DemoMain.cs +++ b/sample/GtkDemo/DemoMain.cs @@ -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) { diff --git a/sample/GtkDemo/DemoPixbuf.cs b/sample/GtkDemo/DemoPixbuf.cs index 7b7684415..5892832bf 100644 --- a/sample/GtkDemo/DemoPixbuf.cs +++ b/sample/GtkDemo/DemoPixbuf.cs @@ -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 diff --git a/sample/GtkDemo/DemoTextView.cs b/sample/GtkDemo/DemoTextView.cs index 01fc07823..e3ce8932c 100644 --- a/sample/GtkDemo/DemoTextView.cs +++ b/sample/GtkDemo/DemoTextView.cs @@ -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. */ diff --git a/sample/GtkDemo/Makefile.am b/sample/GtkDemo/Makefile.am index 837b4b293..5a23d53e3 100644 --- a/sample/GtkDemo/Makefile.am +++ b/sample/GtkDemo/Makefile.am @@ -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)