mod animated;
mod build;
mod buttons;
mod calls;
mod draw;
mod draw_kinds;
mod events;
mod frames;
mod free;
pub(crate) mod layout;
mod lists;
mod maki;
mod objects;
mod options;
mod pointer;
mod resources;
pub mod scripted;
mod shapes;
mod sizes;
mod sliders;
mod system;
#[cfg(test)]
mod tests;
mod tick;
mod touches;
mod tree;
mod vis;
mod vm;
mod windows;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::rc::Rc;
use crate::draw::{BitmapDef, BitmapFontDef, DrawCmd, FontDef, Gamma, Rect, Region, Rgb};
use crate::files::SkinFiles;
use crate::gui::{Container, ContainerId, Kind, Obj, ObjId};
use crate::host::{
Clock, EngineStats, ObjectInfo, Presentation, SavedSettings, SkinHost, SkinSetup,
UnknownObject, WindowId, WindowInfo,
};
use crate::maki::{Handle, Script, SystemObject, Value};
use crate::player::{Player, Status};
use crate::xml::XmlNode;
pub(crate) const MAX_LAYOUT_PASSES: i32 = 4;
pub(crate) const MAX_EVENT_DEPTH: i32 = 48;
pub(crate) const MAX_INCLUDE_DEPTH: usize = 32;
pub(crate) const MAX_XML_DEPTH: usize = 256;
pub(crate) const MAX_NODES: i64 = 200_000;
pub(crate) const MAX_SETTINGS: usize = 4_096;
pub(crate) const MAX_SETTING_LENGTH: usize = 65_536;
pub(crate) const MAX_OBJECTS: i64 = 100_000;
pub(crate) const MAX_ALIAS_DEPTH: i32 = 8;
pub(crate) const EQ_FLAT: i32 = 128;
pub(crate) const PLAYLIST_GUID: &str = "45f3f7c1-a6f3-4ee6-a15e-125e92fc3f8d";
pub(crate) const LIBRARY_GUID: &str = "6b0edf80-c9a5-11d3-9f26-00c04f39ffc6";
pub(crate) const AVS_GUID: &str = "0000000a-000c-0010-ff7b-01014263450c";
pub(crate) const VIDEO_GUID: &str = "f0816d7b-fffc-4343-80f2-e8199aa15cc3";
pub(crate) const VIS_HOLDS: [&str; 2] = [AVS_GUID, VIDEO_GUID];
pub(crate) const LIST_GUIDS: [&str; 2] = [PLAYLIST_GUID, LIBRARY_GUID];
pub(crate) const HOLDER_TAGS: [&str; 2] = ["component", "windowholder"];
pub(crate) const HOST_WINDOWS: [&str; 3] = ["ml", "avs", "video"];
const MAX_OPAQUE_SCAN: i64 = 512 * 512;
const DEFAULT_ASCENT: f32 = 0.8;
const DEFAULT_DESCENT: f32 = 0.2;
pub(crate) const TOGGLE_GUIDS: [(&str, &str); 7] = [
("pl", PLAYLIST_GUID),
("playlist", PLAYLIST_GUID),
("ml", LIBRARY_GUID),
("musiclibrary", LIBRARY_GUID),
("library", LIBRARY_GUID),
("avs", AVS_GUID),
("video", VIDEO_GUID),
];
pub(crate) fn toggle_guid(alias: &str) -> Option<&'static str> {
TOGGLE_GUIDS
.iter()
.find(|(a, _)| *a == alias)
.map(|(_, g)| *g)
}
#[derive(Debug, Clone)]
pub(crate) enum Fit {
Whole,
Cut {
part: BitmapDef,
asked_w: i32,
asked_h: i32,
},
None,
}
pub struct SkinRuntime {
pub(crate) files: Box<dyn SkinFiles>,
pub(crate) classic_regions: HashMap<String, Vec<Vec<(i32, i32)>>>,
pub(crate) classic_pledit: crate::classic::pledit::PleditStyle,
pub(crate) classic_sheets: Rc<crate::classic::Sheets>,
pub(crate) classic_skin: bool,
pub(crate) classic_row_height: Option<i32>,
pub(crate) classic_gen_font: Option<Rc<crate::classic::gen::GenFont>>,
pub(crate) classic_cursors:
HashMap<&'static str, Option<Rc<crate::classic::cursor::SkinCursor>>>,
pub(crate) classic_palette: crate::classic::viscolor::Palette,
pub(crate) classic_vis: crate::classic::vis::ClassicVis,
pub(crate) classic_eq_auto: bool,
pub(crate) classic_pl_scroll: i32,
pub(crate) classic_vis_mode: crate::classic::vis::VisMode,
pub(crate) classic_vis_before: crate::classic::vis::VisMode,
pub(crate) classic_vis_tapped_at: i64,
pub(crate) classic_status: Option<String>,
pub(crate) classic_status_until: i64,
pub(crate) classic_title_base: i32,
pub(crate) classic_title_epoch: i64,
pub(crate) classic_title_key: String,
pub(crate) classic_vis_style: crate::classic::vis::VisStyle,
pub(crate) classic_press: Option<crate::classic::touch::ClassicPress>,
pub(crate) classic_open_menu: Option<(ObjId, crate::classic::touch::PlMenu)>,
pub(crate) classic_remaining: bool,
pub(crate) skin_list_font: bool,
pub(crate) action_from: Option<Rect>,
pub(crate) list_row_extra: i32,
pub(crate) classic_list_font: i32,
pub(crate) holders_shown: Vec<ObjId>,
pub(crate) holders_stale: bool,
pub(crate) classic_style: crate::classic::style::ClassicStyle,
pub(crate) classic_list_ink: Option<std::rc::Rc<crate::classic::listfont::ListInk>>,
pub(crate) classic_list_ink_read: bool,
pub(crate) classic_selected_row: Option<i32>,
pub(crate) classic_selected_more: Vec<i32>,
pub(crate) classic_select_anchor: Option<i32>,
pub(crate) classic_row_marks: std::rc::Rc<crate::classic::marks::RowMarks>,
pub(crate) classic_shades: bool,
pub(crate) host: Box<dyn SkinHost>,
pub(crate) player: Box<dyn Player>,
clock: Clock,
pub(crate) bitmaps: HashMap<String, BitmapDef>,
bitmap_lookups: crate::fasthash::FastMap<String, Option<BitmapDef>>,
image_sizes: crate::fasthash::FastMap<String, (i32, i32)>,
bitmap_fonts: HashMap<String, BitmapFontDef>,
fonts: HashMap<String, FontDef>,
colors: HashMap<String, Rgb>,
color_aliases: HashMap<String, String>,
color_groups: HashMap<String, String>,
aliases: HashMap<String, String>,
pub(crate) group_defs: HashMap<String, Rc<XmlNode>>,
pub(crate) window_types: HashMap<String, Vec<String>>,
earlier_defs: HashMap<usize, Rc<XmlNode>>,
xui_tags: HashMap<String, String>,
gamma_sets: Vec<(String, HashMap<String, Gamma>)>,
current_gamma_set: Option<String>,
gammas: HashMap<String, Option<Gamma>>,
base_bitmaps: HashSet<String>,
base_group_defs: HashSet<usize>,
base_colors: HashSet<String>,
collecting_base: bool,
pub(crate) base_usage: BTreeSet<String>,
resolved_fonts: HashMap<String, Option<Rc<BitmapFontDef>>>,
fits: crate::fasthash::FastMap<BitmapDef, Fit>,
opaque_columns: HashMap<String, i32>,
gdi_lines: HashMap<String, Option<crate::gdi::GdiLineMetrics>>,
shaped: HashMap<ObjId, (i64, DrawCmd)>,
pub(crate) objects: Vec<Obj>,
pub(crate) containers: Vec<Container>,
opened: Vec<ContainerId>,
windows_now: Vec<ObjId>,
windows_at: i64,
window_ids_now: Vec<WindowId>,
window_ids_at: i64,
layouts_by_id: Vec<ObjId>,
placed: HashMap<ObjId, Rect>,
pub(crate) free: free::FreeState,
focused: Option<ObjId>,
shown_before: HashSet<ContainerId>,
pub(crate) scripts: Vec<Script>,
pub(crate) systems: Vec<SystemObject>,
programs: HashMap<String, Option<Rc<crate::maki::Program>>>,
pub(crate) made: Vec<maki::Made>,
config_items: Vec<(String, usize)>,
created: i64,
random_state: u64,
zone_offset: Box<dyn Fn(i64) -> i32>,
shown_for_skin: Vec<String>,
pub(crate) script_error: Option<String>,
pending_starts: Vec<usize>,
pub(crate) timers: Vec<usize>,
starting_buckets: Vec<ObjId>,
pub(crate) animations: Vec<ObjId>,
pub(crate) moving: Vec<ObjId>,
pub(crate) recorded: Option<Vec<scripted::RecordedEvent>>,
pub(crate) private_ints: HashMap<String, i32>,
pub(crate) private_strings: HashMap<String, String>,
config_flags: HashMap<String, bool>,
config_values: HashMap<String, i32>,
pub(crate) stored_settings: BTreeMap<String, String>,
settings_version: i32,
config_version: i32,
pub(crate) unhandled_params: BTreeMap<String, i32>,
pub(crate) skin_name: String,
pub(crate) have_library: bool,
host_actions: bool,
pub(crate) viewport_w: i32,
pub(crate) viewport_h: i32,
view_size: Option<(i32, i32)>,
columns: i32,
column_width: i32,
stretch_last: bool,
pub(crate) touch_slop: i32,
pub(crate) touch: bool,
pub(crate) last_pointer: (i32, i32),
dirty: bool,
moved_dirty: bool,
classic_next_at: i64,
moved_windows: HashSet<ObjId>,
moved_objects: Vec<ObjId>,
clock_second: (i32, bool),
window_drawings: HashMap<ObjId, WindowDrawing>,
pub(crate) drawn_spans: Vec<(ObjId, usize, usize)>,
needs_layout: bool,
scripts_started: bool,
last_status: Status,
last_title: String,
last_volume: i32,
last_switches: i32,
last_tracks: Vec<crate::player::Track>,
last_track_index: i32,
last_eq_on: bool,
last_preamp: i32,
last_bands: Vec<i32>,
last_pan: i32,
last_format: (i32, i32, i32),
last_position: i32,
pub(crate) all_objects: Vec<ObjId>,
sliders: Vec<ObjId>,
texts: Vec<ObjId>,
vis_objects: Vec<ObjId>,
progress_grids: Vec<ObjId>,
buttons: Vec<ObjId>,
captured: Option<ObjId>,
pub(crate) wal_version: f64,
pub(crate) change_count: i64,
pub(crate) shapes_worked_out: i64,
layout_passes: i64,
timer_fires: i64,
last_rects: HashMap<ObjId, Rect>,
told_windows: Vec<WindowId>,
pub(crate) tick_changed: Vec<ObjId>,
pub(crate) drawn_owners: Vec<Option<ObjId>>,
pub(crate) tracking_owners: bool,
slide_lead: i64,
expanded_nodes: i64,
built: i64,
event_depth: i32,
firing: Vec<String>,
edge_placements: i32,
pub(crate) playlist_selected_ms: i32,
pub(crate) pointer: pointer::PointerState,
}
impl SkinRuntime {
pub fn new(
files: Box<dyn SkinFiles>,
host: Box<dyn SkinHost>,
player: Box<dyn Player>,
setup: SkinSetup,
clock: Clock,
) -> Self {
let last_status = player.status();
let last_title = player.title();
let last_volume = player.volume();
let last_switches = switches_of(&*player);
let last_tracks = player.tracks();
let last_track_index = player.track_index();
let last_eq_on = player.eq_enabled();
let last_preamp = player.eq_preamp();
let last_bands = player.eq_bands();
let last_pan = player.pan();
let last_format = (
player.bitrate_kbps(),
player.sample_rate_khz(),
player.channels(),
);
let last_position = player.position_ms();
SkinRuntime {
files,
classic_regions: HashMap::new(),
classic_pledit: crate::classic::pledit::PleditStyle::default(),
classic_sheets: Rc::default(),
classic_skin: false,
classic_row_height: None,
classic_gen_font: None,
classic_cursors: HashMap::new(),
classic_palette: crate::classic::viscolor::BASE,
classic_vis: crate::classic::vis::ClassicVis::default(),
classic_vis_mode: crate::classic::vis::VisMode::default(),
classic_vis_before: crate::classic::vis::VisMode::default(),
classic_vis_tapped_at: i64::MIN / 2,
classic_status: None,
classic_status_until: i64::MAX,
classic_title_base: 0,
classic_title_epoch: 0,
classic_title_key: String::new(),
classic_vis_style: crate::classic::vis::VisStyle::default(),
classic_pl_scroll: 0,
classic_eq_auto: false,
classic_press: None,
classic_open_menu: None,
classic_remaining: false,
classic_selected_row: None,
classic_selected_more: Vec::new(),
classic_select_anchor: None,
classic_row_marks: std::rc::Rc::default(),
classic_shades: true,
host,
player,
clock,
bitmaps: HashMap::new(),
bitmap_lookups: crate::fasthash::FastMap::default(),
image_sizes: crate::fasthash::FastMap::default(),
bitmap_fonts: HashMap::new(),
fonts: HashMap::new(),
colors: HashMap::new(),
color_aliases: HashMap::new(),
color_groups: HashMap::new(),
aliases: HashMap::new(),
group_defs: HashMap::new(),
window_types: HashMap::new(),
earlier_defs: HashMap::new(),
xui_tags: HashMap::new(),
gamma_sets: Vec::new(),
current_gamma_set: None,
gammas: HashMap::new(),
base_bitmaps: HashSet::new(),
base_group_defs: HashSet::new(),
base_colors: HashSet::new(),
collecting_base: false,
base_usage: BTreeSet::new(),
resolved_fonts: HashMap::new(),
fits: crate::fasthash::FastMap::default(),
opaque_columns: HashMap::new(),
gdi_lines: HashMap::new(),
shaped: HashMap::new(),
objects: Vec::new(),
containers: Vec::new(),
opened: Vec::new(),
windows_now: Vec::new(),
windows_at: -1,
window_ids_now: Vec::new(),
window_ids_at: -1,
layouts_by_id: Vec::new(),
placed: HashMap::new(),
free: free::FreeState::default(),
focused: None,
shown_before: HashSet::new(),
scripts: Vec::new(),
systems: Vec::new(),
programs: HashMap::new(),
made: Vec::new(),
config_items: Vec::new(),
created: 0,
random_state: 0x9E37_79B9_7F4A_7C15,
zone_offset: Box::new(|_| 0),
shown_for_skin: Vec::new(),
script_error: None,
pending_starts: Vec::new(),
timers: Vec::new(),
starting_buckets: Vec::new(),
animations: Vec::new(),
moving: Vec::new(),
recorded: None,
private_ints: HashMap::new(),
private_strings: HashMap::new(),
config_flags: HashMap::new(),
config_values: HashMap::new(),
stored_settings: BTreeMap::new(),
settings_version: 0,
config_version: 0,
unhandled_params: BTreeMap::new(),
skin_name: setup.skin_name,
have_library: setup.have_library,
host_actions: setup.host_actions,
viewport_w: 1080,
viewport_h: 1920,
view_size: None,
columns: 1,
column_width: 0,
stretch_last: true,
touch_slop: 6,
touch: false,
skin_list_font: false,
list_row_extra: 0,
classic_list_font: crate::classic::style::ClassicStyle::Winamp5666.list_font_size(),
classic_style: crate::classic::style::ClassicStyle::Winamp5666,
holders_shown: Vec::new(),
holders_stale: false,
action_from: None,
classic_list_ink: None,
classic_list_ink_read: false,
last_pointer: (0, 0),
dirty: true,
moved_dirty: false,
classic_next_at: 0,
moved_windows: HashSet::new(),
moved_objects: Vec::new(),
clock_second: (-1, false),
window_drawings: HashMap::new(),
drawn_spans: Vec::new(),
needs_layout: true,
scripts_started: false,
last_status,
last_title,
last_volume,
last_switches,
last_tracks,
last_track_index,
last_eq_on,
last_preamp,
last_bands,
last_pan,
last_format,
last_position,
all_objects: Vec::new(),
sliders: Vec::new(),
texts: Vec::new(),
vis_objects: Vec::new(),
progress_grids: Vec::new(),
buttons: Vec::new(),
captured: None,
wal_version: 1.0,
change_count: 0,
shapes_worked_out: 0,
layout_passes: 0,
timer_fires: 0,
last_rects: HashMap::new(),
told_windows: Vec::new(),
tick_changed: Vec::new(),
drawn_owners: Vec::new(),
tracking_owners: false,
slide_lead: 0,
expanded_nodes: 0,
built: 0,
event_depth: 0,
firing: Vec::new(),
edge_placements: 0,
playlist_selected_ms: 0,
pointer: pointer::PointerState::default(),
}
}
pub fn host(&mut self) -> &mut dyn SkinHost {
&mut *self.host
}
pub fn player(&mut self) -> &mut dyn Player {
&mut *self.player
}
pub fn set_classic_vis_style(&mut self, style: crate::classic::vis::VisStyle) {
self.classic_vis_style = style;
self.repaint();
}
pub fn now(&self) -> i64 {
(self.clock)()
}
pub fn set_viewport(&mut self, w: i32, h: i32) {
self.viewport_w = w;
self.viewport_h = h;
}
pub fn set_zone_offset(&mut self, f: Box<dyn Fn(i64) -> i32>) {
self.zone_offset = f;
}
pub fn viewport(&self) -> (i32, i32) {
self.view_size.unwrap_or((self.viewport_w, self.viewport_h))
}
pub fn stats(&self) -> EngineStats {
EngineStats {
script_steps: self.scripts.iter().map(|s| s.steps_since_refill()).sum(),
timer_fires: self.timer_fires,
layout_passes: self.layout_passes,
shapes_worked_out: self.shapes_worked_out,
}
}
pub fn color_themes(&self) -> Vec<String> {
self.gamma_sets.iter().map(|(n, _)| n.clone()).collect()
}
pub fn color_theme(&self) -> Option<&str> {
self.current_gamma_set.as_deref()
}
pub fn select_color_theme(&mut self, name: &str) {
let Some(m) = self
.gamma_sets
.iter()
.find(|(n, _)| n.eq_ignore_ascii_case(name))
.map(|(n, _)| n.clone())
else {
return;
};
if self.current_gamma_set.as_deref() != Some(m.as_str()) {
self.settings_changed();
}
self.current_gamma_set = Some(m);
self.gammas.clear();
self.invalidate();
}
pub fn settings_version(&self) -> i32 {
self.settings_version
}
pub fn saved_settings(&self) -> SavedSettings {
SavedSettings {
attributes: self.stored_settings.clone(),
strings: self
.private_strings
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect(),
ints: self
.private_ints
.iter()
.map(|(k, v)| (k.clone(), *v))
.collect(),
}
}
pub fn restore_settings(&mut self, saved: &SavedSettings) {
self.stored_settings
.extend(saved.attributes.iter().map(|(k, v)| (k.clone(), v.clone())));
self.private_strings
.extend(saved.strings.iter().map(|(k, v)| (k.clone(), v.clone())));
self.private_ints
.extend(saved.ints.iter().map(|(k, v)| (k.clone(), *v)));
}
pub(crate) fn settings_changed(&mut self) {
self.settings_version += 1;
}
pub(crate) fn config_changed(&mut self) {
self.config_version += 1;
}
pub(crate) fn store_private_int(&mut self, key: &str, value: i32) {
let k = key.to_lowercase();
if k.len() > MAX_SETTING_LENGTH {
self.host.log(&format!("setting {k} too long, not kept"));
return;
}
if !self.private_ints.contains_key(&k) && self.private_ints.len() >= MAX_SETTINGS {
self.host.log(&format!("too many settings, {k} not kept"));
return;
}
if self.private_ints.insert(k, value) != Some(value) {
self.settings_changed();
}
}
pub(crate) fn store_private_string(&mut self, key: &str, value: &str) {
let k = key.to_lowercase();
if k.len() > MAX_SETTING_LENGTH || value.len() > MAX_SETTING_LENGTH {
self.host.log(&format!("setting {k} too long, not kept"));
return;
}
if !self.private_strings.contains_key(&k) && self.private_strings.len() >= MAX_SETTINGS {
self.host.log(&format!("too many settings, {k} not kept"));
return;
}
if self.private_strings.insert(k, value.to_string()).as_deref() != Some(value) {
self.settings_changed();
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct DrawnWindow {
pub rect: Rect,
pub cmds: Rc<Vec<DrawCmd>>,
pub owners: Rc<Vec<Option<ObjId>>>,
}
#[derive(Debug, Clone)]
pub(crate) struct WindowDrawing {
pub(crate) cmds: Rc<Vec<DrawCmd>>,
pub(crate) owners: Rc<Vec<Option<ObjId>>>,
pub(crate) spans: crate::fasthash::FastMap<ObjId, (usize, usize)>,
}
pub(crate) fn switches_of(p: &dyn Player) -> i32 {
(p.shuffle() as i32) | ((p.repeat() as i32) << 1) | ((p.crossfade() as i32) << 2)
}
pub(crate) fn names_for(id: &str) -> Vec<String> {
let k = id.to_lowercase();
if let Some(rest) = k.strip_prefix("wasabi.") {
vec![k.clone(), format!("studio.{rest}")]
} else if let Some(rest) = k.strip_prefix("studio.") {
vec![k.clone(), format!("wasabi.{rest}")]
} else {
vec![k]
}
}
pub(crate) fn is_grouped(k: &Kind) -> bool {
matches!(
k,
Kind::Group
| Kind::Layout(_)
| Kind::Frame(_)
| Kind::Bucket(_)
| Kind::XFade(_)
| Kind::LayoutStatus(_)
)
}