Set up command line options

This commit is contained in:
Savanni D'Gerinel 2024-11-02 14:08:58 -04:00
parent 6e26740a40
commit 20623284ed
2 changed files with 38 additions and 36 deletions

View File

@ -6,6 +6,7 @@ use std::{
ops::Index, ops::Index,
path::Path, path::Path,
rc::Rc, rc::Rc,
sync::{Arc, RwLock},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
@ -99,7 +100,7 @@ impl Animation for Fade {
let frames = (now - self.start_time).as_secs_f64() * FPS as f64; let frames = (now - self.start_time).as_secs_f64() * FPS as f64;
let alpha = alpha_rate * frames 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.move_to(0., text_display.extents().height());
let _ = context.set_source_rgba(PURPLE.0, PURPLE.1, PURPLE.2, alpha); let _ = context.set_source_rgba(PURPLE.0, PURPLE.1, PURPLE.2, alpha);
text_display.draw(); text_display.draw();
@ -300,34 +301,28 @@ impl CyberScreen {
if let Some(animation) = animations.get(&Position::Top) { if let Some(animation) = animations.get(&Position::Top) {
let y = height as f64 * 1. / 5.; let y = height as f64 * 1. / 5.;
let surface = context.target().create_for_rectangle(Rectangle::new( let surface = context
20., .target()
y, .create_for_rectangle(Rectangle::new(20., y, max_width, region_height))
max_width, .unwrap();
region_height,
)).unwrap();
let ctx = Context::new(&surface).unwrap(); let ctx = Context::new(&surface).unwrap();
animation.tick(now, &ctx, max_width); animation.tick(now, &ctx, max_width);
} }
if let Some(animation) = animations.get(&Position::Middle) { if let Some(animation) = animations.get(&Position::Middle) {
let y = height as f64 * 2. / 5.; let y = height as f64 * 2. / 5.;
let surface = context.target().create_for_rectangle(Rectangle::new( let surface = context
20., .target()
y, .create_for_rectangle(Rectangle::new(20., y, max_width, region_height))
max_width, .unwrap();
region_height,
)).unwrap();
let ctx = Context::new(&surface).unwrap(); let ctx = Context::new(&surface).unwrap();
animation.tick(now, &ctx, max_width); animation.tick(now, &ctx, max_width);
} }
if let Some(animation) = animations.get(&Position::Bottom) { if let Some(animation) = animations.get(&Position::Bottom) {
let y = height as f64 * 3. / 5.; let y = height as f64 * 3. / 5.;
let surface = context.target().create_for_rectangle(Rectangle::new( let surface = context
20., .target()
y, .create_for_rectangle(Rectangle::new(20., y, max_width, region_height))
max_width, .unwrap();
region_height,
)).unwrap();
let ctx = Context::new(&surface).unwrap(); let ctx = Context::new(&surface).unwrap();
animation.tick(now, &ctx, max_width); animation.tick(now, &ctx, max_width);
} }
@ -338,32 +333,41 @@ impl CyberScreen {
} }
fn next_page(&self) { fn next_page(&self) {
println!("next page");
self.imp().next_page(); self.imp().next_page();
self.queue_draw(); self.queue_draw();
} }
} }
fn main() { fn main() {
let script = Script(vec![Step { let script = Arc::new(RwLock::new(Script::default()));
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 app = gtk::Application::builder() let app = gtk::Application::builder()
.application_id("com.luminescent-dreams.cyberpunk-slideshow") .application_id("com.luminescent-dreams.cyberpunk-slideshow")
.build(); .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| { app.connect_activate(move |app| {
let screen = CyberScreen::new(script.clone()); let screen = CyberScreen::new(script.read().unwrap().clone());
let events = EventControllerKey::new(); let events = EventControllerKey::new();

View File

@ -290,13 +290,11 @@ fn word_wrap(content: String, context: &Context, max_width: f64) -> Vec<String>
let extents = context.text_extents(&line).unwrap(); let extents = context.text_extents(&line).unwrap();
if extents.width() > max_width { if extents.width() > max_width {
let line = words[start..idx-1].join(" "); let line = words[start..idx-1].join(" ");
println!("line: {}", line);
start = idx-1; start = idx-1;
lines.push(line.clone()); lines.push(line.clone());
} }
} }
if line.len() > 0 { if line.len() > 0 {
println!("line: {}", line);
lines.push(line); lines.push(line);
} }
lines lines