]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_move.cpp
Copyright fixes
[vlc] / modules / gui / skins2 / controls / ctrl_move.cpp
1 /*****************************************************************************
2  * ctrl_move.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN (Centrale Réseaux) and its contributors
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #include "ctrl_move.hpp"
26 #include "../events/evt_generic.hpp"
27 #include "../events/evt_mouse.hpp"
28 #include "../events/evt_motion.hpp"
29 #include "../src/top_window.hpp"
30 #include "../src/window_manager.hpp"
31 #include "../utils/position.hpp"
32
33
34 CtrlMove::CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager,
35                     CtrlFlat &rCtrl, TopWindow &rWindow,
36                     const UString &rHelp, VarBool *pVisible ):
37     CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
38     m_rWindowManager( rWindowManager ),
39     m_rCtrl( rCtrl ), m_rWindow( rWindow ),
40     m_cmdMovingMoving( this, &transMovingMoving ),
41     m_cmdStillMoving( this, &transStillMoving ),
42     m_cmdMovingStill( this, &transMovingStill )
43 {
44     m_pEvt = NULL;
45     m_xPos = 0;
46     m_yPos = 0;
47
48     // States
49     m_fsm.addState( "moving" );
50     m_fsm.addState( "still" );
51
52     // Transitions
53     m_fsm.addTransition( "moving", "mouse:left:up:none", "still",
54                          &m_cmdMovingStill );
55     m_fsm.addTransition( "still", "mouse:left:down:none", "moving",
56                          &m_cmdStillMoving );
57     m_fsm.addTransition( "moving", "motion", "moving", &m_cmdMovingMoving );
58
59     m_fsm.setState( "still" );
60 }
61
62
63 bool CtrlMove::mouseOver( int x, int y ) const
64 {
65     return m_rCtrl.mouseOver( x, y );
66 }
67
68
69 void CtrlMove::draw( OSGraphics &rImage, int xDest, int yDest )
70 {
71     m_rCtrl.draw( rImage, xDest, yDest );
72 }
73
74
75 void CtrlMove::setLayout( GenericLayout *pLayout, const Position &rPosition )
76 {
77     CtrlGeneric::setLayout( pLayout, rPosition );
78     // Set the layout of the decorated control as well
79     m_rCtrl.setLayout( pLayout, rPosition );
80 }
81
82
83 const Position *CtrlMove::getPosition() const
84 {
85     return m_rCtrl.getPosition();
86 }
87
88
89 void CtrlMove::handleEvent( EvtGeneric &rEvent )
90 {
91     m_pEvt = &rEvent;
92     m_fsm.handleTransition( rEvent.getAsString() );
93     // Transmit the event to the decorated control
94     // XXX: Is it really a good idea?
95     m_rCtrl.handleEvent( rEvent );
96 }
97
98
99 void CtrlMove::transStillMoving( SkinObject *pCtrl )
100 {
101     CtrlMove *pThis = (CtrlMove*)pCtrl;
102     EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
103
104     pThis->m_xPos = pEvtMouse->getXPos();
105     pThis->m_yPos = pEvtMouse->getYPos();
106
107     pThis->captureMouse();
108
109     pThis->m_rWindowManager.startMove( pThis->m_rWindow );
110 }
111
112
113 void CtrlMove::transMovingMoving( SkinObject *pCtrl )
114 {
115     CtrlMove *pThis = (CtrlMove*)pCtrl;
116     EvtMotion *pEvtMotion = (EvtMotion*)pThis->m_pEvt;
117
118     int xNewLeft = pEvtMotion->getXPos() - pThis->m_xPos +
119                    pThis->m_rWindow.getLeft();
120     int yNewTop = pEvtMotion->getYPos() - pThis->m_yPos +
121                   pThis->m_rWindow.getTop();
122
123     pThis->m_rWindowManager.move( pThis->m_rWindow, xNewLeft, yNewTop );
124 }
125
126
127 void CtrlMove::transMovingStill( SkinObject *pCtrl )
128 {
129     CtrlMove *pThis = (CtrlMove*)pCtrl;
130
131     pThis->releaseMouse();
132
133     pThis->m_rWindowManager.stopMove();
134 }