/[RomCheater]/trunk/RomCheater.Core/Docking/FloatingDataTypeConverter.cs
ViewVC logotype

Annotation of /trunk/RomCheater.Core/Docking/FloatingDataTypeConverter.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 892 - (hide annotations) (download)
Wed Sep 17 05:56:41 2014 UTC (7 years ago) by william
File size: 7401 byte(s)
+ alot of dang work to force an icon to be shown on the docked panels
  ** when it was as simple as setting: DockPanel.ShowDocumentIcon to true

1 william 885 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5     using System.Drawing;
6     using System.Linq;
7     using System.Text;
8     using System.Windows.Forms;
9     using WeifenLuo.WinFormsUI.Docking;
10     using libWin32.Win32.NumericConversion.IEEE754;
11 william 889 using RomCheater.Core;
12     namespace RomCheater.Core.Docking
13 william 885 {
14     public partial class FloatingDataTypeConverter : DockContent
15     {
16     public FloatingDataTypeConverter()
17     {
18     InitializeComponent();
19     chkhexadecimal.Checked = true;
20     }
21    
22     private void chkBinary_CheckedChanged(object sender, EventArgs e)
23     {
24     // binary input
25     txtInput.InputType = NumericInputTypes.Binary;
26     txtInput.Value = (0).ToString();
27     }
28    
29     private void chkdecimal_CheckedChanged(object sender, EventArgs e)
30     {
31     // decimal input
32     txtInput.InputType = NumericInputTypes.Decimal;
33     txtInput.Value = (0).ToString();
34     }
35    
36     private void chkhexadecimal_CheckedChanged(object sender, EventArgs e)
37     {
38     // hex input
39     txtInput.InputType = NumericInputTypes.Hex;
40     txtInput.Value = (0).ToString();
41     }
42    
43     private void chkoctal_CheckedChanged(object sender, EventArgs e)
44     {
45     // octal input
46     txtInput.InputType = NumericInputTypes.Octal;
47     txtInput.Value = (0).ToString();
48     }
49    
50     private void chkieee754float_CheckedChanged(object sender, EventArgs e)
51     {
52     //// IEEE754 Hex Float (hex)
53     //txtInput.InputType = NumericInputTypes.IEEE754HexFloat;
54     //txtInput.Value = (0).ToString();
55     }
56    
57     private void btnConvert_Click(object sender, EventArgs e)
58     {
59     try
60     {
61     switch (txtInput.InputType)
62     {
63     case NumericInputTypes.Binary:
64     txtBinary.Value = txtInput.Value;
65     ConvertData(txtBinary.Value, 2);
66     break;
67     case NumericInputTypes.Decimal:
68     txtDecimal.Value = txtInput.Value;
69     ConvertData(txtDecimal.Value, 10);
70     FloatConverter.SetFloatValue(Convert.ToSingle(txtDecimal.Value));
71     FloatConverter.CalculateHexFloat();
72     break;
73     case NumericInputTypes.Hex:
74     txtHex.Value = txtInput.Value;
75     ConvertData(txtHex.Value, 16);
76     FloatConverter.SetFloatHexValue(Convert.ToUInt32(txtHex.Value,16));
77     FloatConverter.CalculateFloat();
78     break;
79     //case NumericInputTypes.IEEE754HexFloat:
80     // txtFloat.Value = txtInput.Value;
81     // ConvertData(txtFloat.Value, 16);
82     // break;
83     case NumericInputTypes.Octal:
84     txtOctal.Value = (txtInput.Value.StartsWith("0")) ? txtInput.Value : string.Format("0{0}", txtInput.Value);
85     ConvertData(txtOctal.Value, 8);
86     break;
87     }
88    
89     }
90     catch (FormatException ex)
91     {
92     MessageBox.Show(ex.ToString(),"Encountered an error in the input format", MessageBoxButtons.OK, MessageBoxIcon.Error);
93     }
94     catch (Exception ex)
95     {
96     MessageBox.Show(ex.ToString(),"Encountered an error while converting the data", MessageBoxButtons.OK, MessageBoxIcon.Error);
97     }
98     }
99    
100     private void ConvertData(string value, int FromBase)
101     {
102     // binary
103     if (txtInput.InputType != NumericInputTypes.Binary)
104     {
105     int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
106     txtBinary.Value = Convert.ToString(val, 2);
107     //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
108     //{
109     // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
110     // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
111     // converter.HexFloat = val2;
112     // txtBinary.Value = Convert.ToString(converter.Float);
113     //}
114     }
115     // decimal
116     if (txtInput.InputType != NumericInputTypes.Decimal)
117     {
118     int val = Convert.ToInt32(value, FromBase);
119     txtDecimal.Value = Convert.ToString(val, 10);
120     //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
121     //{
122     // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
123     // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
124     // converter.HexFloat = val2;
125     // txtDecimal.Value = string.Format("{0:R}", converter.Float);
126     //}
127     }
128     // hex
129     if (txtInput.InputType != NumericInputTypes.Hex)
130     {
131     int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
132     txtHex.Value = Convert.ToString(val, 16);
133     //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
134     //{
135     // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
136     // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
137     // converter.HexFloat = val2;
138     //}
139     }
140     // octal
141     if (txtInput.InputType != NumericInputTypes.Octal)
142     {
143     int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
144     txtOctal.Value = Convert.ToString(val, 8);
145     //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
146     //{
147     // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
148     // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
149     // converter.HexFloat = val2;
150     //}
151     }
152     //// float
153     //if (txtInput.InputType != NumericInputTypes.IEEE754HexFloat)
154     //{
155     // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
156     // uint val = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
157     // float f = Convert.ToSingle(val);
158     // converter.Float = f;
159     // //txtFloat.Value = string.Format("{0:R}", converter.Float);
160     // txtFloat.Value = string.Format("0x{0:x8}", converter.HexFloat);
161     //}
162     }
163     }
164     }

  ViewVC Help
Powered by ViewVC 1.1.22