Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Sprite Editor for .NET

, 27 Jan 2010
Build, edit, and animate your own sprites.
classSprite_C_2008.zip
classSprite
classSprite
classSprite.csproj.user
bin
Release
classSprite.dll
Properties
GraphicsEditor_C_2008.zip
GraphicsEditor CSharp
GraphicsEditor CSharp
graphics editor icon.ico
GraphicsEditor CSharp.csproj.user
Properties
Settings.settings
Resources
Brush_Icon.bmp
click to load image.bmp
colorTemplate.bmp
cursor_cross.bmp
cursor_move.bmp
cursor_resizeDiagonal_BL_TR.bmp
cursor_resizeDiagonal_TL_BR.bmp
cursor_resizeLeftRight.bmp
cursor_resizeUpDown.bmp
Edit_Redo_Icon.bmp
Edit_Undo_Icon.bmp
Eraser_Icon.bmp
FloodFill_Icon.bmp
FloodFill_pnlBackground_sameColor.bmp
FloodFill_pnlBackground_toBorder.bmp
Free-Form Select_Icon.bmp
Gun.bmp
Line_Icon.bmp
Magnify_Icon.bmp
Pencil_Icon.bmp
Pick-color_Icon.bmp
Select_Icon.bmp
sprite Editor.jpg
Straighten_Icon.bmp
Night_Stalker__C_2008.zip
Night Stalker
Night Stalker
Night Stalker.csproj.user
nightstalker.ico
Properties
Settings.settings
Resources
bomb.wav
bulletEaten.wav
BulletEater.spr
bulletEater.wav
bunker.png
bunkerbuster.spr
BunkerBuster.wav
CDbunkerWalls.bmp
Colt Round.png
Colt.spr
colt45.wav
corpse (small).spr
diescream.wav
emptychamber.wav
Evil Jessica (small).spr
Felix the Cat (small).spr
FelixFire.spr
FelixFire.wav
freeLife.wav
gun.png
gun.spr
heartbeat.wav
help_background.jpg
hithard.wav
Jessica Rabbit Small.spr
largeJessica.spr
Laser.spr
laserFire.wav
loadclip.wav
Map WPs.png
Map.jpg
MapCD.bmp
mini bat.spr
NearestWayPointsTable.bfs
nightstalker.bmp
nightstalker.png
red bunker.png
Robot Den New.png
Robot_A.spr
smurf (small).spr
smurf-attack.spr
spider (small).spr
Spider Web.png
splat.wav
WayPointsArray.bfs
WayPointsTable.bfs
Sprites.zip
Sprites
Robot1.bmp
Robot2.bmp
robot3.bmp
Bat
bat.spr
head.bmp
head.jpg
leftwing.bmp
mini bat.spr
wing.bmp
Bullets
bulletEater original.png
bulletEater.bmp
BulletEater.spr
bunkerbuster.bmp
bunkerbuster.spr
Colt.bmp
Colt.spr
Laser.bmp
Laser.spr
master limb.bmp
smurf-attack.bmp
smurf-attack.spr
Claudia Schiffer
alt.spr
Claudia.spr
Claudia_Arm.bmp
Claudia_Foot.bmp
Claudia_Forearm.bmp
Claudia_Hand_Left.bmp
Claudia_Hand_Right.bmp
Claudia_head.bmp
Claudia_head2.bmp
Claudia_mini.spr
Claudia_Schiffer_1.jpg
Claudia_Shin.bmp
Claudia_Thigh.bmp
Claudia_Torso.bmp
gunHand.bmp
Corpse
blood.bmp
corpse (small).spr
Corpse.spr
guts.bmp
master limb.bmp
robot.png
smurfcorpse.png
Evil Jessica
Evil Jessica (small).spr
Evil Jessica.spr
GunHand(near).bmp
JR_Arm.bmp
JR_Arm.png
JR_Dress.bmp
JR_Dress_resized.bmp
JR_Foot.bmp
JR_Forearm.bmp
JR_Hair(far).bmp
JR_Hair(near).bmp
JR_Hand.bmp
JR_Hand_Right.bmp
JR_Head.bmp
JR_MasterBlock.bmp
JR_Shin.bmp
JR_Thigh_far.bmp
JR_Thigh_near.bmp
JR_Torso.bmp
gun
gun.bmp
gun.spr
master block.bmp
Jessica Rabbit
GunHand(near).bmp
Jessica Rabbit Small.spr
Jessica Rabbit.spr
jessica_rabbit at mic.jpg
JR_Arm.bmp
JR_Dress.bmp
JR_Dress_resized.bmp
JR_Foot.bmp
JR_Forearm.bmp
JR_Hair(far).bmp
JR_Hair(near).bmp
JR_Hand.bmp
JR_Hand_Right.bmp
JR_Head.bmp
JR_MasterBlock.bmp
JR_Shin.bmp
JR_Thigh_far.bmp
JR_Thigh_near.bmp
JR_Torso.bmp
Lindsay Lohan
arm.bmp
foot.bmp
forearm.bmp
gunHand.bmp
Hand_Left.bmp
head.bmp
Lindsay Lohan.spr
Mini Lindsay Lohan.spr
shin.bmp
skirt_ass.bmp
skirt_front.bmp
thigh.bmp
torso.bmp
NightStalkerSprites
BulletEater.spr
bunkerbuster.spr
Colt.spr
corpse (small).spr
Evil Jessica (small).spr
gun.spr
Jessica Rabbit Small.spr
Laser.spr
mini bat.spr
Mini Lindsay Lohan.spr
Robot_A.spr
smurf (small).spr
smurf-attack.spr
spider (small).spr
Robot Heart
RobotHeart_Head.bmp
RobotHeart_Torso.bmp
Robot_EyeShut.bmp
ROBOT_heart.bmp
Robot_Heart.spr
Robot_Heart_small.spr
Robot_LeftArm.bmp
Robot_Leg.bmp
Robot_dumb
Arm.bmp
Arm_right_front.bmp
Hand.bmp
Head.bmp
head_back.bmp
Head_Front.bmp
Leg.bmp
leg_back.bmp
leg_front.bmp
Robot_A.spr
Robot_A_original.spr
Robot_A_original_copy.spr
Torso.bmp
Torso_Front.bmp
Smurf
arm(far).bmp
arm(near).bmp
head.bmp
leg.bmp
smurf (small).spr
smurf.spr
Torso.bmp
spider
body.bmp
eyes shut.bmp
head.bmp
legA_left.bmp
legA_right.bmp
legB_left.bmp
legB_right.bmp
LegC_left.bmp
legC_right.bmp
legD_left.bmp
legD_right.bmp
mandible_left.bmp
mandible_right.bmp
spider (small).spr
spider 2.spr
spider.png
spider.spr
sprite_Demo_C_2008.zip
Sprite demo
Sprite demo
Sprite demo.csproj.user
bin
Release
Sprite demo.exe
Properties
Settings.settings
Resources
cartoon grass.jpg
smurf (small).spr
sprite_Editor_C_2008.zip
Sprite Editor
Sprite Editor
Sprite Editor.csproj.user
sprite Editor.ico
bin
Release
cLibPicBoxViewer.dll
Sprite Editor.exe
Properties
Settings.settings
Resources
click to load image.bmp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sprite;

namespace Sprite_Editor
{  
    public enum enuEditHPMode { mouseSetHingeAngle }
    public enum enuEditConfigurationMode { normal, SetHingeRadialCoor }
    public enum enuEditMode { normal, EditHP, EditConfiguration}

    public partial class formSpriteEditor : Form
    {
        #region ".DLLs"
        Sprite.classSpriteMaker spriteMaker = new classSpriteMaker();
        classMath cLibMath = new classMath();
        #endregion

        #region  "constants"
        //"messagebox button/return constants"
        const string conYes = "Yes";
        const string conNo = "No";
        const string conCancel = "Cancel";
        const string conOK = "OK";

        const string conDoNotDrawLimb = "-DO-NOT-DRAW-LIMB-";
        #endregion

        #region "variables"
        enuEditMode editMode = enuEditMode.normal;
        enuEditHPMode EditHPMode = enuEditHPMode.mouseSetHingeAngle;
        enuEditConfigurationMode EditConfigurationMode = enuEditConfigurationMode.normal;

        public bool bolDisposed = false;

        double dblControllingLabelFactor = 0.0;
        double dblAngle = 0.0;
        int intDrawingCenterMove = 50;
        bool bolControlLabelOn = false;
        bool bolImageCentered = false;
        bool bolIgnoreChangesToCmb = false;


        Sprite.classSprite spriteMain;
        Sprite.classSpriteHinge hingeCurrentlySelected = null;
        Sprite.classConfiguration configurationCurrentlySelected = null;
        Sprite.classSpriteLimb limbCurrentlySelected = null;
        Sprite.classSpriteLimb limbPossibleNextSelection = null;

        string[] strDrawSequence;
        udtDrawSequence[] udrConDrawSequence;


        #endregion

        #region "objects"
        PictureBox picImageLoader = new PictureBox();
        Point ptMouse = new Point();
        Point ptDrawingCenter = new Point();
        TextBox txtControlledByLabel;
        System.Windows.Forms.Timer tmrHPAngleTimer = new Timer();
        #endregion

        #region "structures"
        public struct udtDrawSequence
        {
            public string[] Limb;
        }
        #endregion

        public formSpriteEditor()
        {
            InitializeComponent();
            pnlWorkSpace.Controls.Add(cmbLimbs);
            pnlWorkSpace.Controls.Add(grbHingeParameters);

            SizeChanged += new EventHandler(formBuildObject_SizeChanged);

            picMainDisplay.Controls.Add(grbHingeParameters); grbHingeParameters.Visible = true;
            picMainDisplay.Controls.Add(grbConfigurationParameters); grbConfigurationParameters.Visible = false;
            picMainDisplay.Controls.Add(cmbLimbs); cmbLimbs.Visible = true;
            picMainDisplay.Controls.Add(cmbHinges); cmbHinges.Visible = true;
            picMainDisplay.Controls.Add(cmbConfigurations); cmbConfigurations.Visible = true;

            txtHPCurrentAngle.TextChanged += new EventHandler(txtHPCurrentAngle_TextChanged);
            txtConfigurationName.LostFocus += new EventHandler(txtConfigurationName_LostFocus);
            txtConfigurationName.KeyDown += new KeyEventHandler(txtConfigurationName_KeyDown);

            lblHPCurrentAngle.MouseEnter += new EventHandler(lblHPCurrentAngle_MouseEnter);
            lblHPCurrentAngle.MouseLeave += new EventHandler(lblHPCurrentAngle_MouseLeave);
            lblHPCurrentAngle.MouseClick += new MouseEventHandler(lblHPCurrentAngle_MouseClick);

            lblHPCurrentAngle.MouseMove += new MouseEventHandler(lblHPCurrentAngle_MouseMove);

            txtHPDLimbRadAngle.TextChanged += new EventHandler(txtHPDLimbRadAngle_TextChanged);
            txtHPDLimbRadMagnitude.TextChanged += new EventHandler(txtHPDLimbRadMagnitude_TextChanged);
            txtHPSLimbRadAngle.TextChanged += new EventHandler(txtHPSLimbRadAngle_TextChanged);
            txtHPSLimbRadMagnitude.TextChanged += new EventHandler(txtHPSLimbRadMagnitude_TextChanged);

            cmbLimbs.SelectedIndexChanged += new EventHandler(cmbLimbs_SelectedIndexChanged);
            cmbHinges.SelectedIndexChanged += new EventHandler(cmbHinges_SelectedIndexChanged);

            cmbConfigurations.SelectedIndexChanged += new EventHandler(cmbConfigurations_SelectedIndexChanged);
            nudConfigurationStep.ValueChanged += new EventHandler(nudConfigurationStep_ValueChanged);

            picMainDisplay.MouseMove += new MouseEventHandler(picMainDisplay_MouseMove);
            picMainDisplay.MouseClick += new MouseEventHandler(picMainDisplay_MouseClick);

            tmrHPAngleTimer.Tick += new EventHandler(tmrHPAngleTimer_Tick);
            tmrHPAngleTimer.Interval = 100;

            hsbAnimationDelayTime.ValueChanged += new EventHandler(hsbAnimationDelayTime_ValueChanged);
            hsbAngle.ValueChanged += new EventHandler(hsbAngle_ValueChanged);

            lstLimbEditDrawSequence.KeyDown += new KeyEventHandler(lstLimbEditDrawSequence_KeyDown);
            lstLimbEditDrawSequence.MouseWheel += new MouseEventHandler(lstLimbEditDrawSequence_MouseWheel);
            resetDrawingCenter();

            lstConLimbDrawSequence.KeyDown += new KeyEventHandler(lstConLimbDrawSequence_KeyDown);
            lstConLimbDrawSequence.MouseWheel += new MouseEventHandler(lstConLimbDrawSequence_MouseWheel);

            Disposed += new EventHandler(formBuildObject_Disposed);
            refreshTitle();
        }

        void hsbAngle_ValueChanged(object sender, EventArgs e)
        {
            dblAngle = ((double)hsbAngle.Value / (double)hsbAngle.Maximum) * (Math.PI * 2);
            putSpriteConfigurationOnScreen();
        }

