Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

ctrl_move.cpp

00001 /*****************************************************************************
00002  * ctrl_move.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: ctrl_move.cpp 12207 2005-08-15 15:54:32Z asmax $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include "ctrl_move.hpp"
00026 #include "../events/evt_generic.hpp"
00027 #include "../events/evt_mouse.hpp"
00028 #include "../events/evt_motion.hpp"
00029 #include "../src/top_window.hpp"
00030 #include "../src/window_manager.hpp"
00031 #include "../utils/position.hpp"
00032 
00033 
00034 CtrlMove::CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager,
00035                     CtrlFlat &rCtrl, TopWindow &rWindow,
00036                     const UString &rHelp, VarBool *pVisible ):
00037     CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
00038     m_rWindowManager( rWindowManager ),
00039     m_rCtrl( rCtrl ), m_rWindow( rWindow ),
00040     m_cmdMovingMoving( this ),
00041     m_cmdStillMoving( this ),
00042     m_cmdMovingStill( this )
00043 {
00044     m_pEvt = NULL;
00045     m_xPos = 0;
00046     m_yPos = 0;
00047 
00048     // States
00049     m_fsm.addState( "moving" );
00050     m_fsm.addState( "still" );
00051 
00052     // Transitions
00053     m_fsm.addTransition( "moving", "mouse:left:up:none", "still",
00054                          &m_cmdMovingStill );
00055     m_fsm.addTransition( "still", "mouse:left:down:none", "moving",
00056                          &m_cmdStillMoving );
00057     m_fsm.addTransition( "moving", "motion", "moving", &m_cmdMovingMoving );
00058 
00059     m_fsm.setState( "still" );
00060 }
00061 
00062 
00063 bool CtrlMove::mouseOver( int x, int y ) const
00064 {
00065     return m_rCtrl.mouseOver( x, y );
00066 }
00067 
00068 
00069 void CtrlMove::draw( OSGraphics &rImage, int xDest, int yDest )
00070 {
00071     m_rCtrl.draw( rImage, xDest, yDest );
00072 }
00073 
00074 
00075 void CtrlMove::setLayout( GenericLayout *pLayout, const Position &rPosition )
00076 {
00077     CtrlGeneric::setLayout( pLayout, rPosition );
00078     // Set the layout of the decorated control as well
00079     m_rCtrl.setLayout( pLayout, rPosition );
00080 }
00081 
00082 
00083 const Position *CtrlMove::getPosition() const
00084 {
00085     return m_rCtrl.getPosition();
00086 }
00087 
00088 
00089 void CtrlMove::handleEvent( EvtGeneric &rEvent )
00090 {
00091     m_pEvt = &rEvent;
00092     m_fsm.handleTransition( rEvent.getAsString() );
00093     // Transmit the event to the decorated control
00094     // XXX: Is it really a good idea?
00095     m_rCtrl.handleEvent( rEvent );
00096 }
00097 
00098 
00099 void CtrlMove::CmdStillMoving::execute()
00100 {
00101     EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
00102 
00103     m_pParent->m_xPos = pEvtMouse->getXPos();
00104     m_pParent->m_yPos = pEvtMouse->getYPos();
00105 
00106     m_pParent->captureMouse();
00107 
00108     m_pParent->m_rWindowManager.startMove( m_pParent->m_rWindow );
00109 }
00110 
00111 
00112 void CtrlMove::CmdMovingMoving::execute()
00113 {
00114     EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt;
00115 
00116     int xNewLeft = pEvtMotion->getXPos() - m_pParent->m_xPos +
00117                    m_pParent->m_rWindow.getLeft();
00118     int yNewTop = pEvtMotion->getYPos() - m_pParent->m_yPos +
00119                   m_pParent->m_rWindow.getTop();
00120 
00121     m_pParent->m_rWindowManager.move( m_pParent->m_rWindow, xNewLeft, yNewTop );
00122 }
00123 
00124 
00125 void CtrlMove::CmdMovingStill::execute()
00126 {
00127     m_pParent->releaseMouse();
00128 
00129     m_pParent->m_rWindowManager.stopMove();
00130 }

Generated on Tue Dec 20 10:14:41 2005 for vlc-0.8.4a by  doxygen 1.4.2