예제 #1
0
        private void initInput()
        {
            selections = new List <Tuple <string, Color> >
            {
                new Tuple <string, Color>("Red", new Color(231, 76, 60)),
                new Tuple <string, Color>("Green", new Color(46, 204, 113)),
                new Tuple <string, Color>("Blue", new Color(52, 152, 219)),
                new Tuple <string, Color>("Yellow", new Color(241, 196, 15)),
                new Tuple <string, Color>("Turquoise", new Color(26, 188, 156)),
                new Tuple <string, Color>("Purple", new Color(155, 89, 182)),
                new Tuple <string, Color>("Orange", new Color(230, 126, 34)),
                new Tuple <string, Color>("White", Color.White),
            };

            rw.KeyPressed += (s, a) =>
            {
                switch (a.Code)
                {
                case Keyboard.Key.Num1:
                    selection = 0;
                    break;

                case Keyboard.Key.Num2:
                    selection = 1;
                    break;

                case Keyboard.Key.Num3:
                    selection = 2;
                    break;

                case Keyboard.Key.Num4:
                    selection = 3;
                    break;

                case Keyboard.Key.Num5:
                    selection = 4;
                    break;

                case Keyboard.Key.Num6:
                    selection = 5;
                    break;

                case Keyboard.Key.Num7:
                    selection = 6;
                    break;

                case Keyboard.Key.Num8:
                    selection = 7;
                    break;

                case Keyboard.Key.R:
                {
                    quadtree.Set(Color.White);
                    lastRegions = quadtree.FindConnectedComponents();
                    lastRegions.Sort(new Comparison <List <RegionQuadtree <Color> > >((v1, v2) => v1.Count.CompareTo(v2.Count)));
                    break;
                }

                case Keyboard.Key.E:
                {
                    if (qtResolution > 18)
                    {
                        break;
                    }

                    quadtree.ExpandFromCenter();
                    break;
                }
                }
            };

            rw.MouseWheelMoved += (s, a) =>
            {
                selectionRadius += 10 * a.Delta;
                if (selectionRadius < 0)
                {
                    selectionRadius = 0;
                }

                radiusText.DisplayedString = "Radius " + selectionRadius;
            };

            selectionText          = new Text("", fontBold, 32u);
            selectionText.Position = getGUIPos(0.03f, 0.03f);

            radiusText          = new Text("Radius " + selectionRadius, fontBold, 32u);
            radiusText.Position = getGUIPos(0.3f, 0.03f);

            resolutionText          = new Text("Resolution " + quadtree.AABB.Width * qtMultiplier + "x" + quadtree.AABB.Height * qtMultiplier, fontBold, 32u);
            resolutionText.Position = getGUIPos(0.6f, 0.03f);

            helpText                 = new Text("", fontNormal, 20u);
            helpText.Position        = getGUIPos(0.6f, 0.1f);
            helpText.DisplayedString = "Use numbers 1 - 8 to select a color.\n\nLeft click to place current color.\n\nRight click to remove.\n\nMouse wheel to change radius.\n\nR to reset.";
        }