Inheritance: System.ComponentModel.TypeConverter
Ejemplo n.º 1
0
		public void SetUp ()
		{
			pt = new Point (1, 2);
			ptStr = pt.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + pt.Y;

			ptneg = new Point (-2, -3);
			ptnegStr = ptneg.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + ptneg.Y;

			ptconv = (PointConverter) TypeDescriptor.GetConverter (pt);
		}
Ejemplo n.º 2
0
 public GLine(Point aPoint1, Point aPoint2)
 {
     PointConverter aPointConverter = new PointConverter();
     FPoint1 = (PointF)aPointConverter.ConvertTo(aPoint1, typeof(PointF));
     FPoint2 = (PointF)aPointConverter.ConvertTo(aPoint2, typeof(PointF));
 }
Ejemplo n.º 3
0
        static CommonHelper()
        {
            var chrArray = new[] { 'd', 'f', 'F', 'g', 'h', 'H', 'K', 'm', 'M', 's', 't', 'y', 'z' };

            _singleDateFormat = chrArray;
            _inheritPadding = new Padding(-1);

            var days = new[] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
            _daysInMonth = days;

            var singleArray = new float[5][];

            var singleArray1 = new[] { 0.3f, 0.3f, 0.3f, 0f, 0f };
            singleArray[0] = singleArray1;

            var singleArray2 = new[] { 0.59f, 0.59f, 0.59f, 0f, 0f };
            singleArray[1] = singleArray2;

            var singleArray3 = new[] { 0.11f, 0.11f, 0.11f, 0f, 0f };
            singleArray[2] = singleArray3;

            var singleArray4 = new float[5];
            singleArray4[3] = 0.5f;
            singleArray[3] = singleArray4;

            var singleArray5 = new float[5];
            singleArray5[4] = 1f;
            singleArray[4] = singleArray5;

            _matrixDisabled = new ColorMatrix(singleArray);
            _nextId = 1000;
            _baseDate = new DateTime(2000, 1, 1);
            _nullPoint = new Point(0x7fffffff, 0x7fffffff);
            _nullRectangle = new Rectangle(0x7fffffff, 0x7fffffff, 0, 0);
            _dc = new DoubleConverter();
            _sc = new SizeConverter();
            _pc = new PointConverter();
            _bc = new BooleanConverter();
            _cc = new ColorConverter();
        }
