Beispiel #1
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);
        }
Beispiel #2
0
 /// <summary>
 /// IndentArea の幅と高さを指定して TreeNodeIndentArea を初期化します。
 /// </summary>
 /// <param name="width">TreeNodeIndentArea の幅を指定します。</param>
 /// <param name="height">
 /// </param>
 public TreeNodeIndentArea(int width, int height)
 {
     this.size = new Gdi::Size(width, height);
 }
Beispiel #3
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();
        }