diff --git a/program/SoundWindow.cs b/program/SoundWindow.cs index 0a0ce7f..abef23d 100644 --- a/program/SoundWindow.cs +++ b/program/SoundWindow.cs @@ -2,18 +2,35 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using Gtk; using UI = Gtk.Builder.ObjectAttribute; /// Controller for notebook page 2 (SoundBox). Not a Gtk.Window — same /// arrangement as SettingsWindow: it drives widgets inside the shared root. +/// +/// Design "Mix": +/// level 0 : 種別を選択 title + big icon tiles (one per top-level branch) +/// level 1+ : the same tiles, small, as tabs + a 3-column grid of sounds public class SoundWindow { - [UI] private Label ConditionNameLabel = null; - [UI] private Grid SoundButtonGrid = null; - [UI] private Button SoundBackButton = null; + [UI] private Label ConditionNameLabel = null; + [UI] private Grid SoundButtonGrid = null; + [UI] private Button SoundBackButton = null; + // NEW — optional, so an older glade without them still loads + [UI] private Box SoundTabBox = null; + [UI] private Label SoundSubtitleLabel = null; - private const int Columns = 2; + private const int TopColumns = 2; // big tiles on level 0 + private const int ListColumns = 3; // sound grid on level 1+ + private const int ListRowsFit = 7; // more rows than this -> compact buttons + private const int TopTileHeight = 400; + + // "fine crackle(捻髪音)" -> main "捻髪音", sub "fine crackle" + private static readonly Regex NameRx = new Regex(@"^(.*?)\((.*)\)\s*$", RegexOptions.Compiled); + + // Subtitle per branch index (same index rule as the lung/heart colours) + private static readonly string[] BranchSubtitles = { "Breath sounds", "Heart sounds" }; private readonly List _allCases; private readonly List _path = new List(); @@ -38,6 +55,7 @@ ConditionNameLabel.Name = "ConditionNameLabel"; SoundButtonGrid.Name = "SoundButtonGrid"; SoundBackButton.Name = "SoundBackButton"; + if (SoundSubtitleLabel != null) SoundSubtitleLabel.Name = "SoundSubtitleLabel"; Console.WriteLine("SoundWindow ctor: AppMode.Legacy = " + AppMode.Legacy); _allCases = AppMode.Legacy @@ -78,9 +96,7 @@ .Distinct() .ToList(); - ConditionNameLabel.Text = _path.Count == 0 - ? "種別を選択" - : string.Join(" : ", _path); + UpdateHeader(); BuildButtons(options, picked => { @@ -110,6 +126,89 @@ return true; } + // ── header: title on level 0, tile tabs + hint below that ────────── + + private List TopLevel() + { + // Colour by branch index rather than a literal, so renaming or + // translating the CSV's top level doesn't silently turn everything blue. + return _allCases + .Where(c => c.TreePath.Length > 0) + .Select(c => c.TreePath[0]) + .Distinct() + .ToList(); + } + + private int CaseCount(string branch) + { + return _allCases.Count(c => c.TreePath.Length > 0 && + string.Equals(c.TreePath[0], branch, StringComparison.Ordinal)); + } + + private void UpdateHeader() + { + bool top = _path.Count == 0; + var ctx = ConditionNameLabel.StyleContext; + + if (top) + { + ConditionNameLabel.Text = "種別を選択"; + ConditionNameLabel.Xalign = 0; + ctx.RemoveClass("page-hint"); + ctx.AddClass("page-title"); + } + else + { + // The tabs already say 呼吸音 / 心音; show deeper levels as a trail. + ConditionNameLabel.Text = _path.Count == 1 + ? "音源をタッチして開始" + : string.Join(" › ", _path.Skip(1)); + ConditionNameLabel.Xalign = 1; + ctx.RemoveClass("page-title"); + ctx.AddClass("page-hint"); + } + + if (SoundSubtitleLabel != null) SoundSubtitleLabel.Visible = top; + BuildTabs(top); + } + + private void BuildTabs(bool top) + { + if (SoundTabBox == null) return; + + foreach (var child in SoundTabBox.Children) + { + SoundTabBox.Remove(child); + child.Destroy(); + } + + SoundTabBox.Visible = !top; + if (top) return; + + var branches = TopLevel(); + for (int k = 0; k < branches.Count; k++) + { + string branch = branches[k]; + bool active = string.Equals(branch, _path[0], StringComparison.Ordinal); + + var tab = MakeTypeTile(branch, k, active, true); + tab.Clicked += (s, e) => + { + if (_path.Count == 1 && active) return; // already here + _path.Clear(); + _path.Add(branch); + Render(); + }; + // SoundTabBox is no-show-all (so a window-wide ShowAll can't reveal + // it on level 0) — which also makes SoundTabBox.ShowAll() a no-op. + // Show each tab itself instead. + tab.ShowAll(); + SoundTabBox.PackStart(tab, false, false, 0); + } + } + + // ── buttons ──────────────────────────────────────────────────────── + private void BuildButtons(IEnumerable labels, Action onPick) { // MUST be first. Attach() stacks; without this every Render() adds a layer @@ -123,45 +222,148 @@ var list = labels.ToList(); if (list.Count == 0) { SoundButtonGrid.ShowAll(); return; } - bool top = _path.Count == 0; - int rows = (list.Count + Columns - 1) / Columns; - bool compact = !top && rows > 8; + bool top = _path.Count == 0; + var branches = TopLevel(); - // Colour by branch index rather than a literal, so renaming or - // translating the CSV's top level doesn't silently turn everything blue. - var topLevel = _allCases - .Where(c => c.TreePath.Length > 0) - .Select(c => c.TreePath[0]) - .Distinct() - .ToList(); - - int i = 0; - foreach (string text in list) + if (top) { - string captured = text; - var btn = new Button(captured); - btn.Hexpand = true; - btn.Vexpand = false; + // Level 0: big icon tiles, centred vertically. + SoundButtonGrid.Valign = Align.Center; + SoundButtonGrid.ColumnSpacing = 28; + SoundButtonGrid.RowSpacing = 28; - int branchIx = topLevel.IndexOf(top ? captured : _path[0]); + int i = 0; + foreach (string text in list) + { + string captured = text; + var tile = MakeTypeTile(captured, branches.IndexOf(captured), false, false); + tile.HeightRequest = TopTileHeight; + tile.Hexpand = true; + tile.Clicked += (s, e) => onPick(captured); + SoundButtonGrid.Attach(tile, i % TopColumns, i / TopColumns, 1, 1); + i++; + } + } + else + { + // Level 1+: 3-column grid, row by row. + SoundButtonGrid.Valign = Align.Start; + SoundButtonGrid.ColumnSpacing = 10; + SoundButtonGrid.RowSpacing = 10; - var ctx = btn.StyleContext; - ctx.AddClass("sound-clip"); - if (top) ctx.AddClass("top"); - else if (compact) ctx.AddClass("compact"); - if (branchIx == 0) ctx.AddClass("lung"); - else if (branchIx == 1) ctx.AddClass("heart"); + int rows = (list.Count + ListColumns - 1) / ListColumns; + bool compact = rows > ListRowsFit; + int branchIx = branches.IndexOf(_path[0]); - btn.Clicked += (s, e) => onPick(captured); - - // column-major: down the left column, then down the right - SoundButtonGrid.Attach(btn, i / rows, i % rows, 1, 1); - i++; + int i = 0; + foreach (string text in list) + { + string captured = text; + var btn = MakeClipButton(captured, branchIx, compact); + btn.Clicked += (s, e) => onPick(captured); + SoundButtonGrid.Attach(btn, i % ListColumns, i / ListColumns, 1, 1); + i++; + } } SoundButtonGrid.ShowAll(); } + /// Big tile (level 0) or small tab (level 1+): icon + name + subtitle. + private Button MakeTypeTile(string name, int branchIx, bool active, bool small) + { + var btn = new Button(); + var ctx = btn.StyleContext; + ctx.AddClass(small ? "type-tab" : "type-tile"); + if (branchIx == 0) ctx.AddClass("lung"); + else if (branchIx == 1) ctx.AddClass("heart"); + if (active) ctx.AddClass("active"); + + var icon = new SoundIcon(branchIx == 1 ? SoundIcon.Kind.Heart : SoundIcon.Kind.Lungs, + small ? 54 : 140, active); + + string sub = (branchIx >= 0 && branchIx < BranchSubtitles.Length + ? BranchSubtitles[branchIx] + " · " : "") + + CaseCount(name) + " 音源"; + + var title = new Label(name); + title.StyleContext.AddClass("tile-title"); + var subtitle = new Label(sub); + subtitle.StyleContext.AddClass("tile-sub"); + + if (small) + { + title.Xalign = 0; + subtitle.Xalign = 0; + var text = new Box(Orientation.Vertical, 0); + text.Valign = Align.Center; + text.PackStart(title, false, false, 0); + text.PackStart(subtitle, false, false, 0); + + var row = new Box(Orientation.Horizontal, 14); + icon.Valign = Align.Center; + row.PackStart(icon, false, false, 0); + row.PackStart(text, false, false, 0); + btn.Add(row); + } + else + { + var col = new Box(Orientation.Vertical, 18); + col.Halign = Align.Center; + col.Valign = Align.Center; + icon.Halign = Align.Center; + col.PackStart(icon, false, false, 0); + col.PackStart(title, false, false, 0); + col.PackStart(subtitle, false, false, 0); + btn.Add(col); + } + return btn; + } + + /// White card: Japanese name bold on top, English name small below. + private Button MakeClipButton(string text, int branchIx, bool compact) + { + string main = text, sub = null; + var m = NameRx.Match(text); + if (m.Success && m.Groups[2].Value.Trim().Length > 0) + { + main = m.Groups[2].Value.Trim(); + sub = m.Groups[1].Value.Trim(); + } + + var btn = new Button(); + btn.Hexpand = true; + btn.Vexpand = false; + btn.TooltipText = text; + + var ctx = btn.StyleContext; + ctx.AddClass("sound-clip"); + if (compact) ctx.AddClass("compact"); + if (branchIx == 0) ctx.AddClass("lung"); + else if (branchIx == 1) ctx.AddClass("heart"); + + var col = new Box(Orientation.Vertical, 2); + col.Valign = Align.Center; + + var l1 = new Label(main); + l1.Xalign = 0; + l1.Ellipsize = Pango.EllipsizeMode.End; + l1.StyleContext.AddClass("clip-main"); + col.PackStart(l1, false, false, 0); + + if (!string.IsNullOrEmpty(sub)) + { + var l2 = new Label(sub); + l2.Xalign = 0; + l2.Ellipsize = Pango.EllipsizeMode.End; + l2.StyleContext.AddClass("clip-sub"); + col.PackStart(l2, false, false, 0); + } + + btn.Add(col); + return btn; + } + private void Play(CaseDefinition c) { if (c.IsLegacy) @@ -200,46 +402,6 @@ } } - // private void Play(CaseDefinition c) - // { - // if (!AppMode.Legacy && string.IsNullOrWhiteSpace(c.SoundPath)) - // { - // Console.WriteLine("No Sound_File for case " + c.Number); - // return; - // } - - // WavePlayer.Stop(); // the map page owns audio from here on - - // var h = CaseSelected; - // if (h != null) h(this, c); - // // if (string.IsNullOrWhiteSpace(c.SoundPath)) - // // { - // // Console.WriteLine("No Sound_File for case " + c.Number); - // // return; - // // } - - // // WavePlayer.Stop(); // the map page owns audio from here on - - // // var h = CaseSelected; - // // if (h != null) h(this, c); - // // string full = AppMode.ResolveSound(c.SoundPath); - // // if (full == null || !File.Exists(full)) - // // { - // // Console.WriteLine("Sound file missing for case " + c.Number); - // // return; - // // } - - // // string full = AppFile(c.SoundPath); // "sound/SND200.wav" -> absolute - // // if (!File.Exists(full)) - // // { - // // Console.WriteLine("Sound file missing: " + full); - // // return; - // // } - - // // ConditionNameLabel.Text = string.Join(" : ", _path); - // // WavePlayer.Play(full); - // } - private void OnBackClicked(object sender, EventArgs e) { if (_path.Count > 0) @@ -253,4 +415,97 @@ if (BackRequested != null) BackRequested(this, EventArgs.Empty); } } +} + +/// Lungs / heart icon in a circle, drawn with Cairo (no image files needed). +/// Inactive: tinted circle + coloured stroke. Active: solid circle + white stroke. +public class SoundIcon : DrawingArea +{ + public enum Kind { Lungs, Heart } + + private readonly Kind _kind; + private readonly bool _active; + + public SoundIcon(Kind kind, int size, bool active) + { + _kind = kind; + _active = active; + SetSizeRequest(size, size); + Drawn += OnDrawn; + } + + private void OnDrawn(object o, DrawnArgs args) + { + var cr = args.Cr; + int w = AllocatedWidth, h = AllocatedHeight; + double s = Math.Min(w, h); + + bool heart = _kind == Kind.Heart; + double r = heart ? 0.753 : 0.122, g = heart ? 0.224 : 0.435, b = heart ? 0.169 : 0.698; // #C0392B / #1F6FB2 + + // circle + cr.Arc(w / 2.0, h / 2.0, s / 2.0, 0, 2 * Math.PI); + if (_active) cr.SetSourceRGB(r, g, b); + else if (heart) cr.SetSourceRGB(0.984, 0.906, 0.906); // #FBE7E7 + else cr.SetSourceRGB(0.890, 0.933, 0.976); // #E3EEF9 + cr.Fill(); + + // glyph, authored on a 64x64 grid, scaled to 60% of the circle + double k = s * 0.6 / 64.0; + cr.Save(); + cr.Translate((w - 64 * k) / 2.0, (h - 64 * k) / 2.0); + cr.Scale(k, k); + cr.LineWidth = 3.2; + cr.LineCap = Cairo.LineCap.Round; + cr.LineJoin = Cairo.LineJoin.Round; + if (_active) cr.SetSourceRGB(1, 1, 1); + else cr.SetSourceRGB(r, g, b); + + if (heart) HeartPath(cr); else LungsPath(cr); + cr.Stroke(); + cr.Restore(); + + args.RetVal = true; + } + + private static void LungsPath(Cairo.Context cr) + { + // trachea + bronchi + cr.MoveTo(32, 6); cr.LineTo(32, 28); + cr.MoveTo(32, 28); cr.CurveTo(29, 28, 26, 31, 24, 31); + cr.MoveTo(32, 28); cr.CurveTo(35, 28, 38, 31, 40, 31); + // left lobe + cr.MoveTo(24, 31); + cr.CurveTo(22, 23, 18, 18, 14, 18); + cr.CurveTo(8, 18, 5, 30, 5, 42); + cr.CurveTo(5, 51, 8, 57, 14, 57); + cr.CurveTo(21, 57, 24, 52, 24, 45); + cr.ClosePath(); + // right lobe + cr.MoveTo(40, 31); + cr.CurveTo(42, 23, 46, 18, 50, 18); + cr.CurveTo(56, 18, 59, 30, 59, 42); + cr.CurveTo(59, 51, 56, 57, 50, 57); + cr.CurveTo(43, 57, 40, 52, 40, 45); + cr.ClosePath(); + } + + private static void HeartPath(Cairo.Context cr) + { + cr.MoveTo(32, 54); + cr.CurveTo(32, 54, 8, 40, 8, 22); + cr.CurveTo(8, 14, 14, 9, 20, 9); + cr.CurveTo(25, 9, 29, 12, 32, 16); + cr.CurveTo(35, 12, 39, 9, 44, 9); + cr.CurveTo(50, 9, 56, 14, 56, 22); + cr.CurveTo(56, 40, 32, 54, 32, 54); + cr.ClosePath(); + // ECG trace + cr.MoveTo(14, 30); + cr.LineTo(24, 30); + cr.LineTo(28, 23); + cr.LineTo(34, 37); + cr.LineTo(38, 30); + cr.LineTo(50, 30); + } } \ No newline at end of file diff --git a/program/homepageallv8.glade b/program/homepageallv8.glade index bd25100..ccfe141 100644 --- a/program/homepageallv8.glade +++ b/program/homepageallv8.glade @@ -14,6 +14,11 @@ False media-playback-start-symbolic + + True + False + go-previous-symbolic + False False @@ -385,15 +390,51 @@ + + SoundBox True False vertical + 14 - + True False - label + 16 + + + False + True + False + 16 + + + False + True + 0 + + + + + True + False + True + 0 + end + 種別を選択 + + + True + True + 1 + + False @@ -402,43 +443,43 @@ + + SoundSubtitleLabel + True + True + False + 0 + 学習したい音の種類をタッチしてください + + + False + True + 1 + + + True True - False - False + True + True never - in + none True False + none - True False - 6 - 6 + 10 + 10 True - - - - - - - - - - - - - - - @@ -447,23 +488,25 @@ True True - 1 + 2 + 戻る True True True end - True - right + SoundBackIcon + left + True False True - 4 + 3 diff --git a/program/touch_friendly.css b/program/touch_friendly.css index 51cfba3..7e30042 100644 --- a/program/touch_friendly.css +++ b/program/touch_friendly.css @@ -39,16 +39,7 @@ min-width: 0; } -/* ---------- navy title banner ---------- */ -#ConditionNameLabel { - font-family: 'Noto Sans JP', 'IPAPGothic', sans-serif; - font-size: 46px; - font-weight: 700; - color: #ffffff; - background-color: #0B3B6B; - padding: 10px 26px; - margin: 14px 40px 24px 40px; -} +/* #ConditionNameLabel is styled in the SOUND PAGE section below. */ /* ---------- splash / main menu ---------- */ #Option1Button, #Option2Button, #Option3Button { @@ -75,32 +66,122 @@ #LanguageToggle:checked label { color: #ffffff; } /* ---------- back buttons ---------- */ -/* MapBackButton is styled in the MAP PAGE section (red, under 解説を見る). */ -#SoundBackButton, #SettingBackButton { +/* MapBackButton and SoundBackButton are styled in their page sections + (red, bottom-right). */ +#SettingBackButton { min-width: 100px; min-height: 58px; background-color: #F0F0F0; border: 2px solid #B5B5B5; } -#SoundBackButton label, #SettingBackButton label { - font-size: 20px; - color: #111111; -} -#SoundBackButton:hover, #SettingBackButton:hover { - background-color: #E2E2E2; +#SettingBackButton label { font-size: 20px; color: #111111; } +#SettingBackButton:hover { background-color: #E2E2E2; } + +/* ══════════════════════════════════════════════════════════════════ + SOUND PAGE — design "Mix" (icon tiles → tile tabs + 3-column grid) + Classes come from SoundWindow.cs: type-tile, type-tab, active, + lung, heart, sound-clip, compact, clip-main, clip-sub, + tile-title, tile-sub, page-title, page-hint. + ══════════════════════════════════════════════════════════════════ */ + +#SoundBox { + background-color: rgba(239, 234, 224, 0.92); + padding: 22px 40px 20px 40px; } -/* ---------- dynamic sound-list buttons ---------- */ -.sound-clip { min-height: 74px; background-color: #3592C8; } -.sound-clip label { font-size: 20px; color: #ffffff; } -.sound-clip.heart { background-color: #CE3733; } -.sound-clip.lung { background-color: #3592C8; } +/* title on level 0, quiet hint on the list levels */ +#ConditionNameLabel { + font-family: 'Noto Sans JP', 'IPAPGothic', sans-serif; + font-size: 40px; + font-weight: 900; + color: #1E2430; + background-color: transparent; + padding: 0; + margin: 0; +} +#ConditionNameLabel.page-hint { + font-size: 17px; + font-weight: 400; + color: #5E636D; +} +#SoundSubtitleLabel { + font-family: 'Noto Sans JP', 'IPAPGothic', sans-serif; + font-size: 18px; + color: #5E636D; +} -.sound-clip.compact { min-height: 52px; } -.sound-clip.compact label { font-size: 19px; } +/* ── level 0: big icon tiles ── */ +button.type-tile { + background-color: #FFFFFF; + background-image: none; + border: 1px solid #E2DDD2; + border-radius: 20px; + box-shadow: 0 2px 8px rgba(30, 36, 48, 0.08); + outline-style: none; +} +button.type-tile:hover { background-color: #FAF8F4; } +button.type-tile:active { background-color: #F1EEE8; } +button.type-tile label.tile-title { font-size: 48px; font-weight: 900; color: #1E2430; } +button.type-tile label.tile-sub { font-size: 18px; font-weight: 400; color: #5E636D; } -.sound-clip.top { min-height: 112px; } -.sound-clip.top label { font-size: 34px; } +/* ── level 1+: the same tiles, small, as tabs ── */ +button.type-tab { + min-height: 80px; + min-width: 300px; + padding: 0 18px 0 12px; + background-color: #FFFFFF; + background-image: none; + border: 1.5px solid #E2DDD2; + border-radius: 16px; + box-shadow: none; + outline-style: none; +} +button.type-tab:hover { background-color: #FAF8F4; } +button.type-tab label.tile-title { font-size: 26px; font-weight: 700; color: #1E2430; } +button.type-tab label.tile-sub { font-size: 14px; font-weight: 400; color: #6B6F78; } + +button.type-tab.active.lung { background-color: #F2F7FC; border: 2.5px solid #1F6FB2; } +button.type-tab.active.heart { background-color: #FDF3F3; border: 2.5px solid #C0392B; } +button.type-tab.active.lung label.tile-title { color: #0F4C85; font-weight: 900; } +button.type-tab.active.heart label.tile-title { color: #9B2A20; font-weight: 900; } + +/* ── sound buttons: white cards, Japanese name bold, English below ── */ +.sound-clip { + min-height: 72px; + padding: 0 18px; + background-color: #FFFFFF; + background-image: none; + border: 1px solid #E2DDD2; + border-radius: 12px; + box-shadow: none; + outline-style: none; +} +.sound-clip:hover { background-color: #F7F5F1; } +.sound-clip:active { background-color: #EDE9E1; } +.sound-clip.lung:active { border-color: #1F6FB2; } +.sound-clip.heart:active { border-color: #C0392B; } +.sound-clip label.clip-main { font-size: 20px; font-weight: 700; color: #1E2430; } +.sound-clip label.clip-sub { font-size: 14px; font-weight: 400; color: #6B6F78; } + +.sound-clip.compact { min-height: 56px; } +.sound-clip.compact label.clip-main { font-size: 18px; } +.sound-clip.compact label.clip-sub { font-size: 13px; } + +/* 戻る — red, bottom-right (matches the map page) */ +#SoundBackButton { + min-height: 60px; + min-width: 130px; + padding: 0 26px 0 18px; + background-color: #C62828; + background-image: none; + border-width: 0; + border-radius: 12px; + outline-style: none; +} +#SoundBackButton label { color: #FFFFFF; font-size: 21px; font-weight: 700; } +#SoundBackButton image { color: #FFFFFF; margin-right: 6px; } +#SoundBackButton:hover { background-color: #D33A3A; } +#SoundBackButton:active { background-color: #A61F1F; } /* ---------- settings page ---------- */ #ConnectButton, #AutoConnectButton, #RefreshButton {