walkit 0.10.4

Modern Winamp skin engine: .wal skins, MAKI scripts, a draw list for any renderer
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
// SPDX-License-Identifier: GPL-3.0-or-later
//! A classic skin's cursors: which of its 29 cursor files Winamp shows over each part of each
//! window, and the files themselves decoded. Winamp 5.666 loads each as Windows loads a cursor
//! file, so a `.cur` name may hold an animated cursor, and picks one per part of the main window,
//! the equalizer, the playlist, the video window and the gen windows.

use super::style::ClassicStyle;
use super::ClassicWindow;

/// What a skin's cursor stands for, and what the host shows when the skin has no file for it
/// and no base skin is behind it (Winamp then shows an arrow with a small sign).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CursorKind {
    /// The plain arrow.
    Arrow,
    /// Moves the window (four arrows).
    Move,
    /// Drags a slider sideways.
    HorizontalSlide,
    /// Drags a slider up and down.
    VerticalSlide,
    /// Over a close button.
    Close,
    /// Sizes the window.
    Resize,
}

impl CursorKind {
    /// The base skin's file (under [`crate::files::BASE_PREFIX`]) that holds Winamp's cursor
    /// of this kind (base 2.91's cursors are the ones Winamp shows when a skin has none).
    fn winamps_own(self) -> &'static str {
        match self {
            CursorKind::Move => "wasabi-base/titlebar.cur",
            CursorKind::HorizontalSlide => "wasabi-base/posbar.cur",
            CursorKind::Close => "wasabi-base/close.cur",
            CursorKind::Arrow => "wasabi-base/normal.cur",
            CursorKind::VerticalSlide => "wasabi-base/eqslid.cur",
            CursorKind::Resize => "wasabi-base/psize.cur",
        }
    }
}

/// The cursor files a classic skin holds, one entry per place a classic window shows one, each
/// with what it stands for.
pub const CURSOR_FILES: [(&str, CursorKind); 29] = {
    use CursorKind::{Arrow, Close, HorizontalSlide, Move, Resize, VerticalSlide};
    [
        ("volbal.cur", HorizontalSlide),
        ("posbar.cur", HorizontalSlide),
        ("winbut.cur", Arrow),
        ("min.cur", Arrow),
        ("close.cur", Close),
        ("mainmenu.cur", Arrow),
        ("titlebar.cur", Move),
        ("songname.cur", HorizontalSlide),
        ("normal.cur", Arrow),
        ("winbut.cur", Arrow),
        ("min.cur", Arrow),
        ("wsposbar.cur", HorizontalSlide),
        ("close.cur", Close),
        ("mmenu.cur", Arrow),
        ("wsnormal.cur", Arrow),
        ("pwinbut.cur", Arrow),
        ("pclose.cur", Close),
        ("ptbar.cur", Move),
        ("pvscroll.cur", VerticalSlide),
        ("psize.cur", Resize),
        ("pnormal.cur", Arrow),
        ("pwinbut.cur", Arrow),
        ("pclose.cur", Close),
        ("pwssize.cur", HorizontalSlide),
        ("pwsnorm.cur", Arrow),
        ("eqslid.cur", VerticalSlide),
        ("eqclose.cur", Close),
        ("eqtitle.cur", Move),
        ("eqnormal.cur", Arrow),
    ]
};

/// A box a cursor covers: left, top, right, bottom, inclusive; a negative value counts
/// from the window's right or bottom edge.
type Box4 = (i32, i32, i32, i32);

fn within(b: Box4, w: i32, h: i32, x: i32, y: i32) -> bool {
    let fix = |v: i32, size: i32| if v < 0 { v + size } else { v };
    let (l, t, r, bt) = (fix(b.0, w), fix(b.1, h), fix(b.2, w), fix(b.3, h));
    x >= l && x <= r && y >= t && y <= bt
}

/// The first of `boxes` that holds the point, else `boxes.len()`.
fn first(boxes: &[Box4], w: i32, h: i32, x: i32, y: i32) -> usize {
    boxes
        .iter()
        .position(|b| within(*b, w, h, x, y))
        .unwrap_or(boxes.len())
}

