Mogre Window and MOIS [SOLVED]

Kwang1imsa

07-06-2011 05:55:31

I can't really seem to figure out why the window doesn't release the mouse. I think it is because the while loop traps it. Is there a function to fire off MOIS events?

Here's my code, and thanks:

using System;
using SFML;
using SFML.Graphics;
using SFML.Window;
using Tao.OpenGl;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Mogre;
using MOIS;

namespace gravitygame
{
class Game
{
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
public static extern bool FreeConsole();

public static Root mRoot;
//public static RaySceneQuery mSceneRay;
public static Mogre.RenderWindow OGREWin;
public static ArrayList globalVars = new ArrayList();
public static SFML.Graphics.Vector2 camera = new SFML.Graphics.Vector2(0, 0);
public static Color bgcol = new Color();
public static int renderState = 0; //0-2D, 1-3D
public static bool globalPressed = false;
public static SFML.Graphics.RenderWindow SFMLWin;
public static MOIS.InputManager inputManager;
public static MOIS.Keyboard inputKeyboard;
public static MOIS.Mouse inputMouse;
public Game()
{
mRoot = new Root();

RenderSystem renderSystem = mRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
renderSystem.SetConfigOption("Full Screen", "No");
mRoot.RenderSystem = renderSystem;
// Create Render Window
if (mRoot != null)
{
mRoot.Initialise(false, "OGREWin");
NameValuePairList misc = new NameValuePairList();
//misc["externalWindowHandle"] = this.Handle.ToString();
OGREWin = mRoot.CreateRenderWindow("Gravity Game", 320, 320, false, misc);
}
MOIS.ParamList pl = new MOIS.ParamList();
IntPtr hwnd;
OGREWin.GetCustomAttribute("WINDOW", out hwnd);
pl.Insert("WINDOW", hwnd.ToString());
inputManager = MOIS.InputManager.CreateInputSystem(pl);
inputKeyboard = (MOIS.Keyboard)inputManager.CreateInputObject(MOIS.Type.OISKeyboard, true);
inputMouse = (MOIS.Mouse)inputManager.CreateInputObject(MOIS.Type.OISMouse, true);
//mRoot.FrameStarted+=new FrameListener.FrameStartedHandler(MainDraw);
if (inputKeyboard != null)
{
inputKeyboard.KeyPressed += new MOIS.KeyListener.KeyPressedHandler(OnKeyPressed);
inputKeyboard.KeyReleased += new MOIS.KeyListener.KeyReleasedHandler(OnKeyReleased);
}
if (inputMouse != null)
{
inputMouse.MousePressed += new MOIS.MouseListener.MousePressedHandler(OnMousePressed);
inputMouse.MouseReleased += new MOIS.MouseListener.MouseReleasedHandler(OnMouseReleased);
inputMouse.MouseMoved += new MOIS.MouseListener.MouseMovedHandler(OnMouseMove);
}
SFMLWin = new SFML.Graphics.RenderWindow(hwnd);
//SFMLWin = new SFML.Graphics.RenderWindow(new VideoMode(320,320),"Gravity Game");
SFMLWin.PreserveOpenGLStates(true);
SFMLWin.Closed += new EventHandler(OnClosed);
SFMLWin.Resized += new EventHandler<SizeEventArgs>(OnResized);
Gl.glEnable(Gl.GL_DEPTH_TEST);
Gl.glDepthMask(Gl.GL_TRUE);
Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
Gl.glClearDepth(1.0F);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);

while (SFMLWin.IsOpened() && !OGREWin.IsClosed)
{
//set for FPS?
SFMLWin.CurrentView.Move(camera);
SFMLWin.DispatchEvents();
inputKeyboard.Capture();
inputMouse.Capture();
OnKeyHold();
MainDraw();
WindowEventUtilities.MessagePump();
}
}
public static bool MainDraw()
{
SFMLWin.Clear(bgcol);
Gl.glViewport(0, 0, (int)SFMLWin.Width, (int)SFMLWin.Height);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
SFMLWin.Display();
return true;
}
static void Main()
{
FreeConsole();
new Game();
}
static void OnClosed(object sender, EventArgs e = null)
{
SFML.Graphics.RenderWindow window = (SFML.Graphics.RenderWindow)sender;
window.Close();
}

static bool OnMousePressed(MOIS.MouseEvent e, MOIS.MouseButtonID button)
{
return true;
}
static bool OnMouseReleased(MOIS.MouseEvent e, MOIS.MouseButtonID button)
{
return true;
}
static bool OnKeyPressed(MOIS.KeyEvent e)
{
return true;
}
static bool OnKeyHold()
{
return true;
}
static bool OnKeyReleased(MOIS.KeyEvent e)
{
return true;
}
static bool OnMouseMove(MOIS.MouseEvent e)
{
return true;
}
static void OnResized(object sender, SizeEventArgs e)
{
Gl.glViewport(0, 0, (int)e.Width, (int)e.Height);
SFMLWin.CurrentView.SetFromRect(new SFML.Graphics.FloatRect(0.0f, 0.0f, SFMLWin.Width, SFMLWin.Height));
}
}
}

smiley80

07-06-2011 09:42:56

OIS grabs the mouse in exclusive mode by default. You can prevent this with:
pl.Insert("w32_mouse", "DISCL_NONEXCLUSIVE");
pl.Insert("w32_mouse", "DISCL_FOREGROUND");

after:
MOIS.ParamList pl = new MOIS.ParamList();

Kwang1imsa

07-06-2011 21:35:03

Thank you very much, smiley80. This helps a lot.