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:
parent
e5dde2ff7e
commit
c3d54388e2
4 changed files with 40 additions and 31 deletions
|
@ -57,16 +57,25 @@ namespace GtkDemo
|
||||||
|
|
||||||
private void LoadFile (string filename)
|
private void LoadFile (string filename)
|
||||||
{
|
{
|
||||||
Stream file = File.OpenRead (filename);
|
if (File.Exists (filename))
|
||||||
StreamReader sr = new StreamReader (file);
|
{
|
||||||
string s = sr.ReadToEnd ();
|
Stream file = File.OpenRead (filename);
|
||||||
sr.Close ();
|
StreamReader sr = new StreamReader (file);
|
||||||
file.Close ();
|
string s = sr.ReadToEnd ();
|
||||||
|
sr.Close ();
|
||||||
|
file.Close ();
|
||||||
|
|
||||||
infoBuffer.Text = filename;
|
infoBuffer.Text = filename;
|
||||||
sourceBuffer.Text = s;
|
sourceBuffer.Text = s;
|
||||||
|
|
||||||
Fontify ();
|
Fontify ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
infoBuffer.Text = String.Format ("{0} was not found.", filename);
|
||||||
|
sourceBuffer.Text = String.Empty;
|
||||||
|
Fontify ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Fontify ()
|
private void Fontify ()
|
||||||
|
@ -76,7 +85,7 @@ namespace GtkDemo
|
||||||
// TODO: Display system error
|
// TODO: Display system error
|
||||||
private void SetupDefaultIcon ()
|
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)
|
if (pixbuf != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,15 +59,10 @@ namespace GtkDemo
|
||||||
// drawing area
|
// drawing area
|
||||||
DrawingArea drawingArea;
|
DrawingArea drawingArea;
|
||||||
|
|
||||||
string FindFile (string name)
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loads the images for the demo
|
// Loads the images for the demo
|
||||||
void LoadPixbuf ()
|
void LoadPixbuf ()
|
||||||
{
|
{
|
||||||
background = new Pixbuf (FindFile (BackgroundName));
|
background = Gdk.Pixbuf.LoadFromResource (BackgroundName);
|
||||||
|
|
||||||
backWidth = background.Width;
|
backWidth = background.Width;
|
||||||
backHeight = background.Height;
|
backHeight = background.Height;
|
||||||
|
@ -75,7 +70,7 @@ namespace GtkDemo
|
||||||
images = new Pixbuf[ImageNames.Length];
|
images = new Pixbuf[ImageNames.Length];
|
||||||
|
|
||||||
for (int i = 0; i < ImageNames.Length; i++)
|
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
|
// Expose callback for the drawing area
|
||||||
|
|
|
@ -253,20 +253,10 @@ namespace GtkDemo
|
||||||
|
|
||||||
private void InsertText (TextBuffer buffer)
|
private void InsertText (TextBuffer buffer)
|
||||||
{
|
{
|
||||||
|
// we use resources for portability and convenience
|
||||||
/* demo_find_file() looks in the the current directory first,
|
Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif");
|
||||||
* so you can run gtk-demo without installing GTK, then looks
|
pixbuf.ScaleSimple (32, 32, InterpType.Bilinear);
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
/* get start of buffer; each insertion will revalidate the
|
/* get start of buffer; each insertion will revalidate the
|
||||||
* iterator to point to just after the inserted text.
|
* iterator to point to just after the inserted text.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,8 +25,23 @@ sources = \
|
||||||
DemoTextView.cs \
|
DemoTextView.cs \
|
||||||
DemoTreeStore.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))
|
build_sources = $(addprefix $(srcdir)/, $(sources))
|
||||||
|
|
||||||
GtkDemo.exe: $(build_sources) $(assemblies)
|
GtkDemo.exe: $(build_sources) $(assemblies)
|
||||||
$(CSC) /debug /out:GtkDemo.exe $(build_sources) $(references)
|
$(CSC) /debug /out:GtkDemo.exe $(build_sources) $(references) $(images)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue