Пример #1
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            int posX, posY;

            //if (hScrollBar1.Value / this.tile.GetTileSize() >= 0)
            //{
            posX = (e.X + hScrollBar1.Value >> 4) / (tile.GetTileSize() / 16);
            //}
            //else
            //{
            //posX = (e.X >> 4) / (tile.GetTileSize() / 16);
            //}
            //if(vScrollBar2.Value / this.tile.GetTileSize() >= 0)
            //{
            posY = (e.Y + vScrollBar2.Value >> 4) / (tile.GetTileSize() / 16);
            //}
            //else
            //{
            //posY = (e.Y >> 4) / (tile.GetTileSize() / 16);
            //}

            int posXUpdated, posYUpdated;

            if (posX > size - 1 || posY > size - 1)
            {
                return;
            }
            RectangleF cloneRect = new RectangleF(posX * tile.GetTileSize(), posY * tile.GetTileSize(),
                                                  tile.GetTileSize(), tile.GetTileSize());

            System.Drawing.Imaging.PixelFormat format = backGroundImage.PixelFormat;
            Bitmap cloneBitmap = backGroundImage.Clone(cloneRect, format);

            Tile.Instance().CopyTile(cloneBitmap, int.Parse(txtID.Text), txtTileName.Text);

            Bitmap tileImage = Tile.Instance().PasteTile();

            if (tileImage != null)
            {
                //g.DrawImage(tileImage, ((posX * (this.tile.GetTileSize() / 16)) << 4) - hScrollBar1.Value % this.tile.GetTileSize(), ((posY* (this.tile.GetTileSize() / 16)) << 4) - vScrollBar2.Value % this.tile.GetTileSize());
                //TilesData[posX + posY * size] = this.tile.id;
                //TilesDateName[this.tile.id] = txtTileName.Text;
                Tile tile = new Tile();
                tile.location = txtLocation.Text;
                tile.nameTile = txtTileName.Text;
                tile.id       = this.tile.id;

                //if(hScrollBar1.Value % this.tile.GetTileSize()==0)
                //{
                posXUpdated = ((posX * (this.tile.GetTileSize() / 16)) << 4);
                lbX.Text    = posXUpdated.ToString();                      //+ hScrollBar1.Value).ToString();

                //}
                //else
                //{
                //posXUpdated = ((posX * (this.tile.GetTileSize() / 16)) << 4) + 0;
                //lbX.Text = (((posX * (this.tile.GetTileSize() / 16)) << 4) + 0).ToString();

                //}

                //if(vScrollBar2.Value % this.tile.GetTileSize() == 0)
                //{
                posYUpdated = ((posY * (this.tile.GetTileSize() / 16)) << 4);                 //+ vScrollBar2.Value;
                lbY.Text    = posYUpdated.ToString();

                //}
                //else
                //{
                //lbY.Text = (((posY * (this.tile.GetTileSize() / 16)) << 4) + 0).ToString();
                //posYUpdated= ((posY * (this.tile.GetTileSize() / 16)) << 4) + 0;
                //}
                g.DrawImage(tileImage, posXUpdated - hScrollBar1.Value, posYUpdated - vScrollBar2.Value);
                tile.x      = posXUpdated;
                tile.y      = posYUpdated;
                tile.width  = int.Parse(txtWidth.Text);
                tile.height = int.Parse(txtHeight.Text);
                RSTILES.Add(tile);
                //lbX.Text = (((posX * (this.tile.GetTileSize() / 16)) << 4) + hScrollBar1.Value ).ToString();
                //lbY.Text = (((posY * (this.tile.GetTileSize() / 16)) << 4) + vScrollBar2.Value ).ToString();
                //g.DrawImage(tileImage, posXUpdated, posYUpdated);
                lbW.Text = this.tile.GetTileSize().ToString();
                lbH.Text = this.tile.GetTileSize().ToString();
                DrawTilesLine();
            }
        }
Пример #2
0
        public void GetImage(Image iImage)
        {
            image = new Bitmap(iImage);

            g = panel1.CreateGraphics();

            palletSize = image.Size.Width / tile.GetTileSize() > image.Size.Height / tile.GetTileSize() ?
                         image.Size.Width / tile.GetTileSize() : image.Size.Width / tile.GetTileSize();

            //TilesID = new int[palletSize];

            this.Width  = image.Size.Width + 50;
            this.Height = image.Size.Height + 50;


            g.DrawImage(image, 0, 0);
        }