Example #1
0
        void DrawTouchTest()
        {
            var touchElements = TouchPad.Instance.TouchElements;

            foreach (var element in touchElements)
            {
                Point p0 = element.Value.Position.ToPoint();

                Point pL = p0;
                Point pR = p0;

                Point pT = p0;
                Point pB = p0;

                pL.X = 0;
                pR.X = 10000;

                pT.Y = 0;
                pB.Y = 10000;

                _drawBatch.DrawLine(pL, pR, Color.Red);
                _drawBatch.DrawLine(pT, pB, Color.Red);
            }

            _drawBatch.Flush();
        }
Example #2
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float zoom     = (float)_zoom.Value / 100f;
            int   unitSize = Tools.Tool.UnitToPixels(zoom);

            int startX = CurrentPosition.X / unitSize;
            int startY = CurrentPosition.Y / unitSize;

            Rectangle bounds = ScreenBounds;

            startX = startX * unitSize - CurrentPosition.X + bounds.X;
            startY = startY * unitSize - CurrentPosition.Y + bounds.Y + 1;

            int size = (int)Math.Ceiling(UiUnit.Unit * 3);

            int right  = bounds.Right + size;
            int bottom = bounds.Bottom + size;

            AdvancedDrawBatch batch = parameters.DrawBatch;

            batch.PushClip(bounds);

            Color color = Color.White * 0.25f;

            for (int x = startX; x < right; x += unitSize)
            {
                for (int y = startY; y < bottom; y += unitSize)
                {
                    batch.DrawLine(new Point(x - size, y), new Point(x + size - 1, y), color);
                    batch.DrawLine(new Point(x, y - size), new Point(x, y + size - 1), color);
                }
            }

            DrawCurrentLayer(ref parameters);

            if (MousePosition.HasValue)
            {
                Point pos = CurrentPosition;
                pos.X -= bounds.X;
                pos.Y -= bounds.Y;

                Tools.Tool.Current.Draw(parameters.DrawBatch, pos, MousePosition.Value, zoom);
            }

            batch.PopClip();
        }
Example #3
0
        void DrawTiles(ref UiViewDrawParameters parameters, TiledLayer layer)
        {
            Rectangle bounds = ScreenBounds;

            AdvancedDrawBatch batch = parameters.DrawBatch;

            SamplerState oldSamplerState = batch.SamplerState;

            batch.SamplerState = SamplerState.PointClamp;

            int width  = layer.Width;
            int height = layer.Height;

            float zoom     = (float)_zoom.Value / 100f;
            int   unitSize = Tools.Tool.UnitToPixels(zoom);

            int tileSize = Tools.Tool.UnitToPixels(1);

            Rectangle target = new Rectangle(bounds.X - CurrentPosition.X, bounds.Y - CurrentPosition.Y, unitSize, unitSize);
            Rectangle source = new Rectangle(0, 0, tileSize - 1, tileSize - 1);

            Texture2D tileset = CurrentTemplate.Instance.Tileset(layer.Tileset).Item2;

            int startY = target.Y;

            int maxY = 0;

            ushort[,] tiles = layer.Content;

            for (int idxX = 0; idxX < width; ++idxX)
            {
                target.Y = startY;

                if (target.Right >= bounds.X && target.X <= bounds.Right)
                {
                    for (int idxY = 0; idxY < height; ++idxY)
                    {
                        if (target.Bottom >= bounds.Y && target.Y <= bounds.Bottom)
                        {
                            ushort tile = tiles[idxX, idxY];

                            if (tile != 0xffff)
                            {
                                source.X = (tile & 0xff) * tileSize;
                                source.Y = ((tile >> 8) & 0xff) * tileSize;

                                batch.DrawImage(tileset, target, source, Color.White * 0.5f);
                            }
                        }

                        target.Y += unitSize;
                        maxY      = Math.Max(target.Y, maxY);
                    }
                }

                target.X += unitSize;
            }

            Color color = Color.White * 0.25f;

            batch.DrawLine(new Point(target.X, bounds.Top), new Point(target.X, maxY), color);
            batch.DrawLine(new Point(bounds.Left, maxY), new Point(target.X, maxY), color);

            batch.SamplerState = oldSamplerState;
        }