de.lessvoid.nifty.elements.Element Java Examples

The following examples show how to use de.lessvoid.nifty.elements.Element. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElementEditor.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
public void normalizePosition(){
    Element parent = selected.getParent().getNiftyElement();
    Element sel = selected.getNiftyElement();
    float hp = parent.getHeight();
    float wp = parent.getWidth();
    float totalPaddingHorz = parent.getPaddingLeft().getValue(wp) + parent.getPaddingRight().getValue(wp);
    float totalPaddingVert = parent.getPaddingTop().getValue(hp) + parent.getPaddingBottom().getValue(hp);
    float X = (float)(sel.getX()-parent.getX())/(parent.getWidth()- totalPaddingHorz);
    float Y = (float)(sel.getY()-parent.getY())/(parent.getHeight()-totalPaddingVert);
    int percX = Math.round(X*100);
    int percY = Math.round(Y*100);
   
    selected.addAttribute("x", ""+percX+"%");
    selected.addAttribute("y", ""+percY+"%");
    selected.lightRefresh();
    this.update();
}
 
Example #2
Source File: ElementEditor.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
public void normalizeSize(){
    Element parent = selected.getParent().getNiftyElement();
    Element sel = selected.getNiftyElement();
    float hp = parent.getHeight();
    float wp = parent.getWidth();
    float totalPaddingHorz = parent.getPaddingLeft().getValue(wp) + parent.getPaddingRight().getValue(wp);
    float totalPaddingVert = parent.getPaddingTop().getValue(hp) + parent.getPaddingBottom().getValue(hp);
    float width = (float)sel.getWidth()/(parent.getWidth()- totalPaddingHorz);
    float height = (float)sel.getHeight()/(parent.getHeight()-totalPaddingVert);
    int percW = Math.round(width*100);
    int percH = Math.round(height*100);
   
    selected.addAttribute("width", ""+percW+"%");
    selected.addAttribute("height", ""+percH+"%");
    selected.lightRefresh();
    this.update();
}
 
Example #3
Source File: NiftyDDManager.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
public void startDrag(final GElement element){
    if(dragged != null){
        throw new IllegalStateException("You can't start more than one drag&drop");
    }
    
    dragged = element;
    nifty.showPopup(nifty.getCurrentScreen(),popUp.getId(), null);
    final Element ele = this.dragged.getNiftyElement();
    final SizeValue width = SizeValue.px(ele.getWidth());
    this.previousX = ele.getX();
    this.previousY = ele.getY();
    this.previousIndex = this.findIndex(dragged);
    final SizeValue height = SizeValue.px(ele.getHeight());
     ele.setConstraintX(SizeValue.px(previousX));
    ele.setConstraintY(SizeValue.px(previousY));
    ele.setConstraintHeight(height);
    ele.setConstraintWidth(width);
    element.getNiftyElement().markForMove(popUp);
}
 
Example #4
Source File: NiftyDDManager.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
public NiftyDDManager(Nifty nifty){
    Element temp = nifty.findPopupByName(NIFTY_EDITOR_POPUP_SUPPORT);
    if(temp == null){
        PopupBuilder builder = new PopupBuilder(NIFTY_EDITOR_POPUP_SUPPORT);
        builder.childLayoutAbsolute();
        builder.registerPopup(nifty);
        temp = nifty.createPopup(NIFTY_EDITOR_POPUP_SUPPORT);
    }
    popUp = temp;
    this.nifty = nifty;
    dragged = null;
}
 
Example #5
Source File: GLayer.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
public void setIndex(int index) {
    super.setIndex(index);
   GScreen parent = (GScreen) this.parent;
   List<Element> layerElements = parent.getScreen().getLayerElements();
   layerElements.remove(this.nElement);
   layerElements.add(index, nElement);
}
 
Example #6
Source File: InputSystemJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void processSoftKeyboard() {
    SoftTextDialogInput softTextDialogInput = JmeSystem.getSoftTextDialogInput();
    if (softTextDialogInput != null) {
        Element element = nifty.getCurrentScreen().getFocusHandler().getKeyboardFocusElement();
        if (element != null) {
            final TextField textField = element.getNiftyControl(TextField.class);
            if (textField != null) {
                Logger.getLogger(InputSystemJme.class.getName()).log(Level.FINE, "Current TextField: {0}", textField.getId());
                String initialValue = textField.getRealText();
                if (initialValue == null) {
                    initialValue = "";
                }

                softTextDialogInput.requestDialog(SoftTextDialogInput.TEXT_ENTRY_DIALOG, "Enter Text", initialValue, new SoftTextDialogInputListener() {

                    @Override
                    public void onSoftText(int action, String text) {
                        if (action == SoftTextDialogInputListener.COMPLETE) {
                            textField.setText(text);
                        }
                    }
                });
            }
        }
    }

}
 
Example #7
Source File: GUIDrawer.java    From OpenRTS with MIT License 5 votes vote down vote up
protected void setButtonCustomEffet(String id, boolean val){
    Element e = guiCtrl.getElement(id);
    if(e == null)
        throw new IllegalArgumentException("can't find button '"+id+"'.");
    if(val)
        e.startEffect(EffectEventId.onCustom);
    else
        e.stopEffect(EffectEventId.onCustom);
}
 
Example #8
Source File: GUIDrawer.java    From OpenRTS with MIT License 5 votes vote down vote up
protected void changeButtonTextColor(String id, Color color){
    float a = color.getAlpha();
    float r = color.getRed();
    float g = color.getGreen();
    float b = color.getBlue();
    de.lessvoid.nifty.tools.Color niftyColor = new de.lessvoid.nifty.tools.Color(r/255, g/255, b/255, 1);
    Element e = guiCtrl.getElement(id+"#text");
    if(e == null || e.getRenderer(TextRenderer.class) == null)
        throw new IllegalArgumentException("can't find button's text '"+id+"'.");
    e.getRenderer(TextRenderer.class).setColor(niftyColor);
}
 
Example #9
Source File: NiftyDDManager.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
/**
 * Move dragged element around
 * @param x
 * @param y 
 */
public void dragAround(int x,int y){
        if(dragged == null){
            throw new IllegalStateException("You must start drag before!");
        }
        Element ele = this.dragged.getNiftyElement();
        ele.setConstraintX(SizeValue.px(x-ele.getWidth()/2));
        ele.setConstraintY(SizeValue.px(y-ele.getHeight()/2));
        
        popUp.layoutElements();
}
 
Example #10
Source File: GUIDrawer.java    From OpenRTS with MIT License 5 votes vote down vote up
protected void changeLabelText(String id, String text){
    Element e = guiCtrl.getElement(id);
    if(e == null || e.getRenderer(TextRenderer.class) == null)
        throw new IllegalArgumentException("can't find label '"+id+"'.");
    
    e.getRenderer(TextRenderer.class).setText(text);
}
 
Example #11
Source File: GuiSelectionListener.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
private void absoluteBehavior(GElement sel,int key){
    Element parent = sel.getParent().getNiftyElement();
    int xp = parent.getX();
    int yp = parent.getY();
    int totalPaddingHorz = parent.getPaddingLeft().getValueAsInt(parent.getWidth());
    int totalPaddingVert = parent.getPaddingTop().getValueAsInt(parent.getHeight());
    int x = sel.getNiftyElement().getX()-(xp+totalPaddingHorz);
    int y = sel.getNiftyElement().getY()-(yp+totalPaddingVert);
    if(key==KeyEvent.VK_DOWN){
        y++;
        sel.addAttribute("y", ""+y);
        sel.lightRefresh();
    }else  if(key==KeyEvent.VK_UP){
        y--;
        sel.addAttribute("y", ""+y);
        sel.lightRefresh();
    }else  if(key==KeyEvent.VK_LEFT){
        x--;
        sel.addAttribute("x", ""+x);
        sel.lightRefresh();
    }else  if(key==KeyEvent.VK_RIGHT){
        x++;
        sel.addAttribute("x", ""+x);
        sel.lightRefresh();
    }
    niftyView.displayRect(x, y,sel.getNiftyElement().getHeight(), sel.getNiftyElement().getWidth() );
  this.selected.setRect(sel.getNiftyElement().getX(), sel.getNiftyElement().getY(),sel.getNiftyElement().getWidth(), sel.getNiftyElement().getHeight() );
}
 
