Example #1
0
        bool Mouse_MouseMoved(MOIS.MouseEvent arg)
        {
            MouseState_NativePtr state = arg.state;

            if (arg.state.Z.rel != 0 && modChooserMenu.GetNumItems() != 0)
            {
                float newIndex   = modChooserMenu.getSelectionIndex() - arg.state.Z.rel / Mogre.Math.Abs((float)arg.state.Z.rel);
                float finalIndex = OpenMB.Utilities.Helper.Clamp <float>(newIndex, 0.0f, (float)(modChooserMenu.GetNumItems() - 1));

                modChooserMenu.SelectItem((uint)finalIndex);
                //modTitle.setCaption("modChooserMenu.getSelectedItem()");
                modTitle.setCaption(
                    LocateSystem.Instance.GetLocalizedString(
                        "module_info_name",
                        modChooserMenu.getSelectedItem(),
                        modDisplayDataList[modChooserMenu.Items.IndexOf(modChooserMenu.getSelectedItem())].ID
                        ));

                //modDescBox.setText(modDisplayDataList[modChooserMenu.Items.IndexOf(modChooserMenu.getSelectedItem())].Desc);
                modDescBox.setText(
                    LocateSystem.Instance.GetLocalizedString(
                        "module_info_desc",
                        modDisplayDataList[modChooserMenu.Items.IndexOf(modChooserMenu.getSelectedItem())].Desc,
                        modDisplayDataList[modChooserMenu.Items.IndexOf(modChooserMenu.getSelectedItem())].ID
                        ));

                selectedModName = modChooserMenu.getSelectedItem();
            }

            UIManager.Instance.InjectMouseMove(arg);
            return(true);
        }
Example #2
0
        ///<summary>
        ///  start up mois manager
        ///</summary>
        internal bool Startup(IntPtr _windowHandle, int _width, int _height)
        {
            // check if already initialized
            if (mInputMgr != null)
            {
                return(false);
            }

            // initialize input manager
            ParamList pl = new ParamList();

            pl.Insert("WINDOW", _windowHandle.ToString());
            try
            {
                mInputMgr = InputManager.CreateInputSystem(pl);
            }
            catch (AccessViolationException e)
            {
                Debug.WriteLine(e.Message);
            }
            if (mInputMgr == null)
            {
                return(false);
            }

            // initialize keyboard
            mKeyboard = (Keyboard)mInputMgr.CreateInputObject(MOIS.Type.OISKeyboard, true);
            if (mKeyboard == null)
            {
                return(false);
            }

            // set up keyboard event handlers
            mKeyboard.KeyPressed  += OnKeyPressed;
            mKeyboard.KeyReleased += OnKeyReleased;

            // initialize mouse
            mMouse = (Mouse)mInputMgr.CreateInputObject(MOIS.Type.OISMouse, true);
            if (mMouse == null)
            {
                return(false);
            }

            // set up area for absolute mouse positions
            MouseState_NativePtr state = mMouse.MouseState;

            state.width  = _width;
            state.height = _height;

            // set up mouse event handlers
            mMouse.MouseMoved    += OnMouseMoved;
            mMouse.MousePressed  += OnMousePressed;
            mMouse.MouseReleased += OnMouseReleased;

            Clear();

            // OK
            return(true);
        }
Example #3
0
        static void handleNonBufferedMouse()
        {
            //Just dump the current mouse state
            MouseState_NativePtr ms = g_m.MouseState;

            Console.Write("\nMouse: Abs(" + ms.X.abs + " " + ms.Y.abs + " " + ms.Z.abs
                          + ") B: " + ms.buttons + " Rel(" + ms.X.rel + " " + ms.Y.rel + " " + ms.Z.rel + ")");
        }
Example #4
0
        static bool MouseMoved(MouseEvent arg)
        {
            MouseState_NativePtr s = arg.state;

            Console.Write("\nMouseMoved: Abs("
                          + s.X.abs + ", " + s.Y.abs + ", " + s.Z.abs + ") Rel("
                          + s.X.rel + ", " + s.Y.rel + ", " + s.Z.rel + ")");
            return(true);
        }
