Add set_cursor_representation

This commit is contained in:
Drakulix 2017-04-21 22:21:19 +02:00
parent 9b6273f297
commit 056ce6312c
2 changed files with 21 additions and 1 deletions

View File

@ -6,7 +6,7 @@ use backend::graphics::GraphicsBackend;
use backend::graphics::opengl::{Api, OpenglGraphicsBackend, PixelFormat, SwapBuffersError}; use backend::graphics::opengl::{Api, OpenglGraphicsBackend, PixelFormat, SwapBuffersError};
use backend::input::{Axis, AxisSource, InputBackend, InputHandler, KeyState, MouseButton, MouseButtonState, use backend::input::{Axis, AxisSource, InputBackend, InputHandler, KeyState, MouseButton, MouseButtonState,
Seat, SeatCapabilities, TouchEvent, TouchSlot, Output}; Seat, SeatCapabilities, TouchEvent, TouchSlot, Output};
use glutin::{Api as GlutinApi, MouseButton as GlutinMouseButton, PixelFormat as GlutinPixelFormat}; use glutin::{Api as GlutinApi, MouseButton as GlutinMouseButton, PixelFormat as GlutinPixelFormat, MouseCursor};
use glutin::{ContextError, CreationError, ElementState, Event, GlContext, HeadlessContext, use glutin::{ContextError, CreationError, ElementState, Event, GlContext, HeadlessContext,
HeadlessRendererBuilder, MouseScrollDelta, Touch, TouchPhase, Window, WindowBuilder}; HeadlessRendererBuilder, MouseScrollDelta, Touch, TouchPhase, Window, WindowBuilder};
use nix::c_void; use nix::c_void;
@ -81,10 +81,14 @@ impl GlutinHeadlessRenderer {
} }
impl GraphicsBackend for GlutinHeadlessRenderer { impl GraphicsBackend for GlutinHeadlessRenderer {
type CursorFormat = ();
fn set_cursor_position(&mut self, _x: u32, _y: u32) -> Result<(), ()> { fn set_cursor_position(&mut self, _x: u32, _y: u32) -> Result<(), ()> {
//FIXME: Maybe save position? Is it of any use? //FIXME: Maybe save position? Is it of any use?
Ok(()) Ok(())
} }
fn set_cursor_representation(&mut self, cursor: ()) {}
} }
impl OpenglGraphicsBackend for GlutinHeadlessRenderer { impl OpenglGraphicsBackend for GlutinHeadlessRenderer {
@ -139,6 +143,8 @@ impl GlutinWindowedRenderer {
} }
impl GraphicsBackend for GlutinWindowedRenderer { impl GraphicsBackend for GlutinWindowedRenderer {
type CursorFormat = MouseCursor;
fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()> { fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()> {
if let Some((win_x, win_y)) = self.window.get_position() { if let Some((win_x, win_y)) = self.window.get_position() {
self.window self.window
@ -147,6 +153,10 @@ impl GraphicsBackend for GlutinWindowedRenderer {
Err(()) Err(())
} }
} }
fn set_cursor_representation(&mut self, cursor: MouseCursor) {
self.window.set_cursor(cursor);
}
} }
impl OpenglGraphicsBackend for GlutinWindowedRenderer { impl OpenglGraphicsBackend for GlutinWindowedRenderer {

View File

@ -5,6 +5,9 @@
/// General functions any graphics backend should support independently from it's rendering /// General functions any graphics backend should support independently from it's rendering
/// techique. /// techique.
pub trait GraphicsBackend { pub trait GraphicsBackend {
/// Format representing the image drawn for the cursor.
type CursorFormat;
/// Sets the cursor position and therefor updates the drawn cursors position. /// Sets the cursor position and therefor updates the drawn cursors position.
/// Useful as well for e.g. pointer wrapping. /// Useful as well for e.g. pointer wrapping.
/// ///
@ -17,6 +20,13 @@ pub trait GraphicsBackend {
/// the position after every recieved event, but don't rely on pointer wrapping working. /// the position after every recieved event, but don't rely on pointer wrapping working.
/// ///
fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()>; fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()>;
/// Set the cursor drawn on the `GraphicsBackend`.
///
/// The format is entirely dictated by the concrete implementation and might range
/// from raw image buffers over a fixed list of possible cursor types to simply the
/// void type () to represent no possible customization of the cursor itself.
fn set_cursor_representation(&mut self, cursor: Self::CursorFormat);
} }
pub mod software; pub mod software;