Run `rustfmt` on the demos

This commit is contained in:
Patrick Walton 2019-04-29 16:52:37 -07:00
parent 0da11ffe01
commit 60b951409c
6 changed files with 923 additions and 513 deletions

View File

@ -11,11 +11,11 @@
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
use jni::{JNIEnv, JavaVM};
use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JString, JValue}; use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JString, JValue};
use jni::{JNIEnv, JavaVM};
use pathfinder_demo::window::{Event, SVGPath, View, Window, WindowSize};
use pathfinder_demo::DemoApp; use pathfinder_demo::DemoApp;
use pathfinder_demo::Options; use pathfinder_demo::Options;
use pathfinder_demo::window::{Event, SVGPath, View, Window, WindowSize};
use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_geometry::basic::point::Point2DI32;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI32;
use pathfinder_gl::GLVersion; use pathfinder_gl::GLVersion;
@ -40,15 +40,19 @@ thread_local! {
static RESOURCE_LOADER: AndroidResourceLoader = AndroidResourceLoader; static RESOURCE_LOADER: AndroidResourceLoader = AndroidResourceLoader;
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_init(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_init(env: JNIEnv, env: JNIEnv,
class: JClass, class: JClass,
activity: JObject, activity: JObject,
loader: JObject, loader: JObject,
width: i32, width: i32,
height: i32) { height: i32,
) {
let logical_size = Point2DI32::new(width, height); let logical_size = Point2DI32::new(width, height);
let window_size = WindowSize { logical_size, backing_scale_factor: 1.0 }; let window_size = WindowSize {
logical_size,
backing_scale_factor: 1.0,
};
let window = WindowImpl { size: logical_size }; let window = WindowImpl { size: logical_size };
let options = Options::default(); let options = Options::default();
@ -65,10 +69,10 @@ pub unsafe extern "system" fn
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_prepareFrame(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_prepareFrame(env: JNIEnv, env: JNIEnv,
class: JClass) class: JClass,
-> i32 { ) -> i32 {
DEMO_APP.with(|demo_app| { DEMO_APP.with(|demo_app| {
let mut event_queue = EVENT_QUEUE.lock().unwrap(); let mut event_queue = EVENT_QUEUE.lock().unwrap();
match *demo_app.borrow_mut() { match *demo_app.borrow_mut() {
@ -81,10 +85,10 @@ pub unsafe extern "system" fn
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_drawScene(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_drawScene( env: JNIEnv,
env: JNIEnv, class: JClass,
class: JClass) { ) {
DEMO_APP.with(|demo_app| { DEMO_APP.with(|demo_app| {
if let Some(ref mut demo_app) = *demo_app.borrow_mut() { if let Some(ref mut demo_app) = *demo_app.borrow_mut() {
demo_app.draw_scene() demo_app.draw_scene()
@ -93,10 +97,10 @@ pub unsafe extern "system" fn
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_finishDrawingFrame(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_finishDrawingFrame( env: JNIEnv,
env: JNIEnv, class: JClass,
class: JClass) { ) {
DEMO_APP.with(|demo_app| { DEMO_APP.with(|demo_app| {
if let Some(ref mut demo_app) = *demo_app.borrow_mut() { if let Some(ref mut demo_app) = *demo_app.borrow_mut() {
demo_app.finish_drawing_frame() demo_app.finish_drawing_frame()
@ -105,67 +109,82 @@ pub unsafe extern "system" fn
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushWindowResizedEvent(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushWindowResizedEvent( env: JNIEnv,
env: JNIEnv, class: JClass,
class: JClass, width: i32,
width: i32, height: i32,
height: i32) { ) {
EVENT_QUEUE.lock().unwrap().push(Event::WindowResized(WindowSize { EVENT_QUEUE
logical_size: Point2DI32::new(width, height), .lock()
backing_scale_factor: 1.0, .unwrap()
})) .push(Event::WindowResized(WindowSize {
logical_size: Point2DI32::new(width, height),
backing_scale_factor: 1.0,
}))
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDownEvent(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDownEvent( _: JNIEnv,
_: JNIEnv, _: JClass,
_: JClass, x: i32,
x: i32, y: i32,
y: i32) { ) {
EVENT_QUEUE.lock().unwrap().push(Event::MouseDown(Point2DI32::new(x, y))) EVENT_QUEUE
.lock()
.unwrap()
.push(Event::MouseDown(Point2DI32::new(x, y)))
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDraggedEvent(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDraggedEvent( _: JNIEnv,
_: JNIEnv, _: JClass,
_: JClass, x: i32,
x: i32, y: i32,
y: i32) { ) {
EVENT_QUEUE.lock().unwrap().push(Event::MouseDragged(Point2DI32::new(x, y))) EVENT_QUEUE
.lock()
.unwrap()
.push(Event::MouseDragged(Point2DI32::new(x, y)))
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushZoomEvent(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushZoomEvent( _: JNIEnv,
_: JNIEnv, _: JClass,
_: JClass, factor: f32,
factor: f32, center_x: i32,
center_x: i32, center_y: i32,
center_y: i32) { ) {
EVENT_QUEUE.lock().unwrap().push(Event::Zoom(factor, Point2DI32::new(center_x, center_y))) EVENT_QUEUE
.lock()
.unwrap()
.push(Event::Zoom(factor, Point2DI32::new(center_x, center_y)))
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushLookEvent(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushLookEvent( _: JNIEnv,
_: JNIEnv, _: JClass,
_: JClass, pitch: f32,
pitch: f32, yaw: f32,
yaw: f32) { ) {
EVENT_QUEUE.lock().unwrap().push(Event::Look { pitch, yaw }) EVENT_QUEUE.lock().unwrap().push(Event::Look { pitch, yaw })
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushOpenSVGEvent(
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushOpenSVGEvent( env: JNIEnv,
env: JNIEnv, _: JClass,
_: JClass, string: JObject,
string: JObject) { ) {
let string: String = env.get_string(JString::from(string)).unwrap().into(); let string: String = env.get_string(JString::from(string)).unwrap().into();
EVENT_QUEUE.lock().unwrap().push(Event::OpenSVG(SVGPath::Resource(string))) EVENT_QUEUE
.lock()
.unwrap()
.push(Event::OpenSVG(SVGPath::Resource(string)))
} }
struct WindowImpl { struct WindowImpl {
@ -202,18 +221,20 @@ impl Window for WindowImpl {
0 0
} }
fn push_user_event(message_type: u32, message_data: u32) { fn push_user_event(message_type: u32, message_data: u32) {}
}
fn present_open_svg_dialog(&mut self) { fn present_open_svg_dialog(&mut self) {
JAVA_ACTIVITY.with(|java_activity| { JAVA_ACTIVITY.with(|java_activity| {
let mut java_activity = java_activity.borrow_mut(); let mut java_activity = java_activity.borrow_mut();
let java_activity = java_activity.as_mut().unwrap(); let java_activity = java_activity.as_mut().unwrap();
let env = java_activity.vm.get_env().unwrap(); let env = java_activity.vm.get_env().unwrap();
env.call_method(java_activity.activity.as_obj(), env.call_method(
"presentOpenSVGDialog", java_activity.activity.as_obj(),
"()V", "presentOpenSVGDialog",
&[]).unwrap(); "()V",
&[],
)
.unwrap();
}); });
} }
@ -232,13 +253,20 @@ impl ResourceLoader for AndroidResourceLoader {
let java_resource_loader = java_resource_loader.as_ref().unwrap(); let java_resource_loader = java_resource_loader.as_ref().unwrap();
let loader = java_resource_loader.loader.as_obj(); let loader = java_resource_loader.loader.as_obj();
let env = java_resource_loader.vm.get_env().unwrap(); let env = java_resource_loader.vm.get_env().unwrap();
match env.call_method(loader, match env
"slurp", .call_method(
"(Ljava/lang/String;)Ljava/nio/ByteBuffer;", loader,
&[JValue::Object(*env.new_string(path).unwrap())]).unwrap() { "slurp",
"(Ljava/lang/String;)Ljava/nio/ByteBuffer;",
&[JValue::Object(*env.new_string(path).unwrap())],
)
.unwrap()
{
JValue::Object(object) => { JValue::Object(object) => {
let byte_buffer = JByteBuffer::from(object); let byte_buffer = JByteBuffer::from(object);
Ok(Vec::from(env.get_direct_buffer_address(byte_buffer).unwrap())) Ok(Vec::from(
env.get_direct_buffer_address(byte_buffer).unwrap(),
))
} }
_ => panic!("Unexpected return value!"), _ => panic!("Unexpected return value!"),
} }

View File

@ -14,30 +14,47 @@ use crate::GRIDLINE_COUNT;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::{BufferData, BufferTarget, BufferUploadMode, Device, VertexAttrType}; use pathfinder_gpu::{BufferData, BufferTarget, BufferUploadMode, Device, VertexAttrType};
pub struct GroundProgram<D> where D: Device { pub struct GroundProgram<D>
where
D: Device,
{
pub program: D::Program, pub program: D::Program,
pub transform_uniform: D::Uniform, pub transform_uniform: D::Uniform,
pub color_uniform: D::Uniform, pub color_uniform: D::Uniform,
} }
impl<D> GroundProgram<D> where D: Device { impl<D> GroundProgram<D>
where
D: Device,
{
pub fn new(device: &D, resources: &dyn ResourceLoader) -> GroundProgram<D> { pub fn new(device: &D, resources: &dyn ResourceLoader) -> GroundProgram<D> {
let program = device.create_program(resources, "demo_ground"); let program = device.create_program(resources, "demo_ground");
let transform_uniform = device.get_uniform(&program, "Transform"); let transform_uniform = device.get_uniform(&program, "Transform");
let color_uniform = device.get_uniform(&program, "Color"); let color_uniform = device.get_uniform(&program, "Color");
GroundProgram { program, transform_uniform, color_uniform } GroundProgram {
program,
transform_uniform,
color_uniform,
}
} }
} }
pub struct GroundSolidVertexArray<D> where D: Device { pub struct GroundSolidVertexArray<D>
where
D: Device,
{
pub vertex_array: D::VertexArray, pub vertex_array: D::VertexArray,
} }
impl<D> GroundSolidVertexArray<D> where D: Device { impl<D> GroundSolidVertexArray<D>
pub fn new(device: &D, where
ground_program: &GroundProgram<D>, D: Device,
quad_vertex_positions_buffer: &D::Buffer) {
-> GroundSolidVertexArray<D> { pub fn new(
device: &D,
ground_program: &GroundProgram<D>,
quad_vertex_positions_buffer: &D::Buffer,
) -> GroundSolidVertexArray<D> {
let vertex_array = device.create_vertex_array(); let vertex_array = device.create_vertex_array();
let position_attr = device.get_vertex_attr(&ground_program.program, "Position"); let position_attr = device.get_vertex_attr(&ground_program.program, "Position");
@ -51,19 +68,27 @@ impl<D> GroundSolidVertexArray<D> where D: Device {
} }
} }
pub struct GroundLineVertexArray<D> where D: Device { pub struct GroundLineVertexArray<D>
where
D: Device,
{
pub vertex_array: D::VertexArray, pub vertex_array: D::VertexArray,
#[allow(dead_code)] #[allow(dead_code)]
grid_vertex_positions_buffer: D::Buffer, grid_vertex_positions_buffer: D::Buffer,
} }
impl<D> GroundLineVertexArray<D> where D: Device { impl<D> GroundLineVertexArray<D>
where
D: Device,
{
pub fn new(device: &D, ground_program: &GroundProgram<D>) -> GroundLineVertexArray<D> { pub fn new(device: &D, ground_program: &GroundProgram<D>) -> GroundLineVertexArray<D> {
let grid_vertex_positions_buffer = device.create_buffer(); let grid_vertex_positions_buffer = device.create_buffer();
device.allocate_buffer(&grid_vertex_positions_buffer, device.allocate_buffer(
BufferData::Memory(&create_grid_vertex_positions()), &grid_vertex_positions_buffer,
BufferTarget::Vertex, BufferData::Memory(&create_grid_vertex_positions()),
BufferUploadMode::Static); BufferTarget::Vertex,
BufferUploadMode::Static,
);
let vertex_array = device.create_vertex_array(); let vertex_array = device.create_vertex_array();
@ -74,7 +99,10 @@ impl<D> GroundLineVertexArray<D> where D: Device {
device.bind_buffer(&grid_vertex_positions_buffer, BufferTarget::Vertex); device.bind_buffer(&grid_vertex_positions_buffer, BufferTarget::Vertex);
device.configure_float_vertex_attr(&position_attr, 2, VertexAttrType::U8, false, 0, 0, 0); device.configure_float_vertex_attr(&position_attr, 2, VertexAttrType::U8, false, 0, 0, 0);
GroundLineVertexArray { vertex_array, grid_vertex_positions_buffer } GroundLineVertexArray {
vertex_array,
grid_vertex_positions_buffer,
}
} }
} }
@ -82,8 +110,10 @@ fn create_grid_vertex_positions() -> Vec<(u8, u8)> {
let mut positions = vec![]; let mut positions = vec![];
for index in 0..(GRIDLINE_COUNT + 1) { for index in 0..(GRIDLINE_COUNT + 1) {
positions.extend_from_slice(&[ positions.extend_from_slice(&[
(0, index), (GRIDLINE_COUNT, index), (0, index),
(index, 0), (index, GRIDLINE_COUNT), (GRIDLINE_COUNT, index),
(index, 0),
(index, GRIDLINE_COUNT),
]); ]);
} }
positions positions

File diff suppressed because it is too large Load Diff

View File

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::{BackgroundColor, Mode, Options};
use crate::window::Window; use crate::window::Window;
use crate::{BackgroundColor, Mode, Options};
use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_geometry::basic::point::Point2DI32;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI32;
use pathfinder_gpu::Device;
use pathfinder_gpu::resources::ResourceLoader; use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::Device;
use pathfinder_renderer::gpu::debug::DebugUI; use pathfinder_renderer::gpu::debug::DebugUI;
use pathfinder_ui::{BUTTON_HEIGHT, BUTTON_TEXT_OFFSET, BUTTON_WIDTH, FONT_ASCENT, PADDING}; use pathfinder_ui::{BUTTON_HEIGHT, BUTTON_TEXT_OFFSET, BUTTON_WIDTH, FONT_ASCENT, PADDING};
use pathfinder_ui::{TEXT_COLOR, TOOLTIP_HEIGHT, WINDOW_COLOR}; use pathfinder_ui::{TEXT_COLOR, TOOLTIP_HEIGHT, WINDOW_COLOR};
@ -35,15 +35,18 @@ const BACKGROUND_PANEL_HEIGHT: i32 = BUTTON_HEIGHT * 3;
const ROTATE_PANEL_WIDTH: i32 = SLIDER_WIDTH + PADDING * 2; const ROTATE_PANEL_WIDTH: i32 = SLIDER_WIDTH + PADDING * 2;
const ROTATE_PANEL_HEIGHT: i32 = PADDING * 2 + SLIDER_HEIGHT; const ROTATE_PANEL_HEIGHT: i32 = PADDING * 2 + SLIDER_HEIGHT;
static EFFECTS_PNG_NAME: &'static str = "demo-effects"; static EFFECTS_PNG_NAME: &'static str = "demo-effects";
static OPEN_PNG_NAME: &'static str = "demo-open"; static OPEN_PNG_NAME: &'static str = "demo-open";
static ROTATE_PNG_NAME: &'static str = "demo-rotate"; static ROTATE_PNG_NAME: &'static str = "demo-rotate";
static ZOOM_IN_PNG_NAME: &'static str = "demo-zoom-in"; static ZOOM_IN_PNG_NAME: &'static str = "demo-zoom-in";
static ZOOM_OUT_PNG_NAME: &'static str = "demo-zoom-out"; static ZOOM_OUT_PNG_NAME: &'static str = "demo-zoom-out";
static BACKGROUND_PNG_NAME: &'static str = "demo-background"; static BACKGROUND_PNG_NAME: &'static str = "demo-background";
static SCREENSHOT_PNG_NAME: &'static str = "demo-screenshot"; static SCREENSHOT_PNG_NAME: &'static str = "demo-screenshot";
pub struct DemoUI<D> where D: Device { pub struct DemoUI<D>
where
D: Device,
{
effects_texture: D::Texture, effects_texture: D::Texture,
open_texture: D::Texture, open_texture: D::Texture,
rotate_texture: D::Texture, rotate_texture: D::Texture,
@ -57,7 +60,6 @@ pub struct DemoUI<D> where D: Device {
rotate_panel_visible: bool, rotate_panel_visible: bool,
// FIXME(pcwalton): Factor the below out into a model class. // FIXME(pcwalton): Factor the below out into a model class.
pub mode: Mode, pub mode: Mode,
pub background_color: BackgroundColor, pub background_color: BackgroundColor,
pub gamma_correction_effect_enabled: bool, pub gamma_correction_effect_enabled: bool,
@ -68,7 +70,10 @@ pub struct DemoUI<D> where D: Device {
pub show_text_effects: bool, pub show_text_effects: bool,
} }
impl<D> DemoUI<D> where D: Device { impl<D> DemoUI<D>
where
D: Device,
{
pub fn new(device: &D, resources: &dyn ResourceLoader, options: Options) -> DemoUI<D> { pub fn new(device: &D, resources: &dyn ResourceLoader, options: Options) -> DemoUI<D> {
let effects_texture = device.create_texture_from_png(resources, EFFECTS_PNG_NAME); let effects_texture = device.create_texture_from_png(resources, EFFECTS_PNG_NAME);
let open_texture = device.create_texture_from_png(resources, OPEN_PNG_NAME); let open_texture = device.create_texture_from_png(resources, OPEN_PNG_NAME);
@ -106,12 +111,15 @@ impl<D> DemoUI<D> where D: Device {
(self.rotation as f32 / SLIDER_WIDTH as f32 * 2.0 - 1.0) * PI (self.rotation as f32 / SLIDER_WIDTH as f32 * 2.0 - 1.0) * PI
} }
pub fn update<W>(&mut self, pub fn update<W>(
device: &D, &mut self,
window: &mut W, device: &D,
debug_ui: &mut DebugUI<D>, window: &mut W,
action: &mut UIAction) debug_ui: &mut DebugUI<D>,
where W: Window { action: &mut UIAction,
) where
W: Window,
{
// Draw message text. // Draw message text.
self.draw_message_text(device, debug_ui); self.draw_message_text(device, debug_ui);
@ -125,42 +133,59 @@ impl<D> DemoUI<D> where D: Device {
// Draw text effects button. // Draw text effects button.
if self.show_text_effects { if self.show_text_effects {
if debug_ui.ui.draw_button(device, position, &self.effects_texture) { if debug_ui
.ui
.draw_button(device, position, &self.effects_texture)
{
self.effects_panel_visible = !self.effects_panel_visible; self.effects_panel_visible = !self.effects_panel_visible;
} }
if !self.effects_panel_visible { if !self.effects_panel_visible {
debug_ui.ui.draw_tooltip(device, debug_ui.ui.draw_tooltip(
"Text Effects", device,
RectI32::new(position, button_size)); "Text Effects",
RectI32::new(position, button_size),
);
} }
position += Point2DI32::new(button_size.x() + PADDING, 0); position += Point2DI32::new(button_size.x() + PADDING, 0);
} }
// Draw open button. // Draw open button.
if debug_ui.ui.draw_button(device, position, &self.open_texture) { if debug_ui
.ui
.draw_button(device, position, &self.open_texture)
{
// FIXME(pcwalton): This is not sufficient for Android, where we will need to take in // FIXME(pcwalton): This is not sufficient for Android, where we will need to take in
// the contents of the file. // the contents of the file.
window.present_open_svg_dialog(); window.present_open_svg_dialog();
} }
debug_ui.ui.draw_tooltip(device, "Open SVG", RectI32::new(position, button_size)); debug_ui
.ui
.draw_tooltip(device, "Open SVG", RectI32::new(position, button_size));
position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0);
// Draw screenshot button. // Draw screenshot button.
if debug_ui.ui.draw_button(device, position, &self.screenshot_texture) { if debug_ui
.ui
.draw_button(device, position, &self.screenshot_texture)
{
// FIXME(pcwalton): This is not sufficient for Android, where we will need to take in // FIXME(pcwalton): This is not sufficient for Android, where we will need to take in
// the contents of the file. // the contents of the file.
if let Ok(file) = window.run_save_dialog("png") { if let Ok(file) = window.run_save_dialog("png") {
*action = UIAction::TakeScreenshot(file); *action = UIAction::TakeScreenshot(file);
} }
} }
debug_ui.ui.draw_tooltip(device, "Take Screenshot", RectI32::new(position, button_size)); debug_ui.ui.draw_tooltip(
device,
"Take Screenshot",
RectI32::new(position, button_size),
);
position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0);
// Draw mode switch. // Draw mode switch.
let new_mode = debug_ui.ui.draw_text_switch(device, let new_mode =
position, debug_ui
&["2D", "3D", "VR"], .ui
self.mode as u8); .draw_text_switch(device, position, &["2D", "3D", "VR"], self.mode as u8);
if new_mode != self.mode as u8 { if new_mode != self.mode as u8 {
self.mode = match new_mode { self.mode = match new_mode {
0 => Mode::TwoD, 0 => Mode::TwoD,
@ -172,19 +197,26 @@ impl<D> DemoUI<D> where D: Device {
let mode_switch_width = debug_ui.ui.measure_switch(3); let mode_switch_width = debug_ui.ui.measure_switch(3);
let mode_switch_size = Point2DI32::new(mode_switch_width, BUTTON_HEIGHT); let mode_switch_size = Point2DI32::new(mode_switch_width, BUTTON_HEIGHT);
debug_ui.ui.draw_tooltip(device, debug_ui.ui.draw_tooltip(
"2D/3D/VR Mode", device,
RectI32::new(position, mode_switch_size)); "2D/3D/VR Mode",
RectI32::new(position, mode_switch_size),
);
position += Point2DI32::new(mode_switch_width + PADDING, 0); position += Point2DI32::new(mode_switch_width + PADDING, 0);
// Draw background switch. // Draw background switch.
if debug_ui.ui.draw_button(device, position, &self.background_texture) { if debug_ui
.ui
.draw_button(device, position, &self.background_texture)
{
self.background_panel_visible = !self.background_panel_visible; self.background_panel_visible = !self.background_panel_visible;
} }
if !self.background_panel_visible { if !self.background_panel_visible {
debug_ui.ui.draw_tooltip(device, debug_ui.ui.draw_tooltip(
"Background Color", device,
RectI32::new(position, button_size)); "Background Color",
RectI32::new(position, button_size),
);
} }
// Draw background panel, if necessary. // Draw background panel, if necessary.
@ -199,25 +231,40 @@ impl<D> DemoUI<D> where D: Device {
return; return;
} }
if debug_ui.ui.draw_button(device, position, &self.rotate_texture) { if debug_ui
.ui
.draw_button(device, position, &self.rotate_texture)
{
self.rotate_panel_visible = !self.rotate_panel_visible; self.rotate_panel_visible = !self.rotate_panel_visible;
} }
if !self.rotate_panel_visible { if !self.rotate_panel_visible {
debug_ui.ui.draw_tooltip(device, "Rotate", RectI32::new(position, button_size)); debug_ui
.ui
.draw_tooltip(device, "Rotate", RectI32::new(position, button_size));
} }
self.draw_rotate_panel(device, debug_ui, position.x(), action); self.draw_rotate_panel(device, debug_ui, position.x(), action);
position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0);
if debug_ui.ui.draw_button(device, position, &self.zoom_in_texture) { if debug_ui
.ui
.draw_button(device, position, &self.zoom_in_texture)
{
*action = UIAction::ZoomIn; *action = UIAction::ZoomIn;
} }
debug_ui.ui.draw_tooltip(device, "Zoom In", RectI32::new(position, button_size)); debug_ui
.ui
.draw_tooltip(device, "Zoom In", RectI32::new(position, button_size));
position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0);
if debug_ui.ui.draw_button(device, position, &self.zoom_out_texture) { if debug_ui
.ui
.draw_button(device, position, &self.zoom_out_texture)
{
*action = UIAction::ZoomOut; *action = UIAction::ZoomOut;
} }
debug_ui.ui.draw_tooltip(device, "Zoom Out", RectI32::new(position, button_size)); debug_ui
.ui
.draw_tooltip(device, "Zoom Out", RectI32::new(position, button_size));
position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0); position += Point2DI32::new(BUTTON_WIDTH + PADDING, 0);
} }
@ -229,13 +276,17 @@ impl<D> DemoUI<D> where D: Device {
let message_size = debug_ui.ui.measure_text(&self.message); let message_size = debug_ui.ui.measure_text(&self.message);
let window_origin = Point2DI32::new(PADDING, PADDING); let window_origin = Point2DI32::new(PADDING, PADDING);
let window_size = Point2DI32::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT); let window_size = Point2DI32::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT);
debug_ui.ui.draw_solid_rounded_rect(device, debug_ui.ui.draw_solid_rounded_rect(
RectI32::new(window_origin, window_size), device,
WINDOW_COLOR); RectI32::new(window_origin, window_size),
debug_ui.ui.draw_text(device, WINDOW_COLOR,
&self.message, );
window_origin + Point2DI32::new(PADDING, PADDING + FONT_ASCENT), debug_ui.ui.draw_text(
false); device,
&self.message,
window_origin + Point2DI32::new(PADDING, PADDING + FONT_ASCENT),
false,
);
} }
fn draw_effects_panel(&mut self, device: &D, debug_ui: &mut DebugUI<D>) { fn draw_effects_panel(&mut self, device: &D, debug_ui: &mut DebugUI<D>) {
@ -245,40 +296,48 @@ impl<D> DemoUI<D> where D: Device {
let bottom = debug_ui.ui.framebuffer_size().y() - PADDING; let bottom = debug_ui.ui.framebuffer_size().y() - PADDING;
let effects_panel_y = bottom - (BUTTON_HEIGHT + PADDING + EFFECTS_PANEL_HEIGHT); let effects_panel_y = bottom - (BUTTON_HEIGHT + PADDING + EFFECTS_PANEL_HEIGHT);
debug_ui.ui.draw_solid_rounded_rect(device, debug_ui.ui.draw_solid_rounded_rect(
RectI32::new(Point2DI32::new(PADDING, effects_panel_y), device,
Point2DI32::new(EFFECTS_PANEL_WIDTH, RectI32::new(
EFFECTS_PANEL_HEIGHT)), Point2DI32::new(PADDING, effects_panel_y),
WINDOW_COLOR); Point2DI32::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT),
),
WINDOW_COLOR,
);
self.gamma_correction_effect_enabled = self.gamma_correction_effect_enabled = self.draw_effects_switch(
self.draw_effects_switch(device, device,
debug_ui, debug_ui,
"Gamma Correction", "Gamma Correction",
0, 0,
effects_panel_y, effects_panel_y,
self.gamma_correction_effect_enabled); self.gamma_correction_effect_enabled,
self.stem_darkening_effect_enabled = );
self.draw_effects_switch(device, self.stem_darkening_effect_enabled = self.draw_effects_switch(
debug_ui, device,
"Stem Darkening", debug_ui,
1, "Stem Darkening",
effects_panel_y, 1,
self.stem_darkening_effect_enabled); effects_panel_y,
self.subpixel_aa_effect_enabled = self.stem_darkening_effect_enabled,
self.draw_effects_switch(device, );
debug_ui, self.subpixel_aa_effect_enabled = self.draw_effects_switch(
"Subpixel AA", device,
2, debug_ui,
effects_panel_y, "Subpixel AA",
self.subpixel_aa_effect_enabled); 2,
effects_panel_y,
self.subpixel_aa_effect_enabled,
);
} }
fn draw_background_panel(&mut self, fn draw_background_panel(
device: &D, &mut self,
debug_ui: &mut DebugUI<D>, device: &D,
panel_x: i32, debug_ui: &mut DebugUI<D>,
action: &mut UIAction) { panel_x: i32,
action: &mut UIAction,
) {
if !self.background_panel_visible { if !self.background_panel_visible {
return; return;
} }
@ -286,34 +345,45 @@ impl<D> DemoUI<D> where D: Device {
let bottom = debug_ui.ui.framebuffer_size().y() - PADDING; let bottom = debug_ui.ui.framebuffer_size().y() - PADDING;
let panel_y = bottom - (BUTTON_HEIGHT + PADDING + BACKGROUND_PANEL_HEIGHT); let panel_y = bottom - (BUTTON_HEIGHT + PADDING + BACKGROUND_PANEL_HEIGHT);
let panel_position = Point2DI32::new(panel_x, panel_y); let panel_position = Point2DI32::new(panel_x, panel_y);
debug_ui.ui.draw_solid_rounded_rect(device, debug_ui.ui.draw_solid_rounded_rect(
RectI32::new(panel_position, device,
Point2DI32::new(BACKGROUND_PANEL_WIDTH, RectI32::new(
BACKGROUND_PANEL_HEIGHT)), panel_position,
WINDOW_COLOR); Point2DI32::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT),
),
WINDOW_COLOR,
);
self.draw_background_menu_item(device, self.draw_background_menu_item(
debug_ui, device,
BackgroundColor::Light, debug_ui,
panel_position, BackgroundColor::Light,
action); panel_position,
self.draw_background_menu_item(device, action,
debug_ui, );
BackgroundColor::Dark, self.draw_background_menu_item(
panel_position, device,
action); debug_ui,
self.draw_background_menu_item(device, BackgroundColor::Dark,
debug_ui, panel_position,
BackgroundColor::Transparent, action,
panel_position, );
action); self.draw_background_menu_item(
device,
debug_ui,
BackgroundColor::Transparent,
panel_position,
action,
);
} }
fn draw_rotate_panel(&mut self, fn draw_rotate_panel(
device: &D, &mut self,
debug_ui: &mut DebugUI<D>, device: &D,
rotate_panel_x: i32, debug_ui: &mut DebugUI<D>,
action: &mut UIAction) { rotate_panel_x: i32,
action: &mut UIAction,
) {
if !self.rotate_panel_visible { if !self.rotate_panel_visible {
return; return;
} }
@ -322,40 +392,54 @@ impl<D> DemoUI<D> where D: Device {
let rotate_panel_y = bottom - (BUTTON_HEIGHT + PADDING + ROTATE_PANEL_HEIGHT); let rotate_panel_y = bottom - (BUTTON_HEIGHT + PADDING + ROTATE_PANEL_HEIGHT);
let rotate_panel_origin = Point2DI32::new(rotate_panel_x, rotate_panel_y); let rotate_panel_origin = Point2DI32::new(rotate_panel_x, rotate_panel_y);
let rotate_panel_size = Point2DI32::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT); let rotate_panel_size = Point2DI32::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT);
debug_ui.ui.draw_solid_rounded_rect(device, debug_ui.ui.draw_solid_rounded_rect(
RectI32::new(rotate_panel_origin, rotate_panel_size), device,
WINDOW_COLOR); RectI32::new(rotate_panel_origin, rotate_panel_size),
WINDOW_COLOR,
);
let (widget_x, widget_y) = (rotate_panel_x + PADDING, rotate_panel_y + PADDING); let (widget_x, widget_y) = (rotate_panel_x + PADDING, rotate_panel_y + PADDING);
let widget_rect = RectI32::new(Point2DI32::new(widget_x, widget_y), let widget_rect = RectI32::new(
Point2DI32::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT)); Point2DI32::new(widget_x, widget_y),
if let Some(position) = debug_ui.ui Point2DI32::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT),
.event_queue );
.handle_mouse_down_or_dragged_in_rect(widget_rect) { if let Some(position) = debug_ui
.ui
.event_queue
.handle_mouse_down_or_dragged_in_rect(widget_rect)
{
self.rotation = position.x(); self.rotation = position.x();
*action = UIAction::Rotate(self.rotation()); *action = UIAction::Rotate(self.rotation());
} }
let slider_track_y = rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 - let slider_track_y =
SLIDER_TRACK_HEIGHT / 2; rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 - SLIDER_TRACK_HEIGHT / 2;
let slider_track_rect = let slider_track_rect = RectI32::new(
RectI32::new(Point2DI32::new(widget_x, slider_track_y), Point2DI32::new(widget_x, slider_track_y),
Point2DI32::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT)); Point2DI32::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT),
debug_ui.ui.draw_rect_outline(device, slider_track_rect, TEXT_COLOR); );
debug_ui
.ui
.draw_rect_outline(device, slider_track_rect, TEXT_COLOR);
let slider_knob_x = widget_x + self.rotation - SLIDER_KNOB_WIDTH / 2; let slider_knob_x = widget_x + self.rotation - SLIDER_KNOB_WIDTH / 2;
let slider_knob_rect = let slider_knob_rect = RectI32::new(
RectI32::new(Point2DI32::new(slider_knob_x, widget_y), Point2DI32::new(slider_knob_x, widget_y),
Point2DI32::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT)); Point2DI32::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT),
debug_ui.ui.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR); );
debug_ui
.ui
.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR);
} }
fn draw_background_menu_item(&mut self, fn draw_background_menu_item(
device: &D, &mut self,
debug_ui: &mut DebugUI<D>, device: &D,
color: BackgroundColor, debug_ui: &mut DebugUI<D>,
panel_position: Point2DI32, color: BackgroundColor,
action: &mut UIAction) { panel_position: Point2DI32,
action: &mut UIAction,
) {
let (text, index) = (color.as_str(), color as i32); let (text, index) = (color.as_str(), color as i32);
let widget_size = Point2DI32::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT); let widget_size = Point2DI32::new(BACKGROUND_PANEL_WIDTH, BUTTON_HEIGHT);
@ -363,36 +447,50 @@ impl<D> DemoUI<D> where D: Device {
let widget_rect = RectI32::new(widget_origin, widget_size); let widget_rect = RectI32::new(widget_origin, widget_size);
if color == self.background_color { if color == self.background_color {
debug_ui.ui.draw_solid_rounded_rect(device, widget_rect, TEXT_COLOR); debug_ui
.ui
.draw_solid_rounded_rect(device, widget_rect, TEXT_COLOR);
} }
let (text_x, text_y) = (PADDING * 2, BUTTON_TEXT_OFFSET); let (text_x, text_y) = (PADDING * 2, BUTTON_TEXT_OFFSET);
let text_position = widget_origin + Point2DI32::new(text_x, text_y); let text_position = widget_origin + Point2DI32::new(text_x, text_y);
debug_ui.ui.draw_text(device, text, text_position, color == self.background_color); debug_ui
.ui
.draw_text(device, text, text_position, color == self.background_color);
if let Some(_) = debug_ui.ui.event_queue.handle_mouse_down_in_rect(widget_rect) { if let Some(_) = debug_ui
.ui
.event_queue
.handle_mouse_down_in_rect(widget_rect)
{
self.background_color = color; self.background_color = color;
*action = UIAction::ModelChanged; *action = UIAction::ModelChanged;
} }
} }
fn draw_effects_switch(&self, fn draw_effects_switch(
device: &D, &self,
debug_ui: &mut DebugUI<D>, device: &D,
text: &str, debug_ui: &mut DebugUI<D>,
index: i32, text: &str,
window_y: i32, index: i32,
value: bool) window_y: i32,
-> bool { value: bool,
) -> bool {
let text_x = PADDING * 2; let text_x = PADDING * 2;
let text_y = window_y + PADDING + BUTTON_TEXT_OFFSET + (BUTTON_HEIGHT + PADDING) * index; let text_y = window_y + PADDING + BUTTON_TEXT_OFFSET + (BUTTON_HEIGHT + PADDING) * index;
debug_ui.ui.draw_text(device, text, Point2DI32::new(text_x, text_y), false); debug_ui
.ui
.draw_text(device, text, Point2DI32::new(text_x, text_y), false);
let switch_width = debug_ui.ui.measure_switch(2); let switch_width = debug_ui.ui.measure_switch(2);
let switch_x = PADDING + EFFECTS_PANEL_WIDTH - (switch_width + PADDING); let switch_x = PADDING + EFFECTS_PANEL_WIDTH - (switch_width + PADDING);
let switch_y = window_y + PADDING + (BUTTON_HEIGHT + PADDING) * index; let switch_y = window_y + PADDING + (BUTTON_HEIGHT + PADDING) * index;
let switch_position = Point2DI32::new(switch_x, switch_y); let switch_position = Point2DI32::new(switch_x, switch_y);
debug_ui.ui.draw_text_switch(device, switch_position, &["Off", "On"], value as u8) != 0 debug_ui
.ui
.draw_text_switch(device, switch_position, &["Off", "On"], value as u8)
!= 0
} }
} }

View File

@ -21,7 +21,9 @@ use std::path::PathBuf;
pub trait Window { pub trait Window {
fn gl_version(&self) -> GLVersion; fn gl_version(&self) -> GLVersion;
fn gl_default_framebuffer(&self) -> GLuint { 0 } fn gl_default_framebuffer(&self) -> GLuint {
0
}
fn viewport(&self, view: View) -> RectI32; fn viewport(&self, view: View) -> RectI32;
fn make_current(&mut self, view: View); fn make_current(&mut self, view: View);
fn present(&mut self); fn present(&mut self);
@ -31,7 +33,10 @@ pub trait Window {
fn present_open_svg_dialog(&mut self); fn present_open_svg_dialog(&mut self);
fn run_save_dialog(&self, extension: &str) -> Result<PathBuf, ()>; fn run_save_dialog(&self, extension: &str) -> Result<PathBuf, ()>;
fn adjust_thread_pool_settings(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder { fn adjust_thread_pool_settings(
&self,
thread_pool_builder: ThreadPoolBuilder,
) -> ThreadPoolBuilder {
thread_pool_builder thread_pool_builder
} }
} }
@ -45,10 +50,16 @@ pub enum Event {
MouseMoved(Point2DI32), MouseMoved(Point2DI32),
MouseDragged(Point2DI32), MouseDragged(Point2DI32),
Zoom(f32, Point2DI32), Zoom(f32, Point2DI32),
Look { pitch: f32, yaw: f32 }, Look {
pitch: f32,
yaw: f32,
},
SetEyeTransforms(Vec<OcularTransform>), SetEyeTransforms(Vec<OcularTransform>),
OpenSVG(SVGPath), OpenSVG(SVGPath),
User { message_type: u32, message_data: u32 }, User {
message_type: u32,
message_data: u32,
},
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -67,7 +78,10 @@ pub struct WindowSize {
impl WindowSize { impl WindowSize {
#[inline] #[inline]
pub fn device_size(&self) -> Point2DI32 { pub fn device_size(&self) -> Point2DI32 {
self.logical_size.to_f32().scale(self.backing_scale_factor).to_i32() self.logical_size
.to_f32()
.scale(self.backing_scale_factor)
.to_i32()
} }
} }

View File

@ -12,17 +12,17 @@
use jemallocator; use jemallocator;
use nfd::Response; use nfd::Response;
use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize};
use pathfinder_demo::DemoApp; use pathfinder_demo::DemoApp;
use pathfinder_demo::Options; use pathfinder_demo::Options;
use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize};
use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_geometry::basic::point::Point2DI32;
use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::rect::RectI32;
use pathfinder_gl::GLVersion; use pathfinder_gl::GLVersion;
use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader}; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader};
use sdl2::{EventPump, EventSubsystem, Sdl, VideoSubsystem};
use sdl2::event::{Event as SDLEvent, WindowEvent}; use sdl2::event::{Event as SDLEvent, WindowEvent};
use sdl2::keyboard::Keycode as SDLKeycode; use sdl2::keyboard::Keycode as SDLKeycode;
use sdl2::video::{GLContext, GLProfile, Window as SDLWindow}; use sdl2::video::{GLContext, GLProfile, Window as SDLWindow};
use sdl2::{EventPump, EventSubsystem, Sdl, VideoSubsystem};
use sdl2_sys::{SDL_Event, SDL_UserEvent}; use sdl2_sys::{SDL_Event, SDL_UserEvent};
use std::path::PathBuf; use std::path::PathBuf;
use std::ptr; use std::ptr;
@ -150,14 +150,17 @@ impl WindowImpl {
gl_attributes.set_depth_size(24); gl_attributes.set_depth_size(24);
gl_attributes.set_stencil_size(8); gl_attributes.set_stencil_size(8);
window = sdl_video.window("Pathfinder Demo", window = sdl_video
DEFAULT_WINDOW_WIDTH, .window(
DEFAULT_WINDOW_HEIGHT) "Pathfinder Demo",
.opengl() DEFAULT_WINDOW_WIDTH,
.resizable() DEFAULT_WINDOW_HEIGHT,
.allow_highdpi() )
.build() .opengl()
.unwrap(); .resizable()
.allow_highdpi()
.build()
.unwrap();
gl_context = window.gl_create_context().unwrap(); gl_context = window.gl_create_context().unwrap();
gl::load_with(|name| sdl_video.gl_get_proc_address(name) as *const _); gl::load_with(|name| sdl_video.gl_get_proc_address(name) as *const _);
@ -166,9 +169,7 @@ impl WindowImpl {
let resource_loader = FilesystemResourceLoader::locate(); let resource_loader = FilesystemResourceLoader::locate();
let open_svg_message_type = unsafe { let open_svg_message_type = unsafe { sdl_event.register_event().unwrap() };
sdl_event.register_event().unwrap()
};
WindowImpl { WindowImpl {
window, window,
@ -211,16 +212,17 @@ impl WindowImpl {
fn convert_sdl_event(&self, sdl_event: SDLEvent) -> Option<Event> { fn convert_sdl_event(&self, sdl_event: SDLEvent) -> Option<Event> {
match sdl_event { match sdl_event {
SDLEvent::User { type_, .. } if type_ == self.open_svg_message_type => { SDLEvent::User { type_, .. } if type_ == self.open_svg_message_type => Some(
Some(Event::OpenSVG(SVGPath::Path(self.selected_file.clone().unwrap()))) Event::OpenSVG(SVGPath::Path(self.selected_file.clone().unwrap())),
} ),
SDLEvent::User { type_, code, .. } => { SDLEvent::User { type_, code, .. } => Some(Event::User {
Some(Event::User { message_type: type_, message_data: code as u32 }) message_type: type_,
} message_data: code as u32,
SDLEvent::MouseButtonDown { x, y, .. } => { }),
Some(Event::MouseDown(Point2DI32::new(x, y))) SDLEvent::MouseButtonDown { x, y, .. } => Some(Event::MouseDown(Point2DI32::new(x, y))),
} SDLEvent::MouseMotion {
SDLEvent::MouseMotion { x, y, mousestate, .. } => { x, y, mousestate, ..
} => {
let position = Point2DI32::new(x, y); let position = Point2DI32::new(x, y);
if mousestate.left() { if mousestate.left() {
Some(Event::MouseDragged(position)) Some(Event::MouseDragged(position))
@ -229,15 +231,18 @@ impl WindowImpl {
} }
} }
SDLEvent::Quit { .. } => Some(Event::Quit), SDLEvent::Quit { .. } => Some(Event::Quit),
SDLEvent::Window { win_event: WindowEvent::SizeChanged(..), .. } => { SDLEvent::Window {
Some(Event::WindowResized(self.size())) win_event: WindowEvent::SizeChanged(..),
} ..
SDLEvent::KeyDown { keycode: Some(sdl_keycode), .. } => { } => Some(Event::WindowResized(self.size())),
self.convert_sdl_keycode(sdl_keycode).map(Event::KeyDown) SDLEvent::KeyDown {
} keycode: Some(sdl_keycode),
SDLEvent::KeyUp { keycode: Some(sdl_keycode), .. } => { ..
self.convert_sdl_keycode(sdl_keycode).map(Event::KeyUp) } => self.convert_sdl_keycode(sdl_keycode).map(Event::KeyDown),
} SDLEvent::KeyUp {
keycode: Some(sdl_keycode),
..
} => self.convert_sdl_keycode(sdl_keycode).map(Event::KeyUp),
SDLEvent::MultiGesture { d_dist, .. } => { SDLEvent::MultiGesture { d_dist, .. } => {
let mouse_state = self.event_pump.mouse_state(); let mouse_state = self.event_pump.mouse_state();
let center = Point2DI32::new(mouse_state.x(), mouse_state.y()); let center = Point2DI32::new(mouse_state.x(), mouse_state.y());
@ -251,8 +256,10 @@ impl WindowImpl {
match sdl_keycode { match sdl_keycode {
SDLKeycode::Escape => Some(Keycode::Escape), SDLKeycode::Escape => Some(Keycode::Escape),
SDLKeycode::Tab => Some(Keycode::Tab), SDLKeycode::Tab => Some(Keycode::Tab),
sdl_keycode if sdl_keycode as i32 >= SDLKeycode::A as i32 && sdl_keycode
sdl_keycode as i32 <= SDLKeycode::Z as i32 => { if sdl_keycode as i32 >= SDLKeycode::A as i32
&& sdl_keycode as i32 <= SDLKeycode::Z as i32 =>
{
let offset = (sdl_keycode as i32 - SDLKeycode::A as i32) as u8; let offset = (sdl_keycode as i32 - SDLKeycode::A as i32) as u8;
Some(Keycode::Alphanumeric(offset + b'a')) Some(Keycode::Alphanumeric(offset + b'a'))
} }