Beispiel #1
0
        /// <summary>
        /// Creates a UIWorkspace instance. If an instance already exists, a UIException is thrown.
        /// </summary>
        /// <param name="displaySize">The size of the surrounding display in screen coordinates.</param>
        /// <param name="workspaceSize">
        /// The size of the workspace in workspace coordinates.
        /// </param>
        /// <remarks>
        /// The workspace size must be less than or equals with the display size. The position of the workspace
        /// will be automatically set to the middle of the display. The pixel scaling of the workspace will be
        /// automatically set to the greatest possible values in both dimensions such that it is entirely contained
        /// by the display.
        /// </remarks>
        public UIWorkspace(RCIntVector displaySize, RCIntVector workspaceSize)
        {
            if (theInstance != null)
            {
                throw new UIException("An instance of UIWorkspace already exists!");
            }
            if (displaySize == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("displaySize");
            }
            if (displaySize.X <= 0 || displaySize.Y <= 0)
            {
                throw new ArgumentOutOfRangeException("displaySize");
            }
            if (workspaceSize == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("workspaceSize");
            }
            if (workspaceSize.X <= 0 || workspaceSize.Y <= 0)
            {
                throw new ArgumentOutOfRangeException("workspaceSize");
            }
            if (workspaceSize.X > displaySize.X || workspaceSize.Y > displaySize.Y)
            {
                throw new ArgumentException("displaySize must be greater than or equal with workspaceSize!");
            }

            this.activePage      = null;
            this.openedDialog    = null;
            this.registeredPages = new RCSet <UIPage>();

            /// Construct the underlying objects.
            RCIntVector pixelScaling = new RCIntVector(displaySize.X / workspaceSize.X, displaySize.Y / workspaceSize.Y);

            this.display = new UIObject(new RCIntVector(1, 1), new RCIntVector(0, 0), new RCIntRectangle(0, 0, displaySize.X, displaySize.Y));
            RCIntVector scaledAreaPos = (displaySize - workspaceSize * pixelScaling) / 2;

            this.scaledArea = new UIObject(pixelScaling, scaledAreaPos, new RCIntRectangle(0, 0, workspaceSize.X, workspaceSize.Y));
            this.workspace  = new UISensitiveObject(new RCIntVector(0, 0), new RCIntRectangle(0, 0, workspaceSize.X, workspaceSize.Y));

            /// Construct the root of the object tree.
            this.display.Attach(this.scaledArea);
            this.scaledArea.Attach(this.workspace);
            this.mouseManager = new UIMouseManager(this.workspace);

            /// Subscribe for the illegal events of the display and the scaled area.
            this.SubscribeForInvalidTreeOperations(this.display);
            this.SubscribeForInvalidTreeOperations(this.scaledArea);

            /// Attach the display to the render manager.
            UIRoot.Instance.GraphicsPlatform.RenderManager.Attach(this.display);

            /// Register the "RC.UI.UIWorkspace.PixelScaling" resolver method for the configuration files
            DynamicString.RegisterResolver(
                "RC.UI.UIWorkspace.PixelScaling",
                delegate() { return(string.Format("{0};{1}", this.PixelScaling.X, this.PixelScaling.Y)); });

            theInstance = this;
            TraceManager.WriteAllTrace("UIWorkspace.Instance created", UITraceFilters.INFO);
        }
