com.badlogic.gdx.graphics.g2d.GlyphLayout Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g2d.GlyphLayout. 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: SkinTextFont.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void prepareText(String text) {
       if(preparedFonts != null) {
       	return;
       }
       if(font != null) {
           font.dispose();
           font = null;
       }
       
       try {
           parameter.characters = text;
           font = generator.generateFont(parameter);
           layout = new GlyphLayout(font, "");        	
   	} catch (GdxRuntimeException e) {
   		Logger.getGlobal().warning("Font準備失敗 : " + text + " - " + e.getMessage());
   	}
}
 
Example #2
Source File: AMScreen.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
    super.show();
    layout = new GlyphLayout();
    font = new NativeFont(new NativeFontPaint(25));
    font.appendText("正在加载...0123456789%");
    font.setColor(Color.BLACK);
    layout.setText(font, "正在加载...100%");

    stage = new Stage(new StretchViewport(1280, 720));

    assetManager = new AssetManager();
    assetManager.setLogger(new Logger("log", Logger.DEBUG));
    assetManager.setLoader(CocosScene.class, new CocosLoader(new InternalFileHandleResolver()));
    assetManager.load("mainscene/MenuScene.json", CocosScene.class);
}
 
Example #3
Source File: VisSpeller.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
public Text(String text_) {
	text = text_;
	GlyphLayout layout = new GlyphLayout(); 
	layout.setText(font,text_);
	//TextBounds bounds = font.getBounds(text);
	x = Gdx.graphics.getWidth() / 2 - layout.width / 2;
	y = Gdx.graphics.getHeight() / 2 - layout.height / 2;
}
 
Example #4
Source File: SlotActor.java    From Cubes with MIT License 5 votes vote down vote up
public static void drawText(Batch batch, float x, float y, ItemStack itemStack) {
  if (itemStack == null || itemStack.item.getStackCountMax() == 1) return;
  BitmapFontCache cache = Fonts.smallHUD.getCache();
  cache.clear();
  GlyphLayout layout = cache.addText(Integer.toString(itemStack.count), x, y, 32f, Align.right, false);
  cache.translate(0, layout.height);
  cache.draw(batch);
}
 
Example #5
Source File: DifficultyScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void render(float delta) {
    viewport.apply();
    Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    renderer.setProjectionMatrix(viewport.getCamera().combined);
    renderer.begin(ShapeType.Filled);

    renderer.setColor(Constants.EASY_COLOR);
    renderer.circle(Constants.EASY_CENTER.x, Constants.EASY_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);

    renderer.setColor(Constants.MEDIUM_COLOR);
    renderer.circle(Constants.MEDIUM_CENTER.x, Constants.MEDIUM_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);

    renderer.setColor(Constants.HARD_COLOR);
    renderer.circle(Constants.HARD_CENTER.x, Constants.HARD_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);

    renderer.end();

    batch.setProjectionMatrix(viewport.getCamera().combined);

    batch.begin();

    final GlyphLayout easyLayout = new GlyphLayout(font, Constants.EASY_LABEL);
    font.draw(batch, Constants.EASY_LABEL, Constants.EASY_CENTER.x, Constants.EASY_CENTER.y + easyLayout.height / 2, 0, Align.center, false);

    final GlyphLayout mediumLayout = new GlyphLayout(font, Constants.MEDIUM_LABEL);
    font.draw(batch, Constants.MEDIUM_LABEL, Constants.MEDIUM_CENTER.x, Constants.MEDIUM_CENTER.y + mediumLayout.height / 2, 0, Align.center, false);

    final GlyphLayout hardLayout = new GlyphLayout(font, Constants.HARD_LABEL);
    font.draw(batch, Constants.HARD_LABEL, Constants.HARD_CENTER.x, Constants.HARD_CENTER.y + hardLayout.height / 2, 0, Align.center, false);

    batch.end();
}
 
Example #6
Source File: IntegerSetting.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
  super.draw(batch, parentAlpha);
  BitmapFontCache cache = Fonts.hud.getCache();
  cache.clear();
  GlyphLayout layout = cache.addText(String.format(format, getValue()), getX(), getY(), getWidth(), Align.center, false);
  cache.translate(0, (layout.height / 2) + (getHeight() / 2));
  cache.draw(batch);
}
 
