@@ -34,36 +34,68 @@ public void updateAtlasValues() {
34
34
35
35
String s = string ;
36
36
37
- for (int i = 0 ; i < n ; i ++) {
38
-
39
- int a = s .charAt (i ) - mapStartChar ;
40
- float row = (a % itemsPerRow ) * texStepX ;
41
- float col = (a / itemsPerRow ) * texStepY ;
42
-
43
- texCoord .bl_x = row ; // A - x
44
- texCoord .bl_y = col ; // A - y
45
- texCoord .br_x = row + texStepX ; // B - x
46
- texCoord .br_y = col ; // B - y
47
- texCoord .tl_x = row ; // C - x
48
- texCoord .tl_y = col + texStepY ; // C - y
49
- texCoord .tr_x = row + texStepX ; // D - x
50
- texCoord .tr_y = col + texStepY ; // D - y
51
-
52
- vertex .bl_x = i * itemWidth ; // A - x
53
- vertex .bl_y = 0 ; // A - y
54
- vertex .bl_z = 0 ; // A - z
55
- vertex .br_x = i * itemWidth + itemWidth ; // B - x
56
- vertex .br_y = 0 ; // B - y
57
- vertex .br_z = 0 ; // B - z
58
- vertex .tl_x = i * itemWidth ; // C - x
59
- vertex .tl_y = itemHeight ; // C - y
60
- vertex .tl_z = 0 ; // C - z
61
- vertex .tr_x = i * itemWidth + itemWidth ; // D - x
62
- vertex .tr_y = itemHeight ; // D - y
63
- vertex .tr_z = 0 ; // D - z
64
-
65
- textureAtlas_ .updateQuad (texCoord , vertex , i );
37
+ int xpos = 0 ;
38
+ int ypos = 0 ;
39
+ int numLines = 1 ;
40
+ int maxLineWidth = 0 ;
41
+
42
+ for (int i = 0 ; i < n ; i ++)
43
+ {
44
+ // If we see a newline, reset the x-position back to zero
45
+ // and update our y-position. Since OpenGL is y=0 bottom,
46
+ // we negate numLines
47
+ if (s .charAt (i ) == '\n' )
48
+ {
49
+ // Keep track of the longest line
50
+ if (xpos > maxLineWidth )
51
+ {
52
+ maxLineWidth = xpos ;
53
+ }
54
+ xpos = 0 ;
55
+ ypos = -numLines * itemHeight ;
56
+ numLines ++;
57
+ }
58
+ else
59
+ {
60
+ int a = s .charAt (i ) - mapStartChar ;
61
+ float row = (a % itemsPerRow ) * texStepX ;
62
+ float col = (a / itemsPerRow ) * texStepY ;
63
+
64
+ texCoord .bl_x = row ; // A - x
65
+ texCoord .bl_y = col ; // A - y
66
+ texCoord .br_x = row + texStepX ; // B - x
67
+ texCoord .br_y = col ; // B - y
68
+ texCoord .tl_x = row ; // C - x
69
+ texCoord .tl_y = col + texStepY ; // C - y
70
+ texCoord .tr_x = row + texStepX ; // D - x
71
+ texCoord .tr_y = col + texStepY ; // D - y
72
+
73
+ vertex .bl_x = xpos * itemWidth ; // A - x
74
+ vertex .bl_y = ypos ; // A - y
75
+ vertex .bl_z = 0 ; // A - z
76
+ vertex .br_x = xpos * itemWidth + itemWidth ; // B - x
77
+ vertex .br_y = ypos ; // B - y
78
+ vertex .br_z = 0 ; // B - z
79
+ vertex .tl_x = xpos * itemWidth ; // C - x
80
+ vertex .tl_y = ypos + itemHeight ; // C - y
81
+ vertex .tl_z = 0 ; // C - z
82
+ vertex .tr_x = xpos * itemWidth + itemWidth ; // D - x
83
+ vertex .tr_y = ypos + itemHeight ; // D - y
84
+ vertex .tr_z = 0 ; // D - z
85
+
86
+ textureAtlas_ .updateQuad (texCoord , vertex , i );
87
+ xpos ++;
88
+ }
66
89
}
90
+
91
+ int numCharsWidth = n ;
92
+ // If this is multi-line, use the max line width instead of the total string length
93
+ if (numLines > 1 )
94
+ {
95
+ numCharsWidth = maxLineWidth ;
96
+ }
97
+
98
+ setContentSize (itemWidth * numCharsWidth , itemHeight * numLines );
67
99
}
68
100
69
101
public void setString (String newString ) {
@@ -82,7 +114,7 @@ public void draw(GL10 gl) {
82
114
gl .glEnable (GL10 .GL_TEXTURE_2D );
83
115
84
116
//fixed bug that can't show text on G1 by zt
85
- // gl.glColor4f(color_.r / 255f, color_.g / 255f, color_.b / 255f, opacity_ / 255f);
117
+ gl .glColor4f (color_ .r / 255f , color_ .g / 255f , color_ .b / 255f , opacity_ / 255f );
86
118
87
119
textureAtlas_ .draw (gl , string .length ());
88
120
0 commit comments