implement Progressive image loader

and part of the stock browser

svn path=/trunk/gtk-sharp/; revision=32053
This commit is contained in:
John Luke 2004-08-08 18:30:25 +00:00
parent 0b296a59d0
commit 8e7348d260
3 changed files with 52 additions and 17 deletions

View file

@ -37,6 +37,7 @@ namespace GtkDemo
{ {
private static Gtk.Image progressiveImage; private static Gtk.Image progressiveImage;
private VBox vbox; private VBox vbox;
BinaryReader imageStream;
public DemoImages () : base ("images") public DemoImages () : base ("images")
{ {
@ -138,15 +139,25 @@ namespace GtkDemo
static Gdk.PixbufLoader pixbufLoader; static Gdk.PixbufLoader pixbufLoader;
// TODO: Finish this callback // TODO: Decide if we want to perform crazy error handling
// Decide if we want to perform crazy error handling
private bool ProgressiveTimeout () private bool ProgressiveTimeout ()
{ {
Gtk.Image imageStream = new Gtk.Image ("images/alphatest.png"); if (imageStream == null) {
imageStream = new BinaryReader (new StreamReader ("images/alphatest.png").BaseStream);
pixbufLoader = new Gdk.PixbufLoader (); pixbufLoader = new Gdk.PixbufLoader ();
pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback); pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback);
pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback); pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback);
return true; }
if (imageStream.PeekChar () != -1) {
byte[] bytes = imageStream.ReadBytes (256);
pixbufLoader.Write (bytes, (uint) bytes.Length);
return true; // leave the timeout active
}
else {
imageStream.Close ();
return false; // removes the timeout
}
} }
static void ProgressivePreparedCallback (object obj, EventArgs args) static void ProgressivePreparedCallback (object obj, EventArgs args)
@ -158,7 +169,7 @@ namespace GtkDemo
static void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args) static void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args)
{ {
progressiveImage.QueueDraw ();
} }
} }
} }

View file

@ -30,7 +30,10 @@ namespace GtkDemo
list.AppendColumn ("Name", new CellRendererText (), "text", 1); list.AppendColumn ("Name", new CellRendererText (), "text", 1);
list.AppendColumn ("Label", new CellRendererText (), "text", 2); list.AppendColumn ("Label", new CellRendererText (), "text", 2);
list.AppendColumn ("Accel", new CellRendererText (), "text", 3); list.AppendColumn ("Accel", new CellRendererText (), "text", 3);
list.AppendColumn ("ID", new CellRendererText (), "text", 4);
list.Model = CreateStore (); list.Model = CreateStore ();
list.Selection.Changed += new EventHandler (OnSelectionChanged);
scrolledWindow.Add (list); scrolledWindow.Add (list);
Frame frame = new Frame (); Frame frame = new Frame ();
@ -41,18 +44,39 @@ namespace GtkDemo
private ListStore CreateStore () private ListStore CreateStore ()
{ {
// image, name, label, accel // image, name, label, accel, id
ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string)); ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof (string));
for (int i =1; i < 10; i++) string[] stock_ids = Gtk.Stock.ListIds ();
foreach (string s in stock_ids)
{ {
Image icon = new Image ("images/MonoIcon.png"); Gtk.StockItem si;
store.AppendValues (icon, "Gtk.Stock.Ok", "Ok", "_Ok"); /* Gtk.Stock.Lookup is not being generated
if (Gtk.Stock.Lookup (out si)) {
Image icon = new Image (s, IconSize.Menu);
store.AppendValues (si.Pixbuf, si.Label, "Ok", "_Ok", si.StockId);
}
else {
Console.WriteLine ("StockItem {0} could not be found.", s);
}
*/
} }
return store; return store;
} }
void OnSelectionChanged (object o, EventArgs args)
{
TreeIter iter;
TreeModel model;
if (((TreeSelection) o).GetSelected (out model, out iter))
{
// update the frame
}
}
private void WindowDelete (object o, DeleteEventArgs args) private void WindowDelete (object o, DeleteEventArgs args)
{ {
this.Hide (); this.Hide ();

View file

@ -9,7 +9,7 @@ DemoIconFactory
- almost everything - almost everything
DemoImages DemoImages
- fix the progressive loading image - improve the Progressive Image loading and error handling
DemoStockBrowser DemoStockBrowser
- almost everything - almost everything