public Sprite(TextureRegion region) { Color = new Color(1f, 1f, 1f, 1f); SetRegion(region); SetSize(region.RegionWidth, region.RegionHeight); SetOrigin(Width / 2, Height / 2); }
public NinePatch(TextureRegion region, int left, int right, int top, int bottom) : this() { if (region == null) throw new ArgumentNullException("region"); int middleWidth = region.RegionWidth - left - right; int middleHeight = region.RegionHeight - top - bottom; TextureRegion[] patches = new TextureRegion[9]; if (top > 0) { if (left > 0) patches[TopLeft] = new TextureRegion(region, 0, 0, left, top); if (middleWidth > 0) patches[TopCenter] = new TextureRegion(region, left, 0, middleWidth, top); if (right > 0) patches[TopRight] = new TextureRegion(region, left + middleWidth, 0, right, top); } if (middleHeight > 0) { if (left > 0) patches[MiddleLeft] = new TextureRegion(region, 0, top, left, middleHeight); if (middleWidth > 0) patches[MiddleCenter] = new TextureRegion(region, left, top, middleWidth, middleHeight); if (right > 0) patches[MiddleRight] = new TextureRegion(region, left + middleWidth, top, right, middleHeight); } if (bottom > 0) { if (left > 0) patches[BottomLeft] = new TextureRegion(region, 0, top + middleHeight, left, bottom); if (middleWidth > 0) patches[BottomCenter] = new TextureRegion(region, left, top + middleHeight, middleWidth, bottom); if (right > 0) patches[BottomRight] = new TextureRegion(region, left + middleWidth, top + middleHeight, right, bottom); } // If split only vertical, move splits from right to center. if (left == 0 && middleWidth == 0) { patches[TopCenter] = patches[TopRight]; patches[MiddleCenter] = patches[MiddleRight]; patches[BottomCenter] = patches[BottomRight]; patches[TopRight] = null; patches[MiddleRight] = null; patches[BottomRight] = null; } // If split only horizontal, move splits from bottom to center. if (top == 0 && middleHeight == 0) { patches[MiddleLeft] = patches[BottomLeft]; patches[MiddleCenter] = patches[BottomCenter]; patches[MiddleRight] = patches[BottomRight]; patches[BottomLeft] = null; patches[BottomCenter] = null; patches[BottomRight] = null; } Load(patches); }
public void Draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { CheckValid(region.Texture); CheckState(region.Texture); if (_vertices.Length - _vBufferIndex < 4) { Flush(); } float worldOriginX = x + originX; float worldOriginY = y + originY; float fx = -originX; float fy = -originY; float fx2 = width - originX; float fy2 = height - originY; if (scaleX != 1 || scaleY != 1) { fx *= scaleX; fy *= scaleY; fx2 *= scaleX; fy2 *= scaleY; } float x1, y1; float x2, y2; float x3, y3; float x4, y4; if (rotation != 0) { float cos = (float)Math.Cos(rotation); float sin = (float)Math.Sin(rotation); x1 = cos * fx - sin * fy; y1 = sin * fx + cos * fy; x2 = cos * fx - sin * fy2; y2 = sin * fx + cos * fy2; x3 = cos * fx2 - sin * fy2; y3 = sin * fx2 + cos * fy2; x4 = cos * fx2 - sin * fy; y4 = sin * fx2 + cos * fy; } else { x1 = fx; y1 = fy; x2 = fx; y2 = fy2; x3 = fx2; y3 = fy2; x4 = fx2; y4 = fy; } x1 += worldOriginX; y1 += worldOriginY; x2 += worldOriginX; y2 += worldOriginY; x3 += worldOriginX; y3 += worldOriginY; x4 += worldOriginX; y4 += worldOriginY; float u = region.U; float v = region.V2; float u2 = region.U2; float v2 = region.V; Color color = Color.FromNonPremultiplied(Color.R, Color.G, Color.B, Color.A); _vertices[_vBufferIndex + 0] = new VertexPositionColorTexture(new Vector3(x1, y1, 0), color, new Vector2(u, v)); _vertices[_vBufferIndex + 1] = new VertexPositionColorTexture(new Vector3(x2, y2, 0), color, new Vector2(u, v2)); _vertices[_vBufferIndex + 2] = new VertexPositionColorTexture(new Vector3(x3, y3, 0), color, new Vector2(u2, v2)); _vertices[_vBufferIndex + 3] = new VertexPositionColorTexture(new Vector3(x4, y4, 0), color, new Vector2(u2, v)); _vBufferIndex += 4; }
public NinePatch(TextureRegion region, int left, int right, int top, int bottom) : this() { if (region == null) { throw new ArgumentNullException("region"); } int middleWidth = region.RegionWidth - left - right; int middleHeight = region.RegionHeight - top - bottom; TextureRegion[] patches = new TextureRegion[9]; if (top > 0) { if (left > 0) { patches[TopLeft] = new TextureRegion(region, 0, 0, left, top); } if (middleWidth > 0) { patches[TopCenter] = new TextureRegion(region, left, 0, middleWidth, top); } if (right > 0) { patches[TopRight] = new TextureRegion(region, left + middleWidth, 0, right, top); } } if (middleHeight > 0) { if (left > 0) { patches[MiddleLeft] = new TextureRegion(region, 0, top, left, middleHeight); } if (middleWidth > 0) { patches[MiddleCenter] = new TextureRegion(region, left, top, middleWidth, middleHeight); } if (right > 0) { patches[MiddleRight] = new TextureRegion(region, left + middleWidth, top, right, middleHeight); } } if (bottom > 0) { if (left > 0) { patches[BottomLeft] = new TextureRegion(region, 0, top + middleHeight, left, bottom); } if (middleWidth > 0) { patches[BottomCenter] = new TextureRegion(region, left, top + middleHeight, middleWidth, bottom); } if (right > 0) { patches[BottomRight] = new TextureRegion(region, left + middleWidth, top + middleHeight, right, bottom); } } // If split only vertical, move splits from right to center. if (left == 0 && middleWidth == 0) { patches[TopCenter] = patches[TopRight]; patches[MiddleCenter] = patches[MiddleRight]; patches[BottomCenter] = patches[BottomRight]; patches[TopRight] = null; patches[MiddleRight] = null; patches[BottomRight] = null; } // If split only horizontal, move splits from bottom to center. if (top == 0 && middleHeight == 0) { patches[MiddleLeft] = patches[BottomLeft]; patches[MiddleCenter] = patches[BottomCenter]; patches[MiddleRight] = patches[BottomRight]; patches[BottomLeft] = null; patches[BottomCenter] = null; patches[BottomRight] = null; } Load(patches); }
public Image(TextureRegion region) : this(new TextureRegionDrawable(region), Scaling.Stretch, Alignment.Center) { }
public TextureRegion(TextureRegion region, int x, int y, int width, int height) { SetRegion(region, x, y, width, height); }
public TextureRegion[,] Split(int tileWidth, int tileHeight) { int x = RegionX; int y = RegionY; int width = RegionWidth; int height = RegionHeight; int rows = height / tileHeight; int cols = width / tileWidth; int startX = x; TextureRegion[,] tiles = new TextureRegion[rows, cols]; for (int row = 0; row < rows; rows++, y += tileHeight) { x = startX; for (int col = 0; col < cols; col++, x += tileWidth) tiles[row, col] = new TextureRegion(Texture, x, y, tileWidth, tileHeight); } return tiles; }
public void SetRegion(TextureRegion region) { Texture = region.Texture; SetRegion(region._u, region._v, region._u2, region._v2); }
public void Draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { CheckValid(region.Texture); CheckState(region.Texture); if (_vertices.Length - _vBufferIndex < 4) Flush(); float worldOriginX = x + originX; float worldOriginY = y + originY; float fx = -originX; float fy = -originY; float fx2 = width - originX; float fy2 = height - originY; if (scaleX != 1 || scaleY != 1) { fx *= scaleX; fy *= scaleY; fx2 *= scaleX; fy2 *= scaleY; } float x1, y1; float x2, y2; float x3, y3; float x4, y4; if (rotation != 0) { float cos = (float)Math.Cos(rotation); float sin = (float)Math.Sin(rotation); x1 = cos * fx - sin * fy; y1 = sin * fx + cos * fy; x2 = cos * fx - sin * fy2; y2 = sin * fx + cos * fy2; x3 = cos * fx2 - sin * fy2; y3 = sin * fx2 + cos * fy2; x4 = cos * fx2 - sin * fy; y4 = sin * fx2 + cos * fy; } else { x1 = fx; y1 = fy; x2 = fx; y2 = fy2; x3 = fx2; y3 = fy2; x4 = fx2; y4 = fy; } x1 += worldOriginX; y1 += worldOriginY; x2 += worldOriginX; y2 += worldOriginY; x3 += worldOriginX; y3 += worldOriginY; x4 += worldOriginX; y4 += worldOriginY; float u = region.U; float v = region.V2; float u2 = region.U2; float v2 = region.V; Color color = Color.FromNonPremultiplied(Color.R, Color.G, Color.B, Color.A); _vertices[_vBufferIndex + 0] = new VertexPositionColorTexture(new Vector3(x1, y1, 0), color, new Vector2(u, v)); _vertices[_vBufferIndex + 1] = new VertexPositionColorTexture(new Vector3(x2, y2, 0), color, new Vector2(u, v2)); _vertices[_vBufferIndex + 2] = new VertexPositionColorTexture(new Vector3(x3, y3, 0), color, new Vector2(u2, v2)); _vertices[_vBufferIndex + 3] = new VertexPositionColorTexture(new Vector3(x4, y4, 0), color, new Vector2(u2, v)); _vBufferIndex += 4; }
public TextureRegion(TextureRegion region) { SetRegion(region); }
public static TextureRegion[,] Split(TextureContext texture, int tileWidth, int tileHeight) { TextureRegion region = new TextureRegion(texture); return(region.Split(tileWidth, tileHeight)); }
public void SetRegion(TextureRegion region, int x, int y, int width, int height) { Texture = region.Texture; SetRegion(region.RegionX + x, region.RegionY + y, width, height); }
private void Load(TextureRegion[] patches) { Color color = Color.White; if (patches[BottomLeft] != null) { _bottomLeft = Add(patches[BottomLeft], color); LeftWidth = patches[BottomLeft].RegionWidth; BottomHeight = patches[BottomLeft].RegionHeight; } if (patches[BottomCenter] != null) { _bottomCenter = Add(patches[BottomCenter], color); MiddleWidth = Math.Max(MiddleWidth, patches[BottomCenter].RegionWidth); BottomHeight = Math.Max(BottomHeight, patches[BottomCenter].RegionHeight); } if (patches[BottomRight] != null) { _bottomRight = Add(patches[BottomRight], color); RightWidth = Math.Max(RightWidth, patches[BottomRight].RegionWidth); BottomHeight = Math.Max(BottomHeight,patches[BottomRight].RegionHeight); } if (patches[MiddleLeft] != null) { _middleLeft = Add(patches[MiddleLeft], color); LeftWidth = Math.Max(LeftWidth, patches[MiddleLeft].RegionWidth); MiddleHeight = Math.Max(MiddleHeight, patches[MiddleLeft].RegionHeight); } if (patches[MiddleCenter] != null) { _middleCenter = Add(patches[MiddleCenter], color); MiddleWidth = Math.Max(MiddleWidth, patches[MiddleCenter].RegionWidth); MiddleHeight = Math.Max(MiddleHeight, patches[MiddleCenter].RegionHeight); } if (patches[MiddleRight] != null) { _middleRight = Add(patches[MiddleRight], color); RightWidth = Math.Max(RightWidth, patches[MiddleRight].RegionWidth); MiddleHeight = Math.Max(MiddleHeight, patches[MiddleRight].RegionHeight); } if (patches[TopLeft] != null) { _topLeft = Add(patches[TopLeft], color); LeftWidth = Math.Max(LeftWidth, patches[TopLeft].RegionWidth); TopHeight = Math.Max(TopHeight, patches[TopLeft].RegionHeight); } if (patches[TopCenter] != null) { _topCenter = Add(patches[TopCenter], color); MiddleWidth = Math.Max(MiddleWidth, patches[TopCenter].RegionWidth); TopHeight = Math.Max(TopHeight, patches[TopCenter].RegionHeight); } if (patches[TopRight] != null) { _topRight = Add(patches[TopRight], color); RightWidth = Math.Max(RightWidth, patches[TopRight].RegionWidth); TopHeight = Math.Max(TopHeight, patches[TopRight].RegionHeight); } if (_index < _vertices.Length) { VertexPositionColorTexture[] newVertices = new VertexPositionColorTexture[_index]; Array.Copy(_vertices, newVertices, _index); _vertices = newVertices; } }
private int Add(TextureRegion region, Color color) { if (Texture == null) Texture = region.Texture; else if (Texture != region.Texture) throw new ArgumentException("All regions must be from the same texture"); float u = region.U; float v = region.V2; float u2 = region.U2; float v2 = region.V; _vertices[_index + 0].Color = color; _vertices[_index + 0].TextureCoordinate = new Vector2(u, v); _vertices[_index + 1].Color = color; _vertices[_index + 1].TextureCoordinate = new Vector2(u, v2); _vertices[_index + 2].Color = color; _vertices[_index + 2].TextureCoordinate = new Vector2(u2, v2); _vertices[_index + 3].Color = color; _vertices[_index + 3].TextureCoordinate = new Vector2(u2, v); _index += 4; return _index - 4; }
public void Draw(TextureRegion region, float x, float y, float width, float height) { CheckValid(region.Texture); CheckState(region.Texture); if (_vertices.Length - _vBufferIndex < 4) Flush(); float fx2 = x + width; float fy2 = y + height; float u = region.U; float v = region.V2; float u2 = region.U2; float v2 = region.V; Color color = Color.FromNonPremultiplied(Color.R, Color.G, Color.B, Color.A); _vertices[_vBufferIndex + 0] = new VertexPositionColorTexture(new Vector3(x, y, 0), color, new Vector2(u, v)); _vertices[_vBufferIndex + 1] = new VertexPositionColorTexture(new Vector3(x, fy2, 0), color, new Vector2(u, v2)); _vertices[_vBufferIndex + 2] = new VertexPositionColorTexture(new Vector3(fx2, fy2, 0), color, new Vector2(u2, v2)); _vertices[_vBufferIndex + 3] = new VertexPositionColorTexture(new Vector3(fx2, y, 0), color, new Vector2(u2, v)); _vBufferIndex += 4; }
public static TextureRegion[,] Split(TextureContext texture, int tileWidth, int tileHeight) { TextureRegion region = new TextureRegion(texture); return region.Split(tileWidth, tileHeight); }
public BitmapFont(GraphicsDevice device, string fontFile, TextureRegion region, bool flip) : this(device, new BitmapFontData(fontFile, flip), region, true) { }
protected override void InitializeCore() { ShowDebug = true; //Debugger.Launch(); _spriteBatch = new GdxSpriteBatch(Context.GraphicsDevice); _skin = new Skin(Context.GraphicsDevice, "Data/uiskin.json"); _texture1 = new TextureContext(Context.GraphicsDevice, "Data/badlogicsmall.jpg", true); _texture2 = new TextureContext(Context.GraphicsDevice, "Data/badlogic.jpg", true); TextureRegion image = new TextureRegion(_texture1); TextureRegion imageFlipped = new TextureRegion(image); imageFlipped.Flip(true, true); TextureRegion image2 = new TextureRegion(_texture2); _stage = new Stage(Context.GraphicsDevice.Viewport.Width, Context.GraphicsDevice.Viewport.Height, true, Context.GraphicsDevice); Context.Input.Processor = _stage; ImageButtonStyle style = new ImageButtonStyle(_skin.Get<ButtonStyle>()) { ImageUp = new TextureRegionDrawable(image), ImageDown = new TextureRegionDrawable(imageFlipped), }; ImageButton iconButton = new ImageButton(style); Button buttonMulti = new TextButton("Multi\nLine\nToggle", _skin, "toggle") { IsToggle = true, }; Button imgButton = new Button(new Image(image), _skin); Button imgToggleButton = new Button(new Image(image), _skin, "toggle") { IsToggle = true, }; Label myLabel = new Label("This is some text.", _skin); myLabel.TextWrapping = true; Table t = new Table(); t.Row(); t.Add(myLabel); t.Layout(); CheckBox checkbox = new CheckBox("Check me", _skin); Slider slider = new Slider(0, 10, 1, false, _skin); TextField textField = new TextField("", _skin) { MessageText = "Click here!", }; SelectBox dropdown = new SelectBox(selectEntries, _skin); Image imageActor = new Image(image2); ScrollPane scrollPane = new ScrollPane(imageActor); MonoGdx.Scene2D.UI.List list = new MonoGdx.Scene2D.UI.List(listEntries, _skin); ScrollPane scrollPane2 = new ScrollPane(list, _skin); //scrollPane2.FlickScroll = false; SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, _skin, "default-horizontal"); _fpsLabel = new Label("fps:", _skin); Label passwordLabel = new Label("Textfield in password mode: ", _skin); TextField passwordField = new TextField("", _skin) { MessageText = "password", PasswordCharacter = '*', IsPasswordMode = true, }; Window window = new Window("Dialog", _skin); window.SetPosition(0, 0); window.Defaults().SpaceBottom = 10; window.Row().Configure.Fill().ExpandX(); window.Add(iconButton); window.Add(buttonMulti); window.Add(imgButton); window.Add(imgToggleButton); window.Row(); window.Add(checkbox); window.Add(slider).Configure.MinWidth(100).FillX().Colspan(3); window.Row(); window.Add(dropdown).Configure.MinWidth(100).FillX(); window.Add(textField).Configure.MinWidth(100).ExpandX().FillX().Colspan(3); window.Row(); window.Add(splitPane).Configure.Fill().Expand().Colspan(4).MaxHeight(200); window.Row(); window.Add(passwordLabel).Configure.Colspan(2); window.Add(passwordField).Configure.MinWidth(100).ExpandX().FillX().Colspan(2); window.Pack(); /*textField.KeyUp += (field, c) => { if (c == '\n') field.OnscreenKeyboard.Show(false); };*/ _stage.AddActor(window); MonoGdx.Scene2D.UI.List list2 = new MonoGdx.Scene2D.UI.List(listEntries, _skin); ScrollPane scrollPane22 = new ScrollPane(list2, _skin); Window window2 = new Window("ScrollPane", _skin); window2.SetPosition(300, 300); window2.Defaults().SpaceBottom = 10; window2.Row().Configure.Fill().ExpandX(); window2.Add(scrollPane22).Configure.MaxHeight(250).MaxWidth(150); window2.Pack(); _stage.AddActor(window2); }
public AtlasRegion AddRegion(string name, TextureRegion textureRegion) { return(AddRegion(name, textureRegion.Texture, textureRegion.RegionX, textureRegion.RegionY, textureRegion.RegionWidth, textureRegion.RegionHeight)); }
public TextureRegionDrawable(TextureRegion region) { Region = region; }
public Sprite(TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight) { Color = new Color(1f, 1f, 1f, 1f); SetRegion(region, srcX, srcY, srcWidth, srcHeight); SetSize(Math.Abs(srcWidth), Math.Abs(srcHeight)); SetOrigin(Width / 2, Height / 2); }
public NinePatch(TextureRegion region, Color color) : this(region) { Color = color; }
public AtlasRegion AddRegion(string name, TextureRegion textureRegion) { return AddRegion(name, textureRegion.Texture, textureRegion.RegionX, textureRegion.RegionY, textureRegion.RegionWidth, textureRegion.RegionHeight); }
public void Draw(TextureRegion region, float x, float y) { Draw(region, x, y, region.RegionWidth, region.RegionHeight); }
public TiledDrawable(TextureRegion region) : base(region) { }