From 056ce6312ca49a66106d505fea122b8acc7cc896 Mon Sep 17 00:00:00 2001 From: Drakulix Date: Fri, 21 Apr 2017 22:21:19 +0200 Subject: [PATCH] Add set_cursor_representation --- src/backend/glutin.rs | 12 +++++++++++- src/backend/graphics/mod.rs | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/backend/glutin.rs b/src/backend/glutin.rs index e635f7e..7bc4048 100644 --- a/src/backend/glutin.rs +++ b/src/backend/glutin.rs @@ -6,7 +6,7 @@ use backend::graphics::GraphicsBackend; use backend::graphics::opengl::{Api, OpenglGraphicsBackend, PixelFormat, SwapBuffersError}; use backend::input::{Axis, AxisSource, InputBackend, InputHandler, KeyState, MouseButton, MouseButtonState, 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, HeadlessRendererBuilder, MouseScrollDelta, Touch, TouchPhase, Window, WindowBuilder}; use nix::c_void; @@ -81,10 +81,14 @@ impl GlutinHeadlessRenderer { } impl GraphicsBackend for GlutinHeadlessRenderer { + type CursorFormat = (); + fn set_cursor_position(&mut self, _x: u32, _y: u32) -> Result<(), ()> { //FIXME: Maybe save position? Is it of any use? Ok(()) } + + fn set_cursor_representation(&mut self, cursor: ()) {} } impl OpenglGraphicsBackend for GlutinHeadlessRenderer { @@ -139,6 +143,8 @@ impl GlutinWindowedRenderer { } impl GraphicsBackend for GlutinWindowedRenderer { + type CursorFormat = MouseCursor; + fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()> { if let Some((win_x, win_y)) = self.window.get_position() { self.window @@ -147,6 +153,10 @@ impl GraphicsBackend for GlutinWindowedRenderer { Err(()) } } + + fn set_cursor_representation(&mut self, cursor: MouseCursor) { + self.window.set_cursor(cursor); + } } impl OpenglGraphicsBackend for GlutinWindowedRenderer { diff --git a/src/backend/graphics/mod.rs b/src/backend/graphics/mod.rs index 9d1cdde..4ad08f8 100644 --- a/src/backend/graphics/mod.rs +++ b/src/backend/graphics/mod.rs @@ -5,6 +5,9 @@ /// General functions any graphics backend should support independently from it's rendering /// techique. pub trait GraphicsBackend { + /// Format representing the image drawn for the cursor. + type CursorFormat; + /// Sets the cursor position and therefor updates the drawn cursors position. /// 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. /// 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;