diff --git a/cockpit/Cargo.lock b/cockpit/Cargo.lock index d1edbf8b..5b21c23f 100644 --- a/cockpit/Cargo.lock +++ b/cockpit/Cargo.lock @@ -590,11 +590,13 @@ name = "cockpit" version = "0.1.0" dependencies = [ "png", + "raw-window-handle", "serde_json", "slint", "slint-build", "tungstenite", "ureq", + "windows-sys 0.61.2", ] [[package]] @@ -1043,6 +1045,26 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "femtovg" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31eebf3ab1b76359ccd5f850c07a7c6b2722c64d9127c40e02358e83f3ff9b1a" +dependencies = [ + "bitflags 2.13.2", + "bytemuck", + "fnv", + "glow", + "imgref", + "itertools 0.15.0", + "log", + "rgb", + "slotmap", + "swash", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -1103,6 +1125,12 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foldhash" version = "0.1.5" @@ -1294,6 +1322,28 @@ dependencies = [ "slab", ] +[[package]] +name = "gbm" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce852e998d3ca5e4a97014fb31c940dc5ef344ec7d364984525fd11e8a547e6a" +dependencies = [ + "bitflags 2.13.2", + "drm", + "drm-fourcc", + "gbm-sys", + "libc", +] + +[[package]] +name = "gbm-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13a5f2acc785d8fb6bf6b7ab6bfb0ef5dad4f4d97e8e70bb8e470722312f76f" +dependencies = [ + "libc", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -1588,13 +1638,17 @@ dependencies = [ "calloop 0.14.5", "cfg_aliases", "drm", + "gbm", + "glutin", "i-slint-common", "i-slint-core", + "i-slint-renderer-femtovg", "i-slint-renderer-software", "input", "libseat", "memmap2", "nix", + "raw-window-handle", "xkbcommon", ] @@ -1612,6 +1666,7 @@ dependencies = [ "i-slint-common", "i-slint-core", "i-slint-core-macros", + "i-slint-renderer-femtovg", ] [[package]] @@ -1644,6 +1699,7 @@ dependencies = [ "i-slint-common", "i-slint-core", "i-slint-core-macros", + "i-slint-renderer-femtovg", "i-slint-renderer-skia", "i-slint-renderer-software", "imgref", @@ -1784,6 +1840,27 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "i-slint-renderer-femtovg" +version = "1.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb0de504d57cdadf80c2abf7bcb8b7135a3716aee1f41b6ebb90ea93e3649d7c" +dependencies = [ + "cfg-if", + "const-field-offset", + "femtovg", + "glow", + "i-slint-common", + "i-slint-core", + "i-slint-core-macros", + "imgref", + "lyon_path", + "pin-weak", + "rgb", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "i-slint-renderer-skia" version = "1.18.1" @@ -3836,10 +3913,12 @@ dependencies = [ "i-slint-common", "i-slint-core", "i-slint-core-macros", + "i-slint-renderer-femtovg", "i-slint-renderer-software", "num-traits", "once_cell", "pin-weak", + "raw-window-handle", "slint-macros", "unicode-segmentation", "vtable", diff --git a/cockpit/Cargo.toml b/cockpit/Cargo.toml index 361b1a6c..9019421e 100644 --- a/cockpit/Cargo.toml +++ b/cockpit/Cargo.toml @@ -13,12 +13,22 @@ serde_json = "1" # Nur ws:// / http:// lokal: weder tungstenite noch ureq mit TLS. tungstenite = { version = "0.24", default-features = false, features = ["handshake"] } ureq = { version = "2", default-features = false, features = ["json"] } -slint = { version = "1", default-features = false, features = ["std", "compat-1-2", "backend-winit", "renderer-software"] } +# software-renderer-systemfonts: damit Segoe UI (Variable) echt gerendert wird, nicht die Notschrift. +# raw-window-handle-06: gibt den rohen HWND her, damit die Windows-Schale DWM/Mica setzen kann. +# renderer-femtovg (GPU/GL): einziger Weg zu ECHTEM transluzentem Mica - der Software-Renderer +# praesentiert unter Windows ueber softbuffer/GDI ohne Alpha, der Backdrop kaeme nie durch. +# Das headless-Vorschaubild nutzt weiter den Software-Renderer (eigene Plattform in bild.rs). +slint = { version = "1", default-features = false, features = ["std", "compat-1-2", "backend-winit", "renderer-software", "software-renderer-systemfonts", "renderer-femtovg", "raw-window-handle-06"] } + +# Windows-Schale: Mica, dunkler Modus und runde Ecken per DWM auf dem rohen HWND. +[target.'cfg(target_os = "windows")'.dependencies] +windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Security", "Win32_Graphics_Dwm", "Win32_Graphics_Gdi", "Win32_UI_Controls", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_System_JobObjects", "Win32_System_LibraryLoader", "Win32_System_Threading"] } +raw-window-handle = "0.6" [build-dependencies] slint-build = "1" - -# Nur fuer das Vorschaubild (examples/bild.rs): Systemschriften im Software-Renderer, PNG schreiben. -[dev-dependencies] -slint = { version = "1", default-features = false, features = ["software-renderer-systemfonts"] } -png = "0.18" + +# Nur fuer das Vorschaubild (examples/bild.rs): Systemschriften im Software-Renderer, PNG schreiben. +[dev-dependencies] +slint = { version = "1", default-features = false, features = ["software-renderer-systemfonts"] } +png = "0.18" diff --git a/cockpit/src/bruecke.rs b/cockpit/src/bruecke.rs index 0dc638c0..15e9bb1c 100644 --- a/cockpit/src/bruecke.rs +++ b/cockpit/src/bruecke.rs @@ -468,10 +468,24 @@ fn verdrahten(f: &Cockpit) { let w = w.clone(); move || { if let Some(f) = w.upgrade() { + // Windows: ins Tray verstecken statt in die Taskleiste minimieren. + #[cfg(target_os = "windows")] + crate::schale::minimieren(f.window()); + #[cfg(not(target_os = "windows"))] f.window().set_minimized(true); } } }); + f.on_maximieren({ + let w = w.clone(); + move || { + if let Some(f) = w.upgrade() { + let maxi = !f.window().is_maximized(); + f.window().set_maximized(maxi); + f.set_maximiert(maxi); + } + } + }); f.on_schliessen(|| { let _ = slint::quit_event_loop(); }); @@ -505,16 +519,45 @@ fn anlegen(adresse: Adresse, verbindung: Verbindung, ansicht: Ansicht) -> Result Ok(f) } +/// Versucht den GPU-Renderer (femtovg) zu waehlen - Voraussetzung fuer ECHTES transluzentes Mica, +/// weil der Software-Renderer unter Windows ueber softbuffer/GDI ohne Alpha praesentiert. Gelingt es, +/// darf das Fenster durchscheinend werden; sonst bleibt es beim deckenden Fluent-Grund. +/// Muss vor dem ersten Fenster laufen (BackendSelector setzt das globale Backend). +fn gpu_renderer_waehlen() -> bool { + #[cfg(target_os = "windows")] + { + slint::BackendSelector::new().renderer_name("femtovg".into()).select().is_ok() + } + #[cfg(not(target_os = "windows"))] + { + false + } +} + /// Das Fenster mit einer festen Ansicht (ohne Server). pub fn fest(ansicht: Ansicht) -> Result<(), Box> { + let durchscheinend = gpu_renderer_waehlen(); let f = anlegen(Adresse::default(), Verbindung::Getrennt("kein Server (cockpit --live starten)".into()), ansicht)?; + f.set_durchscheinend(durchscheinend); + // Windows-Schale (Mica, dunkler Modus, runde Ecken); der Timer muss bis zum run()-Ende leben. + #[cfg(target_os = "windows")] + let _schale = crate::schale::einrichten(&f); f.run()?; Ok(()) } /// Das Fenster, live über `/ws`: der ws-Thread schiebt die Ansicht in den Event-Loop. pub fn live(url: String) -> Result<(), Box> { + let durchscheinend = gpu_renderer_waehlen(); + // Windows: den Python-Server selbst hochziehen (sonst laeuft nichts) - idempotent, und der + // Waechter killt ihn beim Fensterende wieder. Auf dem Mac macht das die Swift-App. + #[cfg(target_os = "windows")] + let _dienst = crate::dienst::starten(); let f = anlegen(adresse_aus(&url), Verbindung::Startet, Ansicht::default())?; + f.set_durchscheinend(durchscheinend); + // Windows-Schale (Mica, dunkler Modus, runde Ecken); der Timer muss bis zum run()-Ende leben. + #[cfg(target_os = "windows")] + let _schale = crate::schale::einrichten(&f); let halt = Arc::new(AtomicBool::new(false)); let w = f.as_weak(); let w_zustand = f.as_weak(); diff --git a/cockpit/src/dienst.rs b/cockpit/src/dienst.rs new file mode 100644 index 00000000..3a572cc2 --- /dev/null +++ b/cockpit/src/dienst.rs @@ -0,0 +1,162 @@ +//! Windows: den Python-Datenschicht-Server (sicht/start.py) als Kindprozess starten, damit +//! alles aus EINEM App-Start laeuft. Auf dem Mac spawnt die Swift-App den Server; unter Windows +//! macht das hier das Cockpit selbst (die letzte offene Naht). Nur hier lebt der Win32-Teil +//! (Job-Objekt); auf anderen Systemen wird das Modul ueber `#[cfg]` in `lib.rs` nicht uebersetzt. +//! +//! - Idempotent: antwortet Port 8787 schon (z. B. ein dev-Server laeuft), wird NICHTS gestartet. +//! - Lifecycle: das Kind haengt in einem Job-Objekt mit KILL_ON_JOB_CLOSE - endet das Cockpit +//! (auch bei Absturz), raeumt Windows den Server und alles, was er gestartet hat, mit weg. +//! Scheitert irgendetwas, laeuft das Cockpit weiter und verbindet, sobald ein Server antwortet. + +use std::ffi::c_void; +use std::mem::size_of; +use std::net::{Ipv4Addr, SocketAddr, TcpStream}; +use std::os::windows::io::AsRawHandle; +use std::os::windows::process::CommandExt; +use std::path::{Path, PathBuf}; +use std::process::{Child, Command, Stdio}; +use std::time::Duration; + +use windows_sys::Win32::Foundation::{CloseHandle, HANDLE}; +use windows_sys::Win32::System::JobObjects::{ + AssignProcessToJobObject, CreateJobObjectW, SetInformationJobObject, + JobObjectExtendedLimitInformation, JOBOBJECT_EXTENDED_LIMIT_INFORMATION, + JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, +}; + +const CREATE_NO_WINDOW: u32 = 0x0800_0000; // kein Konsolenfenster poppt auf +const PORT: u16 = 8787; + +/// Antwortet auf 127.0.0.1:port schon jemand? (dann laeuft der Server bereits) +fn port_offen(port: u16) -> bool { + let ziel = SocketAddr::from((Ipv4Addr::LOCALHOST, port)); + TcpStream::connect_timeout(&ziel, Duration::from_millis(300)).is_ok() +} + +/// Die Projektwurzel suchen: der Ordner, der `sicht/start.py` enthaelt. Vom Arbeitsverzeichnis +/// und vom Ort der .exe aus nach oben gehen (dev: .../cockpit; installiert: neben der .exe). +fn wurzel_finden() -> Option { + let marke = Path::new("sicht").join("start.py"); + let mut starts: Vec = Vec::new(); + if let Ok(d) = std::env::current_dir() { + starts.push(d); + } + if let Ok(e) = std::env::current_exe() { + if let Some(p) = e.parent() { + starts.push(p.to_path_buf()); + } + } + for start in starts { + for an in start.ancestors() { + if an.join(&marke).is_file() { + return Some(an.to_path_buf()); + } + } + } + None +} + +/// Welches Python: zuerst ein venv in der Wurzel, sonst `python` aus dem PATH. +fn python_pfad(wurzel: &Path) -> PathBuf { + for p in [ + wurzel.join(".venv").join("Scripts").join("python.exe"), + wurzel.join("venv").join("Scripts").join("python.exe"), + ] { + if p.is_file() { + return p; + } + } + PathBuf::from("python") +} + +/// Haelt das Server-Kind am Leben und raeumt es am Ende weg. Solange dieser Waechter lebt, lebt +/// (falls gestartet) der Server; beim Fallenlassen wird das Kind beendet und das Job-Objekt +/// geschlossen - KILL_ON_JOB_CLOSE killt dann auch alles, was der Server noch gestartet hatte. +pub struct Dienst { + kind: Option, + job: HANDLE, +} + +impl Dienst { + fn leer() -> Self { + Dienst { kind: None, job: std::ptr::null_mut() } + } +} + +impl Drop for Dienst { + fn drop(&mut self) { + if let Some(mut k) = self.kind.take() { + let _ = k.kill(); + let _ = k.wait(); + } + if !self.job.is_null() { + unsafe { CloseHandle(self.job) }; + } + } +} + +/// Ein Job-Objekt anlegen, das sein Kind (und dessen Nachkommen) killt, sobald der Handle zugeht. +/// Leerer Handle bei Fehlschlag - dann greift nur noch das `kill()` im Drop. +unsafe fn job_mit_killswitch(prozess: HANDLE) -> HANDLE { + let job = CreateJobObjectW(std::ptr::null(), std::ptr::null()); + if job.is_null() { + return std::ptr::null_mut(); + } + let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = std::mem::zeroed(); + info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + SetInformationJobObject( + job, + JobObjectExtendedLimitInformation, + &info as *const _ as *const c_void, + size_of::() as u32, + ); + AssignProcessToJobObject(job, prozess); + job +} + +/// Den Server starten, falls Port 8787 noch tot ist. Gibt den Waechter zurueck (im Live-Pfad bis +/// zum Fensterende halten). Blockiert NICHT auf den Serverstart - `netz::lauschen` verbindet von +/// selbst neu, sobald er antwortet. +pub fn starten() -> Dienst { + if port_offen(PORT) { + return Dienst::leer(); // es laeuft schon einer - nur verbinden + } + let Some(wurzel) = wurzel_finden() else { + eprintln!("Server nicht gestartet: Projektwurzel (sicht/start.py) nicht gefunden"); + return Dienst::leer(); + }; + let py = python_pfad(&wurzel); + let kind = Command::new(&py) + .arg(Path::new("sicht").join("start.py")) + .arg("--port") + .arg(PORT.to_string()) + .arg("--art") + .arg("App") + .current_dir(&wurzel) + // Der Server bricht sonst bei Umlauten in der Konsole ab. + .env("PYTHONUTF8", "1") + .env("PYTHONIOENCODING", "utf-8") + .creation_flags(CREATE_NO_WINDOW) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn(); + let mut kind = match kind { + Ok(k) => k, + Err(e) => { + eprintln!("Server nicht gestartet ({}): {e}", py.display()); + return Dienst::leer(); + } + }; + let job = unsafe { job_mit_killswitch(kind.as_raw_handle() as HANDLE) }; + // Ganz kurz: ging der Prozess sofort wieder (Python fehlt, Importfehler, Sperre belegt), + // nicht als laufend fuehren - sonst killt der Drop ins Leere. + std::thread::sleep(Duration::from_millis(250)); + if matches!(kind.try_wait(), Ok(Some(_))) { + if !job.is_null() { + unsafe { CloseHandle(job) }; + } + return Dienst::leer(); + } + Dienst { kind: Some(kind), job } +} diff --git a/cockpit/src/lib.rs b/cockpit/src/lib.rs index fad43684..41200fa9 100644 --- a/cockpit/src/lib.rs +++ b/cockpit/src/lib.rs @@ -4,6 +4,8 @@ pub mod ansicht; pub mod anzeige; pub mod bruecke; +#[cfg(target_os = "windows")] +pub mod dienst; pub mod format; pub mod formate; pub mod hauptknopf; @@ -13,6 +15,8 @@ pub mod modus; pub mod nachsichtig; pub mod netz; pub mod plankarte; +#[cfg(target_os = "windows")] +pub mod schale; pub mod spielplan; pub mod verlauf; pub mod wachstum; diff --git a/cockpit/src/schale.rs b/cockpit/src/schale.rs new file mode 100644 index 00000000..89043aea --- /dev/null +++ b/cockpit/src/schale.rs @@ -0,0 +1,339 @@ +//! Windows-native Fensterschale: Mica-Hintergrund, dunkler Modus, runde Ecken (per DWM), +//! ein echtes Fenster-Icon fuer die Taskleiste und ein Tray-Symbol mit Minimieren-ins-Tray. +//! Nur hier lebt Win32-Code; der ganze uebrige Baum bleibt plattformfrei. Auf anderen +//! Systemen ist dieses Modul leer (ueber `#[cfg]` in `lib.rs` gar nicht erst uebersetzt). + +use std::ffi::c_void; +use std::mem::{size_of, zeroed}; +use std::ptr::{null, null_mut}; +use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering}; + +use raw_window_handle::{HasWindowHandle, RawWindowHandle}; +use slint::ComponentHandle; +use windows_sys::Win32::Foundation::{HWND, LPARAM, LRESULT, POINT, WPARAM}; +use windows_sys::Win32::Graphics::Dwm::{DwmExtendFrameIntoClientArea, DwmSetWindowAttribute}; +use windows_sys::Win32::Graphics::Gdi::{ + CreateBitmap, CreateDIBSection, DeleteObject, GetDC, ReleaseDC, BITMAPINFO, BI_RGB, DIB_RGB_COLORS, +}; +use windows_sys::Win32::System::LibraryLoader::GetModuleHandleW; +use windows_sys::Win32::UI::Controls::MARGINS; +use windows_sys::Win32::UI::Shell::{ + Shell_NotifyIconW, NIF_ICON, NIF_MESSAGE, NIF_TIP, NIM_ADD, NIM_DELETE, NOTIFYICONDATAW, +}; +use windows_sys::Win32::UI::WindowsAndMessaging::{ + AppendMenuW, CreateIconIndirect, CreatePopupMenu, CreateWindowExW, DefWindowProcW, DestroyMenu, + DestroyWindow, GetCursorPos, GetWindowLongPtrW, PostMessageW, RegisterClassW, SendMessageW, + SetForegroundWindow, SetWindowLongPtrW, SetWindowPos, ShowWindow, TrackPopupMenu, GWL_EXSTYLE, + GWL_STYLE, ICONINFO, ICON_BIG, ICON_SMALL, MF_STRING, SWP_FRAMECHANGED, SWP_NOACTIVATE, + SWP_NOMOVE, SWP_NOSIZE, SWP_NOZORDER, SW_HIDE, SW_RESTORE, SW_SHOW, TPM_NONOTIFY, TPM_RETURNCMD, + TPM_RIGHTBUTTON, WM_CONTEXTMENU, WM_LBUTTONDBLCLK, WM_LBUTTONUP, WM_RBUTTONUP, WM_SETICON, + WNDCLASSW, WS_CAPTION, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW, WS_POPUP, WS_THICKFRAME, +}; + +type Hwnd = HWND; +type Hicon = *mut c_void; + +// DWM-Attribute als rohe Nummern: windows-sys benennt sie je Fassung anders, die Zahlen stehen fest. +const DWMWA_USE_IMMERSIVE_DARK_MODE: u32 = 20; +const DWMWA_WINDOW_CORNER_PREFERENCE: u32 = 33; +const DWMWA_SYSTEMBACKDROP_TYPE: u32 = 38; + +const DWMWCP_ROUND: u32 = 2; // echte Win11-Rundung (ROUNDSMALL waere 3, kleinere Radien) +const DWMSBT_MAINWINDOW: u32 = 2; // Mica (Hauptfenster) + +// Tray: eigene Fensternachricht und Menue-Kennungen. +const WM_TRAY: u32 = 0x8000 + 1; // WM_APP + 1 +const ID_ANZEIGEN: usize = 1; +const ID_BEENDEN: usize = 2; + +// Das Hauptfenster (zum Zeigen/Verstecken aus dem Tray) und das unsichtbare Tray-Fenster. +static HAUPT_HWND: AtomicIsize = AtomicIsize::new(0); +static TRAY_HWND: AtomicIsize = AtomicIsize::new(0); +static KLASSE_DA: AtomicBool = AtomicBool::new(false); + +fn setze_attr(hwnd: Hwnd, attr: u32, wert: u32) { + // Fehler bewusst ignorieren: aelteres Windows kennt das Attribut nicht, dann bleibt es eben aus. + unsafe { + DwmSetWindowAttribute(hwnd, attr, &wert as *const u32 as *const c_void, 4); + } +} + +/// Die nativen Fensterrahmen-Styles vom rohen HWND nehmen. Trotz `no-frame: true` legt +/// winit unter Windows WS_CAPTION und WS_THICKFRAME an; DWM zeichnet daraufhin eigene +/// Titelleisten-Tasten (Min/Max/Schliessen) oben rechts - die lagen doppelt ueber unseren +/// eigenen Slint-Tasten. Caption und Sizebox entfernen loescht die nativen Tasten. +fn rahmen_weg(hwnd: Hwnd) { + unsafe { + let stil = GetWindowLongPtrW(hwnd, GWL_STYLE); + let ohne = stil & !((WS_CAPTION | WS_THICKFRAME) as isize); + if ohne != stil { + SetWindowLongPtrW(hwnd, GWL_STYLE, ohne); + // SWP_FRAMECHANGED: der geaenderte Rahmen wird neu berechnet (ohne Umzug/Groesse/Z). + SetWindowPos(hwnd, null_mut(), 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); + } + // Sicherstellen, dass ein Taskleisten-Button erscheint: App-Fenster, kein Werkzeugfenster. + let ex = GetWindowLongPtrW(hwnd, GWL_EXSTYLE); + let neu = (ex | WS_EX_APPWINDOW as isize) & !(WS_EX_TOOLWINDOW as isize); + if neu != ex { + SetWindowLongPtrW(hwnd, GWL_EXSTYLE, neu); + } + } +} + +/// Dunkler Modus, runde Ecken und Mica auf dem rohen HWND setzen. +fn mica_auf(hwnd: Hwnd) { + rahmen_weg(hwnd); + setze_attr(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, 1); + setze_attr(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_ROUND); + // Rahmen in die GANZE Clientflaeche ziehen ("sheet of glass", Raender -1). Erst dadurch fuellt + // DWM die durchsichtigen Pixel mit dem Backdrop (Mica) statt mit dem Fenster dahinter. + let rand = MARGINS { cxLeftWidth: -1, cxRightWidth: -1, cyTopHeight: -1, cyBottomHeight: -1 }; + unsafe { + DwmExtendFrameIntoClientArea(hwnd, &rand); + } + setze_attr(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, DWMSBT_MAINWINDOW); +} + +/// Das App-Symbol als ARGB-Pixel: eine Pokerchip-Scheibe im Akzentblau mit weissem Rand +/// (vier Randmarken) und einem duennen weissen Innenring. Reicht fuer Taskleiste und Tray. +fn chip_pixel(s: i32) -> Vec { + let mut px = vec![0u32; (s * s) as usize]; + let mitte = (s as f32 - 1.0) / 2.0; + let rad = (s as f32) / 2.0 - 0.5; + let inner = rad * 0.45; + for y in 0..s { + for x in 0..s { + let dx = x as f32 - mitte; + let dy = y as f32 - mitte; + let d = (dx * dx + dy * dy).sqrt(); + let aussen = (rad - d + 0.5).clamp(0.0, 1.0); // 1px weiche Kante + if aussen <= 0.0 { + continue; + } + let (mut r, mut g, mut b) = (0x00u32, 0x78u32, 0xD4u32); // Akzent #0078D4 + // Weisser Rand mit vier Marken (abwechselnde Sektoren). + if d >= rad - 3.4 && d <= rad - 0.6 { + let ang = dy.atan2(dx) + std::f32::consts::PI; // 0..2pi + let sektor = (ang / (std::f32::consts::PI / 4.0)).floor() as i32; + if sektor % 2 == 0 { + r = 255; + g = 255; + b = 255; + } + } + // Duenner weisser Innenring. + if (d - inner).abs() <= 0.9 { + r = 255; + g = 255; + b = 255; + } + let a = (aussen * 255.0) as u32; + // 32bpp-DIB erwartet BGRA im Speicher = little-endian 0xAARRGGBB. + px[(y * s + x) as usize] = (a << 24) | (r << 16) | (g << 8) | b; + } + } + px +} + +/// Aus den ARGB-Pixeln ein HICON bauen (Farb-DIB + leere AND-Maske, Alpha traegt die Form). +unsafe fn icon_bauen(s: i32) -> Hicon { + let px = chip_pixel(s); + let hdc = GetDC(null_mut()); + let mut bmi: BITMAPINFO = zeroed(); + bmi.bmiHeader.biSize = size_of::() as u32; + bmi.bmiHeader.biWidth = s; + bmi.bmiHeader.biHeight = -s; // negativ = top-down + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 32; + bmi.bmiHeader.biCompression = BI_RGB; + let mut bits: *mut c_void = null_mut(); + let farbe = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &mut bits, null_mut(), 0); + ReleaseDC(null_mut(), hdc); + if !bits.is_null() { + std::ptr::copy_nonoverlapping(px.as_ptr(), bits as *mut u32, px.len()); + } + // AND-Maske 1bpp, komplett 0 (= Farbe/Alpha ueberall nutzen). Zeilen auf 16 Bit ausgerichtet. + let takt = (((s + 15) / 16) * 2) as usize; + let leer = vec![0u8; takt * s as usize]; + let maske = CreateBitmap(s, s, 1, 1, leer.as_ptr() as *const c_void); + let mut ii: ICONINFO = zeroed(); + ii.fIcon = 1; + ii.hbmMask = maske; + ii.hbmColor = farbe; + let icon = CreateIconIndirect(&ii); + DeleteObject(farbe); + DeleteObject(maske); + icon +} + +/// Das Icon am Fenster setzen (gross fuer Alt-Tab/Taskleiste, klein fuer die Titelzeile). +unsafe fn icon_setzen(hwnd: Hwnd, gross: Hicon, klein: Hicon) { + SendMessageW(hwnd, WM_SETICON, ICON_BIG as WPARAM, gross as LPARAM); + SendMessageW(hwnd, WM_SETICON, ICON_SMALL as WPARAM, klein as LPARAM); +} + +fn utf16z(s: &str) -> Vec { + s.encode_utf16().chain(std::iter::once(0)).collect() +} + +/// Das Hauptfenster aus dem Tray wieder zeigen und nach vorn holen. +unsafe fn fenster_zeigen() { + let h = HAUPT_HWND.load(Ordering::SeqCst) as Hwnd; + if !h.is_null() { + ShowWindow(h, SW_SHOW); + ShowWindow(h, SW_RESTORE); + SetForegroundWindow(h); + } +} + +/// Die Fensterschleife beenden (ueber den Slint-Loop, also sauber auf dem UI-Thread). +fn beenden() { + let _ = slint::invoke_from_event_loop(|| { + let _ = slint::quit_event_loop(); + }); +} + +/// Das Kontextmenue am Mauszeiger zeigen (Anzeigen / Beenden) und die Wahl ausfuehren. +unsafe fn menue_zeigen(tray: Hwnd) { + let mut pt = POINT { x: 0, y: 0 }; + GetCursorPos(&mut pt); + let menu = CreatePopupMenu(); + AppendMenuW(menu, MF_STRING, ID_ANZEIGEN, utf16z("Anzeigen").as_ptr()); + AppendMenuW(menu, MF_STRING, ID_BEENDEN, utf16z("Beenden").as_ptr()); + // Trick, damit das Menue zuverlaessig wieder schliesst. + SetForegroundWindow(tray); + let wahl = TrackPopupMenu(menu, TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, pt.x, pt.y, 0, tray, null()); + PostMessageW(tray, 0 /* WM_NULL */, 0, 0); + DestroyMenu(menu); + match wahl as usize { + ID_ANZEIGEN => fenster_zeigen(), + ID_BEENDEN => beenden(), + _ => {} + } +} + +/// Fensterprozedur des unsichtbaren Tray-Fensters: nimmt die Klicks auf das Tray-Symbol an. +unsafe extern "system" fn tray_proc(hwnd: Hwnd, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT { + if msg == WM_TRAY { + let maus = (lp as u32) & 0xFFFF; + match maus { + WM_LBUTTONUP | WM_LBUTTONDBLCLK => fenster_zeigen(), + WM_RBUTTONUP | WM_CONTEXTMENU => menue_zeigen(hwnd), + _ => {} + } + return 0; + } + DefWindowProcW(hwnd, msg, wp, lp) +} + +/// Das Tray-Symbol aufsetzen: ein unsichtbares Fenster als Empfaenger, dann Shell_NotifyIcon. +unsafe fn tray_aufsetzen(icon: Hicon) -> Option { + let hinst = GetModuleHandleW(null()); + let klasse = utf16z("PokerfreakTray"); + if !KLASSE_DA.swap(true, Ordering::SeqCst) { + let mut wc: WNDCLASSW = zeroed(); + wc.lpfnWndProc = Some(tray_proc); + wc.hInstance = hinst; + wc.lpszClassName = klasse.as_ptr(); + RegisterClassW(&wc); + } + let hwnd = CreateWindowExW( + 0, + klasse.as_ptr(), + utf16z("Pokerfreak Tray").as_ptr(), + WS_POPUP, + 0, + 0, + 0, + 0, + null_mut(), + null_mut(), + hinst, + null_mut(), + ); + if hwnd.is_null() { + return None; + } + let mut nid: NOTIFYICONDATAW = zeroed(); + nid.cbSize = size_of::() as u32; + nid.hWnd = hwnd; + nid.uID = 1; + nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + nid.uCallbackMessage = WM_TRAY; + nid.hIcon = icon; + let tip = utf16z("Pokerfreak Cockpit"); + for (i, ch) in tip.iter().take(127).enumerate() { + nid.szTip[i] = *ch; + } + Shell_NotifyIconW(NIM_ADD, &nid); + Some(hwnd) +} + +/// Das Tray-Symbol wieder entfernen und das unsichtbare Fenster schliessen. +unsafe fn tray_weg(tray: Hwnd) { + let mut nid: NOTIFYICONDATAW = zeroed(); + nid.cbSize = size_of::() as u32; + nid.hWnd = tray; + nid.uID = 1; + Shell_NotifyIconW(NIM_DELETE, &nid); + DestroyWindow(tray); +} + +fn hwnd_von(fenster: &slint::Window) -> Option { + let griff = fenster.window_handle(); + match griff.window_handle().ok()?.as_raw() { + RawWindowHandle::Win32(w) => Some(w.hwnd.get() as Hwnd), + _ => None, + } +} + +/// Das Hauptfenster ins Tray schicken (statt in die Taskleiste zu minimieren): einfach verstecken. +/// Das Tray-Symbol bleibt sichtbar; ueber Doppelklick oder "Anzeigen" kommt es zurueck. +pub fn minimieren(fenster: &slint::Window) { + if let Some(hwnd) = hwnd_von(fenster) { + unsafe { + ShowWindow(hwnd, SW_HIDE); + } + } +} + +/// Lebt, solange das Fenster laeuft: haelt den Timer am Leben und raeumt am Ende das Tray-Symbol weg. +pub struct Schale { + _timer: slint::Timer, +} + +impl Drop for Schale { + fn drop(&mut self) { + let tray = TRAY_HWND.swap(0, Ordering::SeqCst) as Hwnd; + if !tray.is_null() { + unsafe { tray_weg(tray) }; + } + } +} + +/// Die Windows-Schale an ein eben erzeugtes Fenster haengen. Der HWND steht erst, wenn der +/// Fenstermanager das Fenster angelegt hat - laut Slint fruehestens einen Schleifendurchlauf +/// nach `show()`. Darum erst kurz spaeter zugreifen. Das zurueckgegebene `Schale` muss am Leben +/// bleiben, bis das Fenster zu ist (einfach bis zum Ende der Fensterschleife halten). +pub fn einrichten(f: &T) -> Schale { + let schwach = f.as_weak(); + let timer = slint::Timer::default(); + timer.start(slint::TimerMode::SingleShot, std::time::Duration::from_millis(50), move || { + if let Some(f) = schwach.upgrade() { + if let Some(hwnd) = hwnd_von(f.window()) { + mica_auf(hwnd); + HAUPT_HWND.store(hwnd as isize, Ordering::SeqCst); + unsafe { + // Die Icons leben bewusst bis Prozessende (ein Symbol fuer die ganze App). + let gross = icon_bauen(32); + let klein = icon_bauen(16); + icon_setzen(hwnd, gross, klein); + if let Some(tray) = tray_aufsetzen(klein) { + TRAY_HWND.store(tray as isize, Ordering::SeqCst); + } + } + } + } + }); + Schale { _timer: timer } +} diff --git a/cockpit/ui/bausteine.slint b/cockpit/ui/bausteine.slint index df1db026..2d829de3 100644 --- a/cockpit/ui/bausteine.slint +++ b/cockpit/ui/bausteine.slint @@ -2,21 +2,50 @@ // Grundbausteine. Nichts hier kennt Poker; die Inhalte stehen in cash.slint und fenster.slint. // Masse und Farben sind aus einem Screenshot der Mac-App abgelesen (Radius 12, Karten #22252b ...). +// Fluent-Dark-Tokens (Windows 11). Die Flaechen sind TRANSLUZENTE Weiss-Schleier, damit der +// Mica-Hintergrund durchscheint; scheint er nicht durch (Software-Renderer), sitzen dieselben +// Schleier auf dem deckenden Grund #202020 und lesen genauso. Keine Apple-Nahschwarz-Hex mehr. export global Farbe { - out property grund: #16181c; - out property karte: #22252b; - out property feld: #2a2e35; // Auswahl, kleine Knoepfe auf Karten - out property knopf: #2f333b; // der Hauptknopf - out property linie: #ffffff14; - out property text: #e8eaed; - out property hell: #c7cbd1; - out property gedaempft: #8a8f98; - out property rot: #e5484d; // Echtgeld, Not-Aus - out property blau: #2d6cdf; // ausgewaehlt - out property blau-hell: #4f8cf0; // Werte, Icon der aktiven Karte - out property teal: #3fb98f; // Schalter, aktiver Reiter, Zuschauer - out property gruen: #57c78a; - out property bernstein: #e3b341; + // Deckender Ersatzgrund, wenn Mica nicht durchscheint (Win11 Mica-Fallback SolidBackground #202020). + out property grund: #202020; + + // Fluent-Textrampe dunkel: primaer 100 %, sekundaer 78.6 %, tertiaer 54.4 %, gesperrt 36.4 %. + out property text: #ffffff; + out property text2: #ffffffc9; + out property text3: #ffffff8b; + out property text-aus: #ffffff5d; + // Alte Namen, auf die Rampe gelegt, damit der Inhalt unveraendert bleibt. + out property hell: #ffffffc9; // = sekundaerer Text + out property gedaempft: #ffffff8b; // = tertiaerer Text + + // Schichten ueber Mica: zarte, transluzente Fuellungen + feine Striche (Fluent Layer/Card/Control). + out property karte: #ffffff0d; // CardBackgroundFillColorDefault ~5 % + out property karte-stark: #ffffff17; // gehobene/aktive Karte + out property feld: #ffffff10; // ControlFillColorDefault ~6 % + out property feld-schwebe: #ffffff17; // ControlFillColorSecondary (Hover) + out property feld-druck: #ffffff0a; // ControlFillColorTertiary (Pressed) + out property knopf: #ffffff10; // Hauptknopf: Fluent-Control-Fuellung + out property strich: #ffffff14; // ControlStrokeColorDefault + out property strich-stark: #ffffff9b; // ControlStrongStroke (Toggle-Rand aus) + out property linie: #ffffff12; // Card-Stroke / Trennlinien ~7 % + + // Zustandsschleier fuer Flaechen ohne eigene Fuellung. + out property schwebe: #ffffff14; // Hover + out property druck: #ffffff0a; // Pressed (Flaeche tritt zurueck) + + // Akzent (Win11): heller Akzent fuer Indikator/Fokus/Werte, #0078D4-Familie fuer Fuellungen. + out property akzent: #60cdff; + out property akzent-fuell: #0078d4; + // Alte Namen -> Akzent (kein macOS-Blau/Teal mehr). + out property blau: #0078d4; // Auswahl-/Primaerfuellung + out property blau-hell: #60cdff; // Werte, Icon der aktiven Karte + out property teal: #60cdff; // aktiver Reiter / Zuschauer / Schalter + + // Semantik: Echtgeld / Not-Aus (Win11-Rot-Familie), Meldungen gruen/bernstein. + out property rot: #c42b1c; + out property rot-hell: #e8605a; + out property gruen: #6ccb5a; + out property bernstein: #fce100; } // ---- Zeichen ------------------------------------------------------------------------------- @@ -69,6 +98,11 @@ export component Icon inherits Rectangle { if art == "minus": Strich { width: parent.width; height: parent.height; f: farbe; d: 2.4; commands: "M 5 12 H 19"; } if art == "x": Strich { width: parent.width; height: parent.height; f: farbe; commands: "M 6 6 L 18 18 M 18 6 L 6 18"; } if art == "klein": Strich { width: parent.width; height: parent.height; f: farbe; commands: "M 5 12 H 19"; } + // Windows-Fenstertasten: duenne, kantige Zeichen wie in Segoe Fluent Icons. + if art == "f-min": Strich { width: parent.width; height: parent.height; f: farbe; d: 1.2; commands: "M 5 12 H 19"; } + if art == "f-max": Strich { width: parent.width; height: parent.height; f: farbe; d: 1.2; commands: "M 6.5 6.5 H 17.5 V 17.5 H 6.5 Z"; } + if art == "f-restore": Strich { width: parent.width; height: parent.height; f: farbe; d: 1.2; commands: "M 6.5 9.5 H 14.5 V 17.5 H 6.5 Z M 9.5 9.5 V 6.5 H 17.5 V 14.5 H 14.5"; } + if art == "f-close": Strich { width: parent.width; height: parent.height; f: farbe; d: 1.2; commands: "M 6.5 6.5 L 17.5 17.5 M 17.5 6.5 L 6.5 17.5"; } if art == "hand": Flaeche { width: parent.width; height: parent.height; f: farbe; commands: "M 6 11 H 21 V 15 A 6 6 0 0 1 15 21 H 12 A 6 6 0 0 1 6 15 Z"; } if art == "hand": Strich { width: parent.width; height: parent.height; f: farbe; d: 3.4; commands: "M 8 11 V 5.5 M 12 10 V 3.5 M 16 10.5 V 5 M 20 12 V 9 M 6 13 L 3.5 10.5"; } if art == "stop": Flaeche { width: parent.width; height: parent.height; f: farbe; commands: "M 6 4 H 18 A 2 2 0 0 1 20 6 V 18 A 2 2 0 0 1 18 20 H 6 A 2 2 0 0 1 4 18 V 6 A 2 2 0 0 1 6 4 Z"; } @@ -89,6 +123,9 @@ export component Icon inherits Rectangle { // ---- Segmentschalter ----------------------------------------------------------------------- // Die Kapsel "Zuschauer | Übung | Echtgeld": das gewaehlte Segment ist in seiner Farbe gefuellt. +// WinUI-SelectorBar: eine schlichte Reihe, das gewaehlte Item traegt unten einen kurzen +// Akzent-Indikator (Farbe des Items - Echtgeld bleibt rot), Hover ist ein zarter Schleier. +// KEINE grosse gefuellte Kapsel mehr (das war der macOS/iOS-Segmentschalter). export component Segmentschalter inherits Rectangle { in property <[string]> titel; in property <[color]> farben; @@ -96,24 +133,34 @@ export component Segmentschalter inherits Rectangle { in property gesperrt: false; callback gewaehlt(int); - height: 40px; - border-radius: self.height / 2; - background: #ffffff12; + height: 36px; opacity: gesperrt ? 0.55 : 1; HorizontalLayout { - padding: 3px; - spacing: 0px; + spacing: 2px; for t[i] in titel: Rectangle { - border-radius: (root.height - 6px) / 2; - background: i == root.aktuell ? root.farben[i] : transparent; + border-radius: 4px; + background: seg.pressed ? Farbe.feld-druck : seg.has-hover ? Farbe.schwebe : transparent; + animate background { duration: 100ms; } Text { text: t; - color: i == root.aktuell ? white : Farbe.gedaempft; + color: i == root.aktuell ? Farbe.text : (seg.has-hover ? Farbe.text2 : Farbe.text3); font-size: 14px; - font-weight: i == root.aktuell ? 700 : 600; + font-weight: i == root.aktuell ? 600 : 400; + horizontal-alignment: center; + vertical-alignment: center; } - TouchArea { + // Akzent-Indikator unten mittig, nur am gewaehlten Item. + Rectangle { + x: (parent.width - self.width) / 2; + y: parent.height - 4px; + width: 16px; + height: 2.5px; + border-radius: 1.25px; + background: i == root.aktuell ? root.farben[i] : transparent; + animate background { duration: 120ms; } + } + seg := TouchArea { enabled: !root.gesperrt; clicked => { root.gewaehlt(i); } } @@ -140,7 +187,9 @@ export component Statuskarte inherits Rectangle { callback angenommen(string); background: Farbe.karte; - border-radius: 12px; + border-radius: 8px; + border-width: 1px; + border-color: Farbe.linie; min-height: 84px; VerticalLayout { @@ -230,8 +279,11 @@ export component Auswahl inherits Rectangle { callback gewaehlt(int); height: 30px; - background: Farbe.feld; - border-radius: 8px; + background: aw.pressed ? Farbe.feld-druck : aw.has-hover ? Farbe.feld-schwebe : Farbe.feld; + border-radius: 4px; + border-width: 1px; + border-color: Farbe.strich; + animate background { duration: 100ms; } HorizontalLayout { padding-left: 10px; @@ -247,14 +299,15 @@ export component Auswahl inherits Rectangle { } Icon { art: "runter"; farbe: Farbe.gedaempft; groesse: 12px; y: (parent.height - self.height) / 2; } } - TouchArea { clicked => { menue.show(); } } + aw := TouchArea { clicked => { menue.show(); } } menue := PopupWindow { x: 0px; y: root.height + 2px; width: max(root.width, root.menue-breite); Rectangle { - background: Farbe.feld; + // Flyout: eigene, fast deckende Flaeche (Mica darf hier nicht durchwaschen). + background: #2c2c2c; border-radius: 8px; border-width: 1px; border-color: Farbe.linie; @@ -262,14 +315,14 @@ export component Auswahl inherits Rectangle { padding: 4px; for o[i] in root.optionen: Rectangle { height: 30px; - border-radius: 6px; - background: ta.has-hover ? #ffffff14 : transparent; + border-radius: 4px; + background: ta.has-hover ? Farbe.schwebe : transparent; Text { x: 8px; text: o; - color: i == root.index ? Farbe.blau-hell : Farbe.text; + color: i == root.index ? Farbe.akzent : Farbe.text; font-size: 13px; - font-weight: i == root.index ? 700 : 400; + font-weight: i == root.index ? 600 : 400; vertical-alignment: center; } ta := TouchArea { clicked => { root.gewaehlt(i); menue.close(); } } @@ -303,7 +356,9 @@ export component Stepper inherits Rectangle { Rectangle { width: 26px; background: Farbe.feld; - border-radius: 8px; + border-radius: 4px; + border-width: 1px; + border-color: Farbe.strich; VerticalLayout { Rectangle { opacity: root.auf-ok ? 1 : 0.3; @@ -322,26 +377,34 @@ export component Stepper inherits Rectangle { // ---- Toggle -------------------------------------------------------------------------------- +// Win11 ToggleSwitch: aus = transparent mit 1px-Rand und gedaempftem Knauf; an = Akzent-Fuellung +// mit weissem Knauf. 40x20 mit kleinem 12px-Knauf (nicht die macOS-Pille). export component Toggle inherits Rectangle { in property an; callback umgeschaltet(); - width: 42px; - height: 24px; - border-radius: 12px; - background: an ? Farbe.teal : #3a3e46; - animate background { duration: 120ms; } + width: 40px; + height: 20px; + border-radius: 10px; + background: an ? Farbe.akzent-fuell : transparent; + border-width: an ? 0px : 1px; + border-color: Farbe.strich-stark; + animate background { duration: 150ms; } Rectangle { - y: 2px; - x: root.an ? root.width - self.width - 2px : 2px; - width: 20px; - height: 20px; - border-radius: 10px; - background: white; - animate x { duration: 120ms; } + y: (parent.height - self.height) / 2; + x: root.an ? root.width - self.width - 4px : 4px; + width: 12px; + height: 12px; + border-radius: 6px; + background: root.an ? white : Farbe.text2; + animate x { duration: 150ms; } } - TouchArea { clicked => { root.umgeschaltet(); } } + ta := TouchArea { clicked => { root.umgeschaltet(); } } + + states [ + schwebt when ta.has-hover && !root.an: { border-color: Farbe.text3; } + ] } // ---- Formatkarte --------------------------------------------------------------------------- @@ -361,10 +424,10 @@ export component Formatkarte inherits Rectangle { property aktiv: anzahl > 0; height: 56px; - border-radius: 10px; - background: aktiv ? #2d6cdf24 : Farbe.karte; - border-width: 1.5px; - border-color: aktiv ? Farbe.blau : transparent; + border-radius: 8px; + background: aktiv ? #0078d42e : Farbe.karte; + border-width: 1px; + border-color: aktiv ? Farbe.akzent : Farbe.linie; HorizontalLayout { padding-left: 10px; @@ -437,8 +500,8 @@ export component Werkzeugknopf inherits Rectangle { callback geklickt(); height: 52px; - border-radius: 9px; - background: ta.has-hover && aktiv ? #ffffff0d : transparent; + border-radius: 4px; + background: (ta.pressed && aktiv) ? Farbe.feld-druck : (ta.has-hover && aktiv) ? Farbe.schwebe : transparent; opacity: aktiv ? 1 : 0.4; VerticalLayout { diff --git a/cockpit/ui/cash.slint b/cockpit/ui/cash.slint index 57e9de82..22a3cc61 100644 --- a/cockpit/ui/cash.slint +++ b/cockpit/ui/cash.slint @@ -88,7 +88,7 @@ export component CashInhalt inherits VerticalLayout { // 2) Modus-Leiste Segmentschalter { titel: ["Zuschauer", "Übung", "Echtgeld"]; - farben: [Farbe.teal, Farbe.blau, Farbe.rot]; + farben: [Farbe.akzent, Farbe.akzent, Farbe.rot]; aktuell: root.lage.modus; gesperrt: root.lage.modus-gesperrt; gewaehlt(i) => { root.modus-gewaehlt(i); } @@ -96,8 +96,8 @@ export component CashInhalt inherits VerticalLayout { // Rueckfrage, bevor Echtgeld einschaltet (ModusLeiste.swift `LiveFrage`) if root.lage.cash-frage: Rectangle { - background: #e5484d1f; - border-radius: 12px; + background: #c42b1c24; + border-radius: 8px; VerticalLayout { padding: 12px; spacing: 8px; @@ -117,17 +117,21 @@ export component CashInhalt inherits VerticalLayout { spacing: 8px; Rectangle { height: 32px; - border-radius: 8px; - background: Farbe.feld; + border-radius: 4px; + background: abta.pressed ? Farbe.feld-druck : abta.has-hover ? Farbe.feld-schwebe : Farbe.feld; + border-width: 1px; + border-color: Farbe.strich; + animate background { duration: 100ms; } Text { text: "Abbrechen"; color: Farbe.text; font-size: 13px; font-weight: 600; } - TouchArea { clicked => { root.cash-abgebrochen(); } } + abta := TouchArea { clicked => { root.cash-abgebrochen(); } } } Rectangle { height: 32px; - border-radius: 8px; - background: Farbe.rot; + border-radius: 4px; + background: bsta.pressed ? Farbe.rot.darker(0.12) : bsta.has-hover ? Farbe.rot.brighter(0.12) : Farbe.rot; + animate background { duration: 100ms; } Text { text: "Echtgeld einschalten"; color: white; font-size: 13px; font-weight: 700; } - TouchArea { clicked => { root.cash-bestaetigt(); } } + bsta := TouchArea { clicked => { root.cash-bestaetigt(); } } } } } @@ -220,15 +224,18 @@ export component CashInhalt inherits VerticalLayout { Text { text: root.lage.zusammen; color: Farbe.gedaempft; font-size: 12px; vertical-alignment: center; } Rectangle { width: ausw-text.preferred-width + 22px; - border-radius: 12px; - background: root.lage.ausweichen ? Farbe.blau : #ffffff14; + border-radius: 4px; + background: root.lage.ausweichen ? Farbe.akzent-fuell : (awc.has-hover ? Farbe.feld-schwebe : Farbe.feld); + border-width: root.lage.ausweichen ? 0px : 1px; + border-color: Farbe.strich; + animate background { duration: 100ms; } ausw-text := Text { text: "Ausweichen"; color: root.lage.ausweichen ? white : Farbe.hell; font-size: 12px; font-weight: 600; } - TouchArea { clicked => { root.ausweichen-umschalten(); } } + awc := TouchArea { clicked => { root.ausweichen-umschalten(); } } } } if root.lage.ausweichen: HorizontalLayout { @@ -299,9 +306,16 @@ export component CashInhalt inherits VerticalLayout { spacing: 10px; height: 56px; Rectangle { - border-radius: 12px; - background: Farbe.knopf; + border-radius: 4px; + // Fluent: ruhend Farbe.knopf, beim Schweben heller, beim Druecken tritt die Flaeche zurueck. + background: !root.lage.knopf-aktiv ? Farbe.knopf + : kta.pressed ? Farbe.knopf.darker(0.12) + : kta.has-hover ? Farbe.knopf.brighter(0.16) + : Farbe.knopf; + border-width: 1px; + border-color: Farbe.linie; opacity: root.lage.knopf-aktiv ? 1 : 0.55; + animate background { duration: 100ms; } HorizontalLayout { alignment: center; spacing: 8px; @@ -319,28 +333,31 @@ export component CashInhalt inherits VerticalLayout { vertical-alignment: center; } } - TouchArea { enabled: root.lage.knopf-aktiv; clicked => { root.knopf-gedrueckt(); } } + kta := TouchArea { enabled: root.lage.knopf-aktiv; clicked => { root.knopf-gedrueckt(); } } } Rectangle { width: 56px; - border-radius: 28px; + border-radius: 6px; // Not-Aus aktiv: der Knopf loest ihn (gruen, Play); sonst rot mit der Hand. - background: root.lage.not-aus ? #ffffff1a : Farbe.rot; + background: root.lage.not-aus + ? (nta.has-hover ? #ffffff26 : #ffffff1a) + : (nta.pressed ? Farbe.rot.darker(0.12) : nta.has-hover ? Farbe.rot.brighter(0.12) : Farbe.rot); border-width: 1px; border-color: root.lage.not-aus ? Farbe.gruen : #ffffff59; + animate background { duration: 100ms; } Icon { art: root.lage.not-aus ? "play" : "hand"; farbe: root.lage.not-aus ? Farbe.gruen : white; groesse: 26px; } - TouchArea { clicked => { root.not-aus(); } } + nta := TouchArea { clicked => { root.not-aus(); } } } } // 9) Werkzeugleiste Rectangle { height: 60px; - border-radius: 12px; + border-radius: 8px; background: Farbe.karte; HorizontalLayout { padding: 4px; diff --git a/cockpit/ui/fenster.slint b/cockpit/ui/fenster.slint index 0f07ee3b..0b0c8013 100644 --- a/cockpit/ui/fenster.slint +++ b/cockpit/ui/fenster.slint @@ -19,33 +19,64 @@ component Platzhalter inherits Rectangle { } } -// Ein kleiner Knopf im Fensterchrome (Minimieren, Schliessen, Einstellungen). +// Ein kleiner App-Knopf in der Titelzeile (hier das Zahnrad): Win11-Rundung, zartes Hover. component Chromeknopf inherits Rectangle { in property art; in property farbe: Farbe.gedaempft; callback geklickt(); - width: 28px; - height: 28px; - border-radius: 14px; - background: ta.has-hover ? #ffffff14 : transparent; - Icon { art: root.art; farbe: root.farbe; groesse: 16px; } + width: 32px; + height: 32px; + border-radius: 6px; + background: ta.pressed ? Farbe.druck : ta.has-hover ? Farbe.schwebe : transparent; + animate background { duration: 90ms; } + Icon { art: root.art; farbe: ta.has-hover ? Farbe.text : root.farbe; groesse: 16px; } + ta := TouchArea { clicked => { root.geklickt(); } } +} + +// Eine Windows-Fenstertaste (Minimieren / Maximieren / Schliessen): hohe, randlose Flaeche +// rechtsbuendig, Win11-Hover (grau; beim Schliessen rot mit weissem Zeichen). +component Fenstertaste inherits Rectangle { + in property art; + in property ist-schliessen: false; + callback geklickt(); + width: 46px; + background: ta.pressed + ? (root.ist-schliessen ? #b21d26 : Farbe.druck) + : ta.has-hover + ? (root.ist-schliessen ? #c42b1c : Farbe.schwebe) + : transparent; + animate background { duration: 80ms; } + Icon { + art: root.art; + groesse: 10px; + farbe: (root.ist-schliessen && ta.has-hover) ? #ffffff : Farbe.hell; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + } ta := TouchArea { clicked => { root.geklickt(); } } } export component Cockpit inherits Window { title: "Pokerfreak Cockpit"; no-frame: true; + // Segoe UI Variable als durchgaengige Schrift - das groesste "Win11-nativ"-Signal. + // Auf dem Mac fehlt die Familie und Slint faellt sauber auf die Systemschrift zurueck. + default-font-family: "Segoe UI Variable"; preferred-width: 440px; preferred-height: 900px; min-width: 380px; min-height: 520px; - background: Farbe.grund; + // Durchscheinend (echtes Mica) nur, wenn die Windows-Schale den GPU-Renderer bekommen hat; + // sonst ein ehrlich deckender Fluent-Dunkelgrund. Siehe bruecke::backdrop_moeglich. + background: root.durchscheinend ? transparent : Farbe.grund; in property lage <=> cash.lage; in property <[KartenZeile]> karten <=> cash.karten; in-out property budget-feld <=> cash.budget-feld; in-out property budget-tippt <=> cash.budget-tippt; in-out property reiter: 0; + in-out property maximiert: false; + in-out property durchscheinend: false; callback modus-gewaehlt <=> cash.modus-gewaehlt; callback cash-bestaetigt <=> cash.cash-bestaetigt; @@ -70,32 +101,55 @@ export component Cockpit inherits Window { callback reiter-gewaehlt(int); callback einstellungen(); callback minimieren(); + callback maximieren(); callback schliessen(); callback ziehen(length, length); // Der Schimmer oben: weinrot in Echtgeld und bei Not-Aus, sonst ein kuehles Blau. + // Durchscheinend: eine transluzente Toenung ueber Mica, die nach unten klar wird. Rectangle { y: 0px; height: 180px; - background: @linear-gradient(180deg, (root.lage.cash || root.lage.not-aus) ? #3b2026 : #1b2638 0%, Farbe.grund 100%); + background: root.durchscheinend + ? @linear-gradient(180deg, (root.lage.cash || root.lage.not-aus) ? #3b2026cc : #1b2638cc 0%, #00000000 100%) + : @linear-gradient(180deg, (root.lage.cash || root.lage.not-aus) ? #3b2026 : #1b2638 0%, Farbe.grund 100%); } VerticalLayout { - // 1) Kopfzeile: links der eigene Fensterchrome, rechts das Zahnrad. Der freie Rest zieht das Fenster. + // 1) Titelzeile wie unter Windows 11: links der Fenstertitel, rechts das Zahnrad und die + // Fenstertasten (Minimieren, Maximieren/Wiederherstellen, Schliessen). Der freie Streifen + // zieht das Fenster; die Tasten liegen darueber und fangen ihre Klicks selbst ab. Rectangle { height: 44px; TouchArea { moved => { root.ziehen(self.mouse-x - self.pressed-x, self.mouse-y - self.pressed-y); } } + // Titel links HorizontalLayout { - padding-left: 10px; - padding-right: 10px; - spacing: 2px; - alignment: stretch; - Chromeknopf { art: "klein"; geklickt => { root.minimieren(); } y: (parent.height - self.height) / 2; } - Chromeknopf { art: "x"; geklickt => { root.schliessen(); } y: (parent.height - self.height) / 2; } - Rectangle { } - Chromeknopf { art: "zahnrad"; geklickt => { root.einstellungen(); } y: (parent.height - self.height) / 2; } + alignment: start; + padding-left: 14px; + VerticalLayout { + alignment: center; + Text { + text: "Pokerfreak Cockpit"; + color: Farbe.gedaempft; + font-size: 12px; + font-weight: 600; + } + } + } + // Zahnrad + Fenstertasten rechtsbuendig; die drei Tasten reichen bis in die obere Ecke. + HorizontalLayout { + alignment: end; + spacing: 0px; + VerticalLayout { + alignment: center; + Chromeknopf { art: "zahnrad"; geklickt => { root.einstellungen(); } } + } + Rectangle { width: 6px; } + Fenstertaste { art: "f-min"; geklickt => { root.minimieren(); } } + Fenstertaste { art: root.maximiert ? "f-restore" : "f-max"; geklickt => { root.maximieren(); } } + Fenstertaste { art: "f-close"; ist-schliessen: true; geklickt => { root.schliessen(); } } } }