Example #7
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
     * 
     */
    public GdxCanvas() {
        this.batch = new SpriteBatch();
        this.color = new Color();
        this.tmpColor = new Color();
        
        this.shaderStack = new Stack<>();
        this.zoomStack = new Stack<>();
        
        this.camera = new OrthographicCamera(getWidth(), getHeight());
        this.camera.setToOrtho(true, getWidth(), getHeight());
        this.camera.position.x = this.camera.viewportWidth/2;
        this.camera.position.y = this.camera.viewportHeight/2;
        this.camera.update();
        
        this.viewport = new FitViewport(getWidth(), getHeight(), camera);
        this.viewport.apply();
                
        this.generators = new HashMap<String, FreeTypeFontGenerator>();
        this.fonts = new HashMap<String, BitmapFont>();
        this.bounds = new GlyphLayout();
                
        this.transform = new Matrix4();
        //this.batch.setTransformMatrix(transform);
                
        //Matrix4 projection = new Matrix4();
        //projection.setToOrtho( 0, getWidth(), getHeight(), 0, -1, 1);
        //this.batch.setProjectionMatrix(projection);
        
//        this.wHeight = getHeight();
        this.batch.setProjectionMatrix(this.camera.combined);
        
        this.shapes = new ShapeRenderer();
        //this.shapes.setTransformMatrix(transform);    
//        this.shapes.setProjectionMatrix(projection);
        //this.shapes.setProjectionMatrix(camera.combined);
        
        this.fbo = new FrameBuffer(Format.RGBA8888, getWidth(), getHeight(), false);
    }
 
Example #8
Source File: RenderedConsole.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void render(Batch b) {
  if (!visible || font == null) return;

  b.draw(modalBackground, 0, consoleY - 4, clientWidth, consoleHeight + 4);

  final int x = 2;
  String inputContents = in.getContents();
  GlyphLayout glyphs = font.draw(b, BUFFER_PREFIX + inputContents, x, bufferY - 2);
  b.draw(cursorTexture, x, bufferY, clientWidth, 2);
  if (showCaret) {
    final int caret = in.getCaretPosition();
    if (caret != in.length()) {
      glyphs.setText(font, BUFFER_PREFIX + inputContents.substring(0, caret));
    }

    b.draw(cursorTexture, x + glyphs.width, consoleY - 2, 2, textHeight);
  }
  Pools.free(glyphs);

  final float outputOffset = scrollOffset * lineHeight;
  if (outputOffset < outputHeight) {
    // offsets output to always appear that it starts at top of console window
    scrollOffset = Math.max(scrollOffset, scrollOffsetMin);
  }

  float position = outputY;
  final int outputSize = OUTPUT.size;
  if (scrollOffset > outputSize) {
    scrollOffset = outputSize;
    position += ((scrollOffsetMin - scrollOffset) * lineHeight);
  }

  for (int i = scrollOffset - 1; i >= 0; i--) {
    if (position > clientHeight) break;
    String line = OUTPUT.get(i);
    font.draw(b, line, x, position);
    position += lineHeight;
  }
}
 
Example #9
Source File: GlythData.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
public static int getWidth(BitmapFont font, GlyphLayout bounds, String str) {
    bounds.setText(font, str);        
    int textWidth = (int)bounds.width+1;
    
    // bug in libgdx, doesn't like strings ending with a space,
    // it ignores it
    if(str.endsWith(" ")) {                        
        textWidth += font.getSpaceWidth();
    }
    
    return textWidth;
}
 
Example #10
Source File: FontMetricsTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void drawDebug(BitmapFont font, GlyphLayout layout, int y) {
  ShapeRenderer shapes = Riiablo.shapes;
  for (GlyphLayout.GlyphRun run : layout.runs) {
    shapes.setColor(Color.GREEN);
    shapes.line(run.x, y + run.y, run.x + run.width, y + run.y);
    shapes.setColor(Color.RED);
    shapes.line(
        run.x, y + run.y - font.getLineHeight(),
        run.x + run.width, y + run.y - font.getLineHeight());
  }
}
 