Example #12
Source File: GuiSelectionListener.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
private void layerBeahvior(GElement sel, int keyCode) {
    List<Element> children = sel.getParent().getNiftyElement().getChildren();
    int index = children.indexOf(sel.getNiftyElement());
    if(keyCode==KeyEvent.VK_UP && index > 0 ){
        index--;
        sel.setIndex(index);
    }else if(keyCode == KeyEvent.VK_DOWN && index < (children.size() - 1)){
        index++;
        sel.setIndex(index);
    }
}
 
Example #13
Source File: GElement.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
public Element getNiftyElement() {
    return nElement;
}
 
Example #14
Source File: GEffect.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
public void createEffectFor(Element ownerElement,EffectEventId eventID){
    effectType.materialize(ownerElement.getNifty(), ownerElement, eventID, new Attributes(),Lists.newLinkedList());
}
 
Example #15
Source File: GCheckbox.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
@Override
public Element getDropContext() {
    throw new IllegalDropException("You can't add elements to a checkbox");
}
 
Example #16
Source File: GEffectsNode.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
public GEffectsNode(Element element){
    this.element = element;
}
 
Example #17
Source File: GRadioButton.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
@Override
public Element getDropContext() {
    throw new IllegalDropException("You can not add elements to a radiobutton");
}
 
Example #18
Source File: GTextfield.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
@Override
public Element getDropContext() {
    throw new IllegalDropException("You can not add elements to a textfield");
}
 
Example #19
Source File: GElement.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
public Element getDropContext() {
    return nElement;
}
 
Example #20
Source File: GLabel.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
@Override
public Element getDropContext() {
    throw new IllegalDropException("You can not add elements to a label");
}
 
Example #21
Source File: ElementEditor.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
public Element getNiftyElement(){
    return selected.getNiftyElement();
}
 
Example #22
Source File: GUIDrawer.java    From OpenRTS with MIT License 4 votes vote down vote up
protected void setBackground(String id, String backgroundPath){
    Element e = guiCtrl.getElement(id);
    if(e == null || e.getRenderer(ImageRenderer.class) == null)
        throw new IllegalArgumentException("can't find element with background '"+id+"'.");
    e.getRenderer(ImageRenderer.class).setImage(guiCtrl.nifty.createImage(backgroundPath, false));
}
 
Example #23
Source File: GUIDrawer.java    From OpenRTS with MIT License 4 votes vote down vote up
protected void changeButtonText(String id, String text){
    Element e = guiCtrl.getElement(id+"#text");
    if(e == null || e.getRenderer(TextRenderer.class) == null)
        throw new IllegalArgumentException("can't find button's text '"+id+"'.");
    e.getRenderer(TextRenderer.class).setText(text);
}
 
Example #24
Source File: GUIDrawer.java    From OpenRTS with MIT License 4 votes vote down vote up
protected Element getElement(String id){
    return guiCtrl.getElement(id);
}
 
Example #25
Source File: GUIController.java    From OpenRTS with MIT License 4 votes vote down vote up
protected Element getElement(String s) {
	return nifty.getCurrentScreen().findElementByName(s);
}
 
Example #26
Source File: GUIEditor.java    From niftyeditor with Apache License 2.0 2 votes vote down vote up
/**
 * 
 * Get Nifty element from a GElement
 * @param id
 * @return Nifty element inside the GElement
 */
public Element getNiftyElement(String id){
    return this.findElement(id).getNiftyElement();
}