Create a slideshow application in my cyberpunk style #252
|
@ -6,6 +6,7 @@ use std::{
|
|||
ops::Index,
|
||||
path::Path,
|
||||
rc::Rc,
|
||||
sync::{Arc, RwLock},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
|
@ -99,7 +100,7 @@ impl Animation for Fade {
|
|||
let frames = (now - self.start_time).as_secs_f64() * FPS as f64;
|
||||
let alpha = alpha_rate * frames as f64;
|
||||
|
||||
let text_display = Text::new(self.text.clone(), context, 32., width);
|
||||
let text_display = Text::new(self.text.clone(), context, 64., width);
|
||||
let _ = context.move_to(0., text_display.extents().height());
|
||||
let _ = context.set_source_rgba(PURPLE.0, PURPLE.1, PURPLE.2, alpha);
|
||||
text_display.draw();
|
||||
|
@ -300,34 +301,28 @@ impl CyberScreen {
|
|||
|
||||
if let Some(animation) = animations.get(&Position::Top) {
|
||||
let y = height as f64 * 1. / 5.;
|
||||
let surface = context.target().create_for_rectangle(Rectangle::new(
|
||||
20.,
|
||||
y,
|
||||
max_width,
|
||||
region_height,
|
||||
)).unwrap();
|
||||
let surface = context
|
||||
.target()
|
||||
.create_for_rectangle(Rectangle::new(20., y, max_width, region_height))
|
||||
.unwrap();
|
||||
let ctx = Context::new(&surface).unwrap();
|
||||
animation.tick(now, &ctx, max_width);
|
||||
}
|
||||
if let Some(animation) = animations.get(&Position::Middle) {
|
||||
let y = height as f64 * 2. / 5.;
|
||||
let surface = context.target().create_for_rectangle(Rectangle::new(
|
||||
20.,
|
||||
y,
|
||||
max_width,
|
||||
region_height,
|
||||
)).unwrap();
|
||||
let surface = context
|
||||
.target()
|
||||
.create_for_rectangle(Rectangle::new(20., y, max_width, region_height))
|
||||
.unwrap();
|
||||
let ctx = Context::new(&surface).unwrap();
|
||||
animation.tick(now, &ctx, max_width);
|
||||
}
|
||||
if let Some(animation) = animations.get(&Position::Bottom) {
|
||||
let y = height as f64 * 3. / 5.;
|
||||
let surface = context.target().create_for_rectangle(Rectangle::new(
|
||||
20.,
|
||||
y,
|
||||
max_width,
|
||||
region_height,
|
||||
)).unwrap();
|
||||
let surface = context
|
||||
.target()
|
||||
.create_for_rectangle(Rectangle::new(20., y, max_width, region_height))
|
||||
.unwrap();
|
||||
let ctx = Context::new(&surface).unwrap();
|
||||
animation.tick(now, &ctx, max_width);
|
||||
}
|
||||
|
@ -338,32 +333,41 @@ impl CyberScreen {
|
|||
}
|
||||
|
||||
fn next_page(&self) {
|
||||
println!("next page");
|
||||
self.imp().next_page();
|
||||
self.queue_draw();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let script = Script(vec![Step {
|
||||
text: "The distinguishing thing".to_owned(),
|
||||
position: Position::Top,
|
||||
transition: Duration::from_secs(2),
|
||||
}]);
|
||||
|
||||
println!("{}", serde_yml::to_string(&script).unwrap());
|
||||
|
||||
let script = Script::from_file(Path::new("./script.yml")).unwrap();
|
||||
for element in script.iter() {
|
||||
println!("{:?}", element);
|
||||
}
|
||||
|
||||
let script = Arc::new(RwLock::new(Script::default()));
|
||||
let app = gtk::Application::builder()
|
||||
.application_id("com.luminescent-dreams.cyberpunk-slideshow")
|
||||
.build();
|
||||
|
||||
app.add_main_option(
|
||||
"script",
|
||||
glib::char::Char::from(b's'),
|
||||
glib::OptionFlags::IN_MAIN,
|
||||
glib::OptionArg::String,
|
||||
"",
|
||||
None,
|
||||
);
|
||||
|
||||
app.connect_handle_local_options({
|
||||
let script = script.clone();
|
||||
move |_, options| {
|
||||
if let Some(script_path) = options.lookup::<String>("script").unwrap() {
|
||||
let mut script = script.write().unwrap();
|
||||
*script = Script::from_file(Path::new(&script_path)).unwrap();
|
||||
-1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.connect_activate(move |app| {
|
||||
let screen = CyberScreen::new(script.clone());
|
||||
let screen = CyberScreen::new(script.read().unwrap().clone());
|
||||
|
||||
let events = EventControllerKey::new();
|
||||
|
||||
|
|
|
@ -290,13 +290,11 @@ fn word_wrap(content: String, context: &Context, max_width: f64) -> Vec<String>
|
|||
let extents = context.text_extents(&line).unwrap();
|
||||
if extents.width() > max_width {
|
||||
let line = words[start..idx-1].join(" ");
|
||||
println!("line: {}", line);
|
||||
start = idx-1;
|
||||
lines.push(line.clone());
|
||||
}
|
||||
}
|
||||
if line.len() > 0 {
|
||||
println!("line: {}", line);
|
||||
lines.push(line);
|
||||
}
|
||||
lines
|
||||
|
|
Loading…
Reference in New Issue