Example #5
0
        static bool MousePressed(MouseEvent arg, MouseButtonID id)
        {
            MouseState_NativePtr s = arg.state;

            Console.Write("\nMouse button #" + id + " pressed. Abs("
                          + s.X.abs + ", " + s.Y.abs + ", " + s.Z.abs + ") Rel("
                          + s.X.rel + ", " + s.Y.rel + ", " + s.Z.rel + ")");
            return(true);
        }
Example #6
0
        internal bool Startup(int windowHandle, uint width, uint height)
        {
            mWindowHanldle = windowHandle;
            if (this.mInputMgr != null)
            {
                return(false);
            }

            // initialize input manager
            ParamList pl = new ParamList();

            pl.Insert("WINDOW", windowHandle.ToString());
            pl.Insert("w32_mouse", "DISCL_NONEXCLUSIVE");
            pl.Insert("w32_mouse", "DISCL_FOREGROUND");
            pl.Insert("w32_keyboard", "DISCL_FOREGROUND");
            pl.Insert("w32_keyboard", "DISCL_NONEXCLUSIVE");

            this.mInputMgr = InputManager.CreateInputSystem(pl);
            if (this.mInputMgr == null)
            {
                return(false);
            }

            // initialize keyboard
            this.KeyBoard = (Keyboard)this.mInputMgr.CreateInputObject(MOIS.Type.OISKeyboard, true);
            if (this.KeyBoard == null)
            {
                return(false);
            }

            // set up keyboard event handlers
            this.KeyBoard.KeyPressed  += OnKeyPressed;
            this.KeyBoard.KeyReleased += OnKeyReleased;

            // initialize mouse
            this.Mouse = (Mouse)this.mInputMgr.CreateInputObject(MOIS.Type.OISMouse, true);
            if (this.Mouse == null)
            {
                return(false);
            }

            // set up area for absolute mouse positions
            MouseState_NativePtr state = this.Mouse.MouseState;

            state.width  = (int)width;
            state.height = (int)height;

            // set up mouse event handlers
            this.Mouse.MouseMoved    += OnMouseMoved;
            this.Mouse.MousePressed  += OnMousePressed;
            this.Mouse.MouseReleased += OnMouseReleased;

            this.Clear();

            return(true);
        }
Example #7
0
        private bool mouseMoved(MouseEvent arg)
        {
            float RotateScale_CameraPitch = .001f; //mouse sensitivity
            float RotateScale_PlayerTurn  = .001f; //mouse sensitivity
            MouseState_NativePtr s        = arg.state;

            if (arg.state.buttons == 2)
            {
                //chat("____________________________________________________________");
                nodes["orbit0"].Pitch(s.Y.rel * RotateScale_CameraPitch);
                if (!player_freeze && !textBarUsage && !consoleBarUsage)
                {
                    if (s.X.rel != 0f)
                    {
                        //nodes["drone"].Yaw(-s.X.rel * RotateScale_PlayerTurn);
                        //setOrient(nodes["drone"]._getDerivedOrientation());
                        setOrient(control.Actor.GlobalOrientationQuaternion * ModifyAngleAroundAxis(new Degree(-s.X.rel * RotateScale_PlayerTurn), new Mogre.Vector3(0, 1, 0)));

                        //Mogre.Quaternion orient1 = control.Actor.GlobalOrientationQuaternion;
                        //Mogre.Vector3 rkAxis = new Mogre.Vector3();
                        //Degree rfAngle = new Degree();
                        //orient1.ToRotationMatrix().ToAxisAngle(out rkAxis, out rfAngle);
                        //orient2 = new Quaternion(new Radian(new Degree(rfAngle.ValueDegrees + (-s.X.rel * RotateScale_PlayerTurn))), new Mogre.Vector3(0, 1, 0));
                        ////control.Actor.GlobalOrientationQuaternion = orient2;
                        ////setOrient(orient2);
                        //spin(rfAngle.ValueDegrees + (-s.X.rel * RotateScale_PlayerTurn));
                    }
                }
                updateCam();
            }

            float mouseZ = (float)OgreWindow.g_m.MouseState.Z.rel * .1f;

            //chat(mouseZ.ToString());
            if (mouseZ > 0)
            {
                middleMouseState = middleMouseStates.scrollup;
                middlemousetimer.reset();
                middlemousetimer.start();
            }
            else if (mouseZ < 0)
            {
                middleMouseState = middleMouseStates.scrolldown;
                middlemousetimer.reset();
                middlemousetimer.start();
            }

            return(true);
        }
