fix ctrl z for remove polygon, now polygon return with there color, sound and teta
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -22,15 +22,15 @@ use gui::{load_file_view, music_view};
|
|||||||
use iced::Font;
|
use iced::Font;
|
||||||
use iced::Theme;
|
use iced::Theme;
|
||||||
use iced::{
|
use iced::{
|
||||||
Color, Event, Task,
|
|
||||||
event::{self, Status},
|
event::{self, Status},
|
||||||
keyboard::{Key, key::Named},
|
keyboard::{key::Named, Key},
|
||||||
|
Color, Event, Task,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use kira::{
|
use kira::{
|
||||||
AudioManager, AudioManagerSettings, DefaultBackend, sound::static_sound::StaticSoundData,
|
sound::static_sound::StaticSoundData, AudioManager, AudioManagerSettings, DefaultBackend,
|
||||||
};
|
};
|
||||||
const FONT_BYTES: &[u8] = include_bytes!("../fonts/EnvyCodeRNerdFontMono-Regular.ttf");
|
const FONT_BYTES: &[u8] = include_bytes!("../fonts/EnvyCodeRNerdFontMono-Regular.ttf");
|
||||||
const FONT: Font = Font::with_name("EnvyCodeR Nerd Font Mono");
|
const FONT: Font = Font::with_name("EnvyCodeR Nerd Font Mono");
|
||||||
@@ -87,7 +87,6 @@ impl Polymusic {
|
|||||||
fn new() -> (Self, Task<Message>) {
|
fn new() -> (Self, Task<Message>) {
|
||||||
let manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())
|
let manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())
|
||||||
.expect("Error to load AudioManager");
|
.expect("Error to load AudioManager");
|
||||||
|
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
time_last_frame: Instant::now(),
|
time_last_frame: Instant::now(),
|
||||||
@@ -120,6 +119,9 @@ impl Polymusic {
|
|||||||
self.current_delta,
|
self.current_delta,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Message::ReAddPolygon(poly) => {
|
||||||
|
self.music.add_polygon_from(self.current_delta, poly);
|
||||||
|
}
|
||||||
Message::Tick => {
|
Message::Tick => {
|
||||||
if self.current_delta >= self.music.length {
|
if self.current_delta >= self.music.length {
|
||||||
self.paused = true
|
self.paused = true
|
||||||
@@ -135,10 +137,10 @@ impl Polymusic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Remove(i) => {
|
Message::Remove(i) => {
|
||||||
let name = self.music.remove_polygon(self.current_delta, i);
|
let poly = self.music.remove_polygon(self.current_delta, i);
|
||||||
self.already_save = false;
|
self.already_save = false;
|
||||||
self.historic.add(
|
self.historic.add(
|
||||||
Message::AddPolygon(name),
|
Message::ReAddPolygon(poly),
|
||||||
Message::Remove(i),
|
Message::Remove(i),
|
||||||
self.current_delta,
|
self.current_delta,
|
||||||
);
|
);
|
||||||
@@ -443,6 +445,7 @@ impl Polymusic {
|
|||||||
self.update(Message::TogglePaused);
|
self.update(Message::TogglePaused);
|
||||||
self.update(Message::Tick);
|
self.update(Message::Tick);
|
||||||
self.update(Message::TogglePaused);
|
self.update(Message::TogglePaused);
|
||||||
|
self.update(Message::None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use iced::Color;
|
use iced::Color;
|
||||||
|
|
||||||
|
use crate::polygon_draw::Polygon;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
None,
|
None,
|
||||||
@@ -18,6 +20,7 @@ pub enum Message {
|
|||||||
|
|
||||||
ChangeNbPerSec(String),
|
ChangeNbPerSec(String),
|
||||||
AddPolygon(String),
|
AddPolygon(String),
|
||||||
|
ReAddPolygon(Polygon),
|
||||||
ChangeTeta(usize, f32),
|
ChangeTeta(usize, f32),
|
||||||
Remove(usize),
|
Remove(usize),
|
||||||
ChangeSound(usize, String),
|
ChangeSound(usize, String),
|
||||||
|
|||||||
18
src/music.rs
18
src/music.rs
@@ -3,16 +3,16 @@ use crate::polygon_draw::*;
|
|||||||
use crate::utils::string_to_polygon;
|
use crate::utils::string_to_polygon;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use kira::{AudioManager, sound::static_sound::StaticSoundData};
|
use kira::{sound::static_sound::StaticSoundData, AudioManager};
|
||||||
|
|
||||||
use iced::event::Status;
|
use iced::event::Status;
|
||||||
use iced::mouse::Cursor;
|
use iced::mouse::Cursor;
|
||||||
use iced::widget::canvas::{Event, Geometry};
|
use iced::widget::canvas::{Event, Geometry};
|
||||||
|
use iced::{keyboard, Vector};
|
||||||
use iced::{
|
use iced::{
|
||||||
Size,
|
|
||||||
mouse::{self, ScrollDelta},
|
mouse::{self, ScrollDelta},
|
||||||
|
Size,
|
||||||
};
|
};
|
||||||
use iced::{Vector, keyboard};
|
|
||||||
|
|
||||||
use iced::widget::canvas;
|
use iced::widget::canvas;
|
||||||
use iced::widget::canvas::Stroke;
|
use iced::widget::canvas::Stroke;
|
||||||
@@ -174,17 +174,23 @@ impl Music {
|
|||||||
|
|
||||||
pub fn add_polygon(&mut self, delta: f32, polygon_name: String) {
|
pub fn add_polygon(&mut self, delta: f32, polygon_name: String) {
|
||||||
let current_frame = self.find_poly_frame(delta);
|
let current_frame = self.find_poly_frame(delta);
|
||||||
let poly = string_to_polygon(polygon_name);
|
let mut poly = string_to_polygon(polygon_name);
|
||||||
|
poly.update();
|
||||||
current_frame.polygons.push(poly);
|
current_frame.polygons.push(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_polygon(&mut self, delta: f32, i: usize) -> String {
|
pub fn add_polygon_from(&mut self, delta: f32, polygon: Polygon) {
|
||||||
|
let current_frame = self.find_poly_frame(delta);
|
||||||
|
current_frame.polygons.push(polygon);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_polygon(&mut self, delta: f32, i: usize) -> Polygon {
|
||||||
let pf = self.find_poly_frame(delta);
|
let pf = self.find_poly_frame(delta);
|
||||||
let mut i = i;
|
let mut i = i;
|
||||||
if i == usize::MAX {
|
if i == usize::MAX {
|
||||||
i = pf.polygons.len() - 1
|
i = pf.polygons.len() - 1
|
||||||
}
|
}
|
||||||
let out = pf.polygons[i].name.clone();
|
let out = pf.polygons[i].clone();
|
||||||
pf.polygons.remove(i);
|
pf.polygons.remove(i);
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user