Ejemplo n.º 4
0
        public void LoadConfig(bool def = false)
        {
            if (def)
            {
                tabletOffset = new Point(0, 0);
                overrideBounds = new Rectangle(0, 0, 0, 0);
                smoothingStrength = 30;
                smoothingInterpolation = 4;
                overlayScreen = 0;
                tolerance = 300;
                manualInterpolation = false;
                stayOnTop = false;
                disableOverlay = false;
                allScreens = false;
                manualOverlayOverride = false;
                disableCatchUp = false;
                snapToCursor = false;
                smoothOnDraw = false;
                tabletOffsetOverride = false;
                disableAutoDetection = false;
                hotkeys[0] = "None";
                hotkeys[1] = "None";
                hotkeys[2] = "None";
                hotkeys[3] = "None";
                hotkeys[4] = "None";
                hotkeys[5] = "None";

                // Main window resetting
                mainForm.checkBox_smoothOnDraw.Checked = false;
                mainForm.checkBox_stayOnTop.Checked = false;
                mainForm.checkBox_tabletMode.Checked = false;
                mainForm.checkBox_tabletMode.Enabled = false;
                mainForm.checkBox_manualInterpolation.Checked = false;
                mainForm.trackBar_smoothingInterpolation.Enabled = false;
                mainForm.textBox_smoothingInterpolation.Enabled = false;
                mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString();
                mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString();
                mainForm.checkBox_smoothOnDraw.Checked = false;
                mainForm.TopMost = false;

                // Cursor and overlay resetting
                overlayForm.cursorColor = Color.FromArgb(128, 128, 128);
                overlayForm.cursorFillColor = Color.FromArgb(255, 255, 254);
                overlayForm.cursorType = Overlay.CursorType.Bullseye;
                overlayForm.Show();
                overlayForm.Bounds = Screen.PrimaryScreen.Bounds;
                mainForm.button_colorDialog.BackColor = overlayForm.cursorColor;

                // Hotkey resetting
                for (int i = 0; i < mainForm.hotKeyHandling.Count(); i++)
                {
                    try
                    {
                        mainForm.hotKeyHandling[i].Dispose();
                    }
                    catch
                    {
                        // Nothing to dispose!
                    }
                }
            }
            else
            {
                try
                {
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    // Main window loading
                    smoothingStrength = int.Parse(config.AppSettings.Settings["Strength"].Value);
                    smoothingInterpolation = int.Parse(config.AppSettings.Settings["Interpolation"].Value);
                    manualInterpolation = bool.Parse(config.AppSettings.Settings["Manual Interpolation"].Value);
                    smoothOnDraw = bool.Parse(config.AppSettings.Settings["Smooth On Draw"].Value);
                    stayOnTop = bool.Parse(config.AppSettings.Settings["Stay On Top"].Value);
                    disableAutoDetection = bool.Parse(config.AppSettings.Settings["Disable Auto Detection"].Value);
                    mainForm.tabletMode = bool.Parse(config.AppSettings.Settings["Tablet Mode"].Value);
                    mainForm.checkBox_tabletMode.Enabled = disableAutoDetection;
                    mainForm.checkBox_tabletMode.Checked = mainForm.tabletMode;
                    mainForm.checkBox_smoothOnDraw.Checked = smoothOnDraw;
                    if (manualInterpolation)
                    {
                        mainForm.checkBox_manualInterpolation.Checked = true;
                        mainForm.trackBar_smoothingInterpolation.Enabled = true;
                        mainForm.textBox_smoothingInterpolation.Enabled = true;
                    }
                    mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString();
                    mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString();
                    if (stayOnTop)
                    {
                        mainForm.checkBox_stayOnTop.Checked = true;
                        mainForm.TopMost = true;
                        overlayForm.TopMost = true;
                    }

                    // Cursor and overlay loading
                    overlayForm.cursorType = (Overlay.CursorType)Enum.Parse(typeof(Overlay.CursorType), config.AppSettings.Settings["Cursor Graphic"].Value);
                    overlayForm.cursorColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Main Color"].Value);
                    overlayForm.cursorFillColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Fill Color"].Value);
                    overlayScreen = int.Parse(config.AppSettings.Settings["Overlay Screen"].Value);
                    disableOverlay = bool.Parse(config.AppSettings.Settings["Disable Overlay"].Value);
                    allScreens = bool.Parse(config.AppSettings.Settings["All Screens"].Value);
                    manualOverlayOverride = bool.Parse(config.AppSettings.Settings["Manual Overlay Override"].Value);
                    RectangleConverter r = new RectangleConverter();
                    overrideBounds = (Rectangle)r.ConvertFromString(config.AppSettings.Settings["Override Bounds"].Value);
                    if (disableOverlay) overlayForm.Hide();
                    overlayForm.Bounds = Screen.AllScreens[overlayScreen].Bounds;
                    if (allScreens) overlayForm.Bounds = new Rectangle(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                    if (manualOverlayOverride) overlayForm.Bounds = overrideBounds;
                    mainForm.button_colorDialog.BackColor = overlayForm.cursorColor;

                    // ...and everything else
                    disableCatchUp = bool.Parse(config.AppSettings.Settings["Disable Catch Up"].Value);
                    snapToCursor = bool.Parse(config.AppSettings.Settings["Snap To Cursor"].Value);
                    tolerance = int.Parse(config.AppSettings.Settings["Tolerance"].Value);
                    tabletOffsetOverride = bool.Parse(config.AppSettings.Settings["Tablet Offset Override"].Value);
                    PointConverter p = new PointConverter();
                    tabletOffset = (Point)p.ConvertFromString(config.AppSettings.Settings["Tablet Offset"].Value);
                    KeysConverter c = new KeysConverter();
                    Keys k;
                    Hotkey.KeyModifiers m;
                    hotkeys[0] = config.AppSettings.Settings["Hotkey 1"].Value;
                    if (hotkeys[0] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 1"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 0, m, k);
                        }
                    }
                    hotkeys[1] = config.AppSettings.Settings["Hotkey 2"].Value;
                    if (hotkeys[1] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 2"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 1, m, k);
                        }
                    }
                    hotkeys[2] = config.AppSettings.Settings["Hotkey 3"].Value;
                    if (hotkeys[2] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 3"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 2, m, k);
                        }
                    }
                    hotkeys[3] = config.AppSettings.Settings["Hotkey 4"].Value;
                    if (hotkeys[3] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 4"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 3, m, k);
                        }
                    }
                    hotkeys[4] = config.AppSettings.Settings["Hotkey 5"].Value;
                    if (hotkeys[4] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 5"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 4, m, k);
                        }
                    }
                    hotkeys[5] = config.AppSettings.Settings["Hotkey 6"].Value;
                    if (hotkeys[5] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 6"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 5, m, k);
                        }
                    }
                }
                catch
                {
                    // Quietly fail loading bad configs or no configs
                }
            }
        }