Beispiel #2
0
        public static void Test()
        {
            ConfigurationManager.Initialize("../../../../config/RC.UI.Test/RC.UI.Test.root");
            UIRoot   root      = new UIRoot();
            Assembly xnaPlugin = Assembly.Load("RC.UI.XnaPlugin, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");

            root.LoadPlugins(xnaPlugin);
            root.InstallPlugins();

            DynamicString.RegisterResolver("RC.UI.UIWorkspace.PixelScaling",
                                           delegate()
            {
                return("2;2");
            });
            UIResourceManager.LoadResourceGroup("RC.App.SplashScreen");
            UIResourceManager.LoadResourceGroup("RC.App.CommonResources");

            UISprite mouseIcon = root.GraphicsPlatform.SpriteManager.LoadSprite("..\\..\\..\\..\\sprites\\pointers\\normal_pointer.png", new RCIntVector(2, 2));

            mouseIcon.TransparentColor = new RCColor(255, 0, 255);
            mouseIcon.Upload();
            UIPointer pointer = new UIPointer(mouseIcon, new RCIntVector(0, 0));

            display   = new TestUIObject(new RCIntVector(2, 2), new RCIntVector(0, 0), new RCIntRectangle(0, 0, 400, 300));
            workspace = new MySensitiveAnimObject(new RCIntVector(40, 50), new RCIntRectangle(0, 0, 320, 200),
                                                  "Workspace", RCColor.Gray, RCColor.Gray);
            display.Attach(workspace);

            MyButton button = new MyButton(new RCIntVector(5, 12), new RCIntVector(60, 20),
                                           RCColor.Brown, RCColor.Yellow, RCColor.White,
                                           "MyButton");
            //button.MouseSensor.Enter += delegate(UISensitiveObject sender) { Console.WriteLine("BUTTON ENTER"); };
            //button.MouseSensor.Move += delegate(UISensitiveObject sender, UIMouseEventArgs args) { Console.WriteLine("BUTTON MOVE"); };
            //button.MouseSensor.Leave += delegate(UISensitiveObject sender) { Console.WriteLine("BUTTON LEAVE"); };
            MyCheckbox checkbox = new MyCheckbox(new RCIntVector(70, 12), new RCIntVector(80, 20),
                                                 RCColor.Red, RCColor.Green, RCColor.LightRed, RCColor.LightGreen, RCColor.White,
                                                 "MyCheckbox");
            MyDropdownSelector selector = new MyDropdownSelector(new RCIntVector(5, 50), new RCIntVector(60, 20),
                                                                 new string[4] {
                "option0", "option1", "option2", "option3"
            },
                                                                 RCColor.WhiteHigh, RCColor.Red,
                                                                 RCColor.Green, RCColor.LightGreen, RCColor.LightBlue, RCColor.Gray);
            //selector.MouseSensor.Enter += delegate(UISensitiveObject sender) { Console.WriteLine("SELECTOR ENTER"); };
            //selector.MouseSensor.Move += delegate(UISensitiveObject sender, UIMouseEventArgs args) { Console.WriteLine("SELECTOR MOVE"); };
            //selector.MouseSensor.Leave += delegate(UISensitiveObject sender) { Console.WriteLine("SELECTOR LEAVE"); };
            MySlider sliderHorz = new MySlider(new RCIntVector(5, 80), new RCIntVector(80, 10),
                                               new UISlider.Settings()
            {
                Alignment            = UISlider.Alignment.Horizontal,
                IntervalLength       = 10,
                SliderBottom         = 3,
                SliderLeft           = 1,
                SliderRight          = 1,
                SliderTop            = 3,
                TimeBetweenTrackings = 300,
                TrackingValueChange  = 3,
                TrackPos             = new RCIntVector(10, 5),
                TrackSize            = new RCIntVector(60, 1)
            },
                                               RCColor.Green, RCColor.LightGreen, RCColor.White);
            MySlider sliderVert = new MySlider(new RCIntVector(5, 100), new RCIntVector(10, 80),
                                               new UISlider.Settings()
            {
                Alignment            = UISlider.Alignment.Vertical,
                IntervalLength       = 10,
                SliderBottom         = 1,
                SliderLeft           = 3,
                SliderRight          = 3,
                SliderTop            = 1,
                TimeBetweenTrackings = 300,
                TrackingValueChange  = 3,
                TrackPos             = new RCIntVector(5, 10),
                TrackSize            = new RCIntVector(60, 1)
            },
                                               RCColor.Green, RCColor.LightGreen, RCColor.White);

            workspace.Attach(button);
            workspace.Attach(checkbox);
            workspace.Attach(selector);
            workspace.Attach(sliderHorz);
            workspace.Attach(sliderVert);
            workspace.AttachSensitive(button);
            workspace.AttachSensitive(checkbox);
            workspace.AttachSensitive(selector);
            workspace.AttachSensitive(sliderHorz);
            workspace.AttachSensitive(sliderVert);
            button.Pressed += delegate(UISensitiveObject sender)
            {
                TraceManager.WriteAllTrace("BUTTON PRESSED", TraceManager.GetTraceFilterID("RC.UI.Test.Info"));
                checkbox.IsEnabled = !checkbox.IsEnabled;
            };
            checkbox.CheckedStateChanged += delegate(UISensitiveObject sender)
            {
                TraceManager.WriteAllTrace("CHECKBOX STATE CHANGED", TraceManager.GetTraceFilterID("RC.UI.Test.Info"));
                button.IsEnabled = checkbox.IsChecked;
            };
            selector.SelectedIndexChanged += delegate(UISensitiveObject sender)
            {
                TraceManager.WriteAllTrace("SELECTED INDEX CHANGED", TraceManager.GetTraceFilterID("RC.UI.Test.Info"));
            };
            sliderHorz.SelectedValueChanged += delegate(UISensitiveObject sender)
            {
                TraceManager.WriteAllTrace(string.Format("SELECTED VALUE CHANGED (horizontal): {0}", sliderHorz.SelectedValue), TraceManager.GetTraceFilterID("RC.UI.Test.Info"));
            };
            sliderVert.SelectedValueChanged += delegate(UISensitiveObject sender)
            {
                TraceManager.WriteAllTrace(string.Format("SELECTED VALUE CHANGED (vertical): {0}", sliderVert.SelectedValue), TraceManager.GetTraceFilterID("RC.UI.Test.Info"));
            };

            UIMouseManager mouseMgr = new UIMouseManager(workspace);

            mouseMgr.SetDefaultMousePointer(pointer);

            root.GraphicsPlatform.RenderManager.Attach(display);
            root.GraphicsPlatform.RenderLoop.Start(new RCIntVector(800, 600));

            root.Dispose();
        }
