Пример #1
0
        public virtual void Brush(Point pixel, Sprite image, Blend.BlendFunction blend)
        {
            pixel = pixel - new Point(image.pivot);
            
            Point grid, offset;
            
            Cells.Coords(pixel, out grid, out offset);
            
            var gw = Mathf.CeilToInt((image.rect.width  + offset.x) / Cells.CellWidth);
            var gh = Mathf.CeilToInt((image.rect.height + offset.y) / Cells.CellHeight);

            for (int y = 0; y < gh; ++y)
            {
                for (int x = 0; x < gw; ++x)
                {
                    IDrawing drawing;

                    Point cell = new Point(grid.x + x, grid.y + y);
                    
                    if (Cells.GetDefault(cell, out drawing, NewCell))
                    {
                        var point = new Point(x * Cells.CellWidth, y * Cells.CellHeight);

                        drawing.Brush(offset - point + image.pivot, image, blend);

                        Changed.Set(cell, true);
                    }
                }
            }
        }
Пример #2
0
        public virtual void Brush(Point offset, 
                                  Sprite image, 
                                  Blend.BlendFunction blend)
        {
            var rtrans = transform as RectTransform;

            Drawing.Brush(offset - (Point) rtrans.localPosition, image, blend);
        }
Пример #3
0
        public static void DrawPolygon(this IDrawing drawing,
                                       IList<Point> points,
                                       Color color,
                                       Blend.BlendFunction blend)
        {
            var brush = Brush.Polygon(points, color);

            drawing.Brush(new Point(-brush.pivot), brush, blend);
        }
Пример #4
0
        public static void DrawCircle(this IDrawing drawing,
                                      Vector2 center,
                                      int radius,
                                      Color color,
                                      Blend.BlendFunction blend)
        {
            var brush = Brush.Circle(radius, color);

            drawing.Brush(new Point(center), brush, blend);
        }
Пример #5
0
 public static void DrawRect(this IDrawing drawing,
                             Vector2 start, 
                             Vector2 size,
                             Color color,
                             Blend.BlendFunction blend)
 {
     using (var brush = Brush.Rectangle((int)size.x, (int)size.y, color))
     {
         drawing.Brush(new Point(start), brush, blend);
     }
 }
Пример #6
0
        public static void DrawLine(this IDrawing drawing,
                                    Vector2 start, 
                                    Vector2 end, 
                                    int thickness,
                                    Color color,
                                    Blend.BlendFunction blend)
        {
            /*
            var tl = new Vector2(Mathf.Min(start.x, end.x),
                                 Mathf.Min(start.y, end.y));
            */

            var tl = start;

            using (var brush = Brush.Line(new Point(start - tl),
                                          new Point(end - tl),
                                          color,
                                          thickness))
            {
                drawing.Brush(start, brush, blend);
            }
        }
Пример #7
0
 public void Brush(Point offset, Sprite image, Blend.BlendFunction blend)
 {
     PixelDraw.Brush.Apply(image,  offset,
                           Sprite, new Point(0, 0),
                           blend);
 }
Пример #8
0
        public static bool Apply(Sprite brush,  Point brushPosition,
                                 Sprite canvas, Point canvasPosition,
                                 Blend.BlendFunction blend)
        {
            var b_offset = brushPosition - brush.pivot;
            var c_offset = canvasPosition - canvas.pivot;

            var world_rect_brush = new Rect(b_offset.x,
                                            b_offset.y,
                                            brush.rect.width,
                                            brush.rect.height);

            var world_rect_canvas = new Rect(c_offset.x,
                                             c_offset.y,
                                             canvas.rect.width,
                                             canvas.rect.height);

            var activeRect = Intersect(world_rect_brush, world_rect_canvas);

            if (activeRect.width < 1 || activeRect.height < 1)
            {
                return false;
            }

            var local_rect_brush = new Rect(activeRect.x - world_rect_brush.x + brush.textureRect.x,
                                            activeRect.y - world_rect_brush.y + brush.textureRect.y,
                                            activeRect.width,
                                            activeRect.height);

            var local_rect_canvas = new Rect(activeRect.x - world_rect_canvas.x + canvas.textureRect.x,
                                             activeRect.y - world_rect_canvas.y + canvas.textureRect.y,
                                             activeRect.width,
                                             activeRect.height);

            Apply(canvas.texture, local_rect_canvas,
                  brush.texture,  local_rect_brush,
                  blend);

            return true;
        }
Пример #9
0
        public static void Apply(Texture2D canvas, Rect canvasRect,
                                 Texture2D brush,  Rect brushRect,
                                 Blend.BlendFunction blend)
        {
            Color[] canvasColors = canvas.GetPixelRect(canvasRect);
            Color[] brushColors  = brush.GetPixelRect(brushRect);

            Assert.IsTrue(canvasColors.Length == brushColors.Length, "Mismatched texture rects!");

            for (int i = 0; i < canvasColors.Length; ++i)
            {
                canvasColors[i] = blend(canvasColors[i], brushColors[i]);
            }

            canvas.SetPixelRect(canvasRect, canvasColors);
        }