Search in sources :

Example 1 with GUIScreenNode

use of net.drewke.tdme.gui.nodes.GUIScreenNode in project tdme by andreasdr.

the class GUIParser method parse.

/**
	 * Parses a GUI XML content
	 * @param xml
	 * @return GUI screen node
	 * @throws IOException
	 */
public static GUIScreenNode parse(String xml) throws Exception {
    // load GUI xml document
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = builder.parse(new ByteArrayInputStream(new String(xml).getBytes()));
    Element xmlRoot = document.getDocumentElement();
    // create GUI main / screen node
    GUIScreenNode guiScreenNode = null;
    if (xmlRoot.getNodeName().equals("screen") == false) {
        throw new GUIParserException("XML root node must be <screen>");
    }
    guiScreenNode = new GUIScreenNode(xmlRoot.getAttribute("id"), GUINode.createFlow(xmlRoot.getAttribute("flow")), GUIParentNode.createOverflow(xmlRoot.getAttribute("overflow-x")), GUIParentNode.createOverflow(xmlRoot.getAttribute("overflow-y")), GUINode.createAlignments(xmlRoot.getAttribute("horizontal-align"), xmlRoot.getAttribute("vertical-align")), GUINode.createRequestedConstraints(xmlRoot.getAttribute("left"), xmlRoot.getAttribute("top"), xmlRoot.getAttribute("width"), xmlRoot.getAttribute("height")), GUINode.getRequestedColor(xmlRoot.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(xmlRoot.getAttribute("border"), xmlRoot.getAttribute("border-left"), xmlRoot.getAttribute("border-top"), xmlRoot.getAttribute("border-right"), xmlRoot.getAttribute("border-bottom"), xmlRoot.getAttribute("border-color"), xmlRoot.getAttribute("border-color-left"), xmlRoot.getAttribute("border-color-top"), xmlRoot.getAttribute("border-color-right"), xmlRoot.getAttribute("border-color-bottom")), GUINode.createPadding(xmlRoot.getAttribute("padding"), xmlRoot.getAttribute("padding-left"), xmlRoot.getAttribute("padding-top"), xmlRoot.getAttribute("padding-right"), xmlRoot.getAttribute("padding-bottom")), GUINode.createConditions(xmlRoot.getAttribute("show-on")), GUINode.createConditions(xmlRoot.getAttribute("hide-on")), xmlRoot.getAttribute("scrollable").trim().equalsIgnoreCase("true"), xmlRoot.getAttribute("popup").trim().equalsIgnoreCase("true"));
    // parse GUI nodes
    parseGUINode(guiScreenNode, xmlRoot, null);
    //
    return guiScreenNode;
}
Also used : GUIScreenNode(net.drewke.tdme.gui.nodes.GUIScreenNode) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) GUIElement(net.drewke.tdme.gui.elements.GUIElement) Element(org.w3c.dom.Element) MutableString(net.drewke.tdme.utils.MutableString) Document(org.w3c.dom.Document)

Example 2 with GUIScreenNode

use of net.drewke.tdme.gui.nodes.GUIScreenNode in project tdme by andreasdr.

the class GUI method determineFocussedNodes.

/**
	 * Determine focussed nodes
	 */
private void determineFocussedNodes() {
    // clear focusable nodes
    focusableNodes.clear();
    // handle screen input events
    focusableScreenNodes.clear();
    for (int i = renderScreens.size() - 1; i >= 0; i--) {
        // screen
        GUIScreenNode screen = renderScreens.get(i);
        if (screen.isVisible() == false)
            continue;
        //
        focusableScreenNodes.add(screen);
        // break here if pop up
        if (screen.isPopUp() == true)
            break;
    }
    // determine focusable nodes in correct order
    for (int i = focusableScreenNodes.size() - 1; i >= 0; i--) {
        // screen
        GUIScreenNode screen = focusableScreenNodes.get(i);
        screen.determineFocussedNodes(screen, focusableNodes);
    }
}
Also used : GUIScreenNode(net.drewke.tdme.gui.nodes.GUIScreenNode)

Example 3 with GUIScreenNode