Example #11
Source File: FontMetricsTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

  stage.act();
  stage.draw();

  Batch b = stage.getBatch();
  b.begin();
  GlyphLayout consolas16Layout = Riiablo.fonts.consolas16.draw(b, STRING, 0, 550, 600, center ? Align.center : Align.left, true);
  b.end();

  PaletteIndexedBatch batch = Riiablo.batch;
  batch.begin(Riiablo.palettes.units);
  batch.setBlendMode(active.getBlendMode());
  GlyphLayout otherLayout = active.draw(batch, STRING, 0, 250, 600, center ? Align.center : Align.left, true);
  batch.end();

  if (debug) {
    ShapeRenderer shapes = Riiablo.shapes;
    shapes.begin(ShapeRenderer.ShapeType.Line);
    drawDebug(Riiablo.fonts.consolas16, consolas16Layout, 550);
    drawDebug(active, otherLayout, 250);
    shapes.end();
  }
}
 
Example #12
Source File: WorldRenderer.java    From SIFTrain with MIT License 5 votes vote down vote up
public WorldRenderer(World world) {
    this.world = world;
    this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
    this.cam.position.set(0f, 0f, 0f);
    this.cam.update();
    spriteBatch = new PolygonSpriteBatch();
    renderer = new ShapeRenderer();
    layout = new GlyphLayout();
    loadTextures();
}
 
Example #13
Source File: SkinTextBitmap.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public SkinTextBitmap(SkinTextBitmapSource source, float size, StringProperty property) {
	super(property);
	this.source = source;
	this.size = size;
	this.layout =new GlyphLayout();
	this.font = source.getFont();
}
 
Example #14
Source File: SkinTextFont.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public void prepareFont(String text) {
    if(font != null) {
        font.dispose();                	
        font = null;
    }
    
    try {
        parameter.characters = text;        	
        font = generator.generateFont(parameter);
        layout = new GlyphLayout(font, "");
        preparedFonts = text;
    } catch (GdxRuntimeException e) {
		Logger.getGlobal().warning("Font準備失敗 : " + text + " - " + e.getMessage());
	}
}
 
Example #15
Source File: GlythData.java    From seventh with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param font
 * @param bounds
 */
public GlythData(BitmapFont font, GlyphLayout bounds) {
    super();
    this.font = font;
    this.bounds = bounds;
}
 
Example #16
Source File: GlythData.java    From seventh with GNU General Public License v2.0 4 votes vote down vote up
public static int getHeight(BitmapFont font, GlyphLayout bounds, String str) {
    bounds.setText(font, str);
    return (int)bounds.height + 8;
}
 
Example #17
Source File: RenderedText.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void measure(){
	
	if (Thread.currentThread().getName().equals("SHPD Actor Thread")){
		throw new RuntimeException("Text measured from the actor thread!");
	}
	
	if ( text == null || text.equals("") ) {
		text = "";
		width=height=0;
		visible = false;
		return;
	} else {
		visible = true;
	}
	
	font = getFont(size);
	
	if (font != null){
		GlyphLayout glyphs = new GlyphLayout( font, text);
		
		for (char c : text.toCharArray()) {
			BitmapFont.Glyph g = font.getData().getGlyph(c);
			if (g == null || (g.id != c)){
				Game.reportException(new Throwable("font file " + font.toString() + " could not render " + c));
			}
		}
		
		//We use the xadvance of the last glyph in some cases to fix issues
		// with fullwidth punctuation marks in some asian scripts
		BitmapFont.Glyph lastGlyph = font.getData().getGlyph(text.charAt(text.length()-1));
		if (lastGlyph != null && lastGlyph.xadvance > lastGlyph.width*1.5f){
			width = glyphs.width - lastGlyph.width + lastGlyph.xadvance;
		} else {
			width = glyphs.width;
		}
		
		//this is identical to l.height in most cases, but we force this for consistency.
		height = Math.round(size*0.75f);
		renderedHeight = glyphs.height;
	}
}
 
Example #18
Source File: InstructScreen.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
public InstructScreen(String instruction) {
    batch = new SpriteBatch();
    layout = new GlyphLayout();
    setInstruction(instruction);
}
 
