Okay I made kind of a place holder editor in C# a while back due to people being busy/lazy.
Now here is a video of it:
You can see the are 2 windows. One for the map and one for tools, tile selecting etc.
My issue is that even if the window with the map has no focus, when I switch tiles or whatever on the tool window the map window still thinks that you're clicking on the map window and lays tiles.
If you watch the beginning of the video you'll see this happen (in case I didn't explain it too well).
Anyone have any ideas on how I could work around this?
Thanks.
Re: C# Window Focus
Posted: Sun Mar 20, 2011 12:33 pm
by Ginto8
It looks like you're using the same WndProc for both windows, which is causing issues. However, if that's not it, you might also want to put some sort of check for whether or not the window has focus in each one's WndProc.
Re: C# Window Focus
Posted: Sun Mar 20, 2011 12:34 pm
by JesseGuarascia
Well as long as you're doing what the title says, you should be fine. With C# forms, I believe there is a way to tell if the window has focus. So in your procedure for clicking tiles on the map, you could have a nice little:
It depends on how you are integrating forms into your XNA project. From the looks of it you have an XNA game running with windows forms on top of it and I don't think XNA allows you to directly manipulate all the functions/attributes of window/forms that the Game class uses, so you can't do it the way Jesse suggested.
You'll have to make a reference from your Game1 object into a form instance to manipulate it.
//in your draw function
System.Windows.Forms.Form myForm = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(this.Window.Handle);
....
//a check before you draw a tile
if (myForm.Focused == true)
{
//draw your tiles
}
Re: C# Window Focus
Posted: Sun Mar 20, 2011 9:16 pm
by JesseGuarascia
krilik wrote:It depends on how you are integrating forms into your XNA project. From the looks of it you have an XNA game running with windows forms on top of it and I don't think XNA allows you to directly manipulate all the functions/attributes of window/forms that the Game class uses, so you can't do it the way Jesse suggested.
You'll have to make a reference from your Game1 object into a form instance to manipulate it.
I have very little experience with XNA, so I wasn't aware that form integration doesn't work the same way normal forms work. Never-the-less, I find having a literal copy of the form to be sort of pointless. A more proper approach (in my opinion anyways), would be to set up a global boolean of sorts, then just use that in your tile placement function. So when the form for selecting tiles has focus (using my code I posted earlier), you could set a boolean to true. Using that same boolean, the XNA portion for tile placement can decide to paint or not.
Although I'm sure krilik's would work just as fine, I don't like the idea of copying an entire form, just to tell if it has focus or not.
Re: C# Window Focus
Posted: Mon Mar 21, 2011 9:10 am
by N64vSNES
Once again.
I don't know where I'd be without you guys
Re: C# Window Focus
Posted: Mon Mar 21, 2011 9:10 pm
by krilik
JesseGuarascia wrote:I have very little experience with XNA, so I wasn't aware that form integration doesn't work the same way normal forms work. Never-the-less, I find having a literal copy of the form to be sort of pointless. A more proper approach (in my opinion anyways), would be to set up a global boolean of sorts, then just use that in your tile placement function. So when the form for selecting tiles has focus (using my code I posted earlier), you could set a boolean to true. Using that same boolean, the XNA portion for tile placement can decide to paint or not.
Although I'm sure krilik's would work just as fine, I don't like the idea of copying an entire form, just to tell if it has focus or not.
Yea as far as I know XNA won't allow you to modify the window the game runs in directly. Probably to prevent people from breaking the Xbox 360 version of their game. Its a bitch like that. They have other functions that will allow you to change the resolution and such to the game window, but its done through another object called a GraphicsDeviceManager, so you're very limited in what you can do.
So I think the only real way it can be accomplished is by passing a reference to a wrapper and manipulating it through that. Kind of dumb, and really inefficient, but C#'s garbage collection cleans up the object once the method is finished.
A better approach would be to design your tools in a Windows Form project and integrate an XNA control into a Windows Form and do it the way you suggest.