use of net.drewke.tdme.gui.nodes.GUIScreenNode in project tdme by andreasdr.

the class GUI method addRenderScreen.

/**
	 * Add render screen
	 * @param screenId
	 */
public void addRenderScreen(String screenId) {
    //
    GUIScreenNode screen = screens.get(screenId);
    if (screen == null)
        return;
    // set screen gui
    screen.setGUI(this);
    //
    renderScreens.add(screen);
}
Also used : GUIScreenNode(net.drewke.tdme.gui.nodes.GUIScreenNode)

Example 4 with GUIScreenNode

use of net.drewke.tdme.gui.nodes.GUIScreenNode in project tdme by andreasdr.

the class GUI method handleEvents.

/**
	 * Handle screen events
	 */
public void handleEvents() {
    // lock
    lockEvents();
    // handle floating nodes of screens first
    for (int i = renderScreens.size() - 1; i >= 0; i--) {
        // screen
        GUIScreenNode screen = renderScreens.get(i);
        if (screen.isVisible() == false)
            continue;
        // floating nodes
        ArrayList<GUINode> floatingNodes = screen.getFloatingNodes();
        for (int j = 0; j < floatingNodes.size(); j++) {
            // floating node
            GUINode floatingNode = floatingNodes.get(j);
            // handle it events
            handleEvents(floatingNode);
        }
        // break here if pop up
        if (screen.isPopUp() == true)
            break;
    }
    // handle screen input events
    for (int i = renderScreens.size() - 1; i >= 0; i--) {
        // screen
        GUIScreenNode screen = renderScreens.get(i);
        if (screen.isVisible() == false)
            continue;
        // handle screen events
        handleEvents(screen);
        // events handler
        if (screen.getInputEventHandler() != null) {
            screen.getInputEventHandler().handleInputEvents();
        }
        // break here if pop up
        if (screen.isPopUp() == true)
            break;
    }
    // discard events
    mouseEvents.clear();
    mouseEventsPool.reset();
    keyboardEvents.clear();
    keyboardEventsPool.reset();
    // unlock
    unlockEvents();
}
Also used : GUIScreenNode(net.drewke.tdme.gui.nodes.GUIScreenNode) GUINode(net.drewke.tdme.gui.nodes.GUINode)

Example 5 with GUIScreenNode

use of net.drewke.tdme.gui.nodes.GUIScreenNode in project tdme by andreasdr.

the class GUI method render.

/**
	 * Render GUIs
	 */
public void render() {
    // return if having nothing to render 
    if (renderScreens.isEmpty() == true)
        return;
    // focus node if not yet done
    if (focussedNode == null) {
        focusNextNode();
    }
    // init rendering
    guiRenderer.setGUI(this);
    engine.initGUIMode();
    guiRenderer.initRendering();
    // render screens
    for (int i = 0; i < renderScreens.size(); i++) {
        // screen
        GUIScreenNode screen = renderScreens.get(i);
        //
        if (screen.isVisible() == false)
            continue;
        // update screen size and layout if reshaped
        if (screen.getScreenWidth() != width || screen.getScreenHeight() != height) {
            screen.setScreenSize(width, height);
            screen.layout();
        }
        // render
        screen.setConditionsMet();
        screen.tick();
        screen.render(guiRenderer);
    }
    // render floating nodes
    for (int i = 0; i < renderScreens.size(); i++) {
        // screen
        GUIScreenNode screen = renderScreens.get(i);
        // skip if not visible
        if (screen.isVisible() == false)
            continue;
        // render floating nodes
        screen.renderFloatingNodes(guiRenderer);
    }
    // done rendering
    guiRenderer.doneRendering();
    engine.doneGUIMode();
}
Also used : GUIScreenNode(net.drewke.tdme.gui.nodes.GUIScreenNode)

Aggregations

GUIScreenNode (net.drewke.tdme.gui.nodes.GUIScreenNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 GUIElement (net.drewke.tdme.gui.elements.GUIElement)1 GUINode (net.drewke.tdme.gui.nodes.GUINode)1 MutableString (net.drewke.tdme.utils.MutableString)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1