private void serializeGumps(string saveas)
 {
     Gump[][] gmps = new Gump[tabControl1.TabCount][];
     for (int i=0; i < tabControl1.TabCount; i++)
     {
         gmps[i]=((GumpViewer)tabControl1.TabPages[i].Controls[0]).Gumps;
     }
     try
     {
         TextWriter tw = new StreamWriter(saveas);
         XmlSerializer xs = new XmlSerializer(typeof(Gump[][]));
         xs.Serialize(tw,gmps);
         tw.Close();
     }
     catch(Exception exc)
     {
         MessageBox.Show(this,"Error saving file:\n"+exc,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
     }
 }
 private void gumpViewer1_GumpRemoved(object sender, ref Gump gump)
 {
     pgProperties.SelectedObject=null;
     cbItems.Items.Remove(gump);
 }
        private void gumpViewer1_SelectedGumpChanged(object sender, Gump gump)
        {
            if (gump==null)
            {
                this.cbItems.SelectedItem=null;
                pgProperties.SelectedObject=null;
                return;
            }

            for(int i=0; i<cbItems.Items.Count; i++)
            {
                if(gump==(Gump)cbItems.Items[i])
                    cbItems.SelectedIndex=i;
            }
        }
 private void bAddGump_Click(object sender, System.EventArgs e)
 {
     if (gumpChooser==null)
         gumpChooser = new GumpChooser(pathToGumps);
     if (gumpChooser.ShowDialog(this)!=DialogResult.Cancel&&gumpChooser.SelectedIndex!=null) {
         Gump gm = new Gump(gumpChooser.SelectedIndex, pathToGumps);
         ((GumpViewer)tabControl1.SelectedTab.Controls[0]).addGump(gm);
     }
 }
 private void gumpViewer1_GumpAdded(object sender, ref Gump gump)
 {
     cbItems.Items.Add(gump);
 }
 private void GumpViewer_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     _gmpMoved=null;
     _gmpResized=null;
     this.Cursor=Cursors.Default;
 }
 private void lbGumps_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     if (lbGumps.SelectedItem == null || !indexes.ContainsKey(lbGumps.SelectedItem))
         return;
     _selectedGump = new Gump((GumpIdx)indexes[lbGumps.SelectedItem], GumpPath);
     gumpPreview1.Image = _selectedGump.Image;
 }
 private void GumpViewer_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (e.Button != MouseButtons.Left)
         return;
     int oldIndex = selectedIndex;
     selectedGump = null;
     IEnumerator ie = items.GetEnumerator();
     Gump g;
     ResizableGump rg;
     int index = 0;
     selectedIndex = -1;
     while (ie.MoveNext()) {
         if (ie.Current.GetType() == typeof(ResizableGump)) {
             rg = (ResizableGump)ie.Current;
             if ((e.X >= rg.X + rg.Width - 2
                 && e.X <= rg.X + rg.Width+2)
                 && (e.Y >= rg.Y + rg.Height - 2
                 && e.Y <= rg.Y + rg.Height + 2)){
                 _gmpResized=rg;
                 selectedGump=rg;
                 selectedIndex=index;
             } else if ((e.X >= rg.X && e.X <= rg.X + rg.Width)
                 && (e.Y >= rg.Y && e.Y <= rg.Y + rg.Height)) {
                 selectedGump=rg;
                 selectedIndex=index;
                 _gmpResized=null;
             }
             index++;
         } else {
             g = (Gump)ie.Current;
             if ((e.X>=g.X&&e.X<=g.X+g.Width)&&(e.Y>=g.Y&&e.Y<=g.Y+g.Height)) {
                 selectedGump=g;
                 selectedIndex=index;
             }
             index++;
         }
     }
     if (selectedIndex != oldIndex) {
         riseOnSelectedIndexChangedEvent();
     } else if (selectedGump != null && _gmpResized == null) {
         _gmpMoved=selectedGump;
         _movedX=e.X-_gmpMoved.X;
         _movedY=e.Y-_gmpMoved.Y;
     }
 }
 protected void riseGumpRemovedEvent(ref Gump gump)
 {
     if (GumpRemoved != null)
         GumpRemoved(this,ref gump);
 }
        public void removeGump(int index)
        {
            if (index<0||index>=items.Count)
                return;
            Gump gmp = (Gump)items[index];
            int cnt=items.Count;
            items.RemoveAt(index);
            selectedGump=null;
            selectedIndex=0;
            if (cnt>items.Count)
                riseGumpRemovedEvent(ref gmp);

            this.Refresh();
        }
 public void removeGump(Gump gmp)
 {
     int cnt=items.Count;
     items.Remove(gmp);
     selectedGump=null;
     selectedIndex=0;
     if (cnt>items.Count)
         riseGumpRemovedEvent(ref gmp);
     this.Refresh();
 }
 public void addGump(Gump gmp)
 {
     items.Add(gmp);
     gmp.SizeChanged+=new sizeChanged(gmp_SizeChanged);
     gmp.PriorityChanged+=new priorityChanged(gmp_PriorityChanged);
     riseGumpAddedEvent(ref gmp);
     SelectedIndex=items.Count-1;
     this.Refresh();
 }