opengl - Focus on MouseOver in Windows with Ogre3D -


i have application using ogre3d create multiple render windows, , i'm using solution posted here support non-exclusive mouse input these windows. however, find have physically click on render window before regains focus, whereas i'd render windows gain focus on mouseover event. possible capture mouseover event on unfocused render window in ogre3d/ois , subsequently set focus render window?

to support kind of functionality using ogre3d in windows, had implement singleton object kept collection of of instantiated displays.

class inputprocessor {     /// @name types     /// @{ public:     /// @}      /// @name inputprocessor implementation     /// @{ public:     void adddisplay(display* _pdisplay);      bool processmousemoved(int _x, int _y, int _z, int _keymodifier);     bool processmousepressed(int _keymodifier, int _id);     bool processmousereleased(int _keymodifier, int _id);      static inputprocessor& getsingleton();     /// @}      /// @name 'structors     /// @{ private:      inputprocessor();     ~inputprocessor();     /// @}      /// @name member variables     /// @{ private:     typedef std::set<display*>     displays_type;     displays_type                  m_displays;     /// @}  };  // class inputprocessor 

then, in uiframelistener (which derives ogre3d's exampleframelistener), transform mouse window coordinates global screen coordinates. if mouse happens reside outside of window region, apply relative mouse movement last recorded mouse position; otherwise, apply absolute mouse position within window:

bool uiframelistener::mousemoved(const ois::mouseevent& e) {     int keymodifierstate = getkeymodifierstate();     int windowleft = m_display.getleft();     int windowtop = m_display.gettop();     int windowwidth = m_display.m_pwindow->getwidth();     int windowheight = m_display.m_pwindow->getheight();      if (e.state.x.abs != 0 && e.state.x.abs != windowwidth)     {         m_lastx = e.state.x.abs;     }     else     {         m_lastx += e.state.x.rel;     }     int x = windowleft + (m_display.m_width * m_lastx) / windowwidth;      if (e.state.y.abs != 0 && e.state.y.abs != windowheight)     {         m_lasty = e.state.y.abs;     }     else     {         m_lasty += e.state.y.rel;     }     int y = windowtop + (m_display.m_height * m_lasty) / windowheight;      int z = 0;     if (e.state.z.rel != 0)     {         z = e.state.z.rel / -120;     }      return inputprocessor::getsingleton().processmousemoved(x, y, z, keymodifierstate); } 

and in inputprocessor::processmousemoved(), determine window mouse cursor in (if any), , set focus appropriately, i.e.

bool inputprocessor::processmousemoved(int _x,                                   int _y,                                   int _z,                                   int _keymodifier) {     bool found = false;      displays_type::iterator iter = m_displays.begin();     while (iter != m_displays.end() && !found)     {         int left = (*iter)->getleft();         int top = (*iter)->gettop();         int width = (*iter)->m_pwindow->getwidth();         int height = (*iter)->m_pwindow->getheight();          if (left <= _x && left + width  > _x &&             top  <= _y && top  + height > _y)         {             found = true;         }         else         {             iter++;         }     }      if (iter != m_displays.end())     {         int left = (*iter)->getleft();         int top = (*iter)->gettop();          (*iter)->m_pcontext->processmousemove(             _x - left, _y - top, _keymodifier         );          (*iter)->m_pcontext->processmousewheel(_z, _keymodifier);          if (!(*iter)->hasfocus())         {             (*iter)->setfocus(true);         }     }      return true; } 

and in implementation of display, have method display::setfocus() sets focus on appropriate window:

void display::setfocus(bool _hasfocus) {     if (m_handle != null && _hasfocus)     {         setfocus(m_handle);     } } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -