Example #1
0
        public void DrawImageClipped(Gdi::Graphics g, Gdi::RectangleF clip)
        {
            clip.Intersect(imageArea);
            float cacheX = clip.X + 0.5f;

            if (offsetX > 0)
            {
                cacheX -= offsetX;
            }
            float cacheY = clip.Y + 0.5f;

            if (offsetY > 0)
            {
                cacheY -= offsetY;
            }
#if WIN32PINVOKE
            using (Gdi::Graphics gImg = Gdi::Graphics.FromImage(this.cache)){
                const int     SRCCOPY = 0x00CC0020;
                System.IntPtr dstDC   = g.GetHdc();
                System.IntPtr srcDC   = GetCacheHdc(dstDC);
                BitBlt(
                    dstDC, (int)clip.X, (int)clip.Y,
                    (int)clip.Width, (int)clip.Height,
                    srcDC, (int)cacheX, (int)cacheY,
                    SRCCOPY
                    );
                g.ReleaseHdc(dstDC);
            }
#else
            Gdi::RectangleF rectI = new Gdi::RectangleF(cacheX, cacheY, clip.Width, clip.Height);
            g.DrawImage(this.cache, clip, rectI, Gdi::GraphicsUnit.Pixel);
#endif
        }
Example #2
0
        public GraphicsClipRectStore(Gdi::Graphics g)
        {
            this.g = g;
            Gdi::RectangleF rectF = g.ClipBounds;

            this.rect = new Gdi::Rectangle(
                (int)rectF.X, (int)rectF.Y,
                (int)rectF.Width, (int)rectF.Height
                );
        }
Example #3
0
        /// <summary>
        /// 描画する背景画像の情報を更新します。
        /// </summary>
        /// <param name="image">描画する背景画像を指定します。</param>
        /// <param name="scaleX">画像の表示 X 倍率を指定します。</param>
        /// <param name="scaleY">画像の表示 Y 倍率を指定します。</param>
        /// <param name="offsetX">画像の表示 X 位置を指定します。</param>
        /// <param name="offsetY">画像の表示 Y 位置を指定します。</param>
        /// <param name="displaySize">画面上の表示の大きさを指定します。</param>
        public void UpdateImage(Gdi::Image image, float scaleX, float scaleY, float offsetX, float offsetY, Gdi::Size displaySize)
        {
            if (image == this.original &&
                scaleX == this.scaleX && scaleY == this.scaleY &&
                offsetX == this.offsetX && offsetY == this.offsetY &&
                displaySize == this.displaySize
                )
            {
                return;
            }

            this.original    = image;
            this.scaleX      = scaleX;
            this.scaleY      = scaleY;
            this.offsetX     = offsetX;
            this.offsetY     = offsetY;
            this.displaySize = displaySize;

            imageArea = new Gdi::RectangleF(offsetX, offsetY, image.Width * scaleX, image.Height * scaleY);
            // 画面座標での描画領域
            Gdi::RectangleF srcRectD = Gdi::RectangleF.Intersect(new Gdi::RectangleF(Gdi::PointF.Empty, displaySize), imageArea);
            // 画像座標での描画領域
            Gdi::RectangleF srcRectI = new Gdi::RectangleF(
                (srcRectD.X - offsetX) / scaleX,
                (srcRectD.Y - offsetY) / scaleY,
                srcRectD.Width / scaleX,
                srcRectD.Height / scaleY
                );

            srcRectD.X = 0;
            srcRectD.Y = 0;

            this.FreeCache();
            this.cache = new System.Drawing.Bitmap((int)(srcRectD.Width + .5f), (int)(srcRectD.Height + .5f));
            using (Gdi::Graphics g = Gdi::Graphics.FromImage(this.cache))
                g.DrawImage(image, srcRectD, srcRectI, Gdi::GraphicsUnit.Pixel);

            ImageEnlight(this.cache);
        }
Example #4
0
 public static Gdi::Rectangle ToRectangle(this Gdi::RectangleF self)
 {
     return(new Gdi::Rectangle((int)self.X, (int)self.Y, (int)self.Width, (int)self.Height));
 }
