Skip to content

Commit 4d692ca

Browse files
committed
Cursor boundary colour can now be set to match that of the button it moves to.
1 parent 589d51e commit 4d692ca

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

button.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ namespace user_interface_base {
195195
}
196196

197197
export class Button extends ButtonBase {
198-
private iconId: string | Bitmap
199-
private _ariaId: string
198+
public boundaryColor: number
199+
public state: number[]
200+
public pressable: boolean
200201
public onClick?: (button: Button) => void
201202
public selected: boolean
203+
private iconId: string | Bitmap
204+
private _ariaId: string
202205
private dynamicBoundaryColorsOn: boolean
203-
private boundaryColor: number
204-
public state: number[]
205-
public pressable: boolean
206206

207207
public get ariaId(): string {
208208
return this._ariaId
@@ -212,14 +212,12 @@ namespace user_interface_base {
212212
this._ariaId = value
213213
}
214214

215-
216215
get getLocalX() { return this.xfrm.localPos.x }
217216
get getLocalY() { return this.xfrm.localPos.y }
218217

219218
set setLocalX(x: number) { this.xfrm.localPos.x = x }
220219
set setLocalY(y: number) { this.xfrm.localPos.y = y }
221220

222-
223221
reportAria(force = false) {
224222
const msg: accessibility.TileAccessibilityMessage = {
225223
type: "tile",
@@ -274,6 +272,10 @@ namespace user_interface_base {
274272
this.boundaryColor = opts.boundaryColor
275273
}
276274

275+
else {
276+
this.boundaryColor = 0
277+
}
278+
277279
this.state = opts.state
278280
}
279281

cursor.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ namespace user_interface_base {
3838
ariaPos: Vec2
3939
ariaId: string
4040
size: Bounds
41-
borderThickness: number
4241
visible = true
4342

4443
resetOutlineColourOnMove = false
@@ -48,15 +47,16 @@ namespace user_interface_base {
4847
this.xfrm = new Affine()
4948
this.cancelHandlerStack = []
5049
this.moveDest = new Vec2()
51-
this.borderThickness = 3
5250
this.setSize()
5351

5452
this.cursorOutlineColour = DEFAULT_CURSOR_OUTLINE_COLOUR
5553
}
5654

57-
public moveTo(pos: Vec2, ariaId: string, sizeHint: Bounds) {
55+
public moveTo(pos: Vec2, ariaId: string, sizeHint: Bounds, newBoundaryColour?: number) {
5856
if (this.resetOutlineColourOnMove)
5957
this.setOutlineColour(DEFAULT_CURSOR_OUTLINE_COLOUR)
58+
if (newBoundaryColour)
59+
this.setOutlineColour(newBoundaryColour)
6060

6161
this.setSize(sizeHint)
6262
this.moveDest.copyFrom(pos)
@@ -72,7 +72,7 @@ namespace user_interface_base {
7272
public snapTo(x: number, y: number, ariaId: string, sizeHint: Bounds) {
7373
this.setSize(
7474
sizeHint ||
75-
new Bounds({ left: 0, top: 0, width: 16, height: 16 }),
75+
new Bounds({ left: 0, top: 0, width: 16, height: 16 })
7676
)
7777
this.moveDest.x = this.xfrm.localPos.x = x
7878
this.moveDest.y = this.xfrm.localPos.y = y
@@ -86,8 +86,7 @@ namespace user_interface_base {
8686
else this.size = size.clone()
8787
}
8888

89-
public setOutlineColour(colour: number = 9) {
90-
// 9 is the DEFAULT_CURSOR_OUTLINE_COLOUR
89+
public setOutlineColour(colour: number = 9) { // 9 is the DEFAULT_CURSOR_OUTLINE_COLOUR
9190
this.cursorOutlineColour = colour
9291
}
9392

@@ -131,23 +130,19 @@ namespace user_interface_base {
131130
return false
132131
}
133132

134-
public setBorderThickness(thickness: number) {
135-
this.borderThickness = thickness
136-
}
137-
138133
update() {
139134
this.xfrm.localPos.copyFrom(this.moveDest)
140135
}
141136

142137
draw() {
143138
if (!this.visible) return
144139

145-
for (let dist = 1; dist <= this.borderThickness; dist++) {
140+
for (let dist = 1; dist <= 3; dist++) {
146141
Screen.outlineBoundsXfrm(
147142
this.xfrm,
148143
this.size,
149144
dist,
150-
this.cursorOutlineColour,
145+
this.cursorOutlineColour
151146
)
152147
}
153148

@@ -159,11 +154,11 @@ namespace user_interface_base {
159154
const h = font.charHeight
160155
const x = Math.max(
161156
Screen.LEFT_EDGE + 1,
162-
Math.min(Screen.RIGHT_EDGE - 1 - w, pos.x - (w >> 1)),
157+
Math.min(Screen.RIGHT_EDGE - 1 - w, pos.x - (w >> 1))
163158
)
164159
const y = Math.min(
165160
pos.y + (this.size.width >> 1) + (font.charHeight >> 1) + 1,
166-
Screen.BOTTOM_EDGE - 1 - font.charHeight,
161+
Screen.BOTTOM_EDGE - 1 - font.charHeight
167162
)
168163
Screen.fillRect(x - 1, y - 1, w + 1, h + 2, 15)
169164
Screen.print(text, x, y, 1, font)

cursorscene.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ namespace user_interface_base {
5050
this.cursor.moveTo(
5151
target.xfrm.worldPos,
5252
target.ariaId,
53-
target.bounds
53+
target.bounds,
54+
this.navigator.makeCursorButtonBoundaryColor() ? target.boundaryColor : undefined
5455
)
5556
}
5657

navigator.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace user_interface_base {
99
screenToButton: (x: number, y: number) => Button
1010
initialCursor: (row: number, col: number) => Button
1111
updateAria: () => void
12-
drawComponents(): void;
12+
drawComponents(): void
13+
makeCursorButtonBoundaryColor(): boolean
1314
}
1415

1516
export const BACK_BUTTON_ERROR_KIND = "back_button"
@@ -47,6 +48,10 @@ namespace user_interface_base {
4748
this.buttonGroups.push(btns)
4849
}
4950

51+
public makeCursorButtonBoundaryColor() {
52+
return false;
53+
}
54+
5055
/**
5156
* Append a col during runtime.
5257
* Does not need to be the same size as the grid height
@@ -175,8 +180,9 @@ namespace user_interface_base {
175180
export class GridNavigator extends RowNavigator {
176181
private height: number;
177182
private widths: number[];
183+
private cursorColorIsButtonColor: boolean;
178184

179-
constructor(btns?: Button[][]) {
185+
constructor(btns?: Button[][], cursorColorIsButtonColor: boolean = false) {
180186
super()
181187

182188
if (btns) {
@@ -187,6 +193,13 @@ namespace user_interface_base {
187193
this.height = 0;
188194
this.widths = []
189195
}
196+
197+
this.cursorColorIsButtonColor = cursorColorIsButtonColor;
198+
}
199+
200+
201+
public isCursorColorIsButtonColor() {
202+
return this.cursorColorIsButtonColor;
190203
}
191204

192205
public setBtns(btns: Button[][]) {
@@ -304,6 +317,9 @@ namespace user_interface_base {
304317
public addRow(btns: Button[]) { }
305318
public addCol(btns: Button[]) { }
306319

320+
public makeCursorButtonBoundaryColor() {
321+
return false;
322+
}
307323

308324
moveToIndex(index: number) {
309325
control.assert(index < this.length, "index out of bounds")

0 commit comments

Comments
 (0)