Example #1
0
        protected override bool OnExposeEvent(Gdk.EventExpose ev)
        {
            Gdk.Window    win  = ev.Window;
            Gdk.Rectangle rect = ev.Area;
            Gdk.GC        gc   = this.Style.BaseGC(StateType.Normal);
            lock (this.drawLock){
                if (this.toDraw != null)
                {
                    //Raise events for the symbols...
                    bool gotSymbol = false;
                    //See if there's a new symbol
                    if (this.symbols != null)
                    {
                        foreach (Symbol s in this.symbols)
                        {
                            if (s.Count > 0 && this.data != s.ToString())
                            {
                                this.data = s.ToString();
                                //Don't raise it inside the expose event :)
                                GLib.IdleHandler raiser = delegate(){
                                    if (this.BarScanned != null)
                                    {
                                        this.BarScanned(this, new BarScannedArgs(s));
                                    }
                                    return(false);
                                };
                                GLib.Idle.Add(raiser);
                                gotSymbol = true;
                            }
                        }
                    }
                    //Avoid beeping more than once..
                    if (gotSymbol)
                    {
                        if (!this.Mute)
                        {
                            System.Media.SystemSounds.Beep.Play();
                        }
                        if (this.overlayingFrames == 0)
                        {
                            GLib.TimeoutHandler hdl = delegate(){
                                this.QueueDraw();
                                this.overlayingFrames -= 1;
                                return(this.overlayingFrames > 0);
                            };
                            GLib.Timeout.Add(35, hdl);
                        }
                        //Start drawing an overlay
                        this.overlayingFrames = overlayFrameCount;
                    }
                    this.symbols = null;                     //Symbols have been handled

                    //See if we want to request a resize
                    if (this.reqHeight != this.toDrawHeight ||
                        this.reqWidth != this.toDrawWidth)
                    {
                        this.reqHeight = this.toDrawHeight;
                        this.reqWidth  = this.toDrawWidth;
                        this.QueueResize();
                    }

                    //Draw the gray image
                    int w = Math.Min(rect.Size.Width, this.toDrawWidth);
                    int h = Math.Min(rect.Size.Height, this.toDrawHeight);

                    //Draw the image
                    win.DrawGrayImage(gc, 0, 0, w, h, Gdk.RgbDither.Normal, this.toDraw, this.toDrawWidth);

                    if (this.overlayingFrames > 0)
                    {
                        Pixbuf overlay_tmp = overlay;
                        if (this.overlay.Width > w * 0.8 || this.overlay.Height > h * 0.8)
                        {
                            int overlayMaxSize = Math.Min(h * 80 / 100, w * 80 / 100);
                            overlay_tmp = overlay.ScaleSimple(overlayMaxSize, overlayMaxSize, InterpType.Bilinear);
                        }

                        w = Math.Min(this.toDrawWidth, (int)overlay_tmp.Width);
                        h = Math.Min(this.toDrawHeight, (int)overlay_tmp.Height);
                        using (Gdk.Pixbuf pix = new Pixbuf(Colorspace.Rgb, true, 8, w, h)){
                            pix.Fill(0x00000000);                             //Fill with invisibility :)
                            overlay_tmp.Composite(pix, 0, 0, w, h, 0, 0, 1, 1, InterpType.Bilinear, 255 / 35 * this.overlayingFrames);
                            win.DrawPixbuf(gc, pix, 0, 0,
                                           (this.toDrawWidth - w) / 2,
                                           (this.toDrawHeight - h) / 2, w, h, RgbDither.Normal, 0, 0);
                        }
                    }
                }
                else
                {
                    win.DrawRectangle(gc, true, rect);

                    int w = Math.Min(this.toDrawWidth, (int)this.sourceMissing.Width);
                    int h = Math.Min(this.toDrawHeight, (int)this.sourceMissing.Height);

                    Rectangle img = new Rectangle((this.toDrawWidth - w) / 2,
                                                  (this.toDrawHeight - h) / 2,
                                                  w, h);
                    Rectangle target = Rectangle.Intersect(img, rect);
                    if (target != Rectangle.Zero)
                    {
                        win.DrawPixbuf(gc, this.sourceMissing,
                                       Math.Max(target.X - img.X, 0),
                                       Math.Max(target.Y - img.Y, 0),
                                       target.X,
                                       target.Y,
                                       target.Width,
                                       target.Height,
                                       RgbDither.Normal, 0, 0);
                    }
                }
            }
            return(true);
        }