예제 #1
0
        void PaintRectangle(Rectangle area, InterpType interpolation)
        {
            int x_offset = scaled_width < Allocation.Width ? (int)(Allocation.Width - scaled_width) / 2 : -XOffset;
            int y_offset = scaled_height < Allocation.Height ? (int)(Allocation.Height - scaled_height) / 2 : -YOffset;

            //Draw background
            if (y_offset > 0)                   //Top
            {
                PaintBackground(new Rectangle(0, 0, Allocation.Width, y_offset), area);
            }
            if (x_offset > 0)                   //Left
            {
                PaintBackground(new Rectangle(0, y_offset, x_offset, (int)scaled_height), area);
            }
            if (x_offset >= 0)                  //Right
            {
                PaintBackground(new Rectangle(x_offset + (int)scaled_width, y_offset, Allocation.Width - x_offset - (int)scaled_width, (int)scaled_height), area);
            }
            if (y_offset >= 0)                  //Bottom
            {
                PaintBackground(new Rectangle(0, y_offset + (int)scaled_height, Allocation.Width, Allocation.Height - y_offset - (int)scaled_height), area);
            }

            if (Pixbuf == null)
            {
                return;
            }

            area.Intersect(new Rectangle(x_offset, y_offset, (int)scaled_width, (int)scaled_height));

            if (area.Width <= 0 || area.Height <= 0)
            {
                return;
            }

            //Short circuit for 1:1 zoom
            if (zoom == 1.0 &&
                !Pixbuf.HasAlpha &&
                Pixbuf.BitsPerSample == 8 &&
                pixbuf_orientation == ImageOrientation.TopLeft)
            {
                GdkWindow.DrawPixbuf(Style.BlackGC,
                                     Pixbuf,
                                     area.X - x_offset, area.Y - y_offset,
                                     area.X, area.Y,
                                     area.Width, area.Height,
                                     RgbDither.Max,
                                     area.X - x_offset, area.Y - y_offset);
                return;
            }

            Rectangle pixbuf_area = PixbufUtils.TransformOrientation((int)scaled_width,
                                                                     (int)scaled_height,
                                                                     new Rectangle((area.X - x_offset),
                                                                                   (area.Y - y_offset),
                                                                                   area.Width,
                                                                                   area.Height),
                                                                     PixbufUtils.ReverseTransformation(pixbuf_orientation));

            using (Pixbuf temp_pixbuf = new Pixbuf(Colorspace.Rgb, false, 8, pixbuf_area.Width, pixbuf_area.Height)) {
                if (Pixbuf.HasAlpha)
                {
                    temp_pixbuf.Fill(0x00000000);
                }

                Pixbuf.CompositeColor(temp_pixbuf,
                                      0, 0,
                                      pixbuf_area.Width, pixbuf_area.Height,
                                      -pixbuf_area.X, -pixbuf_area.Y,
                                      zoom, zoom,
                                      zoom == 1.0 ? InterpType.Nearest : interpolation, 255,
                                      pixbuf_area.X, pixbuf_area.Y,
                                      CheckPattern.CheckSize, CheckPattern.Color1, CheckPattern.Color2);


                ApplyColorTransform(temp_pixbuf);

                using (var dest_pixbuf = PixbufUtils.TransformOrientation(temp_pixbuf, pixbuf_orientation)) {
                    GdkWindow.DrawPixbuf(Style.BlackGC,
                                         dest_pixbuf,
                                         0, 0,
                                         area.X, area.Y,
                                         area.Width, area.Height,
                                         RgbDither.Max,
                                         area.X - x_offset, area.Y - y_offset);
                }
            }
        }
예제 #2
0
        public Point WindowCoordsToImage(Point win)
        {
            if (Pixbuf == null)
            {
                return(Point.Zero);
            }

            int x_offset = scaled_width < Allocation.Width ? (int)(Allocation.Width - scaled_width) / 2 : -XOffset;
            int y_offset = scaled_height < Allocation.Height ? (int)(Allocation.Height - scaled_height) / 2 : -YOffset;

            win.X = Clamp(win.X - x_offset, 0, (int)scaled_width - 1);
            win.Y = Clamp(win.Y - y_offset, 0, (int)scaled_height - 1);

            win = PixbufUtils.TransformOrientation((int)scaled_width, (int)scaled_height, win, PixbufUtils.ReverseTransformation(pixbuf_orientation));

            return(new Point((int)Math.Floor(win.X * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) / (double)(scaled_width - 1) + .5),
                             (int)Math.Floor(win.Y * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) / (double)(scaled_height - 1) + .5)));
        }