Ejemplo n.º 1
0
        public void Shutdown()
        {
            // Release the mouse.
            if (_Mouse != null)
            {
                _Mouse.Unacquire();
                _Mouse.Dispose();
                _Mouse = null;
            }

            // Release the keyboard.
            if (_Keyboard != null)
            {
                _Keyboard.Unacquire();
                _Keyboard.Dispose();
                _Keyboard = null;
            }

            // Release the main interface to direct input.
            if (_DirectInput != null)
            {
                _DirectInput.Dispose();
                _DirectInput = null;
            }
        }
		internal static bool ButtonIsPressed( Mouse control )
		{
			var button = buttonTable[(int) control];
			if (button >= 0)
			{
				return Input.GetMouseButton( button );
			}
			return false;
		}
Ejemplo n.º 3
0
        internal bool Initialize(SystemConfiguration configuration, IntPtr windowsHandle)
        {
            // Screen the screen size which will be used for positioning the mouse cursor.
            _ScreenWidth = configuration.Width;
            _ScreenHeight = configuration.Height;

            // Initialize the location of the mouse on the screen.
            _MouseX = 0;
            _MouseY = 0;

            // Initialize the main direct input interface.
            _DirectInput = new DirectInput();

            // Initialize the direct interface for the keyboard.
            _Keyboard = new Keyboard(_DirectInput);
            _Keyboard.Properties.BufferSize = 256;

            // Set the cooperative level of the keyboard to not share with other programs.
            _Keyboard.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);

            // Now acquire the keyboard.
            if (_Keyboard.Acquire().Failure)
                return false;

            // Initialize the direct interface for the mouse.
            _Mouse = new Mouse(_DirectInput);
            _Mouse.Properties.AxisMode = DeviceAxisMode.Relative;

            // Set the cooperative level of the mouse to share with other programs.
            _Mouse.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            // Now acquire the mouse.
            if (_Mouse.Acquire().Failure)
                return false;

            return true;
        }
Ejemplo n.º 4
0
		/// <summary>
		/// A convenience method for adding a MouseBindingSource to the default bindings.
		/// </summary>
		/// <param name="control">The Mouse control to add.</param>
		public void AddDefaultBinding( Mouse control )
		{
			AddDefaultBinding( new MouseBindingSource( control ) );
		}
		public MouseBindingSource( Mouse mouseControl )
		{
			Control = mouseControl;
		}
