Create custom cursor with directly with event loop
Replace the `CustomCursorBuilder` with the `CustomCursorSource` and perform the loading of the cursor via the `EventLoop::create_custom_cursor` instead of passing it to the builder itself. This follows the `EventLoop::create_window` API.
This commit is contained in:
parent
3fb93b4f83
commit
7abd427216
26 changed files with 213 additions and 175 deletions
|
|
@ -81,6 +81,7 @@ use crate::{
|
|||
dark_mode::try_theme,
|
||||
dpi::{become_dpi_aware, dpi_to_scale_factor},
|
||||
drop_handler::FileDropHandler,
|
||||
icon::WinCursor,
|
||||
ime::ImeContext,
|
||||
keyboard::KeyEventBuilder,
|
||||
keyboard_layout::LAYOUT_CACHE,
|
||||
|
|
@ -90,7 +91,7 @@ use crate::{
|
|||
window_state::{CursorFlags, ImeState, WindowFlags, WindowState},
|
||||
wrap_device_id, Fullscreen, WindowId, DEVICE_ID,
|
||||
},
|
||||
window::WindowId as RootWindowId,
|
||||
window::{CustomCursor as RootCustomCursor, CustomCursorSource, WindowId as RootWindowId},
|
||||
};
|
||||
use runner::{EventLoopRunner, EventLoopRunnerShared};
|
||||
|
||||
|
|
@ -531,6 +532,18 @@ impl ActiveEventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_custom_cursor(&self, source: CustomCursorSource) -> RootCustomCursor {
|
||||
let inner = match WinCursor::new(&source.inner.0) {
|
||||
Ok(cursor) => cursor,
|
||||
Err(err) => {
|
||||
log::warn!("Failed to create custom cursor: {err}");
|
||||
WinCursor::Failed
|
||||
}
|
||||
};
|
||||
|
||||
RootCustomCursor { inner }
|
||||
}
|
||||
|
||||
// TODO: Investigate opportunities for caching
|
||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
||||
monitor::available_monitors()
|
||||
|
|
|
|||
|
|
@ -17,12 +17,9 @@ use windows_sys::{
|
|||
};
|
||||
|
||||
use crate::icon::*;
|
||||
use crate::{
|
||||
cursor::{CursorImage, OnlyCursorImageBuilder},
|
||||
dpi::PhysicalSize,
|
||||
};
|
||||
use crate::{cursor::CursorImage, dpi::PhysicalSize};
|
||||
|
||||
use super::{util, ActiveEventLoop};
|
||||
use super::util;
|
||||
|
||||
impl Pixel {
|
||||
fn convert_to_bgra(&mut self) {
|
||||
|
|
@ -188,7 +185,7 @@ pub enum WinCursor {
|
|||
}
|
||||
|
||||
impl WinCursor {
|
||||
fn new(image: &CursorImage) -> Result<Self, io::Error> {
|
||||
pub(crate) fn new(image: &CursorImage) -> Result<Self, io::Error> {
|
||||
let mut bgra = image.rgba.clone();
|
||||
bgra.chunks_exact_mut(4).for_each(|chunk| chunk.swap(0, 2));
|
||||
|
||||
|
|
@ -236,16 +233,6 @@ impl WinCursor {
|
|||
Ok(Self::Cursor(Arc::new(RaiiCursor { handle })))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &ActiveEventLoop) -> Self {
|
||||
match Self::new(&cursor.0) {
|
||||
Ok(cursor) => cursor,
|
||||
Err(err) => {
|
||||
log::warn!("Failed to create custom cursor: {err}");
|
||||
Self::Failed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, Eq, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub(crate) use self::{
|
|||
|
||||
pub(crate) use self::icon::WinCursor as PlatformCustomCursor;
|
||||
pub use self::icon::WinIcon as PlatformIcon;
|
||||
pub(crate) use crate::cursor::OnlyCursorImageBuilder as PlatformCustomCursorBuilder;
|
||||
pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource;
|
||||
use crate::platform_impl::Fullscreen;
|
||||
|
||||
use crate::event::DeviceId as RootDeviceId;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue