1
+ /*
2
+ * Copyright (c) 2022 See AUTHORS file.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com .github .tommyettinger .textra ;
18
+
19
+ import com .badlogic .gdx .ApplicationAdapter ;
20
+ import com .badlogic .gdx .Gdx ;
21
+ import com .badlogic .gdx .Input ;
22
+ import com .badlogic .gdx .backends .lwjgl3 .Lwjgl3Application ;
23
+ import com .badlogic .gdx .backends .lwjgl3 .Lwjgl3ApplicationConfiguration ;
24
+ import com .badlogic .gdx .graphics .Color ;
25
+ import com .badlogic .gdx .graphics .g2d .Sprite ;
26
+ import com .badlogic .gdx .scenes .scene2d .Group ;
27
+ import com .badlogic .gdx .scenes .scene2d .Stage ;
28
+ import com .badlogic .gdx .scenes .scene2d .ui .Container ;
29
+ import com .badlogic .gdx .scenes .scene2d .ui .Skin ;
30
+ import com .badlogic .gdx .scenes .scene2d .ui .VerticalGroup ;
31
+ import com .badlogic .gdx .scenes .scene2d .utils .SpriteDrawable ;
32
+ import com .badlogic .gdx .scenes .scene2d .utils .TextureRegionDrawable ;
33
+ import com .badlogic .gdx .utils .Align ;
34
+ import com .badlogic .gdx .utils .ScreenUtils ;
35
+ import com .badlogic .gdx .utils .viewport .ScreenViewport ;
36
+
37
+ public class ForestOMossIssueTest extends ApplicationAdapter {
38
+ ScreenViewport viewport ;
39
+ Stage stage ;
40
+ TypingLabel typingLabel ;
41
+ TypingLabel typingLabel2 ;
42
+ float angle ;
43
+
44
+ @ Override
45
+ public void create () {
46
+ viewport = new ScreenViewport ();
47
+ viewport .update (Gdx .graphics .getWidth (),Gdx .graphics .getHeight (),true );
48
+ stage = new Stage (viewport );
49
+ stage .setDebugAll (true );
50
+
51
+ Font gentium = KnownFonts .getGentium ();
52
+
53
+ // Group group=new Group();
54
+ // stage.addActor(group);
55
+
56
+ Sprite bg = new Sprite (gentium .mapping .get (gentium .solidBlock ));
57
+ bg .getColor ().set (Color .FOREST );
58
+
59
+ typingLabel =new TypingLabel ();
60
+ typingLabel .setAlignment (Align .center );
61
+ typingLabel .setFont (gentium );
62
+ typingLabel .style .background = new SpriteDrawable (bg );
63
+ typingLabel .setText ("[WHITE][%?blacken]Roll a ball. When the ball gets into a slot, adjacent slots freeze and become unavailable." );
64
+ typingLabel .setZIndex (0 );
65
+ typingLabel .setPosition (Gdx .graphics .getWidth () / 2f , Gdx .graphics .getHeight () / 2f + 30f );
66
+ // Normally we could use the next line, but the label doesn't have its size set yet, because it hasn't
67
+ // been added to the Stage yet.
68
+ // typingLabel.setOrigin(typingLabel.getWidth()/2f, typingLabel.getHeight()/2f);
69
+ // Instead, we can use the width and height of the layout object, which knows how big the label will be
70
+ // once the typing effect finishes.
71
+ typingLabel .setOrigin (typingLabel .layout .getWidth ()/2f , typingLabel .layout .getHeight ()/2f );
72
+
73
+ // Container<TypingLabel> container=new Container<>(typingLabel);
74
+ // container.setFillParent(true);
75
+ // stage.addActor(container);
76
+
77
+ typingLabel2 =new TypingLabel ();
78
+ typingLabel2 .setAlignment (Align .center );
79
+ typingLabel2 .setFont (gentium );
80
+ typingLabel2 .style .background = new SpriteDrawable (bg );
81
+ typingLabel2 .setText ("[WHITE][%?blacken]Roll a ball. When the ball gets into a slot,\n adjacent slots freeze and become unavailable." );
82
+ typingLabel2 .setZIndex (0 );
83
+ typingLabel2 .setPosition (Gdx .graphics .getWidth () / 2f , Gdx .graphics .getHeight () / 2f - 30f );
84
+ typingLabel2 .setOrigin (typingLabel2 .layout .getWidth ()/2f , typingLabel2 .layout .getHeight ()/2f );
85
+
86
+ VerticalGroup group = new VerticalGroup ();
87
+ group .setFillParent (true );
88
+ group .align (Align .center );
89
+ group .addActor (typingLabel );
90
+ group .addActor (typingLabel2 );
91
+ stage .addActor (group );
92
+
93
+ }
94
+
95
+ @ Override
96
+ public void render () {
97
+ ScreenUtils .clear (Color .DARK_GRAY );
98
+
99
+ if (Gdx .input .isKeyPressed (Input .Keys .UP )) typingLabel .setRotation (angle += Gdx .graphics .getDeltaTime () * 5f );
100
+ else if (Gdx .input .isKeyPressed (Input .Keys .DOWN )) typingLabel .setRotation (angle -= Gdx .graphics .getDeltaTime () * 5f );
101
+
102
+ stage .act ();
103
+ stage .draw ();
104
+ // System.out.println(typingLabel.workingLayout.lines());
105
+ }
106
+
107
+ @ Override
108
+ public void resize (int width , int height ) {
109
+ }
110
+
111
+ @ Override
112
+ public void pause () {
113
+ // Invoked when your application is paused.
114
+ }
115
+
116
+ @ Override
117
+ public void resume () {
118
+ // Invoked when your application is resumed after pause.
119
+ }
120
+
121
+ @ Override
122
+ public void dispose () {
123
+ // Destroy screen's assets here.
124
+ }
125
+ public static void main (String [] args ){
126
+ Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration ();
127
+ config .setTitle ("ForestOMoss Background Issue test" );
128
+ config .setWindowedMode (600 , 480 );
129
+ config .disableAudio (true );
130
+ config .setForegroundFPS (Lwjgl3ApplicationConfiguration .getDisplayMode ().refreshRate );
131
+ config .useVsync (true );
132
+ new Lwjgl3Application (new ForestOMossIssueTest (), config );
133
+ }
134
+
135
+ }
0 commit comments