Example #19
Source File: TypingLabel.java    From typing-label with MIT License 4 votes vote down vote up
/** Adds cached glyphs to the active BitmapFontCache as the char index progresses. */
private void addMissingGlyphs() {
    // Add additional glyphs to layout array, if any
    int glyphLeft = glyphCharIndex - cachedGlyphCharIndex;
    if(glyphLeft < 1) return;

    // Get runs
    GlyphLayout layout = super.getGlyphLayout();
    Array<GlyphRun> runs = layout.runs;

    // Iterate through GlyphRuns to find the next glyph spot
    int glyphCount = 0;
    for(int runIndex = 0; runIndex < glyphRunCapacities.size; runIndex++) {
        int runCapacity = glyphRunCapacities.get(runIndex);
        if((glyphCount + runCapacity) < cachedGlyphCharIndex) {
            glyphCount += runCapacity;
            continue;
        }

        // Get run and increase glyphCount up to its current size
        Array<Glyph> glyphs = runs.get(runIndex).glyphs;
        glyphCount += glyphs.size;

        // Next glyphs go here
        while(glyphLeft > 0) {

            // Skip run if this one is full
            int runSize = glyphs.size;
            if(runCapacity == runSize) {
                break;
            }

            // Put new glyph to this run
            cachedGlyphCharIndex++;
            TypingGlyph glyph = glyphCache.get(cachedGlyphCharIndex);
            glyphs.add(glyph);

            // Cache glyph's vertex index
            glyph.internalIndex = glyphCount;

            // Advance glyph count
            glyphCount++;
            glyphLeft--;
        }
    }
}
 
Example #20
Source File: Message.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
private static void add(Stage stage, String text) {
	msg.clearActions();

	msg.setText(text);

	GlyphLayout textLayout = new GlyphLayout();

	textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true);

	msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2);

	if (!stage.getActors().contains(msg, true))
		stage.addActor(msg);

	msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2),
			Math.round((stage.getHeight() - msg.getHeight()) / 2));
	msg.invalidate();
}
 
Example #21
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
protected GlyphLayout drawItem(Batch batch, BitmapFont font, T item, float x, float y, float width) {
	String string = toString(item);
	return font.draw(batch, string, x, y, 0, string.length(), width, alignment, false, "...");
}
 
Example #22
Source File: CustomList.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void layout() {
	final BitmapFont font = style.font;
	final BitmapFont subfont = style.subtitleFont;
	final Drawable selectedDrawable = style.selection;

	cellRenderer.layout(style);

	GlyphLayout textLayout = new GlyphLayout();

	prefWidth = 0;
	for (int i = 0; i < items.size; i++) {

		textLayout.setText(font, cellRenderer.getCellTitle(items.get(i)));

		prefWidth = Math.max(textLayout.width, prefWidth);
		
		if (cellRenderer.hasImage()) {
			TextureRegion r = cellRenderer.getCellImage(items.get(i));

			float ih = r.getRegionHeight();
			float iw = r.getRegionWidth();

			if (ih > getItemHeight() - 10) {
				ih = getItemHeight() - 10;
				iw *= ih / r.getRegionHeight();
			}

			prefWidth = Math.max(iw + textLayout.width, prefWidth);
		}

		if (cellRenderer.hasSubtitle()) {
			String subtitle = cellRenderer.getCellSubTitle(items.get(i));

			if (subtitle != null) {
				textLayout.setText(subfont, subtitle);
				prefWidth = Math.max(textLayout.width, prefWidth);
			}
		}
	}
	
	prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();

	prefHeight = items.size * cellRenderer.getItemHeight();

	Drawable background = style.background;
	if (background != null) {
		prefWidth += background.getLeftWidth() + background.getRightWidth();
		prefHeight += background.getTopHeight() + background.getBottomHeight();
	}
}
 
Example #23
Source File: RenderedText.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void measure(){
	
	if (Thread.currentThread().getName().equals("SHPD Actor Thread")){
		throw new RuntimeException("Text measured from the actor thread!");
	}
	
	if ( text == null || text.equals("") ) {
		text = "";
		width=height=0;
		visible = false;
		return;
	} else {
		visible = true;
	}
	
	font = Game.platform.getFont(size, text);
	
	if (font != null){
		GlyphLayout glyphs = new GlyphLayout( font, text);
		
		for (char c : text.toCharArray()) {
			BitmapFont.Glyph g = font.getData().getGlyph(c);
			if (g == null || (g.id != c)){
				Game.reportException(new Throwable("font file " + font.toString() + " could not render " + c));
			}
		}
		
		//We use the xadvance of the last glyph in some cases to fix issues
		// with fullwidth punctuation marks in some asian scripts
		BitmapFont.Glyph lastGlyph = font.getData().getGlyph(text.charAt(text.length()-1));
		if (lastGlyph != null && lastGlyph.xadvance > lastGlyph.width*1.5f){
			width = glyphs.width - lastGlyph.width + lastGlyph.xadvance;
		} else {
			width = glyphs.width;
		}
		
		//this is identical to l.height in most cases, but we force this for consistency.
		height = Math.round(size*0.75f);
		renderedHeight = glyphs.height;
	}
}
 
