Skip to content

armgit / WacOS

Public Imported from GitHub
0

A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.

Rust
9.4 KB
Raw Blame
// ---- a página Temas do painel (pedido de 02/12/2026: "guarde o tema antigo numa aba Temas pra gente alterar os temas e
// faça outros 2 temas"). Quatro cartões com uma miniatura de cada tema; clicar troca na hora (ajuste ilha_visual). O
// desenho de cada tema está nas peças comuns (cartao, quadradinho, draw_entrada, px_trilho, ficha, draw_manchas), que
// perguntam visual_ilha(). Incluído no ilha_painel.rs.

const SUB_TEMAS: usize = 11;

/// a descrição curta de cada tema
fn tema_desc(i: usize) -> String {
    tr(match i {
        0 => "Liso, cinza e discreto, como os apps da Apple",
        1 => "Manchas de cor, degradês e o brilho da Siri",
        2 => "Preto puro, só contornos e ícones vazados",
        3 => "Azul-marinho, ícones redondos e destaque cheio",
        _ => "Fundo branco e texto escuro, como o modo claro",
    })
}

/// a miniatura de um tema: o fundo, o trilho com a escolhida, dois cartões com ícone e o campo
unsafe fn tema_mini(dc: &ID2D1DeviceContext, br: &ID2D1SolidColorBrush, r: RectF, v: u8) {
    // cada miniatura com as cores dela (a do Claro é a do Apple pela tinta clara)
    let antes = luz_pausa(v == 4);
    tema_mini_(dc, br, r, if v == 4 { 0 } else { v });
    luz_pausa(antes);
}
unsafe fn tema_mini_(dc: &ID2D1DeviceContext, br: &ID2D1SolidColorBrush, r: RectF, v: u8) {
    let ac = acc();
    let rad = 10.0;
    // o fundo
    br.SetColor(&tinta(&col(0.0, 0.0, 0.0, 1.0)));
    dc.FillRoundedRectangle(&comum::rr(r, rad, rad), br);
    dc.PushAxisAlignedClip(&r, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
    match v {
        1 => {
            mancha(dc, pt(r.left + (r.right - r.left) * 0.7, r.top + 8.0), 90.0, 60.0, col(ac.r, ac.g, ac.b, 0.35));
            mancha(dc, pt(r.left + 20.0, r.bottom - 10.0), 70.0, 50.0, col(0.47, 0.35, 1.0, 0.3));
        }
        3 => {
            mancha(dc, pt((r.left + r.right) / 2.0, r.top + 20.0), 160.0, 90.0, col(0.10, 0.16, 0.42, 0.9));
            mancha(dc, pt((r.left + r.right) / 2.0, r.bottom), 160.0, 80.0, col(0.06, 0.10, 0.30, 0.8));
        }
        _ => {}
    }
    dc.PopAxisAlignedClip();
    let w = r.right - r.left;
    // o trilho
    let tr_ = rf(r.right - 0.55 * w, r.top + 8.0, r.right - 8.0, r.top + 22.0);
    let sel = rf(tr_.left + 2.0, tr_.top + 2.0, tr_.left + 0.45 * (tr_.right - tr_.left), tr_.bottom - 2.0);
    let rr7 = |x: RectF| comum::rr(x, (x.bottom - x.top) / 2.0, (x.bottom - x.top) / 2.0);
    match v {
        1 => {
            br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.05)));
            dc.FillRoundedRectangle(&rr7(tr_), br);
            br.SetColor(&tinta(&alfa(ac, 0.3)));
            dc.FillRoundedRectangle(&rr7(sel), br);
            br.SetColor(&tinta(&alfa(ac, 0.6)));
            dc.DrawRoundedRectangle(&rr7(sel), br, 0.8, None);
        }
        2 => {
            br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.18)));
            dc.DrawRoundedRectangle(&rr7(tr_), br, 0.8, None);
            br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.75)));
            dc.DrawRoundedRectangle(&rr7(sel), br, 0.8, None);
        }
        3 => {
            br.SetColor(&tinta(&alfa(NAVY, 0.16)));
            dc.FillRoundedRectangle(&rr7(tr_), br);
            br.SetColor(&tinta(&alfa(ac, 0.9)));
            dc.FillRoundedRectangle(&rr7(sel), br);
        }
        _ => {
            br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.08)));
            dc.FillRoundedRectangle(&rr7(tr_), br);
            br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.2)));
            dc.FillRoundedRectangle(&rr7(sel), br);
        }
    }
    // dois cartões com um ícone cada
    let ch = (r.bottom - r.top) * 0.36;
    let cy = r.top + 30.0;
    for (k, cor) in [(0x5aa9ff, 0x2f6bff), (0xff7ab8, 0xe0438f)].iter().enumerate() {
        let cw = (w - 24.0) / 2.0;
        let c = rf(r.left + 8.0 + k as f32 * (cw + 8.0), cy, r.left + 8.0 + k as f32 * (cw + 8.0) + cw, cy + ch);
        let (a, b) = (hexcor(cor.0, 1.0), hexcor(cor.1, 1.0));
        let meio = col((a.r + b.r) / 2.0, (a.g + b.g) / 2.0, (a.b + b.b) / 2.0, 1.0);
        let ic = rf(c.left + 6.0, c.top + 6.0, c.left + 18.0, c.top + 18.0);
        match v {
            1 => {
                br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.05)));
                dc.FillRoundedRectangle(&comum::rr(c, 8.0, 8.0), br);
                br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.08)));
                dc.DrawRoundedRectangle(&comum::rr(c, 8.0, 8.0), br, 0.7, None);
                if let Some(g) = degrade(dc, pt(ic.left, ic.top), pt(ic.right, ic.bottom), &[(0.0, a), (1.0, b)]) {
                    dc.FillRoundedRectangle(&comum::rr(ic, 3.5, 3.5), &g);
                }
            }
            2 => {
                br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.16)));
                dc.DrawRoundedRectangle(&comum::rr(c, 6.0, 6.0), br, 0.8, None);
                br.SetColor(&tinta(&meio));
                dc.DrawRoundedRectangle(&comum::rr(ic, 3.0, 3.0), br, 1.0, None);
            }
            3 => {
                br.SetColor(&tinta(&alfa(NAVY, 0.16)));
                dc.FillRoundedRectangle(&comum::rr(c, 9.0, 9.0), br);
                br.SetColor(&tinta(&meio));
                dc.FillEllipse(&ell(pt((ic.left + ic.right) / 2.0, (ic.top + ic.bottom) / 2.0), 6.0, 6.0), br);
            }
            _ => {
                br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.08)));
                dc.FillRoundedRectangle(&comum::rr(c, 7.0, 7.0), br);
                br.SetColor(&tinta(&meio));
                dc.FillRoundedRectangle(&comum::rr(ic, 3.0, 3.0), br);
            }
        }
        // duas linhas de "texto"
        br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.5)));
        dc.FillRoundedRectangle(&comum::rr(rf(c.left + 6.0, c.bottom - 15.0, c.left + cw * 0.6, c.bottom - 12.0), 1.5, 1.5), br);
        br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.22)));
        dc.FillRoundedRectangle(&comum::rr(rf(c.left + 6.0, c.bottom - 9.0, c.left + cw * 0.4, c.bottom - 6.5), 1.2, 1.2), br);
    }
    // o campo
    let f = rf(r.left + 8.0, r.bottom - 22.0, r.right - 8.0, r.bottom - 8.0);
    match v {
        1 => {
            br.SetColor(&tinta(&col(0.07, 0.07, 0.094, 1.0)));
            dc.FillRoundedRectangle(&rr7(f), br);
            let siri = [(0.0, hexcor(0xff8a3d, 1.0)), (0.33, hexcor(0xff4fa3, 1.0)), (0.66, hexcor(0x7a5cff, 1.0)), (1.0, hexcor(0x3db8ff, 1.0))];
            if let Some(g) = degrade(dc, pt(f.left, f.top), pt(f.right, f.bottom), &siri) {
                dc.DrawRoundedRectangle(&rr7(f), &g, 1.0, None);
            }
        }
        2 => {
            br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.2)));
            dc.DrawRoundedRectangle(&rr7(f), br, 0.8, None);
        }
        3 => {
            br.SetColor(&tinta(&alfa(NAVY, 0.18)));
            dc.FillRoundedRectangle(&rr7(f), br);
        }
        _ => {
            br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.1)));
            dc.FillRoundedRectangle(&rr7(f), br);
        }
    }
}

