示例#1
0
        public void Add(ColorRectangle obj)
        {
            int gridX = obj.X / gridSize;
            int gridY = obj.Y / gridSize;
            Tuple <int, int> tuple = new Tuple <int, int>(gridX, gridY);

            //Tìm xem đã map key chưa
            bool matchedX = false;
            bool matched  = false;

            foreach (Tuple <int, int> t in occupiedIndexes)
            {
                if (t.Item1 == tuple.Item1)
                {
                    if (t.Item2 == tuple.Item2)
                    {
                        matched = true;
                    }
                    matchedX = true;
                }
            }
            if (!infos.ContainsKey(tuple.Item1))
            {
                infos.Add(tuple.Item1, new Dictionary <int, List <ColorRectangle> >());
            }
            if (!infos[tuple.Item1].ContainsKey(tuple.Item2))
            {
                infos[tuple.Item1].Add(tuple.Item2, new List <ColorRectangle>());
                occupiedIndexes.Add(tuple);
            }

            infos[tuple.Item1][tuple.Item2].Add(obj);
            System.Diagnostics.Debug.WriteLine(tuple.Item1 + "   -   " + tuple.Item2);
        }
示例#2
0
        private void DrawObjectBoundary(ColorRectangle r, Graphics g)
        {
            Font  fnt   = new Font("Arial", 10);
            Brush brush = new SolidBrush(r.color);

            g.DrawString(r.tag.ToString(), fnt, brush, r.x, r.y - 20, new StringFormat());
            g.DrawRectangle(new Pen(brush, 5), r.getRect());
        }
示例#3
0
 public void Remove(ColorRectangle rect)
 {
     foreach (Tuple <int, int> index in occupiedIndexes.ToList <Tuple <int, int> >())
     {
         List <ColorRectangle> rectangles = infos[index.Item1][index.Item2];
         rectangles.Remove(rect);
         if (rectangles.Count == 0)
         {
             occupiedIndexes.Remove(index);
             infos[index.Item1].Remove(index.Item2);
         }
     }
 }
示例#4
0
 private void button3_Click(object sender, EventArgs e)
 {
     rectangles.Remove(currentRect);
     enemy.Remove(currentRect);
     item.Remove(currentRect);
     gridInfo.Remove(currentRect);
     if (currentRect != null)
     {
         currentRect = null;
     }
     pictureBox1.Refresh();
     UpdateInformation();
 }
示例#5
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (currentRect == null)
            {
                return;
            }

            this.rectangles.Add(currentRect);
            gridInfo.Add(currentRect);
            if (currentRect.type == "Enemy")
            {
                enemy.Add(currentRect);
            }
            else
            {
                item.Add(currentRect);
            }

            currentRect = null;

            pictureBox1.Refresh();
            UpdateInformation();
        }
示例#6
0
        private int resizeOpt; // 0-left, 1-top, 2-right, 3-bottom

        public Form1()
        {
            InitializeComponent();


            rectangles  = new List <ColorRectangle>();
            currentRect = null;
            enemy       = new Enemy();
            item        = new Item();

            isDrawing  = false;
            isDraging  = false;
            isResizing = false;
            dragX      = 0;
            dragY      = 0;
            resizeOpt  = -2;
            //Thiết lập zoom
            radioButton2.Checked = true;
            zoom = 2.0f;
            //Grid
            this.textBox8.Text    = 64.ToString();
            this.textBox8.Enabled = false;
            gridInfo = new GridInfo(64);
        }
示例#7
0
 public void Add(ColorRectangle rect)
 {
     rects.Add(rect);
 }
示例#8
0
 public void Remove(ColorRectangle rect)
 {
     this.rects.Remove(rect);
 }
示例#9
0
 private void button4_Click(object sender, EventArgs e)
 {
     this.currentRect = null;
 }
示例#10
0
        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            //Cho phép chọn các hình chữ nhật đã vẽ

            foreach (ColorRectangle r in rectangles)
            {
                if (e.X >= r.x & e.X <= r.x + r.w & e.Y >= r.y & e.Y <= r.y + r.h)
                {
                    currentRect = r;
                    break;
                }
            }

            //Khi click thì kiểm tra xem đã nạp đủ thông số hay chưa (type , ID, item (optional))
            if (listBox1.SelectedItem == null)
            {
                MessageBox.Show("Choose a type !!! ");
                return;
            }
            string type = listBox1.SelectedItem.ToString();

            int result;

            if (!int.TryParse(this.textBox10.Text, out result) ||
                //!int.TryParse(this.textBox3.Text, out result) ||
                //!int.TryParse(this.textBox4.Text, out result) ||
                //!int.TryParse(this.textBox5.Text, out result) ||
                //!int.TryParse(this.textBox6.Text, out result) ||
                (type == "Item" && !int.TryParse(this.textBox9.Text, out result)))
            {
                MessageBox.Show("Some inputs are invalid !!!");
                return;
            }
            //Tao hinh chu nhat
            if (currentRect == null)
            {
                isDrawing = true;
                int   rTag  = int.Parse(textBox10.Text);
                Color color = Color.FromArgb(255, rTag % 255, rTag % 255, rTag % 255);
                if (type == "Enemy")
                {
                    currentRect = new ColorRectangle(type, rTag, e.X, e.Y, 2, 2, color, zoom, pictureBox1.Height);
                }
                else
                {
                    currentRect = new ColorRectangle(type, rTag, e.X, e.Y, 2, 2, color, zoom, pictureBox1.Height, int.Parse(textBox9.Text));
                }
                //Vẽ lại picture box
                pictureBox1.Refresh();
                //Cập nhật thông tin lên textbox
                UpdateInformation();
            }
            else
            {
                //Drag
                if (e.X > currentRect.x + 5 & e.X <currentRect.x + currentRect.w - 5
                                                   & e.Y> currentRect.y + 5 & e.Y < currentRect.y + currentRect.h - 5)
                {
                    isDraging = true;
                    dragX     = e.X;
                    dragY     = e.Y;
                    return;
                }
                //Resize left edge
                int l, r, t, b;
                l = currentRect.x;
                r = currentRect.x + currentRect.w;
                t = currentRect.y;
                b = currentRect.y + currentRect.h;

                if (e.X >= l & e.X <= l + 5 * zoom & e.Y <= b & e.Y >= t)
                {
                    resizeOpt = 0;
                }
                if (e.Y >= t & e.Y <= t + 5 * zoom & e.X <= r & e.X >= l)
                {
                    resizeOpt = 1;
                }
                if (e.X >= r - 5 * zoom & e.X <= r & e.Y >= t & e.Y <= b)
                {
                    resizeOpt = 2;
                }
                if (e.Y >= b - 5 * zoom & e.Y <= b & e.X >= l & e.X <= r)
                {
                    resizeOpt = 3;
                }
                if (resizeOpt != -2)
                {
                    isResizing = true;
                    System.Diagnostics.Debug.WriteLine(isResizing + " - " + resizeOpt + "\n");
                }
            }
        }