Microsoft.Xna.Framework.Rectangle vs. System.Drawing.Rectangle
I noticed that the XNA framework Rectangle does not have a Contains method like the System.Drawing.Rectangle.
http://msdn2.microsoft.com/en-us/library/system.drawing.rectangle.contains.aspx
I found this function handy for handling mouse clicks on my 2D tile map. Is this by design, a bug, or yet to be implemented?
Thanks,
Trey
[540 byte] By [
TreyTro] at [2007-12-24]
How about adding the rest of the missing System.Drawing.Rectangle methods (Inflate, Intersect, IntersectWith, Offset, Union) as well? I've added a suggestion on this already.
Greetings,
I posted a suggestion for the Contains function on Connection before finding this post. Sorry XNA team.
Here is what I am doing to solve the Rectangle.Contains overload for a X and Y mouse point. I am using it in a Button class so the button object has a Class level member called ButtonRect. But this function could be public in a helper class that has a Rectangle as a parameter as well.
// helper until XNA supports
private bool Contains(int x, int y){
if ((x > this.ButtonRect.Left && x < this.ButtonRect.Right) &&(y <
this.ButtonRect.Bottom && y > this.ButtonRect.Top))return true;elsereturn false;}
I have been building today a Menu component like Mitch shows in his Components Demo. I am about 90% compled. I am assuming that the XNA team will provide one in the final release, but I do not want to wait.
Anyway, not sure if my code is the correct way, but it seems to work.
Micah