use std::collections::vec_deque::IntoIter as VecDequeIter;
use CreationError;
use CursorState;
use EventsLoop;
use MouseCursor;
use Window;
use WindowBuilder;
use WindowId;
use libc;
use platform;
impl WindowBuilder {
#[inline]
pub fn new() -> WindowBuilder {
WindowBuilder {
window: Default::default(),
platform_specific: Default::default(),
}
}
#[inline]
pub fn with_dimensions(mut self, width: u32, height: u32) -> WindowBuilder {
self.window.dimensions = Some((width, height));
self
}
#[inline]
pub fn with_min_dimensions(mut self, width: u32, height: u32) -> WindowBuilder {
self.window.min_dimensions = Some((width, height));
self
}
#[inline]
pub fn with_max_dimensions(mut self, width: u32, height: u32) -> WindowBuilder {
self.window.max_dimensions = Some((width, height));
self
}
#[inline]
pub fn with_title<T: Into<String>>(mut self, title: T) -> WindowBuilder {
self.window.title = title.into();
self
}
#[inline]
pub fn with_fullscreen(mut self, monitor: Option<MonitorId>) -> WindowBuilder {
self.window.fullscreen = monitor;
self
}
#[inline]
pub fn with_maximized(mut self, maximized: bool) -> WindowBuilder {
self.window.maximized = maximized;
self
}
#[inline]
pub fn with_visibility(mut self, visible: bool) -> WindowBuilder {
self.window.visible = visible;
self
}
#[inline]
pub fn with_transparency(mut self, transparent: bool) -> WindowBuilder {
self.window.transparent = transparent;
self
}
#[inline]
pub fn with_decorations(mut self, decorations: bool) -> WindowBuilder {
self.window.decorations = decorations;
self
}
#[inline]
pub fn with_multitouch(mut self) -> WindowBuilder {
self.window.multitouch = true;
self
}
pub fn build(mut self, events_loop: &EventsLoop) -> Result<Window, CreationError> {
if self.window.dimensions.is_none() {
if let Some(ref monitor) = self.window.fullscreen {
self.window.dimensions = Some(monitor.get_dimensions());
}
}
if self.window.dimensions.is_none() {
self.window.dimensions = Some((1024, 768));
}
let w = try!(platform::Window::new(&events_loop.events_loop, &self.window, &self.platform_specific));
Ok(Window { window: w })
}
}
impl Window {
#[inline]
pub fn new(events_loop: &EventsLoop) -> Result<Window, CreationError> {
let builder = WindowBuilder::new();
builder.build(events_loop)
}
#[inline]
pub fn set_title(&self, title: &str) {
self.window.set_title(title)
}
#[inline]
pub fn show(&self) {
self.window.show()
}
#[inline]
pub fn hide(&self) {
self.window.hide()
}
#[inline]
pub fn get_position(&self) -> Option<(i32, i32)> {
self.window.get_position()
}
#[inline]
pub fn set_position(&self, x: i32, y: i32) {
self.window.set_position(x, y)
}
#[inline]
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
self.window.get_inner_size()
}
#[inline]
pub fn get_inner_size_points(&self) -> Option<(u32, u32)> {
self.window.get_inner_size()
}
#[inline]
pub fn get_inner_size_pixels(&self) -> Option<(u32, u32)> {
self.window.get_inner_size().map(|(x, y)| {
let hidpi = self.hidpi_factor();
((x as f32 * hidpi) as u32, (y as f32 * hidpi) as u32)
})
}
#[inline]
pub fn get_outer_size(&self) -> Option<(u32, u32)> {
self.window.get_outer_size()
}
#[inline]
pub fn set_inner_size(&self, x: u32, y: u32) {
self.window.set_inner_size(x, y)
}
#[deprecated]
#[inline]
pub unsafe fn platform_display(&self) -> *mut libc::c_void {
self.window.platform_display()
}
#[deprecated]
#[inline]
pub unsafe fn platform_window(&self) -> *mut libc::c_void {
self.window.platform_window()
}
pub fn set_cursor(&self, cursor: MouseCursor) {
self.window.set_cursor(cursor);
}
#[inline]
pub fn hidpi_factor(&self) -> f32 {
self.window.hidpi_factor()
}
#[inline]
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
self.window.set_cursor_position(x, y)
}
#[inline]
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
self.window.set_cursor_state(state)
}
#[inline]
pub fn set_maximized(&self, maximized: bool) {
self.window.set_maximized(maximized)
}
#[inline]
pub fn set_fullscreen(&self, monitor: Option<MonitorId>) {
self.window.set_fullscreen(monitor)
}
pub fn get_current_monitor(&self) -> MonitorId {
self.window.get_current_monitor()
}
#[inline]
pub fn id(&self) -> WindowId {
WindowId(self.window.id())
}
}
pub struct AvailableMonitorsIter {
pub(crate) data: VecDequeIter<platform::MonitorId>,
}
impl Iterator for AvailableMonitorsIter {
type Item = MonitorId;
#[inline]
fn next(&mut self) -> Option<MonitorId> {
self.data.next().map(|id| MonitorId { inner: id })
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.data.size_hint()
}
}
#[derive(Clone)]
pub struct MonitorId {
pub(crate) inner: platform::MonitorId
}
impl MonitorId {
#[inline]
pub fn get_name(&self) -> Option<String> {
self.inner.get_name()
}
#[inline]
pub fn get_dimensions(&self) -> (u32, u32) {
self.inner.get_dimensions()
}
#[inline]
pub fn get_position(&self) -> (u32, u32) {
self.inner.get_position()
}
}