Exemple #1
0
        public static void SelectTile(int xPos, int yPos, TileTab tab, int clicks)
        {
            var ti            = TileHandler.GetTileImage(tab);
            var tileSize      = ti.TileSize;
            int originalIndex = TileHandler.GetTileIndex(xPos, yPos, tab);
            int index         = ti.ColumnsPerRow * yPos + xPos;

            if (xPos >= ti.Image.Width / tileSize || yPos >= ti.Image.Height / tileSize)
            {
                return;
            }

            if (clicks == 1)
            {
                if (SelectedTiles.Contains(index))
                {
                    SelectedTiles.Remove(index);
                }
                else
                {
                    SelectedTiles.Add(index);
                }
            }
            else
            {
                switch (tab)
                {
                case TileTab.Source: { TileHandler.SelectedTile = originalIndex; break; }

                case TileTab.Randomized: { TileHandler.SelectedTile = RandomizedMap[xPos, yPos]; break; }

                case TileTab.RuleTest: { TileHandler.SelectedTile = RuleTestMap[xPos, yPos]; break; }
                }
            }
        }
Exemple #2
0
        public static void DrawTiles(PictureBox pctb, TileTab tab)
        {
            var img      = new Bitmap(pctb.Image);
            var graphics = Graphics.FromImage(img);

            graphics.Clear(Color.White);
            var tileSize = TileHandler.TileSize;
            var grid     = tab == TileTab.Randomized ? RandomizedMap : RuleTestMap;

            for (int x = 0; x <= grid.GetLength(0) - 1; x++)
            {
                for (int y = 0; y <= grid.GetLength(1) - 1; y++)
                {
                    int srcX = grid[x, y] % TileHandler.GetTileImage(TileTab.Source).ColumnsPerRow;
                    int srcY = (grid[x, y] - srcX) / TileHandler.GetTileImage(TileTab.Source).ColumnsPerRow;
                    var dest = new Rectangle(x * tileSize, y * tileSize, tileSize, tileSize);
                    var src  = new Rectangle(srcX * tileSize, srcY * tileSize, tileSize, tileSize);

                    if (grid[x, y] == -1)
                    {
                        graphics.DrawImage(_Blank, dest.X, dest.Y);
                    }
                    else
                    {
                        graphics.DrawImage(SourceImages[SelectedSource].Image, dest, src, GraphicsUnit.Pixel);
                    }
                }
            }

            pctb.Image = img;
        }
Exemple #3
0
        public static void GroupSelectedTiles(TileTab tab, TileSelectionGroups tsg)
        {
            var ti = TileHandler.GetTileImage(tab);

            foreach (var i in SelectedTiles)
            {
                ti.SetSelectionGroup(i, tsg);
            }
        }
Exemple #4
0
 private void lstvTileSource_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lstvTileSource.SelectedItems.Count == 0)
     {
         return;
     }
     TileHandler.SelectedSource = TileHandler.SourceImages.IndexOf(lstvTileSource.SelectedItems[0].Tag as TileImage);
     _PictureBoxes[0].Image     = TileHandler.GetTileImage(TileTab.Source).Image;
 }
Exemple #5
0
        private void btnSelectAll_Click(object sender, EventArgs e)
        {
            var pctb = (PictureBox)tbcMain.SelectedTab.Controls[0];
            var ti   = TileHandler.GetTileImage((TileTab)tbcMain.SelectedIndex);

            if (TileHandler.SelectedTiles.Count != ti.NumberOfTiles)
            {
                TileHandler.SelectAll((TileTab)tbcMain.SelectedIndex);
            }
            else
            {
                TileHandler.DeselectAll((TileTab)tbcMain.SelectedIndex);
            }

            ReloadSelectedTilesPanel();
            pctb.Invalidate();
        }
Exemple #6
0
        private void OnPctbClick(object sender, MouseEventArgs e)
        {
            var pctb     = (PictureBox)tbcMain.SelectedTab.Controls[0];
            var ti       = TileHandler.GetTileImage((TileTab)tbcMain.SelectedIndex);
            var tileSize = ti.TileSize;
            var xStart   = pctb.Width / 2 - TileHandler.GetWidth((TileTab)tbcMain.SelectedIndex) / 2;
            var yStart   = pctb.Height / 2 - TileHandler.GetHeight((TileTab)tbcMain.SelectedIndex) / 2;
            int xPos     = (e.X - xStart) / tileSize;
            int yPos     = (e.Y - yStart) / tileSize;

            TileHandler.SelectTile(xPos, yPos, (TileTab)tbcMain.SelectedIndex, e.Clicks);

            lblSelectedTile.Text = "Selected Tile: " + TileHandler.SelectedTile;
            //Init the selected tile neighbor test.
            pctb.Invalidate();
            ReloadSelectedTilesPanel();
        }
