Esempio n. 1
0
        //paint me event
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            //deseneaza poza daca este cazul
            if (BackgroundImage != null && Allocation.Width > 5 && Allocation.Height > 5)
            {
                if (BackgroundImageLayout == ImageLayout.None)
                {
                    //draw the pixbuf normally
                    GdkWindow.DrawPixbuf(this.Style.BaseGC(State), BackgroundImage, 0, 0, 0, 0, BackgroundImage.Width, BackgroundImage.Height, Gdk.RgbDither.Normal, 0, 0);
                }
                else if (backgroundImageLayout == ImageLayout.Stretch)
                {
                    //draw pixbuf stretched
                    Gdk.Pixbuf buf = BackgroundImage.ScaleSimple(Allocation.Width, Allocation.Height, Gdk.InterpType.Bilinear);
                    GdkWindow.DrawPixbuf(this.Style.WhiteGC, buf, 0, 0, 0, 0, Allocation.Width, Allocation.Height, Gdk.RgbDither.Normal, 0, 0);
                }
                else if (BackgroundImageLayout == ImageLayout.Center)
                {
                    //draw the pixbuf on center
                    int x = (Allocation.Width / 2) - (BackgroundImage.Width / 2);
                    int y = (Allocation.Height / 2) - (BackgroundImage.Height / 2);
                    GdkWindow.DrawPixbuf(this.Style.BaseGC(State), BackgroundImage, 0, 0, x, y, BackgroundImage.Width, BackgroundImage.Height, Gdk.RgbDither.Normal, 0, 0);
                }
                else if (BackgroundImageLayout == ImageLayout.Tile)
                {
                    //draw backgorund image as tiles
                    int nr_rows = (int)Math.Ceiling((double)(Allocation.Height / backgroundImage.Height)) + 1;
                    int nr_cols = (int)Math.Ceiling((double)(Allocation.Width / backgroundImage.Width)) + 1;
                    int x = 0, y = 0;
                    for (int i = 0; i < nr_rows; i++)
                    {
                        for (int j = 0; j < nr_cols; j++)
                        {
                            GdkWindow.DrawPixbuf(this.Style.WhiteGC, BackgroundImage, 0, 0, x, y, BackgroundImage.Width, BackgroundImage.Height, Gdk.RgbDither.Normal, x, y);
                            x += BackgroundImage.Width;
                        }
                        y += BackgroundImage.Height;
                        x  = 0;
                    }
                }
                else if (BackgroundImageLayout == ImageLayout.Zoom)
                {
                    //draw the zoomed image
                    int sx = Allocation.Width, sy = Allocation.Height;

                    int sizeX, sizeY;

                    if (((sx + 1.0f) / (sy + 1.0f)) < ((BackgroundImage.Width + 1.0f) / (1.0f + BackgroundImage.Height)))
                    {
                        sizeX = sx;
                        sizeY = (int)(BackgroundImage.Height * ((float)sx) / BackgroundImage.Width);
                    }
                    else
                    {
                        sizeY = sy;
                        sizeX = (int)(BackgroundImage.Width * ((float)sy) / BackgroundImage.Height);
                    }

                    Gdk.Pixbuf buf = BackgroundImage.ScaleSimple(sizeX, sizeY, Gdk.InterpType.Bilinear);

                    int x = (Allocation.Width / 2) - (buf.Width / 2);
                    int y = (Allocation.Height / 2) - (buf.Height / 2);

                    GdkWindow.DrawPixbuf(this.Style.WhiteGC, buf, 0, 0, x, y, buf.Width, buf.Height, Gdk.RgbDither.Normal, 0, 0);
                }
            }
            base.OnExposeEvent(evnt);
            //draw border
            DrawBorder();
            return(true);
        }