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 Microsoft.Xna.Framework; using gr2lib.core.coretypes.implementation; using gr2lib.core.ui.helpers; namespace XNABoneViewer { public partial class XNABoneViewerFrm : Form { private List bones; //private Transform bonerotation; private CustomColor ActiveBoneJointColor = System.Drawing.Color.Red; private CustomColor InActiveBoneJointColor = System.Drawing.Color.White; private CustomColor ActiveBoneColor = System.Drawing.Color.Blue; private CustomColor InActiveBoneColor = System.Drawing.Color.LimeGreen; private const float Scaler = 1.0f; /// /// Default Constructor /// public XNABoneViewerFrm() { InitializeComponent(); this.pre_init(); this.post_init(); } /// /// Default Constructor - specifying: bone list /// public XNABoneViewerFrm(List bones) { InitializeComponent(); this.pre_init(); this.bones = bones; this.post_init(); } private void pre_init() { this.bones = new List(); //this.RotateLeftRight.Maximum = 180; //this.rotateUpDown.Maximum = 180; this.PropGrid.ShowCustomProperties = true; this.PropGrid.ToolbarVisible = false; this.PropGrid.PropertySort = PropertySort.NoSort; } private void post_init() { //this.bonerotation = this.bones.BoneRotation; this.bones.Sort(); foreach (Bone bone in this.bones) { bonelist.Items.Add(bone.Name); } //this.BoneViewer = new XNABoneViewerControl(this.bones); this.BoneViewer.Bones = this.bones; this.BoneViewer.InitializeData(); // set size of bone points this.BoneViewer.PointSize = 5; //this.MouseWheel += new MouseEventHandler(XNABoneViewerFrm_MouseWheel); //this.BoneViewer.MouseWheel += new MouseEventHandler(XNABoneViewerFrm_MouseWheel); //this.renderSplit.Panel2.MouseWheel += new MouseEventHandler(XNABoneViewerFrm_MouseWheel); if (this.bones.Count <= 0) { this.chkEnableRender.Checked = false; this.chkEnableRender.Enabled = false; this.btnResetView.Enabled = false; this.RotateLeftRight.Enabled = false; this.rotateUpDown.Enabled = false; this.RotateZ.Enabled = false; this.panLeftRight.Enabled = false; this.PanUpDown.Enabled = false; this.renderInterval.Enabled = false; this.BoneViewer.Enabled = false; this.rotateInOut.Enabled = false; this.txt_renderInterval.Enabled = false; this.txt_rotateInOut.Enabled = false; this.txt_RotateLeftRight.Enabled = false; this.txt_rotateUpDown.Enabled = false; this.txt_RotateZ.Enabled = false; } else { this.chkEnableRender.Checked = true; this.chkEnableRender.Enabled = true; this.btnResetView.Enabled = true; } } private void renderInterval_ValueChanged(object sender, EventArgs e) { this.txt_renderInterval.Value = renderInterval.Value; this.BoneViewer.renderInterval = renderInterval.Value; } private void chkEnableRender_CheckedChanged(object sender, EventArgs e) { this.BoneViewer.EnableRenderer = chkEnableRender.Checked; } private void bonelist_SelectedIndexChanged(object sender, EventArgs e) { try { this.PropGrid.Item.Clear(); this.PropGrid.SelectedObject = null; } catch { } Bone bone = new Bone(); try { bone = this.bones[this.bonelist.SelectedIndex]; } catch { } foreach (Bone b in this.bones) { if (b.BonePropertyData.BoneJointColor.ToArgb() == ActiveBoneJointColor.ToArgb()) { b.BonePropertyData.BoneJointColor = InActiveBoneJointColor; } if (b.BonePropertyData.BoneColor.ToArgb() == ActiveBoneColor.ToArgb()) { b.BonePropertyData.BoneColor = InActiveBoneColor; } } if (bone.BonePropertyData.BoneJointColor.ToArgb() == InActiveBoneJointColor.ToArgb()) { bone.BonePropertyData.BoneJointColor = ActiveBoneJointColor; } if (bone.BonePropertyData.BoneColor.ToArgb() == InActiveBoneColor.ToArgb()) { bone.BonePropertyData.BoneColor = ActiveBoneColor; } this.PropGrid.Item.Add("name", bone, false, "category", "description", true); this.PropGrid.Item[this.PropGrid.Item.Count - 1].IsBrowsable = true; this.PropGrid.Item[this.PropGrid.Item.Count - 1].BrowsableLabelStyle = PropertyGridEx.BrowsableTypeConverter.LabelStyle.lsNormal; this.PropGrid.SelectedObject = this.PropGrid.Item; this.PropGrid.ExpandAllGridItems(); } private void RotateLeftRight_ValueChanged(object sender, EventArgs e) { txt_RotateLeftRight.Value = RotateLeftRight.Value; this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); } private void rotateUpDown_ValueChanged(object sender, EventArgs e) { this.txt_rotateUpDown.Value = this.rotateUpDown.Value; this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); } private void btnResetView_Click(object sender, EventArgs e) { //this.BoneViewer.ApplyRotationScale(0, 0, 0, 1); rotateUpDown.Value = 0; RotateLeftRight.Value = 0; RotateZ.Value = 0; rotateInOut.Value = 1; panLeftRight.Value = (BoneViewer.Width * 2) / 2; PanUpDown.Value = (BoneViewer.Height * 2) / 2; this.BoneViewer.ApplyRotationScale(0, 0, 0, 1); this.BoneViewer.ResetPan(); } private void RotateZ_ValueChanged(object sender, EventArgs e) { txt_RotateZ.Value = RotateZ.Value; this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); } private void rotateInOut_ValueChanged(object sender, EventArgs e) { txt_rotateInOut.Value = rotateInOut.Value * Scaler; this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); } private void panLeftRight_ValueChanged(object sender, EventArgs e) { int Width = BoneViewer.Width * 2; int Height = BoneViewer.Height * 2; int Middle_Width = Width / 2; int Middle_Height = Height / 2; float LeftRightPan = 0; float UpDownPan = 0; float Correction = 0.015625f; LeftRightPan = (panLeftRight.Value - Middle_Width) * Correction; UpDownPan = (PanUpDown.Value - Middle_Height) * Correction; this.BoneViewer.Pan((LeftRightPan * -1.0f) / 2.5f, (UpDownPan) / 2.5f); } private void PanUpDown_ValueChanged(object sender, EventArgs e) { int Width = BoneViewer.Width * 2; int Height = BoneViewer.Height * 2; int Middle_Width = Width / 2; int Middle_Height = Height / 2; float LeftRightPan = 0; float UpDownPan = 0; float Correction = 0.015625f; LeftRightPan = (panLeftRight.Value - Middle_Width) * Correction; UpDownPan = (PanUpDown.Value - Middle_Height) * Correction; this.BoneViewer.Pan((LeftRightPan * -1.0f) / 2.5f, (UpDownPan) / 2.5f); } private void txt_rotateUpDown_ValueChanged(object value) { try { this.rotateUpDown.Value = (int)(Convert.ToInt32(value)); } catch { try { this.rotateUpDown.Value = (int)(Convert.ToSingle(value)); } catch { this.rotateUpDown.Value = this.rotateUpDown.Minimum; this.txt_rotateUpDown.Value = this.rotateUpDown.Minimum; this.txt_rotateUpDown.Value = this.rotateUpDown.Minimum; } } } private void txt_renderInterval_ValueChanged(object value) { try { this.renderInterval.Value = (int)(Convert.ToInt32(value)); } catch { try { this.renderInterval.Value = (int)(Convert.ToSingle(value)); } catch { this.renderInterval.Value = this.renderInterval.Minimum; this.txt_renderInterval.Value = this.renderInterval.Minimum; } } } private void txt_RotateLeftRight_ValueChanged(object value) { try { this.RotateLeftRight.Value = (int)(Convert.ToInt32(value)); } catch { try { this.RotateLeftRight.Value = (int)(Convert.ToSingle(value)); } catch { this.RotateLeftRight.Value = this.RotateLeftRight.Minimum; this.txt_RotateLeftRight.Value = this.RotateLeftRight.Minimum; } } } private void txt_RotateZ_ValueChanged(object value) { try { this.RotateZ.Value = (int)(Convert.ToInt32(value)); } catch { try { this.RotateZ.Value = (int)(Convert.ToSingle(value)); } catch { this.RotateZ.Value = this.RotateZ.Minimum; this.txt_RotateZ.Value = this.RotateZ.Minimum; } } } private void txt_rotateInOut_ValueChanged(object value) { try { this.rotateInOut.Value = (int)(Convert.ToInt32(value) / Scaler); } catch { try { this.rotateInOut.Value = (int)(Convert.ToSingle(value) / Scaler); } catch { this.rotateInOut.Value = this.rotateInOut.Minimum; this.txt_rotateInOut.Value = this.rotateInOut.Minimum; } } } private void XNABoneViewerFrm_Load(object sender, EventArgs e) { txt_renderInterval.Value = renderInterval.Value; txt_rotateUpDown.Value = rotateUpDown.Value; txt_RotateLeftRight.Value = RotateLeftRight.Value; txt_RotateZ.Value = RotateZ.Value; txt_rotateInOut.Value = rotateInOut.Value; panLeftRight.Maximum = (BoneViewer.Width*2); panLeftRight.Minimum = 0; panLeftRight.Value = (BoneViewer.Width*2) / 2; PanUpDown.Maximum = (BoneViewer.Height*2); PanUpDown.Minimum = 0; PanUpDown.Value = (BoneViewer.Height * 2) / 2; this.BoneViewer.ResetPan(); //ChaosMageX.Granny2.Geom.Quaternion rot = this.bonerotation.Rotation; //Matrix33 scale = this.bonerotation.Scale; //this.rotateUpDown.Value = (int)rot.v.x; //this.RotateLeftRight.Value = (int)rot.v.y; //this.RotateZ.Value = (int)rot.v.z; //this.rotateInOut.Value = (int)(scale.right.x); this.BoneViewer.MouseWheel += new MouseEventHandler(BoneViewer_MouseWheel); } private void BoneViewer_MouseMove(object sender, MouseEventArgs e) { int Width = BoneViewer.Width; int Height = BoneViewer.Height; int Middle_Width = Width / 2; int Middle_Height = Height / 2; float LeftRightPan = 0; float UpDownPan = 0; float Correction = 0.015625f; System.Windows.Forms.Control source = (System.Windows.Forms.Control)sender; System.Drawing.Point screen = source.PointToScreen(new System.Drawing.Point(e.X, e.Y)); System.Drawing.Point local = BoneViewer.PointToClient(screen); if (e.Button == MouseButtons.Left) { // Left Button is clicked, pan LeftRightPan = ((local.X - Middle_Width) * Correction);// +this.BoneViewer.Position.Pan.PanLeftRight; UpDownPan = ((local.Y - Middle_Height) * Correction);// +this.BoneViewer.Position.Pan.PanUpDown; this.BoneViewer.Pan((LeftRightPan * -1.0f) / 2.5f, (UpDownPan) / 2.5f); this.BoneViewer.Position.Pan.PanLeftRight = LeftRightPan; this.BoneViewer.Position.Pan.PanUpDown = UpDownPan; Application.DoEvents(); } Application.DoEvents(); } private void BoneViewer_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120; int Value = this.rotateInOut.Minimum; try { Value = this.rotateInOut.Value; int newValue = (numberOfTextLinesToMove * 1) + this.rotateInOut.Value; if (newValue > this.rotateInOut.Maximum) this.rotateInOut.Value = this.rotateInOut.Maximum; this.rotateInOut.Value = newValue; } catch { this.rotateInOut.Value = Value; } } } }