Example #5
0
        //------------------------------------------------------------
        private void UpdateGeometry()
        {
            if (this.bmp == null)
            {
                return;
            }

            switch (this.size_mode)
            {
            case SizeModeType.Stretch: {
                // 全体表示の場合
                float mag_w = this.Width / (float)bmp.Width;
                float mag_h = this.Height / (float)bmp.Height;

                if (limit_mag_full)
                {
                    if (mag_w > 1)
                    {
                        mag_w = 1;
                    }
                    if (mag_h > 1)
                    {
                        mag_h = 1;
                    }
                }

                if (fix_aspect)
                {
                    if (mag_h < mag_w)
                    {
                        mag_w = mag_h;
                    }
                    if (mag_w < mag_h)
                    {
                        mag_h = mag_w;
                    }
                }

                float w = bmp.Width * mag_w;
                float h = bmp.Height * mag_h;
                rcDest = new Gdi::RectangleF((this.Width - w) / 2, (this.Height - h) / 2, w, h);
                rcSrc  = new Gdi::RectangleF(0, 0, bmp.Width, bmp.Height);
                break;
            }

            case SizeModeType.Magnify: {
                // 拡大表示の場合

                // 位置合わせ X
                float w, l, cw, cl;
                w = this.Width / mag;
                if (w < bmp.Width)                       // はみ出る場合
                {
                    cw = this.Width;
                    l  = bmp.Width * center_x - w / 2;
                    cl = (this.Width - cw) / 2f;
                }
                else                           // 収まる場合
                {
                    w  = bmp.Width;
                    cw = w * mag;
                    l  = 0;
                    cl = this.Width / 2f - cw * center_x;
                }

                // 位置合わせ Y
                float h, t, ch, ct;
                h = this.Height / mag;
                if (h < bmp.Height)                       // はみ出る
                {
                    ch = this.Height;
                    t  = bmp.Height * center_y - h / 2;
                    ct = (this.Height - ch) / 2f;
                }
                else                           // 収まる
                {
                    h  = bmp.Height;
                    ch = h * mag;
                    t  = 0;
                    ct = this.Height / 2f - ch * center_y;
                }

                rcSrc  = new Gdi::RectangleF(l, t, w, h);
                rcDest = new Gdi::RectangleF(cl, ct, cw, ch);
                break;
            }

            case SizeModeType.MagnifyAutoPosition: {
                // 切り出し元 X
                float w = this.Width / mag;
                float l;
                if (w < this.bmp.Width)
                {
                    // はみ出る場合
                    l = ksh.Compare.Clamp(bmp.Width * center_x - w / 2, 0, bmp.Width - w);
                }
                else
                {
                    // 収まる場合
                    w = this.bmp.Width;
                    l = 0;
                }

                // 切り出し元 Y
                float h = this.Height / mag;
                float t;
                if (w < this.bmp.Height)
                {
                    // はみ出る場合
                    t = ksh.Compare.Clamp(bmp.Height * center_y - h / 2, 0, bmp.Height - h);
                }
                else
                {
                    // 収まる場合
                    h = this.bmp.Height;
                    t = 0;
                }
                rcSrc = new Gdi::RectangleF(l, t, w, h);

                w     *= mag;
                h     *= mag;
                l      = (this.Width - w) / 2;
                t      = (this.Height - h) / 2;
                rcDest = new Gdi::RectangleF(l, t, w, h);
                break;
            }

            case SizeModeType.AutoSize:
                rcSrc  = new Gdi::RectangleF(0, 0, this.bmp.Width, this.bmp.Height);
                rcDest = new Gdi::RectangleF(0, 0, bmp.Width * mag, bmp.Height * mag);

                // 自身の大きさの変更
                Gdi::Size sz = new Gdi::Size((int)rcDest.Width, (int)rcDest.Height);
                if (this.Dock == Forms::DockStyle.None && this.Size != sz)
                {
                    this.Size = sz;
                    return;                             // SizeChanged から再度呼び出されるのでその折に Invalidate
                }
                break;
            }

            this.Invalidate();
        }
Example #6
0
 /// <summary>
 /// 指定した文字列内の文字位置の範囲にそれぞれが外接する System.Drawing.Region オブジェクトの配列を取得します。
 /// </summary>
 /// <param name="text">計測する文字列。</param>
 /// <param name="font">文字列のテキスト形式を定義する System.Drawing.Font。</param>
 /// <param name="layoutRect">文字列のレイアウト矩形を指定する System.Drawing.RectangleF 構造体。</param>
 /// <param name="stringFormat">行間など、文字列の書式情報を表す System.Drawing.StringFormat。</param>
 /// <returns>このメソッドは、指定した文字列内の文字位置の範囲にそれぞれが外接する System.Drawing.Region オブジェクトの配列を返します。</returns>
 public static Gdi::Region[] MeasureCharacterRanges(string text, Gdi::Font font, Gdi::RectangleF layoutRect, Gdi::StringFormat stringFormat)
 {
     return(g.MeasureCharacterRanges(text, font, layoutRect, stringFormat));
 }