Ejemplo n.º 5
0
 public void SaveConfig()
 {
     Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     config.AppSettings.Settings.Remove("Strength");
     config.AppSettings.Settings.Add("Strength", smoothingStrength.ToString());
     config.AppSettings.Settings.Remove("Interpolation");
     config.AppSettings.Settings.Add("Interpolation", smoothingInterpolation.ToString());
     config.AppSettings.Settings.Remove("Manual Interpolation");
     config.AppSettings.Settings.Add("Manual Interpolation", manualInterpolation.ToString());
     config.AppSettings.Settings.Remove("Smooth On Draw");
     config.AppSettings.Settings.Add("Smooth On Draw", smoothOnDraw.ToString());
     config.AppSettings.Settings.Remove("Stay On Top");
     config.AppSettings.Settings.Add("Stay On Top", stayOnTop.ToString());
     config.AppSettings.Settings.Remove("Tablet Mode");
     config.AppSettings.Settings.Add("Tablet Mode", mainForm.tabletMode.ToString());
     config.AppSettings.Settings.Remove("Overlay Screen");
     config.AppSettings.Settings.Add("Overlay Screen", overlayScreen.ToString());
     config.AppSettings.Settings.Remove("Disable Overlay");
     config.AppSettings.Settings.Add("Disable Overlay", disableOverlay.ToString());
     config.AppSettings.Settings.Remove("All Screens");
     config.AppSettings.Settings.Add("All Screens", allScreens.ToString());
     config.AppSettings.Settings.Remove("Manual Overlay Override");
     config.AppSettings.Settings.Add("Manual Overlay Override", manualOverlayOverride.ToString());
     config.AppSettings.Settings.Remove("Override Bounds");
     RectangleConverter r = new RectangleConverter();
     config.AppSettings.Settings.Add("Override Bounds", r.ConvertToString(overrideBounds));
     config.AppSettings.Settings.Remove("Disable Catch Up");
     config.AppSettings.Settings.Add("Disable Catch Up", disableCatchUp.ToString());
     config.AppSettings.Settings.Remove("Snap to Cursor");
     config.AppSettings.Settings.Add("Snap to Cursor", snapToCursor.ToString());
     config.AppSettings.Settings.Remove("Cursor Graphic");
     config.AppSettings.Settings.Add("Cursor Graphic", overlayForm.cursorType.ToString());
     config.AppSettings.Settings.Remove("Main Color");
     config.AppSettings.Settings.Add("Main Color", ColorTranslator.ToHtml(overlayForm.cursorColor));
     config.AppSettings.Settings.Remove("Fill Color");
     config.AppSettings.Settings.Add("Fill Color", ColorTranslator.ToHtml(overlayForm.cursorFillColor));
     config.AppSettings.Settings.Remove("Disable Auto Detection");
     config.AppSettings.Settings.Add("Disable Auto Detection", disableAutoDetection.ToString());
     config.AppSettings.Settings.Remove("Tolerance");
     config.AppSettings.Settings.Add("Tolerance", tolerance.ToString());
     config.AppSettings.Settings.Remove("Tablet Offset Override");
     config.AppSettings.Settings.Add("Tablet Offset Override", tabletOffsetOverride.ToString());
     config.AppSettings.Settings.Remove("Tablet Offset");
     PointConverter p = new PointConverter();
     config.AppSettings.Settings.Add("Tablet Offset", p.ConvertToString(tabletOffset));
     config.AppSettings.Settings.Remove("Hotkey 1");
     config.AppSettings.Settings.Add("Hotkey 1", hotkeys[0].ToString());
     config.AppSettings.Settings.Remove("Hotkey 2");
     config.AppSettings.Settings.Add("Hotkey 2", hotkeys[1].ToString());
     config.AppSettings.Settings.Remove("Hotkey 3");
     config.AppSettings.Settings.Add("Hotkey 3", hotkeys[2].ToString());
     config.AppSettings.Settings.Remove("Hotkey 4");
     config.AppSettings.Settings.Add("Hotkey 4", hotkeys[3].ToString());
     config.AppSettings.Settings.Remove("Hotkey 5");
     config.AppSettings.Settings.Add("Hotkey 5", hotkeys[4].ToString());
     config.AppSettings.Settings.Remove("Hotkey 6");
     config.AppSettings.Settings.Add("Hotkey 6", hotkeys[5].ToString());
     config.Save(ConfigurationSaveMode.Modified);
 }
