I am rendering my game in a Winform in the same way as done in this sample: WinForms Series 1: Graphics Device
In my game I have some object, for example a rectangle that I can already put and move, in my game world, once created. My project here is a level-editor.
What I want to do is to make every object "sizable" or "scalable" (sorry if this isn't the correct word) in the same way as done in every software we commonly use, I mean:
I have a class like:
public abstract class GameObject
{
protected Vector2 position_ = Vector2.Zero;
protected float rotation_ = 0.0f;
protected Vector2 scale_ = Vector2.One;
protected float depth_ = 0.0f;
protected bool is_passable_ = true;
protected GameObject(
Vector2 starting_position)
{
this.position_ = starting_position;
}
[DisplayName("Position")]
public virtual Vector2 Position
{
get { return position_; }
set { position_ = value; }
}
[BrowsableAttribute(false)]
public abstract Rectangle PositionRectangle
{
get;
}
[BrowsableAttribute(false)]
public abstract Rectangle SelectionRectangle
{
get;
}
[DisplayName("Scale")]
public abstract Vector2 Scale
{
get;
set;
}
[BrowsableAttribute(false)]
public virtual float Depth
{
get { return depth_; }
set { depth_ = value; }
}
[DisplayName("IsPassable?")]
public bool IsPassable
{
get { return is_passable_; }
set { is_passable_ = value; }
}
[BrowsableAttribute(false)]
public abstract Vector2 TextureSize
{
get;
}
public abstract void Update(GameTime gameTime);
public abstract void Draw(SpriteBatch spriteBatch);
}
Once the class is instantiated, inside the form I thought to do something like: (gameWrapper is the control created with the sample to draw the game inside the form)
private void gameWrapper_MouseClick_1(object sender, MouseEventArgs e)
{
Vector2 mouse_xy = new Vector2(e.Location.X, e.Location.Y);
GameObject obj = gameWrapper.GetObjectByPosition(mouse_xy);
propertyGrid1.SelectedObject = obj;
if (obj != null)
gameWrapper.SelectObject(obj);
else gameWrapper.Unselect();
propertyGrid1.Refresh();
}
Inside gameWrapper:
public SelectObject(GameObject obj)
{
List<Vector2> 4verticesList = new List();
//
// Code to add 4 vertices coordinates of the SelectionRectangle to 4verticesList
//
foreach (Vector2 vertex_xy in 4VerticesList)
DrawLittleRectangle(vertex_xy);
}
This is just what I thought to do. Draw little buttons/rectangles with a function and then handle clicks to them.
Is there already written some code to achieve this behaviour? Actually I'm not worried about how the object will resize, but just to the estetic buttons.