1 /*******************************************************************************
\r
2 * Copyright 2011 See AUTHORS file.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
15 ******************************************************************************/
\r
17 package com.badlogic.gdx.tests;
\r
19 import com.badlogic.gdx.Gdx;
\r
20 import com.badlogic.gdx.graphics.GL10;
\r
21 import com.badlogic.gdx.scenes.scene2d.Actor;
\r
22 import com.badlogic.gdx.scenes.scene2d.Stage;
\r
23 import com.badlogic.gdx.scenes.scene2d.ui.Label;
\r
24 import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
\r
25 import com.badlogic.gdx.scenes.scene2d.ui.Skin;
\r
26 import com.badlogic.gdx.scenes.scene2d.ui.Table;
\r
27 import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
\r
28 import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
\r
29 import com.badlogic.gdx.tests.utils.GdxTest;
\r
30 import com.badlogic.gdx.utils.Array;
\r
32 /** Test switch of scroll bars + knobs from right to left, and bottom to top */
\r
33 public class ScrollPaneScrollBarsTest extends GdxTest {
\r
34 private Stage stage;
\r
35 private Array<ScrollPane> scrollPanes = new Array<ScrollPane>();
\r
36 private boolean doFade = true;
\r
37 private boolean doOnTop = true;
\r
38 private Table bottomLeft, bottomRight, topLeft, topRight, horizOnlyTop, horizOnlyBottom, vertOnlyLeft, vertOnlyRight;
\r
40 public void create () {
\r
41 float width = Gdx.graphics.getWidth();
\r
42 float height = Gdx.graphics.getHeight();
\r
43 float btnWidth = 200;
\r
44 float btnHeight = 40;
\r
45 stage = new Stage(0, 0, false);
\r
46 Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
\r
47 Gdx.input.setInputProcessor(stage);
\r
49 final TextButton fadeBtn = new TextButton("Fade: " + doFade, skin);
\r
50 fadeBtn.setSize(btnWidth, btnHeight);
\r
51 fadeBtn.setPosition(0, height - fadeBtn.getHeight());
\r
52 stage.addActor(fadeBtn);
\r
53 fadeBtn.addListener(new ChangeListener() {
\r
55 public void changed (ChangeEvent event, Actor actor) {
\r
57 fadeBtn.setText("Fade: " + doFade);
\r
58 for (ScrollPane pane : scrollPanes) {
\r
59 pane.setFadeScrollBars(doFade);
\r
64 final TextButton onTopBtn = new TextButton("ScrollbarsOnTop: " + doOnTop, skin);
\r
65 onTopBtn.setSize(btnWidth, btnHeight);
\r
66 onTopBtn.setPosition(0 + fadeBtn.getWidth() + 20, height - onTopBtn.getHeight());
\r
67 stage.addActor(onTopBtn);
\r
68 onTopBtn.addListener(new ChangeListener() {
\r
70 public void changed (ChangeEvent event, Actor actor) {
\r
72 onTopBtn.setText("ScrollbarOnTop: " + doOnTop);
\r
73 onTopBtn.invalidate();
\r
74 for (ScrollPane pane : scrollPanes) {
\r
75 pane.setScrollbarsOnTop(doOnTop);
\r
80 // Gdx.graphics.setVSync(false);
\r
85 float contWidth = width / 2 - gap * 1.5f;
\r
86 float contHeight = height / 4.5f - gap * 1.25f;
\r
88 bottomLeft = new Table();
\r
89 bottomLeft.setPosition(x, y);
\r
90 bottomLeft.setSize(contWidth, contHeight);
\r
91 stage.addActor(bottomLeft);
\r
93 bottomRight = new Table();
\r
94 bottomRight.setSize(contWidth, contHeight);
\r
95 x = bottomLeft.getX() + bottomLeft.getWidth() + gap;
\r
96 bottomRight.setPosition(x, y);
\r
97 stage.addActor(bottomRight);
\r
99 topLeft = new Table();
\r
100 topLeft.setSize(contWidth, contHeight);
\r
101 x = bottomLeft.getX();
\r
102 y = bottomLeft.getY() + bottomLeft.getHeight() + gap;
\r
103 topLeft.setPosition(x, y);
\r
104 stage.addActor(topLeft);
\r
106 topRight = new Table();
\r
107 topRight.setSize(contWidth, contHeight);
\r
108 x = bottomRight.getX();
\r
109 y = topLeft.getY();
\r
110 topRight.setPosition(x, y);
\r
111 stage.addActor(topRight);
\r
113 horizOnlyTop = new Table();
\r
114 horizOnlyTop.setSize(contWidth, contHeight);
\r
115 x = topRight.getX();
\r
116 y = topRight.getY() + topRight.getHeight() + gap;
\r
117 horizOnlyTop.setPosition(x, y);
\r
118 stage.addActor(horizOnlyTop);
\r
120 horizOnlyBottom = new Table();
\r
121 horizOnlyBottom.setSize(contWidth, contHeight);
\r
122 x = topLeft.getX();
\r
123 y = topLeft.getY() + topLeft.getHeight() + gap;
\r
124 horizOnlyBottom.setPosition(x, y);
\r
125 stage.addActor(horizOnlyBottom);
\r
127 vertOnlyLeft = new Table();
\r
128 vertOnlyLeft.setSize(contWidth, contHeight);
\r
129 x = horizOnlyBottom.getX();
\r
130 y = horizOnlyBottom.getY() + horizOnlyBottom.getHeight() + gap;
\r
131 vertOnlyLeft.setPosition(x, y);
\r
132 stage.addActor(vertOnlyLeft);
\r
134 vertOnlyRight = new Table();
\r
135 vertOnlyRight.setSize(contWidth, contHeight);
\r
136 x = horizOnlyTop.getX();
\r
137 y = horizOnlyTop.getY() + horizOnlyTop.getHeight() + gap;
\r
138 vertOnlyRight.setPosition(x, y);
\r
139 stage.addActor(vertOnlyRight);
\r
141 Table bottomLeftTable = new Table();
\r
142 Table bottomRightTable = new Table();
\r
143 Table topLeftTable = new Table();
\r
144 Table topRightTable = new Table();
\r
145 Table horizOnlyTopTable = new Table();
\r
146 Table horizOnlyBottomTable = new Table();
\r
147 Table vertOnlyLeftTable = new Table();
\r
148 Table vertOnlyRightTable = new Table();
\r
150 final ScrollPane bottomLeftScroll = new ScrollPane(bottomLeftTable, skin);
\r
151 bottomLeftScroll.setScrollBarPositions(true, false);
\r
153 final ScrollPane bottomRightScroll = new ScrollPane(bottomRightTable, skin);
\r
154 bottomRightScroll.setScrollBarPositions(true, true);
\r
156 final ScrollPane topLeftScroll = new ScrollPane(topLeftTable, skin);
\r
157 topLeftScroll.setScrollBarPositions(false, false);
\r
159 final ScrollPane topRightScroll = new ScrollPane(topRightTable, skin);
\r
160 topRightScroll.setScrollBarPositions(false, true);
\r
162 final ScrollPane horizOnlyTopScroll = new ScrollPane(horizOnlyTopTable, skin);
\r
163 horizOnlyTopScroll.setScrollBarPositions(false, true);
\r
165 final ScrollPane horizOnlyBottomScroll = new ScrollPane(horizOnlyBottomTable, skin);
\r
166 horizOnlyBottomScroll.setScrollBarPositions(true, true);
\r
168 final ScrollPane vertOnlyLeftScroll = new ScrollPane(vertOnlyLeftTable, skin);
\r
169 vertOnlyLeftScroll.setScrollBarPositions(true, false);
\r
171 final ScrollPane vertOnlyRightScroll = new ScrollPane(vertOnlyRightTable, skin);
\r
172 vertOnlyRightScroll.setScrollBarPositions(true, true);
\r
174 ScrollPane[] panes = new ScrollPane[] {bottomLeftScroll, bottomRightScroll, topLeftScroll, topRightScroll,
\r
175 horizOnlyTopScroll, horizOnlyBottomScroll, vertOnlyLeftScroll, vertOnlyRightScroll};
\r
176 for (ScrollPane pane : panes) {
\r
177 scrollPanes.add(pane);
\r
180 Table[] tables = new Table[] {bottomLeftTable, bottomRightTable, topLeftTable, topRightTable, horizOnlyTopTable,
\r
181 horizOnlyBottomTable, vertOnlyLeftTable, vertOnlyRightTable};
\r
182 for (Table t : tables) {
\r
183 t.pad(10).defaults().expandX().space(4);
\r
187 .add(new Label("HORIZONTAL-ONLY-TOP verify HORIZONTAL scroll bar is on the TOP and properly aligned", skin));
\r
188 horizOnlyBottomTable.add(new Label(
\r
189 "HORIZONTAL-ONLY-BOTTOM verify HORIZONTAL scroll bar is on the BOTTOM and properly aligned", skin));
\r
191 for (int i = 0; i < 12; i++) {
\r
192 bottomLeftTable.row();
\r
193 bottomRightTable.row();
\r
194 topLeftTable.row();
\r
195 topRightTable.row();
\r
197 bottomLeftTable.add(new Label(i
\r
198 + " BOTTOM-LEFT verify scroll bars are on the BOTTOM and the LEFT, and are properly aligned", skin));
\r
199 bottomRightTable.add(new Label(i
\r
200 + " BOTTOM-RIGHT verify scroll bars are on the BOTTOM and the RIGHT, and are properly aligned", skin));
\r
201 topLeftTable.add(new Label(i + " TOP-LEFT verify scroll bars are on the TOP and the LEFT, and are properly aligned",
\r
203 topRightTable.add(new Label(i + " TOP-RIGHT verify scroll bars are on the TOP and the RIGHT, and are properly aligned",
\r
206 vertOnlyLeftTable.row();
\r
207 vertOnlyRightTable.row();
\r
209 vertOnlyLeftTable.add(new Label("VERT-ONLY-LEFT", skin));
\r
210 vertOnlyRightTable.add(new Label("VERT-ONLY-RIGHT", skin));
\r
213 bottomLeft.add(bottomLeftScroll).expand().fill().colspan(4);
\r
214 bottomRight.add(bottomRightScroll).expand().fill().colspan(4);
\r
215 topLeft.add(topLeftScroll).expand().fill().colspan(4);
\r
216 topRight.add(topRightScroll).expand().fill().colspan(4);
\r
217 horizOnlyTop.add(horizOnlyTopScroll).expand().fill().colspan(4);
\r
218 horizOnlyBottom.add(horizOnlyBottomScroll).expand().fill().colspan(4);
\r
219 vertOnlyLeft.add(vertOnlyLeftScroll).expand().fill().colspan(4);
\r
220 vertOnlyRight.add(vertOnlyRightScroll).expand().fill().colspan(4);
\r
223 public void render () {
\r
224 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
\r
225 stage.act(Gdx.graphics.getDeltaTime());
\r
227 Table.drawDebug(stage);
\r
230 public void resize (int width, int height) {
\r
231 stage.setViewport(width, height, false);
\r
232 // Gdx.gl.glViewport(100, 100, width - 200, height - 200);
\r
233 // stage.setViewport(800, 600, false, 100, 100, width - 200, height - 200);
\r
236 public void dispose () {
\r
240 public boolean needsGL20 () {
\r