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 VBox vbox;
BinaryReader imageStream;
public DemoImages () : base ("images")
{
@ -133,20 +134,30 @@ namespace GtkDemo
* The timeout simply simulates a slow data source by inserting
* pauses in the reading process.
*/
timeout_id = GLib.Timeout.Add(150, new GLib.TimeoutHandler(ProgressiveTimeout));
timeout_id = GLib.Timeout.Add (150, new GLib.TimeoutHandler (ProgressiveTimeout));
}
static Gdk.PixbufLoader pixbufLoader;
// TODO: Finish this callback
// Decide if we want to perform crazy error handling
private bool ProgressiveTimeout()
// TODO: Decide if we want to perform crazy error handling
private bool ProgressiveTimeout ()
{
Gtk.Image imageStream = new Gtk.Image ("images/alphatest.png");
pixbufLoader = new Gdk.PixbufLoader ();
pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback);
pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback);
return true;
if (imageStream == null) {
imageStream = new BinaryReader (new StreamReader ("images/alphatest.png").BaseStream);
pixbufLoader = new Gdk.PixbufLoader ();
pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback);
pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback);
}
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)
@ -158,7 +169,7 @@ namespace GtkDemo
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 ("Label", new CellRendererText (), "text", 2);
list.AppendColumn ("Accel", new CellRendererText (), "text", 3);
list.AppendColumn ("ID", new CellRendererText (), "text", 4);
list.Model = CreateStore ();
list.Selection.Changed += new EventHandler (OnSelectionChanged);
scrolledWindow.Add (list);
Frame frame = new Frame ();
@ -41,17 +44,38 @@ namespace GtkDemo
private ListStore CreateStore ()
{
// image, name, label, accel
ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string));
for (int i =1; i < 10; i++)
// image, name, label, accel, id
ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof (string));
string[] stock_ids = Gtk.Stock.ListIds ();
foreach (string s in stock_ids)
{
Image icon = new Image ("images/MonoIcon.png");
store.AppendValues (icon, "Gtk.Stock.Ok", "Ok", "_Ok");
Gtk.StockItem si;
/* 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;
}
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)
{

View File

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