/// The cursor slot (an index into [`CURSOR_FILES`]) at `x`, `y` of classic window `win`,
/// `w` x `h`, as `style`'s Winamp picks it.
pub fn slot_at(
    win: ClassicWindow,
    style: ClassicStyle,
    w: i32,
    h: i32,
    x: i32,
    y: i32,
) -> Option<usize> {
    Some(match win {
        // volume and balance share one cursor file
        ClassicWindow::Main => first(
            &[
                (107, 58, 215, 66),
                (18, 73, 263, 81),
                (254, 3, 262, 12),
                (244, 3, 253, 12),
                (264, 3, 272, 12),
                (5, 3, 17, 13),
                (0, 0, 275, 13),
                (105, 24, 266, 35),
            ],
            w,
            h,
            x,
            y,
        ),
        ClassicWindow::MainShade => {
            9 + first(
                &[
                    (254, 3, 262, 12),
                    (244, 3, 253, 12),
                    (228, 3, 242, 12),
                    (264, 3, 272, 12),
                    (5, 3, 17, 13),
                ],
                w,
                h,
                x,
                y,
            )
        }
        ClassicWindow::Equalizer | ClassicWindow::EqualizerShade => {
            let slider = (0..11).any(|i| {
                let x0 = if i == 0 { 21 } else { 60 + 18 * i };
                x >= x0 && x <= x0 + 12 && y > 38 && y < 99
            });
            if slider {
                25
            } else {
                26 + first(&[(264, 3, 272, 12), (0, 0, 275, 13)], w, h, x, y)
            }
        }
        ClassicWindow::Playlist => {
            15 + first(
                &[
                    (-21, 3, -13, 12),
                    (-11, 3, -3, 12),
                    (0, 0, -1, 13),
                    (-15, 20, -7, -38),
                    (-20, -20, -1, -1),
                ],
                w,
                h,
                x,
                y,
            )
        }
        ClassicWindow::PlaylistShade => {
            21 + first(
                &[(-21, 3, -13, 12), (-11, 3, -3, 12), (-29, 3, -20, 12)],
                w,
                h,
                x,
                y,
            )
        }
        ClassicWindow::Video => [16, 17, 19, 20][first(
            &[(-11, 3, -3, 12), (0, 0, -1, 13), (-20, -20, -1, -1)],
            w,
            h,
            x,
            y,
        )],
        ClassicWindow::Gen => {
            // 5.666's boxes stop a pixel short on the right and bottom (probed in the VM); 2.91's
            // take their edges, as the other windows' do
            let edge = i32::from(style == ClassicStyle::Winamp5666);
            let held = |b: Box4| within((b.0, b.1, b.2 - edge, b.3 - edge), w, h, x, y);
            if held((-11, 3, -3, 12)) {
                16
            } else if held((0, 0, -1, 13)) {
                17
            } else if held((-20, -20, -1, -1)) {
                19
            } else {
                // the frame and what the window holds alike (the VM showed PNormal over the
                // media library's lists)
                20
            }
        }
    })
}

/// One picture of a cursor: ARGB rows, and the point that is the pointer's tip.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CursorFrame {
    /// The width.
    pub width: u32,
    /// The height.
    pub height: u32,
    /// The tip, from the left.
    pub hot_x: u32,
    /// The tip, from the top.
    pub hot_y: u32,
    /// ARGB, row by row from the top, straight alpha.
    pub argb: Vec<u32>,
}

/// A decoded cursor: its pictures and the steps an animated one shows them in.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkinCursor {
    /// The pictures.
    pub frames: Vec<CursorFrame>,
    /// Which picture each step shows and for how many milliseconds; one step without a time
    /// for a still cursor.
    pub steps: Vec<(usize, u32)>,
}

fn u16_at(b: &[u8], i: usize) -> Option<u16> {
    Some(u16::from_le_bytes(b.get(i..i + 2)?.try_into().ok()?))
}

fn u32_at(b: &[u8], i: usize) -> Option<u32> {
    Some(u32::from_le_bytes(b.get(i..i + 4)?.try_into().ok()?))
}

