Position relative au parent
This commit is contained in:
parent
3691ac3bf1
commit
14150b7923
|
@ -83,7 +83,8 @@ namespace Exemple
|
|||
Github = GuiManager.Add(new TextField(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 2), null, basicFont, new MyMonoGame.Colors(Color.White, Color.WhiteSmoke, Color.LightGray), Label.textAlign.centerCenter, "Search on Github", SearchGithub, true, Home));
|
||||
GuiManager.Add(new BoxLabelButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4 + 50, 200, 40), boxSprite, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "About", basicFont, new MyMonoGame.Colors(Color.Black, Color.Black, Color.White), Label.textAlign.centerCenter, GoAbout, true, Home));
|
||||
|
||||
About = GuiManager.Add(new Box(new Rectangle(200, 100, ScreenWidth - 400, ScreenHeight - 200), boxSprite, new MyMonoGame.Colors(Color.LightGray, Color.White), false));
|
||||
About = GuiManager.Add(new Element(false));
|
||||
GuiManager.Add(new Box(new Rectangle(200, 100, ScreenWidth - 400, ScreenHeight - 200), boxSprite, new MyMonoGame.Colors(Color.LightGray, Color.White), true, About));
|
||||
GuiManager.Add(new Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4), "By Sheychen", basicFont, new MyMonoGame.Colors(Color.Red, Color.OrangeRed), Label.textAlign.centerCenter, true, About));
|
||||
GuiManager.Add(new BoxLabelButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight /2 - 100, 200, 40), boxSprite, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "My Website", basicFont, new MyMonoGame.Colors(Color.Black, Color.Black, Color.White), Label.textAlign.centerCenter, OpenWebsite, true, About));
|
||||
GuiManager.Add(new BoxLabelButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight /2 - 50, 200, 40), boxSprite, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "Show on GitHub", basicFont, new MyMonoGame.Colors(Color.Black, Color.Black, Color.White), Label.textAlign.centerCenter, OpenGithub, true, About));
|
||||
|
|
|
@ -19,27 +19,29 @@ namespace MyMonoGame.GUI
|
|||
parent = parentLink;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
Color backColor = _isFocus ? _colors._focus : (_isHover ? _colors._hover : _colors._normal);
|
||||
|
||||
Rectangle pos = new Rectangle(_pos.X + relative.X, _pos.Y + relative.Y, _pos.Width, _pos.Height);
|
||||
|
||||
int leftWidth = _backSprites.topLeft.Width;
|
||||
int rightWidth = _backSprites.topRight.Width;
|
||||
int centerWidth = _pos.Width - leftWidth - rightWidth;
|
||||
int centerWidth = pos.Width - leftWidth - rightWidth;
|
||||
|
||||
int topHeight = _backSprites.topLeft.Height;
|
||||
int bottomHeight = _backSprites.bottomLeft.Height;
|
||||
int centerHeight = _pos.Height - topHeight - bottomHeight;
|
||||
int centerHeight = pos.Height - topHeight - bottomHeight;
|
||||
|
||||
spriteBatch.Draw(_backSprites.topLeft, new Rectangle(_pos.X, _pos.Y, leftWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.topCenter, new Rectangle(_pos.X + leftWidth, _pos.Y, centerWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.topRight, new Rectangle(_pos.X + _pos.Width - rightWidth, _pos.Y, rightWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerLeft, new Rectangle(_pos.X, _pos.Y + topHeight, leftWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerCenter, new Rectangle(_pos.X + leftWidth, _pos.Y + topHeight, centerWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerRight, new Rectangle(_pos.X + _pos.Width - rightWidth, _pos.Y + topHeight, rightWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomLeft, new Rectangle(_pos.X, _pos.Y + _pos.Height - bottomHeight, leftWidth, bottomHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomCenter, new Rectangle(_pos.X + leftWidth, _pos.Y + _pos.Height - bottomHeight, centerWidth, bottomHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomRight, new Rectangle(_pos.X + _pos.Width - rightWidth, _pos.Y + _pos.Height - bottomHeight, rightWidth, bottomHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.topLeft, new Rectangle(pos.X, pos.Y, leftWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.topCenter, new Rectangle(pos.X + leftWidth, pos.Y, centerWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.topRight, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y, rightWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerLeft, new Rectangle(pos.X, pos.Y + topHeight, leftWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerCenter, new Rectangle(pos.X + leftWidth, pos.Y + topHeight, centerWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerRight, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y + topHeight, rightWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomLeft, new Rectangle(pos.X, pos.Y + pos.Height - bottomHeight, leftWidth, bottomHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomCenter, new Rectangle(pos.X + leftWidth, pos.Y + pos.Height - bottomHeight, centerWidth, bottomHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomRight, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y + pos.Height - bottomHeight, rightWidth, bottomHeight), backColor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,9 +28,9 @@ namespace MyMonoGame.GUI
|
|||
_button.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
base.Draw(spriteBatch, relative);
|
||||
|
||||
if (_isFocus)
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ namespace MyMonoGame.GUI
|
|||
}
|
||||
}
|
||||
|
||||
_button.Draw(spriteBatch);
|
||||
_button.Draw(spriteBatch, relative);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace MyMonoGame.GUI
|
|||
_label.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
_label.Draw(spriteBatch);
|
||||
base.Draw(spriteBatch, relative);
|
||||
_label.Draw(spriteBatch, relative);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,9 +27,9 @@ namespace MyMonoGame.GUI
|
|||
_button.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
base.Draw(spriteBatch, relative);
|
||||
|
||||
if (_isFocus)
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ namespace MyMonoGame.GUI
|
|||
}
|
||||
}
|
||||
|
||||
_button.Draw(spriteBatch);
|
||||
_button.Draw(spriteBatch, relative);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ namespace MyMonoGame.GUI
|
|||
}
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
if (_isFocus)
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace MyMonoGame.GUI
|
|||
return _pos.Contains(x, y);
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
public virtual void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -49,6 +49,11 @@ namespace MyMonoGame.GUI
|
|||
else { _isHover = Contain(x, y); }
|
||||
}
|
||||
|
||||
public Vector Pos()
|
||||
{
|
||||
return new Vector(_pos.X, _pos.Y);
|
||||
}
|
||||
|
||||
public virtual void Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
|
|
@ -148,10 +148,10 @@ namespace MyMonoGame.GUI
|
|||
}
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
Color color = _isFocus ? _colors._focus : (_isHover ? _colors._hover : _colors._normal);
|
||||
spriteBatch.DrawString(_font, _text, new Vector2(_vector.X, _vector.Y), color);
|
||||
spriteBatch.DrawString(_font, _text, new Vector2(_vector.X + relative.X, _vector.Y + relative.Y), color);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace MyMonoGame.GUI
|
|||
public void Update()
|
||||
{
|
||||
oldState = newState;
|
||||
newState = Microsoft.Xna.Framework.Input.Mouse.GetState();
|
||||
newState = Mouse.GetState();
|
||||
mouseX = newState.X;
|
||||
mouseY = newState.Y;
|
||||
Utilities.Mouse nowState;
|
||||
|
@ -54,9 +54,16 @@ namespace MyMonoGame.GUI
|
|||
}
|
||||
}
|
||||
|
||||
private bool IsEnable(ElementLink elementLink)
|
||||
public bool IsEnable(ElementLink elementLink)
|
||||
{
|
||||
Vector temp;
|
||||
return IsEnable(elementLink ,out temp);
|
||||
}
|
||||
|
||||
private bool IsEnable(ElementLink elementLink, out Vector relative)
|
||||
{
|
||||
bool isEnable = elements[elementLink].isEnable;
|
||||
relative = new Vector();
|
||||
if (isEnable)
|
||||
{
|
||||
ElementLink actualLink = elementLink;
|
||||
|
@ -71,6 +78,7 @@ namespace MyMonoGame.GUI
|
|||
isEnable = parent.isEnable;
|
||||
if (isEnable)
|
||||
{
|
||||
relative.Add(parent.Pos());
|
||||
actualLink = parentLink;
|
||||
}
|
||||
}
|
||||
|
@ -142,9 +150,10 @@ namespace MyMonoGame.GUI
|
|||
{
|
||||
foreach (ElementLink elementLink in elements.Keys.ToArray())
|
||||
{
|
||||
if (IsEnable(elementLink))
|
||||
Vector relative;
|
||||
if (IsEnable(elementLink, out relative))
|
||||
{
|
||||
elements[elementLink].Draw(spriteBatch);
|
||||
elements[elementLink].Draw(spriteBatch, relative);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ namespace MyMonoGame.GUI
|
|||
parent = parentLink;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
Color backColor = _isFocus ? _colors._focus : (_isHover ? _colors._hover : _colors._normal);
|
||||
spriteBatch.Draw(_sprite, _pos, backColor);
|
||||
spriteBatch.Draw(_sprite, new Rectangle(_pos.X + relative.X, _pos.Y + relative.Y, _pos.Width, _pos.Height), backColor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,9 +26,9 @@ namespace MyMonoGame.GUI
|
|||
button.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, Vector relative)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
base.Draw(spriteBatch, relative);
|
||||
|
||||
if (_isFocus)
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ namespace MyMonoGame.GUI
|
|||
}
|
||||
}
|
||||
|
||||
button.Draw(spriteBatch);
|
||||
button.Draw(spriteBatch, relative);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,10 +5,28 @@
|
|||
public int X;
|
||||
public int Y;
|
||||
|
||||
public Vector()
|
||||
{
|
||||
X = 0;
|
||||
Y = 0;
|
||||
}
|
||||
|
||||
public Vector(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public void Add(Vector v)
|
||||
{
|
||||
X += v.X;
|
||||
Y += v.Y;
|
||||
}
|
||||
|
||||
public void Add(int x, int y)
|
||||
{
|
||||
X += x;
|
||||
Y += y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue