private void m_pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            Point scaledPt = m_pictureBox.scalePoint(e.Location);
            SpriteBox temp = m_pictureBox.findSpriteBox(scaledPt);
            if (temp != null)
            {
                m_grabbedSpriteBox = temp;
                this.Cursor = Cursors.SizeAll;

                if (m_grabbedSpriteBox.Center == scaledPt)
                {
                    m_mode = Mode.MoveCenter;
                }
                else if (m_grabbedSpriteBox.ShootPoint == scaledPt)
                {
                    m_mode = Mode.MoveShootPoint;
                }
            }
            else
            {
                m_dragStart = e.Location;
                m_mode = Mode.Draw;
            }
        }
        private void m_pictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            Point dragEnd = e.Location;

            if (m_mode == Mode.Draw)
            {
                if (m_dragStart != s_invalidPoint && m_dragStart != dragEnd)
                {
                    Rectangle r = calculateRectangle(m_dragStart, dragEnd);
                    r = m_pictureBox.scaleInvertRectangle(r);

                    m_pictureBox.addSpriteBox(new SpriteBox(m_bColor.BackColor, r));
                    m_pictureBox.TemporarySpriteBox = null;

                    m_dragStart = s_invalidPoint;
                }
            }

            if (m_mode == Mode.MoveCenter)
            {
                m_grabbedSpriteBox.Center = m_pictureBox.scalePoint(e.Location);
                m_grabbedSpriteBox = null;
            }

            if (m_mode == Mode.MoveShootPoint)
            {
                m_grabbedSpriteBox.ShootPoint = m_pictureBox.scalePoint(e.Location);
                m_grabbedSpriteBox = null;
            }

            m_mode = Mode.None;
        }
        public void addSpriteBox(SpriteBox spriteBox)
        {
            SpriteBoxes.Add(spriteBox);

            // if AnimationSet exists, make sure to update it

            // known Animation, so update it
            if (colorLookup.ContainsKey(spriteBox.Color))
            {
                int animIdx = colorLookup[spriteBox.Color];
                List<SpriteBox> lst = sbLookup[spriteBox.Color];

                lst.Add(spriteBox);

                List<Sprite> sprites = new List<Sprite>();
                foreach (SpriteBox sb in lst)
                {
                    sprites.Add(sb.Sprite);
                }
                m_animationSet.anims[animIdx].sprites = sprites.ToArray();
            }

            // unknown Animation, create it
            else if (m_animationSet != null)
            {
                Animation a = new Animation();

                colorLookup.Add(spriteBox.Color, m_animationSet.anims.Length);

                List<SpriteBox> lst = new List<SpriteBox>();
                lst.Add(spriteBox);
                sbLookup.Add(spriteBox.Color, lst);

                a.sprites = new Sprite[1];
                a.sprites[0] = spriteBox.Sprite;

                List<Animation> anims = new List<Animation>(m_animationSet.anims);
                anims.Add(a);
                m_animationSet.anims = anims.ToArray();
            }
            Refresh();
        }