Commit 88b8c2cc authored by Jeremy Soller's avatar Jeremy Soller

Set position, size, and title using window messages

parent 899113bd
......@@ -17,8 +17,8 @@ pub use graphicspath::GraphicsPath;
pub mod color;
pub mod event;
pub mod renderer;
pub mod graphicspath;
pub mod renderer;
#[cfg(target_os = "redox")]
#[path="orbital/mod.rs"]
......
......@@ -123,9 +123,29 @@ impl Window {
self.t.clone()
}
// Set position
pub fn set_pos(&mut self, x: i32, y: i32) {
let _ = self.file.write(&format!("P,{},{}", x, y).as_bytes());
self.sync_path();
}
// Set size
pub fn set_size(&mut self, width: u32, height: u32) {
//TODO: Improve safety and reliability
unsafe {
syscall::funmap(self.data.as_ptr() as usize).expect("orbclient: failed to unmap memory in resize");
}
let _ = self.file.write(&format!("S,{},{}", width, height).as_bytes());
self.sync_path();
unsafe {
let address = syscall::fmap(self.file.as_raw_fd(), 0, (self.w * self.h * 4) as usize).expect("orbclient: failed to map memory in resize");
self.data = slice::from_raw_parts_mut(address as *mut Color, (self.w * self.h) as usize);
}
}
/// Set title
pub fn set_title(&mut self, title: &str) {
let _ = self.file.write(title.as_bytes());
let _ = self.file.write(&format!("T,{}", title).as_bytes());
self.sync_path();
}
......
......@@ -97,11 +97,14 @@ impl Window {
pub fn sync_path(&mut self) {
if let Some(window) = self.inner.window() {
self.x = window.position().0;
self.y = window.position().1;
self.w = window.size().0;
self.h = window.size().1;
self.t = window.title().to_string();
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();
}
}
......@@ -122,6 +125,23 @@ impl Window {
self.t.clone()
}
// 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.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);
}
self.sync_path();
}
/// Set title
pub fn set_title(&mut self, title: &str) {
if let Some(mut window) = self.inner.window_mut() {
......
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