/// A cursor file: a `.cur` (or `.ico`) or an animated `.ani`, whatever its name says, as
/// Windows loads a cursor file. `None` for what neither holds.
pub fn decode(bytes: &[u8]) -> Option<SkinCursor> {
    if bytes.get(0..4) == Some(b"RIFF") && bytes.get(8..12) == Some(b"ACON") {
        return decode_ani(bytes);
    }
    let frame = decode_cur(bytes)?;
    Some(SkinCursor {
        frames: vec![frame],
        steps: vec![(0, 0)],
    })
}

/// The first picture of a `.cur` or `.ico`, the one Windows shows when no size is asked for.
fn decode_cur(b: &[u8]) -> Option<CursorFrame> {
    let kind = u16_at(b, 2)?;
    if u16_at(b, 0)? != 0 || !(kind == 1 || kind == 2) || u16_at(b, 4)? == 0 {
        return None;
    }
    let (hx, hy) = (u16_at(b, 10)?, u16_at(b, 12)?);
    let size = u32_at(b, 14)? as usize;
    let at = u32_at(b, 18)? as usize;
    let mut frame = decode_dib(b.get(at..at.checked_add(size)?)?)?;
    if kind == 2 {
        frame.hot_x = u32::from(hx).min(frame.width.saturating_sub(1));
        frame.hot_y = u32::from(hy).min(frame.height.saturating_sub(1));
    } else {
        frame.hot_x = frame.width / 2;
        frame.hot_y = frame.height / 2;
    }
    Some(frame)
}

/// A cursor picture's DIB: the colors (1, 4, 8, 24 or 32 bits) over the AND mask, the two
/// stacked in a bitmap twice as tall. A pixel the mask keeps that has a color is combined with the
/// screen under it by exclusive or on Windows; it shows here as Windows draws it over white (a plain inverting
/// pixel is black). A picture in PNG is not read.
fn decode_dib(d: &[u8]) -> Option<CursorFrame> {
    let header = u32_at(d, 0)? as usize;
    if header < 40 {
        return None;
    }
    let width = i32::from_le_bytes(d.get(4..8)?.try_into().ok()?);
    let height = i32::from_le_bytes(d.get(8..12)?.try_into().ok()?) / 2;
    let bits = u16_at(d, 14)?;
    let compression = u32_at(d, 16)?;
    if width <= 0 || height <= 0 || width > 256 || height > 256 || compression != 0 {
        return None;
    }
    let (w, h) = (width as usize, height as usize);
    let colors = if bits <= 8 {
        match u32_at(d, 32)? {
            0 => 1usize << bits,
            n => n as usize,
        }
    } else {
        0
    };
    let palette: Vec<u32> = (0..colors)
        .map(|i| {
            let p = header + 4 * i;
            d.get(p..p + 3).map_or(0, |c| {
                (u32::from(c[2]) << 16) | (u32::from(c[1]) << 8) | u32::from(c[0])
            })
        })
        .collect();
    let xor_at = header + 4 * colors;
    let xor_row = (w * usize::from(bits)).div_ceil(32) * 4;
    let and_at = xor_at + xor_row * h;
    let and_row = w.div_ceil(32) * 4;
    let mut argb = vec![0u32; w * h];
    let mut alpha_seen = false;
    for y in 0..h {
        let row = xor_at + (h - 1 - y) * xor_row;
        for x in 0..w {
            let px = match bits {
                1 | 4 | 8 => {
                    let bit = x * usize::from(bits);
                    let byte = *d.get(row + bit / 8)?;
                    let shift = 8 - usize::from(bits) - bit % 8;
                    let idx = (usize::from(byte) >> shift) & ((1 << bits) - 1);
                    0xff00_0000 | palette.get(idx).copied().unwrap_or(0)
                }
                24 => {
                    let c = d.get(row + 3 * x..row + 3 * x + 3)?;
                    0xff00_0000 | (u32::from(c[2]) << 16) | (u32::from(c[1]) << 8) | u32::from(c[0])
                }
                32 => {
                    let c = d.get(row + 4 * x..row + 4 * x + 4)?;
                    alpha_seen |= c[3] != 0;
                    (u32::from(c[3]) << 24)
                        | (u32::from(c[2]) << 16)
                        | (u32::from(c[1]) << 8)
                        | u32::from(c[0])
                }
                _ => return None,
            };
            argb[y * w + x] = px;
        }
    }
    if !alpha_seen {
        for y in 0..h {
            let row = and_at + (h - 1 - y) * and_row;
            for x in 0..w {
                let masked = d
                    .get(row + x / 8)
                    .is_some_and(|b| (b >> (7 - x % 8)) & 1 == 1);
                let px = &mut argb[y * w + x];
                *px = match (masked, *px & 0x00ff_ffff) {
                    (true, 0) => 0,
                    (true, c) => 0xff00_0000 | (c ^ 0x00ff_ffff),
                    (false, c) => 0xff00_0000 | c,
                };
            }
        }
    }
    Some(CursorFrame {
        width: w as u32,
        height: h as u32,
        hot_x: 0,
        hot_y: 0,
        argb,
    })
}

