Run `rustfmt` on the demos
This commit is contained in:
parent
0da11ffe01
commit
60b951409c
|
@ -11,11 +11,11 @@
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
use jni::{JNIEnv, JavaVM};
|
||||
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::Options;
|
||||
use pathfinder_demo::window::{Event, SVGPath, View, Window, WindowSize};
|
||||
use pathfinder_geometry::basic::point::Point2DI32;
|
||||
use pathfinder_geometry::basic::rect::RectI32;
|
||||
use pathfinder_gl::GLVersion;
|
||||
|
@ -40,15 +40,19 @@ thread_local! {
|
|||
static RESOURCE_LOADER: AndroidResourceLoader = AndroidResourceLoader;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_init(env: JNIEnv,
|
||||
class: JClass,
|
||||
activity: JObject,
|
||||
loader: JObject,
|
||||
width: i32,
|
||||
height: i32) {
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_init(
|
||||
env: JNIEnv,
|
||||
class: JClass,
|
||||
activity: JObject,
|
||||
loader: JObject,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) {
|
||||
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 options = Options::default();
|
||||
|
||||
|
@ -65,10 +69,10 @@ pub unsafe extern "system" fn
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_prepareFrame(env: JNIEnv,
|
||||
class: JClass)
|
||||
-> i32 {
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_prepareFrame(
|
||||
env: JNIEnv,
|
||||
class: JClass,
|
||||
) -> i32 {
|
||||
DEMO_APP.with(|demo_app| {
|
||||
let mut event_queue = EVENT_QUEUE.lock().unwrap();
|
||||
match *demo_app.borrow_mut() {
|
||||
|
@ -81,10 +85,10 @@ pub unsafe extern "system" fn
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_drawScene(
|
||||
env: JNIEnv,
|
||||
class: JClass) {
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_drawScene(
|
||||
env: JNIEnv,
|
||||
class: JClass,
|
||||
) {
|
||||
DEMO_APP.with(|demo_app| {
|
||||
if let Some(ref mut demo_app) = *demo_app.borrow_mut() {
|
||||
demo_app.draw_scene()
|
||||
|
@ -93,10 +97,10 @@ pub unsafe extern "system" fn
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_finishDrawingFrame(
|
||||
env: JNIEnv,
|
||||
class: JClass) {
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_finishDrawingFrame(
|
||||
env: JNIEnv,
|
||||
class: JClass,
|
||||
) {
|
||||
DEMO_APP.with(|demo_app| {
|
||||
if let Some(ref mut demo_app) = *demo_app.borrow_mut() {
|
||||
demo_app.finish_drawing_frame()
|
||||
|
@ -105,67 +109,82 @@ pub unsafe extern "system" fn
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushWindowResizedEvent(
|
||||
env: JNIEnv,
|
||||
class: JClass,
|
||||
width: i32,
|
||||
height: i32) {
|
||||
EVENT_QUEUE.lock().unwrap().push(Event::WindowResized(WindowSize {
|
||||
logical_size: Point2DI32::new(width, height),
|
||||
backing_scale_factor: 1.0,
|
||||
}))
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushWindowResizedEvent(
|
||||
env: JNIEnv,
|
||||
class: JClass,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) {
|
||||
EVENT_QUEUE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push(Event::WindowResized(WindowSize {
|
||||
logical_size: Point2DI32::new(width, height),
|
||||
backing_scale_factor: 1.0,
|
||||
}))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDownEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
x: i32,
|
||||
y: i32) {
|
||||
EVENT_QUEUE.lock().unwrap().push(Event::MouseDown(Point2DI32::new(x, y)))
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDownEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
x: i32,
|
||||
y: i32,
|
||||
) {
|
||||
EVENT_QUEUE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push(Event::MouseDown(Point2DI32::new(x, y)))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDraggedEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
x: i32,
|
||||
y: i32) {
|
||||
EVENT_QUEUE.lock().unwrap().push(Event::MouseDragged(Point2DI32::new(x, y)))
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushMouseDraggedEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
x: i32,
|
||||
y: i32,
|
||||
) {
|
||||
EVENT_QUEUE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push(Event::MouseDragged(Point2DI32::new(x, y)))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushZoomEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
factor: f32,
|
||||
center_x: i32,
|
||||
center_y: i32) {
|
||||
EVENT_QUEUE.lock().unwrap().push(Event::Zoom(factor, Point2DI32::new(center_x, center_y)))
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushZoomEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
factor: f32,
|
||||
center_x: i32,
|
||||
center_y: i32,
|
||||
) {
|
||||
EVENT_QUEUE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push(Event::Zoom(factor, Point2DI32::new(center_x, center_y)))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushLookEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
pitch: f32,
|
||||
yaw: f32) {
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushLookEvent(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
pitch: f32,
|
||||
yaw: f32,
|
||||
) {
|
||||
EVENT_QUEUE.lock().unwrap().push(Event::Look { pitch, yaw })
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn
|
||||
Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushOpenSVGEvent(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
string: JObject) {
|
||||
pub unsafe extern "system" fn Java_graphics_pathfinder_pathfinderdemo_PathfinderDemoRenderer_pushOpenSVGEvent(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
string: JObject,
|
||||
) {
|
||||
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 {
|
||||
|
@ -202,18 +221,20 @@ impl Window for WindowImpl {
|
|||
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) {
|
||||
JAVA_ACTIVITY.with(|java_activity| {
|
||||
let mut java_activity = java_activity.borrow_mut();
|
||||
let java_activity = java_activity.as_mut().unwrap();
|
||||
let env = java_activity.vm.get_env().unwrap();
|
||||
env.call_method(java_activity.activity.as_obj(),
|
||||
"presentOpenSVGDialog",
|
||||
"()V",
|
||||
&[]).unwrap();
|
||||
env.call_method(
|
||||
java_activity.activity.as_obj(),
|
||||
"presentOpenSVGDialog",
|
||||
"()V",
|
||||
&[],
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -232,13 +253,20 @@ impl ResourceLoader for AndroidResourceLoader {
|
|||
let java_resource_loader = java_resource_loader.as_ref().unwrap();
|
||||
let loader = java_resource_loader.loader.as_obj();
|
||||
let env = java_resource_loader.vm.get_env().unwrap();
|
||||
match env.call_method(loader,
|
||||
"slurp",
|
||||
"(Ljava/lang/String;)Ljava/nio/ByteBuffer;",
|
||||
&[JValue::Object(*env.new_string(path).unwrap())]).unwrap() {
|
||||
match env
|
||||
.call_method(
|
||||
loader,
|
||||
"slurp",
|
||||
"(Ljava/lang/String;)Ljava/nio/ByteBuffer;",
|
||||
&[JValue::Object(*env.new_string(path).unwrap())],
|
||||
)
|
||||
.unwrap()
|
||||
{
|
||||
JValue::Object(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!"),
|
||||
}
|
||||
|
|
|
@ -14,30 +14,47 @@ use crate::GRIDLINE_COUNT;
|
|||
use pathfinder_gpu::resources::ResourceLoader;
|
||||
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 transform_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> {
|
||||
let program = device.create_program(resources, "demo_ground");
|
||||
let transform_uniform = device.get_uniform(&program, "Transform");
|
||||
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,
|
||||
}
|
||||
|
||||
impl<D> GroundSolidVertexArray<D> where D: Device {
|
||||
pub fn new(device: &D,
|
||||
ground_program: &GroundProgram<D>,
|
||||
quad_vertex_positions_buffer: &D::Buffer)
|
||||
-> GroundSolidVertexArray<D> {
|
||||
impl<D> GroundSolidVertexArray<D>
|
||||
where
|
||||
D: Device,
|
||||
{
|
||||
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 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,
|
||||
#[allow(dead_code)]
|
||||
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> {
|
||||
let grid_vertex_positions_buffer = device.create_buffer();
|
||||
device.allocate_buffer(&grid_vertex_positions_buffer,
|
||||
BufferData::Memory(&create_grid_vertex_positions()),
|
||||
BufferTarget::Vertex,
|
||||
BufferUploadMode::Static);
|
||||
device.allocate_buffer(
|
||||
&grid_vertex_positions_buffer,
|
||||
BufferData::Memory(&create_grid_vertex_positions()),
|
||||
BufferTarget::Vertex,
|
||||
BufferUploadMode::Static,
|
||||
);
|
||||
|
||||
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.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![];
|
||||
for index in 0..(GRIDLINE_COUNT + 1) {
|
||||
positions.extend_from_slice(&[
|
||||
(0, index), (GRIDLINE_COUNT, index),
|
||||
(index, 0), (index, GRIDLINE_COUNT),
|
||||
(0, index),
|
||||
(GRIDLINE_COUNT, index),
|
||||
(index, 0),
|
||||
(index, GRIDLINE_COUNT),
|
||||
]);
|
||||
}
|
||||
positions
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,12 +8,12 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use crate::{BackgroundColor, Mode, Options};
|
||||
use crate::window::Window;
|
||||
use crate::{BackgroundColor, Mode, Options};
|
||||
use pathfinder_geometry::basic::point::Point2DI32;
|
||||
use pathfinder_geometry::basic::rect::RectI32;
|
||||
use pathfinder_gpu::Device;
|
||||
use pathfinder_gpu::resources::ResourceLoader;
|
||||
use pathfinder_gpu::Device;
|
||||
use pathfinder_renderer::gpu::debug::DebugUI;
|
||||
use pathfinder_ui::{BUTTON_HEIGHT, BUTTON_TEXT_OFFSET, BUTTON_WIDTH, FONT_ASCENT, PADDING};
|
||||
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_HEIGHT: i32 = PADDING * 2 + SLIDER_HEIGHT;
|
||||
|
||||
static EFFECTS_PNG_NAME: &'static str = "demo-effects";
|
||||
static OPEN_PNG_NAME: &'static str = "demo-open";
|
||||
static ROTATE_PNG_NAME: &'static str = "demo-rotate";
|
||||
static ZOOM_IN_PNG_NAME: &'static str = "demo-zoom-in";
|
||||
static ZOOM_OUT_PNG_NAME: &'static str = "demo-zoom-out";
|
||||
static EFFECTS_PNG_NAME: &'static str = "demo-effects";
|
||||
static OPEN_PNG_NAME: &'static str = "demo-open";
|
||||
static ROTATE_PNG_NAME: &'static str = "demo-rotate";
|
||||
static ZOOM_IN_PNG_NAME: &'static str = "demo-zoom-in";
|
||||
static ZOOM_OUT_PNG_NAME: &'static str = "demo-zoom-out";
|
||||
static BACKGROUND_PNG_NAME: &'static str = "demo-background";
|
||||
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,
|
||||
open_texture: D::Texture,
|
||||
rotate_texture: D::Texture,
|
||||
|
@ -57,7 +60,6 @@ pub struct DemoUI<D> where D: Device {
|
|||
rotate_panel_visible: bool,
|
||||
|
||||
// FIXME(pcwalton): Factor the below out into a model class.
|
||||
|
||||
pub mode: Mode,
|
||||
pub background_color: BackgroundColor,
|
||||
pub gamma_correction_effect_enabled: bool,
|
||||
|
@ -68,7 +70,10 @@ pub struct DemoUI<D> where D: Device {
|
|||
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> {
|
||||
let effects_texture = device.create_texture_from_png(resources, EFFECTS_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
|
||||
}
|
||||
|
||||
pub fn update<W>(&mut self,
|
||||
device: &D,
|
||||
window: &mut W,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
action: &mut UIAction)
|
||||
where W: Window {
|
||||
pub fn update<W>(
|
||||
&mut self,
|
||||
device: &D,
|
||||
window: &mut W,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
action: &mut UIAction,
|
||||
) where
|
||||
W: Window,
|
||||
{
|
||||
// Draw message text.
|
||||
|
||||
self.draw_message_text(device, debug_ui);
|
||||
|
@ -125,42 +133,59 @@ impl<D> DemoUI<D> where D: Device {
|
|||
|
||||
// Draw text effects button.
|
||||
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;
|
||||
}
|
||||
if !self.effects_panel_visible {
|
||||
debug_ui.ui.draw_tooltip(device,
|
||||
"Text Effects",
|
||||
RectI32::new(position, button_size));
|
||||
debug_ui.ui.draw_tooltip(
|
||||
device,
|
||||
"Text Effects",
|
||||
RectI32::new(position, button_size),
|
||||
);
|
||||
}
|
||||
position += Point2DI32::new(button_size.x() + PADDING, 0);
|
||||
}
|
||||
|
||||
// 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
|
||||
// the contents of the file.
|
||||
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);
|
||||
|
||||
// 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
|
||||
// the contents of the file.
|
||||
if let Ok(file) = window.run_save_dialog("png") {
|
||||
*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);
|
||||
|
||||
// Draw mode switch.
|
||||
let new_mode = debug_ui.ui.draw_text_switch(device,
|
||||
position,
|
||||
&["2D", "3D", "VR"],
|
||||
self.mode as u8);
|
||||
let new_mode =
|
||||
debug_ui
|
||||
.ui
|
||||
.draw_text_switch(device, position, &["2D", "3D", "VR"], self.mode as u8);
|
||||
if new_mode != self.mode as u8 {
|
||||
self.mode = match new_mode {
|
||||
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_size = Point2DI32::new(mode_switch_width, BUTTON_HEIGHT);
|
||||
debug_ui.ui.draw_tooltip(device,
|
||||
"2D/3D/VR Mode",
|
||||
RectI32::new(position, mode_switch_size));
|
||||
debug_ui.ui.draw_tooltip(
|
||||
device,
|
||||
"2D/3D/VR Mode",
|
||||
RectI32::new(position, mode_switch_size),
|
||||
);
|
||||
position += Point2DI32::new(mode_switch_width + PADDING, 0);
|
||||
|
||||
// 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;
|
||||
}
|
||||
if !self.background_panel_visible {
|
||||
debug_ui.ui.draw_tooltip(device,
|
||||
"Background Color",
|
||||
RectI32::new(position, button_size));
|
||||
debug_ui.ui.draw_tooltip(
|
||||
device,
|
||||
"Background Color",
|
||||
RectI32::new(position, button_size),
|
||||
);
|
||||
}
|
||||
|
||||
// Draw background panel, if necessary.
|
||||
|
@ -199,25 +231,40 @@ impl<D> DemoUI<D> where D: Device {
|
|||
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;
|
||||
}
|
||||
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);
|
||||
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;
|
||||
}
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -229,13 +276,17 @@ impl<D> DemoUI<D> where D: Device {
|
|||
let message_size = debug_ui.ui.measure_text(&self.message);
|
||||
let window_origin = Point2DI32::new(PADDING, PADDING);
|
||||
let window_size = Point2DI32::new(PADDING * 2 + message_size, TOOLTIP_HEIGHT);
|
||||
debug_ui.ui.draw_solid_rounded_rect(device,
|
||||
RectI32::new(window_origin, window_size),
|
||||
WINDOW_COLOR);
|
||||
debug_ui.ui.draw_text(device,
|
||||
&self.message,
|
||||
window_origin + Point2DI32::new(PADDING, PADDING + FONT_ASCENT),
|
||||
false);
|
||||
debug_ui.ui.draw_solid_rounded_rect(
|
||||
device,
|
||||
RectI32::new(window_origin, window_size),
|
||||
WINDOW_COLOR,
|
||||
);
|
||||
debug_ui.ui.draw_text(
|
||||
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>) {
|
||||
|
@ -245,40 +296,48 @@ impl<D> DemoUI<D> where D: Device {
|
|||
|
||||
let bottom = debug_ui.ui.framebuffer_size().y() - PADDING;
|
||||
let effects_panel_y = bottom - (BUTTON_HEIGHT + PADDING + EFFECTS_PANEL_HEIGHT);
|
||||
debug_ui.ui.draw_solid_rounded_rect(device,
|
||||
RectI32::new(Point2DI32::new(PADDING, effects_panel_y),
|
||||
Point2DI32::new(EFFECTS_PANEL_WIDTH,
|
||||
EFFECTS_PANEL_HEIGHT)),
|
||||
WINDOW_COLOR);
|
||||
debug_ui.ui.draw_solid_rounded_rect(
|
||||
device,
|
||||
RectI32::new(
|
||||
Point2DI32::new(PADDING, effects_panel_y),
|
||||
Point2DI32::new(EFFECTS_PANEL_WIDTH, EFFECTS_PANEL_HEIGHT),
|
||||
),
|
||||
WINDOW_COLOR,
|
||||
);
|
||||
|
||||
self.gamma_correction_effect_enabled =
|
||||
self.draw_effects_switch(device,
|
||||
debug_ui,
|
||||
"Gamma Correction",
|
||||
0,
|
||||
effects_panel_y,
|
||||
self.gamma_correction_effect_enabled);
|
||||
self.stem_darkening_effect_enabled =
|
||||
self.draw_effects_switch(device,
|
||||
debug_ui,
|
||||
"Stem Darkening",
|
||||
1,
|
||||
effects_panel_y,
|
||||
self.stem_darkening_effect_enabled);
|
||||
self.subpixel_aa_effect_enabled =
|
||||
self.draw_effects_switch(device,
|
||||
debug_ui,
|
||||
"Subpixel AA",
|
||||
2,
|
||||
effects_panel_y,
|
||||
self.subpixel_aa_effect_enabled);
|
||||
self.gamma_correction_effect_enabled = self.draw_effects_switch(
|
||||
device,
|
||||
debug_ui,
|
||||
"Gamma Correction",
|
||||
0,
|
||||
effects_panel_y,
|
||||
self.gamma_correction_effect_enabled,
|
||||
);
|
||||
self.stem_darkening_effect_enabled = self.draw_effects_switch(
|
||||
device,
|
||||
debug_ui,
|
||||
"Stem Darkening",
|
||||
1,
|
||||
effects_panel_y,
|
||||
self.stem_darkening_effect_enabled,
|
||||
);
|
||||
self.subpixel_aa_effect_enabled = self.draw_effects_switch(
|
||||
device,
|
||||
debug_ui,
|
||||
"Subpixel AA",
|
||||
2,
|
||||
effects_panel_y,
|
||||
self.subpixel_aa_effect_enabled,
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_background_panel(&mut self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
panel_x: i32,
|
||||
action: &mut UIAction) {
|
||||
fn draw_background_panel(
|
||||
&mut self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
panel_x: i32,
|
||||
action: &mut UIAction,
|
||||
) {
|
||||
if !self.background_panel_visible {
|
||||
return;
|
||||
}
|
||||
|
@ -286,34 +345,45 @@ impl<D> DemoUI<D> where D: Device {
|
|||
let bottom = debug_ui.ui.framebuffer_size().y() - PADDING;
|
||||
let panel_y = bottom - (BUTTON_HEIGHT + PADDING + BACKGROUND_PANEL_HEIGHT);
|
||||
let panel_position = Point2DI32::new(panel_x, panel_y);
|
||||
debug_ui.ui.draw_solid_rounded_rect(device,
|
||||
RectI32::new(panel_position,
|
||||
Point2DI32::new(BACKGROUND_PANEL_WIDTH,
|
||||
BACKGROUND_PANEL_HEIGHT)),
|
||||
WINDOW_COLOR);
|
||||
debug_ui.ui.draw_solid_rounded_rect(
|
||||
device,
|
||||
RectI32::new(
|
||||
panel_position,
|
||||
Point2DI32::new(BACKGROUND_PANEL_WIDTH, BACKGROUND_PANEL_HEIGHT),
|
||||
),
|
||||
WINDOW_COLOR,
|
||||
);
|
||||
|
||||
self.draw_background_menu_item(device,
|
||||
debug_ui,
|
||||
BackgroundColor::Light,
|
||||
panel_position,
|
||||
action);
|
||||
self.draw_background_menu_item(device,
|
||||
debug_ui,
|
||||
BackgroundColor::Dark,
|
||||
panel_position,
|
||||
action);
|
||||
self.draw_background_menu_item(device,
|
||||
debug_ui,
|
||||
BackgroundColor::Transparent,
|
||||
panel_position,
|
||||
action);
|
||||
self.draw_background_menu_item(
|
||||
device,
|
||||
debug_ui,
|
||||
BackgroundColor::Light,
|
||||
panel_position,
|
||||
action,
|
||||
);
|
||||
self.draw_background_menu_item(
|
||||
device,
|
||||
debug_ui,
|
||||
BackgroundColor::Dark,
|
||||
panel_position,
|
||||
action,
|
||||
);
|
||||
self.draw_background_menu_item(
|
||||
device,
|
||||
debug_ui,
|
||||
BackgroundColor::Transparent,
|
||||
panel_position,
|
||||
action,
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_rotate_panel(&mut self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
rotate_panel_x: i32,
|
||||
action: &mut UIAction) {
|
||||
fn draw_rotate_panel(
|
||||
&mut self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
rotate_panel_x: i32,
|
||||
action: &mut UIAction,
|
||||
) {
|
||||
if !self.rotate_panel_visible {
|
||||
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_origin = Point2DI32::new(rotate_panel_x, rotate_panel_y);
|
||||
let rotate_panel_size = Point2DI32::new(ROTATE_PANEL_WIDTH, ROTATE_PANEL_HEIGHT);
|
||||
debug_ui.ui.draw_solid_rounded_rect(device,
|
||||
RectI32::new(rotate_panel_origin, rotate_panel_size),
|
||||
WINDOW_COLOR);
|
||||
debug_ui.ui.draw_solid_rounded_rect(
|
||||
device,
|
||||
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_rect = RectI32::new(Point2DI32::new(widget_x, widget_y),
|
||||
Point2DI32::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT));
|
||||
if let Some(position) = debug_ui.ui
|
||||
.event_queue
|
||||
.handle_mouse_down_or_dragged_in_rect(widget_rect) {
|
||||
let widget_rect = RectI32::new(
|
||||
Point2DI32::new(widget_x, widget_y),
|
||||
Point2DI32::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT),
|
||||
);
|
||||
if let Some(position) = debug_ui
|
||||
.ui
|
||||
.event_queue
|
||||
.handle_mouse_down_or_dragged_in_rect(widget_rect)
|
||||
{
|
||||
self.rotation = position.x();
|
||||
*action = UIAction::Rotate(self.rotation());
|
||||
}
|
||||
|
||||
let slider_track_y = rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 -
|
||||
SLIDER_TRACK_HEIGHT / 2;
|
||||
let slider_track_rect =
|
||||
RectI32::new(Point2DI32::new(widget_x, slider_track_y),
|
||||
Point2DI32::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT));
|
||||
debug_ui.ui.draw_rect_outline(device, slider_track_rect, TEXT_COLOR);
|
||||
let slider_track_y =
|
||||
rotate_panel_y + PADDING + SLIDER_KNOB_HEIGHT / 2 - SLIDER_TRACK_HEIGHT / 2;
|
||||
let slider_track_rect = RectI32::new(
|
||||
Point2DI32::new(widget_x, slider_track_y),
|
||||
Point2DI32::new(SLIDER_WIDTH, SLIDER_TRACK_HEIGHT),
|
||||
);
|
||||
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_rect =
|
||||
RectI32::new(Point2DI32::new(slider_knob_x, widget_y),
|
||||
Point2DI32::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT));
|
||||
debug_ui.ui.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR);
|
||||
let slider_knob_rect = RectI32::new(
|
||||
Point2DI32::new(slider_knob_x, widget_y),
|
||||
Point2DI32::new(SLIDER_KNOB_WIDTH, SLIDER_KNOB_HEIGHT),
|
||||
);
|
||||
debug_ui
|
||||
.ui
|
||||
.draw_solid_rect(device, slider_knob_rect, TEXT_COLOR);
|
||||
}
|
||||
|
||||
fn draw_background_menu_item(&mut self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
color: BackgroundColor,
|
||||
panel_position: Point2DI32,
|
||||
action: &mut UIAction) {
|
||||
fn draw_background_menu_item(
|
||||
&mut self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
color: BackgroundColor,
|
||||
panel_position: Point2DI32,
|
||||
action: &mut UIAction,
|
||||
) {
|
||||
let (text, index) = (color.as_str(), color as i32);
|
||||
|
||||
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);
|
||||
|
||||
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_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;
|
||||
*action = UIAction::ModelChanged;
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_effects_switch(&self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
text: &str,
|
||||
index: i32,
|
||||
window_y: i32,
|
||||
value: bool)
|
||||
-> bool {
|
||||
fn draw_effects_switch(
|
||||
&self,
|
||||
device: &D,
|
||||
debug_ui: &mut DebugUI<D>,
|
||||
text: &str,
|
||||
index: i32,
|
||||
window_y: i32,
|
||||
value: bool,
|
||||
) -> bool {
|
||||
let text_x = PADDING * 2;
|
||||
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_x = PADDING + EFFECTS_PANEL_WIDTH - (switch_width + PADDING);
|
||||
let switch_y = window_y + PADDING + (BUTTON_HEIGHT + PADDING) * index;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ use std::path::PathBuf;
|
|||
|
||||
pub trait Window {
|
||||
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 make_current(&mut self, view: View);
|
||||
fn present(&mut self);
|
||||
|
@ -31,7 +33,10 @@ pub trait Window {
|
|||
fn present_open_svg_dialog(&mut self);
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -45,10 +50,16 @@ pub enum Event {
|
|||
MouseMoved(Point2DI32),
|
||||
MouseDragged(Point2DI32),
|
||||
Zoom(f32, Point2DI32),
|
||||
Look { pitch: f32, yaw: f32 },
|
||||
Look {
|
||||
pitch: f32,
|
||||
yaw: f32,
|
||||
},
|
||||
SetEyeTransforms(Vec<OcularTransform>),
|
||||
OpenSVG(SVGPath),
|
||||
User { message_type: u32, message_data: u32 },
|
||||
User {
|
||||
message_type: u32,
|
||||
message_data: u32,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
@ -67,7 +78,10 @@ pub struct WindowSize {
|
|||
impl WindowSize {
|
||||
#[inline]
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,17 +12,17 @@
|
|||
|
||||
use jemallocator;
|
||||
use nfd::Response;
|
||||
use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize};
|
||||
use pathfinder_demo::DemoApp;
|
||||
use pathfinder_demo::Options;
|
||||
use pathfinder_demo::window::{Event, Keycode, SVGPath, View, Window, WindowSize};
|
||||
use pathfinder_geometry::basic::point::Point2DI32;
|
||||
use pathfinder_geometry::basic::rect::RectI32;
|
||||
use pathfinder_gl::GLVersion;
|
||||
use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader};
|
||||
use sdl2::{EventPump, EventSubsystem, Sdl, VideoSubsystem};
|
||||
use sdl2::event::{Event as SDLEvent, WindowEvent};
|
||||
use sdl2::keyboard::Keycode as SDLKeycode;
|
||||
use sdl2::video::{GLContext, GLProfile, Window as SDLWindow};
|
||||
use sdl2::{EventPump, EventSubsystem, Sdl, VideoSubsystem};
|
||||
use sdl2_sys::{SDL_Event, SDL_UserEvent};
|
||||
use std::path::PathBuf;
|
||||
use std::ptr;
|
||||
|
@ -150,14 +150,17 @@ impl WindowImpl {
|
|||
gl_attributes.set_depth_size(24);
|
||||
gl_attributes.set_stencil_size(8);
|
||||
|
||||
window = sdl_video.window("Pathfinder Demo",
|
||||
DEFAULT_WINDOW_WIDTH,
|
||||
DEFAULT_WINDOW_HEIGHT)
|
||||
.opengl()
|
||||
.resizable()
|
||||
.allow_highdpi()
|
||||
.build()
|
||||
.unwrap();
|
||||
window = sdl_video
|
||||
.window(
|
||||
"Pathfinder Demo",
|
||||
DEFAULT_WINDOW_WIDTH,
|
||||
DEFAULT_WINDOW_HEIGHT,
|
||||
)
|
||||
.opengl()
|
||||
.resizable()
|
||||
.allow_highdpi()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
gl_context = window.gl_create_context().unwrap();
|
||||
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 open_svg_message_type = unsafe {
|
||||
sdl_event.register_event().unwrap()
|
||||
};
|
||||
let open_svg_message_type = unsafe { sdl_event.register_event().unwrap() };
|
||||
|
||||
WindowImpl {
|
||||
window,
|
||||
|
@ -211,16 +212,17 @@ impl WindowImpl {
|
|||
|
||||
fn convert_sdl_event(&self, sdl_event: SDLEvent) -> Option<Event> {
|
||||
match sdl_event {
|
||||
SDLEvent::User { type_, .. } if type_ == self.open_svg_message_type => {
|
||||
Some(Event::OpenSVG(SVGPath::Path(self.selected_file.clone().unwrap())))
|
||||
}
|
||||
SDLEvent::User { type_, code, .. } => {
|
||||
Some(Event::User { message_type: type_, message_data: code as u32 })
|
||||
}
|
||||
SDLEvent::MouseButtonDown { x, y, .. } => {
|
||||
Some(Event::MouseDown(Point2DI32::new(x, y)))
|
||||
}
|
||||
SDLEvent::MouseMotion { x, y, mousestate, .. } => {
|
||||
SDLEvent::User { type_, .. } if type_ == self.open_svg_message_type => Some(
|
||||
Event::OpenSVG(SVGPath::Path(self.selected_file.clone().unwrap())),
|
||||
),
|
||||
SDLEvent::User { type_, code, .. } => Some(Event::User {
|
||||
message_type: type_,
|
||||
message_data: code as u32,
|
||||
}),
|
||||
SDLEvent::MouseButtonDown { x, y, .. } => Some(Event::MouseDown(Point2DI32::new(x, y))),
|
||||
SDLEvent::MouseMotion {
|
||||
x, y, mousestate, ..
|
||||
} => {
|
||||
let position = Point2DI32::new(x, y);
|
||||
if mousestate.left() {
|
||||
Some(Event::MouseDragged(position))
|
||||
|
@ -229,15 +231,18 @@ impl WindowImpl {
|
|||
}
|
||||
}
|
||||
SDLEvent::Quit { .. } => Some(Event::Quit),
|
||||
SDLEvent::Window { win_event: WindowEvent::SizeChanged(..), .. } => {
|
||||
Some(Event::WindowResized(self.size()))
|
||||
}
|
||||
SDLEvent::KeyDown { keycode: Some(sdl_keycode), .. } => {
|
||||
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::Window {
|
||||
win_event: WindowEvent::SizeChanged(..),
|
||||
..
|
||||
} => Some(Event::WindowResized(self.size())),
|
||||
SDLEvent::KeyDown {
|
||||
keycode: Some(sdl_keycode),
|
||||
..
|
||||
} => 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, .. } => {
|
||||
let mouse_state = self.event_pump.mouse_state();
|
||||
let center = Point2DI32::new(mouse_state.x(), mouse_state.y());
|
||||
|
@ -251,8 +256,10 @@ impl WindowImpl {
|
|||
match sdl_keycode {
|
||||
SDLKeycode::Escape => Some(Keycode::Escape),
|
||||
SDLKeycode::Tab => Some(Keycode::Tab),
|
||||
sdl_keycode if sdl_keycode as i32 >= SDLKeycode::A as i32 &&
|
||||
sdl_keycode as i32 <= SDLKeycode::Z as i32 => {
|
||||
sdl_keycode
|
||||
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;
|
||||
Some(Keycode::Alphanumeric(offset + b'a'))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue