/// <summary> /// Initializes a new instance of the <see cref="Compositor"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="window">The window with which this compositor is associated.</param> public Compositor(UltravioletContext uv, IUltravioletWindow window) : base(uv) { Contract.Require(window, nameof(window)); this.window = window; }
/// <summary> /// Initializes a new instance of the <see cref="CustomCompositor"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="window">The window with which this compositor is associated.</param> public CustomCompositor(UltravioletContext uv, IUltravioletWindow window) : base(uv, window) { rtScene = RenderTarget2D.Create(BufferWidth, BufferHeight); rtSceneColor = RenderBuffer2D.Create(RenderBufferFormat.Color, BufferWidth, BufferHeight); rtScene.Attach(rtSceneColor); rtSceneDepthStencil = RenderBuffer2D.Create(RenderBufferFormat.Depth24Stencil8, BufferWidth, BufferHeight); rtScene.Attach(rtSceneDepthStencil); rtInterface = RenderTarget2D.Create(BufferWidth, BufferHeight); rtInterfaceColor = RenderBuffer2D.Create(RenderBufferFormat.Color, BufferWidth, BufferHeight); rtInterface.Attach(rtInterfaceColor); rtInterfaceDepthStencil = RenderBuffer2D.Create(RenderBufferFormat.Depth24Stencil8, BufferWidth, BufferHeight); rtInterface.Attach(rtInterfaceDepthStencil); rtComposition = RenderTarget2D.Create(BufferWidth, BufferHeight, RenderTargetUsage.PreserveContents); rtCompositionColor = RenderBuffer2D.Create(RenderBufferFormat.Color, BufferWidth, BufferHeight); rtComposition.Attach(rtCompositionColor); rtCompositionDepthStencil = RenderBuffer2D.Create(RenderBufferFormat.Depth24Stencil8, BufferWidth, BufferHeight); rtComposition.Attach(rtCompositionDepthStencil); spriteBatch = SpriteBatch.Create(); }
/// <inheritdoc/> public void ShowMessageBox(MessageBoxType type, String title, String message, IUltravioletWindow parent = null) { Contract.EnsureNotDisposed(this, Disposed); if (parent == null) parent = Windows.GetPrimary(); var flags = GetSDLMessageBoxFlag(type); var window = (parent == null) ? IntPtr.Zero : (IntPtr)((OpenGLUltravioletWindow)parent); if (SDL.ShowSimpleMessageBox(flags, title, message, window) < 0) throw new SDL2.SDL2Exception(); }
/// <summary> /// Opens the specified modal dialog box and returns a <see cref="Task"/> that completes /// when the modal dialog box is closed. /// </summary> /// <param name="window">The window in which to open the modal dialog box.</param> /// <param name="modal">The modal dialog box to open.</param> /// <param name="duration">The amount of time over which to transition the modal dialog /// box's state, or <see langword="null"/> to use the default transition time.</param> /// <returns>A <see cref="ModalTask{T}"/> that completes when the modal dialog box is closed.</returns> public static ModalTask <Boolean?> ShowDialogAsync(IUltravioletWindow window, Modal modal, TimeSpan?duration = null) { Contract.Require(modal, nameof(modal)); return(modal.ShowAsync(window, duration)); }
/// <inheritdoc/> public void ShowMessageBox(MessageBoxType type, String title, String message, IUltravioletWindow parent = null) { Contract.EnsureNotDisposed(this, Disposed); }
/// <summary> /// Handles the Ultraviolet context's <see cref="UltravioletContext.WindowDrawn"/> event. /// </summary> private void uv_WindowDrawn(UltravioletContext uv, UltravioletTime time, IUltravioletWindow window) { OnWindowDrawn(time, window); }
/// <summary> /// Handles the Ultraviolet window manager's PrimaryWindowChanged event. /// </summary> /// <param name="window">The primary window.</param> private void uv_PrimaryWindowChanged(IUltravioletWindow window) { HookPrimaryWindowEvents(); }
/// <summary> /// Called after one of the application's windows has been drawn. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> /// <param name="window">The window that was just drawn.</param> protected virtual void OnWindowDrawn(UltravioletTime time, IUltravioletWindow window) { }
/// <summary> /// Raises the <see cref="WheelScrolled"/> event. /// </summary> /// <param name="window">The window in which the input event took place.</param> /// <param name="x">The amount that the wheel was scrolled along the horizontal axis.</param> /// <param name="y">The amount that the wheel was scrolled along the vertical axis.</param> protected virtual void OnWheelScrolled(IUltravioletWindow window, Int32 x, Int32 y) => WheelScrolled?.Invoke(window, this, x, y);
/// <summary> /// Handles the Ultraviolet window's Drawing event. /// </summary> /// <param name="window">The window being rendered.</param> /// <param name="time">Time elapsed since the last call to Draw.</param> private void uvWindow_Drawing(IUltravioletWindow window, UltravioletTime time) { OnDrawing(EventArgs.Empty); }
/// <summary> /// Shows the modal and returns a <see cref="Task"/> which completes when /// the modal is closed. /// </summary> /// <param name="window">The window in which to show the modal.</param> /// <param name="duration">The amount of time over which to transition the screen's state, or <see langword="null"/> to use the default transition time.</param> /// <returns>A <see cref="Task"/> which completes when the modal is closed.</returns> private ModalTask<Boolean?> ShowAsync(IUltravioletWindow window, TimeSpan? duration = null) { var screen = Screen; if (screen == null) return new ModalTask<Boolean?>(new Task<Boolean?>(() => true)); var wasOpen = open; open = true; dialogResult = null; this.taskCompletionSource = new TaskCompletionSource<Boolean?>(); if (wasOpen) return new ModalTask<Boolean?>(this.taskCompletionSource.Task); OnOpening(); Open(window, screen, duration); return new ModalTask<Boolean?>(this.taskCompletionSource.Task); }
/// <summary> /// Opens the specified modal dialog box. /// </summary> /// <param name="window">The window in which to open the modal dialog box.</param> /// <param name="modal">The modal dialog box to open.</param> /// <param name="duration">The amount of time over which to transition the modal dialog /// box's state, or <see langword="null"/> to use the default transition time.</param> public static void ShowDialog(IUltravioletWindow window, Modal modal, TimeSpan? duration = null) { Contract.Require(modal, nameof(modal)); modal.Show(window, duration); }
/// <inheritdoc/> public UIScreenStack GetScreens(IUltravioletWindow window) { Contract.EnsureNotDisposed(this, Disposed); return((window == null) ? GetScreens() : screenStacks[window]); }
/// <summary> /// Handles the window manager's WindowDestroyed event. /// </summary> /// <param name="window">The window that was destroyed.</param> private void WindowInfo_WindowDestroyed(IUltravioletWindow window) { DestroyScreenStack(window); }
/// <summary> /// Handles the window manager's WindowCreated event. /// </summary> /// <param name="window">The window that was created.</param> private void WindowInfo_WindowCreated(IUltravioletWindow window) { CreateScreenStack(window); }
/// <summary> /// Handles a window's DrawingUI event. /// </summary> /// <param name="window">The window being drawn.</param> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> private void Window_DrawingUI(IUltravioletWindow window, UltravioletTime time) { screenStacks[window].Draw(time, spriteBatch); }
/// <inheritdoc/> protected override void OnWindowDestroyed(IUltravioletWindow window) { base.OnWindowDestroyed(window); }
/// <summary> /// Shows the modal and returns a <see cref="Task"/> which completes when /// the modal is closed. /// </summary> /// <param name="window">The window in which to show the modal.</param> /// <param name="screen">The screen on which the modal will be opened.</param> /// <param name="duration">The amount of time over which to transition the screen's state, or <see langword="null"/> to use the default transition time.</param> /// <returns>A <see cref="Task"/> which completes when the modal is closed.</returns> private void Open(IUltravioletWindow window, UIScreen screen, TimeSpan? duration = null) { var screenStack = screen.Ultraviolet.GetUI().GetScreens(window); if (screen.State != UIPanelState.Closed) screenStack.Close(screen, TimeSpan.Zero); if (!hooked) { screen.Closed += onClosedHandler; hooked = true; } screenStack.Open(screen, duration); }
/// <summary> /// Raises the <see cref="WindowDrawn"/> event. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> /// <param name="window">The window that was just drawn.</param> protected virtual void OnWindowDrawn(UltravioletTime time, IUltravioletWindow window) => WindowDrawn?.Invoke(this, time, window);
/// <summary> /// Creates a new instance of the <see cref="DefaultCompositor"/> class. /// </summary> /// <param name="window">The window with which the created compositor is associated.</param> /// <returns>The instance of <see cref="DefaultCompositor"/> that was created.</returns> public static DefaultCompositor Create(IUltravioletWindow window) { var uv = UltravioletContext.DemandCurrent(); return new DefaultCompositor(uv, window); }
/// <summary> /// Raises the <see cref="ButtonReleased"/> event. /// </summary> /// <param name="window">The window that raised the event.</param> /// <param name="scancode">The <see cref="Scancode"/> that represents the button that was released.</param> protected virtual void OnButtonReleased(IUltravioletWindow window, Scancode scancode) => ButtonReleased?.Invoke(window, this, scancode);
/// <summary> /// Raises the <see cref="Moved"/> event. /// </summary> /// <param name="window">The window in which the input event took place.</param> /// <param name="x">The x-coordinate of the mouse's current position.</param> /// <param name="y">The y-coordinate of the mouse's current position.</param> /// <param name="dx">The difference between the x-coordinate of the mouse's /// current position and the x-coordinate of the mouse's previous position.</param> /// <param name="dy">The difference between the y-coordinate of the mouse's /// current position and the y-coordinate of the mouse's previous position.</param> protected virtual void OnMoved(IUltravioletWindow window, Int32 x, Int32 y, Int32 dx, Int32 dy) => Moved?.Invoke(window, this, x, y, dx, dy);
/// <summary> /// Raises the <see cref="KeyPressed"/> event. /// </summary> /// <remarks>Platforms may send multiple key press events while a key is held down. Any such /// event after the first is marked as a "repeat" event and should be handled accordingly.</remarks> /// <param name="window">The window that raised the event.</param> /// <param name="key">The <see cref="Key"/> that was pressed.</param> /// <param name="ctrl">A value indicating whether the Control modifier is active.</param> /// <param name="alt">A value indicating whether the Alt modifier is active.</param> /// <param name="shift">A value indicating whether the Shift modifier is active.</param> /// <param name="repeat">A value indicating whether this is a repeated key press.</param> protected virtual void OnKeyPressed(IUltravioletWindow window, Key key, Boolean ctrl, Boolean alt, Boolean shift, Boolean repeat) { KeyPressed?.Invoke(window, this, key, ctrl, alt, shift, repeat); }
/// <summary> /// Gets the mouse cursor's position within the specified window. /// </summary> /// <param name="window">The window to evaluate.</param> /// <returns>The cursor's compositor-space position within the specified /// window, or <see langword="null"/> if the cursor is outside of the window.</returns> public abstract Point2?GetPositionInWindow(IUltravioletWindow window);
/// <summary> /// Raises the <see cref="KeyReleased"/> event. /// </summary> /// <param name="window">The window that raised the event.</param> /// <param name="key">The <see cref="Key"/> that was released.</param> protected virtual void OnKeyReleased(IUltravioletWindow window, Key key) { KeyReleased?.Invoke(window, this, key); }
/// <summary> /// Handles the Ultraviolet window manager's PrimaryWindowChanging event. /// </summary> /// <param name="window">The primary window.</param> private void uv_PrimaryWindowChanging(IUltravioletWindow window) { SaveSettings(); }
/// <summary> /// Raises the <see cref="TextInput"/> event. /// </summary> /// <param name="window">The window that raised the event.</param> protected virtual void OnTextInput(IUltravioletWindow window) { TextInput?.Invoke(window, this); }
/// <summary> /// Handles the Ultraviolet window's Drawing event. /// </summary> /// <param name="window">The window being drawn.</param> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> private void uv_Drawing(IUltravioletWindow window, UltravioletTime time) { OnDrawing(time); }
/// <summary> /// Raises the <see cref="TextEditing"/> event. /// </summary> /// <param name="window">The window that raised the event.</param> protected virtual void OnTextEditing(IUltravioletWindow window) { TextEditing?.Invoke(window, this); }
/// <summary> /// Initializes a new instance of the <see cref="UIScreenStack"/> class. /// </summary> /// <param name="window">The window that owns the screen stack.</param> internal UIScreenStack(IUltravioletWindow window) { this.window = window; }
/// <summary> /// Binds the touch device to the specified window. This window's coordinate system is used /// to denormalize touch coordinates. If no window is bound to the device, the primary window is used. /// </summary> /// <param name="window">The window to bind to the device.</param> public abstract void BindToWindow(IUltravioletWindow window);
/// <summary> /// Opens the specified modal dialog box. /// </summary> /// <param name="window">The window in which to open the modal dialog box.</param> /// <param name="modal">The modal dialog box to open.</param> /// <param name="duration">The amount of time over which to transition the modal dialog /// box's state, or <see langword="null"/> to use the default transition time.</param> public static void ShowDialog(IUltravioletWindow window, Modal modal, TimeSpan?duration = null) { Contract.Require(modal, nameof(modal)); modal.Show(window, duration); }
/// <summary> /// Cleans up a window's resources after it is destroyed. /// </summary> /// <param name="window">The window that was destroyed.</param> protected virtual void OnWindowCleanup(IUltravioletWindow window) { }
/// <summary> /// Raises the WindowCreated event. /// </summary> /// <param name="window">The window that was created.</param> protected void OnWindowCreated(IUltravioletWindow window) => WindowCreated?.Invoke(window);
/// <summary> /// Raises the WindowDestroyed event. /// </summary> /// <param name="window">The window that is being destroyed.</param> protected void OnWindowDestroyed(IUltravioletWindow window) => WindowDestroyed?.Invoke(window);
/// <summary> /// Opens the specified modal dialog box and returns a <see cref="Task"/> that completes /// when the modal dialog box is closed. /// </summary> /// <param name="window">The window in which to open the modal dialog box.</param> /// <param name="modal">The modal dialog box to open.</param> /// <param name="duration">The amount of time over which to transition the modal dialog /// box's state, or <see langword="null"/> to use the default transition time.</param> /// <returns>A <see cref="ModalTask{T}"/> that completes when the modal dialog box is closed.</returns> public static ModalTask<Boolean?> ShowDialogAsync(IUltravioletWindow window, Modal modal, TimeSpan? duration = null) { Contract.Require(modal, nameof(modal)); return modal.ShowAsync(window, duration); }
/// <summary> /// Designates the window that is currently associated with the specified OpenGL context. /// </summary> /// <param name="window">The window to designate as current.</param> /// <param name="openGLContext">A pointer to the OpenGL context.</param> public abstract void DesignateCurrentWindow(IUltravioletWindow window, IntPtr openGLContext);
/// <summary> /// Shows the modal. /// </summary> /// <param name="window">The window in which to show the modal.</param> /// <param name="duration">The amount of time over which to transition the screen's state, or <see langword="null"/> to use the default transition time.</param> private void Show(IUltravioletWindow window, TimeSpan? duration = null) { var screen = Screen; if (screen == null || open) return; open = true; dialogResult = null; this.taskCompletionSource = null; OnOpening(); Open(window, screen, duration); }
/// <summary> /// Raises the <see cref="ButtonReleased"/> event. /// </summary> /// <param name="window">The window in which the input event took place.</param> /// <param name="button">The mouse button that was released.</param> protected virtual void OnButtonReleased(IUltravioletWindow window, MouseButton button) => ButtonReleased?.Invoke(window, this, button);
/// <summary> /// Initializes a new instance of the <see cref="DefaultCompositor"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="window">The window with which this compositor is associated.</param> public DefaultCompositor(UltravioletContext uv, IUltravioletWindow window) : base(uv, window) { }
/// <summary> /// Raises the <see cref="DoubleClick"/> event. /// </summary> /// <param name="window">The window in which the input event took place.</param> /// <param name="button">The mouse button that was clicked.</param> protected virtual void OnDoubleClick(IUltravioletWindow window, MouseButton button) => DoubleClick?.Invoke(window, this, button);
/// <summary> /// Gets the screen stack associated with the specified window. /// </summary> /// <param name="window">The window for which to retrieve a screen stack, /// or <see langword="null"/> to retrieve the screen stack for the primary window.</param> /// <returns>The <see cref="UIScreenStack"/> associated with the specified window.</returns> public UIScreenStack GetScreens(IUltravioletWindow window) { Contract.EnsureNotDisposed(this, Disposed); return (window == null) ? GetScreens() : screenStacks[window]; }
protected override void OnWindowDrawing(UltravioletTime time, IUltravioletWindow window) { windowHeight = window.ClientSize.Height; windowWidth = window.ClientSize.Width; base.OnWindowDrawing(time, window); }