/// An animated cursor: `anih` (frames, steps, the time per step in 1/60 s, whether a `seq `
/// orders them), `rate` (a time per step), `seq ` and the `fram` list of `icon` pictures.
fn decode_ani(b: &[u8]) -> Option<SkinCursor> {
    let mut frames = Vec::new();
    let mut steps_n = 0usize;
    let mut jiffies = 0u32;
    let mut sequenced = false;
    let mut rates: Vec<u32> = Vec::new();
    let mut seq: Vec<u32> = Vec::new();
    let mut walk = vec![(12usize, b.len())];
    while let Some((mut i, end)) = walk.pop() {
        while i + 8 <= end {
            let id = b.get(i..i + 4)?;
            let n = u32_at(b, i + 4)? as usize;
            let body = i + 8;
            let stop = body.checked_add(n)?.min(end);
            match id {
                b"LIST" => walk.push((body + 4, stop)),
                b"anih" => {
                    steps_n = u32_at(b, body + 8)? as usize;
                    jiffies = u32_at(b, body + 28)?;
                    sequenced = u32_at(b, body + 32)? & 2 != 0;
                }
                b"rate" => rates = (0..n / 4).filter_map(|k| u32_at(b, body + 4 * k)).collect(),
                b"seq " => seq = (0..n / 4).filter_map(|k| u32_at(b, body + 4 * k)).collect(),
                b"icon" => frames.push(decode_cur(b.get(body..stop)?)?),
                _ => {}
            }
            i = body + n + (n & 1);
        }
    }
    if frames.is_empty() {
        return None;
    }
    let count = if steps_n == 0 { frames.len() } else { steps_n };
    let steps = (0..count)
        .map(|k| {
            let frame = if sequenced {
                seq.get(k).copied().unwrap_or(0) as usize
            } else {
                k
            };
            let jif = rates.get(k).copied().unwrap_or(jiffies).max(1);
            (frame.min(frames.len() - 1), jif * 1000 / 60)
        })
        .collect();
    Some(SkinCursor { frames, steps })
}

impl crate::runtime::SkinRuntime {
    /// The cursor slot (an index into [`CURSOR_FILES`]) Winamp shows at `sx`, `sy` of the
    /// stack, over a classic skin's window; `None` elsewhere.
    pub fn classic_cursor_at(&mut self, sx: i32, sy: i32) -> Option<usize> {
        let o = self.hit_test_stack(sx, sy)?;
        let l = self.layout_object(o)?;
        let win = self.all_objects.iter().copied().find(|&c| {
            matches!(self.objects[c].kind, crate::gui::Kind::ClassicWindow(_))
                && self.layout_object(c) == Some(l)
        })?;
        let crate::gui::Kind::ClassicWindow(kind) = self.objects[win].kind else {
            return None;
        };
        let (x, y) = self.layout_point(l, sx, sy);
        let r = self.objects[win].base.rect;
        slot_at(
            kind,
            self.classic_style,
            r.width,
            r.height,
            x - r.left,
            y - r.top,
        )
    }

