~ubuntu-branches/debian/wheezy/vlc/wheezy

« back to all changes in this revision

Viewing changes to modules/gui/skins2/controls/ctrl_resize.cpp

Tags: upstream-0.7.2.final
Import upstream version 0.7.2.final

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * ctrl_resize.cpp
 
3
 *****************************************************************************
 
4
 * Copyright (C) 2003 VideoLAN
 
5
 * $Id: ctrl_resize.cpp 6964 2004-03-05 20:56:39Z ipkiss $
 
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_resize.hpp"
 
26
#include "../events/evt_generic.hpp"
 
27
#include "../events/evt_mouse.hpp"
 
28
#include "../events/evt_motion.hpp"
 
29
#include "../src/generic_layout.hpp"
 
30
#include "../src/os_factory.hpp"
 
31
#include "../utils/position.hpp"
 
32
#include "../commands/async_queue.hpp"
 
33
#include "../commands/cmd_resize.hpp"
 
34
 
 
35
 
 
36
CtrlResize::CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl,
 
37
                        GenericLayout &rLayout, const UString &rHelp,
 
38
                        VarBool *pVisible ):
 
39
    CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_rCtrl( rCtrl ),
 
40
    m_rLayout( rLayout ), m_cmdOutStill( this, &transOutStill ),
 
41
    m_cmdStillOut( this, &transStillOut ),
 
42
    m_cmdStillStill( this, &transStillStill ),
 
43
    m_cmdStillResize( this, &transStillResize ),
 
44
    m_cmdResizeStill( this, &transResizeStill ),
 
45
    m_cmdResizeResize( this, &transResizeResize )
 
46
{
 
47
    m_pEvt = NULL;
 
48
    m_xPos = 0;
 
49
    m_yPos = 0;
 
50
 
 
51
    // States
 
52
    m_fsm.addState( "out" );
 
53
    m_fsm.addState( "still" );
 
54
    m_fsm.addState( "resize" );
 
55
 
 
56
    // Transitions
 
57
    m_fsm.addTransition( "out", "enter", "still", &m_cmdOutStill );
 
58
    m_fsm.addTransition( "still", "leave", "out", &m_cmdStillOut );
 
59
    m_fsm.addTransition( "still", "motion", "still", &m_cmdStillStill );
 
60
    m_fsm.addTransition( "resize", "mouse:left:up:none", "still",
 
61
                         &m_cmdResizeStill );
 
62
    m_fsm.addTransition( "still", "mouse:left:down:none", "resize",
 
63
                         &m_cmdStillResize );
 
64
    m_fsm.addTransition( "resize", "motion", "resize", &m_cmdResizeResize );
 
65
 
 
66
    m_fsm.setState( "still" );
 
67
}
 
68
 
 
69
 
 
70
bool CtrlResize::mouseOver( int x, int y ) const
 
71
{
 
72
    return m_rCtrl.mouseOver( x, y );
 
73
}
 
74
 
 
75
 
 
76
void CtrlResize::draw( OSGraphics &rImage, int xDest, int yDest )
 
77
{
 
78
    m_rCtrl.draw( rImage, xDest, yDest );
 
79
}
 
80
 
 
81
 
 
82
void CtrlResize::setLayout( GenericLayout *pLayout, const Position &rPosition )
 
83
{
 
84
    CtrlGeneric::setLayout( pLayout, rPosition );
 
85
    // Set the layout of the decorated control as well
 
86
    m_rCtrl.setLayout( pLayout, rPosition );
 
87
}
 
88
 
 
89
 
 
90
const Position *CtrlResize::getPosition() const
 
91
{
 
92
    return m_rCtrl.getPosition();
 
93
}
 
94
 
 
95
 
 
96
void CtrlResize::handleEvent( EvtGeneric &rEvent )
 
97
{
 
98
    m_pEvt = &rEvent;
 
99
    m_fsm.handleTransition( rEvent.getAsString() );
 
100
    // Transmit the event to the decorated control
 
101
    // XXX: Is it really a good idea?
 
102
    m_rCtrl.handleEvent( rEvent );
 
103
}
 
