Irrlicht in a WinForm!
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am
I build a WindowApplication1 with C#, and then make irr draw in a picturebox in the center of the form.
But when I add the FPS camera, I can never get the key&mouse control anymore. then where should I set that "InputReceiverEnabled" property?! I can't! I can't do that unless I modify the Irrlicht's source code in WndProc in CIrrDeviceWin32.cpp file. But I haven't tried that yet.
What I want is:
I can have the control of the key & mouse, and when I press a hot key, I will enter the FPS camera mode, and when I press another hot key, I will exit the FPS camera mode, and the form regain the control and could receive event from key and mouse again.
I am making the level editor and this problem really bother me a lot!
I wonder if anyone succeeded without modifying Irr's src?
But when I add the FPS camera, I can never get the key&mouse control anymore. then where should I set that "InputReceiverEnabled" property?! I can't! I can't do that unless I modify the Irrlicht's source code in WndProc in CIrrDeviceWin32.cpp file. But I haven't tried that yet.
What I want is:
I can have the control of the key & mouse, and when I press a hot key, I will enter the FPS camera mode, and when I press another hot key, I will exit the FPS camera mode, and the form regain the control and could receive event from key and mouse again.
I am making the level editor and this problem really bother me a lot!
I wonder if anyone succeeded without modifying Irr's src?
michael520,
If any control on the WinForm has focus, then *ALL* events are sent to the WinForm and not Irrlicht Device. Odds are, all of your events are being handled by the WinForm event handler and never passed to IrrlichtDevice. Add a On KeyPress event to your form to see if your WinForm is capturing your events instead of the IrrlichtDevice.
Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).
If any control on the WinForm has focus, then *ALL* events are sent to the WinForm and not Irrlicht Device. Odds are, all of your events are being handled by the WinForm event handler and never passed to IrrlichtDevice. Add a On KeyPress event to your form to see if your WinForm is capturing your events instead of the IrrlichtDevice.
Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am
Also, even when I use common AddCameraSceneNode(), the form can't receive KeyPress event:
So I found in Irrlicht's source, in WndProc() in CIrrDeviceWin32.cpp:
So, we can see that irr will send all event to those scenenode(cameras), and then return zero, not return DefWindowProc()!@!!
I think this is a big imperfect of Irrlicht.
Code: Select all
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode) {
case Keys.F9:
MessageBox.Show("F9 pressed");
break;
default:
break;
}
}
Code: Select all
case WM_KEYDOWN:
{
event.EventType = irr::EET_KEY_INPUT_EVENT;
event.KeyInput.Key = (irr::EKEY_CODE)wParam;
event.KeyInput.PressedDown = true;
dev = getDeviceFromHWnd(hWnd);
BYTE allKeys[256];
WORD KeyAsc=0;
GetKeyboardState(allKeys);
ToAscii(wParam,lParam,allKeys,&KeyAsc,0);
event.KeyInput.Shift = ((allKeys[VK_SHIFT] & 0x80)!=0);
event.KeyInput.Control = ((allKeys[VK_CONTROL] & 0x80)!=0);
event.KeyInput.Char = KeyAsc; //KeyAsc >= 0 ? KeyAsc : 0;
if (dev)
dev->postEventFromUser(event);
return 0;
}
//other event has familiar processing.
I think this is a big imperfect of Irrlicht.
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am
Shurijo, in some applications, we do need to put Irr draw in only a part of a form, and some button/controls in other part. And most of time, putting irr in a picturebox or panel is very convenient for application such as level editor, not games.
Have you ever used IrrEdit? you may understand what I am describing through that.
Have you ever used IrrEdit? you may understand what I am describing through that.
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am
I've used IrrEdit (Niko is using C++ now instead of C#, maybe you can ask for his C# source code??), but I don't use it right now (I need it to support TerrainSceneNodes for my app).
I understand what you are trying to do and I hope you figure it out (because I'd like to eventually get things working that way, too). I'm using the full IrrlichtDevice window as my main game window and IrrlichtDevice in a PictureBox on my main menu WinForm (for character selection - allows user to select model/texture, etc.). For interacting with the device in the picturebox, I'm only capturing events from the WinForm (such as rotate character, etc.).
In one of my much eariler attempts, I made a map editor (just like your level editor) and got frustrated with having to manage the events on both WinForm and IrrlichtDevice. So I just went to a IrrlichtWindow for that with a separate WinForm with my tool bar (think how Photoshop or GIMP has multiple floating menu/dialogs that you can drag away from the main window). That way, I didn't have to mess with sending the right event to the right eventhandler (all events on that window were recieved by IrrlichtDevice) and all WinForms.UIControl events were handled by my other dialogs and sent to my map irrlichtWindow.
I understand what you are trying to do and I hope you figure it out (because I'd like to eventually get things working that way, too). I'm using the full IrrlichtDevice window as my main game window and IrrlichtDevice in a PictureBox on my main menu WinForm (for character selection - allows user to select model/texture, etc.). For interacting with the device in the picturebox, I'm only capturing events from the WinForm (such as rotate character, etc.).
In one of my much eariler attempts, I made a map editor (just like your level editor) and got frustrated with having to manage the events on both WinForm and IrrlichtDevice. So I just went to a IrrlichtWindow for that with a separate WinForm with my tool bar (think how Photoshop or GIMP has multiple floating menu/dialogs that you can drag away from the main window). That way, I didn't have to mess with sending the right event to the right eventhandler (all events on that window were recieved by IrrlichtDevice) and all WinForms.UIControl events were handled by my other dialogs and sent to my map irrlichtWindow.
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am
I am thinking about how to modify Irr's message processing routines, and make it more friendly for applications such as level editor etc with other window gui elements in the same form...
In fact, this problem exist both in C++ and C# because they both have the same WndProc() in Irrlicht.dll.
It may be a hard job...
In fact, this problem exist both in C++ and C# because they both have the same WndProc() in Irrlicht.dll.
It may be a hard job...
I think thats a good idea. I'd love an OverrideKeyPress=true property of the IrrlichtDevice that would ignore it's handle's events (if handle != null).michael520 wrote:I am thinking about how to modify Irr's message processing routines, and make it more friendly for applications such as level editor etc with other window gui elements in the same form...
In fact, this problem exist both in C++ and C# because they both have the same WndProc() in Irrlicht.dll.
It may be a hard job...
All of the tutorials (with the exception of the WinForm tutorial) use an IrrlichtDevice without placing it on a .NET WinForm.Ros wrote:shurijo
say:How? where i can look example of code?Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am
I don't need console startRos wrote:
shurijo
say:
Quote:
Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).
How? where i can look example of code?
All of the tutorials (with the exception of the WinForm tutorial) use an IrrlichtDevice without placing it on a .NET WinForm.
I need WinForm start without console.