Example #24
Source File: VisTextArea.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
protected void calculateOffsets () {
	super.calculateOffsets();
	if (!this.text.equals(lastText)) {
		this.lastText = text;
		BitmapFont font = style.font;
		float maxWidthLine = this.getWidth()
				- (style.background != null ? style.background.getLeftWidth() + style.background.getRightWidth() : 0);
		linesBreak.clear();
		int lineStart = 0;
		int lastSpace = 0;
		char lastCharacter;
		Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
		GlyphLayout layout = layoutPool.obtain();
		for (int i = 0; i < text.length(); i++) {
			lastCharacter = text.charAt(i);
			if (lastCharacter == ENTER_DESKTOP || lastCharacter == ENTER_ANDROID) {
				linesBreak.add(lineStart);
				linesBreak.add(i);
				lineStart = i + 1;
			} else {
				lastSpace = (continueCursor(i, 0) ? lastSpace : i);
				layout.setText(font, text.subSequence(lineStart, i + 1));
				if (layout.width > maxWidthLine && softwrap) {
					if (lineStart >= lastSpace) {
						lastSpace = i - 1;
					}
					linesBreak.add(lineStart);
					linesBreak.add(lastSpace + 1);
					lineStart = lastSpace + 1;
					lastSpace = lineStart;
				}
			}
		}
		layoutPool.free(layout);
		// Add last line
		if (lineStart < text.length()) {
			linesBreak.add(lineStart);
			linesBreak.add(text.length());
		}
		showCursor();
	}
}
 
Example #25
Source File: HighlightTextArea.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
protected void calculateOffsets () {
	super.calculateOffsets();
	if (chunkUpdateScheduled == false) return;
	chunkUpdateScheduled = false;
	highlights.sort();
	renderChunks.clear();

	String text = getText();

	Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
	GlyphLayout layout = layoutPool.obtain();
	boolean carryHighlight = false;
	for (int lineIdx = 0, highlightIdx = 0; lineIdx < linesBreak.size; lineIdx += 2) {
		int lineStart = linesBreak.items[lineIdx];
		int lineEnd = linesBreak.items[lineIdx + 1];
		int lineProgress = lineStart;
		float chunkOffset = 0;

		for (; highlightIdx < highlights.size; ) {
			Highlight highlight = highlights.get(highlightIdx);
			if (highlight.getStart() > lineEnd) {
				break;
			}

			if (highlight.getStart() == lineProgress || carryHighlight) {
				renderChunks.add(new Chunk(text.substring(lineProgress, Math.min(highlight.getEnd(), lineEnd)), highlight.getColor(), chunkOffset, lineIdx));
				lineProgress = Math.min(highlight.getEnd(), lineEnd);

				if (highlight.getEnd() > lineEnd) {
					carryHighlight = true;
				} else {
					carryHighlight = false;
					highlightIdx++;
				}
			} else {
				//protect against overlapping highlights
				boolean noMatch = false;
				while (highlight.getStart() <= lineProgress) {
					highlightIdx++;
					if (highlightIdx >= highlights.size) {
						noMatch = true;
						break;
					}
					highlight = highlights.get(highlightIdx);
					if (highlight.getStart() > lineEnd) {
						noMatch = true;
						break;
					}
				}
				if (noMatch) break;
				renderChunks.add(new Chunk(text.substring(lineProgress, highlight.getStart()), defaultColor, chunkOffset, lineIdx));
				lineProgress = highlight.getStart();
			}

			Chunk chunk = renderChunks.peek();
			layout.setText(style.font, chunk.text);
			chunkOffset += layout.width;
			//current highlight needs to be applied to next line meaning that there is no other highlights that can be applied to currently parsed line
			if (carryHighlight) break;
		}

		if (lineProgress < lineEnd) {
			renderChunks.add(new Chunk(text.substring(lineProgress, lineEnd), defaultColor, chunkOffset, lineIdx));
		}
	}

	maxAreaWidth = 0;
	for (String line : text.split("\\n")) {
		layout.setText(style.font, line);
		maxAreaWidth = Math.max(maxAreaWidth, layout.width + 30);
	}

	layoutPool.free(layout);
	updateScrollLayout();
}
 
Example #26
Source File: DifficultyScreen.java    From ud405 with MIT License 4 votes vote down vote up
@Override
public void render(float delta) {
    // TODO: Apply the viewport
    viewport.apply();
    Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // TODO: Set the ShapeRenderer's projection matrix
    renderer.setProjectionMatrix(viewport.getCamera().combined);


    // TODO: Use ShapeRenderer to draw the buttons
    renderer.begin(ShapeType.Filled);

    renderer.setColor(Constants.EASY_COLOR);
    renderer.circle(Constants.EASY_CENTER.x, Constants.EASY_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);

    renderer.setColor(Constants.MEDIUM_COLOR);
    renderer.circle(Constants.MEDIUM_CENTER.x, Constants.MEDIUM_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);

    renderer.setColor(Constants.HARD_COLOR);
    renderer.circle(Constants.HARD_CENTER.x, Constants.HARD_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);

    renderer.end();


    // TODO: Set the SpriteBatche's projection matrix
    batch.setProjectionMatrix(viewport.getCamera().combined);

    // TODO: Use SpriteBatch to draw the labels on the buttons
    // HINT: Use GlyphLayout to get vertical centering
    batch.begin();

    final GlyphLayout easyLayout = new GlyphLayout(font, Constants.EASY_LABEL);
    font.draw(batch, Constants.EASY_LABEL, Constants.EASY_CENTER.x, Constants.EASY_CENTER.y + easyLayout.height / 2, 0, Align.center, false);

    final GlyphLayout mediumLayout = new GlyphLayout(font, Constants.MEDIUM_LABEL);
    font.draw(batch, Constants.MEDIUM_LABEL, Constants.MEDIUM_CENTER.x, Constants.MEDIUM_CENTER.y + mediumLayout.height / 2, 0, Align.center, false);

    final GlyphLayout hardLayout = new GlyphLayout(font, Constants.HARD_LABEL);
    font.draw(batch, Constants.HARD_LABEL, Constants.HARD_CENTER.x, Constants.HARD_CENTER.y + hardLayout.height / 2, 0, Align.center, false);

    batch.end();
}
 
Example #27
Source File: Client.java    From riiablo with Apache License 2.0 4 votes vote down vote up
private void drawLoading(Batch b) {
  BitmapFont font = console.getFont();
  if (font == null) return;
  GlyphLayout ellipsis = new GlyphLayout(font, "Loading... " + (int) (Riiablo.assets.getProgress() * 100) + "%");
  font.draw(b, ellipsis, 0, ellipsis.height);
}
 
Example #28
Source File: RenderSystem.java    From riiablo with Apache License 2.0 4 votes vote down vote up
private void drawDebugSpecial(ShapeRenderer shapes) {
  for (int i = Map.WALL_OFFSET, x, y; i < Map.WALL_OFFSET + Map.MAX_WALLS; i++) {
    int startX2 = startX;
    int startY2 = startY;
    float startPx2 = startPx;
    float startPy2 = startPy;
    for (y = 0; y < viewBuffer.length; y++) {
      int tx = startX2;
      int ty = startY2;
      int stx = tx * Tile.SUBTILE_SIZE;
      int sty = ty * Tile.SUBTILE_SIZE;
      float px = startPx2;
      float py = startPy2;
      int size = viewBuffer[y];
      for (x = 0; x < size; x++) {
        Map.Zone zone = map.getZone(stx, sty);
        if (zone != null) {
          DS1.Cell cell = zone.getCell(i, tx, ty);
          if (cell != null) {
            if (Map.ID.POPPADS.contains(cell.id)) {
              shapes.setColor(Map.ID.getColor(cell));
              Map.Preset preset = zone.getGrid(tx, ty);
              Map.Preset.PopPad popPad = preset.popPads.get(cell.id);
              if (popPad.startX == zone.getGridX(tx) && popPad.startY == zone.getGridY(ty)) {
                int width  = popPad.endX - popPad.startX;
                int height = popPad.endY - popPad.startY;
                iso.getPixOffset(tmpVec2);
                float offsetX = tmpVec2.x;
                float offsetY = tmpVec2.y;
                iso.toScreen(tmpVec2.set(stx, sty));
                float topLeftX = tmpVec2.x - offsetX;
                float topLeftY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(width, 0));
                float topRightX = tmpVec2.x - offsetX;
                float topRightY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(0, height));
                float bottomLeftX = tmpVec2.x - offsetX;
                float bottomLeftY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(width, height));
                float bottomRightX = tmpVec2.x - offsetX;
                float bottomRightY = tmpVec2.y - offsetY;
                shapes.line(topLeftX, topLeftY, topRightX, topRightY);
                shapes.line(topRightX, topRightY, bottomRightX, bottomRightY);
                shapes.line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
                shapes.line(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
              }
            } else {
              shapes.setColor(Color.WHITE);
              DebugUtils.drawDiamond2(shapes, px, py, Tile.WIDTH, Tile.HEIGHT);
            }
            shapes.end();

            batch.begin();
            batch.setShader(null);
            BitmapFont font = Riiablo.fonts.consolas12;
            String str = String.format("%s%n%08x", Map.ID.getName(cell.id), cell.value);
            GlyphLayout layout = new GlyphLayout(font, str, 0, str.length(), font.getColor(), 0, Align.center, false, null);
            font.draw(batch, layout,
                px + Tile.WIDTH50,
                py + Tile.HEIGHT50 + font.getLineHeight() / 4);
            batch.end();
            batch.setShader(Riiablo.shader);

            shapes.begin(ShapeRenderer.ShapeType.Line);
          }
        }

        tx++;
        stx += Tile.SUBTILE_SIZE;
        px += Tile.WIDTH50;
        py -= Tile.HEIGHT50;
      }

      startY2++;
      if (y >= tilesX - 1) {
        startX2++;
        startPy2 -= Tile.HEIGHT;
      } else {
        startX2--;
        startPx2 -= Tile.WIDTH;
      }
    }
  }
}
 
Example #29
Source File: Entity.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public void drawDebugStatus(PaletteIndexedBatch batch, ShapeRenderer shapes) {
  float x = screen.x;
  float y = screen.y;
  if (animation != null && isSelectable()) animation.drawDebug(shapes, x, y);

  shapes.setColor(Color.WHITE);
  DebugUtils.drawDiamond(shapes, x, y, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);
  //shapes.ellipse(x - Tile.SUBTILE_WIDTH50, y - Tile.SUBTILE_HEIGHT50, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);

  final float R = 32;
  shapes.setColor(Color.RED);
  shapes.line(x, y, x + MathUtils.cos(angle) * R, y + MathUtils.sin(angle) * R);

  if (animation != null) {
    int numDirs = animation.getNumDirections();
    float rounded = Direction.snapToDirection(angle, numDirs);
    shapes.setColor(Color.GREEN);
    shapes.line(x, y, x + MathUtils.cos(rounded) * R * 0.5f, y + MathUtils.sin(rounded) * R * 0.5f);
  }

  shapes.end();
  batch.begin();
  batch.setShader(null);
  StringBuilder builder = new StringBuilder(64)
      .append(classname).append('\n')
      .append(token).append(' ').append(type.MODE[mode]).append(' ').append(WCLASS[wclass]).append('\n');
  if (animation != null) {
    builder
        .append(StringUtils.leftPad(Integer.toString(animation.getFrame()), 2))
        .append('/')
        .append(StringUtils.leftPad(Integer.toString(animation.getNumFramesPerDir() - 1), 2))
        .append(' ')
        .append(animation.getFrameDelta())
        .append('\n');
  }
  appendToStatus(builder);
  GlyphLayout layout = Riiablo.fonts.consolas12.draw(batch, builder.toString(), x, y - Tile.SUBTILE_HEIGHT50, 0, Align.center, false);
  Pools.free(layout);
  batch.end();
  batch.setShader(Riiablo.shader);
  shapes.begin(ShapeRenderer.ShapeType.Line);
}
 