unsafe fn px_temas(dc: &ID2D1DeviceContext, br: &ID2D1SolidColorBrush, ca: RectF) {
    let f = fonts();
    let y = ca.top;
    text(dc, br, &tr("Temas"), &f.val, rf(ca.left, y - 1.0, ca.right, y + 23.0), WHITE);
    text(dc, br, &tr("O visual do painel da Ilha. Troca na hora."), &f.small, rf(ca.left + largura_texto(&tr("Temas"), &f.val) + 12.0, y + 3.0, ca.right, y + 21.0), GRAY);
    let atual = visual_ilha() as usize;
    let top = y + 34.0;
    let (gap, cols) = (12.0f32, 2usize);
    let cw = (ca.right - ca.left - gap) / cols as f32;
    let linhas = VISUAIS.len().div_ceil(cols);
    let chh = ((ca.bottom - top - gap * (linhas - 1) as f32) / linhas as f32).min(150.0);
    for (i, (_, nome)) in VISUAIS.iter().enumerate() {
        let (c, l) = (i % cols, i / cols);
        let r = rf(ca.left + c as f32 * (cw + gap), top + l as f32 * (chh + gap), ca.left + c as f32 * (cw + gap) + cw, top + l as f32 * (chh + gap) + chh);
        let q = hq(HitId::TemaIlha, i as i32);
        let on = atual == i;
        // o cartão do Apple, sempre (a página não muda de cara com o tema escolhido para comparar melhor)
        br.SetColor(&tinta(&col(1.0, 1.0, 1.0, 0.06 + 0.04 * q.min(1.0))));
        dc.FillRoundedRectangle(&comum::rr(r, 14.0, 14.0), br);
        if on {
            br.SetColor(&tinta(&alfa(acc(), 0.95)));
            dc.DrawRoundedRectangle(&comum::rr(rf(r.left + 1.0, r.top + 1.0, r.right - 1.0, r.bottom - 1.0), 14.0, 14.0), br, 2.0, None);
        }
        let mini = rf(r.left + 10.0, r.top + 10.0, r.left + 10.0 + (r.right - r.left) * 0.48, r.bottom - 10.0);
        tema_mini(dc, br, mini, i as u8);
        let tx = mini.right + 12.0;
        text(dc, br, &tr(nome), &f.title, rf(tx, r.top + 14.0, r.right - 30.0, r.top + 34.0), WHITE);
        let (_, hd) = medir(&tema_desc(i), &fonte_q(11.5, DWRITE_FONT_WEIGHT_NORMAL), r.right - 12.0 - tx);
        br.SetColor(&tinta(&GRAY));
        dc.DrawText(&w(&tema_desc(i)), &fonte_q(11.5, DWRITE_FONT_WEIGHT_NORMAL), &rf(tx, r.top + 36.0, r.right - 12.0, r.top + 36.0 + hd + 4.0), br, D2D1_DRAW_TEXT_OPTIONS_CLIP, DWRITE_MEASURING_MODE_NATURAL);
        if on {
            let cc = pt(r.right - 18.0, r.top + 22.0);
            br.SetColor(&tinta(&acc()));
            dc.FillEllipse(&ell(cc, 9.0, 9.0), br);
            sym(dc, br, "checkmark", around(cc.x, cc.y, 9.0, 8.0), WHITE);
        }
        add_hit(HitId::TemaIlha, r, i as i32);
    }
}
fn px_tema_escolhe(i: i32) {
    if s().foto.is_some() {
        return;
    }
    if let Some((k, _)) = VISUAIS.get(i.max(0) as usize) {
        shell::set_setting("ilha_visual", k);
        log!("ilha: tema do painel {k}");
    }
    start_frames();
}