Skip to content

Commit 589d51e

Browse files
authored
Merge pull request #4 from RThom6/main
Added setting cursor border thickness
2 parents f10fe88 + c675685 commit 589d51e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cursor.ts

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

4344
resetOutlineColourOnMove = false
@@ -47,6 +48,7 @@ namespace user_interface_base {
4748
this.xfrm = new Affine()
4849
this.cancelHandlerStack = []
4950
this.moveDest = new Vec2()
51+
this.borderThickness = 3
5052
this.setSize()
5153

5254
this.cursorOutlineColour = DEFAULT_CURSOR_OUTLINE_COLOUR
@@ -70,7 +72,7 @@ namespace user_interface_base {
7072
public snapTo(x: number, y: number, ariaId: string, sizeHint: Bounds) {
7173
this.setSize(
7274
sizeHint ||
73-
new Bounds({ left: 0, top: 0, width: 16, height: 16 })
75+
new Bounds({ left: 0, top: 0, width: 16, height: 16 }),
7476
)
7577
this.moveDest.x = this.xfrm.localPos.x = x
7678
this.moveDest.y = this.xfrm.localPos.y = y
@@ -84,7 +86,8 @@ namespace user_interface_base {
8486
else this.size = size.clone()
8587
}
8688

87-
public setOutlineColour(colour: number = 9) { // 9 is the DEFAULT_CURSOR_OUTLINE_COLOUR
89+
public setOutlineColour(colour: number = 9) {
90+
// 9 is the DEFAULT_CURSOR_OUTLINE_COLOUR
8891
this.cursorOutlineColour = colour
8992
}
9093

@@ -128,19 +131,23 @@ namespace user_interface_base {
128131
return false
129132
}
130133

134+
public setBorderThickness(thickness: number) {
135+
this.borderThickness = thickness
136+
}
137+
131138
update() {
132139
this.xfrm.localPos.copyFrom(this.moveDest)
133140
}
134141

135142
draw() {
136143
if (!this.visible) return
137144

138-
for (let dist = 1; dist <= 3; dist++) {
145+
for (let dist = 1; dist <= this.borderThickness; dist++) {
139146
Screen.outlineBoundsXfrm(
140147
this.xfrm,
141148
this.size,
142149
dist,
143-
this.cursorOutlineColour
150+
this.cursorOutlineColour,
144151
)
145152
}
146153

@@ -152,11 +159,11 @@ namespace user_interface_base {
152159
const h = font.charHeight
153160
const x = Math.max(
154161
Screen.LEFT_EDGE + 1,
155-
Math.min(Screen.RIGHT_EDGE - 1 - w, pos.x - (w >> 1))
162+
Math.min(Screen.RIGHT_EDGE - 1 - w, pos.x - (w >> 1)),
156163
)
157164
const y = Math.min(
158165
pos.y + (this.size.width >> 1) + (font.charHeight >> 1) + 1,
159-
Screen.BOTTOM_EDGE - 1 - font.charHeight
166+
Screen.BOTTOM_EDGE - 1 - font.charHeight,
160167
)
161168
Screen.fillRect(x - 1, y - 1, w + 1, h + 2, 15)
162169
Screen.print(text, x, y, 1, font)

0 commit comments

Comments
 (0)