예제 #1
0
 public virtual void OnPaint(Graphics g, CanvasViewport viewport)
 {
     foreach (var obj in DrawableObjects)
     {
         obj.OnPaint(g, viewport);
     }
 }
예제 #2
0
 public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewViewport, IConvertWorldView convertWorldView)
 {
     foreach (var obj in DrawableObjects)
     {
         obj.OnPaintInView(viewGraphics, viewViewport, convertWorldView);
     }
 }
        internal void OnZoom(float zoomValue, PointF anchorPoint)
        {
            if (!_isControlEnter && PaddingCanvasGroupParent.IsControlDown)
            {
                _isControlEnter   = true;
                _anchorPointWorld = GetWorldPointFromPaddingCanvasViewPoint(anchorPoint);
            }
            //anchorPoint = _anchorPointView;

            //anchorPointWorld.X = (int)anchorPointWorld.X;
            //anchorPointWorld.Y = (int)anchorPointWorld.Y;

            if (TestInterface != null)
            {
                TestInterface.WorldMouseX = _anchorPointWorld.X;
                TestInterface.WorldMouseY = _anchorPointWorld.Y;
            }

            WorldViewGroup.CanvasViewport.Scale = zoomValue;
            InvalidateCanvasSize();
            EditorCanvasScrollHandling.InvalidateScrollMaxValue();

            PointF anchorPointNew          = GetPaddingCanvasViewPointFromWorldPoint(_anchorPointWorld);
            PointF expectedViewportInView  = new PointF(anchorPointNew.X - anchorPoint.X, anchorPointNew.Y - anchorPoint.Y);
            PointF expectedViewportInWorld = CanvasViewport.GetViewToWorldLocation(expectedViewportInView);

            EditorCanvasScrollHandling.CanvasScrollbar.HValue = expectedViewportInWorld.X;
            EditorCanvasScrollHandling.CanvasScrollbar.VValue = expectedViewportInWorld.Y;
        }
예제 #4
0
 public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewViewport, IConvertWorldView convertWorldView)
 {
     if (@interface.RootNode == null)
     {
         return;
     }
     DrawQuadnode(@interface.RootNode, viewGraphics, convertWorldView);
 }
        public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewViewport, IConvertWorldView convertWorldView)
        {
            if ([email protected])
            {
                return;
            }
            Rectangle locationRect = convertWorldView.GetViewRect(@interface.SelectingRect);

            viewGraphics.DrawRectangle(new Pen(@interface.SelectingColorBorder, 1), locationRect);
            viewGraphics.FillRectangle(new SolidBrush(@interface.SelectingBackColor), locationRect);
        }
        public Matrix GetWorldToViewMatrix()
        {
            Matrix matrix = new Matrix();

            matrix.Scale(WorldViewGroup.CanvasViewport.Scale, WorldViewGroup.CanvasViewport.Scale, MatrixOrder.Append);
            matrix.Translate(PaddingLeft, PaddingTop, MatrixOrder.Append);
            var wtvMatrix = CanvasViewport.GetWorldToViewMatrix();

            matrix.Multiply(wtvMatrix, MatrixOrder.Append);
            return(matrix);
        }
예제 #7
0
        public Bitmap GetImage(Graphics g, Graphics viewGraphics, CanvasViewport viewport)
        {
            if (TileRenderParent == null)
            {
                return(null);
            }
            int tileWidth        = TileRenderParent.TileWidth;
            int tileHeight       = TileRenderParent.TileHeight;
            int tileRows         = TileRenderParent.TileRows;
            int tileColumns      = TileRenderParent.TileColumns;
            int tileSheetColumns = TileRenderParent.TilesheetColumns;

            int cBegin = (int)viewport.X / tileWidth;
            int cEnd   = viewport.Right / tileWidth + 1;

            int rBegin = (int)viewport.Y / tileHeight;
            int rEnd   = (int)viewport.Bottom / tileHeight + 1;

            if (cEnd > tileColumns)
            {
                cEnd = tileColumns;
            }
            if (rEnd > tileRows)
            {
                rEnd = tileRows;
            }

            int xWorld = cBegin * tileWidth;
            int yWorld = rBegin * tileHeight;

            float xRender = 0;
            float yRender = 0;
            float xBegin  = xRender;

            Bitmap tileBitmap = new Bitmap((cEnd - cBegin) * tileWidth, (rEnd - rBegin) * tileHeight);

            for (int rIndex = rBegin; rIndex < rEnd; rIndex++)
            {
                xRender = xBegin;
                for (int cIndex = cBegin; cIndex < cEnd; cIndex++)
                {
                    int        index      = Matrix[rIndex, cIndex];
                    RectangleF cropedRect = new RectangleF((index % tileSheetColumns) * tileWidth,
                                                           (index / tileSheetColumns) * tileHeight, tileWidth, tileHeight
                                                           );
                    RectangleF locationRect = new RectangleF(xRender, yRender, tileWidth, tileHeight);
                    Graphics.FromImage(tileBitmap).DrawImageFromOtherImage(Tilesheet, cropedRect, locationRect);
                    xRender += tileWidth;
                }
                yRender += tileHeight;
            }

            return(tileBitmap);
        }