Beispiel #3
0
        public static void Test()
        {
            ConfigurationManager.Initialize("../../../../config/RC.UI.Test/RC.UI.Test.root");
            UIRoot   root      = new UIRoot();
            Assembly xnaPlugin = Assembly.Load("RC.UI.XnaPlugin, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");

            root.LoadPlugins(xnaPlugin);
            root.InstallPlugins();

            UISprite mouseIcon = root.GraphicsPlatform.SpriteManager.LoadSprite("..\\..\\..\\..\\sprites\\pointers\\normal_pointer.png", new RCIntVector(2, 2));

            mouseIcon.TransparentColor = new RCColor(255, 0, 255);
            mouseIcon.Upload();
            UIPointer pointer = new UIPointer(mouseIcon, new RCIntVector(0, 0));

            DynamicString.RegisterResolver("RC.UI.UIWorkspace.PixelScaling",
                                           delegate()
            {
                return("2;2");
            });
            UIResourceManager.LoadResourceGroup("RC.App.SplashScreen");
            UIResourceManager.LoadResourceGroup("RC.App.CommonResources");

            display   = new TestUIObject(new RCIntVector(2, 2), new RCIntVector(0, 0), new RCIntRectangle(0, 0, 400, 300));
            workspace = new MySensitiveObject(new RCIntVector(40, 50), new RCIntRectangle(0, 0, 320, 200),
                                              "Workspace", RCColor.Gray, RCColor.Gray);
            display.Attach(workspace);

            MySensitiveObject objA = new MySensitiveObject(new RCIntVector(5, 12), new RCIntRectangle(0, 0, 130, 90), "A", RCColor.Blue, RCColor.LightBlue);
            MySensitiveObject objB = new MySensitiveObject(new RCIntVector(5, 107), new RCIntRectangle(0, 0, 130, 90), "B", RCColor.Blue, RCColor.LightBlue);
            MyDraggableObject objC = new MyDraggableObject(new RCIntVector(140, 12), new RCIntRectangle(0, 0, 130, 180), "C", RCColor.Cyan, RCColor.LightCyan);

            workspace.Attach(objA);
            workspace.Attach(objB);
            workspace.Attach(objC);
            workspace.AttachSensitive(objA);
            workspace.AttachSensitive(objB);
            workspace.AttachSensitive(objC);

            MySensitiveObject objAA = new MySensitiveObject(new RCIntVector(5, 12), new RCIntRectangle(0, 0, 120, 30), "AA", RCColor.Green, RCColor.LightGreen);
            MySensitiveObject objAB = new MySensitiveObject(new RCIntVector(5, 47), new RCIntRectangle(0, 0, 120, 30), "AB", RCColor.Green, RCColor.LightGreen);
            MySensitiveObject objBA = new MySensitiveObject(new RCIntVector(5, 12), new RCIntRectangle(0, 0, 120, 30), "BA", RCColor.Green, RCColor.LightGreen);
            MySensitiveObject objBB = new MySensitiveObject(new RCIntVector(5, 47), new RCIntRectangle(0, 0, 120, 30), "BB", RCColor.Green, RCColor.LightGreen);
            MyDraggableObject objCA = new MyDraggableObject(new RCIntVector(5, 12), new RCIntRectangle(0, 0, 120, 30), "CA", RCColor.Magenta, RCColor.LightMagenta);
            MyDraggableObject objCB = new MyDraggableObject(new RCIntVector(5, 47), new RCIntRectangle(0, 0, 120, 30), "CB", RCColor.Gray, RCColor.White);

            objA.Attach(objAA);
            objA.Attach(objAB);
            objB.Attach(objBA);
            objB.Attach(objBB);
            objC.Attach(objCA);
            objC.Attach(objCB);
            objA.AttachSensitive(objAA);
            objA.AttachSensitive(objAB);
            objB.AttachSensitive(objBA);
            objB.AttachSensitive(objBB);
            objC.AttachSensitive(objCA);
            objC.AttachSensitive(objCB);

            //root.SystemEventQueue.Subscribe<UIKeyboardEventArgs>(OnKeyboardEvent);
            //root.SystemEventQueue.Subscribe<UIMouseEventArgs>(OnMouseEvent);

            UIMouseManager mouseMgr = new UIMouseManager(workspace);

            mouseMgr.SetDefaultMousePointer(pointer);

            root.GraphicsPlatform.RenderManager.Attach(display);
            root.GraphicsPlatform.RenderLoop.Start(new RCIntVector(800, 600));

            root.Dispose();
        }