LCOV - code coverage report
Current view: top level - resources - ui.go Coverage Total Hit
Test: coverage.lcov Lines: 74.1 % 54 40
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package resources
       2              : 
       3              : import (
       4              :         "github.com/hajimehoshi/ebiten/v2"
       5              :         "github.com/hajimehoshi/ebiten/v2/text/v2"
       6              : )
       7              : 
       8              : // UIResources はUIリソースを管理する。フォントのフェイスと、直接描画で使う素材画像を持つ。
       9              : // ウィジェットの組み立ては uicore のツリーが担うので、ここは描画の土台になる
      10              : // フェイスと画像だけを提供する
      11              : type UIResources struct {
      12              :         Fonts *fonts
      13              : 
      14              :         GradientLine *ebiten.Image
      15              :         GaugeFill    *ebiten.Image
      16              : 
      17              :         // 9スライスで描く UI テクスチャ。窓・タイトルバー・入力枠・選択バー・パネルの背景に使う。
      18              :         // plain な *ebiten.Image なので外部ライブラリに依存しない
      19              :         WindowBG     *NineSliceTex
      20              :         PanelBG      *NineSliceTex
      21              :         TitleBar     *NineSliceTex
      22              :         InputBG      *NineSliceTex
      23              :         SelectionBar *NineSliceTex
      24              : 
      25              :         Text *TextResources
      26              : }
      27              : 
      28              : // NineSliceTex は9スライス描画のためのテクスチャと分割幅。BX・BY はソースの左中右・上中下の幅。
      29              : type NineSliceTex struct {
      30              :         Image *ebiten.Image
      31              :         BX    [3]int
      32              :         BY    [3]int
      33              : }
      34              : 
      35              : // TextResources はテキスト描画に使うフェイス一式を管理する
      36              : type TextResources struct {
      37              :         SmallFace text.Face
      38              :         BodyFace  text.Face
      39              :         // KeycapFace はキーキャップの箱に描くグリフ専用のフェイス。本文よりひと回り大きい。
      40              :         // 大きいフェイスは行の高さも広げるため、通常の本文には使わないこと
      41              :         KeycapFace     text.Face
      42              :         TitleFontFace  text.Face
      43              :         SplashFontFace text.Face
      44              : }
      45              : 
      46              : // NewUIResources は新しいUIリソースを作成する。フォントと直接描画の素材だけを読み込む
      47              : func NewUIResources(sources []*text.GoTextFaceSource) (UIResources, error) {
      48            1 :         fonts, err := loadFonts(sources)
      49            1 :         if err != nil {
      50            1 :                 return UIResources{}, err
      51            1 :         }
      52              : 
      53            1 :         gradientLine, err := newImageFromFile("assets/graphics/gradient-line.png")
      54            1 :         if err != nil {
      55            0 :                 return UIResources{}, err
      56            0 :         }
      57              : 
      58            1 :         gaugeFill, err := newImageFromFile("assets/graphics/gauge-fill.png")
      59            1 :         if err != nil {
      60            0 :                 return UIResources{}, err
      61            0 :         }
      62              : 
      63              :         // 窓・タイトルバー・選択バーは中央サイズから対称に分割する
      64            1 :         windowBG, err := newNineSliceTex("assets/graphics/list-idle-trans.png", 40, 40)
      65            1 :         if err != nil {
      66            0 :                 return UIResources{}, err
      67            0 :         }
      68            1 :         panelBG, err := newNineSliceTex("assets/graphics/panel-idle.png", 40, 40)
      69            1 :         if err != nil {
      70            0 :                 return UIResources{}, err
      71            0 :         }
      72            1 :         titleBar, err := newNineSliceTex("assets/graphics/titlebar-idle.png", 40, 24)
      73            1 :         if err != nil {
      74            0 :                 return UIResources{}, err
      75            0 :         }
      76            1 :         selectionBar, err := newNineSliceTex("assets/graphics/selection-bar.png", 56, 10)
      77            1 :         if err != nil {
      78            0 :                 return UIResources{}, err
      79            0 :         }
      80              :         // 入力枠は左右非対称の分割。枠の飾りを歪ませないよう左右で幅を変える
      81            1 :         inputImg, err := newImageFromFile("assets/graphics/text-input-idle.png")
      82            1 :         if err != nil {
      83            0 :                 return UIResources{}, err
      84            0 :         }
      85            1 :         inputBG := &NineSliceTex{Image: inputImg, BX: [3]int{9, 14, 6}, BY: [3]int{9, 14, 6}}
      86            1 : 
      87            1 :         return UIResources{
      88            1 :                 Fonts: fonts,
      89            1 : 
      90            1 :                 GradientLine: gradientLine,
      91            1 :                 GaugeFill:    gaugeFill,
      92            1 : 
      93            1 :                 WindowBG:     windowBG,
      94            1 :                 PanelBG:      panelBG,
      95            1 :                 TitleBar:     titleBar,
      96            1 :                 InputBG:      inputBG,
      97            1 :                 SelectionBar: selectionBar,
      98            1 : 
      99            1 :                 Text: &TextResources{
     100            1 :                         SmallFace:      fonts.smallFace,
     101            1 :                         BodyFace:       fonts.bodyFace,
     102            1 :                         KeycapFace:     fonts.keycapFace,
     103            1 :                         TitleFontFace:  fonts.titleFontFace,
     104            1 :                         SplashFontFace: fonts.splashFontFace,
     105            1 :                 },
     106            1 :         }, nil
     107              : }
        

Generated by: LCOV version 2.0-1