My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package com.badlogic.gdx.tests;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle;
import com.badlogic.gdx.scenes.scene2d.ui.FlickScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox.SelectBoxStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Slider.ValueChangedListener;
import com.badlogic.gdx.scenes.scene2d.ui.SplitPane;
import com.badlogic.gdx.scenes.scene2d.ui.SplitPane.SplitPaneStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener;
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle;
import com.badlogic.gdx.scenes.scene2d.ui.tablelayout.Table;
import com.badlogic.gdx.tests.utils.GdxTest;

public class UITest extends GdxTest {
String[] listEntries = {"This is a list entry", "And another one", "The meaning of life", "Is hard to come by",
"This is a list entry", "And another one", "The meaning of life", "Is hard to come by", "This is a list entry",
"And another one", "The meaning of life", "Is hard to come by", "This is a list entry", "And another one",
"The meaning of life", "Is hard to come by", "This is a list entry", "And another one", "The meaning of life",
"Is hard to come by"};

Skin skin;
Stage stage;
SpriteBatch batch;
Texture texture1;
Texture texture2;
Actor root;

@Override
public void create () {
batch = new SpriteBatch();
skin = new Skin(Gdx.files.internal("data/uiskin.json"), Gdx.files.internal("data/uiskin.png"));
texture1 = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
texture2 = new Texture(Gdx.files.internal("data/badlogic.jpg"));
TextureRegion image = new TextureRegion(texture1);
TextureRegion image2 = new TextureRegion(texture2);
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
Gdx.input.setInputProcessor(stage);

// Group.debug = true;

final Button button = new TextButton("Single", skin.getStyle(TextButtonStyle.class), "button-sl");
final Button buttonMulti = new TextButton("Multi\nLine\nToggle", skin.getStyle("toggle", TextButtonStyle.class),
"button-ml-tgl");
final Button imgButton = new Button(new Image(image), skin.getStyle(ButtonStyle.class));
final Button imgToggleButton = new Button(new Image(image), skin.getStyle("toggle", ButtonStyle.class));
final CheckBox checkBox = new CheckBox("Check me", skin.getStyle(CheckBoxStyle.class), "checkbox");
final Slider slider = new Slider(0, 10, 1, skin.getStyle(SliderStyle.class), "slider");
final TextField textfield = new TextField("", "Click here!", skin.getStyle(TextFieldStyle.class), "textfield");
final SelectBox dropdown = new SelectBox(new String[] {"Android", "Windows", "Linux", "OSX"},
skin.getStyle(SelectBoxStyle.class), "combo");
final Image imageActor = new Image(image2);
final FlickScrollPane scrollPane = new FlickScrollPane(imageActor, "flickscroll");
final List list = new List(listEntries, skin.getStyle(ListStyle.class), "list");
final ScrollPane scrollPane2 = new ScrollPane(list, skin.getStyle(ScrollPaneStyle.class), "scroll");
final SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, skin.getStyle("default-horizontal",
SplitPaneStyle.class), "split");
final Label fpsLabel = new Label("fps:", skin.getStyle(LabelStyle.class), "label");

// configures an example of a TextField in password mode.
final Label passwordLabel = new Label("Textfield in password mode: ", skin);
final TextField passwordTextField = new TextField("", "password", skin);
passwordTextField.setPasswordCharacter('*');
passwordTextField.setPasswordMode(true);

// window.debug();
Window window = new Window("Dialog", skin.getStyle(WindowStyle.class), "window");
window.x = window.y = 0;
window.defaults().spaceBottom(10);
window.row().fill().expandX();
window.add(button).fill(0f, 0f);
window.add(buttonMulti);
window.add(imgButton);
window.add(imgToggleButton);
window.row();
window.add(checkBox);
window.add(slider).minWidth(100).fillX().colspan(3);
window.row();
window.add(dropdown);
window.add(textfield).minWidth(100).expandX().fillX().colspan(3);
window.row();
window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
window.row();
window.add(passwordLabel).colspan(2);
window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
window.row();
window.add(fpsLabel).colspan(4);
window.pack();

// stage.addActor(new Button("Behind Window", skin));
stage.addActor(window);

textfield.setTextFieldListener(new TextFieldListener() {
public void keyTyped (TextField textField, char key) {
if (key == '\n') textField.getOnscreenKeyboard().show(false);
}
});

slider.setValueChangedListener(new ValueChangedListener() {
public void changed (Slider slider, float value) {
Gdx.app.log("UITest", "slider: " + value);
}
});
}

@Override
public void render () {
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

((Label)stage.findActor("label")).setText("fps: " + Gdx.graphics.getFramesPerSecond());

stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
stage.draw();
Table.drawDebug(stage);
}

@Override
public void resize (int width, int height) {
stage.setViewport(width, height, false);
}

@Override
public void dispose () {
stage.dispose();
skin.dispose();
texture1.dispose();
texture2.dispose();
}
}

Change log

r3612 by badlogicgames on Mar 21, 2012   Diff
[fixed] proper disposing of resources in
tests runnable in GWT backend.
Go to: 
Project members, sign in to write a code review

Older revisions

r3382 by ariel.coppes on Feb 20, 2012   Diff
Added passwordCharacter field to
TextField by default with the value of
the TextField.BULLET constant, and a
setPasswordCharacter(char) to be able
to configure the desired password
...
r2898 by nathan.sweet on Nov 15, 2011   Diff
[removed] Stage from widget
constructors.
r2895 by nathan.sweet on Nov 15, 2011   Diff
[updated] scene2d, changed how focus
is handled. Now stored on stage, and
all actors have a stage reference.
Removed constructors that take a
stage.
...
All revisions of this file

File info

Size: 7672 bytes, 171 lines
Powered by Google Project Hosting