Line data Source code
1 : package hud
2 :
3 : import (
4 : "image"
5 :
6 : text "github.com/hajimehoshi/ebiten/v2/text/v2"
7 :
8 : "github.com/kijimaD/ruins/internal/widgets/theme"
9 : "github.com/kijimaD/ruins/internal/widgets/uicore"
10 : )
11 :
12 : // 画面右上へ置く情報パネルの寸法
13 : const (
14 : infoPanelWidth = 300 // パネルの幅
15 : infoPanelMargin = 10 // 画面端との余白
16 : infoPanelPad = 10 // パネル内側の余白
17 : // LineH は世界の上に重ねるパネルに置く本文1行の高さ。ログ領域も同じ値を使い、行送りを揃える
18 : LineH = 20
19 : )
20 :
21 : // InfoPanel は画面の右上へ置く情報パネル。パネルの意匠を敷き、行を上から順に書き足す。
22 : // 見回しや射撃のように、ゲーム世界の上へ一時的に情報を出す画面で使う。
23 : type InfoPanel struct {
24 : cv uicore.Canvas
25 : face text.Face
26 : rect image.Rectangle
27 : y int // 次に書き込む行の上端
28 : }
29 :
30 : // NewInfoPanel は高さ height のパネルを画面右上へ敷き、書き込み位置を先頭に置く。単一固定パネルなので
31 : // 右上座標を直に求める。行はパネル矩形を基準に上から書き足す。
32 : func NewInfoPanel(cv uicore.Canvas, chrome Chrome, face text.Face, screenWidth, height int) *InfoPanel {
33 1 : x := screenWidth - infoPanelWidth - infoPanelMargin
34 1 : rect := image.Rect(x, infoPanelMargin, x+infoPanelWidth, infoPanelMargin+height)
35 1 : chrome.Panel(cv, rect)
36 1 : return &InfoPanel{
37 1 : cv: cv,
38 1 : face: face,
39 1 : rect: rect,
40 1 : y: rect.Min.Y + infoPanelPad,
41 1 : }
42 : }
43 :
44 : // Line は1行書き、書き込み位置を1行ぶん送る。
45 : func (p *InfoPanel) Line(s string) {
46 1 : p.cv.DrawText(image.Pt(p.rect.Min.X+infoPanelPad, p.y), s, p.face, theme.TextPrimary)
47 1 : p.y += LineH
48 1 : }
49 :
50 : // Gap は書き込み位置を px ぶん送る。段落の切れ目に使う。
51 1 : func (p *InfoPanel) Gap(px int) { p.y += px }
52 :
53 : // SeekBottom は書き込み位置をパネル下端から fromBottom だけ上へ移す。
54 : // 操作説明のように、内容の量によらず下端に置きたい行に使う。
55 1 : func (p *InfoPanel) SeekBottom(fromBottom int) { p.y = p.rect.Max.Y - fromBottom }
|