@@ -20,51 +20,24 @@ internal interface TextCanvas {
20
20
}
21
21
22
22
internal class TextSurface (
23
- initialWidth : Int ,
24
- initialHeight : Int ,
23
+ override val width : Int ,
24
+ override val height : Int ,
25
25
) : TextCanvas {
26
- private var realWidth: Int = initialWidth
27
- private var realHeight: Int = initialHeight
28
-
29
- override val width: Int get() = realWidth
30
- override val height: Int get() = realHeight
31
26
32
27
override var translationX = 0
33
28
override var translationY = 0
34
29
35
- private val rows = MutableList (height) { createBlankRow (width) }
30
+ private val rows = Array (height) { Array (width) { newBlankPixel } }
36
31
37
32
override operator fun get (row : Int , column : Int ): TextPixel {
38
33
val x = translationX + column
39
34
val y = translationY + row
40
- if (x < 0 || y < 0 ) {
35
+ if (x >= width || y >= height || x < 0 || y < 0 ) {
41
36
return reusableDirtyPixel
42
37
}
43
- val widthDiff = x - width + 1
44
- if (widthDiff > 0 ) {
45
- if (widthDiff == 1 ) {
46
- rows.forEach { it.add(newBlankPixel) }
47
- } else {
48
- rows.forEach { it.addAll(createBlankRow(widthDiff)) }
49
- }
50
- realWidth + = widthDiff
51
- }
52
- val heightDiff = y - height + 1
53
- if (heightDiff > 0 ) {
54
- if (heightDiff == 1 ) {
55
- rows.add(createBlankRow(width))
56
- } else {
57
- rows.addAll(MutableList (heightDiff) { createBlankRow(width) })
58
- }
59
- realHeight + = heightDiff
60
- }
61
38
return rows[y][x]
62
39
}
63
40
64
- private inline fun createBlankRow (size : Int ): MutableList <TextPixel > {
65
- return MutableList (size) { newBlankPixel }
66
- }
67
-
68
41
fun appendRowTo (appendable : Appendable , row : Int ) {
69
42
// Reused heap allocation for building ANSI attributes inside the loop.
70
43
val attributes = mutableListOf<Int >()
0 commit comments