예제 #8
0
        private void DrawSelectedTile(Graphics viewGraphics, CanvasViewport viewport)
        {
            if (CurrentColumn < 0 || CurrentRow < 0)
            {
                return;
            }
            int    x            = _selectedTile.X * @interface.TileWidth;
            int    y            = _selectedTile.Y * @interface.TileHeight;
            PointF viewLocation = viewport.GetWorldToViewLocation(new PointF(x, y));
            SizeF  sizeValue    = new SizeF(@interface.TileWidth * viewport.Scale, @interface.TileHeight * viewport.Scale);

            viewGraphics.DrawRectangle(new Pen(@interface.SelectedTileColor, 2), viewLocation.X, viewLocation.Y, sizeValue.Width, sizeValue.Height);
        }
        public override void OnPaint(Graphics graphics, IConvertWorldView convertWorldView)
        {
            InvalidateWorldViewport();
            if (WorldViewGroup.CanvasViewport.Width * WorldViewGroup.CanvasViewport.Height == 0)
            {
                graphics.Clear(Color.FromArgb(207, 207, 207));
                return;
            }
            Color borderColor = Color.FromArgb(194, 194, 194);
            var   realSize    = WorldViewGroup.CanvasViewport.RealSize;
            Image worldBitmap = new Bitmap((int)realSize.Width, (int)realSize.Height);

            graphics.Clear(Color.FromArgb(207, 207, 207));

            RectangleF interserctRect = GetInterserctRect();
            PointF     renderLocation = new PointF(PaddingLeft, PaddingTop);

            renderLocation   = CanvasViewport.GetWorldToViewLocation(renderLocation);
            renderLocation.X = (renderLocation.X).GreaterOrEqualThan(0);
            renderLocation.Y = (renderLocation.Y).GreaterOrEqualThan(0);

            if (TileRender != null)
            {
                Image tileImage = TileRender.GetImage(Graphics.FromImage(worldBitmap), graphics, WorldViewGroup.CanvasViewport);
                int   cBegin    = (int)WorldViewGroup.CanvasViewport.X / TileWidth;
                int   rBegin    = (int)WorldViewGroup.CanvasViewport.Y / TileHeight;

                RectangleF rectCrop = new RectangleF(WorldViewGroup.CanvasViewport.X - cBegin * TileWidth - 0.5f,
                                                     WorldViewGroup.CanvasViewport.Y - rBegin * TileHeight - 0.5f,
                                                     WorldViewGroup.CanvasViewport.Width, WorldViewGroup.CanvasViewport.Height);
                graphics.DrawImageFromOtherImage(tileImage, rectCrop,
                                                 new RectangleF(renderLocation, interserctRect.Size));
            }


            WorldViewGroup.OnPaint(Graphics.FromImage(worldBitmap), convertWorldView);

            graphics.DrawImageFromOtherImage(worldBitmap, new RectangleF(0, 0, worldBitmap.Width, worldBitmap.Height),
                                             new RectangleF(renderLocation, interserctRect.Size));

            PointF firstCorner = new PointF(PaddingLeft, PaddingTop);
            PointF lastCorner  = new PointF(PaddingLeft + WorldViewGroup.EditorCanvas.Width * WorldViewGroup.CanvasViewport.Scale,
                                            PaddingTop + WorldViewGroup.EditorCanvas.Height * WorldViewGroup.CanvasViewport.Scale);

            firstCorner = CanvasViewport.GetWorldToViewLocation(firstCorner);
            lastCorner  = CanvasViewport.GetWorldToViewLocation(lastCorner);

            RectangleF r = RectangleF.FromLTRB(firstCorner.X, firstCorner.Y, lastCorner.X, lastCorner.Y);

            graphics.DrawRectangle(new Pen(borderColor, 1), r.X, r.Y, r.Width, r.Height);
        }
        public PointF GetPaddingCanvasViewPointFromWorldPoint(PointF worldPoint)
        {
            // Padding Canvas View to Padding Canvas World Matrix
            Matrix matrix = CanvasViewport.GetWorldToViewMatrix();

            matrix.Invert();
            // Padding Canvas World Matrix to World matrix
            var paddingCanvasWorldToWorldTransform = WorldToPaddingCanvasTransform();

            paddingCanvasWorldToWorldTransform.Invert();
            matrix.Multiply(paddingCanvasWorldToWorldTransform, MatrixOrder.Append);

            matrix.Invert();
            return(matrix.TransformPoint(worldPoint));
        }
