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

ctrl_resize.cpp

00001 /*****************************************************************************
00002  * ctrl_resize.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: ctrl_resize.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_resize.hpp"
00026 #include "../events/evt_generic.hpp"
00027 #include "../events/evt_mouse.hpp"
00028 #include "../events/evt_motion.hpp"
00029 #include "../src/generic_layout.hpp"
00030 #include "../src/os_factory.hpp"
00031 #include "../utils/position.hpp"
00032 #include "../commands/async_queue.hpp"
00033 #include "../commands/cmd_resize.hpp"
00034 
00035 
00036 CtrlResize::CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl,
00037                         GenericLayout &rLayout, const UString &rHelp,
00038                         VarBool *pVisible ):
00039     CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_rCtrl( rCtrl ),
00040     m_rLayout( rLayout ), m_cmdOutStill( this ),
00041     m_cmdStillOut( this ),
00042     m_cmdStillStill( this ),
00043     m_cmdStillResize( this ),
00044     m_cmdResizeStill( this ),
00045     m_cmdResizeResize( this )
00046 {
00047     m_pEvt = NULL;
00048     m_xPos = 0;
00049     m_yPos = 0;
00050 
00051     // States
00052     m_fsm.addState( "out" );
00053     m_fsm.addState( "still" );
00054     m_fsm.addState( "resize" );
00055 
00056     // Transitions
00057     m_fsm.addTransition( "out", "enter", "still", &m_cmdOutStill );
00058     m_fsm.addTransition( "still", "leave", "out", &m_cmdStillOut );
00059     m_fsm.addTransition( "still", "motion", "still", &m_cmdStillStill );
00060     m_fsm.addTransition( "resize", "mouse:left:up:none", "still",
00061                          &m_cmdResizeStill );
00062     m_fsm.addTransition( "still", "mouse:left:down:none", "resize",
00063                          &m_cmdStillResize );
00064     m_fsm.addTransition( "resize", "motion", "resize", &m_cmdResizeResize );
00065 
00066     m_fsm.setState( "still" );
00067 }
00068 
00069 
00070 bool CtrlResize::mouseOver( int x, int y ) const
00071 {
00072     return m_rCtrl.mouseOver( x, y );
00073 }
00074 
00075 
00076 void CtrlResize::draw( OSGraphics &rImage, int xDest, int yDest )
00077 {
00078     m_rCtrl.draw( rImage, xDest, yDest );
00079 }
00080 
00081 
00082 void CtrlResize::setLayout( GenericLayout *pLayout, const Position &rPosition )
00083 {
00084     CtrlGeneric::setLayout( pLayout, rPosition );
00085     // Set the layout of the decorated control as well
00086     m_rCtrl.setLayout( pLayout, rPosition );
00087 }
00088 
00089 
00090 const Position *CtrlResize::getPosition() const
00091 {
00092     return m_rCtrl.getPosition();
00093 }
00094 
00095 
00096 void CtrlResize::handleEvent( EvtGeneric &rEvent )
00097 {
00098     m_pEvt = &rEvent;
00099     m_fsm.handleTransition( rEvent.getAsString() );
00100     // Transmit the event to the decorated control
00101     // XXX: Is it really a good idea?
00102     m_rCtrl.handleEvent( rEvent );
00103 }
00104 
00105 
00106 void CtrlResize::CmdOutStill::execute()
00107 {
00108     OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00109     pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00110 }
00111 
00112 
00113 void CtrlResize::CmdStillOut::execute()
00114 {
00115     OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00116     pOsFactory->changeCursor( OSFactory::kDefaultArrow );
00117 }
00118 
00119 
00120 void CtrlResize::CmdStillStill::execute()
00121 {
00122     OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00123     pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00124 }
00125 
00126 
00127 void CtrlResize::CmdStillResize::execute()
00128 {
00129     EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
00130 
00131     // Set the cursor
00132     OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00133     pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00134 
00135     m_pParent->m_xPos = pEvtMouse->getXPos();
00136     m_pParent->m_yPos = pEvtMouse->getYPos();
00137 
00138     m_pParent->captureMouse();
00139 
00140     m_pParent->m_width = m_pParent->m_rLayout.getWidth();
00141     m_pParent->m_height = m_pParent->m_rLayout.getHeight();
00142 }
00143 
00144 
00145 void CtrlResize::CmdResizeStill::execute()
00146 {
00147     // Set the cursor
00148     OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00149     pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00150 
00151     m_pParent->releaseMouse();
00152 }
00153 
00154 
00155 void CtrlResize::CmdResizeResize::execute()
00156 {
00157     EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt;
00158 
00159     // Set the cursor
00160     OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00161     pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00162 
00163     int newWidth = pEvtMotion->getXPos() - m_pParent->m_xPos + m_pParent->m_width;
00164     int newHeight = pEvtMotion->getYPos() - m_pParent->m_yPos + m_pParent->m_height;
00165 
00166     // Check boundaries
00167     if( newWidth < m_pParent->m_rLayout.getMinWidth() )
00168     {
00169         newWidth = m_pParent->m_rLayout.getMinWidth();
00170     }
00171     if( newWidth > m_pParent->m_rLayout.getMaxWidth() )
00172     {
00173         newWidth = m_pParent->m_rLayout.getMaxWidth();
00174     }
00175     if( newHeight < m_pParent->m_rLayout.getMinHeight() )
00176     {
00177         newHeight = m_pParent->m_rLayout.getMinHeight();
00178     }
00179     if( newHeight > m_pParent->m_rLayout.getMaxHeight() )
00180     {
00181         newHeight = m_pParent->m_rLayout.getMaxHeight();
00182     }
00183 
00184     // Create a resize command
00185     CmdGeneric *pCmd = new CmdResize( m_pParent->getIntf(), m_pParent->m_rLayout,
00186                                       newWidth, newHeight );
00187     // Push the command in the asynchronous command queue
00188     AsyncQueue *pQueue = AsyncQueue::instance( m_pParent->getIntf() );
00189     pQueue->remove( "resize" );
00190     pQueue->push( CmdGenericPtr( pCmd ) );
00191 }

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