Example #8
0
        bool Mouse_MouseMoved(MOIS.MouseEvent arg)
        {
            MouseState_NativePtr state = arg.state;

            if (arg.state.Z.rel != 0 && modChooserMenu.getNumItems() != 0)
            {
                float newIndex   = modChooserMenu.getSelectionIndex() - arg.state.Z.rel / Mogre.Math.Abs((float)arg.state.Z.rel);
                float finalIndex = OpenMB.Utilities.Helper.Clamp <float>(newIndex, 0.0f, (float)(modChooserMenu.getNumItems() - 1));
                modChooserMenu.selectItem((uint)finalIndex);
                modTitle.setCaption(modChooserMenu.getSelectedItem());
                modDescBox.setText(modDescs[modNames.ToList().IndexOf(modChooserMenu.getSelectedItem())]);
                selectedModName = modChooserMenu.getSelectedItem();
            }

            return(GameManager.Instance.trayMgr.injectMouseMove(arg));
        }
Example #9
0
        static bool appRunning = true;  //Global Exit Flag

        static void DoStartup()
        {
            ParamList pl   = new ParamList();
            Form1     form = new Form1();

            form.Show();
            pl.Insert("WINDOW", form.Handle.ToString());

            //Default mode is foreground exclusive..but, we want to show mouse - so nonexclusive
            pl.Insert("w32_mouse", "DISCL_FOREGROUND");
            pl.Insert("w32_mouse", "DISCL_NONEXCLUSIVE");

            //This never returns null.. it will raise an exception on errors
            g_InputManager = InputManager.CreateInputSystem(pl);

            uint v = InputManager.VersionNumber;

            Console.WriteLine("OIS Version: " + (v >> 16) + "." + ((v >> 8) & 0x000000FF) + "." + (v & 0x000000FF)
                              + "\n\tRelease Name: " //+ InputManager.VersionName
                              + "\n\tPlatform: " + g_InputManager.InputSystemName()
                              + "\n\tNumber of Mice: " + g_InputManager.GetNumberOfDevices(MOIS.Type.OISMouse)
                              + "\n\tNumber of Keyboards: " + g_InputManager.GetNumberOfDevices(MOIS.Type.OISKeyboard)
                              + "\n\tNumber of Joys/Pads = " + g_InputManager.GetNumberOfDevices(MOIS.Type.OISJoyStick));

            //List all devices
            DeviceList list = g_InputManager.ListFreeDevices();

            foreach (KeyValuePair <MOIS.Type, string> pair in list)
            {
                Console.WriteLine("\n\tDevice: " + g_DeviceType[(int)pair.Key] + " Vendor: " + pair.Value);
            }

            g_kb              = (Keyboard)g_InputManager.CreateInputObject(MOIS.Type.OISKeyboard, true);
            g_kb.KeyPressed  += new KeyListener.KeyPressedHandler(KeyPressed);
            g_kb.KeyReleased += new KeyListener.KeyReleasedHandler(KeyReleased);

            g_m                = (Mouse)g_InputManager.CreateInputObject(MOIS.Type.OISMouse, true);
            g_m.MouseMoved    += new MouseListener.MouseMovedHandler(MouseMoved);
            g_m.MousePressed  += new MouseListener.MousePressedHandler(MousePressed);
            g_m.MouseReleased += new MouseListener.MouseReleasedHandler(MouseReleased);

            MouseState_NativePtr ms = g_m.MouseState;

            ms.width  = form.Width;
            ms.height = form.Height;

            //This demo only uses at max 4 joys
            int numSticks = g_InputManager.GetNumberOfDevices(MOIS.Type.OISJoyStick);

            if (numSticks > 4)
            {
                numSticks = 4;
            }

            g_joys = new JoyStick[numSticks];

            for (int i = 0; i < numSticks; ++i)
            {
                g_joys[i]                 = (JoyStick)g_InputManager.CreateInputObject(MOIS.Type.OISJoyStick, true);
                g_joys[i].AxisMoved      += new JoyStickListener.AxisMovedHandler(AxisMoved);
                g_joys[i].ButtonPressed  += new JoyStickListener.ButtonPressedHandler(JoyButtonPressed);
                g_joys[i].ButtonReleased += new JoyStickListener.ButtonReleasedHandler(JoyButtonReleased);
                g_joys[i].PovMoved       += new JoyStickListener.PovMovedHandler(PovMoved);
                g_joys[i].Vector3Moved   += new JoyStickListener.Vector3MovedHandler(Vector3Moved);
            }
        }
