예제 #1
0
        private void picPreview_Paint(object sender, PaintEventArgs e)
        {
            int   x, y, topX, topY, scale;
            Panel src;

            if (DesignMode)
            {
                return;
            }

            src = (Panel)sender;
            e.Graphics.Clear(Color.FromKnownColor(KnownColor.AppWorkspace));

            if (_sprite == null)
            {
                return;
            }

            // ===============================================================
            // === Draw the background
            // ===============================================================
            // Determine the scale factor for a 128x64 sprite
            x     = src.Width / 128;
            y     = src.Height / 64;
            scale = Math.Min(x, y);
            // Center the sprite depending on its real size
            topX = (src.Width - _sprite.Width * scale) / 2;
            topY = (src.Height - _sprite.Height * scale) / 2;

            e.Graphics.FillRectangle(
                brushBackground,
                0,
                0,
                src.Width,
                src.Height);

            for (x = 0; x < _sprite.Width; x++)
            {
                for (y = 0; y < _sprite.Height; y++)
                {
                    if (_sprite.GetPixel(x, y) == true)
                    {
                        e.Graphics.FillRectangle(
                            brushForeground,
                            topX + x * scale,
                            topY + y * scale,
                            scale,
                            scale);
                    }
                }
            }
        }
예제 #2
0
        private void DrawingArea_Paint(object sender, PaintEventArgs e)
        {
            int          x, y;
            int          minX, maxX, minY, maxY;
            List <Point> points;

            if (DesignMode)
            {
                return;
            }

            minX = Math.Min(_x0, _x1);
            maxX = Math.Max(_x0, _x1);
            minY = Math.Min(_y0, _y1);
            maxY = Math.Max(_y0, _y1);

            if (OnNotify != null)
            {
                OnNotify(this, new OnNotifyEventArgs("DrawingArea", Properties.Resources.MSG_DRAWING_REFRESH));
            }

            e.Graphics.Clear(Color.FromKnownColor(KnownColor.AppWorkspace));

            if (_sprite == null)
            {
                return;
            }

            // ===============================================================
            // === Draw the background
            // ===============================================================
            // Determine the scale factor for a 128x64 sprite
            x      = Width / 128;
            y      = Height / 64;
            _scale = Math.Min(x, y);
            // Center the sprite depending on its real size
            _topX = (Width - _sprite.Width * _scale) / 2;
            _topY = (Height - _sprite.Height * _scale) / 2;

            if (_showGrid == true)
            {
                for (x = 0; x < _sprite.Width; x++)
                {
                    for (y = 0; y < _sprite.Height; y++)
                    {
                        if (_sprite.GetPixel(x, y) == true)
                        {
                            e.Graphics.FillRectangle(brushPixel, _topX + x * _scale, _topY + y * _scale, _scale, _scale);
                        }
                        else
                        {
                            e.Graphics.FillRectangle(
                                (((x / _gridSize + y / _gridSize) % 2 == 0) ? (((x + y) % 2 == 0) ? brushGridDark1 : brushGridLight1) : (((x + y) % 2 == 0) ? brushGridDark2 : brushGridLight2)),
                                _topX + x * _scale,
                                _topY + y * _scale,
                                _scale,
                                _scale);
                        }
                    }
                }
            }
            else
            {
                e.Graphics.FillRectangle(brushNoGrid, _topX, _topY, _sprite.Width * _scale, _sprite.Height * _scale);

                for (x = 0; x < _sprite.Width; x++)
                {
                    for (y = 0; y < _sprite.Height; y++)
                    {
                        if (_sprite.GetPixel(x, y) == true)
                        {
                            e.Graphics.FillRectangle(brushPixel, _topX + x * _scale, _topY + y * _scale, _scale, _scale);
                        }
                    }
                }
            }

            if (_pressed)
            {
                switch (_currentTool)
                {
                case DrawingTools.DrawLine:
                    points = drawLine(_x0, _y0, _x1, _y1);

                    foreach (Point point in points)
                    {
                        e.Graphics.FillRectangle(
                            brushTemp,
                            _topX + point.X * _scale, _topY + point.Y * _scale, _scale, _scale);
                    }
                    break;

                case DrawingTools.DrawRect:
                    points = drawRect(minX, minY, maxX, maxY);
                    foreach (Point point in points)
                    {
                        e.Graphics.FillRectangle(
                            brushTemp,
                            _topX + point.X * _scale, _topY + point.Y * _scale, _scale, _scale);
                    }
                    break;

                case DrawingTools.DrawFilledRect:
                    e.Graphics.FillRectangle(
                        brushTemp,
                        _topX + minX * _scale,
                        _topY + minY * _scale,
                        ((maxX - minX) + 1) * _scale,
                        ((maxY - minY) + 1) * _scale);
                    break;
                }
            }
        }