⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pixelbuffergraphics.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
字号:

//  Copyright (C) 2006  Riccardo Marzi <riccardo@dotnetfireball.org>
//	
//	This library is free software; you can redistribute it and/or
//	modify it under the terms of the GNU Lesser General Public
//	License as published by the Free Software Foundation; either
//	version 2.1 of the License, or (at your option) any later version.
//	
//	This library is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//	Lesser General Public License for more details.
//	
//	You should have received a copy of the GNU Lesser General Public
//	License along with this library; if not, write to the Free Software
//	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Fireball.Win32;

namespace Fireball.Drawing.Drawing2D
{
    public class PixelBufferGraphics:IDisposable
    {
        private const int CLIP_LINE = 0;
        private const int CLIP_LINE_HORIZONTAL = 1;
        private const int CLIP_LINE_VERTICAL = 2;
        private const int CLIP_LINE_DIAGONAL = 3;

        protected PixelBuffer pixelBuffer;

        public PixelBufferGraphics(PixelBuffer pixelBuffer)
        {
            this.pixelBuffer = pixelBuffer;
        }

        ~PixelBufferGraphics()
        {
            this.Dispose();
        }
        public virtual void Dispose()
        {
            pixelBuffer = null;
        }

        internal virtual void ClearGraphics()
        {
        }

        #region Public Members

        public virtual void DrawLine(Point pt1, Point pt2, Color color)
        {
            this.InternalDrawLine(pt1.X, pt1.Y, pt2.X, pt2.Y, color.ToArgb());
        }
        public virtual void DrawLine(int x1, int y1, int x2, int y2, Color color)
        {
            this.InternalDrawLine(x1, y1, x2, y2, color.ToArgb());
        }

        public virtual void BlendRectangle(Point pt1, Point pt2, Color color)
        {
            this.FillRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y, color);
        }
        public virtual void BlendRectangle(int x1, int y1, int x2, int y2, Color color)
        {
            int _x1 = x1;
            int _y1 = y1;
            int _x2 = x2;
            int _y2 = y2;

            if (_x1 > _x2)
            {
                _x1 = x2;
                _x2 = x1;
            }
            if (_y1 > _y2)
            {
                _y1 = y2;
                _y2 = y1;
            }

            pixelBuffer.BlendSubBuffer(color, _x1, _y1, _x2 - _x1, _y2 - _y1);
        }
        public virtual void FillRectangle(Point pt1, Point pt2, Color color)
        {
            this.FillRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y, color);
        }
        public virtual void FillRectangle(int x1, int y1, int x2, int y2, Color color)
        {
            int _x1 = x1;
            int _y1 = y1;
            int _x2 = x2;
            int _y2 = y2;

            if (_x1 > _x2)
            {
                _x1 = x2;
                _x2 = x1;
            }
            if (_y1 > _y2)
            {
                _y1 = y2;
                _y2 = y1;
            }

            pixelBuffer.SetSubBuffer(color, _x1, _y1, _x2 - _x1, _y2 - _y1);
        }

        #endregion

        #region Stubs

        public virtual void DrawRectangle(Point pt1, Point pt2, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawRectangle(int x1, int y1, int x2, int y2, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawEllipse(Point pt1, Point pt2, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawEllipse(int x1, int y1, int x2, int y2, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawArc(Point pt1, Point pt2, Point pt3, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawArc(int x1, int y1, int x2, int y2, int x3, int y3, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawArc(Point pt1, Point pt2, float startAngle, float sweepAngle, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawArc(int x1, int y1, int x2, int y2, float startAngle, float sweepAngle, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawPolyline(Point[] pts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawPolyline(int[] xPts, int[] yPts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawPolygon(Point[] pts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawPolygon(int[] xPts, int[] yPts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawCurve(Point[] pts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawCurve(int[] xPts, int[] yPts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawClosedCurve(Point[] pts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawClosedCurve(int[] xPts, int[] yPts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawBezierCurve(Point pt1, Point pt2, Point pt3, Point pt4, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawBezierCurve(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawPie(int x1, int y1, int x2, int y2, int x3, int y3, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void DrawPie(Point pt1, Point pt2, float startAngle, float sweepAngle, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillEllipse(Point pt1, Point pt2, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillEllipse(int x1, int y1, int x2, int y2, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillPolygon(Point[] pts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillPolygon(int[] xPts, int[] yPts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillClosedCurve(Point[] pts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillClosedCurve(int[] xPts, int[] yPts, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillPie(int x1, int y1, int x2, int y2, int x3, int y3, Color color)
        {
            throw new NotImplementedException();
        }
        public virtual void FillPie(Point pt1, Point pt2, float startAngle, float sweepAngle, Color color)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region Private Members

        #region Old Code

        //public void DrawLine(int x1, int y1, int x2, int y2, ColorHLS color)
        //{
        //    ColorHLS pixCol = color.Clone();
        //    PixelFillingDelegate pfd = delegate(int x, int y, int count, int total, bool setPixel)
        //    {

        //        if (setPixel)
        //            SetPixel(x, y, pixCol);

        //        return pixCol;
        //    };

        //    DrawLine(x1, y1, x2, y2, pfd);
        //}
        //public void DrawLine(int x1, int y1, int x2, int y2, ColorHLS color1, ColorHLS color2)
        //{
        //    bool created = false;
        //    ColorHLS color = new ColorHLS(color1);
        //    float[,] steps = new float[0, 0];
        //    ColorHLS[] colors = new ColorHLS[0];

        //    PixelFillingDelegate pfd = delegate(int x, int y, int count, int total, bool setPixel)
        //    {
        //        if (!created)
        //        {
        //            steps = ColorUtils.GetGradientColorSteps(color1, color2, total);
        //            created = true;
        //        }

        //        color.SetRGB(
        //            (byte)steps[count, 0],
        //            (byte)steps[count, 1],
        //            (byte)steps[count, 2]
        //            );

        //        if (setPixel)
        //            SetPixel(x, y, color);

        //        return color;
        //    };

        //    DrawLine(x1, y1, x2, y2, pfd);
        //}
        //public void DrawLine(int x1, int y1, int x2, int y2, PixelFillingDelegate pixFillingDelegate)
        //{
        //    int deltax, deltay;

        //    deltax = (x2 - x1);
        //    deltay = (y2 - y1);

        //    if (deltax == 0)
        //    {
        //        if (deltay == 0)
        //        {
        //            return;
        //        }
        //        DrawVerticalLine(x1, y1, deltay, pixFillingDelegate);
        //        return;
        //    }
        //    else if (deltay == 0)
        //    {
        //        DrawHorizontalLine(x1, y1, deltax, pixFillingDelegate);
        //        return;
        //    }

        //    /* Calcoliamo il deltax ed il deltay della linea, ovvero il numero di pixel presenti a livello
        //        orizzontale e verticale. Utilizziamo la funzione abs() poich

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -