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 MonoGameNinePatch(TextureRegion texture, int left, int right, int top, int bottom) { _textureRegion = texture; _topHeight = top; _leftWidth = left; _middleWidth = _textureRegion.getRegionWidth() - right - left; _rightWidth = right; _middleHeight = _textureRegion.getRegionHeight() - top - bottom; _bottomHeight = bottom; _ninePatchRegion = new MonoGameTextureRegion(_textureRegion); _textureRegionX = _textureRegion.getRegionX(); _textureRegionY = _textureRegion.getRegionY(); _rightX = _textureRegion.getRegionWidth() - right; _bottomY = _textureRegion.getRegionHeight() - bottom; }
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); }
public TextureRegion[][] split(int tileWidth, int tileHeight) { var x = getRegionX(); var y = getRegionY(); var width = _regionWidth; var height = _regionHeight; var rows = height / tileHeight; var cols = width / tileWidth; var startX = x; var tiles = new TextureRegion[rows][]; for (var row = 0; row < rows; row++, y += tileHeight) { tiles[row] = new TextureRegion[cols]; x = startX; for (var col = 0; col < cols; col++, x += tileWidth) { tiles[row][col] = new MonoGameTextureRegion(_texture, x, y, tileWidth, tileHeight); } } return(tiles); }