add small canvas on time line
This commit is contained in:
55
src/music.rs
55
src/music.rs
@@ -1,14 +1,17 @@
|
|||||||
use crate::message::Message;
|
use crate::message::Message;
|
||||||
use crate::utils::string_to_polygon;
|
use crate::utils::string_to_polygon;
|
||||||
use crate::{polygon_draw::*, utils::string_to_color};
|
use crate::{polygon_draw::*, utils::string_to_color};
|
||||||
|
use iced::widget::shader::wgpu::util::RenderEncoder;
|
||||||
|
use kira::Frame;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use kira::{AudioManager, sound::static_sound::StaticSoundData};
|
use kira::{AudioManager, sound::static_sound::StaticSoundData};
|
||||||
|
|
||||||
|
use iced::Vector;
|
||||||
use iced::event::Status;
|
use iced::event::Status;
|
||||||
use iced::mouse::Cursor;
|
use iced::mouse::Cursor;
|
||||||
use iced::widget::canvas::Event;
|
use iced::widget::canvas::{Event, Geometry};
|
||||||
use iced::{mouse, padding};
|
use iced::{Size, mouse, padding};
|
||||||
|
|
||||||
use iced::widget::canvas;
|
use iced::widget::canvas;
|
||||||
use iced::widget::canvas::Stroke;
|
use iced::widget::canvas::Stroke;
|
||||||
@@ -166,13 +169,23 @@ impl canvas::Program<Message> for Music {
|
|||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
_cursor: mouse::Cursor,
|
_cursor: mouse::Cursor,
|
||||||
) -> Vec<canvas::Geometry> {
|
) -> Vec<canvas::Geometry> {
|
||||||
|
let mut geo_small_frame: Vec<Geometry> = vec![];
|
||||||
|
let mut geo_cursor: Vec<Geometry> = vec![];
|
||||||
let mut frame = canvas::Frame::new(renderer, bounds.size());
|
let mut frame = canvas::Frame::new(renderer, bounds.size());
|
||||||
let mut toggle_color = true;
|
let mut toggle_color = true;
|
||||||
let padding = 8.;
|
let padding = 8.;
|
||||||
let w = bounds.width - (padding * 2.);
|
let w = bounds.width - (padding * 2.);
|
||||||
for (delta, _) in &self.poly_frame {
|
for (delta, polyframe) in &self.poly_frame {
|
||||||
let x = delta / self.length * w + 8.;
|
let x = delta / self.length * w + 8.;
|
||||||
frame.fill_rectangle(
|
let mut back_frame = canvas::Frame::new(
|
||||||
|
renderer,
|
||||||
|
Size {
|
||||||
|
width: bounds.width,
|
||||||
|
height: bounds.height,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
back_frame.fill_rectangle(
|
||||||
iced::Point { x: x, y: 0.0 },
|
iced::Point { x: x, y: 0.0 },
|
||||||
frame.size(),
|
frame.size(),
|
||||||
if toggle_color {
|
if toggle_color {
|
||||||
@@ -181,10 +194,33 @@ impl canvas::Program<Message> for Music {
|
|||||||
Color::from_rgb8(69, 104, 130)
|
Color::from_rgb8(69, 104, 130)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
geo_small_frame.push(back_frame.into_geometry());
|
||||||
toggle_color = !toggle_color;
|
toggle_color = !toggle_color;
|
||||||
|
let mut small_frame = canvas::Frame::new(
|
||||||
|
renderer,
|
||||||
|
Size {
|
||||||
|
width: bounds.width,
|
||||||
|
height: bounds.height,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
small_frame.translate(Vector {
|
||||||
|
x: x + (bounds.height / 10.),
|
||||||
|
y: (bounds.height / 10.),
|
||||||
|
});
|
||||||
|
polyframe.draw_in_frame(
|
||||||
|
&mut small_frame,
|
||||||
|
Size {
|
||||||
|
width: (8. * bounds.height) / 10.,
|
||||||
|
height: (8. * bounds.height) / 10.,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
geo_small_frame.push(small_frame.into_geometry());
|
||||||
}
|
}
|
||||||
let x = self.current_delta / self.length * w + 8.;
|
let x = self.current_delta / self.length * w + 8.;
|
||||||
frame.stroke_rectangle(
|
let mut frame_cursor = canvas::Frame::new(renderer, bounds.size());
|
||||||
|
frame_cursor.stroke_rectangle(
|
||||||
iced::Point::new(x, 0.),
|
iced::Point::new(x, 0.),
|
||||||
iced::Size {
|
iced::Size {
|
||||||
width: 0.,
|
width: 0.,
|
||||||
@@ -196,7 +232,7 @@ impl canvas::Program<Message> for Music {
|
|||||||
..Stroke::default()
|
..Stroke::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
frame.stroke_rectangle(
|
frame_cursor.stroke_rectangle(
|
||||||
iced::Point { x: 0.0, y: 0.0 },
|
iced::Point { x: 0.0, y: 0.0 },
|
||||||
frame.size(),
|
frame.size(),
|
||||||
Stroke {
|
Stroke {
|
||||||
@@ -205,9 +241,14 @@ impl canvas::Program<Message> for Music {
|
|||||||
..Stroke::default()
|
..Stroke::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
geo_cursor.push(frame_cursor.into_geometry());
|
||||||
|
|
||||||
|
//vec_geo.push(frame.into_geometry());
|
||||||
// Then, we produce the geometry
|
// Then, we produce the geometry
|
||||||
vec![frame.into_geometry()]
|
let mut out = vec![frame.into_geometry()];
|
||||||
|
out.append(&mut geo_small_frame);
|
||||||
|
out.append(&mut geo_cursor);
|
||||||
|
out
|
||||||
}
|
}
|
||||||
fn update(
|
fn update(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ use crate::utils::string_to_color;
|
|||||||
|
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
use iced::Size;
|
||||||
use iced::Vector;
|
use iced::Vector;
|
||||||
use iced::mouse;
|
use iced::mouse;
|
||||||
use iced::widget::canvas;
|
use iced::widget::canvas;
|
||||||
use iced::widget::canvas::Stroke;
|
use iced::widget::canvas::{Frame, Stroke, Style};
|
||||||
use iced::widget::canvas::Style;
|
use iced::{Color, Point, Rectangle, Renderer, Theme};
|
||||||
use iced::{Color, Rectangle, Renderer, Theme};
|
|
||||||
use kira::sound::static_sound::StaticSoundData;
|
use kira::sound::static_sound::StaticSoundData;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -49,6 +49,65 @@ impl PolygonFrame {
|
|||||||
polygons: vec![],
|
polygons: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn draw_in_frame(&self, frame: &mut Frame, size: Size) {
|
||||||
|
let radius = size.height / 2.0 - (size.height / 10.);
|
||||||
|
let mut vec = Vector::new(0.0, -radius);
|
||||||
|
let c = Point {
|
||||||
|
x: size.width / 2.,
|
||||||
|
y: size.height / 2.,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Draw Circle
|
||||||
|
let circle = canvas::Path::circle(c, radius);
|
||||||
|
frame.stroke(
|
||||||
|
&circle,
|
||||||
|
Stroke {
|
||||||
|
width: 6.0,
|
||||||
|
style: Style::Solid(Color::from_rgba8(210, 193, 182, 0.25)),
|
||||||
|
..Stroke::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw all polygons by there points
|
||||||
|
for poly in &self.polygons {
|
||||||
|
let l = poly.points_teta.len();
|
||||||
|
let mut line: canvas::Path;
|
||||||
|
let mut t1: f32;
|
||||||
|
let mut t2: f32;
|
||||||
|
let mut color: Color;
|
||||||
|
for i in 0..l {
|
||||||
|
t1 = poly.points_teta[i] + poly.global_teta;
|
||||||
|
t2 = poly.points_teta[(i + 1) % l] + poly.global_teta;
|
||||||
|
line = canvas::Path::line(c + vec.rotate(t1), c + vec.rotate(t2));
|
||||||
|
color = poly.color.clone();
|
||||||
|
color.a = 0.25;
|
||||||
|
frame.stroke(
|
||||||
|
&line,
|
||||||
|
Stroke {
|
||||||
|
width: 4.0,
|
||||||
|
style: Style::Solid(poly.color.clone()),
|
||||||
|
..Stroke::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// Draw the red dot on the current position
|
||||||
|
let dot = canvas::Path::circle(frame.center() + vec.rotate(self.teta), 10.0);
|
||||||
|
frame.fill(&dot, Color::from_rgb(1.0, 0.0, 0.0));
|
||||||
|
*/
|
||||||
|
// Draw the frame
|
||||||
|
/*
|
||||||
|
frame.stroke_rectangle(
|
||||||
|
iced::Point { x: 0.0, y: 0.0 },
|
||||||
|
size,
|
||||||
|
Stroke {
|
||||||
|
width: 8.0,
|
||||||
|
style: Style::Solid(Color::from_rgb8(207, 74, 28)),
|
||||||
|
..Stroke::default()
|
||||||
|
},
|
||||||
|
);*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message> canvas::Program<Message> for PolygonFrame {
|
impl<Message> canvas::Program<Message> for PolygonFrame {
|
||||||
|
|||||||
Reference in New Issue
Block a user