/// <summary> /// Constructs a default window manager that holds the device (owner) in shared mode. /// </summary> public DefaultWindowManager(GraphicsDevice device, RenderTargetView renderTarget, Input.InputService input, IGuiTheme theme) { // Rendering data. this.device = device; this.renderTarget = renderTarget; // Input data. this.processor = new EventProcessor(new EventPump(input.CreateDevice(InputDeviceType.Mouse), input.CreateDevice(InputDeviceType.Keyboard))); // We bind events. this.processor.KeyDown += KeyDown; this.processor.KeyUp += KeyUp; this.processor.MouseButtonDown += MouseButtonDown; this.processor.MouseButtonUp += MouseButtonUp; this.processor.MouseAxis += MouseAxis; // We create "desktop manager". this.desktopManager = new GuiManager(new GraphicsCanvas(device, renderTarget, new Vector2f(1.0f, 1.0f))); this.pointer = new SharpMedia.Graphics.GUI.Standalone.GuiPointer(desktopManager, processor, null, null, new SharpMedia.Graphics.GUI.Standalone.Sensitivity()); theme.AutomaticApply(this.pointer, false); // FIXME: add pointer somehow to be "forward" this.desktopManager.AddNLObject(pointer); // We create composition. this.compositor = new Compositor(device); }
public void SimpleGUI(IDeviceCanvas canvas, IGuiTheme theme, Input.InputService input) { canvas.PointsPerPixel = 0.001f; using (GuiManager manager = new GuiManager(canvas)) { // We create a simple area. Area area = new Area(); using (area.Enter()) { // We create a hiearchical style. Style style = Style.Create <Area.AreaStyle>(); Area.AreaStyle astyle = new Area.AreaStyle(); astyle.Background.Fill = new SolidFill(Colour.LightBlue); astyle.Border.Pen = new Pen(new SolidFill(Colour.Gray), 0.003f, 0.0f, LineMode.Square); style.AddStyle(CommonStyleStates.Normal, astyle); astyle = new Area.AreaStyle(); astyle.Background.Fill = new SolidFill(Colour.LightGreen); astyle.Border.Pen = new Pen(new SolidFill(Colour.Gray), 0.003f, 0.0f, LineMode.Square); style.AddStyle(CommonStyleStates.PointerOver, astyle); // We apply style. area.Style = style; area.PreferredRect = GuiRect.CreateRectangle(new GuiVector2(new Vector2f(0.1f, 0.1f)), new GuiVector2(new Vector2f(0.4f, 0.4f))); } Button button = new Button( GuiRect.CreateRectangle( new GuiVector2(new Vector2f(0.1f, 0.6f)), new GuiVector2(new Vector2f(0.4f, 0.9f)) ), "Click me!", null); Label label = new Label(); using (label.Enter()) { label.Text = "SharpMedia rocks!"; label.PreferredRect = GuiRect.CreateRectangle(new GuiVector2(new Vector2f(0.6f, 0.6f)), new GuiVector2(new Vector2f(0.9f, 0.9f))); label.TextSelectedRange = new Vector2i(1, 5); } Label label2 = new Label(); using (label2.Enter()) { label2.PreferredRect = GuiRect.CreateRectangle(new GuiVector2(new Vector2f(0.6f, 0.1f)), new GuiVector2(new Vector2f(0.9f, 0.4f))); label2.IsEnabled = false; label.Events.TextSelect += delegate(Label xlabel, Vector2i sel) { using (label2.Enter()) { label2.Text = xlabel.SelectedText; } }; button.Events.ButtonClicked += delegate(Button button2) { using (label2.Enter()) { label2.Text += label2.Text; } }; } Container sheet = new Container(); using (sheet.Enter()) { sheet.AddChild(area); sheet.AddChild(label2); sheet.AddChild(button); sheet.AddChild(label); } // We apply theme. theme.AutomaticApply(sheet, true); manager.RootObject = sheet; manager.PreRendering += new Action <GuiManager>(PreRendering); manager.Rendered += new Action <GuiManager>(PostRendering); EventPump pump = new EventPump(input.CreateDevice(InputDeviceType.Mouse), input.CreateDevice(InputDeviceType.Keyboard), input.CreateDevice(InputDeviceType.Cursor)); EventProcessor processor = new EventProcessor(pump); // We bind input. Standalone.InputRouter router = new Standalone.InputRouter(manager, processor, theme.ObtainStyle(typeof(Standalone.GuiPointer), null), theme.ObtainRenderer(typeof(Standalone.GuiPointer), null), null); bool end = false; canvas.Device.SwapChain.Window.Closed += delegate(Window w) { end = true; }; DateTime time = DateTime.Now; while (!end) { canvas.Device.SwapChain.Window.DoEvents(); while (processor.Process() != null) { ; } // We update iut. DateTime t = DateTime.Now; manager.Update((float)(t - time).TotalSeconds); time = t; // We render it. manager.Render(); Console.WriteLine(canvas.Device.DevicePerformance.CurrentFPS); canvas.Device.SwapChain.Present(); } // Must dispose before it, devices bound so also disposed. pump.Dispose(); } }