Commit b2bbae8c authored by Jeremy Soller's avatar Jeremy Soller

Update SDL2

parent e16319b3
[package]
name = "orbclient"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
description = "The Orbital Client Library"
repository = "https://github.com/redox-os/orbclient"
version = "0.3.8"
keywords = [
"orbital",
"redox",
"ui",
]
license-file = "LICENSE"
readme = "README.md"
keywords = ["orbital", "redox", "ui"]
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
[lib]
name = "orbclient"
path = "src/lib.rs"
readme = "README.md"
repository = "https://github.com/redox-os/orbclient"
version = "0.3.9"
[features]
default = []
no_std = []
[target.'cfg(all(not(feature="no_std"), target_os = "redox"))'.dependencies]
redox_syscall = "0.1"
[target.'cfg(all(not(feature="no_std"), not(target_os = "redox")))'.dependencies]
sdl2 = "0.29"
[lib]
name = "orbclient"
path = "src/lib.rs"
[target.'cfg(all(not(feature="no_std"), not(target_os="redox")))'.dependencies]
sdl2 = "0.30.0"
[target.'cfg(all(not(feature="no_std"), target_os="redox"))'.dependencies]
redox_syscall = "0.1.31"
......@@ -16,7 +16,7 @@ pub static FONT: &'static [u8] = include_bytes!("../res/unifont.font");
pub use color::Color;
pub use event::*;
#[cfg(not(feature="no_std"))]
pub use imp::{get_display_size, EventIter, Window};
pub use sys::{get_display_size, EventIter, Window};
pub use graphicspath::GraphicsPath;
pub use renderer::Renderer;
......@@ -35,9 +35,9 @@ pub enum WindowFlag {
}
#[cfg(all(not(feature="no_std"), target_os = "redox"))]
#[path="imp/orbital.rs"]
mod imp;
#[path="sys/orbital.rs"]
mod sys;
#[cfg(all(not(feature="no_std"), not(target_os = "redox")))]
#[path="imp/sdl2.rs"]
mod imp;
#[path="sys/sdl2.rs"]
mod sys;
......@@ -49,7 +49,7 @@ pub struct Window {
/// True if the window should not wait for events
async: bool,
/// The inner renderer
inner: sdl2::render::Renderer<'static>,
inner: sdl2::render::WindowCanvas,
}
impl Renderer for Window {
......@@ -65,7 +65,7 @@ impl Renderer for Window {
/// Access pixel buffer
fn data(&self) -> &[Color] {
let window = self.inner.window().unwrap();
let window = self.inner.window();
let surface = window.surface(unsafe { & *EVENT_PUMP }).unwrap();
let bytes = surface.without_lock().unwrap();
unsafe { slice::from_raw_parts(bytes.as_ptr() as *const Color, bytes.len()/mem::size_of::<Color>()) }
......@@ -73,8 +73,8 @@ impl Renderer for Window {
/// Access pixel buffer mutably
fn data_mut(&mut self) -> &mut [Color] {
let window = self.inner.window_mut().unwrap();
let surface = window.surface_mut(unsafe { & *EVENT_PUMP }).unwrap();
let window = self.inner.window_mut();
let mut surface = window.surface(unsafe { & *EVENT_PUMP }).unwrap();
let bytes = surface.without_lock_mut().unwrap();
unsafe { slice::from_raw_parts_mut(bytes.as_mut_ptr() as *mut Color, bytes.len()/mem::size_of::<Color>()) }
}
......@@ -133,23 +133,22 @@ impl Window {
h: h,
t: title.to_string(),
async: async,
inner: window.renderer().software().build().unwrap(),
inner: window.into_canvas().software().build().unwrap(),
}),
Err(_) => None
}
}
pub fn sync_path(&mut self) {
if let Some(window) = self.inner.window() {
let pos = window.position();
let size = window.size();
let title = window.title();
self.x = pos.0;
self.y = pos.1;
self.w = size.0;
self.h = size.1;
self.t = title.to_string();
}
let window = self.inner.window();
let pos = window.position();
let size = window.size();
let title = window.title();
self.x = pos.0;
self.y = pos.1;
self.w = size.0;
self.h = size.1;
self.t = title.to_string();
}
/// Get x
......@@ -171,26 +170,22 @@ impl Window {
// Set position
pub fn set_pos(&mut self, x: i32, y: i32) {
if let Some(mut window) = self.inner.window_mut() {
let _ = window.set_position(sdl2::video::WindowPos::Positioned(x),
sdl2::video::WindowPos::Positioned(y));
}
self.inner.window_mut().set_position(
sdl2::video::WindowPos::Positioned(x),
sdl2::video::WindowPos::Positioned(y)
);
self.sync_path();
}
// Set size
pub fn set_size(&mut self, width: u32, height: u32) {
if let Some(mut window) = self.inner.window_mut() {
let _ = window.set_size(width, height);
}
let _ = self.inner.window_mut().set_size(width, height);
self.sync_path();
}
/// Set title
pub fn set_title(&mut self, title: &str) {
if let Some(mut window) = self.inner.window_mut() {
let _ = window.set_title(title);
}
let _ = self.inner.window_mut().set_title(title);
self.sync_path();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment