use of net.drewke.tdme.gui.events.GUIActionListener in project tdme by andreasdr.
the class GUITest method init.
/*
* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
*/
public void init(GLAutoDrawable drawable) {
// init engine
engine.init(drawable);
// register gui to mouse, keyboard events
glWindow.addMouseListener(engine.getGUI());
glWindow.addKeyListener(engine.getGUI());
//
try {
engine.getGUI().addScreen("test", GUIParser.parse("resources/tests/gui", "test.xml"));
engine.getGUI().getScreen("test").setScreenSize(640, 480);
engine.getGUI().getScreen("test").addActionListener(new GUIActionListener() {
public void onActionPerformed(GUIActionListener.Type type, GUIElementNode node) {
// check if button 1 is pressed
if (type == Type.PERFORMED && node.getName().equals("button")) {
// action performed
System.out.println(node.getId() + ".actionPerformed()");
// test get values
HashMap<String, MutableString> values = new HashMap<String, MutableString>();
node.getScreenNode().getValues(values);
System.out.println(values);
// test set values
values.clear();
values.put("select", new MutableString("8"));
values.put("input", new MutableString("Enter some more text here!"));
values.put("checkbox1", new MutableString("1"));
values.put("checkbox2", new MutableString("1"));
values.put("checkbox3", new MutableString("1"));
values.put("dropdown", new MutableString("11"));
values.put("radio", new MutableString("3"));
values.put("selectmultiple", new MutableString("|1|2|3|15|16|17|"));
node.getScreenNode().setValues(values);
// test GUI tab controller select tab method
((GUITabController) node.getScreenNode().getNodeById("tab1").getController()).selectTab();
} else // check if button 2 is pressed
if (type == Type.PERFORMED && node.getName().equals("button2")) {
try {
{
GUIParentNode parentNode = (GUIParentNode) (node.getScreenNode().getNodeById("sadd_inner"));
parentNode.replaceSubNodes("<dropdown-option text=\"Option 1\" value=\"1\" />" + "<dropdown-option text=\"Option 2\" value=\"2\" />" + "<dropdown-option text=\"Option 3\" value=\"3\" />" + "<dropdown-option text=\"Option 4\" value=\"4\" />" + "<dropdown-option text=\"Option 5\" value=\"5\" />" + "<dropdown-option text=\"Option 6\" value=\"6\" />" + "<dropdown-option text=\"Option 7\" value=\"7\" />" + "<dropdown-option text=\"Option 8\" value=\"8\" selected=\"true\" />" + "<dropdown-option text=\"Option 9\" value=\"9\" />" + "<dropdown-option text=\"Option 10\" value=\"10\" />", true);
}
{
//
GUIParentNode parentNode = (GUIParentNode) (node.getScreenNode().getNodeById("sasb_inner"));
parentNode.replaceSubNodes("<selectbox-option text=\"Option 1\" value=\"1\" />" + "<selectbox-option text=\"Option 2\" value=\"2\" />" + "<selectbox-option text=\"Option 3\" value=\"3\" />" + "<selectbox-option text=\"Option 4\" value=\"4\" selected=\"true\" />" + "<selectbox-option text=\"Option 5\" value=\"5\" />" + "<selectbox-option text=\"Option 6\" value=\"6\" />" + "<selectbox-option text=\"Option 7\" value=\"7\" />" + "<selectbox-option text=\"Option 8\" value=\"8\" />" + "<selectbox-option text=\"Option 9\" value=\"9\" />" + "<selectbox-option text=\"Option 10\" value=\"10\" />", true);
}
} catch (Exception e) {
e.printStackTrace();
}
// test GUI tab controller select tab method
((GUITabController) node.getScreenNode().getNodeById("tab2").getController()).selectTab();
}
}
});
engine.getGUI().getScreen("test").addChangeListener(new GUIChangeListener() {
public void onValueChanged(GUIElementNode node) {
System.out.println(node.getName() + ":onValueChanged: " + node.getController().getValue());
}
});
// layout
engine.getGUI().getScreen("test").layout();
// add fade in effect
GUIColorEffect effectFadeIn = new GUIColorEffect();
effectFadeIn.getColorMulStart().set(0f, 0f, 0f, 1f);
effectFadeIn.getColorMulEnd().set(1f, 1f, 1f, 1f);
effectFadeIn.setTimeTotal(1f);
effectFadeIn.start();
engine.getGUI().getScreen("test").addEffect("fadein", effectFadeIn);
// add scroll in effect
GUIPositionEffect effectScrollIn = new GUIPositionEffect();
effectScrollIn.setPositionXStart(-800f);
effectScrollIn.setPositionXEnd(0f);
effectScrollIn.setTimeTotal(1f);
effectScrollIn.start();
engine.getGUI().getScreen("test").addEffect("scrollin", effectScrollIn);
// add to render queue
engine.getGUI().addRenderScreen("test");
} catch (Exception exception) {
exception.printStackTrace();
}
}
use of net.drewke.tdme.gui.events.GUIActionListener in project tdme by andreasdr.
the class GUIScrollAreaController method init.
/*
* (non-Javadoc)
* @see net.drewke.tdme.gui.nodes.GUINodeController#init()
*/
public void init() {
final GUIParentNode contentNode = (GUIParentNode) node.getScreenNode().getNodeById(node.getId() + "_inner");
final GUIElementNode upArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_vertical_layout_up");
final GUIElementNode downArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_vertical_layout_down");
final GUIElementNode leftArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_horizontal_layout_left");
final GUIElementNode rightArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_horizontal_layout_right");
node.getScreenNode().addActionListener(new GUIActionListener() {
public void onActionPerformed(Type type, GUIElementNode node) {
if (node == upArrowNode) {
// determine scrollable height
float elementHeight = contentNode.getComputedConstraints().height;
float contentHeight = contentNode.getContentHeight();
float scrollableHeight = contentHeight - elementHeight;
// skip if no scrollable height
if (scrollableHeight <= 0f)
return;
// set up children render offset y and clip it
float childrenRenderOffsetY = contentNode.getChildrenRenderOffsetY() - 1f;
if (childrenRenderOffsetY < 0f)
childrenRenderOffsetY = 0f;
contentNode.setChildrenRenderOffsetY(childrenRenderOffsetY);
} else if (node == downArrowNode) {
// determine scrollable height
float elementHeight = contentNode.getComputedConstraints().height;
float contentHeight = contentNode.getContentHeight();
float scrollableHeight = contentHeight - elementHeight;
// skip if no scrollable height
if (scrollableHeight <= 0f)
return;
// set up children render offset y and clip it
float childrenRenderOffsetY = contentNode.getChildrenRenderOffsetY() + 1f;
if (childrenRenderOffsetY > contentHeight - contentNode.getComputedConstraints().height) {
childrenRenderOffsetY = contentHeight - contentNode.getComputedConstraints().height;
}
contentNode.setChildrenRenderOffsetY(childrenRenderOffsetY);
} else if (node == leftArrowNode) {
// determine scrollable width
float elementWidth = contentNode.getComputedConstraints().width;
float contentWidth = contentNode.getContentWidth();
float scrollableWidth = contentWidth - elementWidth;
// skip if no scrollable width
if (scrollableWidth <= 0f)
return;
// set up children render offset X and clip it
float childrenRenderOffsetX = contentNode.getChildrenRenderOffsetX() - 1f;
if (childrenRenderOffsetX < 0f)
childrenRenderOffsetX = 0f;
contentNode.setChildrenRenderOffsetX(childrenRenderOffsetX);
} else if (node == rightArrowNode) {
// determine scrollable width
float elementWidth = contentNode.getComputedConstraints().width;
float contentWidth = contentNode.getContentWidth();
float scrollableWidth = contentWidth - elementWidth;
// skip if no scrollable width
if (scrollableWidth <= 0f)
return;
// set up children render offset x and clip it
float childrenRenderOffsetX = contentNode.getChildrenRenderOffsetX() + 1f;
if (childrenRenderOffsetX > contentWidth - contentNode.getComputedConstraints().width) {
childrenRenderOffsetX = contentWidth - contentNode.getComputedConstraints().width;
}
contentNode.setChildrenRenderOffsetX(childrenRenderOffsetX);
}
}
});
}
use of net.drewke.tdme.gui.events.GUIActionListener in project tdme by andreasdr.
the class GUIScrollAreaHorizontalController method init.
/*
* (non-Javadoc)
* @see net.drewke.tdme.gui.nodes.GUINodeController#init()
*/
public void init() {
final GUIParentNode contentNode = (GUIParentNode) node.getScreenNode().getNodeById(node.getId() + "_inner");
final GUIElementNode leftArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_horizontal_layout_left");
final GUIElementNode rightArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_horizontal_layout_right");
node.getScreenNode().addActionListener(new GUIActionListener() {
public void onActionPerformed(Type type, GUIElementNode node) {
if (node == leftArrowNode) {
// determine scrollable width
float elementWidth = contentNode.getComputedConstraints().width;
float contentWidth = contentNode.getContentWidth();
float scrollableWidth = contentWidth - elementWidth;
// skip if no scrollable width
if (scrollableWidth <= 0f)
return;
// set up children render offset X and clip it
float childrenRenderOffsetX = contentNode.getChildrenRenderOffsetX() - 1f;
if (childrenRenderOffsetX < 0f)
childrenRenderOffsetX = 0f;
contentNode.setChildrenRenderOffsetX(childrenRenderOffsetX);
} else if (node == rightArrowNode) {
// determine scrollable width
float elementWidth = contentNode.getComputedConstraints().width;
float contentWidth = contentNode.getContentWidth();
float scrollableWidth = contentWidth - elementWidth;
// skip if no scrollable width
if (scrollableWidth <= 0f)
return;
// set up children render offset x and clip it
float childrenRenderOffsetX = contentNode.getChildrenRenderOffsetX() + 1f;
if (childrenRenderOffsetX > contentWidth - contentNode.getComputedConstraints().width) {
childrenRenderOffsetX = contentWidth - contentNode.getComputedConstraints().width;
}
contentNode.setChildrenRenderOffsetX(childrenRenderOffsetX);
}
}
});
}
use of net.drewke.tdme.gui.events.GUIActionListener in project tdme by andreasdr.
the class GUIScrollAreaVerticalController method init.
/*
* (non-Javadoc)
* @see net.drewke.tdme.gui.nodes.GUINodeController#init()
*/
public void init() {
final GUIParentNode contentNode = (GUIParentNode) node.getScreenNode().getNodeById(node.getId() + "_inner");
final GUIElementNode upArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_vertical_layout_up");
final GUIElementNode downArrowNode = (GUIElementNode) node.getScreenNode().getNodeById(node.getId() + "_scrollbar_vertical_layout_down");
node.getScreenNode().addActionListener(new GUIActionListener() {
public void onActionPerformed(Type type, GUIElementNode node) {
if (node == upArrowNode) {
// determine scrollable height
float elementHeight = contentNode.getComputedConstraints().height;
float contentHeight = contentNode.getContentHeight();
float scrollableHeight = contentHeight - elementHeight;
// skip if no scrollable height
if (scrollableHeight <= 0f)
return;
// set up children render offset y and clip it
float childrenRenderOffsetY = contentNode.getChildrenRenderOffsetY() - 1f;
if (childrenRenderOffsetY < 0f)
childrenRenderOffsetY = 0f;
contentNode.setChildrenRenderOffsetY(childrenRenderOffsetY);
} else if (node == downArrowNode) {
// determine scrollable height
float elementHeight = contentNode.getComputedConstraints().height;
float contentHeight = contentNode.getContentHeight();
float scrollableHeight = contentHeight - elementHeight;
// skip if no scrollable height
if (scrollableHeight <= 0f)
return;
// set up children render offset y and clip it
float childrenRenderOffsetY = contentNode.getChildrenRenderOffsetY() + 1f;
if (childrenRenderOffsetY > contentHeight - contentNode.getComputedConstraints().height) {
childrenRenderOffsetY = contentHeight - contentNode.getComputedConstraints().height;
}
contentNode.setChildrenRenderOffsetY(childrenRenderOffsetY);
}
}
});
}
Aggregations