1use animaterm::prelude::*;
2use animaterm::utilities::message_box;
3use std::collections::HashMap;
4
5fn main() {
6 let mut mgr = Manager::new(true, None, None, None, None, None);
7
8 let mut library = HashMap::with_capacity(2);
9 let cols = 10;
10 let rows = 5;
11 let start_frame = 0;
12 let glyph_1 = Glyph::new(
13 '\u{2580}',
14 Color::new_8bit(0, 0, 5),
15 Color::new_8bit(5, 5, 0),
16 false,
17 true,
18 false,
19 false,
20 false,
21 false,
22 false,
23 false,
24 false,
25 false,
26 );
27 let glyph_2 = Glyph::new(
28 '\u{258C}',
29 Color::new_truecolor(255, 255, 255),
30 Color::new_truecolor(255, 0, 0),
31 false,
32 true,
33 false,
34 false,
35 false,
36 false,
37 false,
38 false,
39 false,
40 false,
41 );
42
43 library.insert(start_frame, vec![glyph_1; rows * cols]);
44 library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
45 let ordering = vec![
46 (start_frame, Timestamp::new(0, 500)),
47 (start_frame + 1, Timestamp::new(0, 500)),
48 ];
49 let running = false;
50 let looping = true;
51 let start_time = Timestamp::now();
52 let animation = Animation::new(running, looping, ordering, start_time);
53 let mut animations = HashMap::new();
54 let anim_id = 0;
55 animations.insert(anim_id, animation);
56 let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
57 let fast_ordering = vec![
58 (start_frame, Timestamp::new(0, 200)),
59 (start_frame + 1, Timestamp::new(0, 200)),
60 ];
61 let mut fast_anim_id = anim_id;
62 if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
63 {
64 fast_anim_id = id;
65 };
66
67 let layer = 0;
68 let offset = (15, 5);
69 let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
70 let screen_size = mgr.screen_size();
71 let title = "Navigation help".to_string();
72 let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
73 let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
74 let mbid = mgr
75 .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
76 .unwrap();
77 mgr.set_graphic(mbid, 0, true);
78
79 let var_ordering = vec![
80 (start_frame, Timestamp::new(0, 400)),
81 (start_frame + 1, Timestamp::new(0, 400)),
82 (start_frame, Timestamp::new(0, 300)),
83 (start_frame + 1, Timestamp::new(0, 300)),
84 (start_frame, Timestamp::new(0, 200)),
85 (start_frame + 1, Timestamp::new(0, 200)),
86 (start_frame, Timestamp::new(0, 100)),
87 (start_frame + 1, Timestamp::new(0, 100)),
88 (start_frame, Timestamp::new(0, 200)),
89 (start_frame + 1, Timestamp::new(0, 200)),
90 (start_frame, Timestamp::new(0, 300)),
91 (start_frame + 1, Timestamp::new(0, 300)),
92 ];
93 mgr.add_animation(
102 graphic_id,
103 Animation::new(false, true, var_ordering, Timestamp::now()),
104 );
105 let mut var_anim_id = 0;
106
107 if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
108 var_anim_id = anim_id;
109 }
110
111 let mut keep_running = true;
112 while keep_running {
113 if let Some(key) = mgr.read_key() {
114 match key {
115 Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
116 Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
117 Key::A => mgr.start_animation(graphic_id, anim_id),
118 Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
119 Key::P => mgr.pause_animation(graphic_id),
120 Key::CtrlP => mgr.pause_animation(graphic_id),
121 Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
122 Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
123 Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
124 Key::Q | Key::ShiftQ => {
125 keep_running = false;
126 }
127 _ => continue,
128 }
129 }
130 }
131
132 mgr.terminate();
133}