• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 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.badlogic.gdx.tests;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.graphics.GL20;
21 import com.badlogic.gdx.graphics.Texture;
22 import com.badlogic.gdx.scenes.scene2d.InputEvent;
23 import com.badlogic.gdx.scenes.scene2d.InputListener;
24 import com.badlogic.gdx.scenes.scene2d.Stage;
25 import com.badlogic.gdx.scenes.scene2d.ui.Image;
26 import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
27 import com.badlogic.gdx.scenes.scene2d.ui.Skin;
28 import com.badlogic.gdx.scenes.scene2d.ui.Table;
29 import com.badlogic.gdx.tests.utils.GdxTest;
30 
31 public class ScrollPane2Test extends GdxTest {
32 	Stage stage;
33 	Skin skin;
34 
create()35 	public void create () {
36 		stage = new Stage();
37 		Gdx.input.setInputProcessor(stage);
38 
39 		skin = new Skin(Gdx.files.internal("data/uiskin.json"));
40 
41 		ScrollPane pane2 = new ScrollPane(new Image(new Texture("data/group-debug.png")), skin);
42 		pane2.setScrollingDisabled(false, true);
43 		// pane2.setCancelTouchFocus(false);
44 		pane2.addListener(new InputListener() {
45 			public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
46 				event.stop();
47 				return true;
48 			}
49 		});
50 
51 		Table mytable = new Table();
52 		mytable.debug();
53 		mytable.add(new Image(new Texture("data/group-debug.png")));
54 		mytable.row();
55 		mytable.add(new Image(new Texture("data/group-debug.png")));
56 		mytable.row();
57 		mytable.add(pane2).size(100);
58 		mytable.row();
59 		mytable.add(new Image(new Texture("data/group-debug.png")));
60 		mytable.row();
61 		mytable.add(new Image(new Texture("data/group-debug.png")));
62 
63 		ScrollPane pane = new ScrollPane(mytable, skin);
64 		pane.setScrollingDisabled(true, false);
65 		// pane.setCancelTouchFocus(false);
66 		if (false) {
67 			// This sizes the pane to the size of it's contents.
68 			pane.pack();
69 			// Then the height is hardcoded, leaving the pane the width of it's contents.
70 			pane.setHeight(Gdx.graphics.getHeight());
71 		} else {
72 			// This shows a hardcoded size.
73 			pane.setWidth(300);
74 			pane.setHeight(Gdx.graphics.getHeight());
75 		}
76 
77 		stage.addActor(pane);
78 	}
79 
render()80 	public void render () {
81 		Gdx.gl.glClearColor(0, 0, 0, 1);
82 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
83 		stage.act(Gdx.graphics.getDeltaTime());
84 		stage.draw();
85 	}
86 
resize(int width, int height)87 	public void resize (int width, int height) {
88 		stage.getViewport().update(width, height, true);
89 	}
90 
91 	@Override
dispose()92 	public void dispose () {
93 		stage.dispose();
94 		skin.dispose();
95 	}
96 }
97