    /// The skin's picture for cursor `slot`, decoded once. Without that file, Winamp's
    /// cursor of the slot's kind, from the base skin behind the skin; `None` without either,
    /// and the host shows a cursor for the [`CursorKind`].
    pub fn classic_cursor(&mut self, slot: usize) -> Option<std::rc::Rc<SkinCursor>> {
        let &(file, kind) = CURSOR_FILES.get(slot)?;
        self.cursor_file(file)
            .or_else(|| self.cursor_file(kind.winamps_own()))
    }

    fn cursor_file(&mut self, file: &'static str) -> Option<std::rc::Rc<SkinCursor>> {
        if let Some(c) = self.classic_cursors.get(file) {
            return c.clone();
        }
        let c = self
            .files
            .read(file)
            .and_then(|b| decode(&b))
            .map(std::rc::Rc::new);
        self.classic_cursors.insert(file, c.clone());
        c
    }
}

#[cfg(test)]
pub(crate) mod tests {
    use super::{decode, slot_at, ClassicStyle, CURSOR_FILES};
    use crate::classic::ClassicWindow;

    /// A 2 x 2 cursor, 24 bits: red, green / blue, white; the mask keeps the white one out.
    pub(crate) fn cur(hot: (u16, u16)) -> Vec<u8> {
        let mut dib = Vec::new();
        dib.extend(40u32.to_le_bytes());
        dib.extend(2i32.to_le_bytes());
        dib.extend(4i32.to_le_bytes());
        dib.extend(1u16.to_le_bytes());
        dib.extend(24u16.to_le_bytes());
        dib.extend([0u8; 24]);
        // rows bottom up, each 8 bytes (6 used)
        dib.extend([0xff, 0, 0, 0xff, 0xff, 0xff, 0, 0]); // blue, white
        dib.extend([0, 0, 0xff, 0, 0xff, 0, 0, 0]); // red, green
        dib.extend([0x40, 0, 0, 0]); // mask bottom row: white out
        dib.extend([0, 0, 0, 0]);
        let mut f = vec![0, 0, 2, 0, 1, 0, 2, 2, 0, 0];
        f.extend(hot.0.to_le_bytes());
        f.extend(hot.1.to_le_bytes());
        f.extend((dib.len() as u32).to_le_bytes());
        f.extend(22u32.to_le_bytes());
        f.extend(dib);
        f
    }

    #[test]
    fn a_cur_gives_its_picture_its_mask_and_its_tip() {
        let c = decode(&cur((1, 0))).expect("decoded");
        let f = &c.frames[0];
        assert_eq!((f.width, f.height, f.hot_x, f.hot_y), (2, 2, 1, 0));
        assert_eq!(
            f.argb,
            vec![0xffff_0000, 0xff00_ff00, 0xff00_00ff, 0xff00_0000]
        );
        assert_eq!(c.steps, vec![(0, 0)]);
    }

    #[test]
    fn an_ani_steps_through_its_icons_at_its_rates() {
        let icon = cur((0, 0));
        let chunk = |id: &[u8], body: &[u8]| {
            let mut c = id.to_vec();
            c.extend((body.len() as u32).to_le_bytes());
            c.extend(body);
            if body.len() % 2 == 1 {
                c.push(0);
            }
            c
        };
        let mut anih = Vec::new();
        for v in [36u32, 2, 3, 0, 0, 0, 0, 6, 3] {
            anih.extend(v.to_le_bytes());
        }
        let mut rate = Vec::new();
        for v in [6u32, 12, 3] {
            rate.extend(v.to_le_bytes());
        }
        let mut seq = Vec::new();
        for v in [0u32, 1, 0] {
            seq.extend(v.to_le_bytes());
        }
        let mut fram = b"fram".to_vec();
        fram.extend(chunk(b"icon", &icon));
        fram.extend(chunk(b"icon", &icon));
        let mut body = b"ACON".to_vec();
        body.extend(chunk(b"anih", &anih));
        body.extend(chunk(b"rate", &rate));
        body.extend(chunk(b"seq ", &seq));
        body.extend(chunk(b"LIST", &fram));
        let file = chunk(b"RIFF", &body);
        let c = decode(&file).expect("decoded");
        assert_eq!(c.frames.len(), 2);
        assert_eq!(c.steps, vec![(0, 100), (1, 200), (0, 50)]);
    }

