Exemple #1
0
 public virtual void Up(int pX, int pY, float pPressure)
 {
     isDown = false;
     options = null;
     m_picture = null;
     m_layer = null;
 }
Exemple #2
0
 public virtual void Down(int pX, int pY, float pPressure, Picture pPicture, Layer pLayer, object pOptions)
 {
     isDown = true;
     m_lastPosition = new Point(pX, pY);
     m_lastPressure = pPressure;
     SetOptions(pOptions as Newtonsoft.Json.Linq.JContainer);
     m_layer = pLayer;
     m_picture = pPicture;
 }
        //---------------------------------------------------------------------
        // Render the alterations to the layer
        //---------------------------------------------------------------------
        protected override void DrawStep(Layer layer, Point position, float pPressure)
        {
            int size = MathExt.RoundToInt(options.size * pPressure);
            int halfSize = size / 2;
            Rectangle toolArea = new Rectangle(0, 0, size, size);
            int halfSizeSquared = halfSize * halfSize;
            Color color = options.color;

            // Set the tool size rect to the locate on of the point to be painted
            Point centre = new Point((position.X - halfSize),
                                     (position.Y - halfSize));
            toolArea.Location = centre;

            // Get the area to be painted
            Rectangle areaToPaint = new Rectangle();
            areaToPaint = Rectangle.Intersect(layer.GetArea(), toolArea);

            // Get bitmap data to draw to
            Bitmap bmp = layer.GetBitmap();

            // Lock the bitmap memory area
            System.Drawing.Imaging.BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            // Set up iteration of unsafe byte data
            int stride = data.Stride;

            // Do shit with pointers
            unsafe
            {
                byte* ptr = (byte*)data.Scan0;

                // Check this is not a null area
                if (!areaToPaint.IsEmpty)
                {
                    // Go through the draw area and set the pixels as they should be
                    int len = toolArea.Height * toolArea.Width;
                    for (int i = 0; i < len; i++ )
                    {
                        int x = i % toolArea.Width;
                        int y = i/toolArea.Width;
                        // Check if the pixel is inside the circle
                        if ((((halfSize - x) * (halfSize - x)) + ((halfSize - y) * (halfSize - y)) <= halfSizeSquared) && layer.GetArea().Contains(x + toolArea.X, y + toolArea.Y))
                        {
                            // Set the pixel RGB channels individually
                            ptr[((x + toolArea.X) * 4) + (y + toolArea.Y) * stride] = color.B;
                            ptr[((x + toolArea.X) * 4) + (y + toolArea.Y) * stride + 1] = color.G;
                            ptr[((x + toolArea.X) * 4) + (y + toolArea.Y) * stride + 2] = color.R;
                            ptr[((x + toolArea.X) * 4) + (y + toolArea.Y) * stride + 3] = color.A;
                        }
                    }
                }
            }

            // Unlock the bitmap memory area
            bmp.UnlockBits(data);
        }
        // Calculate the line and step through
        public void DrawLine(Layer layer, Point start, Point end, float pStartPressure, float pEndPressure)
        {
            // Create a line vector
            PointF fStart = PointFExt.FromPoint(start);
            PointF fEnd = PointFExt.FromPoint(end);
            PointF delta = fEnd.Subtract(fStart);

            // Create the point to draw at
            PointF drawPoint = new Point(end.X, end.Y);

            // Find the length of the line
            float length = delta.Length();

            // For each step along the line...
            for (int i = 0; i < length; i++)
            {
                // Draw a pixel
                float quota =  (float)i / length;
                PointF position = PointFExt.Lerp(fStart, fEnd,quota);
                float pressure = MathExt.Lerp(pStartPressure, pEndPressure, quota);
                DrawStep(layer, position.ToPointRounded(), pressure);

            }
        }
Exemple #5
0
 void ToolUp(JToken inputMessage)
 {
     float pressure = inputMessage.Value<float>("pressure");
     int x = inputMessage.Value<int>("x");
     int y = inputMessage.Value<int>("y");
     m_currentTool.Up(x, y, pressure);
     m_currentLayer.History.StoreUndoData(inputMessage);
     m_currentTool = null;
     m_currentLayer = null;
 }
Exemple #6
0
 void ToolDown(JToken inputMessage)
 {
     float pressure = inputMessage.Value<float>("pressure");
     int x = inputMessage.Value<int>("x");
     int y = inputMessage.Value<int>("y");
     Tool tool = m_tools[inputMessage.Value<string>("tool")]; //swap tool on tool down
     string layerID = inputMessage.Value<string>("layer");
     m_currentLayer = m_picture.GetLayer(layerID);
     m_currentTool = tool;
     m_currentTool.Down(x, y, pressure, m_picture, m_currentLayer, inputMessage["options"]);
     m_currentLayer.History.BeginNewUndoLevel();
     m_currentLayer.History.StoreUndoData(inputMessage);
 }
 public void Redraw(Layer pLayer)
 {
     m_cachedLayer = pLayer;
     previewImageBox.Invalidate();
     previewImageBox.Update();
 }
Exemple #8
0
 // Draw on the actual canvas
 protected virtual void DrawStep(Layer layer, System.Drawing.Point point, float pPressure)
 {
 }
Exemple #9
0
 public override void Down(int pX, int pY, float pPressure, Picture pPicture, Layer pLayer, object pOptions)
 {
     base.Down(pX, pY, pPressure, pPicture, pLayer, pOptions);
     DrawStep(pLayer, new Point(pX, pY), pPressure);
 }
 private void OnLayerNameChange(Layer layer, String name)
 {
 }
 // Draw on the actual canvas
 protected virtual void DrawStep(Layer layer, System.Drawing.Point point, float pPressure)
 {
 }
 public override void Down(int pX, int pY, float pPressure, Picture pPicture, Layer pLayer, object pOptions)
 {
     base.Down(pX, pY, pPressure, pPicture, pLayer, pOptions);
     DrawStep(pLayer, new Point(pX, pY), pPressure);
 }
 public void Redraw(Layer pLayer)
 {
     m_cachedLayer = pLayer;
     previewImageBox.Invalidate();
     previewImageBox.Update();
 }
 void ToolUp(Dictionary<string, object> inputMessage)
 {
     float pressure = Convert.ToSingle(inputMessage["pressure"]);
     int x = Convert.ToInt32(inputMessage["x"]);
     int y = Convert.ToInt32(inputMessage["y"]);
     m_currentTool.Up(x, y, pressure);
     m_currentLayer.History.StoreUndoData(inputMessage);
     m_currentTool = null;
     m_currentLayer = null;
 }
 void ToolDown(Dictionary<string, object> inputMessage)
 {
     float pressure = Convert.ToSingle(inputMessage["pressure"]);
     int x = Convert.ToInt32(inputMessage["x"]);
     int y = Convert.ToInt32(inputMessage["y"]);
     Tool tool = m_tools[inputMessage["tool"] as string]; //swap tool on tool down
     string layerID = inputMessage["layer"] as string;
     m_currentLayer = m_picture.GetLayer(layerID);
     m_currentTool = tool;
     m_currentTool.Down(x, y, pressure, m_picture, m_currentLayer, inputMessage["options"]);
     m_currentLayer.History.BeginNewUndoLevel();
     m_currentLayer.History.StoreUndoData(inputMessage);
 }