Ejemplo n.º 6
0
        public override void OnFrame(Controller controller)
        {
            //get screens
            screens = controller.CalibratedScreens;

            //calculate fps
            double fps = 1.0 * Stopwatch.Frequency / (stopWatch.ElapsedTicks - lasttime);
            lasttime = stopWatch.ElapsedTicks;

            timeaccum += 1.0 / fps;
            framesaccum++;
            if (timeaccum >= 0.5)
            {
                UpdateText(form.fps_label, "fps: " + Convert.ToString((int)(1.0 * framesaccum / timeaccum)));
                timeaccum -= 0.5;
                framesaccum = 0;
            }

            bool wasd = false;
            float scale, yoffset,ws,ad;
            bool intersect;
            lock (thisLock) //get access to input data
            {
                scale = (float)form.sens;
                yoffset = (float)form.yoffset;
                ws = (float)form.wsval;
                ad = (float)form.adval;
                intersect = form.intersect;
                wasd = form.wasd_check.Checked;
            }

            //move phase for keyboard simulation
            phase += par / fps * freq;
            if (phase > 1)
            {
                par = -1;
                phase = 1;
            }
            if (phase < 0)
            {
                par = 1;
                phase = 0;
            }

            Pointable point1 = null;
            bool point1_ok = false;

            // Get the most recent frame
            Frame frame = controller.Frame();

            if (!frame.Tools.Empty)
            {
                //get the nearest tool
                int nearest = 0;
                double nearestval = double.MaxValue;
                ToolList tools = frame.Tools;
                for (int i = 0; i < tools.Count(); i++)
                {
                    if (tools[i].TipPosition.z < nearestval)
                    {
                        nearest = i;
                        nearestval = tools[i].TipPosition.z;
                    }
                }
                point1 = tools[nearest];
                point1_ok = true;
            }
            else if (!frame.Hands.Empty)
            {
                // Get the first hand
                Hand hand = frame.Hands[0];

                // Check if the hand has any fingers
                FingerList fingers = hand.Fingers;
                if (!fingers.Empty)
                {

                    //get the finger closest to the screen (smallest z)
                    int nearest = 0;
                    double nearestval = double.MaxValue;
                    for (int i = 0; i < fingers.Count(); i++)
                    {
                        if (fingers[i].TipPosition.z < nearestval)
                        {
                            nearest = i;
                            nearestval = fingers[i].TipPosition.z;
                        }
                    }
                    point1 = fingers[nearest];
                    point1_ok = true;

                }

            }

            if (point1_ok) //there is finger or tool
            {
                PointConverter pc = new PointConverter();
                Point pt = new Point();

                //wasd not checked
                if (!wasd)
                {
                    //interset/project on screen
                    Vector intersection;
                    if (intersect)
                        intersection = screens[0].Intersect(point1, true, 4.0f / scale);
                    else
                        intersection = screens[0].Project(point1.TipPosition, true, 4.0f / scale);

                    //scale and offset screen position
                    double scx = (intersection.x - 0.5) * scale + 0.5;
                    double scy = (1 - intersection.y - 0.5) * scale + 0.5 + yoffset;
                    pt.X = (int)(scx * screens[0].WidthPixels);
                    pt.Y = (int)(scy * screens[0].HeightPixels);

                    Cursor.Position = pt;
                }
                //if wasd is checked
                else
                {
                    string str = "";

                    float x = point1.TipPosition.x;
                    float y = point1.TipPosition.y;
                    float z = point1.TipPosition.z;

                    var hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
                    Hand hand = frame.Hands[0];

                    double xph = -hand.PalmNormal.Roll*ad*8; //steering using roll
                    double zph = (Math.Abs(hand.PalmPosition.z-100) - ws * 200.0) / (200.0 * ws); //acceleration using z

                    //stroke or release given keys

                    if (xph > 0 && Math.Abs(xph) > phase)
                    {
                        str += "D";
                        if (!pD || Math.Abs(xph) > 1)
                            Stroke(0x20);
                        pD = true;
                    }
                    else
                    {
                        if (pD)
                            Release(0x20);
                        pD = false;
                    }
                    if (xph < 0 && Math.Abs(xph) > phase)
                    {
                        str += "A";
                        if (!pA || Math.Abs(xph) > 1)
                            Stroke(0x1E);
                        pA = true;
                    }
                    else
                    {
                        if (pA)
                            Release(0x1E);
                        pA = false;
                    }

                    if (z > 0 && zph > phase)
                    {
                        str += "S";
                        if (!pS || zph > 1)
                            Stroke(0x1F);
                        pS = true;
                    }
                    else
                    {
                        if (pS)
                            Release(0x1F);
                        pS = false;
                    }
                    if (z < 0 && zph > phase)
                    {
                        str += "W";
                        if (!pW || zph > 1)
                            Stroke(0x11);
                        pW = true;
                    }
                    else
                    {
                        if (pW)
                            Release(0x11);
                        pW = false;
                    }

                    UpdateText(form.debug_label, Convert.ToString(str));
                }
            }
            else
            {
                if (pW)
                    Release(0x11);
                if (pA)
                    Release(0x1E);
                if (pS)
                    Release(0x1F);
                if (pD)
                    Release(0x20);
                pW = false;
                pA = false;
                pS = false;
                pD = false;
            }
        }