public void draw(org.mini2Dx.core.Graphics g, float x, float y, float width, float height) { var xCount = (int)(width / _textureRegion.getRegionWidth()); var yCount = (int)(height / _textureRegion.getRegionHeight()); var xRemainder = width - xCount * _textureRegion.getRegionWidth(); var yRemainder = height - yCount * _textureRegion.getRegionHeight(); TextureRegion xRemainderRegion = null; TextureRegion yRemainderRegion = null; TextureRegion xyRemainderRegion = null; if (xRemainder != 0) { xRemainderRegion = new MonoGameTextureRegion(_textureRegion, (int)xRemainder, _textureRegion.getRegionHeight()); } if (yRemainder != 0) { yRemainderRegion = new MonoGameTextureRegion(_textureRegion, _textureRegion.getRegionWidth(), (int)yRemainder); } if (xRemainder != 0 && yRemainder != 0) { xyRemainderRegion = new MonoGameTextureRegion(_textureRegion, (int)xRemainder, (int)yRemainder); } for (int i = 0; i < xCount; i++) { for (int j = 0; j < yCount; j++) { g.drawTextureRegion(_textureRegion, x + _textureRegion.getRegionWidth() * i, y + j * _textureRegion.getRegionHeight()); } } if (xRemainderRegion != null) { for (int i = 0; i < yCount; i++) { g.drawTextureRegion(xRemainderRegion, x + xCount * _textureRegion.getRegionWidth(), y + i * _textureRegion.getRegionHeight()); } } if (yRemainderRegion != null) { for (int i = 0; i < xCount; i++) { g.drawTextureRegion(yRemainderRegion, x + i * _textureRegion.getRegionWidth(), y + yCount * _textureRegion.getRegionHeight()); } } if (xyRemainderRegion != null) { g.drawTextureRegion(xyRemainderRegion, x + xCount * _textureRegion.getRegionWidth(), y + yCount * _textureRegion.getRegionHeight()); } }
public void render(org.mini2Dx.core.Graphics g, float x, float y, float width, float height) { var newTint = _setColor.copy().multiply(g.getTint()); var oldTint = g.getTint(); var middleWidth = (int)(width - _leftWidth - _rightWidth); var middleHeight = (int)(height - _topHeight - _bottomHeight); g.setTint(newTint); _ninePatchRegion.setRegionX(_textureRegionX); _ninePatchRegion.setRegionY(_textureRegionY); _ninePatchRegion.setRegionWidth((int)_leftWidth); _ninePatchRegion.setRegionHeight((int)_topHeight); draw(g, _ninePatchRegion, x, y, _leftWidth, _topHeight); _ninePatchRegion.setRegionX(_textureRegionX + (int)_leftWidth); _ninePatchRegion.setRegionWidth((int)_middleWidth); draw(g, _ninePatchRegion, x + _leftWidth, y, middleWidth, _topHeight); _ninePatchRegion.setRegionX(_textureRegionX + (int)_rightX); _ninePatchRegion.setRegionWidth((int)_rightWidth); draw(g, _ninePatchRegion, x + width - _rightWidth, y, _rightWidth, _topHeight); _ninePatchRegion.setRegionY(_textureRegionY + (int)_topHeight); _ninePatchRegion.setRegionHeight((int)_middleHeight); draw(g, _ninePatchRegion, x + width - _rightWidth, y + _topHeight, _rightWidth, middleHeight); _ninePatchRegion.setRegionX(_textureRegionX + (int)_leftWidth); _ninePatchRegion.setRegionWidth((int)_middleWidth); draw(g, _ninePatchRegion, x + _leftWidth, y + _topHeight, middleWidth, middleHeight); _ninePatchRegion.setRegionX(_textureRegionX); _ninePatchRegion.setRegionWidth((int)_leftWidth); draw(g, _ninePatchRegion, x, y + _topHeight, _leftWidth, middleHeight); _ninePatchRegion.setRegionY(_textureRegionY + (int)_bottomY); _ninePatchRegion.setRegionHeight((int)_bottomHeight); draw(g, _ninePatchRegion, x, y + height - _bottomHeight, _leftWidth, _bottomHeight); _ninePatchRegion.setRegionX(_textureRegionX + (int)_leftWidth); _ninePatchRegion.setRegionWidth((int)_middleWidth); draw(g, _ninePatchRegion, x + _leftWidth, y + height - _bottomHeight, middleWidth, _bottomHeight); _ninePatchRegion.setRegionX(_textureRegionX + (int)_rightX); _ninePatchRegion.setRegionWidth((int)_rightWidth); draw(g, _ninePatchRegion, x + width - _rightWidth, y + height - _bottomHeight, _rightWidth, _bottomHeight); g.setTint(oldTint); }
public void render(org.mini2Dx.core.Graphics g, float x, float y, float width, float height) { var newTint = _setColor.copy().multiply(g.getTint()); var oldTint = g.getTint(); g.setTint(newTint); _ninePatchRegion = new MonoGameTextureRegion(_textureRegion); _ninePatchRegion.setRegionX(0); _ninePatchRegion.setRegionY(0); _ninePatchRegion.setRegionWidth((int)_leftWidth); _ninePatchRegion.setRegionHeight((int)_topHeight); draw(g, _ninePatchRegion, x, y, _leftWidth, _topHeight); _ninePatchRegion.setRegionX((int)_leftWidth); _ninePatchRegion.setRegionWidth((int)(_textureRegion.getRegionWidth() - _leftWidth - _rightWidth)); draw(g, _ninePatchRegion, x + _leftWidth, y, width - _leftWidth - _rightWidth, _topHeight); _ninePatchRegion.setRegionX((int)(_textureRegion.getRegionWidth() - _rightWidth)); _ninePatchRegion.setRegionWidth((int)_rightWidth); draw(g, _ninePatchRegion, x + width - _rightWidth, y, _rightWidth, _topHeight); _ninePatchRegion.setRegionY((int)_topHeight); _ninePatchRegion.setRegionHeight((int)(_textureRegion.getRegionHeight() - _topHeight - _bottomHeight)); draw(g, _ninePatchRegion, x + width - _rightWidth, y + _topHeight, _rightWidth, height - _topHeight - _bottomHeight); _ninePatchRegion.setRegionX((int)_leftWidth); _ninePatchRegion.setRegionWidth((int)(_textureRegion.getRegionWidth() - _leftWidth - _rightWidth)); draw(g, _ninePatchRegion, x + _leftWidth, y + _topHeight, width - _leftWidth - _rightWidth, height - _topHeight - _bottomHeight); _ninePatchRegion.setRegionX(0); _ninePatchRegion.setRegionWidth((int)_leftWidth); draw(g, _ninePatchRegion, x, y + _topHeight, _leftWidth, height - _topHeight - _bottomHeight); _ninePatchRegion.setRegionY((int)(_textureRegion.getRegionHeight() - _bottomHeight)); _ninePatchRegion.setRegionHeight((int)_bottomHeight); draw(g, _ninePatchRegion, x, y + height - _bottomHeight, _leftWidth, _bottomHeight); _ninePatchRegion.setRegionX((int)_leftWidth); _ninePatchRegion.setRegionWidth((int)(_textureRegion.getRegionWidth() - _leftWidth - _rightWidth)); draw(g, _ninePatchRegion, x + _leftWidth, y + height - _bottomHeight, width - _leftWidth - _rightWidth, _bottomHeight); _ninePatchRegion.setRegionX((int)(_textureRegion.getRegionWidth() - _rightWidth)); _ninePatchRegion.setRegionWidth((int)_rightWidth); draw(g, _ninePatchRegion, x + width - _rightWidth, y + height - _bottomHeight, _rightWidth, _bottomHeight); g.setTint(oldTint); }
private static void draw(org.mini2Dx.core.Graphics g, TextureRegion ninePatchRegion, float dstX, float dstY, float dstWidth, float dstHeight) { g.drawTextureRegion(ninePatchRegion, dstX, dstY, dstWidth, dstHeight); }