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.
C# Window Focus
Moderator: Coders of Rage
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: C# Window Focus
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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
-
- Chaos Rift Cool Newbie
- Posts: 70
- Joined: Mon Dec 13, 2010 10:55 pm
Re: C# Window Focus
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:
That should fix your problem.
Code: Select all
if (mapWindow.hasFocus()){
// Draw tiles
}
-- Jesse Guarascia
I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
-
- Chaos Rift Newbie
- Posts: 25
- Joined: Sat Apr 18, 2009 11:24 pm
- Favorite Gaming Platforms: SNES,PS1
Re: C# Window Focus
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.
You'll have to make a reference from your Game1 object into a form instance to manipulate it.
Code: Select all
//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
}
-
- Chaos Rift Cool Newbie
- Posts: 70
- Joined: Mon Dec 13, 2010 10:55 pm
Re: C# Window Focus
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.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.
An example would be something like:
TileSelectForm.cs:
Code: Select all
if (this.hasFocus()){
// Set the global boolean to true
selectFormHasFocus = true;
}
Code: Select all
if (!selectFormHasFocus){
// Paint tiles
}
-- Jesse Guarascia
I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
Re: C# Window Focus
Once again.
I don't know where I'd be without you guys
I don't know where I'd be without you guys
-
- Chaos Rift Newbie
- Posts: 25
- Joined: Sat Apr 18, 2009 11:24 pm
- Favorite Gaming Platforms: SNES,PS1
Re: C# Window Focus
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.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.
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.