Changeset 125

Show
Ignore:
Timestamp:
08/20/10 20:30:16 (18 months ago)
Author:
Carsten
Message:

Improved mouse input handling in the cafu_to_wx branch.

Location:
cafu/branches/cafu_to_wx
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • cafu/branches/cafu_to_wx/Ca3DE/MainCanvas.cpp

    r120 r125  
    120120      m_ConByGuiWin(NULL), 
    121121      m_Timer(), 
    122       m_TotalTime(0.0) 
     122      m_TotalTime(0.0), 
     123      m_LastMousePos(IN_OTHER_2D_GUI) 
    123124{ 
    124125    m_GLContext=new wxGLContext(this); 
     
    553554    cf::GuiSys::GuiMan->DistributeClockTickEvents(FrameTimeF); 
    554555 
     556    // If the active GUI is the client GUI, see how far the mouse cursor is off center, 
     557    // derive a mouse event from it, then recenter the mouse cursor. 
     558    cf::GuiSys::GuiI* ActiveGui=cf::GuiSys::GuiMan->GetTopmostActiveAndInteractive(); 
     559 
     560    if (ActiveGui && ActiveGui->GetRootWindow()->Name=="Client") 
     561    { 
     562        const wxPoint MousePos  =ScreenToClient(wxGetMousePosition());  // Note: ScreenToClient() is a method of wxWindow. 
     563        const wxSize  WinCenter =GetClientSize()/2; 
     564        const wxPoint MouseDelta=MousePos-WinCenter; 
     565 
     566        if (m_LastMousePos==IN_CLIENT_3D_GUI) 
     567        { 
     568            CaMouseEventT ME; 
     569 
     570            ME.Type  =CaMouseEventT::CM_MOVE_X; 
     571            ME.Amount=MouseDelta.x;     // TODO: Factor out screen resolution... 
     572            if (ME.Amount!=0) ActiveGui->ProcessDeviceEvent(ME); 
     573 
     574            ME.Type  =CaMouseEventT::CM_MOVE_Y; 
     575            ME.Amount=MouseDelta.y;     // TODO: Factor out screen resolution... 
     576            if (ME.Amount!=0) ActiveGui->ProcessDeviceEvent(ME); 
     577        } 
     578 
     579        if (MouseDelta.x || MouseDelta.y) WarpPointer(WinCenter.x, WinCenter.y); 
     580        m_LastMousePos=IN_CLIENT_3D_GUI; 
     581    } 
     582 
    555583    if (!m_Parent->IsIconized()) 
    556584    { 
     
    584612    cf::GuiSys::GuiI* Gui=cf::GuiSys::GuiMan->GetTopmostActiveAndInteractive(); 
    585613 
    586     // This is equivalent to (but much easier than) calling cf::GuiSys::GuiMan->ProcessDeviceEvent(MouseEvent). 
    587     if (Gui) 
    588     { 
    589         Gui->SetMousePos(ME.GetX()*(cf::GuiSys::VIRTUAL_SCREEN_SIZE_X/GetSize().x), 
    590                          ME.GetY()*(cf::GuiSys::VIRTUAL_SCREEN_SIZE_Y/GetSize().y)); 
     614    // This is equivalent to calling cf::GuiSys::GuiMan->ProcessDeviceEvent(MouseEvent), 
     615    // but computing the amount of mouse movement is much easier (and more precise) like this. 
     616    if (Gui && Gui->GetRootWindow()->Name!="Client") 
     617    { 
     618        float OldMousePosX; 
     619        float OldMousePosY; 
     620 
     621        Gui->GetMousePos(OldMousePosX, OldMousePosY); 
     622 
     623        const float NewMousePosX=ME.GetX()*(cf::GuiSys::VIRTUAL_SCREEN_SIZE_X/GetSize().x); 
     624        const float NewMousePosY=ME.GetY()*(cf::GuiSys::VIRTUAL_SCREEN_SIZE_Y/GetSize().y); 
     625 
     626        // This works, but doesn't forward the mouse event to the windows. 
     627        // Gui->SetMousePos(NewMousePosX, NewMousePosY); 
     628 
     629        CaMouseEventT ME; 
     630 
     631        ME.Type  =CaMouseEventT::CM_MOVE_X; 
     632        ME.Amount=NewMousePosX-OldMousePosX; 
     633        if (ME.Amount!=0) Gui->ProcessDeviceEvent(ME); 
     634 
     635        ME.Type  =CaMouseEventT::CM_MOVE_Y; 
     636        ME.Amount=NewMousePosY-OldMousePosY; 
     637        if (ME.Amount!=0) Gui->ProcessDeviceEvent(ME); 
     638 
     639        m_LastMousePos=IN_OTHER_2D_GUI; 
    591640    } 
    592641} 
  • cafu/branches/cafu_to_wx/Ca3DE/MainCanvas.hpp

    r119 r125  
    5757 
    5858    enum InitStateT { INIT_REQUIRED, INIT_FAILED, INIT_SUCCESS }; 
     59    enum LastMousePosT { IN_CLIENT_3D_GUI, IN_OTHER_2D_GUI }; 
    5960 
    6061    void Initialize(); 
     
    8990    TimerT        m_Timer; 
    9091    double        m_TotalTime; 
     92    LastMousePosT m_LastMousePos;   ///< Used to prevent unwanted changes to the players heading and pitch when we're switching back from a 2D GUI to the 3D client view. 
    9193 
    9294    DECLARE_EVENT_TABLE() 
  • cafu/branches/cafu_to_wx/CaWE/GuiEditor/ChildFrame.cpp

    r124 r125  
    496496void GuiEditor::ChildFrameT::OnMenuEditDelete(wxCommandEvent& CE) 
    497497{ 
    498     SubmitCommand(new CommandDeleteT(m_GuiDocument, m_GuiDocument->GetSelection())); 
     498    if (m_GuiDocument->GetSelection().Size()>0) 
     499        SubmitCommand(new CommandDeleteT(m_GuiDocument, m_GuiDocument->GetSelection())); 
    499500} 
    500501 
     
    698699 
    699700        case ID_TOOLBAR_WINDOW_DELETE: 
    700             SubmitCommand(new CommandDeleteT(m_GuiDocument, m_GuiDocument->GetSelection())); 
     701            if (m_GuiDocument->GetSelection().Size()>0) 
     702                SubmitCommand(new CommandDeleteT(m_GuiDocument, m_GuiDocument->GetSelection())); 
    701703            break; 
    702704 
  • cafu/branches/cafu_to_wx/Libs/GuiSys/Gui.hpp

    r36 r125  
    6969            /// Returns whether this GUI is fullscreen and fully opaque, i.e. whether this GUI covers everything under it. If true, the GuiSys saves the rendering of the GUIs "below" this one. This can improve the GUI performance significantly if e.g. the player is at a point in the game where the world rendering FPS is low. 
    7070            virtual bool GetIsFullCover() const=0; 
     71 
     72            /// Returns the position of the mouse cursor. 
     73            virtual void GetMousePos(float& MousePosX, float& MousePosY) const=0; 
    7174 
    7275            /// Sets the position of the mouse cursor. 
  • cafu/branches/cafu_to_wx/Libs/GuiSys/GuiImpl.cpp

    r124 r125  
    291291{ 
    292292    IsInteractive=IsInteractive_; 
     293} 
     294 
     295 
     296void GuiImplT::GetMousePos(float& MousePosX_, float& MousePosY_) const 
     297{ 
     298    MousePosX_=MousePosX; 
     299    MousePosY_=MousePosY; 
    293300} 
    294301 
  • cafu/branches/cafu_to_wx/Libs/GuiSys/GuiImpl.hpp

    r124 r125  
    7676            bool GetIsInteractive() const { return IsInteractive; } 
    7777            bool GetIsFullCover() const { return IsFullCover; } 
     78            void GetMousePos(float& MousePosX_, float& MousePosY_) const; 
    7879            void SetMousePos(float MousePosX_, float MousePosY_); 
    7980            void SetShowMouse(bool ShowMouse_);