Impl display

This commit is contained in:
Stephen Seo 2021-09-16 13:50:14 +09:00
parent bea743d836
commit 83dcfe520d
3 changed files with 746 additions and 14 deletions

551
Cargo.lock generated
View file

@ -2,6 +2,24 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "adler32"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "ahash"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
name = "ansi_term"
version = "0.11.0"
@ -22,12 +40,66 @@ dependencies = [
"winapi",
]
[[package]]
name = "audir-sles"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea47348666a8edb7ad80cbee3940eb2bccf70df0e6ce09009abe1a836cb779f5"
[[package]]
name = "audrey"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58b92a84e89497e3cd25d3672cd5d1c288abaac02c18ff21283f17d118b889b8"
dependencies = [
"dasp_frame",
"dasp_sample",
"hound",
"lewton",
]
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bumpalo"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
[[package]]
name = "bytemuck"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cc"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
@ -43,6 +115,131 @@ dependencies = [
"vec_map",
]
[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "crc32fast"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [
"cfg-if",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [
"cfg-if",
"lazy_static",
]
[[package]]
name = "dasp_frame"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2a3937f5fe2135702897535c8d4a5553f8b116f76c1529088797f2eee7c5cd6"
dependencies = [
"dasp_sample",
]
[[package]]
name = "dasp_sample"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
[[package]]
name = "deflate"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
dependencies = [
"adler32",
"byteorder",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "fontdue"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75712fff1702bac51b7eaa5a5ca9f9853b8055ef5906088a32f4fe196595a1d"
dependencies = [
"hashbrown",
"ttf-parser",
]
[[package]]
name = "gif"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a668f699973d0f573d15749b7002a9ac9e1f9c6b220e7b165601334c173d8de"
dependencies = [
"color_quant",
"weezl",
]
[[package]]
name = "glam"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "333928d5eb103c5d4050533cec0384302db6be8ef7d3cebd30ec6a35350353da"
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [
"ahash",
]
[[package]]
name = "heck"
version = "0.3.3"
@ -61,25 +258,221 @@ dependencies = [
"libc",
]
[[package]]
name = "hound"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549"
[[package]]
name = "image"
version = "0.23.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"gif",
"jpeg-decoder",
"num-iter",
"num-rational",
"num-traits",
"png",
"scoped_threadpool",
"tiff",
]
[[package]]
name = "jpeg-decoder"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
dependencies = [
"rayon",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lewton"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d542c1a317036c45c2aa1cf10cc9d403ca91eb2d333ef1a4917e5cb10628bd0"
dependencies = [
"byteorder",
"ogg",
"smallvec",
]
[[package]]
name = "libc"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
[[package]]
name = "macroquad"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c11792fb3af71339e4354ee3dbde4bbe5731dac266cc087b414338dfb1ca1bd"
dependencies = [
"bumpalo",
"fontdue",
"glam",
"image",
"macroquad_macro",
"miniquad",
"quad-rand",
"quad-snd",
]
[[package]]
name = "macroquad_macro"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15db41b6abd0156c498868ec69f8973731ef75874768ac234980422579e70805"
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memoffset"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
dependencies = [
"autocfg",
]
[[package]]
name = "miniquad"
version = "0.3.0-alpha.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6793a3ef846953fc7c01302093abf8749be22742c63db05c66ef0a2c889a7fbb"
dependencies = [
"sapp-android",
"sapp-darwin",
"sapp-dummy",
"sapp-ios",
"sapp-linux",
"sapp-wasm",
"sapp-windows",
]
[[package]]
name = "miniz_oxide"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
dependencies = [
"adler32",
]
[[package]]
name = "miniz_oxide"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
dependencies = [
"adler",
"autocfg",
]
[[package]]
name = "mpd_info_screen"
version = "0.1.0"
dependencies = [
"image",
"macroquad",
"structopt",
]
[[package]]
name = "ndk-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c44922cb3dbb1c70b5e5f443d63b64363a898564d739ba5198e3a9138442868d"
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "ogg"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13e571c3517af9e1729d4c63571a27edd660ade0667973bfc74a67c660c2b651"
dependencies = [
"byteorder",
]
[[package]]
name = "png"
version = "0.16.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
dependencies = [
"bitflags",
"crc32fast",
"deflate",
"miniz_oxide 0.3.7",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
@ -113,6 +506,34 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "quad-alsa-sys"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66c2f04a6946293477973d85adc251d502da51c57b08cd9c997f0cfd8dcd4b5"
dependencies = [
"libc",
]
[[package]]
name = "quad-rand"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658fa1faf7a4cc5f057c9ee5ef560f717ad9d8dc66d975267f709624d6e1ab88"
[[package]]
name = "quad-snd"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9b33c4e021bc86d54061b7d23ec96e6fd4c4400066658b043e2b2b36ebca737"
dependencies = [
"audir-sles",
"audrey",
"libc",
"quad-alsa-sys",
"winapi",
]
[[package]]
name = "quote"
version = "1.0.9"
@ -122,6 +543,113 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rayon"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90"
dependencies = [
"autocfg",
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"lazy_static",
"num_cpus",
]
[[package]]
name = "sapp-android"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a4a81f462ba2783213978528560aa138adf2f94da1ac940c1b5c854c03e1724"
dependencies = [
"libc",
"ndk-sys",
]
[[package]]
name = "sapp-darwin"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0310e2445f307468aa13f1cde94d6fba6b8fd329afbb642dedbe3faf1a145f31"
dependencies = [
"cc",
]
[[package]]
name = "sapp-dummy"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66f1ad26a5b6c682b9ca27c66db9aa91002b8d98a82ac7101ded57285215a478"
dependencies = [
"libc",
]
[[package]]
name = "sapp-ios"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "081e6e5261c9ac2e938979b6a854a53b439f065fc3c897205ce7e69d3028b4a9"
dependencies = [
"cc",
]
[[package]]
name = "sapp-linux"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbdb2f8011955c62544d9e626a58333e788810d00bd7411d52b81611b92af142"
dependencies = [
"libc",
]
[[package]]
name = "sapp-wasm"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00e859e8645a3bcb85aecd40bab883438e4105f21b21bccbeac2348760f508bb"
[[package]]
name = "sapp-windows"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8faec983cb54ce5e9529815fc0aae6c36bab9fba9cd0ae5590dfa17bc0719fa"
dependencies = [
"winapi",
]
[[package]]
name = "scoped_threadpool"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "smallvec"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0"
dependencies = [
"maybe-uninit",
]
[[package]]
name = "strsim"
version = "0.8.0"
@ -172,6 +700,23 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "tiff"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437"
dependencies = [
"jpeg-decoder",
"miniz_oxide 0.4.4",
"weezl",
]
[[package]]
name = "ttf-parser"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ae2f58a822f08abdaf668897e96a5656fe72f5a9ce66422423e8849384872e6"
[[package]]
name = "unicode-segmentation"
version = "1.8.0"
@ -202,6 +747,12 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "weezl"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -7,3 +7,5 @@ edition = "2018"
[dependencies]
structopt = "0.3"
macroquad = "0.3"
image = "0.23"

View file

@ -1,3 +1,6 @@
use image::{DynamicImage, ImageResult};
use macroquad::prelude::*;
use std::convert::TryInto;
use std::fs::File;
use std::io::{Read, Write};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
@ -7,6 +10,13 @@ use std::thread;
use std::time::{Duration, Instant};
use structopt::StructOpt;
const POLL_DURATION: Duration = Duration::from_secs(2);
const TITLE_X_OFFSET: f32 = 20.0f32;
const TITLE_Y_OFFSET: f32 = 20.0f32;
const TIMER_X_OFFSET: f32 = 20.0f32;
const TIMER_Y_OFFSET: f32 = 20.0f32;
const TIME_MAX_DIFF: f64 = 2.0f64;
#[derive(StructOpt, Debug)]
#[structopt(name = "mpd_info_screen")]
struct Opt {
@ -23,6 +33,7 @@ struct Shared {
current_song: String,
current_song_length: f64,
current_song_position: f64,
current_song_pos_rec: Instant,
thread_running: bool,
stream: TcpStream,
password: String,
@ -37,6 +48,7 @@ impl Shared {
current_song: String::new(),
current_song_length: 0.0,
current_song_position: 0.0,
current_song_pos_rec: Instant::now(),
thread_running: true,
stream,
password: String::new(),
@ -276,6 +288,7 @@ fn info_loop(shared_data: Arc<Mutex<Shared>>) -> Result<(), String> {
lock.current_song_position = value;
lock.dirty = true;
song_pos_get_time = Instant::now();
lock.current_song_pos_rec = Instant::now();
} else {
println!("Got error trying to get current_song_position");
}
@ -326,13 +339,13 @@ fn info_loop(shared_data: Arc<Mutex<Shared>>) -> Result<(), String> {
} else if let Err(e) = write_result {
println!("Got error requesting authentication: {}", e);
}
} else if song_title_get_time.elapsed() > Duration::from_secs(5) {
} else if song_title_get_time.elapsed() > POLL_DURATION {
let write_result = lock.stream.write(b"currentsong\n");
if let Err(e) = write_result {
println!("Got error requesting currentsong info: {}", e);
}
} else if song_length_get_time.elapsed() > Duration::from_secs(5)
|| song_pos_get_time.elapsed() > Duration::from_secs(5)
} else if song_length_get_time.elapsed() > POLL_DURATION
|| song_pos_get_time.elapsed() > POLL_DURATION
{
let write_result = lock.stream.write(b"status\n");
if let Err(e) = write_result {
@ -360,20 +373,40 @@ fn info_loop(shared_data: Arc<Mutex<Shared>>) -> Result<(), String> {
Ok(())
}
fn get_info_from_shared(shared: Arc<Mutex<Shared>>, force_check: bool) -> Result<(), String> {
fn get_info_from_shared(
shared: Arc<Mutex<Shared>>,
force_check: bool,
) -> Result<(String, f64, f64, Instant), String> {
let mut title: String = String::new();
let mut length: f64 = 0.0;
let mut pos: f64 = 0.0;
let mut instant_rec: Instant = Instant::now();
if let Ok(mut lock) = shared.lock() {
if lock.dirty || force_check {
println!("Current song: {}", lock.current_song);
println!("Current song length: {}", lock.current_song_length);
println!("Current song position: {}", lock.current_song_position);
title = lock.current_song.clone();
length = lock.current_song_length;
pos = lock.current_song_position;
instant_rec = lock.current_song_pos_rec;
//println!("Current song: {}", lock.current_song);
//println!("Current song length: {}", lock.current_song_length);
//println!("Current song position: {}", lock.current_song_position);
lock.dirty = false;
}
}
Ok(())
Ok((title, length, pos, instant_rec))
}
fn main() -> Result<(), String> {
fn window_conf() -> Conf {
Conf {
window_title: String::from("mpd info screen"),
fullscreen: false,
..Default::default()
}
}
#[macroquad::main(window_conf)]
async fn main() -> Result<(), String> {
let opt = Opt::from_args();
println!("Got host addr == {}, port == {}", opt.host, opt.port);
@ -398,12 +431,158 @@ fn main() -> Result<(), String> {
info_loop(thread_shared_data).expect("Failure during info_loop");
});
thread::sleep(Duration::from_secs(2));
let wait_time: f64 = 0.75;
let mut timer: f64 = 0.0;
let mut track_timer: f64 = 0.0;
let mut title: String = String::new();
let mut art_texture: Option<Texture2D> = None;
get_info_from_shared(shared_data.clone(), false)
.expect("Should be able to get info from shared");
'macroquad_main: loop {
let dt: f64 = get_frame_time() as f64;
clear_background(BLACK);
thread::sleep(Duration::from_secs(10));
if is_key_pressed(KeyCode::Escape) {
break 'macroquad_main;
}
timer -= dt;
track_timer -= dt;
if timer < 0.0 || track_timer < 0.0 {
timer = wait_time;
let info_result = get_info_from_shared(shared_data.clone(), true);
if let Ok((track_title, duration, pos, instant_rec)) = info_result {
if track_title != title {
title = track_title;
art_texture = None;
}
let duration_since = instant_rec.elapsed();
let recorded_time = duration - pos - duration_since.as_secs_f64();
if (recorded_time - track_timer).abs() > TIME_MAX_DIFF {
track_timer = duration - pos;
}
}
if art_texture.is_none() {
let mut image_result: Option<ImageResult<DynamicImage>> = None;
{
let lock_result = shared_data.lock();
if let Ok(l) = lock_result {
image_result = Some(image::load_from_memory(&l.art_data));
}
}
if let Some(Ok(dynimg)) = image_result {
let img_buf = dynimg.to_rgba8();
art_texture = Some(Texture2D::from_rgba8(
img_buf
.width()
.try_into()
.expect("width of image should fit in u16"),
img_buf
.height()
.try_into()
.expect("height of image should fit into u16"),
&img_buf.to_vec(),
));
}
}
}
if let Some(texture) = art_texture {
if texture.width() > screen_width() || texture.height() > screen_height() {
let ratio: f32 = texture.width() / texture.height();
// try filling to height
let mut height = screen_height();
let mut width = screen_height() * ratio;
if width > screen_width() {
// try filling to width instead
width = screen_width();
height = screen_width() / ratio;
}
let draw_params: DrawTextureParams = DrawTextureParams {
dest_size: Some(Vec2::new(width, height)),
..Default::default()
};
draw_texture_ex(
texture,
(screen_width() - width) / 2.0f32,
(screen_height() - height) / 2.0f32,
WHITE,
draw_params,
);
} else {
draw_texture(
texture,
(screen_width() - texture.width()) / 2.0f32,
(screen_height() - texture.height()) / 2.0f32,
WHITE,
);
}
}
if !title.is_empty() {
let mut text_size = 64;
let mut text_dim: TextDimensions;
loop {
text_dim = measure_text(&title, None, text_size, 1.0f32);
if text_dim.width + TITLE_X_OFFSET > screen_width() {
text_size -= 4;
} else {
break;
}
if text_size <= 4 {
text_size = 4;
break;
}
}
draw_rectangle(
TITLE_X_OFFSET,
screen_height() - TITLE_Y_OFFSET - text_dim.height * 2.0,
text_dim.width,
text_dim.height,
Color::new(0.0, 0.0, 0.0, 0.4),
);
draw_text(
&title,
TITLE_X_OFFSET,
screen_height() - TITLE_Y_OFFSET - text_dim.height,
text_size as f32,
WHITE,
);
let mut timer_string = track_timer.to_string();
let dot_pos = timer_string.find(".");
if let Some(pos) = dot_pos {
timer_string.truncate(pos + 2);
}
let timer_dim = measure_text(&timer_string, None, 64, 1.0f32);
draw_rectangle(
TIMER_X_OFFSET,
screen_height()
- TITLE_Y_OFFSET
- text_dim.height
- TIMER_Y_OFFSET
- timer_dim.height * 2.0,
timer_dim.width,
timer_dim.height,
Color::new(0.0, 0.0, 0.0, 0.4),
);
draw_text(
&timer_string,
TIMER_X_OFFSET,
screen_height()
- TITLE_Y_OFFSET
- text_dim.height
- TIMER_Y_OFFSET
- timer_dim.height,
64.0f32,
WHITE,
);
}
next_frame().await
}
println!("Stopping thread...");
shared_data
@ -412,7 +591,7 @@ fn main() -> Result<(), String> {
.thread_running = false;
println!("Waiting on thread...");
thread::sleep(Duration::from_secs(2));
thread::sleep(Duration::from_millis(200));
println!("Joining on thread...");
child.join().expect("Should be able to join on thread");