Ois mouse switch inside and outside the game window (non-exclusive input)

Source: Internet
Author: User

Useful for non fullscreen mode, especially when debugging)

If you want to switch between the game window and other applications, or use the keyboard outside the game, you can add the following code in ois:

// Insert the following right before calling minputsystem = ois: inputmanager: createinputsystem (paramlist );
# If definedOis_win32_platform

Paramlist. insert (STD: make_pair (STD: string ("w32_mouse"), STD: string ("discl_foreground ")));
Paramlist. insert (STD: make_pair (STD: string ("w32_mouse"), STD: string ("discl_nonexclusive ")));
Paramlist. insert (STD: make_pair (STD: string ("w32_keyboard"), STD: string ("discl_foreground ")));

Paramlist. insert (STD: make_pair (STD: string ("w32_keyboard"), STD: string ("discl_nonexclusive ")));
Showcursor (0); // hide the system mouse


# Elif definedOis_linux_platform

Paramlist. insert (STD: make_pair (STD: string ("x11_mouse_grab"), STD: string ("false ")));
Paramlist. insert (STD: make_pair (STD: string ("x11_mouse_hide"), STD: string ("false ")));
Paramlist. insert (STD: make_pair (STD: string ("x11_keyboard_grab"), STD: string ("false ")));
Paramlist. insert (STD: make_pair (STD: string ("xautorepeaton"), STD: string ("true ")));
# Endif


Basically, this is enough!



When the Ogre rendering window is not full screen, you want to move the mouse out of the application window just like other applications. However, according to the ogre tutorial, no specific method is described. First, search online. If someone does, they don't need to waste brain cells.
Some people have implemented this on the Internet, but the mouse position is always uncoordinated when moving the mouse according to the method. The main problem lies in this sentence"
Mouse: mousemoved
In the event
Moved (E. State. X. Rel, E. State. Y. rel)
Postion (E. State. X. Abs, E. State. Y. Abs)"

Why can't I find it"
Mouse: mousemoved"

This event (I used ogre1.6 ).
No way, you only have to rely on yourself. After a long time, I finally got it done.
No code, no truth. The following are detailed steps + code:
1. Add the following code in the exampleframelistener constructor:

Ois: paramlist pl;
Size_t %whnd = 0;
STD: ostringstream into whndstr;
Win-> getcustomattribute ("window", & windowhnd );
When whndstr <then whnd;
Pl. insert (STD: make_pair (STD: string ("window"), Fig. STR ()));
Pl. insert (STD: make_pair (STD: string ("w32_mouse"), STD: string ("discl_foreground ")));
Pl. insert (STD: make_pair (STD: string ("w32_mouse"), STD: string ("discl_nonexclusive ")));
Minputmanager = ois: inputmanager: createinputsystem (PL );
Showcursor (0); // hide the system mouse


2. Add the code to the mousemoved (const ois: mouseevent & Arg) function to check whether the mouse is within the window range.

// Mwindow indicates the current rendered window
If (Arg. state. X. ABS <mwindow-> getviewport (0)-> getactualleft () + 2
| (Arg. state. Y. ABS <mwindow-> getviewport (0)-> getactualtop () + 0.5)

| (Arg. state. x. ABS> (mwindow-> getviewport (0)-> getactualleft () + mwindow-> getviewport (0)-> getactualwidth ()-2 ))

| (Arg. state. y. ABS> (mwindow-> getviewport (0)-> getactualtop () + mwindow-> getviewport (0)-> getactualheight ()-2 )))

Cegui: mousecursor: getsingleton (). Hide ();
Else // mouse in the window
// Use OIS absolute coordinates
// If injectmousemove (Arg. state. X. Rel, Arg. state. Y. rel) is used, a bug occurs, indicating that the cegui mouse position is different from the system mouse position.
// Therefore, use injectmouseposition (Arg. state. X. Abs, Arg. state. Y. Abs) to trigger the mousemove event in cegui.
Cegui: System: getsingleton (). injectmouseposition (Arg. state. X. Abs, Arg. state. Y. Abs );
Cegui: mousecursor: getsingleton (). Show ();

If the mouse can only move within a very small range, you need to set the state. Width and state. Height of the mouse state to the same width and height of the rendering window, but this is not the case.

After the sample is changed, it is basically OK, but it is only basic and there are some minor bugs. When you press the right-click button to change the angle of view, you usually need to hide the mouse first. After the right-click button is released, the mouse is displayed. If you want to release the mouse
The mouse position is still in the right-click position, it will be more troublesome, I spent a lot of time to implement it. However, you do not need to do this. You can set the mouse position in the window after you release the right mouse button.
It is easy for users to accept.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.