    #[test]
    fn the_main_window_picks_winamps_cursors() {
        let at = |x, y| {
            slot_at(
                ClassicWindow::Main,
                ClassicStyle::Winamp5666,
                275,
                116,
                x,
                y,
            )
            .map(|s| CURSOR_FILES[s].0)
        };
        assert_eq!(
            at(180, 60),
            Some("volbal.cur"),
            "balance shares the volume's"
        );
        assert_eq!(at(100, 75), Some("posbar.cur"));
        assert_eq!(at(268, 5), Some("close.cur"));
        assert_eq!(at(100, 5), Some("titlebar.cur"));
        assert_eq!(at(150, 30), Some("songname.cur"));
        assert_eq!(at(50, 100), Some("normal.cur"));
    }

    #[test]
    fn the_other_windows_pick_theirs() {
        let s = |w, ww, hh, x, y| {
            slot_at(w, ClassicStyle::Winamp5666, ww, hh, x, y).map(|s| CURSOR_FILES[s].0)
        };
        assert_eq!(
            s(ClassicWindow::Equalizer, 275, 116, 25, 60),
            Some("eqslid.cur")
        );
        assert_eq!(
            s(ClassicWindow::Equalizer, 275, 116, 80, 60),
            Some("eqslid.cur")
        );
        assert_eq!(
            s(ClassicWindow::Equalizer, 275, 116, 50, 60),
            Some("eqnormal.cur")
        );
        assert_eq!(
            s(ClassicWindow::Playlist, 300, 145, 290, 140),
            Some("psize.cur")
        );
        assert_eq!(
            s(ClassicWindow::Playlist, 300, 145, 289, 50),
            Some("pvscroll.cur")
        );
        assert_eq!(
            s(ClassicWindow::PlaylistShade, 300, 14, 275, 7),
            Some("pwssize.cur")
        );
        assert_eq!(
            s(ClassicWindow::MainShade, 275, 14, 230, 7),
            Some("wsposbar.cur")
        );
        assert_eq!(
            s(ClassicWindow::Video, 275, 232, 268, 5),
            Some("pclose.cur")
        );
        assert_eq!(s(ClassicWindow::Gen, 275, 116, 100, 5), Some("ptbar.cur"));
        assert_eq!(
            s(ClassicWindow::Gen, 275, 116, 100, 50),
            Some("pnormal.cur"),
            "over the library too"
        );
        assert_eq!(
            s(ClassicWindow::Gen, 275, 116, 100, 13),
            Some("pnormal.cur")
        );
        assert_eq!(s(ClassicWindow::Gen, 275, 116, 273, 114), Some("psize.cur"));
        assert_eq!(
            s(ClassicWindow::Gen, 275, 116, 274, 114),
            Some("pnormal.cur")
        );
        assert_eq!(s(ClassicWindow::Gen, 275, 116, 270, 110), Some("psize.cur"));
    }

    #[test]
    fn a_2_91_gen_window_takes_its_boxes_edges() {
        let at = |style, x, y| {
            slot_at(ClassicWindow::Gen, style, 275, 116, x, y).map(|s| CURSOR_FILES[s].0)
        };
        // the close box's right edge, w - 3, and the title's bottom row, 13
        assert_eq!(at(ClassicStyle::Winamp5666, 272, 5), Some("ptbar.cur"));
        assert_eq!(at(ClassicStyle::Winamp291, 272, 5), Some("pclose.cur"));
        assert_eq!(at(ClassicStyle::Winamp5666, 100, 13), Some("pnormal.cur"));
        assert_eq!(at(ClassicStyle::Winamp291, 100, 13), Some("ptbar.cur"));
    }
}