conchyliferous
24-02-2010 08:39:03
I have made a user (custom) control to host (embed) my RenderWindow. (The user control is used to draw graphics in a portion of a larger Form filled with controls).
I have problems parsing mouse events after I apply the RenderWindow.
If I don't initialize the RenderWindow everything works as expected. If initialized it seams to steal the mouse events. I can not even focus the user control using the mouse. I can however TAB to the user control to gain focus, and then the keyboard events fire as expected.
So, how can I get the mouse events through the RenderWindow? Are there any other options? Source code is welcome.
Here is a simplified version of my code:
I have problems parsing mouse events after I apply the RenderWindow.
If I don't initialize the RenderWindow everything works as expected. If initialized it seams to steal the mouse events. I can not even focus the user control using the mouse. I can however TAB to the user control to gain focus, and then the keyboard events fire as expected.
So, how can I get the mouse events through the RenderWindow? Are there any other options? Source code is welcome.
Here is a simplified version of my code:
public partial class MogrePanel : UserControl
{
Root mogreRoot;
RenderWindow mogreWindow;
Camera cam;
public MogrePanel()
{
InitializeComponent();
// To make control focusable.
SetStyle(ControlStyles.Selectable, true);
// Define input handlers.
KeyDown += new KeyEventHandler(KeyDownHandler);
KeyUp += new KeyEventHandler(KeyUpHandler);
MouseDown += new MouseEventHandler(MouseDownHandler);
MouseUp += new MouseEventHandler(MouseUpHandler);
MouseMove += new MouseEventHandler(MouseMoveHandler);
Disposed += new EventHandler(MogrePanel_Disposed);
Resize += new EventHandler(MogrePanel_Resize);
}
private void MogrePanel_Disposed(object sender, EventArgs e)
{
...
}
private void MogrePanel_Resize(object sender, EventArgs e)
{
...
}
public void Init()
{
CreateRoot();
DefineResources();
SetupRenderSystem();
CreateRenderWindow();
InitializeResourceGroups();
CreateScene();
}
private void CreateRoot()
{
mogreRoot = new Root("Mogre/Configuration/plugins.cfg", "Mogre/Configuration/ogre.cfg", "Mogre/mogre.log");
}
private void DefineResources()
{
...
}
private void SetupRenderSystem()
{
...
}
private void CreateRenderWindow()
{
mogreRoot.Initialise(false, "Main Ogre Window");
NameValuePairList misc = new NameValuePairList();
misc["parentWindowHandle"] = this.Handle.ToString();
misc["outerDimensions"] = "true";
mogreWindow = mogreRoot.CreateRenderWindow("MainRenderWindow", (uint)this.Width, (uint)this.Height, false, misc);
mogreRoot.FrameStarted += new FrameListener.FrameStartedHandler(FrameStarted);
}
private void InitializeResourceGroups()
{
...
}
private void CreateScene()
{
...
}
public void StartRender()
{
Show();
while (rendering && mogreRoot != null && mogreRoot.RenderOneFrame())
Application.DoEvents();
}
private bool FrameStarted(FrameEvent evt)
{
cam.Position += cam.Orientation * translation * evt.timeSinceLastFrame;
return true;
}
void KeyDownHandler(object sender, KeyEventArgs e)
{
...
}
void KeyUpHandler(object sender, KeyEventArgs e)
{
...
}
void MouseDownHandler(object sender, MouseEventArgs e)
{
...
}
void MouseUpHandler(object sender, MouseEventArgs e)
{
...
}
void MouseMoveHandler(object sender, MouseEventArgs e)
{
...
}
}