104
 
 
105
 
 
106
void CtrlResize::transOutStill( SkinObject *pCtrl )
 
107
{
 
108
    CtrlResize *pThis = (CtrlResize*)pCtrl;
 
109
    OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
 
110
    pOsFactory->changeCursor( OSFactory::kResizeNWSE );
 
111
}
 
112
 
 
113
 
 
114
void CtrlResize::transStillOut( SkinObject *pCtrl )
 
115
{
 
116
    CtrlResize *pThis = (CtrlResize*)pCtrl;
 
117
    OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
 
118
    pOsFactory->changeCursor( OSFactory::kDefaultArrow );
 
119
}
 
120
 
 
121
 
 
122
void CtrlResize::transStillStill( SkinObject *pCtrl )
 
123
{
 
124
    CtrlResize *pThis = (CtrlResize*)pCtrl;
 
125
    OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
 
126
    pOsFactory->changeCursor( OSFactory::kResizeNWSE );
 
127
}
 
128
 
 
129
 
 
130
void CtrlResize::transStillResize( SkinObject *pCtrl )
 
131
{
 
132
    CtrlResize *pThis = (CtrlResize*)pCtrl;
 
133
    EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
 
134
 
 
135
    // Set the cursor
 
136
    OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
 
137
    pOsFactory->changeCursor( OSFactory::kResizeNWSE );
 
138
 
 
139
    pThis->m_xPos = pEvtMouse->getXPos();
 
140
    pThis->m_yPos = pEvtMouse->getYPos();
 
141
 
 
142
    pThis->captureMouse();
 
143
 
 
144
    pThis->m_width = pThis->m_rLayout.getWidth();
 
145
    pThis->m_height = pThis->m_rLayout.getHeight();
 
146
}
 
147
 
 
148
 
 
149
void CtrlResize::transResizeStill( SkinObject *pCtrl )
 
150
{
 
151
    CtrlResize *pThis = (CtrlResize*)pCtrl;
 
152
 
 
153
    // Set the cursor
 
154
    OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
 
155
    pOsFactory->changeCursor( OSFactory::kResizeNWSE );
 
156
 
 
157
    pThis->releaseMouse();
 
158
}
 
159
 
 
160
 
 
161
void CtrlResize::transResizeResize( SkinObject *pCtrl )
 
162
{
 
163
    CtrlResize *pThis = (CtrlResize*)pCtrl;
 
164
    EvtMotion *pEvtMotion = (EvtMotion*)pThis->m_pEvt;
 
165
 
 
166
    // Set the cursor
 
167
    OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
 
168
    pOsFactory->changeCursor( OSFactory::kResizeNWSE );
 
169
 
 
170
    int newWidth = pEvtMotion->getXPos() - pThis->m_xPos + pThis->m_width;
 
171
    int newHeight = pEvtMotion->getYPos() - pThis->m_yPos + pThis->m_height;
 
172
 
 
173
    // Check boundaries
 
174
    if( newWidth < pThis->m_rLayout.getMinWidth() )
 
175
    {
 
176
        newWidth = pThis->m_rLayout.getMinWidth();
 
177
    }
 
178
    if( newWidth > pThis->m_rLayout.getMaxWidth() )
 
179
    {
 
180
        newWidth = pThis->m_rLayout.getMaxWidth();
 
181
    }
 
182
    if( newHeight < pThis->m_rLayout.getMinHeight() )
 
183
    {
 
184
        newHeight = pThis->m_rLayout.getMinHeight();
 
185
    }
 
186
    if( newHeight > pThis->m_rLayout.getMaxHeight() )
 
187
    {
 
188
        newHeight = pThis->m_rLayout.getMaxHeight();
 
189
    }
 
190
 
 
191
    // Create a resize command
 
192
    CmdGeneric *pCmd = new CmdResize( pThis->getIntf(), pThis->m_rLayout,
 
193
                                      newWidth, newHeight );
 
194
    // Push the command in the asynchronous command queue
 
195
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
 
196
    pQueue->remove( "resize" );
 
197
    pQueue->push( CmdGenericPtr( pCmd ) );
 
198
}