        void lstConLimbDrawSequence_MouseWheel(object sender, MouseEventArgs e)
        {
            int intConfigIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);
            int intSel = lstConLimbDrawSequence.SelectedIndex;
            if (e.Delta < 0 && intSel < lstConLimbDrawSequence.Items.Count - 1)
            {
                lstLimbDrawSequence_Down(ref lstConLimbDrawSequence, ref udrConDrawSequence[intConfigIndex].Limb);
                intSel++;
            }
            else if (e.Delta > 0 && intSel > 0)
            {
                lstLimbDrawSequence_Up(ref lstConLimbDrawSequence, ref udrConDrawSequence[intConfigIndex].Limb);
                intSel--;
            }
            rebuildConLimbDrawSequence();
            resetSpriteConLimbDrawSeqToArray();
            putSpriteConfigurationOnScreen();
            lstConLimbDrawSequence.SelectedIndex = intSel;
        }
        void lstConLimbDrawSequence_KeyDown(object sender, KeyEventArgs e)
        {
            int intSel = lstConLimbDrawSequence.SelectedIndex;
            int intConfigIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);
            switch (e.KeyCode)
            {
                case Keys.Up:
                    lstLimbDrawSequence_Up(ref lstConLimbDrawSequence, ref udrConDrawSequence[intConfigIndex].Limb);
                    break;

                case Keys.Down:
                    lstLimbDrawSequence_Down(ref lstConLimbDrawSequence, ref udrConDrawSequence[intConfigIndex].Limb);
                    break;
            }
            rebuildConLimbDrawSequence();
            resetSpriteConLimbDrawSeqToArray();
            putSpriteConfigurationOnScreen();
            lstConLimbDrawSequence.SelectedIndex = intSel;
        }

        void lstLimbEditDrawSequence_MouseWheel(object sender, MouseEventArgs e)
        {
            int intSel = lstLimbEditDrawSequence.SelectedIndex;
            if (e.Delta < 0 && intSel < lstLimbEditDrawSequence.Items.Count - 1)
            {
                lstLimbDrawSequence_Down(ref lstLimbEditDrawSequence, ref strDrawSequence);
                intSel++;
            }
            else if (e.Delta > 0 && intSel > 0)
            {
                lstLimbDrawSequence_Up(ref lstLimbEditDrawSequence, ref strDrawSequence);
                intSel--;
            }
            rebuildLimbEditDrawSequence();
            resetLimbDrawSequenceToStringArray();
            PutSpriteOnScreen();
            lstLimbEditDrawSequence.SelectedIndex = intSel;
        }

        void resetLimbDrawSequenceToStringArray()
        {
            spriteMain.limbDrawSequence = new classSpriteLimb[0];
            for (int intLimbCounter = 0; intLimbCounter < strDrawSequence.Length; intLimbCounter++)
            {
                if (strDrawSequence[intLimbCounter].CompareTo(conDoNotDrawLimb) == 0)
                {
                    break;
                }
                else
                {
                    Array.Resize<classSpriteLimb>(ref spriteMain.limbDrawSequence, spriteMain.limbDrawSequence.Length + 1);
                    classSpriteLimb thisLimb = spriteMain.getLimbByName(strDrawSequence[intLimbCounter]);
                    if (thisLimb == null)
                        if (strDrawSequence[intLimbCounter].ToUpper().Trim().CompareTo(spriteMain.MasterLimb.Name.ToUpper().Trim())==0)
                            thisLimb = spriteMain.MasterLimb;
                    spriteMain.limbDrawSequence[spriteMain.limbDrawSequence.Length - 1] = thisLimb;
                }
            }
        }

      
        void lstLimbEditDrawSequence_KeyDown(object sender, KeyEventArgs e)
        {
            int intSel = lstLimbEditDrawSequence.SelectedIndex;
            switch (e.KeyCode)
            {
                case Keys.Up:
                    lstLimbDrawSequence_Up(ref lstLimbEditDrawSequence, ref strDrawSequence);
                    break;

                case Keys.Down:
                    lstLimbDrawSequence_Down(ref lstLimbEditDrawSequence, ref strDrawSequence);
                    break;
            }
            rebuildLimbEditDrawSequence();
            resetLimbDrawSequenceToStringArray();
            PutSpriteOnScreen();
            lstLimbEditDrawSequence.SelectedIndex = intSel;
        }

        void lstLimbDrawSequence_Down() { lstLimbDrawSequence_Down(ref lstLimbEditDrawSequence, ref strDrawSequence); }
        void lstLimbDrawSequence_Down(ref ListBox lstBox, ref string[] strDrawSeq)
        {
            int intSel = lstBox.SelectedIndex;
            if (intSel < lstBox.Items.Count - 1)
            {
                string strTemp = strDrawSeq[intSel + 1];
                strDrawSeq[intSel + 1] = strDrawSeq[intSel];
                strDrawSeq[intSel] = strTemp;
                lstBox.SelectedIndex = intSel;// +1;
            }
        }

        void lstLimbDrawSequence_Up() { }
        void lstLimbDrawSequence_Up(ref ListBox lstBox, ref string[] strDrawSeq)
        {
            int intSel = lstBox.SelectedIndex;
            if (intSel > 0)
            {
                string strTemp = strDrawSeq[intSel - 1];
                strDrawSeq[intSel - 1] = strDrawSeq[intSel];
                strDrawSeq[intSel] = strTemp;
                lstBox.SelectedIndex = intSel;// -1;
            }
        }

        void hsbAnimationDelayTime_ValueChanged(object sender, EventArgs e)
        {
            tmrAnimate.Interval = hsbAnimationDelayTime.Value;
        }

        void formBuildObject_SizeChanged(object sender, EventArgs e)
        {
            if (bolImageCentered)
            {
                resetDrawingCenter();
                PutSpriteOnScreen();
               
            }
            hsbAngle.Width = Width - hsbAngle.Left - 35;
            hsbAngle.Top = Height - hsbAngle.Height - 65;
        }

        void resetDrawingCenter()
        {
            ptDrawingCenter.X = picMainDisplay.Width - (picMainDisplay.Width - (grbConfigurationParameters.Left + grbConfigurationParameters.Width)) / 2;
            ptDrawingCenter.Y = (picMainDisplay.Height / 2);
            bolImageCentered = true;
        }

        void tmrHPAngleTimer_Tick(object sender, EventArgs e)
        {
            tmrHPAngleTimer.Enabled = false;
            HPAngleMouseSet();
        }

        void picMainDisplay_MouseClick(object sender, MouseEventArgs e)
        {

            switch (editMode)
            {
                case enuEditMode.EditHP:
                    switch (EditHPMode)
                    {
                        case enuEditHPMode.mouseSetHingeAngle:
                            editMode = enuEditMode.normal;
                            PutSpriteOnScreen();
                            break;
                    }
                    break;

                case enuEditMode.normal:
                    limbCurrentlySelected = limbPossibleNextSelection;
                    if (limbPossibleNextSelection != null)
                    {
                        hingeCurrentlySelected = limbPossibleNextSelection.MasterHinge;
                        if (hingeCurrentlySelected == null)
                            cmbHinges.Text = "";
                        else
                            setcmbHingesByName();
                    }
                    if (limbCurrentlySelected != null)
                    {
                        displayHingeParameters();
                        setCmbHPSelectedLimbByName();
                    }
                    if (grbConfigurationParameters.Visible)
                    {
                        setCmbConfigurationLimbByName();
                    }
                    break;

                case enuEditMode.EditConfiguration:
                    switch (EditConfigurationMode)
                    {
                        case enuEditConfigurationMode.normal:
                            catchSpriteConfiguration();
                            break;

                        case enuEditConfigurationMode.SetHingeRadialCoor:
                            break;
                    }

                    editMode = enuEditMode.normal;
                    break;
            }
        }

        void picMainDisplay_MouseMove(object sender, MouseEventArgs e)
        {
            ptMouse.X = e.X; ptMouse.Y = e.Y;
            //loadLimbDrawSequence();    
            switch (editMode)
            {
                case enuEditMode.EditHP:
                case enuEditMode.EditConfiguration:
                    switch (EditHPMode)
                    {
                        case enuEditHPMode.mouseSetHingeAngle:
                            HPAngleMouseSet();
                            break;
                    }
                    break;

                case enuEditMode.normal:
                    int intTolerance = 25;

                    if (spriteMain == null)
                        return;
                    Sprite.classSpriteLimb limbNext = null;

                    int dX, dY;
                    double dblDistanceFromMouse;
                    if (spriteMain != null && spriteMain.hinges != null && spriteMain.hinges.Length > 0)
                    {
                        for (int intHingeCounter = 0; intHingeCounter < spriteMain.hinges.Length; intHingeCounter++)
                        {
                            dX = ptMouse.X - spriteMain.hinges[intHingeCounter].Limb_Slave.Loc.X;
                            dY = ptMouse.Y - spriteMain.hinges[intHingeCounter].Limb_Slave.Loc.Y;
                            dblDistanceFromMouse = Math.Sqrt(dX * dX + dY * dY);

                            if (dblDistanceFromMouse < intTolerance)
                            {
                                limbNext = spriteMain.hinges[intHingeCounter].Limb_Slave;
                                //break;
                            }
                        }

                     
                    }
                    dX = ptMouse.X - spriteMain.MasterLimb.Loc.X;
                    dY = ptMouse.Y - spriteMain.MasterLimb.Loc.Y;
                    dblDistanceFromMouse = Math.Sqrt(dX * dX + dY * dY);

                    if (dblDistanceFromMouse < intTolerance)
                    {
                        limbNext = spriteMain.MasterLimb;
                        //break;
                    }

                    if (limbNext != limbPossibleNextSelection)
                    {
                        PutSpriteOnScreen();
                        if (limbNext != null)
                        {
                            Bitmap bmp = new Bitmap(picMainDisplay.Image);
                            using (Graphics g = Graphics.FromImage(bmp))
                            {
                                int intRadius = 2;
                                g.DrawEllipse(new Pen(Color.Black), limbNext.Loc.X - intRadius, limbNext.Loc.Y - intRadius, 2 * intRadius, 2 * intRadius);
                                intRadius = 3;
                                g.DrawEllipse(new Pen(Color.White), limbNext.Loc.X - intRadius, limbNext.Loc.Y - intRadius, 2 * intRadius, 2 * intRadius);

                            }
                            picMainDisplay.Image = bmp;

                            picMainDisplay.Refresh();
                        }
                    }

                    limbPossibleNextSelection = limbNext;
                    break;
            }
        }

        void setHPAngleTimer()
        {
            tmrHPAngleTimer.Enabled = false;
            tmrHPAngleTimer.Enabled = true;
        }

        void txtHPCurrentAngle_TextChanged(object sender, EventArgs e)
        {
            try
            {
                hingeCurrentlySelected.Angle = Convert.ToDouble(txtHPCurrentAngle.Text);
                PutSpriteOnScreen();
            }
            catch (Exception) { }
        }

        void txtHPSLimbRadMagnitude_TextChanged(object sender, EventArgs e)
        {
            try
            {
                hingeCurrentlySelected.RadCoor_Slave.radius = Convert.ToDouble(txtHPSLimbRadMagnitude.Text);
                PutSpriteOnScreen();
            }
            catch (Exception) { }
        }

        void txtHPDLimbRadMagnitude_TextChanged(object sender, EventArgs e)
        {
            try
            {
                hingeCurrentlySelected.RadCoor_Master.radius = Convert.ToDouble(txtHPDLimbRadMagnitude.Text);
                PutSpriteOnScreen();
            }
            catch (Exception) { }
        }

        void txtHPSLimbRadAngle_TextChanged(object sender, EventArgs e)
        {
            try
            {
                hingeCurrentlySelected.RadCoor_Slave.angle = Convert.ToDouble(txtHPSLimbRadAngle.Text);
                PutSpriteOnScreen();
            }
            catch (Exception) { }
        }

        void txtHPDLimbRadAngle_TextChanged(object sender, EventArgs e)
        {
            try
            {
                hingeCurrentlySelected.RadCoor_Master.angle = Convert.ToDouble(txtHPDLimbRadAngle.Text);
                PutSpriteOnScreen();
            }
            catch (Exception) { }
        }

        void formBuildObject_Disposed(object sender, EventArgs e)
        {
            bolDisposed = true;
        }

        void nudConfigurationStep_ValueChanged(object sender, EventArgs e)
        {
            //callingForm.drawObject(ref pnlWorkSpace, spriteMain, true);
            //rebuildConLimbDrawSequence();
            //try
            //{
            //    for (int intHingeCounter = 0;
            //         intHingeCounter < configurationCurrentlySelected.steps[(int)nudConfigurationStep.Value].hingeDetails.Length;
            //         intHingeCounter++)
            //        configurationCurrentlySelected
            //                .steps[(int)nudConfigurationStep.Value]
            //                .hingeDetails[intHingeCounter].hinge.Angle
            //                  = configurationCurrentlySelected
            //                                    .steps[(int)nudConfigurationStep.Value]
            //                                    .hingeDetails[intHingeCounter]
            //                                    .angle;
            //}
            //catch (Exception) { }
            displayHingeParameters();
            displayConfigurationParameters();
            putSpriteConfigurationOnScreen();
            //PutSpriteOnScreen();
        }

        void txtHPName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
                testValidHingeName();
        }
        void txtHPName_LostFocus(object sender, EventArgs e)
        { testValidHingeName(); }
        void testValidHingeName()
        {
            //for (int inthingeCounter = 0; inthingeCounter < spriteMain.hinges.Length; inthingeCounter++)
            //{
            //    if (inthingeCounter != intHingeCurrentlySelected)
            //        if (string.Compare(spriteMain.getNameFromCharArray(spriteMain.hinges[inthingeCounter].name).Trim().ToUpper(), txtHPName.Text.ToString().Trim().ToUpper()) == 0)
            //        {
            //            txtHPName.Text = spriteMain.getNameFromCharArray(spriteMain.hinges[intHingeCurrentlySelected].name);
            //            MessageBox.Show("A hinge named '" + txtBDName.Text.ToString().Trim() + "' already exists.  You must use unique hinge name", "hinge name previously used");
            //            return;
            //        }
            //}
            //spriteMain.hinges[intHingeCurrentlySelected].name = spriteMain.getNameFromString(txtHPName.Text.ToString()).ToCharArray();
            //rebuildHingeLst();
        }

        void testValidLimbName()
        {
            //for (int intBlockCounter = 0; intBlockCounter < spriteMain.blocks.Length; intBlockCounter++)
            //{
            //    if (intBlockCounter != intBlockCurrentlySelected)
            //        if (string.Compare(spriteMain.getNameFromCharArray(spriteMain.blocks[intBlockCounter].name).Trim().ToUpper(), txtBDName.Text.ToString().Trim().ToUpper()) == 0)
            //        {
            //            txtBDName.Text = spriteMain.getNameFromCharArray(spriteMain.blocks[intBlockCurrentlySelected].name);
            //            MessageBox.Show("A block named '" + txtBDName.Text.ToString().Trim() + "' already exists.  You must use unique block name", "block name previously used");
            //            return;
            //        }
            //}
            //spriteMain.blocks[intBlockCurrentlySelected].name = spriteMain.getNameFromString(txtBDName.Text.ToString()).ToCharArray();
            //rebuildLimbLst();
        }

        void txtConfigurationName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                configurationNameChange();
            }
        }

        void configurationNameChange()
        {
            if (!testValidConfigurationName(txtConfigurationName.Text))
            {
                MessageBox.Show("The new configurations's name must be original", "invalid configuration name", MessageBoxButtons.OK);
                txtConfigurationName.SelectAll();
                txtConfigurationName.Focus();
            }
            else
            {
                if (configurationCurrentlySelected != null)
                {
                    configurationCurrentlySelected.name = txtConfigurationName.Text.ToString();
                    rebuildConfigurationLst();
                }
            }
        }

        void txtConfigurationName_LostFocus(object sender, EventArgs e) { configurationNameChange(); }

        bool testValidConfigurationName(string strNewConfigurationName)
        {
            if (spriteMain.Configurations != null && spriteMain.Configurations.Length > 0)
            {

                for (int intConfigurationCounter = 0; intConfigurationCounter < spriteMain.Configurations.Length; intConfigurationCounter++)
                    if (configurationCurrentlySelected != spriteMain.Configurations[intConfigurationCounter])
                        if (spriteMain.Configurations[intConfigurationCounter].name != null && spriteMain.Configurations[intConfigurationCounter].name.Trim().ToUpper().CompareTo(strNewConfigurationName) == 0)
                            return false;
            }
            else
                return true;

            return true;
        }

        void reorderConfigurationAlphabetically()
        {
            //if (spriteMain.Configuration == null || spriteMain.Configuration.Length < 2)
            //    return;
            //int intBestIndex, intInnerLoop, intOuterLoop;
            //string strBestName, strThisName;
            //udtObjectConfiguration udtConTemp = new udtObjectConfiguration();
            //for (intOuterLoop = 0; intOuterLoop < spriteMain.Configuration.Length - 2; intOuterLoop++)
            //{
            //    intBestIndex = intOuterLoop;
            //    strBestName = spriteMain.getNameFromCharArray(spriteMain.Configuration[intOuterLoop].name.name );
            //    for (intInnerLoop = intOuterLoop + 1; intInnerLoop < spriteMain.Configuration.Length; intInnerLoop++)
            //    {
            //        strThisName = spriteMain.getNameFromCharArray(spriteMain.Configuration[intInnerLoop].name.name );
            //        if (string.Compare(strThisName, strBestName) < 0)
            //        {
            //            strBestName = strThisName;
            //            intBestIndex = intInnerLoop;
            //        }
            //    }
            //    if (intBestIndex != intInnerLoop)
            //    {
            //        udtConTemp = spriteMain.Configuration[intOuterLoop];
            //        spriteMain.Configuration[intOuterLoop] = spriteMain.Configuration[intBestIndex];
            //        spriteMain.Configuration[intBestIndex] = udtConTemp;
            //    }
            //}
        }

        // mouse enter labels
        void lblHPCurrentAngle_MouseEnter(object sender, EventArgs e)
        { handle_MouseEnterLabel(ref lblHPCurrentAngle); }

        // mouse leave labels
        void lblHPCurrentAngle_MouseLeave(object sender, EventArgs e)
        { handle_MouseEnterLabel(ref lblHPCurrentAngle); }

        // mouse click labels

        void lblHPCurrentAngle_MouseClick(object sender, MouseEventArgs e)
        {
            try
            { // shutting it off
                txtControlledByLabel.BackColor = Color.White;
                txtControlledByLabel.ForeColor = Color.Black;
            }
            catch (Exception) { }
            txtControlledByLabel = txtHPCurrentAngle;
            handle_MouseLabelClick();
        }

        void lblConfigurationImpactStep_MouseClick(object sender, MouseEventArgs e)
        {
            //spriteMain.Configuration[intConfigurationCurrentlySelected].intImpactCarryThoughStepNumber = (int)nudConfigurationStep.Value;
            //setImpactLabel(spriteMain.Configuration[intConfigurationCurrentlySelected].intImpactCarryThoughStepNumber);
        }

        // mouse move labels
        void lblHPCurrentAngle_MouseMove(object sender, MouseEventArgs e)
        {
            double dblX = MousePosition.X - this.Left - 5 - grbHingeParameters.Left - grbHPRange.Left - lblHPCurrentAngle.Left;
            dblControllingLabelFactor = dblX / (double)lblHPCurrentAngle.Width;
            handle_MouseMove();
            if (grbConfigurationParameters.Visible)
            {
                //try
                //{
                //    if (spriteMain.Configuration != null
                //        && spriteMain.Configuration[intConfigurationCurrentlySelected] != null
                //        && spriteMain.Configuration[intConfigurationCurrentlySelected].Step != null
                //        && spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value] != null
                //        && spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value].hingeDetails!= null
                //        && spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value].HingeDetail[intConfigurationHingeCurrentlySelected].intHingeIndex == intHingeCurrentlySelected)
                //    {
                //        spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value].HingeDetail[intConfigurationHingeCurrentlySelected].dblAngle = Convert.ToDouble(txtHPCurrentAngle.Text.ToString());
                //        displayConfigurationParameters();

                //    }
                //}
                //catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
        }

        // HANDLE MOUSE LABELS
        void handle_MouseLabelClick()
        {
            bolControlLabelOn = !bolControlLabelOn;

            if (bolControlLabelOn)
            { // turning it on
                Pen thisPen = new Pen(Color.FromArgb(txtControlledByLabel.BackColor.A, 254, 254, 254));
                txtControlledByLabel.BackColor = thisPen.Color;
                txtControlledByLabel.Focus();
            }
        }

        void handle_MouseLeaveLabel(ref Label thisLabel)
        {
            Color clrRememberBackColor = thisLabel.BackColor;
            thisLabel.BackColor = thisLabel.ForeColor;
            thisLabel.ForeColor = clrRememberBackColor;
            bolControlLabelOn = false;
        }

        void handle_MouseEnterLabel(ref Label thisLabel)
        {
            Color clrRememberBackColor = thisLabel.BackColor;
            thisLabel.BackColor = thisLabel.ForeColor;
            thisLabel.ForeColor = clrRememberBackColor;
        }

        void handle_MouseMove()
        {
            if (bolControlLabelOn)
            {
                double dblPrecision = Math.Pow(10, 4);
                double dblOldValue = 0;
                try { dblOldValue = Math.Floor(Convert.ToDouble(txtControlledByLabel.Text.ToString()) * dblPrecision) / dblPrecision; }
                catch (Exception) { }
                double dblNewValue = 0;
                if (dblOldValue != dblNewValue)
                {
                    txtControlledByLabel.Text = dblNewValue.ToString();
                    txtControlledByLabel.Refresh();
                    //if (testObject())
                    //    callingForm.drawObject(ref pnlWorkSpace, spriteMain, true);
                    //if (bolControlHP)
                    //    handle_SetHPValues();
                    //else
                    //    handle_SetBDValues();
                    //if (testObject())
                    //    callingForm.drawObject(ref pnlWorkSpace, spriteMain, false);
                }
            }
        }

        void handle_TxtMouseWheel(ref TextBox thisTextBox, MouseEventArgs e)
        {
            double dblCurrentValue = Convert.ToDouble(txtControlledByLabel.Text.ToString());

            byte G = txtControlledByLabel.BackColor.G;
            byte deltaG = 50;
            if (Math.Sign(e.Delta) > 0)
                if (G < 254 - deltaG)
                    G += deltaG;
                else
                    G = 254;
            else
                if (G > deltaG)
                    G -= deltaG;
                else
                    G = 0;
            Pen thisPen = new Pen(Color.FromArgb(txtControlledByLabel.BackColor.A, G, G, G));
            txtControlledByLabel.BackColor = thisPen.Color;
            txtControlledByLabel.ForeColor = (G < 200 ? Color.White : Color.Black);
            txtControlledByLabel.Refresh();

        }


        void setcmbHingesByName()
        {
            try
            {
                setcmbHingesByName(hingeCurrentlySelected.name);
            }
            catch (Exception)
            {
            }
        }
        void setcmbHingesByName(string strHingeName)
        {
            strHingeName = strHingeName.Trim().ToUpper();
            if (cmbHinges.Items.Count > 0)
                for (int intHingeCounter = 0; intHingeCounter < cmbHinges.Items.Count; intHingeCounter++)
                    if (cmbHinges.Items[intHingeCounter].ToString().Trim().ToUpper().CompareTo(strHingeName) == 0)
                    {
                        cmbHinges.SelectedIndex = intHingeCounter;
                        cmbHinges.Text = cmbHinges.Items[intHingeCounter].ToString();
                        return;
                    }
        }

        void setcmbLimbsByName() { setcmbLimbsByName(limbCurrentlySelected.Name); }
        void setcmbLimbsByName(string strLimbName)
        {
            strLimbName = strLimbName.Trim().ToUpper();
            if (cmbLimbs.Items.Count > 0)
                for (int intLimbCounter = 0; intLimbCounter < cmbLimbs.Items.Count; intLimbCounter++)
                    if (cmbLimbs.Items[intLimbCounter].ToString().Trim().ToUpper().CompareTo(strLimbName) == 0)
                    {
                        cmbLimbs.SelectedIndex = intLimbCounter;
                        cmbLimbs.Text = cmbLimbs.Items[intLimbCounter].ToString();
                        return;
                    }
        }

        void setCmbHPSelectedLimbByName() { setCmbHPSelectedLimbByName(limbCurrentlySelected.Name); }
        void setCmbHPSelectedLimbByName(string strLimbName)
        {
            if (bolIgnoreChangesToCmb)
                return;
            strLimbName = strLimbName.Trim().ToUpper();
            if (cmbLimbs.Items.Count > 0)
                for (int intLimbCounter = 0; intLimbCounter < cmbLimbs.Items.Count; intLimbCounter++)
                    if (cmbLimbs.Items[intLimbCounter].ToString().Trim().ToUpper().CompareTo(strLimbName) == 0)
                    {
                        cmbLimbs.SelectedIndex = intLimbCounter;
                        cmbLimbs.Text = cmbLimbs.Items[intLimbCounter].ToString();
                        return;
                    }
        }
        void setCmbConfigurationLimbByName()
        {
            if (limbCurrentlySelected != null)
                setCmbConfigurationLimbByName(limbCurrentlySelected.Name);
        }
        void setCmbConfigurationLimbByName(string strLimbName)
        {
            strLimbName = strLimbName.Trim().ToUpper();

            if (configurationCurrentlySelected != null)
            {
                //classSpriteLimb limThisLimb = spriteMain.getLimbByName(strLimbName);
                //if (MessageBox.Show("The limb \""
                //                    + limThisLimb.Name
                //                    + "\" is not currently part of the configuration \""
                //                    + configurationCurrentlySelected.name
                //                    + "\".\r\nDo you wish to add it?", "new configuration limb", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //{
                //    addLimbToConfiguration(limbCurrentlySelected);
                //}
            }
        }

        void cmbLimbs_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bolIgnoreChangesToCmb)
                return;
            string strLimbName = cmbLimbs.Text.Trim().ToUpper();
            limbCurrentlySelected = spriteMain.getLimbByName(strLimbName);
            if (limbCurrentlySelected == null)
                if (spriteMain.MasterLimb.Name.ToUpper().Trim().CompareTo(strLimbName) == 0)
                    limbCurrentlySelected = spriteMain.MasterLimb;

            hingeCurrentlySelected = limbCurrentlySelected.MasterHinge;
            displayHingeParameters();
            cmbLimbs.Text = cmbLimbs.Text.Trim();

            if (hingeCurrentlySelected != null)
                setcmbHingesByName();
        }

        //void cmbConfigurationAddHinge_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (bolIgnoreChangesToCmb)
        //        return;

        //    cmbConfigurationAddHinge.Visible = false;
        //    Sprite.classSpriteHinge selectedHinge = spriteMain.getHingeByName(cmbConfigurationAddHinge.Text.Trim());

        //    if (spriteMain.Configurations == null || spriteMain.Configurations.Length == 0)
        //    {
        //        MessageBox.Show("You must first create a new configuration.","no configurations exist", MessageBoxButtons.OK);
        //        return;
        //    }

        //    if (configurationCurrentlySelected == null)
        //    {
        //        MessageBox.Show("You must first select a configuration","no configuration selected", MessageBoxButtons.OK);
        //        return;
        //    }

        //    // test if already selected
        //    //if (configurationCurrentlySelected.steps == null)
        //    //{

        //    //    configurationCurrentlySelected.steps = new udtConfigurationStep[1];
        //    //    configurationCurrentlySelected.steps[(int)nudConfigurationStep.Value] = new udtConfigurationStep();
        //    //    configurationCurrentlySelected.steps[(int)nudConfigurationStep.Value].hingeDetails = new udtConfigurationStepHinge[1];
        //    //    configurationCurrentlySelected.steps[(int)nudConfigurationStep.Value].hingeDetails[0].hinge = selectedHinge;
        //    //    configurationCurrentlySelected.steps[(int)nudConfigurationStep.Value].hingeDetails[0].angle = selectedHinge.Angle;
        //    //    rebuildConLimbDrawSequence();
        //    //    return;
        //    //}
        //    //else
        //    addLimbToConfiguration(limbCurrentlySelected);
        //}

        void addLimbToConfiguration(classSpriteLimb selectedLimb)
        {
            if (configurationCurrentlySelected == null)
                return;
            if (configurationCurrentlySelected.LimbDrawSequence != null)
            {
                for (int intHingeCounter = 0; intHingeCounter < configurationCurrentlySelected.LimbDrawSequence.Length; intHingeCounter++)
                {
                    if (selectedLimb == configurationCurrentlySelected.LimbDrawSequence[intHingeCounter])
                    {
                        MessageBox.Show("That limb is already in the Current Configuration list", "error");
                        return;
                    }
                }
                Array.Resize<classSpriteLimb>(ref configurationCurrentlySelected.LimbDrawSequence, configurationCurrentlySelected.LimbDrawSequence.Length + 1);
                configurationCurrentlySelected.LimbDrawSequence[configurationCurrentlySelected.LimbDrawSequence.Length - 1] = selectedLimb;
            }
            else
            {
                configurationCurrentlySelected.LimbDrawSequence = new classSpriteLimb[1];
                configurationCurrentlySelected.LimbDrawSequence[0] = selectedLimb;
            }

            if (configurationCurrentlySelected.steps == null)
            {
                configurationCurrentlySelected.steps = new udtConfigurationStep[1];
                configurationCurrentlySelected.steps[0] = new udtConfigurationStep();
                configurationCurrentlySelected.steps[0].hingeDetails = new udtConfigurationStepHinge[0];
            }

            for (int intStepCounter = 0; intStepCounter < configurationCurrentlySelected.steps.Length; intStepCounter++)
            {
                Array.Resize<udtConfigurationStepHinge>(ref configurationCurrentlySelected.steps[intStepCounter].hingeDetails,
                                                        configurationCurrentlySelected.steps[intStepCounter].hingeDetails.Length + 1);
                configurationCurrentlySelected.steps[intStepCounter].hingeDetails
                                    [configurationCurrentlySelected.steps[intStepCounter].hingeDetails.Length - 1]
                                                                                .angle = selectedLimb.MasterHinge.Angle;
                configurationCurrentlySelected.steps[intStepCounter].hingeDetails
                                    [configurationCurrentlySelected.steps[intStepCounter].hingeDetails.Length - 1]
                                                                                .hinge = selectedLimb.MasterHinge;
            }

            rebuildConLimbDrawSequence();

            return;
        }

        void cmbHinges_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bolIgnoreChangesToCmb)
                return;
            string strHingeName = cmbHinges.Text;
            hingeCurrentlySelected = spriteMain.getHingeByName(strHingeName);
            limbCurrentlySelected = hingeCurrentlySelected.Limb_Slave;
            displayHingeParameters();

            bolIgnoreChangesToCmb = true;
            setcmbLimbsByName();
            bolIgnoreChangesToCmb = false;            
        }

        void cmbConfigurations_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bolIgnoreChangesToCmb)
                return;

            configurationCurrentlySelected = spriteMain.getConfigurationByName(cmbConfigurations.Text.Trim());
            txtConfigurationName.Text = configurationCurrentlySelected.name;
            setNudConfigurationStep();
            rebuildConLimbDrawSequence();
            displayConfigurationParameters();
            putSpriteConfigurationOnScreen();
        }

        private void mnuQuit_Click(object sender, EventArgs e) { this.Dispose(); }
        private void mnuOpenSprite_Click(object sender, EventArgs e)
        {
            OpenFileDialog OFD = new OpenFileDialog();
            OFD.Filter = "Graphic Files | *.spr";
            if (OFD.ShowDialog() == DialogResult.OK)
            {
                spriteMain = spriteMaker.loadSprite(OFD.FileName);
                loadLimbDrawSequence();
                PutSpriteOnScreen();
                resetFormContents();
            }
        }

        private void setNudConfigurationStep()
        {
            try
            {
                if (configurationCurrentlySelected.steps.Length > 0)
                    nudConfigurationStep.Maximum = configurationCurrentlySelected.steps.Length - 1;
                else
                    nudConfigurationStep.Maximum = 0;
            }
            catch (Exception) { nudConfigurationStep.Maximum = 0; }
            nudConfigurationStep.Value = 0;
        }

        

        private void mnuNewObject_Click(object sender, EventArgs e)
        {

        //    picImageLoader = new PictureBox();
        //startNewObject:
        //    OpenFileDialog ofd = new OpenFileDialog();
        //    if (ofd.ShowDialog() == DialogResult.OK)
        //    {
        //        picImageLoader.Load(ofd.FileName);

        //        string strReply = conNo;
        //        classMessageBox msgbox = new classMessageBox("Does this sprite rotate?", "Rotate?", conYes, conNo, conCancel);
        //        msgbox.addImage(picImageLoader.Image);
        //        msgbox.Owner = this;
        //        msgbox.ShowDialog();
        //        strReply = msgbox.Reply;
        //        msgbox.Dispose();
        //        if (strReply.CompareTo(conCancel) == 0)
        //            return;
        //        bool bolRotate = (strReply.CompareTo(conYes) == 0);

        //        bool bolAlwaysVertical = false;
        //        if (bolRotate)
        //        {
        //            classMessageBox msgbox = new classMessageBox("Does this sprite remain vertical when it rotates?", "Always vertical?", conYes, conNo, conCancel);
        //            msgbox.addImage(picImageLoader.Image);
        //            msgbox.Owner = this;
        //            msgbox.ShowDialog();
        //            strReply = msgbox.Reply;
        //            msgbox.Dispose();
        //            if (strReply.CompareTo(conCancel) == 0)
        //                return;
        //            bolAlwaysVertical = (strReply.CompareTo(conYes) == 0);
        //        }

        //        string strName = "";
        //        while (strName.Length == 0)
        //        {
        //            classMessageBox msgbox = new classMessageBox("What do you want to call this sprite?", "Name of sprite", conOK, conCancel);
        //            msgbox.showTextBox("new sprite");
        //            msgbox.Owner = this;
        //            msgbox.ShowDialog();
        //            strReply = msgbox.Reply;
        //            strName = msgbox.txt.Text;
        //            msgbox.Dispose();

        //            if (strReply == null || strReply.CompareTo(conCancel) == 0)
        //                return;
        //            if (strName.Length == 0)
        //                MessageBox.Show("please enter a name for your sprite");
        //        }

        //        string strNameMasterLimb = "";
        //        while (strNameMasterLimb.Length == 0)
        //        {
        //            classMessageBox msgbox = new classMessageBox("What is the name of this part of your sprite?, e.g. 'torso'", "Name of master limb", conOK, conCancel);
        //            msgbox.showTextBox("master limb");
        //            msgbox.Owner = this;
        //            msgbox.ShowDialog();
        //            strReply = msgbox.Reply;
        //            strNameMasterLimb = msgbox.txt.Text;
        //            msgbox.Dispose();

        //            if (strReply == null || strReply.CompareTo(conCancel) == 0)
        //                return;
        //            if (strNameMasterLimb.Length == 0)
        //                MessageBox.Show("please enter a name for your sprite's master limb.");
        //        }
            formNewSprite frmNewSprite = new formNewSprite();
            frmNewSprite.Owner = this;

            frmNewSprite.ShowDialog();

            if(frmNewSprite.udrNewSpriteInfo.flag)
            {   
                resetDrawingCenter();
                spriteMain = spriteMaker.getSprite( frmNewSprite.udrNewSpriteInfo.rotate, frmNewSprite.udrNewSpriteInfo.alwaysVertical , frmNewSprite.udrNewSpriteInfo.name , frmNewSprite.udrNewSpriteInfo.MasterLimbName, frmNewSprite.udrNewSpriteInfo.bmpMasterLimb);
                picImageLoader.Dispose();
                editMode = enuEditMode.normal;
                grbConfigurationParameters.Visible = false;
                spriteMain.limbDrawSequence = new classSpriteLimb[1];
                spriteMain.limbDrawSequence[0] = spriteMain.MasterLimb;
                initStrDrawSequence();
                PutSpriteOnScreen();
                resetFormContents();
            }
        }

        private void initConLimbDrawSequence()
        {
            int intConfigIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);
            Array.Resize<udtDrawSequence>(ref udrConDrawSequence, spriteMain.Configurations.Length);
            udrConDrawSequence[intConfigIndex] = new udtDrawSequence();
            udrConDrawSequence[intConfigIndex].Limb = new string[strDrawSequence.Length];
            for (int intLimbCounter = 0; intLimbCounter < strDrawSequence.Length; intLimbCounter++)
                udrConDrawSequence[intConfigIndex].Limb[intLimbCounter] = strDrawSequence[intLimbCounter];
        }

        private void initStrDrawSequence()
        {
            strDrawSequence = new string[2];
            strDrawSequence[0] = spriteMain.MasterLimb.Name;
            strDrawSequence[1] = conDoNotDrawLimb;
            rebuildLimbEditDrawSequence();
        }

        private void addLimbToDrawSequence(classSpriteLimb thisLimb)
        {
            Array.Resize<classSpriteLimb>(ref spriteMain.limbDrawSequence, spriteMain.limbDrawSequence.Length + 1);
            spriteMain.limbDrawSequence[spriteMain.limbDrawSequence.Length - 1] = thisLimb;

            Array.Resize<string>(ref strDrawSequence, spriteMain.hinges.Length + 2);
            if (spriteMain.limbDrawSequence.Length > 1)
            {
                for (int intLimbCounter = strDrawSequence.Length - 2; intLimbCounter >= 0; intLimbCounter--)
                {
                    strDrawSequence[intLimbCounter + 1] = strDrawSequence[intLimbCounter];
                    if (strDrawSequence[intLimbCounter]!=null 
                        && strDrawSequence[intLimbCounter].CompareTo(conDoNotDrawLimb) == 0)
                    {
                        strDrawSequence[intLimbCounter] = thisLimb.Name;
                        break;
                    }
                }
            }
            rebuildLimbEditDrawSequence();

            // do the same for all udrConDrawSequences
            if (spriteMain.Configurations != null)
                for (int intConfigCounter = 0; intConfigCounter < spriteMain.Configurations.Length; intConfigCounter++)
                {
                    Array.Resize<string>(ref udrConDrawSequence[intConfigCounter].Limb, udrConDrawSequence[intConfigCounter].Limb.Length + 1);
                    udrConDrawSequence[intConfigCounter].Limb[udrConDrawSequence[intConfigCounter].Limb.Length - 1] = thisLimb.Name;
                }

        }

        private void loadLimbDrawSequence()
        {
            strDrawSequence = new string[spriteMain.hinges.Length + 2];
            string strTest = ".";
            for (int intLimbCounter = 0; intLimbCounter < spriteMain.limbDrawSequence.Length; intLimbCounter++)
            {
                try
                {
                    strDrawSequence[intLimbCounter] = spriteMain.limbDrawSequence[intLimbCounter].Name;
                    strTest += spriteMain.limbDrawSequence[intLimbCounter].Name.ToUpper().Trim() + ".";
                }
                catch (Exception) { }
            }

            int intNumDrawLimbs = spriteMain.limbDrawSequence.Length;
            strDrawSequence[intNumDrawLimbs] = conDoNotDrawLimb;

            int intNumNotDrawn = 0;
            for (int intHingeCounter = 0; intHingeCounter < spriteMain.hinges.Length; intHingeCounter++)
            {
                string strThisLimb = "." + spriteMain.hinges[intHingeCounter].Limb_Slave.Name.ToUpper().Trim() + ".";
                if (!strTest.Contains(strThisLimb))
                {
                    strDrawSequence[intNumDrawLimbs+ ++intNumNotDrawn] = spriteMain.hinges[intHingeCounter].Limb_Slave.Name;
                }
            }

            if (!strTest.Contains("." + spriteMain.MasterLimb.Name.ToString().ToUpper().Trim() + "."))
                strDrawSequence[intNumDrawLimbs + ++intNumNotDrawn] = spriteMain.MasterLimb.Name;
            
            // load limbdrawsequences for each configuration
            if (spriteMain.Configurations != null)
            {
                udrConDrawSequence = new udtDrawSequence[spriteMain.Configurations.Length];
                for (int intConCounter = 0; intConCounter < spriteMain.Configurations.Length; intConCounter++)
                {
                    udrConDrawSequence[intConCounter].Limb = new string[spriteMain.hinges.Length + 2];
                    string strConTest = ".";
                    string strDrawnLimbs = ".";
                    for (int intLimbCounter = 0; intLimbCounter < spriteMain.Configurations[intConCounter].LimbDrawSequence.Length; intLimbCounter++)
                    {
                        if (spriteMain.Configurations[intConCounter].LimbDrawSequence[intLimbCounter].Name == null)
                        {
                        }
                        string strThisLimbName = spriteMain.Configurations[intConCounter].LimbDrawSequence[intLimbCounter].Name.Trim();
                        strDrawnLimbs += strThisLimbName.ToUpper() + ".";
                        udrConDrawSequence[intConCounter].Limb[intLimbCounter] = strThisLimbName;
                        strConTest += spriteMain.Configurations[intConCounter].LimbDrawSequence[intLimbCounter].Name.ToUpper().Trim() + ".";
                    }

                    int intConNumDrawLimbs = spriteMain.Configurations[intConCounter].LimbDrawSequence.Length;
                    udrConDrawSequence[intConCounter].Limb[intConNumDrawLimbs] = conDoNotDrawLimb;
                    if (intConNumDrawLimbs < udrConDrawSequence[intConCounter].Limb.Length - 1)
                    {
                        int intLimbNotDrawnIndex = intConNumDrawLimbs + 1;
                        for (int intLimbCounter = 0; intLimbCounter < spriteMain.hinges.Length; intLimbCounter++)
                        {
                            string strThisLimbName = spriteMain.hinges[intLimbCounter].Limb_Slave.Name.ToString().ToUpper().Trim();
                            if (!strDrawnLimbs.Contains("." + strThisLimbName + "."))
                            {
                                udrConDrawSequence[intConCounter].Limb[intLimbNotDrawnIndex++] = spriteMain.hinges[intLimbCounter].Limb_Slave.Name.ToString().Trim();
                                strDrawnLimbs += spriteMain.hinges[intLimbCounter].Limb_Slave.Name.ToString().ToUpper().Trim() + ".";
                            }
                        }

                        if (!strDrawnLimbs.Contains("." + spriteMain.MasterLimb.Name.ToString().Trim().ToUpper() + "."))
                            udrConDrawSequence[intConCounter].Limb[intLimbNotDrawnIndex++] = spriteMain.MasterLimb.Name.ToString().Trim();


                    }

                    //int intConNumNotDrawn = 0;
                    //for (int intHingeCounter = 0; intHingeCounter < spriteMain.hinges.Length; intHingeCounter++)
                    //{
                    //    string strThisLimb = "." + spriteMain.hinges[intHingeCounter].Limb_Slave.Name.ToUpper().Trim() + ".";
                    //    if (!strConTest.Contains(strThisLimb))
                    //    {
                    //        udrConDrawSequence[intConCounter].Limb[++intConNumNotDrawn] = spriteMain.hinges[intHingeCounter].Limb_Slave.Name;
                    //    }
                    //}
                }
            }
            rebuildLimbEditDrawSequence();
        }

        private void mnuSaveSprite_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "sprites |*.spr";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string strFilename = sfd.FileName;
                int intcutchr = strFilename.IndexOf(".");
                if (intcutchr > 0)
                    strFilename = strFilename.Substring(0, intcutchr);
                strFilename += ".spr";
                spriteMaker.saveSprite(ref spriteMain, strFilename);
            }
        }

        //private void refreshDisplay()
        //{
        //    spriteMain.blocks[spriteMain.udrData.intIndexMasterBlock].udrMapPos.Pos.x = ptDrawingCenter.X;
        //    spriteMain.blocks[spriteMain.udrData.intIndexMasterBlock].udrMapPos.Pos.y = ptDrawingCenter.Y;
        //    if (testObject())
        //        callingForm.drawObject(ref pnlWorkSpace, spriteMain);
        //    if (grbBlockDimensions.Visible)
        //        displayBlockDimensions();
        //    if (grbHingeParameters.Visible)
        //        displayHingeParameters();
        //}

        private void displayConfigurationParameters()
        {
            //    if (spriteMain.Configuration == null)
            //    {
            //        MessageBox.Show("no Configurations exist", "Configuration error");
            //        return;
            //    }
            //    if (intConfigurationCurrentlySelected < 0 || intConfigurationCurrentlySelected > spriteMain.Configuration.Length)
            //    {
            //        MessageBox.Show("invalid selection", "Configuration selection error");
            //        return;
            //    }
            //    lblConfigurationName.Text = "(" + intConfigurationCurrentlySelected.ToString() + ")";
            //    txtConfigurationName.Text = spriteMain.getNameFromCharArray(spriteMain.Configuration[intConfigurationCurrentlySelected].name.name );
            //    if (spriteMain.Configuration[intConfigurationCurrentlySelected].Step != null)
            //        if (spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value] != null)
            //            if (spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value].hingeDetails!= null)
            //                try { lblConfigurationHingeAngle.Text = "angle : " + spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value].HingeDetail[intConfigurationHingeCurrentlySelected].dblAngle.ToString(); }
            //                catch (Exception) { lblConfigurationHingeAngle.Text = "angle : "; }
            //    setImpactLabel(spriteMain.Configuration[intConfigurationCurrentlySelected].intImpactCarryThoughStepNumber);
            //    try { nudConfigurationImpactMaximum.Value = (decimal)spriteMain.Configuration[intConfigurationCurrentlySelected].dblMaximumImpactForce; }
            //    catch (Exception) { nudConfigurationImpactMaximum.Value = nudConfigurationImpactMaximum.Minimum; }
            //    try { nudConfigurationImpactStepPercentage.Value = (decimal)spriteMain.Configuration[intConfigurationCurrentlySelected].steps[(int)nudConfigurationStep.Value].dblPercentImpactForce; }
            //    catch (Exception) { }
        }

        void rebuildConLimbDrawSequence()
        {
            if (spriteMain == null)
            {
                MessageBox.Show("No object in memory", "error");
                return;
            }
            if (spriteMain.Configurations == null)
            {
                //MessageBox.Show("No configurations listed", "error");
                return;
            }
            if (configurationCurrentlySelected == null)
                return;

            if (udrConDrawSequence == null || udrConDrawSequence.Length == 0)
                return;

            int intConIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);

            lstConLimbDrawSequence.Items.Clear();
            //loadLimbDrawSequence();
            for (int intLimbCounter = 0; intLimbCounter < udrConDrawSequence[intConIndex].Limb.Length; intLimbCounter++)
                lstConLimbDrawSequence.Items.Add(udrConDrawSequence[intConIndex].Limb[intLimbCounter]);
        }

        private void resetFormContents()
        {
            double dblZero = 0;
            string strZero = dblZero.ToString("f3");

            txtConfigurationName.Text = "";
            txtHPCurrentAngle.Text = strZero;

            txtHPDLimbRadAngle.Text = strZero;
            txtHPDLimbRadMagnitude.Text = strZero;

            txtHPSLimbRadAngle.Text = strZero;
            txtHPSLimbRadMagnitude.Text = strZero;

            if (spriteMain == null)
            {
                limbCurrentlySelected = null;
                hingeCurrentlySelected = null;
                configurationCurrentlySelected = null;
            }
            else
            {
                if (spriteMain.hinges != null && spriteMain.hinges.Length > 0)
                {
                    hingeCurrentlySelected = spriteMain.hinges[0];
                    limbCurrentlySelected = spriteMain.hinges[0].Limb_Slave;
                    displayHingeParameters();
                }
                else
                    hingeCurrentlySelected = null;

                if (spriteMain.Configurations != null && spriteMain.Configurations.Length > 0)
                    configurationCurrentlySelected = spriteMain.Configurations[0];
                else
                    configurationCurrentlySelected = null;
            }

            rebuildConfigurationLst();
            rebuildConLimbDrawSequence();
            rebuildHingeLst();
            rebuildLimbLst();
        }

        private void displayHingeParameters()
        {
            if (limbCurrentlySelected == spriteMain.MasterLimb)
                return;

            if (spriteMain.hinges == null)
            {
                MessageBox.Show("no hinges exist", "hinge error");
                return;
            }

            if (hingeCurrentlySelected == null)
            {
                MessageBox.Show("invalid selection", "hinge selection error");
                return;
            }

            grbHingeParameters.Text = hingeCurrentlySelected.name.ToString().Trim() + " hinge";
            grbHPDominantLimb.Text = hingeCurrentlySelected.Limb_Master.Name.ToString().Trim();
            grbHPSubmissiveLimb.Text = hingeCurrentlySelected.Limb_Slave.Name.ToString().Trim();

            txtHPDLimbRadAngle.Text = hingeCurrentlySelected.RadCoor_Master.angle.ToString("f3");
            txtHPDLimbRadMagnitude.Text = hingeCurrentlySelected.RadCoor_Master.radius.ToString("f3");

            txtHPSLimbRadAngle.Text = hingeCurrentlySelected.RadCoor_Slave.angle.ToString("f3");
            txtHPSLimbRadMagnitude.Text = hingeCurrentlySelected.RadCoor_Slave.radius.ToString("f3");
        }

        //private void mnuHingesShowParameters_Click(object sender, EventArgs e)
        //{
        //    grbHingeParameters.Visible = !grbHingeParameters.Visible;
        //    grbHingeParameters.BringToFront();
        //    grbHingeParameters.Left = 5;
        //    grbHingeParameters.Top = 45;
        //    rebuildHingeLst();
        //    rebuildLimbLst();
        //    PutSpriteOnScreen();
        //}
        
        private void mnuLimbsCreateNew_Click(object sender, EventArgs e)
        {  
            if (limbCurrentlySelected == null)
            {
                MessageBox.Show("you must first select a limb onto which this new limb will be attached.");
                return;
            }
        
            formNewLimb frmNewLimb = new formNewLimb(ref spriteMain, ref limbCurrentlySelected);
            frmNewLimb.Owner = this;
            frmNewLimb.ShowDialog();

            if (frmNewLimb.udrNewLimbInfo.flag)
            {
                Sprite.classSpriteLimb limbNew = new classSpriteLimb(ref spriteMain, frmNewLimb.udrNewLimbInfo.rotate, frmNewLimb.udrNewLimbInfo.alwaysVertical, frmNewLimb.udrNewLimbInfo.name, frmNewLimb.udrNewLimbInfo.bmpBaseImage);
                limbCurrentlySelected.addLimb(limbNew, frmNewLimb.udrNewLimbInfo.hingeName, new classMath.classRadialCoor(0, 0), new classMath.classRadialCoor(0, 0));

                addLimbToDrawSequence(limbNew);
                resetSpriteConLimbDrawSeqToArray();
                rebuildConLimbDrawSequence();
                rebuildLimbEditDrawSequence();
                picImageLoader.Dispose();

                PutSpriteOnScreen();
                rebuildLimbLst();
                rebuildHingeLst();

                cmbLimbs.SelectedIndex = cmbLimbs.Items.Count - 1;
                cmbHinges.SelectedIndex = cmbHinges.Items.Count - 1;
            }

        }

        private void mnuLimbsLoadNewBaseImage_Click(object sender, EventArgs e)
        {
            if (limbCurrentlySelected == null)
            {
                MessageBox.Show("You must first select a limb from the limb's combo box", "no limb selected", MessageBoxButtons.OK);
                return;
            }
            classSpriteLimb thisLimb = spriteMain.getLimbByName(limbCurrentlySelected.Name);
            if (thisLimb == null)
                if (limbCurrentlySelected == spriteMain.MasterLimb)
                    thisLimb = spriteMain.MasterLimb;
                else
                    return;
            string strReply = "";
            classMessageBox msgbox = new classMessageBox("Are you sure you want to change the base image of this limb \"" + thisLimb.Name + "\"?", "Load new image?", conYes, conNo);
            msgbox.Owner = this;
            msgbox.addImage(thisLimb.udrSpriteLimbImages[0].bmp);
            msgbox.txt.Focus();
            msgbox.ShowDialog();
            strReply = msgbox.Reply;
            msgbox.Dispose();

            if (strReply == null || strReply.CompareTo(conNo) == 0)
                return;

            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                PictureBox picTemp = new PictureBox();
                picTemp.Load(ofd.FileName);
                msgbox = new classMessageBox("Is this the new image you want for the limb \"" + thisLimb.Name + "\"?", "Correct image?", conYes, conNo);
                msgbox.Owner = this;
                msgbox.addImage(picTemp.Image);
                msgbox.txt.Focus();
                msgbox.ShowDialog();
                strReply = msgbox.Reply;
                msgbox.Dispose();

                if (strReply == null || strReply.CompareTo(conNo) == 0)
                    return;

                Bitmap[] bmpOriginal = new Bitmap[1];
                bmpOriginal[0] = new Bitmap(picTemp.Image);
                //cLibPicBoxViewer pic2 = new cLibPicBoxViewer(bmpOriginal[0],"new arm");

                thisLimb.initImages(bmpOriginal);
                PutSpriteOnScreen();
            }

        }

        private void mnuLimbsDelete_Click(object sender, EventArgs e)
        {
            if (limbCurrentlySelected == null)
            {
                MessageBox.Show("You must first select a limb from the limb's combo box", "no limb selected", MessageBoxButtons.OK);
                return;
            }
            string strReply = "";
            classMessageBox msgbox = new classMessageBox("Are you sure you want to delete this limb \"" + limbCurrentlySelected.Name + "\"?", "Delete Limb?", conYes, conNo);
            msgbox.Owner = this;
            msgbox.addImage(limbCurrentlySelected.udrSpriteLimbImages[0].bmp);
            msgbox.txt.Focus();
            msgbox.ShowDialog();
            strReply = msgbox.Reply;
            msgbox.Dispose();

            if (strReply == null || strReply.CompareTo(conNo) == 0)
                return;

            deleteLimbRecursion(limbCurrentlySelected);
            // now clean up all limbs & hinges marked for deletiong (bolFlag == false)
            int intHinges = 0;
            for (int intHingeCounter = 0; intHingeCounter < spriteMain.hinges.Length; intHingeCounter++)
            {
                spriteMain.hinges[intHinges] = spriteMain.hinges[intHingeCounter];

                if (spriteMain.hinges[intHingeCounter].bolFlag)
                    intHinges++;
            }
            if (intHinges > 0)
                Array.Resize<classSpriteHinge>(ref spriteMain.hinges, intHinges);
            else
                spriteMain.hinges = null;
            PutSpriteOnScreen();

            // remove this limb from all drawSequence arrays
            removeLimbFromDrawSequence(ref spriteMain.limbDrawSequence, limbCurrentlySelected);
            rebuildLimbEditDrawSequence();
            if (spriteMain.Configurations != null)
            {
                for (int intConfigCounter = 0; intConfigCounter < spriteMain.Configurations.Length; intConfigCounter++)
                    removeLimbFromDrawSequence(ref spriteMain.Configurations[intConfigCounter].LimbDrawSequence, limbCurrentlySelected);
                rebuildConLimbDrawSequence();
            }
            rebuildConLimbDrawSequence();
            rebuildConfigurationLst();
            rebuildHingeLst();
            rebuildLimbLst();
            loadLimbDrawSequence();
        }

        private void removeLimbFromDrawSequence(ref classSpriteLimb[] thisSequence, classSpriteLimb thisLimb)
        {
            int intOffset = 0;
            for (int intLimbCounter = 0; intLimbCounter < thisSequence.Length- intOffset ; intLimbCounter++)
            {
                if (thisSequence[intLimbCounter] == thisLimb)
                    intOffset = 1;
                if (intLimbCounter < thisSequence.Length - intOffset)
                    thisSequence[intLimbCounter] = thisSequence[intLimbCounter + intOffset];
            }
            Array.Resize<classSpriteLimb>(ref thisSequence, thisSequence.Length - intOffset);
        }

        private void deleteLimbRecursion(classSpriteLimb thisLimb)
        {
            for (int intLimbCounter = 0; thisLimb.mySlaveLimbs != null && intLimbCounter < thisLimb.mySlaveLimbs.Length; intLimbCounter++)
                deleteLimbRecursion(thisLimb.mySlaveLimbs[intLimbCounter]);

            classSpriteLimb masterLimb = thisLimb.MasterHinge.Limb_Master;

            int intNumLimbs = 0;
            for (int intLimbCounter = 0; intLimbCounter < masterLimb.mySlaveLimbs.Length; intLimbCounter++)
            {
                masterLimb.mySlaveLimbs[intNumLimbs] = masterLimb.mySlaveLimbs[intLimbCounter];
                if (masterLimb.mySlaveLimbs[intLimbCounter] != thisLimb)
                    intNumLimbs++;
            }
            if (intNumLimbs > 0)
                Array.Resize<classSpriteLimb>(ref masterLimb.mySlaveLimbs, intNumLimbs);
            else
                masterLimb.mySlaveLimbs = null;

            thisLimb.bolFlag = false;
            thisLimb.MasterHinge.bolFlag = false;
        }

        private void rebuildLimbLst()
        {
            cmbLimbs.Items.Clear();
            int intRememberIndexSelectedLimbs = cmbLimbs.SelectedIndex;

            if (spriteMain == null || spriteMain.hinges == null)
            {
                cmbLimbs.Text = "";
                return;
            }

            cmbLimbs.Items.Add(spriteMain.MasterLimb.Name);

            for (int intHingeCounter = 0; intHingeCounter < spriteMain.hinges.Length; intHingeCounter++)
            {
                string strName = spriteMain.hinges[intHingeCounter].Limb_Slave.Name.ToString().Trim();
                cmbLimbs.Items.Add(strName);
            }
            if (intRememberIndexSelectedLimbs >= 0)
            {
                if (intRememberIndexSelectedLimbs < cmbLimbs.Items.Count)
                    cmbLimbs.Text = cmbLimbs.Items[intRememberIndexSelectedLimbs].ToString();
                else if (cmbLimbs.Items.Count > 0)
                    cmbLimbs.Text = cmbLimbs.Items[0].ToString();
                else
                    cmbLimbs.Text = "";
            }
            else
                cmbLimbs.Text = "";

            //cmbLimbs.BringToFront();
        }

        private void rebuildHingeLst()
        {
            int intRememberHingeSelected = cmbHinges.SelectedIndex;

            cmbHinges.Items.Clear();
            if (spriteMain != null)
                if (spriteMain.hinges != null)
                {
                    for (int intHingeCounter = 0; intHingeCounter < spriteMain.hinges.Length; intHingeCounter++)
                    {
                        string strTemp = spriteMain.hinges[intHingeCounter].name.Trim();
                        cmbHinges.Items.Add(strTemp);
                    }
                    cmbHinges.Text = "";
                    if (intRememberHingeSelected >= 0)
                    {
                        if (cmbHinges.Items.Count > intRememberHingeSelected)
                            cmbHinges.Text = cmbHinges.Items[intRememberHingeSelected].ToString();
                        else if (cmbHinges.Items.Count > 0)
                            cmbHinges.Text = cmbHinges.Items[0].ToString();
                    }
                }
        }

        private void rebuildConfigurationLst()
        {
            cmbConfigurations.Items.Clear();
            if (spriteMain != null)
            {
                if (spriteMain.hinges != null && spriteMain.Configurations != null)
                {
                    int intSelectedIndex = 0;
                    for (int intConfigurationCounter = 0; intConfigurationCounter < spriteMain.Configurations.Length; intConfigurationCounter++)
                    {
                        cmbConfigurations.Items.Add(spriteMain.Configurations[intConfigurationCounter].name.Trim());
                        if (spriteMain.Configurations[intConfigurationCounter].name.Trim().ToUpper().CompareTo(txtConfigurationName.Text.ToString().Trim().ToUpper()) == 0)
                            intSelectedIndex = intConfigurationCounter;
                    }

                    if (cmbConfigurations.Items.Count > 0)
                        cmbConfigurations.Text = cmbConfigurations.Items[intSelectedIndex].ToString();
                    else
                        cmbConfigurations.Text = "";
                }
                else
                    cmbConfigurations.Text = "";
            }
        }

        private void mnuConfigurationShowParameters_Click(object sender, EventArgs e)
        {
            if (grbConfigurationParameters.Visible)
            {
                grbConfigurationParameters.Visible = false;
                configurationCurrentlySelected = null;
                return;
            }
            if (spriteMain == null)
            {
                MessageBox.Show("You must first create or load a sprite into memory", "No sprite loaded", MessageBoxButtons.OK);
                return;
            }

            if (spriteMain.Configurations == null || spriteMain.Configurations.Length == 0)
            {
                MessageBox.Show("You must first create a configuration", "no configurations", MessageBoxButtons.OK);
                return;
            }

            grbConfigurationParameters.Visible = !grbConfigurationParameters.Visible;
            grbConfigurationParameters.BringToFront();
            //cmbConfigurations.BringToFront();
            rebuildConfigurationLst();
            rebuildConLimbDrawSequence();
        }

        private void mnuConfigurationCreateNew_Click(object sender, EventArgs e)
        {
            if (spriteMain == null)
            {
                MessageBox.Show("There is no object loaded", "error");
                return;
            }

            if (spriteMain.Configurations == null)
                spriteMain.Configurations = new classConfiguration[0];

            Array.Resize<classConfiguration>(ref spriteMain.Configurations, spriteMain.Configurations.Length + 1);
            spriteMain.Configurations[spriteMain.Configurations.Length - 1] = new classConfiguration();

            string strNewConfigurationName = "New Configuration #";
            string strTestName = "";
            int intNameCounter = 0;
            do
            {
                intNameCounter++;
                strTestName = strNewConfigurationName + intNameCounter.ToString();
            } while (!testValidConfigurationName(strTestName));

            spriteMain.Configurations[spriteMain.Configurations.Length - 1].name = strTestName;
            txtConfigurationName.Text = spriteMain.Configurations[spriteMain.Configurations.Length - 1].name.Trim();

            configurationCurrentlySelected = spriteMain.Configurations[spriteMain.Configurations.Length - 1];

            grbConfigurationParameters.Visible = true;
            setNudConfigurationStep();
            initConLimbDrawSequence();
            resetSpriteConLimbDrawSeqToArray();
            rebuildConLimbDrawSequence();
            rebuildConfigurationLst();

            configurationCurrentlySelected.steps = new udtConfigurationStep[0];
            nudConfigurationStep.Maximum = -1;
            AddStepToConfiguration();
            catchSpriteConfiguration();

            txtConfigurationName.SelectAll();
            txtConfigurationName.Focus();
        }

        private void btnConfigurationStepAdd_Click(object sender, EventArgs e)
        {
            nudConfigurationStep.Minimum = 0;
            if (spriteMain == null)
            {
                MessageBox.Show("There is no object in memory", "error");
                return;
            }
            if (spriteMain.Configurations == null)
            {
                MessageBox.Show("There is no configuration in memory", "error");
                return;
            }

            if (configurationCurrentlySelected == null)
            {
                MessageBox.Show("Current configuration selection error", "erro");
                return;
            }
            AddStepToConfiguration();

        }

        void AddStepToConfiguration()
        {
            Array.Resize<Sprite.udtConfigurationStep>(ref configurationCurrentlySelected.steps, configurationCurrentlySelected.steps.Length + 1);

            nudConfigurationStep.Maximum += 1;
            configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum] = new Sprite.udtConfigurationStep();
            //if (nudConfigurationStep.Maximum > 0 && nudConfigurationStep.Value == nudConfigurationStep.Maximum - 1)
            { // add to the end of list
                configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].hingeDetails
                    = new udtConfigurationStepHinge[configurationCurrentlySelected.LimbDrawSequence.Length];

                // initialize cache bitmaps (leave null)
                configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].BmpCacheByMirrorType = new udtConfigurationStepBmpMirrortype[4];
                for (int intMirrorType = 0; intMirrorType < 4; intMirrorType++)
                {
                    configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].BmpCacheByMirrorType[intMirrorType].dir = new udtBmpAndPtTLInfo[16];
                }
                if ((int)nudConfigurationStep.Maximum > 0)
                    for (int intLimbCounter = 0; intLimbCounter < configurationCurrentlySelected.LimbDrawSequence.Length; intLimbCounter++)
                        configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].hingeDetails[intLimbCounter]
                        = copyConfigurationHingeDetail(configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].hingeDetails[intLimbCounter]);
            }
            //else
            //{ // move list down after nud.value then insert new there
            //    configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].hingeDetails
            //        = new udtConfigurationStepHinge[configurationCurrentlySelected.LimbDrawSequence.Length];

            //    // initialize cache bitmaps (leave null)
            //    configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].BmpCacheByMirrorType = new udtConfigurationStepBmpMirrortype[4];
            //    for (int intMirrorType = 0; intMirrorType < 4; intMirrorType++)
            //        configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum].BmpCacheByMirrorType[intMirrorType].dir = new udtBmpAndPtTLInfo[16];

            //    for (int intStepCounter = (int)nudConfigurationStep.Maximum; intStepCounter > (int)nudConfigurationStep.Value; intStepCounter--)
            //        for (int intHingeCounter = 0; intHingeCounter < configurationCurrentlySelected.steps[(int)nudConfigurationStep.Maximum - 1].hingeDetails.Length; intHingeCounter++)
            //            configurationCurrentlySelected.steps[intStepCounter].hingeDetails[intHingeCounter]
            //                = copyConfigurationHingeDetail(configurationCurrentlySelected.steps[intStepCounter - 1].hingeDetails[intHingeCounter]);
            //}

            nudConfigurationStep.Value = configurationCurrentlySelected.steps.Length - 1;

        }

        private udtConfigurationStepHinge copyConfigurationHingeDetail(udtConfigurationStepHinge udrOriginal)
        {
            udtConfigurationStepHinge udrCopy = new udtConfigurationStepHinge();

            udrCopy.angle = udrOriginal.angle;
            udrCopy.hinge = udrOriginal.hinge;

            return udrCopy;
        }

        private void btnConfigurationStepDel_Click(object sender, EventArgs e)
        {
            if (spriteMain == null)
            {
                MessageBox.Show("There is no object in memory", "error");
                return;
            }
            if (spriteMain.Configurations == null)
            {
                MessageBox.Show("There is no configuration in memory", "error");
                return;
            }

            if (configurationCurrentlySelected == null)
            {
                MessageBox.Show("Current configuration selection error", "erro");
                return;
            }

            if (configurationCurrentlySelected.steps.Length > 1)
            {
                for (int intStepCounter = (int)nudConfigurationStep.Value; intStepCounter < (int)nudConfigurationStep.Maximum; intStepCounter++)
                    for (int intHingeCounter = 0; intHingeCounter < configurationCurrentlySelected.steps[intStepCounter].hingeDetails.Length; intHingeCounter++)
                        configurationCurrentlySelected.steps[intStepCounter].hingeDetails[intHingeCounter]
                              = copyConfigurationHingeDetail(
                                      configurationCurrentlySelected.steps[intStepCounter + 1].hingeDetails[intHingeCounter]
                                                                         );

                Array.Resize<udtConfigurationStep>(ref configurationCurrentlySelected.steps, configurationCurrentlySelected.steps.Length - 1);
                if (nudConfigurationStep.Value > 0)
                    nudConfigurationStep.Value -= 1;
                nudConfigurationStep.Maximum -= 1;
            }
        }

        private void mnuConfigurationDelete_Click(object sender, EventArgs e)
        {
            if (spriteMain.Configurations == null)
                return;

            if (spriteMain.Configurations.Length <= 1)
            { // there's only one delete it
                spriteMain.Configurations = null;
                goto endConfigurationDelete;
            }

            if (configurationCurrentlySelected.name.CompareTo(spriteMain.Configurations[spriteMain.Configurations.Length - 1].name) == 0)
            { // its the last one shrink the array size and quit
                Array.Resize<classConfiguration>(ref spriteMain.Configurations, spriteMain.Configurations.Length - 1);
                goto endConfigurationDelete;
            }

            // copy last element in array over the one to be deleted then shrink the array and quit
            int intCurrentlySelectConfigurationIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);
            spriteMain.Configurations[intCurrentlySelectConfigurationIndex] = spriteMain.Configurations[spriteMain.Configurations.Length - 1];
            Array.Resize<classConfiguration>(ref spriteMain.Configurations, spriteMain.Configurations.Length - 1);

        endConfigurationDelete:
            reorderConfigurationAlphabetically();
            rebuildConfigurationLst();
            if (spriteMain.Configurations != null)
                configurationCurrentlySelected = spriteMain.Configurations[0];
            else
                configurationCurrentlySelected = null;
            rebuildConLimbDrawSequence();
        }

        private void mnuRefreshScreen_Click(object sender, EventArgs e) { refreshScreen(); }
        private void refreshScreen() { PutSpriteOnScreen(); }

        private void mnuSCMoveImage_Up_Click(object sender, EventArgs e)
        {
            ptDrawingCenter.Y -= intDrawingCenterMove;
            PutSpriteOnScreen();
            bolImageCentered = false;
        }

        private void refreshTitle()
        {
            if (spriteMain != null)
            {
                Text = spriteMain.myName.Trim()
                     + "(" + ptDrawingCenter.X.ToString("d3") + ", " + ptDrawingCenter.Y.ToString("d3") + ")"
                     + " factor = " + spriteMain.DisplaySize.ToString("f3");
            }
            else
                Text = "no sprite loaded";
        }

        private void mnuSCMoveImage_Down_Click(object sender, EventArgs e)
        {
            ptDrawingCenter.Y += intDrawingCenterMove;
            PutSpriteOnScreen();
            bolImageCentered = false;
        }

        private void mnuSCMoveImage_Right_Click(object sender, EventArgs e)
        {
            ptDrawingCenter.X += intDrawingCenterMove;
            PutSpriteOnScreen();
            bolImageCentered = false;
        }

        private void mnuSCMoveImage_Left_Click(object sender, EventArgs e)
        {
            ptDrawingCenter.X -= intDrawingCenterMove;
            PutSpriteOnScreen();
            bolImageCentered = false;
        }

        private void mnuSCResizeImage_Greater_Click(object sender, EventArgs e)
        {
            spriteMain.DisplaySize *= 1.1;
            PutSpriteOnScreen();
        }

        private void mnuSCResizeImage_Smaller_Click(object sender, EventArgs e)
        {
            spriteMain.DisplaySize *= 0.9;
            PutSpriteOnScreen();
        }

        /// <summary>
        /// draw sprite on the main screen with default values
        /// </summary>
        private void PutSpriteOnScreen()
        {
            if (spriteMain != null)
                PutSpriteOnScreen(ref picMainDisplay, spriteMain.DisplaySize, ptDrawingCenter);
        }
        /// <summary>
        /// draw sprite on the specified picturebox, at size and location
        /// </summary>
        /// <param name="pic">picture box onto which the sprite is to be drawn</param>
        /// <param name="dblSize">size factor which determines the size of output image relative to current DisplaySize setting of this sprite</param>
        /// <param name="ptLocation">location on picture box where this sprite is to be drawn</param>
        private void PutSpriteOnScreen(ref PictureBox pic, double dblSize, Point ptLocation)
        {
            if (pic != null && pic.Width > 0 && pic.Height > 0)
            {
                Bitmap bmp = new Bitmap(pic.Width, pic.Height);
                spriteMain.putImageOnScreen(ref bmp, ptDrawingCenter, dblSize, enuMirror.none);
                pic.Image = bmp;
                pic.Refresh();
                refreshTitle();
            }
        }

        /// <summary>
        /// set the currently selected configurations hinge values equal to those on the screen for this step
        /// </summary>
        void catchSpriteConfiguration()
        {
            int intConfigIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);
            classConfiguration thisCon = spriteMain.Configurations[intConfigIndex];
            udtConfigurationStep thisStep = thisCon.steps[(int)nudConfigurationStep.Value];

            int intNumDrawnLimbs = 0;
            for (intNumDrawnLimbs = 0; intNumDrawnLimbs < udrConDrawSequence[intConfigIndex].Limb.Length; intNumDrawnLimbs++)
                if (udrConDrawSequence[intConfigIndex].Limb[intNumDrawnLimbs].CompareTo(conDoNotDrawLimb) == 0)
                    break;

            if (thisStep.hingeDetails.Length != intNumDrawnLimbs)
            {
                Array.Resize<udtConfigurationStepHinge>(ref thisStep.hingeDetails, intNumDrawnLimbs);
            }




            for (int intLimbCounter = 0;
                     intLimbCounter < thisCon.LimbDrawSequence.Length;
                     intLimbCounter++)
            {
                classSpriteLimb thisLimb = spriteMain.getLimbByName(thisCon.LimbDrawSequence[intLimbCounter].Name);

                if (thisLimb == null)
                {
                    if (thisCon.LimbDrawSequence[intLimbCounter].Name.ToUpper().Trim().CompareTo(spriteMain.MasterLimb.Name.ToUpper().Trim()) == 0)
                        thisLimb = spriteMain.MasterLimb;
                }
                thisStep.hingeDetails[intLimbCounter].hinge = thisLimb.MasterHinge;

                if (thisStep.hingeDetails[intLimbCounter].hinge != null)
                    thisStep.hingeDetails[intLimbCounter].angle = thisLimb.MasterHinge.Angle;
            }

        }

        /// <summary>
        /// set the currently selected configurations draw sequence to accord with the value held in udrConDrawSequence array
        /// </summary>
        void resetSpriteConLimbDrawSeqToArray()
        {
            if (configurationCurrentlySelected != null)
            {
                int intConfigIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);
                spriteMain.Configurations[intConfigIndex].LimbDrawSequence = new classSpriteLimb[0];

                for (int intLimbCounter = 0; intLimbCounter < udrConDrawSequence[intConfigIndex].Limb.Length; intLimbCounter++)
                {
                    if (udrConDrawSequence[intConfigIndex].Limb[intLimbCounter].CompareTo(conDoNotDrawLimb) == 0)
                    {
                        break;
                    }
                    else
                    {
                        Array.Resize<classSpriteLimb>(ref spriteMain.Configurations[intConfigIndex].LimbDrawSequence,
                                                          spriteMain.Configurations[intConfigIndex].LimbDrawSequence.Length + 1);
                        spriteMain.Configurations[intConfigIndex].LimbDrawSequence[spriteMain.Configurations[intConfigIndex].LimbDrawSequence.Length - 1]
                            = spriteMain.getLimbByName(udrConDrawSequence[intConfigIndex].Limb[intLimbCounter]);
                        if (spriteMain.Configurations[intConfigIndex].LimbDrawSequence[spriteMain.Configurations[intConfigIndex].LimbDrawSequence.Length - 1] == null)
                            if (udrConDrawSequence[intConfigIndex].Limb[intLimbCounter].ToUpper().Trim().CompareTo(spriteMain.MasterLimb.Name.ToUpper().Trim()) == 0)
                                spriteMain.Configurations[intConfigIndex].LimbDrawSequence[spriteMain.Configurations[intConfigIndex].LimbDrawSequence.Length - 1] = spriteMain.MasterLimb;
                    }
                }
            }
        }

        void putSpriteConfigurationOnScreen()
        {
            if (configurationCurrentlySelected == null)
                return;

            int intConfigIndex = spriteMain.getIndexOfConfigurationByName(configurationCurrentlySelected.name);
            putSpriteConfigurationOnScreen(intConfigIndex, (int)nudConfigurationStep.Value);
        }
        void putSpriteConfigurationOnScreen(int intConfigurationIndex, int intConfigurationStep)
        { putSpriteConfigurationOnScreen(ref picMainDisplay, intConfigurationIndex, intConfigurationStep, spriteMain.DisplaySize); }
        void putSpriteConfigurationOnScreen(ref PictureBox pic, int intConfigurationIndex, int intConfigurationStep, double dblSize)
        {
            Bitmap bmp = new Bitmap(pic.Width, pic.Height);
            enuMirror mirror = enuMirror.none;
            if (chkFlipH.Checked && chkFlipV.Checked)
                mirror = enuMirror.VerticalAndHorizontal;
            else if (chkFlipH.Checked)
                mirror = enuMirror.horizontal;
            else if (chkFlipV.Checked)
                mirror = enuMirror.vertical;

            bool bolForceRebuild = !chkUseCacheImages.Checked;

            spriteMain.putConfigurationOnScreen(ref bmp, intConfigurationIndex, intConfigurationStep, ptDrawingCenter,dblAngle, spriteMain.DisplaySize, mirror, bolForceRebuild);

            pic.Image = bmp;
            pic.Refresh();
            refreshTitle();
        }

        private void mnuSCRotateImage_Clockwise_Click(object sender, EventArgs e)
        {
            //callingForm.drawObject(ref pnlWorkSpace, spriteMain, true);
            //spriteMain.udrData.udrMapPos.angle += dblRotateImageAngle;
            //callingForm.drawObject(ref pnlWorkSpace, spriteMain, false);
        }

        private void mnuSCRotateImage_CounteClockwise_Click(object sender, EventArgs e)
        {
            //callingForm.drawObject(ref pnlWorkSpace, spriteMain, true);
            //spriteMain.udrData.udrMapPos.angle -= dblRotateImageAngle;
            //callingForm.drawObject(ref pnlWorkSpace, spriteMain, false);
        }

        private void btnConfigurationAnimate_Click(object sender, EventArgs e)
        {
            nudConfigurationStep.Value = 0;
            PutSpriteOnScreen();
            tmrAnimate.Enabled = !tmrAnimate.Enabled;
        }

        private void tmrAnimate_Tick(object sender, EventArgs e)
        {
            tmrAnimate.Enabled = false;
            if (configurationCurrentlySelected == null)
                return;

            nudConfigurationStep.Value = (decimal)((nudConfigurationStep.Value + 1) % (nudConfigurationStep.Maximum + 1));
            putSpriteConfigurationOnScreen();
            
            
            /// debug start
            /// test find gun hand
            //enuMirror mirror = enuMirror.none;

            //if (chkFlipH.Checked && chkFlipV.Checked)
            //    mirror = enuMirror.VerticalAndHorizontal;
            //else if (chkFlipV.Checked)
            //    mirror = enuMirror.vertical;
            //else if (chkFlipH.Checked)
            //    mirror = enuMirror.horizontal;
            //Point ptHead = (spriteMain.getConfigurationByName("walk")).getLimbPos("head", mirror, (int)nudConfigurationStep.Value, 0);

            //ptHead = new Point(ptHead.X + ptDrawingCenter.X, ptHead.Y + ptDrawingCenter.Y);
            //Bitmap bmp = new Bitmap(picMainDisplay.Image);

            //using (Graphics g = Graphics.FromImage(bmp))
            //{
            //    g.DrawEllipse(new Pen(Color.Red), new Rectangle(ptHead.X - 1, ptHead.Y - 1, 2, 2));
            //    g.DrawEllipse(new Pen(Color.Red), new Rectangle(ptHead.X - 2, ptHead.Y - 2, 4, 4));
            //}

            //picMainDisplay.Image = bmp;
            /// debug stop




            tmrAnimate.Interval = (int)hsbAnimationDelayTime.Value;
            tmrAnimate.Enabled = true;
        }

        private void btnConfigurationAnimationStep_Click(object sender, EventArgs e)
        {
            tmrAnimate.Enabled = false;
            nudConfigurationStep.Value = (decimal)((nudConfigurationStep.Value + 1) % (nudConfigurationStep.Maximum + 1));
            //PutSpriteOnScreen();
        }

        private void btnHPDMouseSet_Click(object sender, EventArgs e)
        {
            if (hingeCurrentlySelected == null)
                return;

            classEditRadialCoor formEditRadMaster = new classEditRadialCoor(hingeCurrentlySelected.Limb_Master.udrSpriteLimbImages[0].bmp,
                                                                            hingeCurrentlySelected.RadCoor_Master,
                                                                            "Mouse Set Hinge " + hingeCurrentlySelected.name + "'s Master Rad-coor");
            formEditRadMaster.Owner = this;
            formEditRadMaster.ShowDialog();
            txtHPDLimbRadAngle.Text = formEditRadMaster.radCoor.angle.ToString();
            txtHPDLimbRadMagnitude.Text = formEditRadMaster.radCoor.radius.ToString();
            formEditRadMaster.Dispose();
            PutSpriteOnScreen();
        }

        private void btnHPSMouseSet_Click(object sender, EventArgs e)
        {
            if (hingeCurrentlySelected == null)
                return;
            classEditRadialCoor formEditRadSlave = new classEditRadialCoor(hingeCurrentlySelected.Limb_Slave.udrSpriteLimbImages[0].bmp, 
                                                                           hingeCurrentlySelected.RadCoor_Slave,
                                                                           "Mouse Set Hinge " + hingeCurrentlySelected.name + "'s Slave Rad-coor");
            formEditRadSlave.Owner = this;
            formEditRadSlave.ShowDialog();
            txtHPSLimbRadAngle.Text = (-formEditRadSlave.radCoor.angle).ToString();
            txtHPSLimbRadMagnitude.Text = formEditRadSlave.radCoor.radius.ToString();
            formEditRadSlave.Dispose();
            PutSpriteOnScreen();
        }

        private void btnHPAngleMouseSet_Click(object sender, EventArgs e)
        {
            EditHPMode = enuEditHPMode.mouseSetHingeAngle;
            if (grbConfigurationParameters.Visible)
                editMode = enuEditMode.EditConfiguration;
            else
                editMode = enuEditMode.EditHP;
        }

        private void HPAngleMouseSet()
        {
            if (hingeCurrentlySelected == null)
                return;
            Point ptMasterLimb = hingeCurrentlySelected.Limb_Master.Loc;
            Point ptHinge = new Point((int)(ptMasterLimb.X + spriteMain.DisplaySize * hingeCurrentlySelected.RadCoor_Master.radius * Math.Cos(hingeCurrentlySelected.RadCoor_Master.angle - hingeCurrentlySelected.Limb_Master.Angle)),
                                      (int)(ptMasterLimb.Y - spriteMain.DisplaySize * hingeCurrentlySelected.RadCoor_Master.radius * Math.Sin(hingeCurrentlySelected.RadCoor_Master.angle - hingeCurrentlySelected.Limb_Master.Angle)));

            double dblAngleWithMouse = cLibMath.arcTan(ptMouse.X - ptHinge.X, ptMouse.Y - ptHinge.Y);
            double dblAngleRelativeToMasterLimbAngle = dblAngleWithMouse - hingeCurrentlySelected.Limb_Master.Angle;

            hingeCurrentlySelected.Angle = dblAngleRelativeToMasterLimbAngle;
            txtHPCurrentAngle.Text = hingeCurrentlySelected.Angle.ToString();
            PutSpriteOnScreen();

            Bitmap bmp = new Bitmap(picMainDisplay.Image);
            int intRadius = 2;
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawEllipse(new Pen(Color.Blue), ptHinge.X - intRadius, ptHinge.Y - intRadius, intRadius * 2, intRadius * 2);
                g.DrawLine(new Pen(Color.Brown), ptMouse, ptHinge);
            }
            picMainDisplay.Image = bmp;
            picMainDisplay.Refresh();
        }

        private void mnuLimbsEditDrawSequence_Click(object sender, EventArgs e)
        {
            //loadLimbDrawSequence();
            grbLimbEditDrawSequence.Visible = !grbLimbEditDrawSequence.Visible;
            if (grbLimbEditDrawSequence.Visible)
                rebuildLimbEditDrawSequence();
        }

        private void rebuildLimbEditDrawSequence()
        {
            lstLimbEditDrawSequence.Items.Clear();
            for (int intLimbCounter = 0; intLimbCounter < strDrawSequence.Length; intLimbCounter++)
                try
                {
                    lstLimbEditDrawSequence.Items.Add(strDrawSequence[intLimbCounter]);
                }
                catch (Exception) { }
        }

        private void mnuResizeSprite_Click(object sender, EventArgs e)
        {
            formResizeSprite frmNewSize = new formResizeSprite();
            frmNewSize.Owner = this;
            frmNewSize.ShowDialog();
            double dblNewSize = frmNewSize.dblNewSizeFactor;
            if (dblNewSize > 0 && dblNewSize != 1.0)
            {
                if (MessageBox.Show("You wish to resize the sprite \""
                                      + spriteMain.myName.ToString().Trim()
                                      + "\" to %" + dblNewSize.ToString("f3")
                                      + " of its original size?"
                                      + "\r\nIs this correct?",
                                    "Resize to %" + dblNewSize.ToString("f3"),
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    resizeLimb(ref spriteMain.MasterLimb, dblNewSize);
                    for (int intHinCounter = 0; intHinCounter < spriteMain.hinges.Length; intHinCounter++)
                    {
                        classSpriteHinge thisHinge = spriteMain.hinges[intHinCounter];

                        classSpriteLimb thisLimb = thisHinge.Limb_Slave;
                        resizeLimb(ref thisLimb, dblNewSize);

                        thisHinge.RadCoor_Master.radius *= dblNewSize;
                        thisHinge.RadCoor_Slave.radius *= dblNewSize;
                    }
                    if (configurationCurrentlySelected != null)
                        putSpriteConfigurationOnScreen();
                    else
                        PutSpriteOnScreen();
                }
            }
        }

        private void resizeLimb(ref classSpriteLimb thisLimb, double dblSizeFactor)
        {
            Bitmap[] bmpOriginal = new Bitmap[1];
            int intNewWidth = (int)(thisLimb.udrSpriteLimbImages[0].bmp.Width * dblSizeFactor);
            if (intNewWidth < 1)
                intNewWidth = 1;
            int intNewHeight = (int)(thisLimb.udrSpriteLimbImages[0].bmp.Height * dblSizeFactor);
            if (intNewHeight < 1)
                intNewHeight = 1;

            bmpOriginal[0] = new Bitmap(thisLimb.udrSpriteLimbImages[0].bmp,
                                        new Size(intNewWidth ,intNewHeight));
            thisLimb.initImages(bmpOriginal);
        }

        private void formBuildObject_Load(object sender, EventArgs e)
        {

        }

        private void mnuConfigurations_PrintEnum_Click(object sender, EventArgs e)
        {

        }

        private void mnuConfigurations_Reorder_Click(object sender, EventArgs e)
        {
            formReorderConfigurations frmReorder = new formReorderConfigurations(ref spriteMain);
            frmReorder.Owner = this;
            frmReorder.ShowDialog();
            frmReorder.Dispose();
            rebuildConfigurationLst();
        }

    }

   
    public class formNewSprite : Form
    {
        public struct udtNewSpriteInfo
        {
            public string name;
            public string MasterLimbName;
            public Bitmap bmpMasterLimb;
            public bool rotate;
            public bool alwaysVertical;
            public bool flag;
        }
        static Size sz = new Size(800, 500);
        static Point pt = new Point(0, 0);

        public udtNewSpriteInfo udrNewSpriteInfo;
        Label lblNewSpriteName = new Label();
        TextBox txtNewSpriteName = new TextBox();
        CheckBox chkRotate = new CheckBox();
        CheckBox chkAlwaysVertical = new CheckBox();
        Label lblMasterLimbName = new Label();
        TextBox txtMasterLimbName = new TextBox();
        PictureBox picMasterLimb = new PictureBox();

        Button btnOk = new Button();
        Button btnCancel = new Button();

        Timer tmrInitSize = new Timer();
        public formNewSprite()
        {
            placeObjects();

            Text = "Create new sprite";

            Controls.Add(lblNewSpriteName);

            Controls.Add(txtNewSpriteName);
            txtNewSpriteName.Text = "New Sprite Name";
            txtNewSpriteName.SelectAll();

            Controls.Add(txtMasterLimbName);
            txtMasterLimbName.Text = "New Master Limb Name";
            txtMasterLimbName.SelectAll();

            Controls.Add(btnCancel);
            btnCancel.AutoSize = true;
            btnCancel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            btnCancel.Text = "Cancel";

            Controls.Add(btnOk);
            btnOk.AutoSize = true;
            btnOk.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            btnOk.Text = "Ok";

            Controls.Add(chkAlwaysVertical);
            udrNewSpriteInfo.alwaysVertical = chkAlwaysVertical.Checked = false;

            Controls.Add(chkRotate);
            udrNewSpriteInfo.rotate = chkRotate.Checked = true;

            Controls.Add(lblMasterLimbName);

            Controls.Add(picMasterLimb);

            SizeChanged += new EventHandler(formNewLimb_SizeChanged);
            Move += new EventHandler(formNewLimb_Move);

            chkRotate.CheckedChanged += new EventHandler(chkRotate_CheckedChanged);
            chkAlwaysVertical.CheckedChanged += new EventHandler(chkAlwaysVertical_CheckedChanged);
            txtMasterLimbName.TextChanged += new EventHandler(txtMasterLimbName_TextChanged);
            txtNewSpriteName.TextChanged += new EventHandler(txtNewSpriteName_TextChanged);
            picMasterLimb.Click += new EventHandler(picMasterLimb_Click);
            btnOk.Click += new EventHandler(btnOk_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);

            tmrInitSize.Interval = 5;
            tmrInitSize.Enabled = true;
            tmrInitSize.Tick += new EventHandler(tmrInitSize_Tick);
        }

        void tmrInitSize_Tick(object sender, EventArgs e)
        {
            tmrInitSize.Enabled = false;
            Size = sz;
            Location = pt;
        }

        void formNewLimb_Move(object sender, EventArgs e) { pt = Location; }
        void formNewLimb_SizeChanged(object sender, EventArgs e) { sz = Size; placeObjects(); }

        void placeObjects()
        {
            //Label lblNewSpriteName = new Label();
            lblNewSpriteName.Top = 15;
            lblNewSpriteName.Left = 5;
            lblNewSpriteName.AutoSize = true;
            lblNewSpriteName.Text = "Name of New Sprite:";

            //TextBox txtNewSpriteName = new TextBox();
            txtNewSpriteName.Left = lblNewSpriteName.Left + lblNewSpriteName.Width + 5;
            txtNewSpriteName.Top = lblNewSpriteName.Top;
            txtNewSpriteName.Width = 400;

            //PictureBox picMasterLimb = new PictureBox();
            picMasterLimb.Top = lblNewSpriteName.Top + txtNewSpriteName.Height + 5;
            picMasterLimb.Left = lblNewSpriteName.Left;
            if (udrNewSpriteInfo.bmpMasterLimb == null)
            {
                picMasterLimb.SizeMode = PictureBoxSizeMode.CenterImage;
                picMasterLimb.Image = Sprite_Editor.Properties.Resources.click_to_load_image;
            }
            else
            {
                picMasterLimb.SizeMode = PictureBoxSizeMode.AutoSize;
                picMasterLimb.Image = udrNewSpriteInfo.bmpMasterLimb;
            }

            //CheckBox chkRotate = new CheckBox();
            chkRotate.Left = lblNewSpriteName.Left;
            chkRotate.Top = picMasterLimb.Top + picMasterLimb.Height + 5;
            chkRotate.Text = "this limb rotates";
            chkRotate.AutoSize = true;

            //CheckBox chkAlwaysVertical = new CheckBox();
            chkAlwaysVertical.Left = chkRotate.Left + chkRotate.Width + 5;
            chkAlwaysVertical.Top = chkRotate.Top;
            chkAlwaysVertical.Text = "This limb is always vertical";
            chkAlwaysVertical.AutoSize = true;

            //label lblMasterLimbName = new Label();
            lblMasterLimbName.Left = lblNewSpriteName.Left;
            lblMasterLimbName.Top = chkRotate.Top + chkRotate.Height + 5;
            lblMasterLimbName.Text = "Name of sprite's master limb :";
            lblMasterLimbName.AutoSize = true;

            //TextBox txtMasterLimbName = new TextBox();
            txtMasterLimbName.Left = lblMasterLimbName.Left + lblMasterLimbName.Width + 5;
            txtMasterLimbName.Top = lblMasterLimbName.Top;
            txtMasterLimbName.Width = txtNewSpriteName.Width;

            btnOk.Left = Width - btnOk.Width - 20;
            btnOk.Top = Height - btnOk.Height - 45;
            btnCancel.Left = btnOk.Left - btnCancel.Width - 5;
            btnCancel.Top = btnOk.Top;
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            udrNewSpriteInfo.flag = false;
            Dispose();
        }

        void btnOk_Click(object sender, EventArgs e)
        {
            if (testIfValidNewLimb())
            {
                udrNewSpriteInfo.flag = true;
                Dispose();
            }
        }

        bool testIfValidNewLimb()
        {
            if (udrNewSpriteInfo.bmpMasterLimb == null)
            {
                MessageBox.Show("Please select a base image for this new sprite's master limb.");
                return false;
            }

            return true;
        }

        void chkRotate_CheckedChanged(object sender, EventArgs e)
        {
            chkAlwaysVertical.Enabled = chkRotate.Checked;
            udrNewSpriteInfo.rotate = chkAlwaysVertical.Checked;
        }

        void chkAlwaysVertical_CheckedChanged(object sender, EventArgs e)
        {
            udrNewSpriteInfo.alwaysVertical = chkAlwaysVertical.Checked;
        }

        void txtNewSpriteName_TextChanged(object sender, EventArgs e)
        {
            udrNewSpriteInfo.name = txtNewSpriteName.Text.ToString().Trim();
        }

        void txtMasterLimbName_TextChanged(object sender, EventArgs e)
        {
            udrNewSpriteInfo.MasterLimbName = txtMasterLimbName.Text.ToString().Trim();
        }

        void picMasterLimb_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                picMasterLimb.Load(ofd.FileName);
                picMasterLimb.SizeMode = PictureBoxSizeMode.AutoSize;
                udrNewSpriteInfo.bmpMasterLimb = new Bitmap(picMasterLimb.Image);
                placeObjects();
            }
        }


    }


    public class formNewLimb : Form
    {
        public struct udtNewLimbInfo
        {
            public string name;
            public classSpriteLimb masterLimb;
            public bool rotate;
            public bool alwaysVertical;
            public string hingeName;
            public Bitmap bmpBaseImage;
            public bool flag;
        }
        static Size sz = new Size(800, 500);
        static Point pt = new Point(0, 0);

        classSprite mainSprite;

        public udtNewLimbInfo udrNewLimbInfo;
        Label lblMasterLimbName = new Label();
        Label lblNewLimbName = new Label();
        TextBox txtNewLimbName = new TextBox();
        CheckBox chkRotate = new CheckBox();
        CheckBox chkAlwaysVertical = new CheckBox();
        Label lblNewHingeName = new Label();
        TextBox txtNewHingeName = new TextBox();
        PictureBox picMasterLimb = new PictureBox();
        PictureBox picNewLimb = new PictureBox();

        Button btnOk = new Button();
        Button btnCancel = new Button();

        Timer tmrInitSize = new Timer();
        public formNewLimb(ref classSprite thisSprite,
                           ref classSpriteLimb MasterLimb)
        {
            mainSprite = thisSprite;
            udrNewLimbInfo.masterLimb = MasterLimb;
            placeObjects();

            Text = "Create new limb";
           
            Controls.Add(lblMasterLimbName);

            Controls.Add(lblNewLimbName);
            
            Controls.Add(txtNewLimbName); 
            txtNewLimbName.Text = "New Limb Name"; 
            txtNewLimbName.SelectAll();
            txtNewLimbName.Width = 400;
            
            Controls.Add(txtNewHingeName); 
            txtNewHingeName.Text = "New Hinge Name"; 
            txtNewHingeName.SelectAll();
            txtNewHingeName.Width = txtNewLimbName.Width;
            
            Controls.Add(btnCancel);
            btnCancel.AutoSize = true;
            btnCancel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            btnCancel.Text = "Cancel";
            
            Controls.Add(btnOk);
            btnOk.AutoSize = true;
            btnOk.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            btnOk.Text = "Ok";
            
            Controls.Add(chkAlwaysVertical); 
            udrNewLimbInfo.alwaysVertical = chkAlwaysVertical.Checked = false;
            
            Controls.Add(chkRotate); 
            udrNewLimbInfo.rotate = chkRotate.Checked = true;
            
            Controls.Add(lblNewHingeName);
            
            Controls.Add(picNewLimb);
            
            Controls.Add(picMasterLimb);            
            
            SizeChanged += new EventHandler(formNewLimb_SizeChanged);
            Move += new EventHandler(formNewLimb_Move);

            chkRotate.CheckedChanged += new EventHandler(chkRotate_CheckedChanged);
            chkAlwaysVertical.CheckedChanged += new EventHandler(chkAlwaysVertical_CheckedChanged);
            txtNewHingeName.TextChanged += new EventHandler(txtNewHingeName_TextChanged);
            txtNewLimbName.TextChanged += new EventHandler(txtNewLimbName_TextChanged);
            picNewLimb.Click += new EventHandler(picNewLimb_Click);
            btnOk.Click += new EventHandler(btnOk_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);

            tmrInitSize.Interval = 5;
            tmrInitSize.Enabled = true;
            tmrInitSize.Tick += new EventHandler(tmrInitSize_Tick);
        }

        void tmrInitSize_Tick(object sender, EventArgs e)
        {
            tmrInitSize.Enabled = false;
            Size = sz; 
            Location = pt;            
        }
                
        void formNewLimb_Move(object sender, EventArgs e) { pt = Location; }
        void formNewLimb_SizeChanged(object sender, EventArgs e) { sz = Size; placeObjects(); }

        void placeObjects()
        {
            //Label lblNewLimbName = new Label();
            lblNewLimbName.Top = 15;
            lblNewLimbName.Left = 5;
            lblNewLimbName.AutoSize = true;
            lblNewLimbName.Text = "Name of New Limb:";

            //TextBox txtNewLimbName = new TextBox();
            txtNewLimbName.Left = lblNewLimbName.Left + lblNewLimbName.Width + 5;
            txtNewLimbName.Top = lblNewLimbName.Top;

            //PictureBox picNewLimb = new PictureBox();
            picNewLimb.Top = lblNewLimbName.Top + txtNewLimbName.Height + 5;
            picNewLimb.Left =lblNewLimbName.Left;
            if (udrNewLimbInfo.bmpBaseImage == null)
            {
                picNewLimb.SizeMode = PictureBoxSizeMode.CenterImage;
                picNewLimb.Image = Sprite_Editor.Properties.Resources.click_to_load_image;
            }
            else
            {
                picNewLimb.SizeMode = PictureBoxSizeMode.AutoSize;
                picNewLimb.Image = udrNewLimbInfo.bmpBaseImage;
            }

            //CheckBox chkRotate = new CheckBox();
            chkRotate.Left = lblNewLimbName.Left;
            chkRotate.Top = picNewLimb.Top + picNewLimb.Height + 5;
            chkRotate.Text = "this limb rotates";
            chkRotate.AutoSize = true;

            //CheckBox chkAlwaysVertical = new CheckBox();
            chkAlwaysVertical.Left = chkRotate.Left + chkRotate.Width + 5;
            chkAlwaysVertical.Top = chkRotate.Top;
            chkAlwaysVertical.Text = "This limb is always vertical"; 
            chkAlwaysVertical.AutoSize = true;

            //label lblNewHingeName = new Label();
            lblNewHingeName.Left = lblNewLimbName.Left;
            lblNewHingeName.Top = chkRotate.Top + chkRotate.Height + 5;
            lblNewHingeName.Text = "New Hinge Name :";
            lblNewHingeName.AutoSize = true;

            //TextBox txtNewHingeName = new TextBox();
            txtNewHingeName.Left = lblNewHingeName.Left + lblNewHingeName.Width + 5;
            txtNewHingeName.Top = lblNewHingeName.Top;
            
            //Label lblMasterLimbName = new Label();
            lblMasterLimbName.Top = txtNewHingeName.Top + txtNewHingeName.Height + 25;
            lblMasterLimbName.Left = lblNewLimbName.Left;
            lblMasterLimbName.AutoSize = true;
            lblMasterLimbName.Text = "Master Limb Name :" + udrNewLimbInfo.masterLimb.Name.ToString().Trim();

            //PictureBox picMasterLimb = new PictureBox();
            picMasterLimb.Top = lblMasterLimbName.Top + lblMasterLimbName.Height + 5;
            picMasterLimb.Left = lblMasterLimbName.Left;
            picMasterLimb.SizeMode = PictureBoxSizeMode.AutoSize;
            picMasterLimb.Image = udrNewLimbInfo.masterLimb.udrSpriteLimbImages[0].bmp;

            btnOk.Left = Width - btnOk.Width - 20;
            btnOk.Top = Height - btnOk.Height - 45;
            btnCancel.Left = btnOk.Left - btnCancel.Width - 5;
            btnCancel.Top = btnOk.Top;
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            udrNewLimbInfo.flag = false;
            Dispose();
        }

        void btnOk_Click(object sender, EventArgs e)
        {
            if (testIfValidNewLimb())
            {
                udrNewLimbInfo.flag = true;
                Dispose();
            }
        }

        bool testIfValidNewLimb()
        {
            if (udrNewLimbInfo.bmpBaseImage == null)
            {
                MessageBox.Show("Please select a base image for this new limb.");
                return false;
            }

            string strNewLimbName = udrNewLimbInfo.name.ToUpper().Trim();
            for (int intHingeCounter = 0; intHingeCounter < mainSprite.hinges.Length; intHingeCounter++)
            {
                if (mainSprite.hinges[intHingeCounter].Limb_Slave.Name.ToString().ToUpper().Trim().CompareTo(strNewLimbName) == 0)
                {
                    MessageBox.Show("The name of your new limb \"" + udrNewLimbInfo.name + "\" is already in use.  Please rename your new limb.");
                    return false;
                }
            }

            if (mainSprite.MasterLimb.Name.ToString().ToUpper().Trim().CompareTo(strNewLimbName) == 0)
            {
                MessageBox.Show("The name of your new limb \"" + udrNewLimbInfo.name + "\" is already in use.  Please rename your new limb.");
                return false;
            }

            string strNewHingeName = udrNewLimbInfo.hingeName.ToString().ToUpper().Trim();
            for (int intHingeCounter = 0; intHingeCounter < mainSprite.hinges.Length; intHingeCounter++)
            {
                if (mainSprite.hinges[intHingeCounter].name.ToString().ToUpper().Trim().CompareTo(strNewHingeName) == 0)
                {
                    MessageBox.Show("The name of your new limb's master hinge \"" + udrNewLimbInfo.hingeName + "\" is already in use.  Please rename the hinge connecting your new limb to the sprite.");
                    return false;
                }
            }

            return true;
        }

        void chkRotate_CheckedChanged(object sender, EventArgs e)
        {
            chkAlwaysVertical.Enabled = chkRotate.Checked;
            udrNewLimbInfo.rotate = chkAlwaysVertical.Checked;
        }

        void chkAlwaysVertical_CheckedChanged(object sender, EventArgs e)
        {
            udrNewLimbInfo.alwaysVertical = chkAlwaysVertical.Checked;
        }

        void txtNewLimbName_TextChanged(object sender, EventArgs e)
        {
            udrNewLimbInfo.name = txtNewLimbName.Text.ToString().Trim();
        }

        void txtNewHingeName_TextChanged(object sender, EventArgs e)
        {
            udrNewLimbInfo.hingeName = txtNewHingeName.Text.ToString().Trim();
        }

        void picNewLimb_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                picNewLimb.Load(ofd.FileName);
                picNewLimb.SizeMode = PictureBoxSizeMode.AutoSize ;
                udrNewLimbInfo.bmpBaseImage = new Bitmap(picNewLimb.Image);
                placeObjects();
            }
        }

        
    }


    public class formReorderConfigurations : Form
    {
        ListBox lst = new ListBox();
        TextBox txt = new TextBox();
        Button btnOk = new Button();
        Button btnCopyEnumToClipBoard = new Button();

        classSprite sprite;

        public formReorderConfigurations(ref classSprite Sprite)
        {
            sprite = Sprite;

            Text = sprite.myName.ToString().Trim();

            rebuildLst();

            Controls.Add(lst);
            Controls.Add(txt);
            txt.Top = 5;
            txt.Left = 5;
            txt.Width = 400;
            txt.Height = (sprite.Configurations.Length + 5) * (txt.Font.Height + 1);
            txt.Multiline = true;

            lst.Top = txt.Top;
            lst.Height = (lst.Font.Height + 1) * (lst.Items.Count+1);
            lst.Left = txt.Left + txt.Width + 5;
            lst.Width = 300;
            lst.MouseWheel += new MouseEventHandler(lst_MouseWheel);
            lst.KeyDown += new KeyEventHandler(lst_KeyDown);
                       
            Controls.Add(btnOk);
            btnOk.Text = "Ok";
            btnOk.Top = lst.Top + lst.Height + 5;
            btnOk.AutoSize = true;
            btnOk.Left = lst.Left + lst.Width - btnOk.Width;
            btnOk.Click += new EventHandler(btnOk_Click);

            Controls.Add(btnCopyEnumToClipBoard);
            btnCopyEnumToClipBoard.Text = "Copy Enum to ClipBoard";
            btnCopyEnumToClipBoard.Top = btnOk.Top;
            btnCopyEnumToClipBoard.AutoSize = true;
            btnCopyEnumToClipBoard.Left = btnOk.Left - btnCopyEnumToClipBoard.Width;
            btnCopyEnumToClipBoard.Click += new EventHandler(btnCopyEnumToClipBoard_Click);

            Width = btnOk.Left + btnOk.Width + 25;
            Height = txt.Top + txt.Height + 45;

            printEnum();
        }

        void btnCopyEnumToClipBoard_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Clipboard.SetText(txt.Text.ToString());
        }        

        void lst_KeyDown(object sender, KeyEventArgs e)
        {
            int intSel = lst.SelectedIndex;
            switch (e.KeyCode)
            {
                case Keys.Up:
                    lst_Up();
                    break;

                case Keys.Down:
                    lst_Down();
                    break;
            }
            lst.SelectedIndex = intSel;
        }

        void lst_MouseWheel(object sender, MouseEventArgs e)
        {
            int intSel = lst.SelectedIndex;
            if (e.Delta < 0 && intSel < lst.Items.Count - 1)
            {
                lst_Down();
                intSel++;
            }
            else if (e.Delta > 0 && intSel > 0)
            {
                lst_Up();
                intSel--;
            }
            lst.SelectedIndex = intSel;
        }

        void lst_Down()
        {
            int intSel = lst.SelectedIndex;
            if (intSel < lst.Items.Count - 1)
            {
                classConfiguration conTemp = sprite.Configurations[intSel + 1];
                sprite.Configurations[intSel + 1] = sprite.Configurations[intSel];
                sprite.Configurations[intSel] = conTemp;
                lst.SelectedIndex = intSel;
            }
            printEnum();
            rebuildLst();
        }

        void lst_Up() 
        {
            int intSel = lst.SelectedIndex;
            if (intSel > 0)
            {
                classConfiguration conTemp = sprite.Configurations[intSel - 1];
                sprite.Configurations[intSel - 1] = sprite.Configurations[intSel];
                sprite.Configurations[intSel] = conTemp;
                lst.SelectedIndex = intSel;
            }
            printEnum();
            rebuildLst();
        }

        void printEnum()
        {
            string strSpriteName = sprite.myName.ToString().Trim();
            txt.Text = "public enum enu" + eraseIllegalCharactersFromString(ref strSpriteName) + "_Configurations"
                     + "\r\n{";
            for (int intConCounter = 0; intConCounter < sprite.Configurations.Length; intConCounter++)
            {
                string strConName = sprite.Configurations[intConCounter].name.ToString().Trim();
                eraseIllegalCharactersFromString(ref strConName);
                txt.Text += "\r\n    " + strConName  + ",";
            }
            txt.Text += "\r\n    _numCon\r\n}";
        }

        string eraseIllegalCharactersFromString(ref string str)
        {
            string strIllegalChar = " !@#$%^&*()+=-:;[]}{,'\"|\\/?><";
            foreach (char c in strIllegalChar)
                str = str.Replace(c, '_');
            return str;
        }

        void btnOk_Click(object sender, EventArgs e) { Dispose(); }

        void rebuildLst()
        {
            lst.Items.Clear();
            for (int intConCounter = 0; intConCounter <sprite.Configurations.Length ; intConCounter++)
                lst.Items.Add(sprite.Configurations[intConCounter].name.ToString());

        }
    }


    public class formResizeSprite : Form
    {
        TextBox txtNewSize = new TextBox();
        Label lblInstructions = new Label();
        HScrollBar hsb = new HScrollBar();
        Button btnOK = new Button();
        Button btnCancel = new Button();

        public double dblNewSizeFactor = 1.0;

        public formResizeSprite()
        {
            Controls.Add(lblInstructions);
            lblInstructions.Text = "Set factor by which sprite will be resized : ";
            lblInstructions.Font = new Font("ms sans-serif", 14);
            lblInstructions.Top = 15;
            lblInstructions.Left = 5;
            lblInstructions.AutoSize = true;

            Controls.Add(txtNewSize);
            txtNewSize.Font = lblInstructions.Font;
            txtNewSize.Left = lblInstructions.Left + lblInstructions.Width + 5;
            txtNewSize.Top = lblInstructions.Top;
            txtNewSize.Width = 70;
            txtNewSize.Height = 30;
            txtNewSize.Multiline = true;
            txtNewSize.TextAlign = HorizontalAlignment.Right;
            txtNewSize.BorderStyle = BorderStyle.None;
            setText();
            txtNewSize.TextChanged += new EventHandler(txtNewSize_TextChanged);
            txtNewSize.KeyDown += new KeyEventHandler(txtNewSize_KeyDown);

            Controls.Add(hsb);
            hsb.LargeChange = 100;
            hsb.Minimum = 0;
            hsb.Maximum = 10099;
            hsb.Value = (int)(Math.Ceiling(10000.0 * 0.95 / 1.95));
            hsb.Top = txtNewSize.Top + txtNewSize.Height + 5;
            hsb.Left = lblInstructions.Left;
            hsb.Width = txtNewSize.Left + txtNewSize.Width - lblInstructions.Left;
            hsb.ValueChanged += new EventHandler(hsb_ValueChanged);

            Width = hsb.Width + 25;

            Controls.Add(btnCancel);
            btnCancel.Text = "Cancel";
            btnCancel.AutoSize = true;
            btnCancel.Top = hsb.Top + hsb.Height + 5;
            btnCancel.Left = Width - btnCancel.Width - 20;
            btnCancel.Click += new EventHandler(btnCancel_Click);

            Controls.Add(btnOK);
            btnOK.Text = "Ok";
            btnOK.Top = btnCancel.Top;
            btnOK.Left = btnCancel.Left - btnOK.Width - 5;
            btnOK.Click += new EventHandler(btnOK_Click);

            Height = btnOK.Top + btnOK.Height + 45;
        }

        void setText() { txtNewSize.Text = dblNewSizeFactor.ToString("f3"); }
        void btnOK_Click(object sender, EventArgs e) { Dispose(); }

        void btnCancel_Click(object sender, EventArgs e)
        {
            dblNewSizeFactor = -1;
            Dispose();
        }

        void hsb_ValueChanged(object sender, EventArgs e)
        {
            dblNewSizeFactor = (double)(hsb.Value * 1.95 / 10000.0) + 0.05;
            setText();
        }

        void txtNewSize_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    e.SuppressKeyPress = true;
                    Dispose();
                    break;
            }
        }

        void txtNewSize_TextChanged(object sender, EventArgs e)
        {
            double dblTemp = dblNewSizeFactor;
            try { dblTemp = Convert.ToDouble(txtNewSize.Text); }
            catch (Exception)
            {
                dblTemp = dblNewSizeFactor;
                txtNewSize.Text = dblNewSizeFactor.ToString("f3");
            }
        }
    }

    public class classEditRadialCoor : System.Windows.Forms.Form
    {
        PictureBox pic = new PictureBox();
        public classMath.classRadialCoor radCoor = new classMath.classRadialCoor();
        classMath.classRadialCoor radOriginalCoor;
        classMath cLibMath = new classMath();
        Point ptMouse = new Point();
        Point ptCenter;
        Bitmap bmpOriginal;
        double dblMaxFactor = 1.0;
        int intMaxHeight = Screen.PrimaryScreen.WorkingArea.Height / 2;
        int intMaxWidth = Screen.PrimaryScreen.WorkingArea.Width / 2;
        int intMinBorder = 100;
    
        public classEditRadialCoor(Bitmap bmp, classMath.classRadialCoor udrRad, string strTitle)
        {
            radOriginalCoor = udrRad;
            double dblWidthFactor = 1.0;
            if (bmp.Width > 2 * intMinBorder)
                dblWidthFactor = ((double)intMaxWidth / (double)(bmp.Width - 2 * intMinBorder));

            double dblHeightFactor = 1.0;
            if (bmp.Height > 2 * intMinBorder)
                dblHeightFactor = ((double)intMaxHeight / (double)(bmp.Height - 2 * intMinBorder));
            double dblBestFactor = (dblWidthFactor < dblHeightFactor ? dblWidthFactor : dblHeightFactor);

            dblMaxFactor = (dblBestFactor < 1 ? dblBestFactor : 1.0);
            bmpOriginal = new Bitmap(bmp, new Size((int)(bmp.Width * dblMaxFactor), (int)(bmp.Height * dblMaxFactor)));


           
            Text = strTitle;
            Controls.Add(pic);
            pic.BackColor = System.Drawing.Color.White;
            pic.SizeMode = PictureBoxSizeMode.AutoSize;
            pic.Top = 5; pic.Left = 5;

            pic.MouseMove += new MouseEventHandler(pic_MouseMove);
            pic.MouseClick += new MouseEventHandler(pic_MouseClick);

            pic.Visible = true;
            ptMouse.X = ptCenter.X; ptMouse.Y = ptCenter.Y;
            drawImage();
        }

        void drawImage()
        {
            Bitmap bmpOriginalOutput = new Bitmap(bmpOriginal.Width + 2 * intMinBorder , bmpOriginal.Height + 2 * intMinBorder);
            ptCenter = new Point(bmpOriginalOutput.Width / 2, bmpOriginalOutput.Height / 2);
            int intRadius = 4;

            Point ptCenterOldLoc = new Point((int)(ptCenter.X + radOriginalCoor.radius * dblMaxFactor * Math.Cos(radOriginalCoor.angle)),
                                             (int)(ptCenter.Y + radOriginalCoor.radius * dblMaxFactor * Math.Sin(radOriginalCoor.angle)));

            using (Graphics g = Graphics.FromImage(bmpOriginalOutput))
            {
                g.DrawImage(bmpOriginal, new Point(intMinBorder, intMinBorder));
                g.DrawEllipse(new Pen(Color.Red, 1), ptCenter.X - intRadius - 1, ptCenter.Y - intRadius - 1, 2 * (intRadius + 1), 2 * (intRadius + 1));
                g.DrawEllipse(new Pen(Color.White, 1), ptCenter.X - intRadius, ptCenter.Y - intRadius, 2 * (intRadius), 2 * (intRadius));
                g.DrawLine(new Pen(Color.Orange), ptCenter, ptMouse);

                g.DrawEllipse(new Pen(Color.Black), new Rectangle(ptCenterOldLoc.X - 1, ptCenterOldLoc.Y - 1, 2, 2));
                g.DrawEllipse(new Pen(Color.White), new Rectangle(ptCenterOldLoc.X - 2, ptCenterOldLoc.Y - 2, 4, 4));
            }           

            pic.Image = bmpOriginalOutput;
            pic.Refresh();
            Width = pic.Width + 10;
            Height = pic.Height + 20;
            if (Top + Height > Screen.PrimaryScreen.WorkingArea.Height)
                Top = Screen.PrimaryScreen.WorkingArea.Height - Height;
            if (Left + Width > Screen.PrimaryScreen.WorkingArea.Width)
                Left = Screen.PrimaryScreen.WorkingArea.Width - Width;
        }

        void pic_MouseClick(object sender, MouseEventArgs e) { Close(); }
        void pic_MouseMove(object sender, MouseEventArgs e)
        {
            ptMouse.X = e.X; ptMouse.Y = e.Y;
            int intDX = ptMouse.X - ptCenter.X;
            int intDY = -(ptMouse.Y - ptCenter.Y);
            radCoor.angle = cLibMath.arcTan(intDX, intDY);
            radCoor.radius = Math.Sqrt(intDX * intDX + intDY * intDY) / dblMaxFactor;
            drawImage();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Christ Kennedy
CEO unemployable
Canada Canada
Christ Kennedy, published his fourth novel "Cleats of the Counter Revolution" in the summer of 2010. He grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University and is currently walking across ontario plotting a new novel, far away from any computer.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 27 Jan 2010
Article Copyright 2010 by Christ Kennedy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid