From 96b9be6c335f526162664e2072ff81d80970acd8 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 11 Jun 2013 12:23:27 -0700 Subject: [PATCH] Add a cheesy progress indicator --- src/components/main/compositing/mod.rs | 8 +---- .../main/platform/common/glut_windowing.rs | 31 +++++++++++++++++-- src/components/main/windowing.rs | 5 +-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/components/main/compositing/mod.rs b/src/components/main/compositing/mod.rs index 2eafb59eeb9..33e02afbae0 100644 --- a/src/components/main/compositing/mod.rs +++ b/src/components/main/compositing/mod.rs @@ -150,13 +150,7 @@ fn run_main_loop(port: Port, match port.recv() { Exit => *done = true, - ChangeReadyState(ready_state) => { - let window_title = match ready_state { - compositor_interface::FinishedLoading => ~"Servo", - _ => fmt!("%? — Servo", ready_state), - }; - window.set_title(window_title); - } + ChangeReadyState(ready_state) => window.set_ready_state(ready_state), Paint(new_layer_buffer_set, new_size) => { debug!("osmain: received new frame"); diff --git a/src/components/main/platform/common/glut_windowing.rs b/src/components/main/platform/common/glut_windowing.rs index 847c4346c31..275e20bdf42 100644 --- a/src/components/main/platform/common/glut_windowing.rs +++ b/src/components/main/platform/common/glut_windowing.rs @@ -19,6 +19,9 @@ use geom::size::Size2D; use glut::glut::{ACTIVE_CTRL, DOUBLE, HAVE_PRECISE_MOUSE_WHEEL, WindowHeight, WindowWidth}; use glut::glut; use glut::machack; +use script::compositor_interface::{FinishedLoading, Loading, Rendering, ReadyState}; + +static THROBBER: [char, ..8] = [ '⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷' ]; /// A structure responsible for setting up and tearing down the entire windowing system. pub struct Application; @@ -46,6 +49,9 @@ pub struct Window { mouse_down_button: @mut c_int, mouse_down_point: @mut Point2D, + + ready_state: ReadyState, + throbber_frame: u8, } impl WindowMethods for Window { @@ -70,6 +76,9 @@ impl WindowMethods for Window { mouse_down_button: @mut 0, mouse_down_point: @mut Point2D(0, 0), + + ready_state: FinishedLoading, + throbber_frame: 0, }; // Spin the event loop every 50 ms to allow the Rust channels to be polled. @@ -80,6 +89,8 @@ impl WindowMethods for Window { let register_timer_callback: @mut @fn() = @mut ||{}; *register_timer_callback = || { glut::timer_func(50, *register_timer_callback); + window.throbber_frame = (window.throbber_frame + 1) % (THROBBER.len() as u8); + window.update_window_title() }; // Register event handlers. @@ -174,12 +185,28 @@ impl WindowMethods for Window { glut::post_redisplay() } - pub fn set_title(@mut self, title: &str) { - glut::set_window_title(self.glut_window, title); + /// Sets the ready state. + pub fn set_ready_state(@mut self, ready_state: ReadyState) { + self.ready_state = ready_state; + self.update_window_title() } } impl Window { + /// Helper function to set the window title in accordance with the ready state. + fn update_window_title(&self) { + let throbber = THROBBER[self.throbber_frame]; + match self.ready_state { + Loading => { + glut::set_window_title(self.glut_window, fmt!("%c Loading — Servo", throbber)) + } + Rendering => { + glut::set_window_title(self.glut_window, fmt!("%c Rendering — Servo", throbber)) + } + FinishedLoading => glut::set_window_title(self.glut_window, "Servo"), + } + } + /// Helper function to handle keyboard events. fn handle_key(&self, key: u8) { debug!("got key: %d", key as int); diff --git a/src/components/main/windowing.rs b/src/components/main/windowing.rs index 829d1f26c40..8cced181ed3 100644 --- a/src/components/main/windowing.rs +++ b/src/components/main/windowing.rs @@ -6,6 +6,7 @@ use geom::point::Point2D; use geom::size::Size2D; +use script::compositor_interface::ReadyState; pub enum WindowMouseEvent { WindowClickEvent(uint, Point2D), @@ -61,7 +62,7 @@ pub trait WindowMethods { pub fn check_loop(@mut self); /// Schedules a redisplay at the next turn of the event loop. pub fn set_needs_display(@mut self); - /// Sets the title of the window - pub fn set_title(@mut self, title: &str); + /// Sets the ready state of the current page. + pub fn set_ready_state(@mut self, ready_state: ReadyState); }