Example #10
0
        private bool InitRender(string wndTitle, ref GameConfigXml gameOptions)
        {
            root = Root.Singleton == null ? new Root() : Root.Singleton;
            root.FrameStarted += new FrameListener.FrameStartedHandler(frameStarted);

            log         = EngineLogManager.Instance.CreateLog("./Log/Engine.log");
            rendererLog = LogManager.Singleton.CreateLog("./Log/Mogre.log", true, true, false);
            rendererLog.SetDebugOutputEnabled(true);

            RenderSystem        rs     = null;
            IniConfigFileParser parser = new IniConfigFileParser();

            if (gameOptions == null)
            {
                gameOptions = GameConfigXml.Load("game.xml", root);
            }

            defaultRenderSystemName = gameOptions.GraphicConfig.CurrentRenderSystem;
            var renderParams = gameOptions.GraphicConfig[gameOptions.GraphicConfig.CurrentRenderSystem];

            if (!string.IsNullOrEmpty(defaultRenderSystemName))
            {
                var videModeRenderParam = renderParams.Where(o => o.Name == "Video Mode").First();
                rs = root.GetRenderSystemByName(defaultRenderSystemName);
                string strVideoMode = Regex.Match(
                    videModeRenderParam.Value,
                    "[0-9]{3,4} x [0-9]{3,4}").Value;
                VideoMode["Width"]  = strVideoMode.Split('x')[0].Trim();
                VideoMode["Height"] = strVideoMode.Split('x')[1].Trim();
            }

            var ogreConfigMap = rs.GetConfigOptions();

            if (rs != null && renderParams != null)
            {
                foreach (var kpl in renderParams)
                {
                    string renderParamKey   = kpl.Name;
                    string renderParamValue = kpl.Value;
                    //Validate the render parameter
                    if (!ogreConfigMap[renderParamKey].possibleValues.Contains(renderParamValue))
                    {
                        renderParamValue = ogreConfigMap[renderParamKey].possibleValues[0];
                    }
                    rs.SetConfigOption(renderParamKey, renderParamValue);
                }
                root.RenderSystem = rs;
            }

            renderWindow = root.Initialise(true, wndTitle);

            IntPtr hwnd;

            renderWindow.GetCustomAttribute("WINDOW", out hwnd);
            Helper.SetRenderWindowIcon(new System.Drawing.Icon(Path.Combine(Environment.CurrentDirectory, "app.ico")), hwnd);

            viewport = renderWindow.AddViewport(null);
            ColourValue cv = new ColourValue(0.5f, 0.5f, 0.5f);

            viewport.BackgroundColour = cv;

            viewport.Camera = null;

            int hWnd = 0;

            renderWindow.GetCustomAttribute("WINDOW", out hWnd);

            inputMgr        = MOIS.InputManager.CreateInputSystem((uint)hWnd);
            keyboard        = (Keyboard)inputMgr.CreateInputObject(MOIS.Type.OISKeyboard, true);
            mouse           = (Mouse)inputMgr.CreateInputObject(MOIS.Type.OISMouse, true);
            keyMouseManager = new InputKeyMouseManager();
            keyMouseManager.SomeKeyPressd += KeyMouseManager_SomeKeyPressd;

            MouseState_NativePtr mouseState = mouse.MouseState;

            mouseState.width  = viewport.ActualWidth;
            mouseState.height = viewport.ActualHeight;

            foreach (var resource in gameOptions.ResourcesConfig.Resources)
            {
                foreach (var resLoc in resource.ResourceLocs)
                {
                    ResourceGroupManager.Singleton.AddResourceLocation(resLoc, resource.Type, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                }
            }

            foreach (var keyMapper in gameOptions.InputConfig.Mappers)
            {
                KeyMapperManager.Instance.AddKeyMapper(keyMapper.GameKeyCode, keyMapper.GetKeyCollections());
            }

            if (!LocateSystem.Instance.IsInit)
            {
                LocateSystem.Instance.InitLocateSystem(LocateSystem.Instance.ConvertReadableStringToLocate(gameOptions.LocateConfig.CurrentLocate));
            }

            SkinManager.Instance.LoadSkin("Default.skn");

            ResourceGroupManager.Singleton.AddResourceLocation(
                string.Format("./Media/Engine/Fonts/{0}/", LocateSystem.Instance.Locate.ToString()), "FileSystem",
                "General");

            TextureManager.Singleton.DefaultNumMipmaps = 5;

            ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

            UIManager.Instance.Init("AMOFTrayMgr", renderWindow, mouse, new UIListener());


            timer = new Timer();
            timer.Reset();

            renderWindow.IsActive = true;

            this.gameOptions = gameOptions;

            log.LogMessage("Game Started!");

            return(true);
        }
Example #11
0
        private bool InitRender(string wndTitle, ref Dictionary <string, string> gameOptions)
        {
            root = Root.Singleton == null ? new Root() : Root.Singleton;
            root.FrameStarted += new FrameListener.FrameStartedHandler(frameStarted);

            log         = EngineLogManager.Instance.CreateLog("./Log/Engine.log");
            rendererLog = LogManager.Singleton.CreateLog("./Log/Mogre.log", true, true, false);
            rendererLog.SetDebugOutputEnabled(true);

            RenderSystem        rs     = null;
            IniConfigFileParser parser = new IniConfigFileParser();

            if (gameOptions == null)
            {
                gameOptions = new Dictionary <string, string>();

                IniConfigFile cf       = (IniConfigFile)parser.Load("Game.cfg");
                var           sections = cf.Sections;
                foreach (var section in sections)
                {
                    foreach (var kpl in section.KeyValuePairs)
                    {
                        gameOptions.Add(kpl.Key, kpl.Value);
                    }
                }

                cf       = (IniConfigFile)parser.Load("ogre.cfg");
                sections = cf.Sections;
                string renderSystem = null;
                foreach (var section in sections)
                {
                    if (section.Name == "")
                    {
                        foreach (var kpl in section.KeyValuePairs)
                        {
                            renderSystem = kpl.Value;
                            gameOptions.Add(kpl.Key, kpl.Value);
                        }
                    }
                    else if (section.Name == renderSystem)
                    {
                        foreach (var kpl in section.KeyValuePairs)
                        {
                            gameOptions.Add("Render Params_" + kpl.Key, kpl.Value);
                        }
                    }
                }
            }

            defaultRenderSystemName = gameOptions.Where(o => o.Key == "Render System").First().Value;
            var renderParams = gameOptions.Where(o => o.Key.StartsWith("Render Params"));

            if (!string.IsNullOrEmpty(defaultRenderSystemName))
            {
                var videModeRenderParam = renderParams.Where(o => o.Key == "Render Params_Video Mode").First();
                rs = root.GetRenderSystemByName(defaultRenderSystemName);
                string strVideoMode = Regex.Match(
                    videModeRenderParam.Value,
                    "[0-9]{3,4} x [0-9]{3,4}").Value;
                videoMode["Width"]  = strVideoMode.Split('x')[0].Trim();
                videoMode["Height"] = strVideoMode.Split('x')[1].Trim();
            }

            var ogreConfigMap = rs.GetConfigOptions();

            if (rs != null && renderParams != null)
            {
                foreach (var kpl in renderParams)
                {
                    string renderParamKey   = kpl.Key.Split('_')[1];
                    string renderParamValue = kpl.Value;
                    //Validate the render parameter
                    if (!ogreConfigMap[renderParamKey].possibleValues.Contains(renderParamValue))
                    {
                        renderParamValue = ogreConfigMap[renderParamKey].possibleValues[0];
                    }
                    rs.SetConfigOption(renderParamKey, renderParamValue);
                }
                root.RenderSystem = rs;
            }
            renderWindow = root.Initialise(true, wndTitle);

            viewport = renderWindow.AddViewport(null);
            ColourValue cv = new ColourValue(0.5f, 0.5f, 0.5f);

            viewport.BackgroundColour = cv;

            viewport.Camera = null;

            int hWnd = 0;

            renderWindow.GetCustomAttribute("WINDOW", out hWnd);

            inputMgr = InputManager.CreateInputSystem((uint)hWnd);
            keyboard = (Keyboard)inputMgr.CreateInputObject(MOIS.Type.OISKeyboard, true);
            mouse    = (Mouse)inputMgr.CreateInputObject(MOIS.Type.OISMouse, true);

            mouse.MouseMoved    += new MouseListener.MouseMovedHandler(mouseMoved);
            mouse.MousePressed  += new MouseListener.MousePressedHandler(mousePressed);
            mouse.MouseReleased += new MouseListener.MouseReleasedHandler(mouseReleased);

            keyboard.KeyPressed  += new KeyListener.KeyPressedHandler(keyPressed);
            keyboard.KeyReleased += new KeyListener.KeyReleasedHandler(keyReleased);

            MouseState_NativePtr mouseState = mouse.MouseState;

            mouseState.width  = viewport.ActualWidth;
            mouseState.height = viewport.ActualHeight;

            string        secName, typeName, archName;
            IniConfigFile conf = new IniConfigFile();

            conf = (IniConfigFile)parser.Load("resources.cfg");
            for (int i = 0; i < conf.Sections.Count; i++)
            {
                secName = conf.Sections[i].Name;
                for (int j = 0; j < conf.Sections[i].KeyValuePairs.Count; j++)
                {
                    typeName = conf.Sections[i].KeyValuePairs[j].Key;
                    archName = conf.Sections[i].KeyValuePairs[j].Value;
                    ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
                }
            }

            if (!LocateSystem.Singleton.IsInit)
            {
                LocateSystem.Singleton.InitLocateSystem(LocateSystem.Singleton.ConvertLocateShortStringToLocateInfo(gameOptions.Where(o => o.Key == "CurrentLocate").First().Value));
            }

            ResourceGroupManager.Singleton.AddResourceLocation(
                string.Format("./Media/Engine/Fonts/{0}/", LocateSystem.Singleton.Locate.ToString()), "FileSystem",
                "General");

            TextureManager.Singleton.DefaultNumMipmaps = 5;

            ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

            trayMgr = new SdkTrayManager("AMOFTrayMgr", renderWindow, mouse, new SdkTrayListener());

            timer = new Timer();
            timer.Reset();

            renderWindow.IsActive = true;

            this.gameOptions = gameOptions;

            log.LogMessage("Game Started!");

            return(true);
        }