mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Update to latest iced git, rebase fixes
This commit is contained in:
parent
545f3bd44b
commit
3baac6aeba
47
Cargo.lock
generated
47
Cargo.lock
generated
@ -1845,6 +1845,12 @@ dependencies = [
|
||||
"xml-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glam"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b00572b5b10070ac495be20a25b4c8d379d20bcdec8ea0c870022b620ec79b20"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
@ -2152,29 +2158,63 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "iced_core"
|
||||
version = "0.2.1"
|
||||
source = "git+https://github.com/Imberflur/iced#cf514910c2c0db8633377d2719b244e388774cee"
|
||||
source = "git+https://github.com/hecrj/iced?rev=b5d842f#b5d842f877145c78f5d595a87cc1927bb6f5b86a"
|
||||
|
||||
[[package]]
|
||||
name = "iced_futures"
|
||||
version = "0.1.2"
|
||||
source = "git+https://github.com/Imberflur/iced#cf514910c2c0db8633377d2719b244e388774cee"
|
||||
source = "git+https://github.com/hecrj/iced?rev=b5d842f#b5d842f877145c78f5d595a87cc1927bb6f5b86a"
|
||||
dependencies = [
|
||||
"futures 0.3.5",
|
||||
"log",
|
||||
"wasm-bindgen-futures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iced_graphics"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/hecrj/iced?rev=b5d842f#b5d842f877145c78f5d595a87cc1927bb6f5b86a"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"glam",
|
||||
"iced_native",
|
||||
"iced_style",
|
||||
"raw-window-handle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iced_native"
|
||||
version = "0.2.2"
|
||||
source = "git+https://github.com/Imberflur/iced#cf514910c2c0db8633377d2719b244e388774cee"
|
||||
source = "git+https://github.com/hecrj/iced?rev=b5d842f#b5d842f877145c78f5d595a87cc1927bb6f5b86a"
|
||||
dependencies = [
|
||||
"iced_core",
|
||||
"iced_futures",
|
||||
"num-traits 0.2.12",
|
||||
"twox-hash",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iced_style"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/hecrj/iced?rev=b5d842f#b5d842f877145c78f5d595a87cc1927bb6f5b86a"
|
||||
dependencies = [
|
||||
"iced_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iced_winit"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/hecrj/iced?rev=b5d842f#b5d842f877145c78f5d595a87cc1927bb6f5b86a"
|
||||
dependencies = [
|
||||
"iced_graphics",
|
||||
"iced_native",
|
||||
"log",
|
||||
"winapi 0.3.9",
|
||||
"window_clipboard",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
@ -5212,6 +5252,7 @@ dependencies = [
|
||||
"guillotiere",
|
||||
"hashbrown 0.7.2",
|
||||
"iced_native",
|
||||
"iced_winit",
|
||||
"image",
|
||||
"inline_tweak",
|
||||
"itertools",
|
||||
|
@ -35,7 +35,8 @@ winit = {version = "0.22.2", features = ["serde"]}
|
||||
conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
|
||||
conrod_winit = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
|
||||
euc = {git = "https://github.com/zesterer/euc.git"}
|
||||
iced = {package = "iced_native", git = "https://github.com/Imberflur/iced"}
|
||||
iced = {package = "iced_native", git = "https://github.com/hecrj/iced", rev = "b5d842f"}
|
||||
iced_winit = {git = "https://github.com/hecrj/iced", rev = "b5d842f"}
|
||||
window_clipboard = "0.1.1"
|
||||
glyph_brush = "0.7.0"
|
||||
|
||||
|
@ -2,7 +2,7 @@ use super::{
|
||||
img_ids::Imgs, ERROR_COLOR, FACTION_COLOR, GROUP_COLOR, INFO_COLOR, KILL_COLOR, LOOT_COLOR,
|
||||
OFFLINE_COLOR, ONLINE_COLOR, REGION_COLOR, SAY_COLOR, TELL_COLOR, TEXT_COLOR, WORLD_COLOR,
|
||||
};
|
||||
use crate::{ui::fonts::Fonts, GlobalState, Localization};
|
||||
use crate::{i18n::Localization, ui::fonts::Fonts, GlobalState};
|
||||
use client::{cmd, Client};
|
||||
use common::{
|
||||
comp::{
|
||||
|
@ -197,7 +197,6 @@ impl PlayState for CharSelectionState {
|
||||
);
|
||||
|
||||
// Draw the UI to the screen.
|
||||
self.char_selection_ui
|
||||
.render(global_state.window.renderer_mut());
|
||||
self.char_selection_ui.render(renderer);
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,13 @@ use crate::{
|
||||
};
|
||||
use client::Client;
|
||||
use common::{
|
||||
character::{CharacterItem, MAX_CHARACTERS_PER_PLAYER},
|
||||
assets::Asset,
|
||||
character::{CharacterId, CharacterItem, MAX_CHARACTERS_PER_PLAYER},
|
||||
comp,
|
||||
comp::humanoid,
|
||||
};
|
||||
//ImageFrame, Tooltip,
|
||||
use crate::settings::Settings;
|
||||
use common::assets::load_expect;
|
||||
//use std::time::Duration;
|
||||
//use ui::ice::widget;
|
||||
use iced::{
|
||||
@ -49,7 +49,7 @@ image_ids_ice! {
|
||||
delete_button_press: "voxygen.element.buttons.x_red_press",
|
||||
|
||||
|
||||
name_input: "voxygen.element.misc_bg.textbox_mid",
|
||||
name_input: "voxygen.element.misc_bg.textbox",
|
||||
|
||||
// Tool Icons
|
||||
daggers: "voxygen.element.icons.daggers",
|
||||
@ -106,7 +106,7 @@ pub enum Event {
|
||||
tool: Option<String>,
|
||||
body: comp::Body,
|
||||
},
|
||||
DeleteCharacter(i32),
|
||||
DeleteCharacter(CharacterId),
|
||||
}
|
||||
|
||||
struct CharacterList {
|
||||
@ -165,6 +165,8 @@ struct Controls {
|
||||
i18n: std::sync::Arc<Localization>,
|
||||
// Voxygen version
|
||||
version: String,
|
||||
// Alpha disclaimer
|
||||
alpha: String,
|
||||
|
||||
info_content: Option<InfoContent>,
|
||||
// enter: bool,
|
||||
@ -190,12 +192,14 @@ impl Controls {
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
common::util::GIT_VERSION.to_string()
|
||||
);
|
||||
let alpha = format!("Veloren Pre-Alpha {}", env!("CARGO_PKG_VERSION"),);
|
||||
|
||||
Self {
|
||||
fonts,
|
||||
imgs,
|
||||
i18n,
|
||||
version,
|
||||
alpha,
|
||||
|
||||
info_content: None,
|
||||
mode: Mode::Select {
|
||||
@ -227,6 +231,18 @@ impl Controls {
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(HorizontalAlignment::Right);
|
||||
|
||||
let alpha = iced::Text::new(&self.alpha)
|
||||
.size(self.fonts.cyri.scale(15))
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(HorizontalAlignment::Center);
|
||||
|
||||
let top_text = Row::with_children(vec![
|
||||
Space::new(Length::Fill, Length::Shrink).into(),
|
||||
alpha.into(),
|
||||
version.into(),
|
||||
])
|
||||
.width(Length::Fill);
|
||||
|
||||
let content = match &mut self.mode {
|
||||
Mode::Select {
|
||||
list,
|
||||
@ -375,7 +391,7 @@ impl Controls {
|
||||
};
|
||||
|
||||
Container::new(
|
||||
Column::with_children(vec![version.into(), content.into()])
|
||||
Column::with_children(vec![top_text.into(), content.into()])
|
||||
.spacing(3)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill),
|
||||
@ -408,7 +424,7 @@ pub struct CharSelectionUi {
|
||||
impl CharSelectionUi {
|
||||
pub fn new(global_state: &mut GlobalState) -> Self {
|
||||
// Load language
|
||||
let i18n = load_expect::<Localization>(&i18n_asset_key(
|
||||
let i18n = Localization::load_expect(&i18n_asset_key(
|
||||
&global_state.settings.language.selected_language,
|
||||
));
|
||||
|
||||
|
@ -85,7 +85,7 @@ impl PlayState for MainMenuState {
|
||||
Event::Close => return PlayStateResult::Shutdown,
|
||||
// Pass events to ui.
|
||||
Event::IcedUi(event) => {
|
||||
self.main_menu_ui.handle_iced_event(event);
|
||||
self.main_menu_ui.handle_event(event);
|
||||
},
|
||||
// Ignore all other events.
|
||||
_ => {},
|
||||
|
@ -15,12 +15,12 @@ use crate::{
|
||||
},
|
||||
GlobalState,
|
||||
};
|
||||
use iced::{text_input, Column, Container, HorizontalAlignment, Length};
|
||||
use iced::{text_input, Column, Container, HorizontalAlignment, Length, Row, Space};
|
||||
//ImageFrame, Tooltip,
|
||||
use crate::settings::Settings;
|
||||
use common::assets::Asset;
|
||||
use image::DynamicImage;
|
||||
use rand::{seq::SliceRandom, thread_rng, Rng};
|
||||
use rand::{seq::SliceRandom, thread_rng};
|
||||
use std::time::Duration;
|
||||
|
||||
// TODO: what is this? (showed up in rebase)
|
||||
@ -139,6 +139,8 @@ struct Controls {
|
||||
i18n: std::sync::Arc<Localization>,
|
||||
// Voxygen version
|
||||
version: String,
|
||||
// Alpha disclaimer
|
||||
alpha: String,
|
||||
|
||||
selected_server_index: Option<usize>,
|
||||
login_info: LoginInfo,
|
||||
@ -182,6 +184,7 @@ impl Controls {
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
common::util::GIT_VERSION.to_string()
|
||||
);
|
||||
let alpha = format!("Veloren Pre-Alpha {}", env!("CARGO_PKG_VERSION"),);
|
||||
|
||||
let screen = /* if settings.show_disclaimer {
|
||||
Screen::Disclaimer {
|
||||
@ -211,6 +214,7 @@ impl Controls {
|
||||
bg_img,
|
||||
i18n,
|
||||
version,
|
||||
alpha,
|
||||
|
||||
selected_server_index,
|
||||
login_info,
|
||||
@ -236,6 +240,18 @@ impl Controls {
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(HorizontalAlignment::Right);
|
||||
|
||||
let alpha = iced::Text::new(&self.alpha)
|
||||
.size(self.fonts.cyri.scale(15))
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(HorizontalAlignment::Center);
|
||||
|
||||
let top_text = Row::with_children(vec![
|
||||
Space::new(Length::Fill, Length::Shrink).into(),
|
||||
alpha.into(),
|
||||
version.into(),
|
||||
])
|
||||
.width(Length::Fill);
|
||||
|
||||
let bg_img = if matches!(&self.screen, Screen::Connecting {..}) {
|
||||
self.bg_img
|
||||
} else {
|
||||
@ -274,7 +290,7 @@ impl Controls {
|
||||
};
|
||||
|
||||
Container::new(
|
||||
Column::with_children(vec![version.into(), content])
|
||||
Column::with_children(vec![top_text.into(), content])
|
||||
.spacing(3)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill),
|
||||
@ -465,7 +481,7 @@ impl<'a> MainMenuUi {
|
||||
let controls = Controls::new(
|
||||
fonts,
|
||||
Imgs::load(&mut ui).expect("Failed to load images"),
|
||||
ui.add_graphic(Graphic::Image(DynamicImage::load_expect(bg_img_spec))),
|
||||
ui.add_graphic(Graphic::Image(DynamicImage::load_expect(bg_img_spec), None)),
|
||||
i18n,
|
||||
&global_state.settings,
|
||||
);
|
||||
|
@ -36,9 +36,12 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) {
|
||||
}
|
||||
// iced ui events
|
||||
// TODO: no clone
|
||||
if let winit::Event::WindowEvent { event, .. } = event.clone() {
|
||||
if let Some(event) = ui::ice::window_event(event) {
|
||||
global_state.window.send_event(Event::IcedUi(event));
|
||||
if let winit::event::Event::WindowEvent { event, .. } = &event {
|
||||
let window = &mut global_state.window;
|
||||
if let Some(event) =
|
||||
ui::ice::window_event(event, window.scale_factor(), window.modifiers())
|
||||
{
|
||||
window.send_event(Event::IcedUi(event));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ pub struct Event(pub Input);
|
||||
impl Event {
|
||||
pub fn try_from(
|
||||
event: &winit::event::Event<()>,
|
||||
window: &glutin::ContextWrapper<glutin::PossiblyCurrent, winit::window::Window>,
|
||||
window: &winit::window::Window,
|
||||
) -> Option<Self> {
|
||||
use conrod_winit::*;
|
||||
// A wrapper around the winit window that allows us to implement the trait
|
||||
@ -26,7 +26,7 @@ impl Event {
|
||||
|
||||
fn hidpi_factor(&self) -> f64 { winit::window::Window::scale_factor(&self.0) }
|
||||
}
|
||||
convert_event!(event, &WindowRef(window.window())).map(Self)
|
||||
convert_event!(event, &WindowRef(window)).map(Self)
|
||||
}
|
||||
|
||||
pub fn is_keyboard_or_mouse(&self) -> bool {
|
||||
|
@ -11,7 +11,7 @@ impl Font {
|
||||
pub fn new(font: &i18n::Font, ui: &mut crate::ui::Ui) -> Self {
|
||||
Self {
|
||||
metadata: font.clone(),
|
||||
conrod_id: ui.new_font(crate::ui::Font::load_expect(&font.asset_key)),
|
||||
conrod_id: ui.new_font(crate::ui::ice::RawFont::load_expect(&font.asset_key)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ impl GraphicCache {
|
||||
use image::GenericImageView;
|
||||
self.get_graphic(id)
|
||||
.and_then(|graphic| match graphic {
|
||||
Graphic::Image(image) => Some(image.dimensions()),
|
||||
Graphic::Image(image, _) => Some(image.dimensions()),
|
||||
Graphic::Voxel(segment, _, _) => {
|
||||
use common::vol::SizedVol;
|
||||
let size = segment.size();
|
||||
|
@ -109,6 +109,7 @@ impl common::assets::Asset for RawFont {
|
||||
|
||||
fn parse(
|
||||
mut buf_reader: std::io::BufReader<std::fs::File>,
|
||||
_specifier: &str,
|
||||
) -> Result<Self, common::assets::Error> {
|
||||
use std::io::Read;
|
||||
let mut buf = Vec::new();
|
||||
|
@ -1,12 +0,0 @@
|
||||
// Taken from https://github.com/hecrj/iced/blob/e1438774af809c2951c4c7446638500446c81111/winit/src/clipboard.rs
|
||||
pub struct Clipboard(window_clipboard::Clipboard);
|
||||
|
||||
impl Clipboard {
|
||||
pub fn new(window: &winit::Window) -> Option<Clipboard> {
|
||||
window_clipboard::Clipboard::new(window).map(Clipboard).ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl iced::Clipboard for Clipboard {
|
||||
fn content(&self) -> Option<String> { self.0.read().ok() }
|
||||
}
|
@ -1,24 +1,22 @@
|
||||
// tooltip_manager: TooltipManager,
|
||||
mod cache;
|
||||
mod clipboard;
|
||||
pub mod component;
|
||||
mod renderer;
|
||||
pub mod widget;
|
||||
mod winit_conversion;
|
||||
|
||||
pub use cache::{Font, FontId, RawFont};
|
||||
pub use graphic::{Id, Rotation};
|
||||
pub use iced::Event;
|
||||
pub use iced_winit::conversion::window_event;
|
||||
pub use renderer::{style, IcedRenderer};
|
||||
pub use winit_conversion::window_event;
|
||||
|
||||
use super::{
|
||||
graphic::{self, Graphic},
|
||||
scale::{Scale, ScaleMode},
|
||||
};
|
||||
use crate::{render::Renderer, window::Window, Error};
|
||||
use clipboard::Clipboard;
|
||||
use iced::{mouse, Cache, Size, UserInterface};
|
||||
use iced_winit::Clipboard;
|
||||
use vek::*;
|
||||
|
||||
pub type Element<'a, M> = iced::Element<'a, M, IcedRenderer>;
|
||||
@ -28,6 +26,7 @@ pub struct IcedUi {
|
||||
cache: Option<Cache>,
|
||||
events: Vec<Event>,
|
||||
clipboard: Clipboard,
|
||||
cursor_position: Vec2<f32>,
|
||||
// Scaling of the ui
|
||||
scale: Scale,
|
||||
window_resized: Option<Vec2<u32>>,
|
||||
@ -46,6 +45,7 @@ impl IcedUi {
|
||||
events: Vec::new(),
|
||||
// TODO: handle None
|
||||
clipboard: Clipboard::new(window.window()).unwrap(),
|
||||
cursor_position: Vec2::zero(),
|
||||
scale,
|
||||
window_resized: None,
|
||||
})
|
||||
@ -74,6 +74,13 @@ impl IcedUi {
|
||||
Event::Mouse(mouse::Event::CursorMoved { x, y }) => {
|
||||
// TODO: return f32 here
|
||||
let scale = self.scale.scale_factor_logical() as f32;
|
||||
// TODO: determine why iced moved cursor position out of the `Cache` and if we
|
||||
// may need to handle this in a different way to address
|
||||
// whatever issue iced was trying to address
|
||||
self.cursor_position = Vec2 {
|
||||
x: x * scale,
|
||||
y: y * scale,
|
||||
};
|
||||
self.events.push(Event::Mouse(mouse::Event::CursorMoved {
|
||||
x: x * scale,
|
||||
y: y * scale,
|
||||
@ -129,6 +136,11 @@ impl IcedUi {
|
||||
}
|
||||
}
|
||||
|
||||
let cursor_position = iced::Point {
|
||||
x: self.cursor_position.x,
|
||||
y: self.cursor_position.y,
|
||||
};
|
||||
|
||||
// TODO: convert to f32 at source
|
||||
let window_size = self.scale.scaled_window_size().map(|e| e as f32);
|
||||
|
||||
@ -141,11 +153,13 @@ impl IcedUi {
|
||||
|
||||
let messages = user_interface.update(
|
||||
self.events.drain(..),
|
||||
cursor_position,
|
||||
Some(&self.clipboard),
|
||||
&mut self.renderer,
|
||||
);
|
||||
|
||||
let (primitive, mouse_interaction) = user_interface.draw(&mut self.renderer);
|
||||
let (primitive, mouse_interaction) =
|
||||
user_interface.draw(&mut self.renderer, cursor_position);
|
||||
|
||||
self.cache = Some(user_interface.into_cache());
|
||||
|
||||
|
@ -20,7 +20,7 @@ use crate::{
|
||||
Error,
|
||||
};
|
||||
use common::util::srgba_to_linear;
|
||||
use std::ops::Range;
|
||||
use std::{convert::TryInto, ops::Range};
|
||||
use vek::*;
|
||||
|
||||
enum DrawKind {
|
||||
@ -29,7 +29,7 @@ enum DrawKind {
|
||||
Plain,
|
||||
}
|
||||
enum DrawCommand {
|
||||
Draw { kind: DrawKind, verts: Range<usize> },
|
||||
Draw { kind: DrawKind, verts: Range<u32> },
|
||||
Scissor(Aabr<u16>),
|
||||
WorldPos(Option<usize>),
|
||||
}
|
||||
@ -37,14 +37,30 @@ impl DrawCommand {
|
||||
fn image(verts: Range<usize>, id: TexId) -> DrawCommand {
|
||||
DrawCommand::Draw {
|
||||
kind: DrawKind::Image(id),
|
||||
verts,
|
||||
// TODO: move conversion into helper method so we don't have to write it out so many
|
||||
// times
|
||||
verts: verts
|
||||
.start
|
||||
.try_into()
|
||||
.expect("Vertex count for UI rendering does not fit in a u32!")
|
||||
..verts
|
||||
.end
|
||||
.try_into()
|
||||
.expect("Vertex count for UI rendering does not fit in a u32!"),
|
||||
}
|
||||
}
|
||||
|
||||
fn plain(verts: Range<usize>) -> DrawCommand {
|
||||
DrawCommand::Draw {
|
||||
kind: DrawKind::Plain,
|
||||
verts,
|
||||
verts: verts
|
||||
.start
|
||||
.try_into()
|
||||
.expect("Vertex count for UI rendering does not fit in a u32!")
|
||||
..verts
|
||||
.end
|
||||
.try_into()
|
||||
.expect("Vertex count for UI rendering does not fit in a u32!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -625,7 +641,7 @@ impl IcedRenderer {
|
||||
DrawKind::Plain => self.cache.glyph_cache_tex(),
|
||||
};
|
||||
let model = self.model.submodel(verts.clone());
|
||||
renderer.render_ui_element(&model, tex, scissor, globals, locals);
|
||||
renderer.render_ui_element(model, tex, scissor, globals, locals);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ use iced::{mouse, text, Color, HorizontalAlignment, Rectangle, Size, VerticalAli
|
||||
impl text::Renderer for IcedRenderer {
|
||||
type Font = FontId;
|
||||
|
||||
const DEFAULT_SIZE: u16 = 20;
|
||||
// TODO: expose as setting
|
||||
fn default_size(&self) -> u16 { 20 }
|
||||
|
||||
fn measure(&self, content: &str, size: u16, font: Self::Font, bounds: Size) -> (f32, f32) {
|
||||
// Using the physical scale might make these cached info usable below?
|
||||
|
@ -1,274 +0,0 @@
|
||||
// Using reference impl: https://github.com/hecrj/iced/blob/e1438774af809c2951c4c7446638500446c81111/winit/src/conversion.rs
|
||||
use iced::{
|
||||
keyboard::{self, KeyCode, ModifiersState},
|
||||
mouse, window, Event,
|
||||
};
|
||||
|
||||
/// Converts a winit event into an iced event.
|
||||
pub fn window_event(event: winit::WindowEvent) -> Option<Event> {
|
||||
use winit::WindowEvent;
|
||||
|
||||
match event {
|
||||
WindowEvent::Resized(new_size) => {
|
||||
let logical_size: winit::dpi::LogicalSize = new_size;
|
||||
|
||||
Some(Event::Window(window::Event::Resized {
|
||||
width: logical_size.width as u32,
|
||||
height: logical_size.height as u32,
|
||||
}))
|
||||
},
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
let position: winit::dpi::LogicalPosition = position;
|
||||
|
||||
Some(Event::Mouse(mouse::Event::CursorMoved {
|
||||
x: position.x as f32,
|
||||
y: position.y as f32,
|
||||
}))
|
||||
},
|
||||
WindowEvent::MouseInput { button, state, .. } => {
|
||||
let button = mouse_button(button);
|
||||
|
||||
Some(Event::Mouse(match state {
|
||||
winit::ElementState::Pressed => mouse::Event::ButtonPressed(button),
|
||||
winit::ElementState::Released => mouse::Event::ButtonReleased(button),
|
||||
}))
|
||||
},
|
||||
WindowEvent::MouseWheel { delta, .. } => match delta {
|
||||
winit::MouseScrollDelta::LineDelta(delta_x, delta_y) => {
|
||||
Some(Event::Mouse(mouse::Event::WheelScrolled {
|
||||
delta: mouse::ScrollDelta::Lines {
|
||||
x: delta_x,
|
||||
y: delta_y,
|
||||
},
|
||||
}))
|
||||
},
|
||||
winit::MouseScrollDelta::PixelDelta(position) => {
|
||||
let position: winit::dpi::LogicalPosition = position;
|
||||
Some(Event::Mouse(mouse::Event::WheelScrolled {
|
||||
delta: mouse::ScrollDelta::Pixels {
|
||||
x: position.x as f32,
|
||||
y: position.y as f32,
|
||||
},
|
||||
}))
|
||||
},
|
||||
},
|
||||
WindowEvent::ReceivedCharacter(c) => {
|
||||
Some(Event::Keyboard(keyboard::Event::CharacterReceived(c)))
|
||||
},
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
winit::KeyboardInput {
|
||||
virtual_keycode: Some(virtual_keycode),
|
||||
state,
|
||||
modifiers,
|
||||
..
|
||||
},
|
||||
..
|
||||
} => Some(Event::Keyboard({
|
||||
let key_code = key_code(virtual_keycode);
|
||||
let modifiers = modifiers_state(modifiers);
|
||||
|
||||
match state {
|
||||
winit::ElementState::Pressed => keyboard::Event::KeyPressed {
|
||||
key_code,
|
||||
modifiers,
|
||||
},
|
||||
winit::ElementState::Released => keyboard::Event::KeyReleased {
|
||||
key_code,
|
||||
modifiers,
|
||||
},
|
||||
}
|
||||
})),
|
||||
// iced also can use file hovering events but we don't need them right now
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
// iced has a function for converting mouse cursors here
|
||||
|
||||
/// Converts winit mouse button to iced mouse button
|
||||
fn mouse_button(mouse_button: winit::MouseButton) -> mouse::Button {
|
||||
match mouse_button {
|
||||
winit::MouseButton::Left => mouse::Button::Left,
|
||||
winit::MouseButton::Right => mouse::Button::Right,
|
||||
winit::MouseButton::Middle => mouse::Button::Middle,
|
||||
winit::MouseButton::Other(other) => mouse::Button::Other(other),
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts winit `ModifiersState` to iced `ModifiersState`
|
||||
fn modifiers_state(modifiers: winit::ModifiersState) -> ModifiersState {
|
||||
ModifiersState {
|
||||
shift: modifiers.shift,
|
||||
control: modifiers.ctrl,
|
||||
alt: modifiers.alt,
|
||||
logo: modifiers.logo,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts winit `VirtualKeyCode` to iced `KeyCode`
|
||||
fn key_code(virtual_keycode: winit::VirtualKeyCode) -> KeyCode {
|
||||
match virtual_keycode {
|
||||
winit::VirtualKeyCode::Key1 => KeyCode::Key1,
|
||||
winit::VirtualKeyCode::Key2 => KeyCode::Key2,
|
||||
winit::VirtualKeyCode::Key3 => KeyCode::Key3,
|
||||
winit::VirtualKeyCode::Key4 => KeyCode::Key4,
|
||||
winit::VirtualKeyCode::Key5 => KeyCode::Key5,
|
||||
winit::VirtualKeyCode::Key6 => KeyCode::Key6,
|
||||
winit::VirtualKeyCode::Key7 => KeyCode::Key7,
|
||||
winit::VirtualKeyCode::Key8 => KeyCode::Key8,
|
||||
winit::VirtualKeyCode::Key9 => KeyCode::Key9,
|
||||
winit::VirtualKeyCode::Key0 => KeyCode::Key0,
|
||||
winit::VirtualKeyCode::A => KeyCode::A,
|
||||
winit::VirtualKeyCode::B => KeyCode::B,
|
||||
winit::VirtualKeyCode::C => KeyCode::C,
|
||||
winit::VirtualKeyCode::D => KeyCode::D,
|
||||
winit::VirtualKeyCode::E => KeyCode::E,
|
||||
winit::VirtualKeyCode::F => KeyCode::F,
|
||||
winit::VirtualKeyCode::G => KeyCode::G,
|
||||
winit::VirtualKeyCode::H => KeyCode::H,
|
||||
winit::VirtualKeyCode::I => KeyCode::I,
|
||||
winit::VirtualKeyCode::J => KeyCode::J,
|
||||
winit::VirtualKeyCode::K => KeyCode::K,
|
||||
winit::VirtualKeyCode::L => KeyCode::L,
|
||||
winit::VirtualKeyCode::M => KeyCode::M,
|
||||
winit::VirtualKeyCode::N => KeyCode::N,
|
||||
winit::VirtualKeyCode::O => KeyCode::O,
|
||||
winit::VirtualKeyCode::P => KeyCode::P,
|
||||
winit::VirtualKeyCode::Q => KeyCode::Q,
|
||||
winit::VirtualKeyCode::R => KeyCode::R,
|
||||
winit::VirtualKeyCode::S => KeyCode::S,
|
||||
winit::VirtualKeyCode::T => KeyCode::T,
|
||||
winit::VirtualKeyCode::U => KeyCode::U,
|
||||
winit::VirtualKeyCode::V => KeyCode::V,
|
||||
winit::VirtualKeyCode::W => KeyCode::W,
|
||||
winit::VirtualKeyCode::X => KeyCode::X,
|
||||
winit::VirtualKeyCode::Y => KeyCode::Y,
|
||||
winit::VirtualKeyCode::Z => KeyCode::Z,
|
||||
winit::VirtualKeyCode::Escape => KeyCode::Escape,
|
||||
winit::VirtualKeyCode::F1 => KeyCode::F1,
|
||||
winit::VirtualKeyCode::F2 => KeyCode::F2,
|
||||
winit::VirtualKeyCode::F3 => KeyCode::F3,
|
||||
winit::VirtualKeyCode::F4 => KeyCode::F4,
|
||||
winit::VirtualKeyCode::F5 => KeyCode::F5,
|
||||
winit::VirtualKeyCode::F6 => KeyCode::F6,
|
||||
winit::VirtualKeyCode::F7 => KeyCode::F7,
|
||||
winit::VirtualKeyCode::F8 => KeyCode::F8,
|
||||
winit::VirtualKeyCode::F9 => KeyCode::F9,
|
||||
winit::VirtualKeyCode::F10 => KeyCode::F10,
|
||||
winit::VirtualKeyCode::F11 => KeyCode::F11,
|
||||
winit::VirtualKeyCode::F12 => KeyCode::F12,
|
||||
winit::VirtualKeyCode::F13 => KeyCode::F13,
|
||||
winit::VirtualKeyCode::F14 => KeyCode::F14,
|
||||
winit::VirtualKeyCode::F15 => KeyCode::F15,
|
||||
winit::VirtualKeyCode::F16 => KeyCode::F16,
|
||||
winit::VirtualKeyCode::F17 => KeyCode::F17,
|
||||
winit::VirtualKeyCode::F18 => KeyCode::F18,
|
||||
winit::VirtualKeyCode::F19 => KeyCode::F19,
|
||||
winit::VirtualKeyCode::F20 => KeyCode::F20,
|
||||
winit::VirtualKeyCode::F21 => KeyCode::F21,
|
||||
winit::VirtualKeyCode::F22 => KeyCode::F22,
|
||||
winit::VirtualKeyCode::F23 => KeyCode::F23,
|
||||
winit::VirtualKeyCode::F24 => KeyCode::F24,
|
||||
winit::VirtualKeyCode::Snapshot => KeyCode::Snapshot,
|
||||
winit::VirtualKeyCode::Scroll => KeyCode::Scroll,
|
||||
winit::VirtualKeyCode::Pause => KeyCode::Pause,
|
||||
winit::VirtualKeyCode::Insert => KeyCode::Insert,
|
||||
winit::VirtualKeyCode::Home => KeyCode::Home,
|
||||
winit::VirtualKeyCode::Delete => KeyCode::Delete,
|
||||
winit::VirtualKeyCode::End => KeyCode::End,
|
||||
winit::VirtualKeyCode::PageDown => KeyCode::PageDown,
|
||||
winit::VirtualKeyCode::PageUp => KeyCode::PageUp,
|
||||
winit::VirtualKeyCode::Left => KeyCode::Left,
|
||||
winit::VirtualKeyCode::Up => KeyCode::Up,
|
||||
winit::VirtualKeyCode::Right => KeyCode::Right,
|
||||
winit::VirtualKeyCode::Down => KeyCode::Down,
|
||||
winit::VirtualKeyCode::Back => KeyCode::Backspace,
|
||||
winit::VirtualKeyCode::Return => KeyCode::Enter,
|
||||
winit::VirtualKeyCode::Space => KeyCode::Space,
|
||||
winit::VirtualKeyCode::Compose => KeyCode::Compose,
|
||||
winit::VirtualKeyCode::Caret => KeyCode::Caret,
|
||||
winit::VirtualKeyCode::Numlock => KeyCode::Numlock,
|
||||
winit::VirtualKeyCode::Numpad0 => KeyCode::Numpad0,
|
||||
winit::VirtualKeyCode::Numpad1 => KeyCode::Numpad1,
|
||||
winit::VirtualKeyCode::Numpad2 => KeyCode::Numpad2,
|
||||
winit::VirtualKeyCode::Numpad3 => KeyCode::Numpad3,
|
||||
winit::VirtualKeyCode::Numpad4 => KeyCode::Numpad4,
|
||||
winit::VirtualKeyCode::Numpad5 => KeyCode::Numpad5,
|
||||
winit::VirtualKeyCode::Numpad6 => KeyCode::Numpad6,
|
||||
winit::VirtualKeyCode::Numpad7 => KeyCode::Numpad7,
|
||||
winit::VirtualKeyCode::Numpad8 => KeyCode::Numpad8,
|
||||
winit::VirtualKeyCode::Numpad9 => KeyCode::Numpad9,
|
||||
winit::VirtualKeyCode::AbntC1 => KeyCode::AbntC1,
|
||||
winit::VirtualKeyCode::AbntC2 => KeyCode::AbntC2,
|
||||
winit::VirtualKeyCode::Add => KeyCode::Add,
|
||||
winit::VirtualKeyCode::Apostrophe => KeyCode::Apostrophe,
|
||||
winit::VirtualKeyCode::Apps => KeyCode::Apps,
|
||||
winit::VirtualKeyCode::At => KeyCode::At,
|
||||
winit::VirtualKeyCode::Ax => KeyCode::Ax,
|
||||
winit::VirtualKeyCode::Backslash => KeyCode::Backslash,
|
||||
winit::VirtualKeyCode::Calculator => KeyCode::Calculator,
|
||||
winit::VirtualKeyCode::Capital => KeyCode::Capital,
|
||||
winit::VirtualKeyCode::Colon => KeyCode::Colon,
|
||||
winit::VirtualKeyCode::Comma => KeyCode::Comma,
|
||||
winit::VirtualKeyCode::Convert => KeyCode::Convert,
|
||||
winit::VirtualKeyCode::Decimal => KeyCode::Decimal,
|
||||
winit::VirtualKeyCode::Divide => KeyCode::Divide,
|
||||
winit::VirtualKeyCode::Equals => KeyCode::Equals,
|
||||
winit::VirtualKeyCode::Grave => KeyCode::Grave,
|
||||
winit::VirtualKeyCode::Kana => KeyCode::Kana,
|
||||
winit::VirtualKeyCode::Kanji => KeyCode::Kanji,
|
||||
winit::VirtualKeyCode::LAlt => KeyCode::LAlt,
|
||||
winit::VirtualKeyCode::LBracket => KeyCode::LBracket,
|
||||
winit::VirtualKeyCode::LControl => KeyCode::LControl,
|
||||
winit::VirtualKeyCode::LShift => KeyCode::LShift,
|
||||
winit::VirtualKeyCode::LWin => KeyCode::LWin,
|
||||
winit::VirtualKeyCode::Mail => KeyCode::Mail,
|
||||
winit::VirtualKeyCode::MediaSelect => KeyCode::MediaSelect,
|
||||
winit::VirtualKeyCode::MediaStop => KeyCode::MediaStop,
|
||||
winit::VirtualKeyCode::Minus => KeyCode::Minus,
|
||||
winit::VirtualKeyCode::Multiply => KeyCode::Multiply,
|
||||
winit::VirtualKeyCode::Mute => KeyCode::Mute,
|
||||
winit::VirtualKeyCode::MyComputer => KeyCode::MyComputer,
|
||||
winit::VirtualKeyCode::NavigateForward => KeyCode::NavigateForward,
|
||||
winit::VirtualKeyCode::NavigateBackward => KeyCode::NavigateBackward,
|
||||
winit::VirtualKeyCode::NextTrack => KeyCode::NextTrack,
|
||||
winit::VirtualKeyCode::NoConvert => KeyCode::NoConvert,
|
||||
winit::VirtualKeyCode::NumpadComma => KeyCode::NumpadComma,
|
||||
winit::VirtualKeyCode::NumpadEnter => KeyCode::NumpadEnter,
|
||||
winit::VirtualKeyCode::NumpadEquals => KeyCode::NumpadEquals,
|
||||
winit::VirtualKeyCode::OEM102 => KeyCode::OEM102,
|
||||
winit::VirtualKeyCode::Period => KeyCode::Period,
|
||||
winit::VirtualKeyCode::PlayPause => KeyCode::PlayPause,
|
||||
winit::VirtualKeyCode::Power => KeyCode::Power,
|
||||
winit::VirtualKeyCode::PrevTrack => KeyCode::PrevTrack,
|
||||
winit::VirtualKeyCode::RAlt => KeyCode::RAlt,
|
||||
winit::VirtualKeyCode::RBracket => KeyCode::RBracket,
|
||||
winit::VirtualKeyCode::RControl => KeyCode::RControl,
|
||||
winit::VirtualKeyCode::RShift => KeyCode::RShift,
|
||||
winit::VirtualKeyCode::RWin => KeyCode::RWin,
|
||||
winit::VirtualKeyCode::Semicolon => KeyCode::Semicolon,
|
||||
winit::VirtualKeyCode::Slash => KeyCode::Slash,
|
||||
winit::VirtualKeyCode::Sleep => KeyCode::Sleep,
|
||||
winit::VirtualKeyCode::Stop => KeyCode::Stop,
|
||||
winit::VirtualKeyCode::Subtract => KeyCode::Subtract,
|
||||
winit::VirtualKeyCode::Sysrq => KeyCode::Sysrq,
|
||||
winit::VirtualKeyCode::Tab => KeyCode::Tab,
|
||||
winit::VirtualKeyCode::Underline => KeyCode::Underline,
|
||||
winit::VirtualKeyCode::Unlabeled => KeyCode::Unlabeled,
|
||||
winit::VirtualKeyCode::VolumeDown => KeyCode::VolumeDown,
|
||||
winit::VirtualKeyCode::VolumeUp => KeyCode::VolumeUp,
|
||||
winit::VirtualKeyCode::Wake => KeyCode::Wake,
|
||||
winit::VirtualKeyCode::WebBack => KeyCode::WebBack,
|
||||
winit::VirtualKeyCode::WebFavorites => KeyCode::WebFavorites,
|
||||
winit::VirtualKeyCode::WebForward => KeyCode::WebForward,
|
||||
winit::VirtualKeyCode::WebHome => KeyCode::WebHome,
|
||||
winit::VirtualKeyCode::WebRefresh => KeyCode::WebRefresh,
|
||||
winit::VirtualKeyCode::WebSearch => KeyCode::WebSearch,
|
||||
winit::VirtualKeyCode::WebStop => KeyCode::WebStop,
|
||||
winit::VirtualKeyCode::Yen => KeyCode::Yen,
|
||||
winit::VirtualKeyCode::Copy => KeyCode::Copy,
|
||||
winit::VirtualKeyCode::Paste => KeyCode::Paste,
|
||||
winit::VirtualKeyCode::Cut => KeyCode::Cut,
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ use crate::{
|
||||
#[rustfmt::skip]
|
||||
use ::image::GenericImageView;
|
||||
use cache::Cache;
|
||||
use common::{assets, span, util::srgba_to_linear};
|
||||
use common::{span, util::srgba_to_linear};
|
||||
use conrod_core::{
|
||||
event::Input,
|
||||
graph::{self, Graph},
|
||||
|
@ -499,6 +499,7 @@ pub struct Window {
|
||||
pub mouse_y_inversion: bool,
|
||||
fullscreen: FullScreenSettings,
|
||||
modifiers: winit::event::ModifiersState,
|
||||
scale_factor: f64,
|
||||
needs_refresh_resize: bool,
|
||||
keypress_map: HashMap<GameInput, winit::event::ElementState>,
|
||||
pub remapping_keybindings: Option<GameInput>,
|
||||
@ -587,6 +588,8 @@ impl Window {
|
||||
channel::Receiver<String>,
|
||||
) = channel::unbounded::<String>();
|
||||
|
||||
let scale_factor = window.window().scale_factor();
|
||||
|
||||
let mut this = Self {
|
||||
renderer: Renderer::new(
|
||||
device,
|
||||
@ -603,6 +606,7 @@ impl Window {
|
||||
mouse_y_inversion: settings.gameplay.mouse_y_inversion,
|
||||
fullscreen: FullScreenSettings::default(),
|
||||
modifiers: Default::default(),
|
||||
scale_factor,
|
||||
needs_refresh_resize: false,
|
||||
keypress_map,
|
||||
remapping_keybindings: None,
|
||||
@ -922,8 +926,8 @@ impl Window {
|
||||
self.events
|
||||
.push(Event::Resize(Vec2::new(width as u32, height as u32)));
|
||||
},
|
||||
WindowEvent::ScaleFactorChanged { .. } => {
|
||||
// TODO: Handle properly!
|
||||
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
|
||||
self.scale_factor = scale_factor
|
||||
},
|
||||
WindowEvent::ReceivedCharacter(c) => self.events.push(Event::Char(c)),
|
||||
WindowEvent::MouseInput { button, state, .. } => {
|
||||
@ -1374,7 +1378,11 @@ impl Window {
|
||||
self.remapping_keybindings = Some(game_input);
|
||||
}
|
||||
|
||||
pub fn window(&self) -> &winit::Window { self.window.window() }
|
||||
pub fn window(&self) -> &winit::window::Window { self.window.window() }
|
||||
|
||||
pub fn modifiers(&self) -> winit::event::ModifiersState { self.modifiers }
|
||||
|
||||
pub fn scale_factor(&self) -> f64 { self.scale_factor }
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user