예제 #11
0
        public CanvasViewGroup(IEditorCanvasScrollbar scrollbar, int vpWidth, int vpHeight)
        {
            EditorCanvas               = new EditorCanvas();
            EditorCanvasRender         = new EditorCanvasRender();
            EditorCanvasScrollHandling = new EditorCanvasScrollHandling();
            CanvasViewport             = new CanvasViewport(0, 0, vpWidth, vpHeight, EditorCanvas);
            CanvasViewport.Scale       = 1.0f;

            EditorCanvas.Width          = 1000;
            EditorCanvas.Height         = 1000;
            EditorCanvasRender.Canvas   = EditorCanvas;
            EditorCanvasRender.Viewport = CanvasViewport;
            EditorCanvasScrollHandling.CanvasScrollbar = scrollbar;
            EditorCanvasScrollHandling.Canvas          = EditorCanvas;
            EditorCanvasScrollHandling.Viewport        = CanvasViewport;
        }
예제 #12
0
        public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewViewport, IConvertWorldView convertWorldView)
        {
            int selectedTileIndex = @interface.SelectedTileIndex;

            if (@interface.SelectedTileIndex == -1)
            {
                return;
            }
            int   nRows           = @interface.TilesModel.TileRows;
            int   nColumns        = @interface.TilesModel.TileColumns;
            int   tileWidth       = @interface.TilesModel.TileWidth;
            int   tileHeight      = @interface.TilesModel.TileHeight;
            var   worldMatrix     = @interface.TilesModel.Matrix;
            Point prepareLocation = @interface.TilePrepareAddLocation;

            for (int rIndex = 0; rIndex < nRows; rIndex++)
            {
                for (int cIndex = 0; cIndex < nColumns; cIndex++)
                {
                    if (worldMatrix[rIndex, cIndex] == @interface.SelectedTileIndex)
                    {
                        Rectangle locationRect = new Rectangle(cIndex * tileWidth, rIndex * tileHeight, tileWidth, tileHeight);
                        locationRect = convertWorldView.GetViewRect(locationRect);
                        viewGraphics.DrawRectangle(new Pen(@interface.SelectedTileInWorldColor, 2),
                                                   locationRect);
                        viewGraphics.FillRectangle(new SolidBrush(Color.FromArgb(50, @interface.SelectedTileInWorldColor.R, @interface.SelectedTileInWorldColor.G, @interface.SelectedTileInWorldColor.B)), locationRect);
                    }
                }
            }

            if (@interface.CanAddTile)
            {
                int rIndex = prepareLocation.Y / tileHeight;
                int cIndex = prepareLocation.X / tileWidth;

                Rectangle locationRect = new Rectangle(cIndex * tileWidth, rIndex * tileHeight, tileWidth, tileHeight);
                locationRect = convertWorldView.GetViewRect(locationRect);
                viewGraphics.DrawRectangle(new Pen(@interface.SelectedTileInWorldColor, 2),
                                           locationRect);

                var cropRect = new Rectangle(tileWidth * (selectedTileIndex % @interface.TilesModel.TilesheetColumns),
                                             tileHeight * (selectedTileIndex / @interface.TilesModel.TilesheetColumns), tileWidth, tileHeight
                                             );

                viewGraphics.DrawImageFromOtherImage(@interface.TilesModel.Tilesheet, cropRect, locationRect);
            }
        }
 public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewViewport, IConvertWorldView convertWorldView)
 {
     if (@interface.FocusedObjectCategory != null)
     {
         if (@interface.FocusedObjectCategory.TreeViewObject.TreeViewObjectType == Controls.TreeViewControl.TreeViewObjectType.CategoryRectangle)
         {
             return;
         }
         RectangleF locationRect = new RectangleF(@interface.FocusedObjectCategoryLocation,
                                                  @interface.FocusedObjectCategory.ObjectCategoryImage.Size
                                                  );
         locationRect = convertWorldView.GetViewRect(locationRect);
         viewGraphics.DrawImageFromOtherImage(@interface.FocusedObjectCategory.ObjectCategoryImage,
                                              new RectangleF(Point.Empty, @interface.FocusedObjectCategory.ObjectCategoryImage.Size),
                                              locationRect);
     }
 }
예제 #14
0
        public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewViewport, IConvertWorldView convertWorldView)
        {
            foreach (var index in @interface.TilesIndex)
            {
                int col = index % @interface.TilesheetColumns;
                int row = index / @interface.TilesheetColumns;


                Rectangle rect = new Rectangle(col * @interface.TileWidth, row * @interface.TileHeight, @interface.TileWidth, @interface.TileHeight);

                Point viewLocation = viewViewport.GetWorldToViewLocation(new Point(col * @interface.TileWidth, row * @interface.TileHeight)).ToPoint();
                Size  sizeValue    = new Size((int)(@interface.TileWidth * viewViewport.Scale), (int)(@interface.TileHeight * viewViewport.Scale));

                var viewRect = new Rectangle(viewLocation, sizeValue);
                viewGraphics.DrawRectangle(new Pen(@interface.TileObjectColor, 2), viewRect);
            }
        }
예제 #15
0
        public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewViewport, IConvertWorldView convertWorldView)
        {
            if ([email protected])
            {
                return;
            }
            var tileRenderParent = @interface.TilesModel;
            int tileWidth        = tileRenderParent.TileWidth;
            int tileHeight       = tileRenderParent.TileHeight;
            int tileRows         = tileRenderParent.TileRows;
            int tileColumns      = tileRenderParent.TileColumns;
            int tileSheetColumns = tileRenderParent.TilesheetColumns;

            viewGraphics.FillRectangle(new SolidBrush(Color.FromArgb(50, 30, 30, 30)),
                                       viewGraphics.ClipBounds);

            int rowIndex = @interface.SelectTileFromWorldLocation.Y / @interface.TileHeight;
            int colIndex = @interface.SelectTileFromWorldLocation.X / @interface.TileWidth;

            if (rowIndex < 0 || rowIndex >= tileRenderParent.TileRows ||
                colIndex < 0 || colIndex >= tileRenderParent.TileColumns
                )
            {
                return;
            }

            int        tileIndex  = @interface.TilesModel.Matrix[rowIndex, colIndex];
            RectangleF cropedRect = new RectangleF((tileIndex % tileSheetColumns) * tileWidth,
                                                   (tileIndex / tileSheetColumns) * tileHeight, tileWidth, tileHeight
                                                   );

            var viewRect = new Rectangle(@interface.TileWidth * (@interface.SelectTileFromWorldLocation.X / @interface.TileWidth),
                                         @interface.TileHeight * (@interface.SelectTileFromWorldLocation.Y / @interface.TileHeight),
                                         @interface.TileWidth,
                                         @interface.TileHeight);

            viewRect = convertWorldView.GetViewRect(viewRect);

            viewGraphics.DrawImageFromOtherImage(tileRenderParent.Tilesheet
                                                 , cropedRect, viewRect);
        }
예제 #16
0
 public void OnPaint(Graphics g, CanvasViewport viewport)
 {
 }
예제 #17
0
 public void OnPaintInView(Graphics viewGraphics, CanvasViewport viewport, IConvertWorldView convertWorldView)
 {
     DrawCurrentTile(viewGraphics, viewport);
     DrawSelectedTile(viewGraphics, viewport);
 }
예제 #18
0
 public void OnPaint(Graphics g, CanvasViewport viewport)
 {
     g.DrawImageFromOtherImage(Tilesheet, viewport.BoudingRect, new RectangleF(0, 0, viewport.Width, viewport.Height));
 }
예제 #19
0
 public Matrix GetWorldToViewMatrix()
 {
     return(CanvasViewport.GetWorldToViewMatrix());
 }