Examples of NinePatch


Examples of com.badlogic.gdx.graphics.g2d.NinePatch

        Object object = map.get(name);
        if (object == null) {
          ObjectMap<String, Object> regions = data.resources.get(TextureRegion.class);
          if (regions != null) {
            object = regions.get(name);
            if (object != null) object = new NinePatch((TextureRegion)object)
          }
          if (object == null)
            throw new SerializationException("Skin has a " + type.getSimpleName()
              + " that could not be found in the resources: " + jsonData);
        }
        return object;
      }
    }

    json.setSerializer(Skin.class, new Serializer<Skin>() {
      public void write (Json json, Skin skin, Class valueType) {
        json.writeObjectStart();
        json.writeValue("resources", skin.data.resources);
        for (Entry<Class, ObjectMap<String, Object>> entry : data.resources.entries())
          json.setSerializer(entry.key, new AliasSerializer(entry.value));
        json.writeField(skin, "styles");
        json.writeObjectEnd();
      }

      public Skin read (Json json, Object jsonData, Class ignored) {
        ObjectMap map = (ObjectMap)jsonData;
        readTypeMap(json, (ObjectMap)map.get("resources"), true);
        for (Entry<Class, ObjectMap<String, Object>> entry : data.resources.entries())
          json.setSerializer(entry.key, new AliasSerializer(entry.value));
        readTypeMap(json, (ObjectMap)map.get("styles"), false);
        return skin;
      }

      private void readTypeMap (Json json, ObjectMap<String, ObjectMap> typeToValueMap, boolean isResource) {
        if (typeToValueMap == null)
          throw new SerializationException("Skin file is missing a \"" + (isResource ? "resources" : "styles")
            + "\" section.");
        for (Entry<String, ObjectMap> typeEntry : typeToValueMap.entries()) {
          Class type;
          try {
            type = Class.forName(typeEntry.key);
          } catch (ClassNotFoundException ex) {
            throw new SerializationException(ex);
          }
          ObjectMap<String, ObjectMap> valueMap = (ObjectMap)typeEntry.value;
          for (Entry<String, ObjectMap> valueEntry : valueMap.entries()) {
            try {
              if (isResource)
                addResource(valueEntry.key, json.readValue(type, valueEntry.value));
              else
                addStyle(valueEntry.key, json.readValue(type, valueEntry.value));
            } catch (Exception ex) {
              throw new SerializationException("Error reading " + type.getSimpleName() + ": " + valueEntry.key, ex);
            }
          }
        }
      }
    });

    json.setSerializer(TextureRegion.class, new Serializer<TextureRegion>() {
      public void write (Json json, TextureRegion region, Class valueType) {
        json.writeObjectStart();
        json.writeValue("x", region.getRegionX());
        json.writeValue("y", region.getRegionY());
        json.writeValue("width", region.getRegionWidth());
        json.writeValue("height", region.getRegionHeight());
        json.writeObjectEnd();
      }

      public TextureRegion read (Json json, Object jsonData, Class type) {
        int x = json.readValue("x", int.class, jsonData);
        int y = json.readValue("y", int.class, jsonData);
        int width = json.readValue("width", int.class, jsonData);
        int height = json.readValue("height", int.class, jsonData);
        return new TextureRegion(skin.data.texture, x, y, width, height);
      }
    });

    json.setSerializer(BitmapFont.class, new Serializer<BitmapFont>() {
      public void write (Json json, BitmapFont font, Class valueType) {
        json.writeValue(font.getData().getFontFile().toString().replace('\\', '/'));
      }

      public BitmapFont read (Json json, Object jsonData, Class type) {
        String path = json.readValue(String.class, jsonData);
        FileHandle file = skinFile.parent().child(path);
        if (!file.exists()) file = Gdx.files.internal(path);
        return new BitmapFont(file, false);
      }
    });

    json.setSerializer(NinePatch.class, new Serializer<NinePatch>() {
      public void write (Json json, NinePatch ninePatch, Class valueType) {
        json.writeValue(ninePatch.getPatches());
      }

      public NinePatch read (Json json, Object jsonData, Class type) {
        return new NinePatch(json.readValue(TextureRegion[].class, jsonData));
      }
    });

    return json;
  }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

        Object object = map.get(name);
        if (object == null) {
          ObjectMap<String, Object> regions = data.resources.get(TextureRegion.class);
          if (regions != null) {
            object = regions.get(name);
            if (object != null) object = new NinePatch((TextureRegion)object)
          }
          if (object == null)
            throw new SerializationException("Skin has a " + type.getSimpleName()
              + " that could not be found in the resources: " + jsonData);
        }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

    height = prefHeight;
    setStyle(style);

    transform = true;

    final NinePatch background = style.background;
    TableLayout layout = getTableLayout();
    layout.padBottom(Integer.toString((int)(background.getBottomHeight()) + 1));
    layout.padTop(Integer.toString((int)(background.getTopHeight()) + 1));
    layout.padLeft(Integer.toString((int)(background.getLeftWidth()) + 1));
    layout.padRight(Integer.toString((int)(background.getRightWidth()) + 1));
  }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

  public void setStyle (WindowStyle style) {
    this.style = style;
  }

  private void calculateBoundsAndScissors (Matrix4 transform) {
    final NinePatch background = style.background;
    final BitmapFont titleFont = style.titleFont;

    widgetBounds.x = background.getLeftWidth();
    widgetBounds.y = background.getBottomHeight();
    widgetBounds.width = width - background.getLeftWidth() - background.getRightWidth();
    widgetBounds.height = height - background.getTopHeight() - background.getBottomHeight();
    ScissorStack.calculateScissors(stage.getCamera(), transform, widgetBounds, scissors);
    titleBounds.x = 0;
    titleBounds.y = height - background.getTopHeight();
    titleBounds.width = width;
    titleBounds.height = background.getTopHeight();
    textBounds.set(titleFont.getBounds(title));
    textBounds.height -= titleFont.getDescent();
  }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

    textBounds.set(titleFont.getBounds(title));
    textBounds.height -= titleFont.getDescent();
  }

  public void draw (SpriteBatch batch, float parentAlpha) {
    final NinePatch backgroundPatch = style.background;
    final BitmapFont titleFont = style.titleFont;
    final Color titleFontColor = style.titleFontColor;

    layout();
    applyTransform(batch);
    calculateBoundsAndScissors(batch.getTransformMatrix());

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    backgroundPatch.draw(batch, 0, 0, width, height);
    float textY = height - (int)(backgroundPatch.getTopHeight() / 2) + (int)(textBounds.height / 2);
    titleFont.setColor(titleFontColor.r, titleFontColor.g, titleFontColor.b, titleFontColor.a * parentAlpha);
    titleFont.drawMultiLine(batch, title, (int)(width / 2), textY, 0, HAlignment.CENTER);
    batch.flush();

    ScissorStack.pushScissors(scissors);
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

  }

  Vector3 tmp = new Vector3();

  private void calculateBoundsAndPositions (Matrix4 batchTransform) {
    final NinePatch background = style.background;
    final NinePatch hScrollKnob = style.hScrollKnob;
    final NinePatch vScrollKnob = style.vScrollKnob;

    // Get available space size by subtracting background's padded area.
    float areaWidth = width - background.getLeftWidth() - background.getRightWidth();
    float areaHeight = height - background.getTopHeight() - background.getBottomHeight();

    // Get widget's desired width.
    float widgetWidth, widgetHeight;
    if (widget instanceof Layout) {
      Layout layout = (Layout)widget;
      widgetWidth = layout.getPrefWidth();
      widgetHeight = layout.getPrefHeight();
    } else {
      widgetWidth = widget.width;
      widgetHeight = widget.height;
    }

    // Figure out if we need horizontal/vertical scrollbars,
    hasHScroll = false;
    hasVScroll = false;
    if (widgetWidth > areaWidth) hasHScroll = true;
    if (widgetHeight > areaHeight) hasVScroll = true;

    // Check again, now taking into account the area that's taken up by any enabled scrollbars.
    if (hasVScroll && (widgetWidth > areaWidth - vScrollKnob.getTotalWidth())) {
      hasHScroll = true;
      areaWidth -= vScrollKnob.getTotalWidth();
    }
    if (hasHScroll && (widgetHeight > areaHeight - hScrollKnob.getTotalHeight())) {
      hasVScroll = true;
      areaHeight -= hScrollKnob.getTotalHeight();
    }

    // If the widget is smaller than the available space, make it take up the available space.
    widgetWidth = Math.max(areaWidth, widgetWidth);
    widgetHeight = Math.max(areaHeight, widgetHeight);
    if (widget.width != widgetWidth || widget.height != widgetHeight) {
      widget.width = widgetWidth;
      widget.height = widgetHeight;
      if (widget instanceof Layout) {
        Layout layout = (Layout)widget;
        layout.invalidate();
        layout.layout();
      }
    }

    // Set the bounds and scroll knob sizes if scrollbars are needed.
    if (hasHScroll) {
      hScrollBounds.set(background.getLeftWidth(), background.getBottomHeight(), areaWidth, hScrollKnob.getTotalHeight());
      hScrollKnobBounds.width = Math.max(hScrollKnob.getTotalWidth(), (int)(hScrollBounds.width * areaWidth / widget.width));
      hScrollKnobBounds.height = hScrollKnob.getTotalHeight();

      hScrollKnobBounds.x = hScrollBounds.x + (int)((hScrollBounds.width - hScrollKnobBounds.width) * hScrollAmount);
      hScrollKnobBounds.y = hScrollBounds.y;
    }

    if (hasVScroll) {
      vScrollBounds.set(width - background.getRightWidth() - vScrollKnob.getTotalWidth(), height - background.getTopHeight()
        - areaHeight, vScrollKnob.getTotalWidth(), areaHeight);
      vScrollKnobBounds.width = vScrollKnob.getTotalWidth();
      vScrollKnobBounds.height = Math.max(vScrollKnob.getTotalHeight(),
        (int)(vScrollBounds.height * areaHeight / widget.height));
      vScrollKnobBounds.x = vScrollBounds.x;
      vScrollKnobBounds.y = vScrollBounds.y + (int)((vScrollBounds.height - vScrollKnobBounds.height) * (1 - vScrollAmount));
    }

View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

    ScissorStack.calculateScissors(stage.getCamera(), batchTransform, widgetAreaBounds, scissorBounds);
  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final NinePatch background = style.background;
    final NinePatch hScrollKnob = style.hScrollKnob;
    final NinePatch hScroll = style.hScroll;
    final NinePatch vScrollKnob = style.vScrollKnob;
    final NinePatch vScroll = style.vScroll;

    // Setup transform for this group.
    applyTransform(batch);

    // Calculate the bounds for the scrollbars, the widget area and the scissor area.
    calculateBoundsAndPositions(batch.getTransformMatrix());

    // Draw the background ninepatch.
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    background.draw(batch, 0, 0, width, height);
    batch.flush();

    // Enable scissors for widget area and draw the widget.
    ScissorStack.pushScissors(scissorBounds);
    drawChildren(batch, parentAlpha);
    ScissorStack.popScissors();

    // Render scrollbars and knobs on top.
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    if (hasHScroll) {
      hScroll.draw(batch, hScrollBounds.x, hScrollBounds.y, hScrollBounds.width, hScrollBounds.height);
      hScrollKnob.draw(batch, hScrollKnobBounds.x, hScrollKnobBounds.y, hScrollKnobBounds.width, hScrollKnobBounds.height);
    }
    if (hasVScroll) {
      vScroll.draw(batch, vScrollBounds.x, vScrollBounds.y, vScrollBounds.width, vScrollBounds.height);
      vScrollKnob.draw(batch, vScrollKnobBounds.x, vScrollKnobBounds.y, vScrollKnobBounds.width, vScrollKnobBounds.height);
    }

    resetTransform(batch);
  }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final BitmapFont font = style.font;
    final NinePatch selectedPatch = style.selectedPatch;
    final Color fontColorSelected = style.fontColorSelected;
    final Color fontColorUnselected = style.fontColorUnselected;

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

    float posY = height;
    for (int i = 0; i < items.length; i++) {
      if (selected == i) {
        selectedPatch.draw(batch, x, y + posY - itemHeight, Math.max(prefWidth, width), itemHeight);
        font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha);
      } else {
        font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a
          * parentAlpha);
      }
 
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

    if (items == null) throw new IllegalArgumentException("items cannot be null.");
    this.items = items;
    selected = 0;

    final BitmapFont font = style.font;
    final NinePatch selectedPatch = style.selectedPatch;
    prefWidth = 0;
    prefHeight = 0;

    for (int i = 0; i < items.length; i++) {
      String item = items[i];
      TextBounds bounds = font.getBounds(item);
      prefWidth = Math.max(bounds.width, prefWidth);
    }

    itemHeight = font.getCapHeight() - font.getDescent() * 2;
    itemHeight += selectedPatch.getTopHeight() + selectedPatch.getBottomHeight();
    prefWidth += selectedPatch.getLeftWidth() + selectedPatch.getRightWidth();
    prefHeight = items.length * itemHeight;
    textOffsetX = selectedPatch.getLeftWidth();
    textOffsetY = selectedPatch.getTopHeight() - font.getDescent();
  }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

  public void setItems (String[] items) {
    if (items == null) throw new IllegalArgumentException("items cannot be null.");
    this.items = items;

    NinePatch background = style.background;
    BitmapFont font = style.font;

    prefHeight = Math.max(background.getTopHeight() + background.getBottomHeight() + font.getCapHeight() - font.getDescent()
      * 2, background.getTotalHeight());

    float max = 0;
    for (int i = 0; i < items.length; i++)
      max = Math.max(font.getBounds(items[i]).width, max);
    prefWidth = background.getLeftWidth() + background.getRightWidth() + max;

    width = prefWidth;
    height = prefHeight;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.