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
4.7 KB
Raw Blame
//! Porte de src\comum\leopard.h: o metal das janelas do Mac OS X Leopard.

use windows::Win32::Graphics::Direct2D::Common::*;
use windows::Win32::Graphics::Direct2D::*;

use crate::{col, linear, pt, rf, Cor, RectF};

pub fn on() -> bool {
    crate::semaforo::leopard()
}

pub unsafe fn metal(rt: &ID2D1RenderTarget, r: RectF, active: bool, dark: bool, top: bool, r_top: f32) {
    if r.bottom <= r.top || r.right <= r.left {
        return;
    }
    let g = |v: f32| col(v, v, v, 1.0);
    let mut hl = if active { 220.0 / 255.0 } else { 241.0 / 255.0 };
    let (mut c0, mut c1, edge);
    if dark {
        c0 = g(if active { 0.36 } else { 0.30 });
        c1 = g(if active { 0.22 } else { 0.24 });
        edge = g(0.06);
        hl = 0.42;
    } else if active {
        c0 = g(197.0 / 255.0);
        c1 = g(150.0 / 255.0);
        edge = g(64.0 / 255.0);
    } else {
        c0 = g(233.0 / 255.0);
        c1 = g(207.0 / 255.0);
        edge = g(135.0 / 255.0);
    }
    if !top && !dark {
        c0 = g(if active { 190.0 } else { 228.0 } / 255.0);
        c1 = g(if active { 150.0 } else { 207.0 } / 255.0);
        hl = if active { 214.0 } else { 238.0 } / 255.0;
    }
    let mut shape: Option<ID2D1PathGeometry> = None;
    if r_top > 0.5 {
        if let Ok(f) = rt.GetFactory() {
            if let Ok(gm) = f.CreatePathGeometry() {
                if let Ok(sk) = gm.Open() {
                    let rr = r_top;
                    sk.BeginFigure(pt(r.left, r.bottom), D2D1_FIGURE_BEGIN_FILLED);
                    sk.AddLine(pt(r.left, r.top + rr));
                    sk.AddArc(&D2D1_ARC_SEGMENT { point: pt(r.left + rr, r.top), size: D2D_SIZE_F { width: rr, height: rr }, rotationAngle: 0.0, sweepDirection: D2D1_SWEEP_DIRECTION_CLOCKWISE, arcSize: D2D1_ARC_SIZE_SMALL });
                    sk.AddLine(pt(r.right - rr, r.top));
                    sk.AddArc(&D2D1_ARC_SEGMENT { point: pt(r.right, r.top + rr), size: D2D_SIZE_F { width: rr, height: rr }, rotationAngle: 0.0, sweepDirection: D2D1_SWEEP_DIRECTION_CLOCKWISE, arcSize: D2D1_ARC_SIZE_SMALL });
                    sk.AddLine(pt(r.right, r.bottom));
                    sk.EndFigure(D2D1_FIGURE_END_CLOSED);
                    if sk.Close().is_ok() {
                        shape = Some(gm);
                    }
                }
            }
        }
    }
    if let Some(lb) = linear(rt, &[(0.0, c0), (1.0, c1)], pt(0.0, r.top), pt(0.0, r.bottom)) {
        match &shape {
            Some(s) => rt.FillGeometry(s, &lb, None),
            None => rt.FillRectangle(&r, &lb),
        }
    }
    let (mut dpx, mut dpy) = (96.0f32, 96.0f32);
    rt.GetDpi(&mut dpx, &mut dpy);
    let px = 96.0 / dpx;
    if let Some(b) = crate::brush(rt, g(hl)) {
        let m = if top { r_top * 0.7 } else { 0.0 };
        rt.FillRectangle(&rf(r.left + m, r.top + if top { 0.0 } else { px }, r.right - m, r.top + if top { px } else { 2.0 * px }), &b);
        b.SetColor(&edge);
        if top {
            rt.FillRectangle(&rf(r.left, r.bottom - px, r.right, r.bottom), &b);
        } else {
            rt.FillRectangle(&rf(r.left, r.top, r.right, r.top + px), &b);
        }
    }
}

pub fn sidebar(active: bool, dark: bool) -> Cor {
    if dark {
        return col(0.17, 0.18, 0.20, 1.0);
    }
    if active {
        col(214.0 / 255.0, 221.0 / 255.0, 229.0 / 255.0, 1.0)
    } else {
        col(232.0 / 255.0, 232.0 / 255.0, 232.0 / 255.0, 1.0)
    }
}

/// o ícone de documento do 10.5 pela extensão ("" = a miniatura do Windows)
pub fn doc_icon(nome: &str) -> &'static str {
    let x = nome.rsplit_once('.').map(|(_, x)| x.to_lowercase()).unwrap_or_default();
    match x.as_str() {
        "txt" | "md" | "ini" | "cfg" | "toml" | "json" | "yaml" | "yml" => "doc texto",
        "csv" | "xls" | "xlsx" | "ods" => "doc planilha",
        "log" => "doc log",
        "pdf" => "doc pdf",
        "doc" | "docx" | "odt" => "doc word",
        "rtf" => "doc rich",
        "ppt" | "pptx" | "key" => "doc apresentacao",
        "zip" | "rar" | "7z" | "tar" | "gz" => "doc zip",
        "mp3" | "wav" | "flac" | "m4a" | "ogg" | "aif" | "aiff" | "mid" | "midi" => "doc audio",
        "html" | "htm" => "doc html",
        "xml" => "doc xml",
        "js" | "ps1" | "sh" | "bat" | "cmd" => "doc script",
        "py" => "doc python",
        "c" | "h" => "doc c",
        "cpp" | "hpp" | "cs" => "doc cpp",
        "java" => "doc java",
        "iso" | "img" => "doc disco",
        "ttf" | "otf" => "doc fonte",
        "dll" | "sys" => "doc exe",
        "png" | "jpg" | "jpeg" | "gif" | "bmp" | "webp" | "heic" | "tif" | "tiff" | "ico" | "svg" | "mp4" | "mov" | "mkv" | "avi" | "wmv" | "webm" | "m4v"
        | "exe" | "msi" | "lnk" | "url" | "appref-ms" => "",
        _ => "doc generico",
    }
}