Ejemplo n.º 6
0
 private void DoInputsStartup()
 {
     ParamList pl = new ParamList();
     pl.Insert("WINDOW", this.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;
     log("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)
         log("\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 = renderBox.Width;
     //ms.height = renderBox.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);
     }
 }
Ejemplo n.º 7
0
 public Main()
 {
     _graphicsDeviceManager = new GraphicsDeviceManager(this)
     {
         SynchronizeWithVerticalRetrace = false,
         PreferredBackBufferWidth = PreferredSize.Width,
         PreferredBackBufferHeight = PreferredSize.Height,
         PreferredBackBufferFormat = PixelFormat.R8G8B8A8.UNormSRgb,
         //DeviceCreationFlags = DeviceCreationFlags.Debug
     };
     IsFixedTimeStep = false;
     Content.RootDirectory = "Content";
     var directInput = new DirectInput();
     _keyboard = new Keyboard(directInput);
     _keyboard.Acquire();
     _mouse = new Mouse(directInput);
     _mouse.Acquire();
 }
 internal override void Load( BinaryReader reader )
 {
     mouseControl = (Mouse) reader.ReadInt32();
 }
Ejemplo n.º 9
0
        public static int Main(string[] args)
        {
            string fileName = "";
            bool showHelp = false;

            Console.WriteLine("Hello Mice World!");
            var p = new OptionSet {
                { "f|file=", "the ods file",
                    (string v) => fileName = v },
                { "h|help", "show this message and exit",
                    v => showHelp = v != null },
            };
            List<string> extraArgs;
            try {
                extraArgs = p.Parse(args);
            } catch (OptionException oe) {
                Console.Error.WriteLine(oe.Message);
                return -1;
            }
            if (extraArgs.Count != 0 || fileName == "") {
                ShowHelp(p);
                return -1;
            }
            if (showHelp) {
                ShowHelp(p);
                return 0;
            }

            //https://github.com/tonyqus/npoi
            HSSFWorkbook wb = new HSSFWorkbook(new FileStream (fileName, FileMode.Open));
            ISheet sheet = wb.GetSheetAt(0);
            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();

            // We skip the first two rows with headers.
            rows.MoveNext();
            rows.MoveNext();
            int lastWantedCell = 5;
            // Each row is a cage.
            int id = 0;
            bool done = false;
            List<Cage> cages = new List<Cage> ();
            while (rows.MoveNext() && !done) {
                Cage cage = new Cage(id++);
                IRow row = (HSSFRow)rows.Current;
                string genotype = "";
                string sex = "";
                int amount = 0;
                DateTime dob = new DateTime();
                for (int i = 0; i < lastWantedCell; i++) {
                    ICell cell = row.GetCell(i);
                    //Console.WriteLine(cell + " working with this cell");
                    if (cell == null) {
                        if (i > 0) {
                            throw new Exception(".xls with wrong structure given, I need " + lastWantedCell + " columns");
                        }
                        continue;
                    } else {
                        switch (i) {
                        case 0:
                            cage.Number = (int)cell.NumericCellValue;
                            break;
                        case 1: // genotype
                            genotype = cell.StringCellValue;
                            break;
                        case 2: //sex
                            sex = cell.StringCellValue;
                            break;
                        case 3: //amount
                            amount = (int) cell.NumericCellValue;
                            break;
                        case 4: //date of birth
                            dob = cell.DateCellValue;
                            break;
                        case 5:
                            throw new Exception("Something really unespected have happened\n");
                        }
                    }
                }
                int mouse_id = 0;
                while (mouse_id < amount) {
                    Mouse m = new Mouse(dob, mouse_id, sex.ToUpper().ToCharArray()[0]);
                    m.AddLocus(GetSimpleLocus(genotype));
                    mouse_id++;
                    if (!cage.AddMouse(m)) {
                        Console.Error.WriteLine("Mouse " + m + " cannot be loaded as long as it's already somewhere");
                    }
                }
                cages.Add(cage);
            }
            foreach (Cage c in cages) {
                foreach (Mouse m in c) {
                    Console.Write(m);
                    Console.WriteLine(" Genotipo? " + m.IsOmozigous(LOCUS_NAME));
                }
            }
            return 0;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes SlimDX and input devices.
        /// </summary>
        /// <param name="caption">Window caption string.</param>
        public FrameworkForm(string caption)
            : base(caption)
        {
            SwapChainDescription description = new SwapChainDescription()
            {
                BufferCount = 1,
                Flags = SwapChainFlags.None,
                IsWindowed = true,
                ModeDescription = new ModeDescription(ClientSize.Width, ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle = Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            try
            {
#if DEBUG
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out graphicsDevice, out swapChain);
#else
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out graphicsDevice, out swapChain);
#endif
            }
            catch
            {
                MessageBox.Show("An error has occurred during initialization process.");
                Environment.Exit(0);
            }
            finally
            {
                if (graphicsDevice.FeatureLevel != FeatureLevel.Level_11_0)
                {
                    MessageBox.Show("This program requires DirectX 11. Your version is " + graphicsDevice.FeatureLevel.ToString() + ".");
                    Environment.Exit(0);
                }
            }

            Factory factory = swapChain.GetParent<Factory>();
            factory.SetWindowAssociation(Handle, WindowAssociationFlags.IgnoreAltEnter);
            KeyDown += (o, e) =>
            {
                // Fixes Alt-Enter keyboard input bug in SlimDX.
                if (e.Alt && e.KeyCode == Keys.Enter)
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;

                // Makes screenshot.
                if (e.KeyCode == Keys.F12)
                    MakeScreenshot(Application.StartupPath);
            };

            SizeChanged += (o, e) =>
            {
                // Dispose old resources.
                if (renderTargetView != null)
                    renderTargetView.Dispose();
                if (backBufferTexture != null)
                    backBufferTexture.Dispose();

                // Resize buffers.
                swapChain.ResizeBuffers(1, ClientSize.Width, ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);

                InitializeOutputMerger();

                camera.UpdateProjection();

                postProcess.Initialize(ClientSize.Width, ClientSize.Height);
            };

            fillMode = FillMode.Solid;
            InitializeOutputMerger();

            // Initializes input devices.
            DirectInput directInput = new DirectInput();
            keyboard = new Keyboard(directInput);
            keyboard.Acquire();
            mouse = new Mouse(directInput);
            mouse.Acquire();

            camera = new Camera(graphicsDevice, new Vector3(50, 50, 50), new Vector3(0, 0, 0), 0.1f, 1000.0f);
            textures = new List<TexturePack>();
            postProcess = new PostProcess(graphicsDevice, ClientSize.Width, ClientSize.Height);
            quadRenderer = new QuadRenderer(graphicsDevice);
        }