Exemple #1
0
 private void SetZoomValue(float value)
 {
     _zoom_value           = MathExtra.Clamp(value, _zoom_min_value, _zoom_max_value);;
     sldZoomLevel.Value    = (int)(_zoom_value / _zoom_step_value);
     textBoxZoomValue.Text = Convert.ToInt32((int)_zoom_value).ToString() + "%";
     RaiseEventValueChanged(new EventArgs());
 }
Exemple #2
0
        private void textBoxZoomValue_Validating(object sender, CancelEventArgs e)
        {
            string text  = textBoxZoomValue.Text.Replace("%", string.Empty).Replace(" ", string.Empty);
            int    value = 0;

            try
            {
                value = Convert.ToInt32(text);
            }
            catch
            {
                value = 100;
            }
            value = MathExtra.Clamp(value / _zoom_step_value, sldZoomLevel.Minimum, sldZoomLevel.Maximum);
            textBoxZoomValue.Text = (value * _zoom_step_value).ToString();
        }
Exemple #3
0
        private void previewPanel_Paint(object sender, PaintEventArgs e)
        {
            if (!IsFrameValid)
            {
                return;
            }

            ViewFrame thisFrame  = _view.Loops[(int)udLoop.Value].Frames[(int)udFrame.Value];
            int       spriteNum  = thisFrame.Image;
            Size      spriteSize = Utilities.GetSizeSpriteWillBeRenderedInGame(spriteNum);

            spriteSize = MathExtra.SafeScale(spriteSize, _zoomLevel);
            if (spriteSize.Width <= previewPanel.ClientSize.Width && spriteSize.Height <= previewPanel.ClientSize.Height)
            {
                int    x   = chkCentrePivot.Checked ? previewPanel.ClientSize.Width / 2 - spriteSize.Width / 2 : 0;
                int    y   = previewPanel.ClientSize.Height - spriteSize.Height;
                IntPtr hdc = e.Graphics.GetHdc();
                Factory.NativeProxy.DrawSprite(hdc, x, y, spriteSize.Width, spriteSize.Height, spriteNum, thisFrame.Flipped);
                e.Graphics.ReleaseHdc();
            }
            else
            {
                Bitmap bmp = Utilities.GetBitmapForSpriteResizedKeepingAspectRatio(new Sprite(spriteNum, spriteSize.Width, spriteSize.Height), previewPanel.ClientSize.Width, previewPanel.ClientSize.Height, chkCentrePivot.Checked, false, SystemColors.Control);

                if (thisFrame.Flipped)
                {
                    Point   urCorner = new Point(0, 0);
                    Point   ulCorner = new Point(bmp.Width, 0);
                    Point   llCorner = new Point(bmp.Width, bmp.Height);
                    Point[] destPara = { ulCorner, urCorner, llCorner };
                    e.Graphics.DrawImage(bmp, destPara);
                }
                else
                {
                    e.Graphics.DrawImage(bmp, 1, 1);
                }

                bmp.Dispose();
            }
        }
Exemple #4
0
        private void UpdateSize()
        {
            if (_view == null)
            {
                return;
            }
            // Calculate the maximal view frame size,
            // see if the frame may be resized within the control's client size
            Size viewSize = Utilities.GetSizeViewWillBeRenderedInGame(_view);

            viewSize = MathExtra.SafeScale(viewSize, _zoomLevel);
            if (previewPanel.ClientSize.Width < viewSize.Width ||
                previewPanel.ClientSize.Height < viewSize.Height)
            {
                previewPanel.ClientSize = new Size(
                    Math.Max(previewPanel.ClientSize.Width, viewSize.Width),
                    Math.Max(previewPanel.ClientSize.Height, viewSize.Height));
            }
            else
            {
                previewPanel.ClientSize = new Size(
                    Math.Max(_defaultFrameSize.Width, viewSize.Width),
                    Math.Max(_defaultFrameSize.Height, viewSize.Height));
            }
            previewPanel.Invalidate();

            if (_autoResize)
            {
                // Try to calculate necessary size, knowing the previewPanel's
                // location relative to client edges, and its new size
                // (actually use panelAutoScroll as a reference here, as it's
                // previewPanel's immediate parent).
                this.ClientSize = new Size(
                    panelAutoScroll.Left + (this.ClientRectangle.Right - panelAutoScroll.Right) + previewPanel.Width,
                    panelAutoScroll.Top + (this.ClientRectangle.Bottom - panelAutoScroll.Bottom) + previewPanel.Height);
            }
        }