Exemple #7
0
        public Main()
        {
            InitializeComponent();

            //Source panel.
            Point pt = new Point(tbcMain.Location.X + 15, tbcMain.Location.Y + 32);

            pnlTileSource.Parent   = this;
            pnlTileSource.Location = pt;
            pnlTileSource.BringToFront();
            pnlTileSource.Hide();

            //Selected tiles panel.
            pt = new Point(tbcMain.Width - 25 - pnlSelectedTiles.Width, tbcMain.Location.Y + 32);
            pnlSelectedTiles.Parent   = this;
            pnlSelectedTiles.Location = pt;
            pnlSelectedTiles.BringToFront();
            pnlSelectedTiles.Hide();
            pnlSelectedTiles.Anchor = AnchorStyles.Top | AnchorStyles.Right;

            TileHandler.Initialize();

            //Add the columns.
            lstvTileSource.Columns.Add("Path", -2, HorizontalAlignment.Left);
            lstvTileAttributes.Columns.Add("Attribute", -2, HorizontalAlignment.Left);
            ReloadSourcePanel();

            var img = TileHandler.GetTileImage(TileTab.Source).Image;

            pctbMain.Image  = img;
            pctbMain.Width  = img.Width;
            pctbMain.Height = img.Height;

            pctbTileTest.Image     = TileHandler.GetTileImage(TileTab.Randomized).Image;
            pctbSelectedTile.Image = TileHandler.GetTileImage(TileTab.RuleTest).Image;

            _PictureBoxes    = new PictureBox[3];
            _PictureBoxes[0] = pctbMain;
            _PictureBoxes[1] = pctbTileTest;
            _PictureBoxes[2] = pctbSelectedTile;
        }
Exemple #8
0
        private void OnMainPaint(object sender, PaintEventArgs e)
        {
            if (!_EnableGrid)
            {
                return;
            }

            var tileSize = TileHandler.GetTileImage((TileTab)tbcMain.SelectedIndex).TileSize;
            var pctb     = (PictureBox)tbcMain.SelectedTab.Controls[0];
            var ti       = TileHandler.GetTileImage((TileTab)tbcMain.SelectedIndex);

            var xStart = pctb.Width / 2 - TileHandler.GetWidth((TileTab)tbcMain.SelectedIndex) / 2;
            var yStart = pctb.Height / 2 - TileHandler.GetHeight((TileTab)tbcMain.SelectedIndex) / 2;

            Graphics g      = e.Graphics;
            int      xCount = ti.Image.Width / tileSize + 1;
            int      yCount = ti.Image.Height / tileSize + 1;
            Pen      p      = new Pen(Color.Black);
            Brush    red    = new SolidBrush(Color.FromArgb(50, 255, 10, 10));
            Brush    blue   = new SolidBrush(Color.FromArgb(50, 10, 10, 255));
            Brush    green  = new SolidBrush(Color.FromArgb(50, 10, 255, 10));
            Brush    gray   = new SolidBrush(Color.FromArgb(100, 10, 10, 10));

            //Draw grid.
            for (int y = 0; y < yCount; y++)
            {
                g.DrawLine(p, xStart, yStart + y * tileSize, xStart + (xCount - 1) * tileSize, yStart + y * tileSize);
            }
            for (int x = 0; x < xCount; x++)
            {
                g.DrawLine(p, xStart + x * tileSize, yStart, xStart + x * tileSize, yStart + (yCount - 1) * tileSize);
            }

            //Draw cell groups.
            foreach (var t in ti.GetTiles())
            {
                var x = xStart + (t.Index % ti.ColumnsPerRow) * ti.TileSize;
                var y = yStart + (t.Index / ti.ColumnsPerRow) * ti.TileSize;

                if (t.SelectionGroup == TileSelectionGroups.Blue)
                {
                    g.FillRectangle(blue, x, y, tileSize, tileSize);
                }
                else if (t.SelectionGroup == TileSelectionGroups.Green)
                {
                    g.FillRectangle(green, x, y, tileSize, tileSize);
                }
                else if (t.SelectionGroup == TileSelectionGroups.Red)
                {
                    g.FillRectangle(red, x, y, tileSize, tileSize);
                }

                if (TileHandler.SelectedTiles.Contains(t.Index))
                {
                    g.FillRectangle(gray, x, y, tileSize, tileSize);
                }
            }

            //Draw cell selections.
            foreach (var t in TileHandler.SelectedTiles)
            {
                var x = xStart + (t % ti.ColumnsPerRow) * ti.TileSize;
                var y = yStart + (t / ti.ColumnsPerRow) * ti.TileSize;

                if (TileHandler.SelectedTiles.Contains(t))
                {
                    g.FillRectangle(gray, x, y, tileSize, tileSize);
                }
            }
        }