Example #30
Source File: GameRenderer.java    From Radix with MIT License 4 votes vote down vote up
private void createDynamicRenderers() {
    float currentHeight = 2;

    String glInfoStr = String.format("%s (%s) [%s]",
            Gdx.gl.glGetString(GL_RENDERER), Gdx.gl.glGetString(GL_VERSION), Gdx.gl.glGetString(GL_VENDOR));
    GlyphLayout glGl = glInfoRender.setText(glInfoStr, 0, 0);
    glInfoRender.setPosition((float) Gdx.graphics.getWidth() - glGl.width, (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    String fpsStr = "FPS: " + String.valueOf(Gdx.graphics.getFramesPerSecond());
    if (RadixClient.getInstance().getSettingsManager().getVisualSettings().getNonContinuous().getValue()) {
        fpsStr = fpsStr.concat(" (NON-CONTINUOUS! INACCURATE!)");
        fpsRender.setColor(Color.RED);
    }

    GlyphLayout fpsGl = fpsRender.setText(fpsStr, 0, 0);
    fpsRender.setPosition((float) Gdx.graphics.getWidth() - fpsGl.width, (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    DecimalFormat posFormat = new DecimalFormat("#.00");
    String coordsStr = String.format("(x,y,z): %s,%s,%s",
            posFormat.format(game.getPlayer().getPosition().getX()),
            posFormat.format(game.getPlayer().getPosition().getY()),
            posFormat.format(game.getPlayer().getPosition().getZ()));
    GlyphLayout posGl = positionRender.setText(coordsStr, 0, 0);
    positionRender.setPosition((float) Gdx.graphics.getWidth() - posGl.width, (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    String chunk = String.format("Chunk (x,z): %s,%s",
            game.getWorld().getChunkPosition(game.getPlayer().getPosition().getX()),
            game.getWorld().getChunkPosition(game.getPlayer().getPosition().getZ()));
    GlyphLayout chunkGl = chunkposRender.setText(chunk, 0, 0);
    chunkposRender.setPosition((float) Gdx.graphics.getWidth() - chunkGl.width,
            (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    String headingStr = String.format("(yaw,pitch): %s,%s",
            posFormat.format(game.getPlayer().getRotation().getYaw()),
            posFormat.format(game.getPlayer().getRotation().getPitch()));
    GlyphLayout headingGl = headingRender.setText(headingStr, 0, 0);
    headingRender.setPosition((float) Gdx.graphics.getWidth() - headingGl.width,
            (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    int playerX = MathUtils.floor(game.getPlayer().getPosition().getX());
    int playerY = MathUtils.floor(game.getPlayer().getPosition().getY());
    int playerZ = MathUtils.floor(game.getPlayer().getPosition().getZ());
    IChunk playerChunk = game.getWorld().getChunk(playerX, playerZ);
    try {
        if (playerChunk != null) {
            String llStr = String.format("Light Level @ Feet: %d",
                    playerChunk.getSunlight(playerX & (game.getWorld().getChunkSize() - 1),
                            playerY, playerZ & (game.getWorld().getChunkSize() - 1)));
            GlyphLayout llGl = lightlevelRender.setText(llStr, 0, 0);
            lightlevelRender.setPosition((float) Gdx.graphics.getWidth() - llGl.width,
                    (Gdx.graphics.getHeight() - currentHeight));
            currentHeight += debugTextRenderer.getLineHeight();
        }
    } catch (BlockStorage.CoordinatesOutOfBoundsException ex) {
        ex.printStackTrace();
    }

    String threadsStr = "Active threads: " + Thread.activeCount();
    GlyphLayout threadsGl = activeThreadsRender.setText(threadsStr, 0, 0);
    activeThreadsRender.setPosition((float) Gdx.graphics.getWidth() - threadsGl.width,
            (Gdx.graphics.getHeight() - currentHeight));

    // Current looked-at block info. Draws next to the crosshair
    String currentBlockStr = "";
    Vec3i cbLoc = game.getSelectedBlock();
    if (cbLoc != null) {
        try {
            Block cbBlk = game.getWorld().getChunk(cbLoc.x, cbLoc.z).getBlock(
                    cbLoc.x & (game.getWorld().getChunkSize() - 1),
                    cbLoc.y,
                    cbLoc.z & (game.getWorld().getChunkSize() - 1)
            );
            if (cbBlk != null) {
                currentBlockStr = String.format(
                        "%s (%d)\n" + // Name (id)
                                "%d%%", // Breaking percentage
                        cbBlk.getHumanName(), cbBlk.getID(),
                        100 - Math.round(game.getPlayer().getBreakPercent() * 100));
            }
        } catch (CoordinatesOutOfBoundsException e) { // Shouldn't happen
            e.printStackTrace();
        }
    }
    selectedBlockRender.setText(currentBlockStr, 0, 0);
    selectedBlockRender.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

    glDebugRender.setText(String.format("DC: %d, GLC: %d, VTCS: %d, TB: %d, SS: %d",
                    curDC, curGLC, curVTCS, curTB, curSS),
            0, debugTextRenderer.getLineHeight() + 45);
}