Commit b7dc5e88 authored by Cyril Deguet's avatar Cyril Deguet

* all: brand new skins interface ( still _experimental_) for x11 and

  win32, by ipkiss and myself...
 Among the features:
 - framework rewritten from scratch, heavily based on design patterns
  => new controls can be (hopefully) created more easily, portability
  to other OS is better, and the interface is less dependant from
  the vlc core
 - new concept of "layout", to provide a window with several different
  views (as in winamp3 skins)
 - controls can now be placed at a relative position to the edges of
  a window, which allow controls and layouts to be resizable (e.g
  for the playlist window)
 - Use of libpng and libfreetype2 for better portability between x11 and
   win32 => ttf fonts and antialiasing
 - New DTD for the xml theme ( *it will probably change again* )
 - Very very beginning of scripting in the xml file
 - And many things I miss
 - And probably many bugs ;)
parent 4fc0ccfa
SOURCES_skins = \
commands/async_queue.cpp \
commands/async_queue.hpp \
commands/cmd_add_item.cpp \
commands/cmd_add_item.hpp \
commands/cmd_generic.hpp \
commands/cmd_change_skin.cpp \
commands/cmd_change_skin.hpp \
commands/cmd_dialogs.hpp \
commands/cmd_input.cpp \
commands/cmd_input.hpp \
commands/cmd_layout.cpp \
commands/cmd_layout.hpp \
commands/cmd_notify_playlist.cpp \
commands/cmd_notify_playlist.hpp \
commands/cmd_on_top.cpp \
commands/cmd_on_top.hpp \
commands/cmd_playlist.cpp \
commands/cmd_playlist.hpp \
commands/cmd_quit.cpp \
commands/cmd_quit.hpp \
commands/cmd_resize.cpp \
commands/cmd_resize.hpp \
commands/cmd_show_window.hpp \
\
controls/ctrl_button.cpp \
controls/ctrl_button.hpp \
controls/ctrl_checkbox.cpp \
controls/ctrl_checkbox.hpp \
controls/ctrl_flat.hpp \
controls/ctrl_generic.cpp \
controls/ctrl_generic.hpp \
controls/ctrl_image.cpp \
controls/ctrl_image.hpp \
controls/ctrl_list.cpp \
controls/ctrl_list.hpp \
controls/ctrl_move.cpp \
controls/ctrl_move.hpp \
controls/ctrl_resize.cpp \
controls/ctrl_resize.hpp \
controls/ctrl_slider.cpp \
controls/ctrl_slider.hpp \
controls/ctrl_radialslider.cpp \
controls/ctrl_radialslider.hpp \
controls/ctrl_text.hpp \
controls/ctrl_text.cpp \
\
events/evt_enter.hpp \
events/evt_generic.hpp \
events/evt_focus.hpp \
events/evt_input.cpp \
events/evt_input.hpp \
events/evt_key.cpp \
events/evt_key.hpp \
events/evt_leave.hpp \
events/evt_motion.hpp \
events/evt_mouse.cpp \
events/evt_mouse.hpp \
events/evt_refresh.hpp \
events/evt_special.cpp \
events/evt_special.hpp \
events/evt_scroll.cpp \
events/evt_scroll.hpp \
\
parser/builder.cpp \
parser/builder.hpp \
parser/builder_data.hpp \
parser/flex.c \
parser/interpreter.cpp \
parser/interpreter.hpp \
parser/parser_context.hpp \
parser/skin.c \
parser/skin.h \
parser/wrappers.cpp \
parser/wrappers.h \
\
src/anchor.cpp \
src/anchor.hpp \
src/dialogs.cpp \
src/dialogs.hpp \
src/ft2_bitmap.cpp \
src/ft2_bitmap.hpp \
src/ft2_font.cpp \
src/ft2_font.hpp \
src/generic_bitmap.hpp \
src/generic_font.hpp \
src/generic_layout.cpp \
src/generic_layout.hpp \
src/generic_window.cpp \
src/generic_window.hpp \
src/logger.cpp \
src/logger.hpp \
src/os_factory.cpp \
src/os_factory.hpp \
src/os_graphics.hpp \
src/os_loop.hpp \
src/os_timer.hpp \
src/os_window.hpp \
src/os_tooltip.hpp \
src/png_bitmap.cpp \
src/png_bitmap.hpp \
src/scaled_bitmap.cpp \
src/scaled_bitmap.hpp \
src/skin_main.cpp \
src/skin_common.hpp \
src/theme.cpp \
src/theme.hpp \
src/theme_loader.cpp \
src/theme_loader.hpp \
src/tooltip.cpp \
src/tooltip.hpp \
src/var_manager.cpp \
src/var_manager.hpp \
src/vlcproc.cpp \
src/vlcproc.hpp \
src/window_manager.cpp \
src/window_manager.hpp \
\
utils/bezier.cpp \
utils/bezier.hpp \
utils/fsm.cpp \
utils/fsm.hpp \
utils/observer.hpp \
utils/pointer.hpp \
utils/position.cpp \
utils/position.hpp \
utils/ustring.cpp \
utils/ustring.hpp \
utils/variable.hpp \
utils/var_bool.cpp \
utils/var_bool.hpp \
utils/var_list.cpp \
utils/var_list.hpp \
utils/var_percent.cpp \
utils/var_percent.hpp \
utils/var_text.cpp \
utils/var_text.hpp \
\
vars/playlist.cpp \
vars/playlist.hpp \
vars/time.cpp \
vars/time.hpp \
vars/volume.cpp \
vars/volume.hpp \
vars/vlcvars.cpp \
vars/vlcvars.hpp \
\
win32/win32_dragdrop.cpp \
win32/win32_dragdrop.hpp \
win32/win32_factory.cpp \
win32/win32_factory.hpp \
win32/win32_graphics.cpp \
win32/win32_graphics.hpp \
win32/win32_loop.cpp \
win32/win32_loop.hpp \
win32/win32_timer.cpp \
win32/win32_timer.hpp \
win32/win32_tooltip.cpp \
win32/win32_tooltip.hpp \
win32/win32_window.cpp \
win32/win32_window.hpp \
\
x11/x11_display.cpp \
x11/x11_display.hpp \
x11/x11_dragdrop.cpp \
x11/x11_dragdrop.hpp \
x11/x11_factory.cpp \
x11/x11_factory.hpp \
x11/x11_graphics.cpp \
x11/x11_graphics.hpp \
x11/x11_loop.cpp \
x11/x11_loop.hpp \
x11/x11_timer.cpp \
x11/x11_timer.hpp \
x11/x11_window.cpp \
x11/x11_window.hpp \
x11/x11_tooltip.cpp \
x11/x11_tooltip.hpp \
$(NULL)
/*****************************************************************************
* async_queue.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: async_queue.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "async_queue.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_timer.hpp"
AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf )
{
// Create a timer
OSFactory *pOsFactory = OSFactory::instance( pIntf );
m_pTimer = pOsFactory->createOSTimer( Callback( this, &doFlush ) );
// Flush the queue every 10 ms
m_pTimer->start( 10, false );
}
AsyncQueue::~AsyncQueue()
{
}
AsyncQueue *AsyncQueue::instance( intf_thread_t *pIntf )
{
if( ! pIntf->p_sys->p_queue )
{
AsyncQueue *pQueue;
pQueue = new AsyncQueue( pIntf );
if( pQueue )
{
// Initialization succeeded
pIntf->p_sys->p_queue = pQueue;
}
}
return pIntf->p_sys->p_queue;
}
void AsyncQueue::destroy( intf_thread_t *pIntf )
{
if( pIntf->p_sys->p_queue )
{
delete pIntf->p_sys->p_queue;
pIntf->p_sys->p_queue = NULL;
}
}
void AsyncQueue::push( const CmdGenericPtr &rcCommand )
{
m_cmdList.push_back( rcCommand );
}
void AsyncQueue::remove( const string &rType )
{
list<CmdGenericPtr>::iterator it;
for( it = m_cmdList.begin(); it != m_cmdList.end(); it++ )
{
// Remove the command if it is of the given type
if( (*it).get()->getType() == rType )
{
list<CmdGenericPtr>::iterator itNew = it;
itNew++;
m_cmdList.erase( it );
it = itNew;
}
}
}
void AsyncQueue::flush()
{
while( m_cmdList.size() > 0 )
{
// Execute the first command in the queue
CmdGenericPtr &rcCommand = m_cmdList.front();
rcCommand.get()->execute();
// And remove it
m_cmdList.pop_front();
}
}
void AsyncQueue::doFlush( SkinObject *pObj )
{
AsyncQueue *pThis = (AsyncQueue*)pObj;
// Flush the queue
pThis->flush();
}
/*****************************************************************************
* async_queue.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: async_queue.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef ASYNC_QUEUE_HPP
#define ASYNC_QUEUE_HPP
#include "cmd_generic.hpp"
#include <list>
#include <string>
class OSTimer;
/// Asynchronous queue for commands
class AsyncQueue: public SkinObject
{
public:
/// Get the instance of AsyncQueue
/// Returns NULL if initialization failed.
static AsyncQueue *instance( intf_thread_t *pIntf );
/// Destroy the instance of AsyncQueue
static void destroy( intf_thread_t *pIntf );
/// Add a command in the queue
void push( const CmdGenericPtr &rcCommand );
/// Remove the commands of the given type
void remove( const string &rType );
/// Flush the queue and execute the commands
void flush();
private:
/// Command queue
list<CmdGenericPtr> m_cmdList;
/// Timer
OSTimer *m_pTimer;
// Private because it is a singleton
AsyncQueue( intf_thread_t *pIntf );
virtual ~AsyncQueue();
/// Callback for the timer
static void doFlush( SkinObject *pObj );
};
#endif
/*****************************************************************************
* cmd_add_item.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_add_item.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <vlc/vlc.h>
#include "cmd_add_item.hpp"
void CmdAddItem::execute()
{
playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
if( pPlaylist == NULL )
{
return;
}
if( m_playNow )
{
// Enqueue and play the item
playlist_Add( pPlaylist, m_name.c_str(), 0, 0,
PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
}
else
{
// Enqueue the item only
playlist_Add( pPlaylist, m_name.c_str(), 0, 0,
PLAYLIST_APPEND, PLAYLIST_END );
}
}
/*****************************************************************************
* cmd_add_item.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_add_item.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_ADD_ITEM_HPP
#define CMD_ADD_ITEM_HPP
#include "cmd_generic.hpp"
#include <string>
/// "Add item" command
class CmdAddItem: public CmdGeneric
{
public:
CmdAddItem( intf_thread_t *pIntf, const string &rName, bool playNow ):
CmdGeneric( pIntf ), m_name( rName ), m_playNow( playNow ) {}
virtual ~CmdAddItem() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "add item"; }
private:
/// Name of the item to enqueue
string m_name;
/// Should we play the item immediately?
bool m_playNow;
};
#endif
/*****************************************************************************
* cmd_change_skin.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_change_skin.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_change_skin.hpp"
#include "cmd_quit.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_loop.hpp"
#include "../src/theme.hpp"
#include "../src/theme_loader.hpp"
void CmdChangeSkin::execute()
{
// Save the old theme to restore it in case of problem
Theme *pOldTheme = getIntf()->p_sys->p_theme;
if( pOldTheme )
{
pOldTheme->getWindowManager().hideAll();
}
ThemeLoader loader( getIntf() );
if( loader.load( m_file ) )
{
// Everything went well
msg_Dbg( getIntf(), "New theme successfully loaded (%s)",
m_file.c_str() );
if( pOldTheme )
{
delete pOldTheme;
}
}
else if( pOldTheme )
{
msg_Err( getIntf(), "A problem occurred when loading the new theme,"
" restoring the previous one" );
getIntf()->p_sys->p_theme = pOldTheme;
pOldTheme->getWindowManager().showAll();
}
else
{
msg_Err( getIntf(), "Cannot load the theme, aborting" );
// Quit
CmdQuit cmd( getIntf() );
cmd.execute();
}
}
/*****************************************************************************
* cmd_change_skin.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_change_skin.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_CHANGE_SKIN_HPP
#define CMD_CHANGE_SKIN_HPP
#include "cmd_generic.hpp"
class WindowManager;
/// "Change Skin" command
class CmdChangeSkin: public CmdGeneric
{
public:
CmdChangeSkin( intf_thread_t *pIntf, const string &rFile ):
CmdGeneric( pIntf ), m_file( rFile ) {}
virtual ~CmdChangeSkin() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "change skin"; }
private:
/// Skin file to load
string m_file;
};
#endif
/*****************************************************************************
* cmd_dialogs.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_dialogs.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_DIALOGS_HPP
#define CMD_DIALOGS_HPP
#include "cmd_generic.hpp"
#include "../src/dialogs.hpp"
#include "cmd_change_skin.hpp"
template<int TYPE = 0> class CmdDialogs;
// XXX use an enum instead
typedef CmdDialogs<1> CmdDlgChangeSkin;
typedef CmdDialogs<2> CmdDlgFileSimple;
typedef CmdDialogs<3> CmdDlgFile;
typedef CmdDialogs<4> CmdDlgDisc;
typedef CmdDialogs<5> CmdDlgNet;
typedef CmdDialogs<6> CmdDlgMessages;
typedef CmdDialogs<7> CmdDlgPrefs;
typedef CmdDialogs<8> CmdDlgFileInfo;
typedef CmdDialogs<9> CmdDlgPopupMenu;
typedef CmdDialogs<10> CmdDlgAdd;
/// Generic "Open dialog" command
template<int TYPE>
class CmdDialogs: public CmdGeneric
{
public:
CmdDialogs( intf_thread_t *pIntf ): CmdGeneric( pIntf ) {}
virtual ~CmdDialogs() {}
/// This method does the real job of the command
virtual void execute()
{
/// Get the dialogs provider
Dialogs *pDialogs = Dialogs::instance( getIntf() );
if( pDialogs == NULL )
{
return;
}
switch( TYPE )
{
case 1:
pDialogs->showChangeSkin();
break;
case 2:
pDialogs->showFileSimple( true );
break;
case 3:
pDialogs->showFile( true );
break;
case 4:
pDialogs->showDisc( true );
break;
case 5:
pDialogs->showNet( true );
break;
case 6:
pDialogs->showMessages();
break;
case 7:
pDialogs->showPrefs();
break;
case 8:
pDialogs->showFileInfo();
break;
case 9:
pDialogs->showPopupMenu( true );
break;
case 10:
pDialogs->showFile( false );
break;
default:
msg_Warn( getIntf(), "Unknown dialog type" );
break;
}
}
/// Return the type of the command
virtual string getType() const { return "dialog"; }
};
#endif
/*****************************************************************************
* cmd_dummy.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_dummy.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_DUMMY_HPP
#define CMD_DUMMY_HPP
#include "cmd_generic.hpp"
/// Dummy command
class CmdDummy: public CmdGeneric
{
public:
CmdDummy( intf_thread_t *pIntf ): CmdGeneric( pIntf ) {}
virtual ~CmdDummy() {}
/// This method does the real job of the command
virtual void execute() {}
/// Return the type of the command
virtual string getType() const { return "dummy"; }
};
#endif
/*****************************************************************************
* cmd_generic.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_generic.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_GENERIC_HPP
#define CMD_GENERIC_HPP
#include "../src/skin_common.hpp"
#include "../utils/pointer.hpp"
#include <string>
/// Macro to define the prototype of simple commands
#define DEFINE_COMMAND( name, type ) \
class Cmd##name: public CmdGeneric \
{ \
public: \
Cmd##name( intf_thread_t *pIntf ): CmdGeneric( pIntf ) {} \
virtual ~Cmd##name() {} \
virtual void execute(); \
virtual string getType() const { return type; } \
\
};
/// Base class for skins commands
class CmdGeneric: public SkinObject
{
public:
virtual ~CmdGeneric() {}
/// This method does the real job of the command
virtual void execute() = 0;
/// Return the type of the command
virtual string getType() const { return ""; }
protected:
CmdGeneric( intf_thread_t *pIntf ): SkinObject( pIntf ) {}
};
typedef CountedPtr<CmdGeneric> CmdGenericPtr;
#endif
/*****************************************************************************
* cmd_input.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_input.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_input.hpp"
void CmdStop::execute()
{
playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
if( pPlaylist == NULL )
{
return;
}
playlist_Stop( pPlaylist );
}
void CmdSlower::execute()
{
input_thread_t *pInput =
(input_thread_t *)vlc_object_find( getIntf(), VLC_OBJECT_INPUT,
FIND_ANYWHERE );
if( pInput )
{
vlc_value_t val;
val.b_bool = VLC_TRUE;
var_Set( pInput, "rate-slower", val );
vlc_object_release( pInput );
}
}
void CmdFaster::execute()
{
input_thread_t *pInput =
(input_thread_t *)vlc_object_find( getIntf(), VLC_OBJECT_INPUT,
FIND_ANYWHERE );
if( pInput )
{
vlc_value_t val;
val.b_bool = VLC_TRUE;
var_Set( pInput, "rate-faster", val );
vlc_object_release( pInput );
}
}
/*****************************************************************************
* cmd_input.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_input.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_INPUT_HPP
#define CMD_INPUT_HPP
#include "cmd_generic.hpp"
/// Commands to control the input
DEFINE_COMMAND( Stop, "stop" )
DEFINE_COMMAND( Slower, "slower" )
DEFINE_COMMAND( Faster, "faster" )
#endif
/*****************************************************************************
* cmd_layout.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_layout.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_layout.hpp"
#include "../src/generic_window.hpp"
#include "../src/generic_layout.hpp"
#include "../src/theme.hpp"
CmdLayout::CmdLayout( intf_thread_t *pIntf, const string &windowId,
const string &layoutId ):
CmdGeneric( pIntf ), m_windowId( windowId ), m_layoutId( layoutId )
{
}
void CmdLayout::execute()
{
// Get the window and the layout
if( !getIntf()->p_sys->p_theme )
{
return;
}
GenericWindow *pWindow =
getIntf()->p_sys->p_theme->getWindowById( m_windowId );
GenericLayout *pLayout =
getIntf()->p_sys->p_theme->getLayoutById( m_layoutId );
if( !pWindow || !pLayout )
{
msg_Err( getIntf(), "Cannot change layout (%s, %s)",
m_windowId.c_str(), m_layoutId.c_str() );
return;
}
// XXX TODO: check that the layout isn't a layout of another window
pWindow->setActiveLayout( pLayout );
}
/*****************************************************************************
* cmd_layout.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_layout.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_LAYOUT_HPP
#define CMD_LAYOUT_HPP
#include "cmd_generic.hpp"
#include <string>
/// "Change layout" command
class CmdLayout: public CmdGeneric
{
public:
CmdLayout( intf_thread_t *pIntf, const string &windowId,
const string &layoutId );
virtual ~CmdLayout() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "change layout"; }
private:
string m_windowId;
string m_layoutId;
};
#endif
/*****************************************************************************
* cmd_notify_playlist.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_notify_playlist.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_notify_playlist.hpp"
#include "../src/vlcproc.hpp"
#include "../vars/playlist.hpp"
void CmdNotifyPlaylist::execute()
{
// Notify the playlist variable
Playlist &rVar = VlcProc::instance( getIntf() )->getPlaylistVar();
rVar.onChange();
}
/*****************************************************************************
* cmd_notify_playlist.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_notify_playlist.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_NOTIFY_PLAYLIST_HPP
#define CMD_NOTIFY_PLAYLIST_HPP
#include "cmd_generic.hpp"
/// Command to notify the playlist of a change
class CmdNotifyPlaylist: public CmdGeneric
{
public:
CmdNotifyPlaylist( intf_thread_t *pIntf ): CmdGeneric( pIntf ) {}
virtual ~CmdNotifyPlaylist() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "notify playlist"; }
};
#endif
/*****************************************************************************
* cmd_on_top.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_on_top.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_on_top.hpp"
#include "../src/theme.hpp"
#include "../src/window_manager.hpp"
void CmdOnTop::execute()
{
getIntf()->p_sys->p_theme->getWindowManager().toggleOnTop();
}
/*****************************************************************************
* cmd_on_top.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_on_top.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_ON_TOP_HPP
#define CMD_ON_TOP_HPP
#include "cmd_generic.hpp"
/// "Always on top" command
class CmdOnTop: public CmdGeneric
{
public:
CmdOnTop( intf_thread_t *pIntf ): CmdGeneric( pIntf ) {}
virtual ~CmdOnTop() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "always on top"; }
};
#endif
/*****************************************************************************
* cmd_playlist.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_playlist.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_playlist.hpp"
void CmdPlaylistDel::execute()
{
m_rList.delSelected();
}
void CmdPlaylistSort::execute()
{
// XXX add the mode and type
playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
if( pPlaylist != NULL )
{
playlist_Sort( pPlaylist, SORT_TITLE, SORT_NORMAL );
}
}
void CmdPlaylistNext::execute()
{
playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
if( pPlaylist != NULL )
{
playlist_Next( pPlaylist );
}
}
void CmdPlaylistPrevious::execute()
{
playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
if( pPlaylist != NULL )
{
playlist_Prev( pPlaylist );
}
}
/*****************************************************************************
* cmd_playlist.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_playlist.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_PLAYLIST_HPP
#define CMD_PLAYLIST_HPP
#include "cmd_generic.hpp"
#include "../utils/var_list.hpp"
/// Command to delete the selected items from a list
class CmdPlaylistDel: public CmdGeneric
{
public:
CmdPlaylistDel( intf_thread_t *pIntf, VarList &rList ):
CmdGeneric( pIntf ), m_rList( rList ) {}
virtual ~CmdPlaylistDel() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "playlist del"; }
private:
/// List
VarList &m_rList;
};
/// Command to sort the playlist
DEFINE_COMMAND( PlaylistSort, "playlist sort" )
/// Command to jump to the next item
DEFINE_COMMAND( PlaylistNext, "playlist next" )
/// Command to jump to the previous item
DEFINE_COMMAND( PlaylistPrevious, "playlist previous" )
#endif
/*****************************************************************************
* cmd_quit.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_quit.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_quit.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_loop.hpp"
void CmdQuit::execute()
{
// Get the instance of OSFactory
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
// Exit the main OS loop
pOsFactory->getOSLoop()->exit();
}
/*****************************************************************************
* cmd_quit.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_quit.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_QUIT_HPP
#define CMD_QUIT_HPP
#include "cmd_generic.hpp"
/// "Quit" command
class CmdQuit: public CmdGeneric
{
public:
CmdQuit( intf_thread_t *pIntf ): CmdGeneric( pIntf ) {}
virtual ~CmdQuit() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "quit"; }
};
#endif
/*****************************************************************************
* cmd_resize.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_resize.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "cmd_resize.hpp"
#include "../src/generic_layout.hpp"
CmdResize::CmdResize( intf_thread_t *pIntf, GenericLayout &rLayout, int width,
int height ):
CmdGeneric( pIntf ), m_rLayout( rLayout ), m_width( width ),
m_height( height )
{
}
void CmdResize::execute()
{
// Resize the layout
m_rLayout.resize( m_width, m_height );
}
/*****************************************************************************
* cmd_resize.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_resize.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_RESIZE_HPP
#define CMD_RESIZE_HPP
#include "cmd_generic.hpp"
class GenericLayout;
/// Command to resize a layout
class CmdResize: public CmdGeneric
{
public:
/// Resize the given layout
CmdResize( intf_thread_t *pIntf, GenericLayout &rLayout, int width,
int height );
virtual ~CmdResize() {}
/// This method does the real job of the command
virtual void execute();
/// Return the type of the command
virtual string getType() const { return "resize"; }
private:
GenericLayout &m_rLayout;
int m_width, m_height;
};
#endif
/*****************************************************************************
* cmd_show_window.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: cmd_show_window.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CMD_SHOW_WINDOW_HPP
#define CMD_SHOW_WINDOW_HPP
#include "cmd_generic.hpp"
#include "../utils/var_bool.hpp"
template<bool newValue> class CmdShowHideWindow;
typedef CmdShowHideWindow<true> CmdShowWindow;
typedef CmdShowHideWindow<false> CmdHideWindow;
/// "Show/Hide window" command
template<bool newValue>
class CmdShowHideWindow: public CmdGeneric
{
public:
CmdShowHideWindow( intf_thread_t *pIntf, VarBool &rVariable ):
CmdGeneric( pIntf ), m_rVariable( rVariable ) {}
virtual ~CmdShowHideWindow() {}
/// This method does the real job of the command
virtual void execute() { m_rVariable.set( newValue ); }
/// Return the type of the command
virtual string getType() const { return "show/hide window"; }
private:
/// Reference to the observed variable
VarBool &m_rVariable;
};
#endif
/*****************************************************************************
* ctrl_button.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_button.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "ctrl_button.hpp"
#include "../events/evt_generic.hpp"
#include "../src/generic_bitmap.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp"
#include "../commands/cmd_generic.hpp"
CtrlButton::CtrlButton( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
const GenericBitmap &rBmpOver,
const GenericBitmap &rBmpDown, CmdGeneric &rCommand,
const UString &rTooltip, const UString &rHelp ):
CtrlGeneric( pIntf, rHelp ), m_fsm( pIntf ), m_rCommand( rCommand ),
m_tooltip( rTooltip ),
m_cmdUpOverDownOver( this, &transUpOverDownOver ),
m_cmdDownOverUpOver( this, &transDownOverUpOver ),
m_cmdDownOverDown( this, &transDownOverDown ),
m_cmdDownDownOver( this, &transDownDownOver ),
m_cmdUpOverUp( this, &transUpOverUp ),
m_cmdUpUpOver( this, &transUpUpOver ),
m_cmdDownUp( this, &transDownUp ),
m_cmdUpHidden( this, &transUpHidden ),
m_cmdHiddenUp( this, &transHiddenUp )
{
// Build the images of the button
OSFactory *pOsFactory = OSFactory::instance( pIntf );
m_pImgUp = pOsFactory->createOSGraphics( rBmpUp.getWidth(),
rBmpUp.getHeight() );
m_pImgUp->drawBitmap( rBmpUp, 0, 0 );
m_pImgDown = pOsFactory->createOSGraphics( rBmpDown.getWidth(),
rBmpDown.getHeight() );
m_pImgDown->drawBitmap( rBmpDown, 0, 0 );
m_pImgOver = pOsFactory->createOSGraphics( rBmpOver.getWidth(),
rBmpOver.getHeight() );
m_pImgOver->drawBitmap( rBmpOver, 0, 0 );
// States
m_fsm.addState( "up" );
m_fsm.addState( "down" );
m_fsm.addState( "upOver" );
m_fsm.addState( "downOver" );
m_fsm.addState( "hidden" );
// Transitions
m_fsm.addTransition( "upOver", "mouse:left:down", "downOver",
&m_cmdUpOverDownOver );
m_fsm.addTransition( "downOver", "mouse:left:up", "upOver",
&m_cmdDownOverUpOver );
m_fsm.addTransition( "downOver", "leave", "down", &m_cmdDownOverDown );
m_fsm.addTransition( "down", "enter", "downOver", &m_cmdDownDownOver );
m_fsm.addTransition( "upOver", "leave", "up", &m_cmdUpOverUp );
m_fsm.addTransition( "up", "enter", "upOver", &m_cmdUpUpOver );
m_fsm.addTransition( "down", "mouse:left:up", "up", &m_cmdDownUp );
// XXX: It would be easy to use a "ANY" initial state to handle these
// four lines in only one. But till now it isn't worthwhile...
m_fsm.addTransition( "up", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "down", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "upOver", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "downOver", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "hidden", "special:show", "up", &m_cmdHiddenUp );
// Initial state
m_fsm.setState( "up" );
m_pImg = m_pImgUp;
}
CtrlButton::~CtrlButton()
{
SKINS_DELETE( m_pImgUp );
SKINS_DELETE( m_pImgDown );
SKINS_DELETE( m_pImgOver );
}
void CtrlButton::handleEvent( EvtGeneric &rEvent )
{
m_fsm.handleTransition( rEvent.getAsString() );
}
bool CtrlButton::mouseOver( int x, int y ) const
{
if( m_pImg )
{
return m_pImg->hit( x, y );
}
else
{
return false;
}
}
void CtrlButton::draw( OSGraphics &rImage, int xDest, int yDest )
{
if( m_pImg )
{
// Draw the current image
rImage.drawGraphics( *m_pImg, 0, 0, xDest, yDest );
}
}
void CtrlButton::transUpOverDownOver( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->captureMouse();
pThis->m_pImg = pThis->m_pImgDown;
pThis->notifyLayout();
}
void CtrlButton::transDownOverUpOver( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->releaseMouse();
pThis->m_pImg = pThis->m_pImgUp;
pThis->notifyLayout();
// Execute the command associated to this button
pThis->m_rCommand.execute();
}
void CtrlButton::transDownOverDown( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->m_pImg = pThis->m_pImgUp;
pThis->notifyLayout();
}
void CtrlButton::transDownDownOver( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->m_pImg = pThis->m_pImgDown;
pThis->notifyLayout();
}
void CtrlButton::transUpUpOver( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->m_pImg = pThis->m_pImgOver;
pThis->notifyLayout();
}
void CtrlButton::transUpOverUp( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->m_pImg = pThis->m_pImgUp;
pThis->notifyLayout();
}
void CtrlButton::transDownUp( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->releaseMouse();
}
void CtrlButton::transUpHidden( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->m_pImg = NULL;
pThis->notifyLayout();
}
void CtrlButton::transHiddenUp( SkinObject *pCtrl )
{
CtrlButton *pThis = (CtrlButton*)pCtrl;
pThis->m_pImg = pThis->m_pImgUp;
pThis->notifyLayout();
}
/*****************************************************************************
* ctrl_button.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_button.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_BUTTON_HPP
#define CTRL_BUTTON_HPP
#include "ctrl_generic.hpp"
#include "../utils/fsm.hpp"
class GenericBitmap;
class OSGraphics;
class CmdGeneric;
/// Base class for button controls
class CtrlButton: public CtrlGeneric
{
public:
/// Create a button with 3 images
CtrlButton( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
const GenericBitmap &rBmpOver,
const GenericBitmap &rBmpDown,
CmdGeneric &rCommand, const UString &rTooltip,
const UString &rHelp );
virtual ~CtrlButton();
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Get the text of the tooltip
virtual UString getTooltipText() const { return m_tooltip; }
private:
/// Finite state machine of the control
FSM m_fsm;
/// Command triggered by the button
CmdGeneric &m_rCommand;
/// Tooltip text
const UString m_tooltip;
/// Callbacks objects
Callback m_cmdUpOverDownOver;
Callback m_cmdDownOverUpOver;
Callback m_cmdDownOverDown;
Callback m_cmdDownDownOver;
Callback m_cmdUpOverUp;
Callback m_cmdUpUpOver;
Callback m_cmdDownUp;
Callback m_cmdUpHidden;
Callback m_cmdHiddenUp;
/// Images of the button in the different states
OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
/// Current image
OSGraphics *m_pImg;
/// Callback functions
static void transUpOverDownOver( SkinObject *pCtrl );
static void transDownOverUpOver( SkinObject *pCtrl );
static void transDownOverDown( SkinObject *pCtrl );
static void transDownDownOver( SkinObject *pCtrl );
static void transUpOverUp( SkinObject *pCtrl );
static void transUpUpOver( SkinObject *pCtrl );
static void transDownUp( SkinObject *pCtrl );
static void transUpHidden( SkinObject *pCtrl );
static void transHiddenUp( SkinObject *pCtrl );
};
#endif
/*****************************************************************************
* ctrl_checkbox.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_checkbox.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "ctrl_checkbox.hpp"
#include "../events/evt_generic.hpp"
#include "../commands/cmd_generic.hpp"
#include "../src/generic_bitmap.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp"
#include "../utils/var_bool.hpp"
CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf,
const GenericBitmap &rBmpUp1,
const GenericBitmap &rBmpOver1,
const GenericBitmap &rBmpDown1,
const GenericBitmap &rBmpUp2,
const GenericBitmap &rBmpOver2,
const GenericBitmap &rBmpDown2,
CmdGeneric &rCommand1, CmdGeneric &rCommand2,
const UString &rTooltip1,
const UString &rTooltip2,
VarBool &rVariable, const UString &rHelp ):
CtrlGeneric( pIntf, rHelp ), m_fsm( pIntf ), m_rVariable( rVariable ),
m_rCommand1( rCommand1 ), m_rCommand2( rCommand2 ),
m_tooltip1( rTooltip1 ), m_tooltip2( rTooltip2 ),
m_cmdUpOverDownOver( this, &transUpOverDownOver ),
m_cmdDownOverUpOver( this, &transDownOverUpOver ),
m_cmdDownOverDown( this, &transDownOverDown ),
m_cmdDownDownOver( this, &transDownDownOver ),
m_cmdUpOverUp( this, &transUpOverUp ),
m_cmdUpUpOver( this, &transUpUpOver ),
m_cmdDownUp( this, &transDownUp ),
m_cmdUpHidden( this, &transUpHidden ),
m_cmdHiddenUp( this, &transHiddenUp )
{
// Build the images of the checkbox
OSFactory *pOsFactory = OSFactory::instance( pIntf );
m_pImgUp1 = pOsFactory->createOSGraphics( rBmpUp1.getWidth(),
rBmpUp1.getHeight() );
m_pImgUp1->drawBitmap( rBmpUp1, 0, 0 );
m_pImgDown1 = pOsFactory->createOSGraphics( rBmpDown1.getWidth(),
rBmpDown1.getHeight() );
m_pImgDown1->drawBitmap( rBmpDown1, 0, 0 );
m_pImgOver1 = pOsFactory->createOSGraphics( rBmpOver1.getWidth(),
rBmpOver1.getHeight() );
m_pImgOver1->drawBitmap( rBmpOver1, 0, 0 );
m_pImgUp2 = pOsFactory->createOSGraphics( rBmpUp2.getWidth(),
rBmpUp2.getHeight() );
m_pImgUp2->drawBitmap( rBmpUp2, 0, 0 );
m_pImgDown2 = pOsFactory->createOSGraphics( rBmpDown2.getWidth(),
rBmpDown2.getHeight() );
m_pImgDown2->drawBitmap( rBmpDown2, 0, 0 );
m_pImgOver2 = pOsFactory->createOSGraphics( rBmpOver2.getWidth(),
rBmpOver2.getHeight() );
m_pImgOver2->drawBitmap( rBmpOver2, 0, 0 );
// States
m_fsm.addState( "up" );
m_fsm.addState( "down" );
m_fsm.addState( "upOver" );
m_fsm.addState( "downOver" );
m_fsm.addState( "hidden" );
// Transitions
m_fsm.addTransition( "upOver", "mouse:left:down", "downOver",
&m_cmdUpOverDownOver );
m_fsm.addTransition( "downOver", "mouse:left:up", "upOver",
&m_cmdDownOverUpOver );
m_fsm.addTransition( "downOver", "leave", "down", &m_cmdDownOverDown );
m_fsm.addTransition( "down", "enter", "downOver", &m_cmdDownDownOver );
m_fsm.addTransition( "upOver", "leave", "up", &m_cmdUpOverUp );
m_fsm.addTransition( "up", "enter", "upOver", &m_cmdUpUpOver );
m_fsm.addTransition( "down", "mouse:left:up", "up", &m_cmdDownUp );
// XXX: It would be easy to use a "ANY" initial state to handle these
// four lines in only one. But till now it isn't worthwhile...
m_fsm.addTransition( "up", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "down", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "upOver", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "downOver", "special:hide", "hidden", &m_cmdUpHidden );
m_fsm.addTransition( "hidden", "special:show", "up", &m_cmdHiddenUp );
// Observe the variable
m_rVariable.addObserver( this );
// Initial state
m_fsm.setState( "up" );
if( !m_rVariable.get() )
{
m_pImgUp = m_pImgUp1;
m_pImgOver = m_pImgOver1;
m_pImgDown = m_pImgDown1;
m_pImgCurrent = m_pImgUp;
m_pCommand = &m_rCommand1;
m_pTooltip = &m_tooltip1;
}
else
{
m_pImgUp = m_pImgUp2;
m_pImgOver = m_pImgOver2;
m_pImgDown = m_pImgDown2;
m_pImgCurrent = m_pImgDown;
m_pCommand = &m_rCommand2;
m_pTooltip = &m_tooltip2;
}
}
CtrlCheckbox::~CtrlCheckbox()
{
m_rVariable.delObserver( this );
SKINS_DELETE( m_pImgUp1 );
SKINS_DELETE( m_pImgDown1 );
SKINS_DELETE( m_pImgOver1 );
SKINS_DELETE( m_pImgUp2 );
SKINS_DELETE( m_pImgDown2 );
SKINS_DELETE( m_pImgOver2 );
}
void CtrlCheckbox::handleEvent( EvtGeneric &rEvent )
{
m_fsm.handleTransition( rEvent.getAsString() );
}
bool CtrlCheckbox::mouseOver( int x, int y ) const
{
if( m_pImgCurrent )
{
return m_pImgCurrent->hit( x, y );
}
else
{
return false;
}
}
void CtrlCheckbox::draw( OSGraphics &rImage, int xDest, int yDest )
{
if( m_pImgCurrent )
{
// Draw the current image
rImage.drawGraphics( *m_pImgCurrent, 0, 0, xDest, yDest );
}
}
void CtrlCheckbox::transUpOverDownOver( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->captureMouse();
pThis->m_pImgCurrent = pThis->m_pImgDown;
pThis->notifyLayout();
}
void CtrlCheckbox::transDownOverUpOver( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->releaseMouse();
// Invert the state variable
pThis->m_rVariable.set( !pThis->m_rVariable.get() );
pThis->m_pImgCurrent = pThis->m_pImgUp;
pThis->notifyLayout();
// Execute the command
pThis->m_pCommand->execute();
}
void CtrlCheckbox::transDownOverDown( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->m_pImgCurrent = pThis->m_pImgUp;
pThis->notifyLayout();
}
void CtrlCheckbox::transDownDownOver( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->m_pImgCurrent = pThis->m_pImgDown;
pThis->notifyLayout();
}
void CtrlCheckbox::transUpUpOver( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->m_pImgCurrent = pThis->m_pImgOver;
pThis->notifyLayout();
}
void CtrlCheckbox::transUpOverUp( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->m_pImgCurrent = pThis->m_pImgUp;
pThis->notifyLayout();
}
void CtrlCheckbox::transDownUp( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->releaseMouse();
}
void CtrlCheckbox::transUpHidden( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->m_pImgCurrent = NULL;
pThis->notifyLayout();
}
void CtrlCheckbox::transHiddenUp( SkinObject *pCtrl )
{
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl;
pThis->m_pImgCurrent = pThis->m_pImgUp;
pThis->notifyLayout();
}
void CtrlCheckbox::onUpdate( Subject<VarBool> &rVariable )
{
changeButton();
}
void CtrlCheckbox::changeButton()
{
// Are we using the first set of images or the second one?
if( m_pImgUp == m_pImgUp1 )
{
m_pImgUp = m_pImgUp2;
m_pImgOver = m_pImgOver2;
m_pImgDown = m_pImgDown2;
m_pTooltip = &m_tooltip2;
m_pCommand = &m_rCommand2;
}
else
{
m_pImgUp = m_pImgUp1;
m_pImgOver = m_pImgOver1;
m_pImgDown = m_pImgDown1;
m_pTooltip = &m_tooltip1;
m_pCommand = &m_rCommand1;
}
// XXX: We assume that the checkbox is up
m_pImgCurrent = m_pImgUp;
// Notify the window the tooltip has changed
notifyTooltipChange();
// Refresh
notifyLayout();
}
/*****************************************************************************
* ctrl_checkbox.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_checkbox.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_CHECKBOX_HPP
#define CTRL_CHECKBOX_HPP
#include "ctrl_generic.hpp"
#include "../utils/fsm.hpp"
#include "../utils/observer.hpp"
class GenericBitmap;
class OSGraphics;
class CmdGeneric;
class VarBool;
/// Base class for checkbox controls
class CtrlCheckbox: public CtrlGeneric, public Observer<VarBool>
{
public:
/// Create a checkbox with 6 images
CtrlCheckbox( intf_thread_t *pIntf,
const GenericBitmap &rBmpUp1,
const GenericBitmap &rBmpOver1,
const GenericBitmap &rBmpDown1,
const GenericBitmap &rBmpUp2,
const GenericBitmap &rBmpOver2,
const GenericBitmap &rBmpDown2,
CmdGeneric &rCommand1, CmdGeneric &rCommand2,
const UString &rTooltip1, const UString &rTooltip2,
VarBool &rVariable, const UString &rHelp );
virtual ~CtrlCheckbox();
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Get the text of the tooltip XXX
virtual UString getTooltipText() const { return *m_pTooltip; }
private:
/// Finite state machine of the control
FSM m_fsm;
/// Observed variable
VarBool &m_rVariable;
/// Commands for the 2 states
CmdGeneric &m_rCommand1, &m_rCommand2;
/// Current command
CmdGeneric *m_pCommand;
/// Tooltip texts for the 2 states
const UString m_tooltip1, m_tooltip2;
/// Current tooltip
const UString *m_pTooltip;
/// Callbacks objects
Callback m_cmdUpOverDownOver;
Callback m_cmdDownOverUpOver;
Callback m_cmdDownOverDown;
Callback m_cmdDownDownOver;
Callback m_cmdUpOverUp;
Callback m_cmdUpUpOver;
Callback m_cmdDownUp;
Callback m_cmdUpHidden;
Callback m_cmdHiddenUp;
/// Images of the checkbox in the different states
OSGraphics *m_pImgUp1, *m_pImgOver1, *m_pImgDown1;
OSGraphics *m_pImgUp2, *m_pImgOver2, *m_pImgDown2;
/// Current set of images (pointing to 1 or 2)
/// In fact, we consider here that a checkbox acts like 2 buttons, in a
/// symetric way; this is a small trick to avoid multiplicating the
/// callbacks (and it could be extended easily to support 3 buttons or
/// more...)
OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
/// Current image
OSGraphics *m_pImgCurrent;
/// Callback functions
static void transUpOverDownOver( SkinObject *pCtrl );
static void transDownOverUpOver( SkinObject *pCtrl );
static void transDownOverDown( SkinObject *pCtrl );
static void transDownDownOver( SkinObject *pCtrl );
static void transUpOverUp( SkinObject *pCtrl );
static void transUpUpOver( SkinObject *pCtrl );
static void transDownUp( SkinObject *pCtrl );
static void transUpHidden( SkinObject *pCtrl );
static void transHiddenUp( SkinObject *pCtrl );
/// Method called when the observed variable is modified
virtual void onUpdate( Subject<VarBool> &rVariable );
/// Helper function to update the current state of images
void changeButton();
};
#endif
/*****************************************************************************
* ctrl_flat.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_flat.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_FLAT_HPP
#define CTRL_FLAT_HPP
#include "ctrl_generic.hpp"
/// Base class for "mover controls" and images
class CtrlFlat: public CtrlGeneric
{
protected:
CtrlFlat( intf_thread_t *pIntf, const UString &rHelp ):
CtrlGeneric( pIntf, rHelp ) {}
virtual ~CtrlFlat() {}
};
#endif
/*****************************************************************************
* ctrl_generic.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_generic.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "ctrl_generic.hpp"
#include "../src/generic_layout.hpp"
#include "../src/generic_window.hpp"
#include "../src/os_graphics.hpp"
#include "../utils/position.hpp"
CtrlGeneric::CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp ):
SkinObject( pIntf ), m_pLayout( NULL ), m_pPosition( NULL ),
m_help( rHelp )
{
}
CtrlGeneric::~CtrlGeneric()
{
if( m_pPosition )
{
delete m_pPosition;
}
}
void CtrlGeneric::setLayout( GenericLayout *pLayout,
const Position &rPosition )
{
m_pLayout = pLayout;
if( m_pPosition )
{
delete m_pPosition;
}
m_pPosition = new Position( rPosition );
onPositionChange();
}
void CtrlGeneric::notifyLayout() const
{
// Notify the layout
if( m_pLayout )
{
m_pLayout->onControlUpdate( *this );
}
}
void CtrlGeneric::captureMouse() const
{
// Tell the layout we want to capture the mouse
if( m_pLayout )
{
m_pLayout->onControlCapture( *this );
}
}
void CtrlGeneric::releaseMouse() const
{
// Tell the layout we want to release the mouse
if( m_pLayout )
{
m_pLayout->onControlRelease( *this );
}
}
void CtrlGeneric::notifyTooltipChange() const
{
GenericWindow *pWin = getWindow();
if( pWin )
{
// Notify the window
pWin->onTooltipChange( *this );
}
}
GenericWindow *CtrlGeneric::getWindow() const
{
if( m_pLayout )
{
return m_pLayout->getWindow();
}
return NULL;
}
/*****************************************************************************
* ctrl_generic.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_generic.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_GENERIC_HPP
#define CTRL_GENERIC_HPP
#include "../src/skin_common.hpp"
#include "../utils/pointer.hpp"
#include "../utils/fsm.hpp"
#include "../utils/ustring.hpp"
class EvtGeneric;
class OSGraphics;
class GenericLayout;
class Position;
class GenericWindow;
/// Base class for controls
class CtrlGeneric: public SkinObject
{
public:
virtual ~CtrlGeneric();
/// Handle an event on the control
virtual void handleEvent( EvtGeneric &rEvent ) {}
/// Check whether coordinates are inside the control
virtual bool mouseOver( int x, int y ) const { return false; }
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest ) {}
/// Set the position and the associated layout of the control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
/// Get the position of the control in the layout, if any
virtual const Position *getPosition() const { return m_pPosition; }
/// Get the text of the tooltip
virtual UString getTooltipText() const
{ return UString( getIntf(), "" ); }
/// Overload this method if you want to do something special when
/// the layout is resized
virtual void onResize() {}
/// Get the help text
virtual const UString &getHelpText() const { return m_help; }
/// Return true if the control can gain the focus
virtual bool isFocusable() const { return false; }
protected:
CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp );
/// Tell the layout when the image has changed
virtual void notifyLayout() const;
/// Ask the layout to capture the mouse
virtual void captureMouse() const;
/// Ask the layout to release the mouse
virtual void releaseMouse() const;
/// Notify the window the tooltip has changed
virtual void notifyTooltipChange() const;
/// Get the associated window, if any
virtual GenericWindow *getWindow() const;
/// Overload this method if you want to do something special when
/// the Position object is set
virtual void onPositionChange() {}
private:
/// Associated layout
GenericLayout *m_pLayout;
/// Position in the layout
Position *m_pPosition;
/// Help text
UString m_help;
};
typedef CountedPtr<CtrlGeneric> CtrlGenericPtr;
#endif
/*****************************************************************************
* ctrl_image.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_image.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "ctrl_image.hpp"
#include "../commands/cmd_dialogs.hpp"
#include "../events/evt_generic.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp"
#include "../src/scaled_bitmap.hpp"
#include "../utils/position.hpp"
CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
const UString &rHelp ):
CtrlFlat( pIntf, rHelp ), m_rBitmap( rBitmap )
{
OSFactory *pOsFactory = OSFactory::instance( pIntf );
// Create an initial unscaled image in the buffer
m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
rBitmap.getHeight() );
m_pImage->drawBitmap( m_rBitmap );
}
CtrlImage::~CtrlImage()
{
SKINS_DELETE( m_pImage );
}
void CtrlImage::handleEvent( EvtGeneric &rEvent )
{
// No FSM for this simple transition
if( rEvent.getAsString() == "mouse:right:down:none" )
{
CmdDlgPopupMenu cmd( getIntf() );
cmd.execute();
}
}
bool CtrlImage::mouseOver( int x, int y ) const
{
return m_pImage->hit( x, y );
}
void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest )
{
const Position *pPos = getPosition();
if( pPos )
{
int width = pPos->getWidth();
int height = pPos->getHeight();
if( width != m_pImage->getWidth() || height != m_pImage->getHeight() )
{
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
// Rescale the image with the actual size of the control
ScaledBitmap bmp( getIntf(), m_rBitmap, width, height );
SKINS_DELETE( m_pImage );
m_pImage = pOsFactory->createOSGraphics( width, height );
m_pImage->drawBitmap( bmp, 0, 0 );
}
rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
}
}
/*****************************************************************************
* ctrl_image.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_image.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_IMAGE_HPP
#define CTRL_IMAGE_HPP
#include "../commands/cmd_generic.hpp"
#include "ctrl_flat.hpp"
class GenericBitmap;
class OSGraphics;
/// Control image
class CtrlImage: public CtrlFlat
{
public:
// Create an image with the given bitmap (which is NOT copied)
CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
const UString &rHelp );
virtual ~CtrlImage();
/// Handle an event on the control
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
private:
/// Bitmap
const GenericBitmap &m_rBitmap;
/// Buffer to stored the rendered bitmap
OSGraphics *m_pImage;
};
#endif
This diff is collapsed.
/*****************************************************************************
* ctrl_list.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_list.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_LIST_HPP
#define CTRL_LIST_HPP
#include "ctrl_generic.hpp"
#include "../utils/observer.hpp"
#include "../utils/var_list.hpp"
class OSGraphics;
class GenericFont;
/// Class for control list
class CtrlList: public CtrlGeneric, public Observer<VarList>,
public Observer<VarPercent>
{
public:
CtrlList( intf_thread_t *pIntf, VarList &rList, GenericFont &rFont,
uint32_t fgcolor, uint32_t playcolor, uint32_t bgcolor1,
uint32_t bgcolor2, uint32_t selColor,
const UString &rHelp );
virtual ~CtrlList();
/// Handle an event on the control.
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the control.
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Called when the layout is resized
virtual void onResize();
/// Return true if the control can gain the focus
virtual bool isFocusable() const { return true; }
private:
/// List associated to the control
VarList &m_rList;
/// Font
GenericFont &m_rFont;
/// Color of normal text
uint32_t m_fgColor;
/// Color of the playing item
uint32_t m_playColor;
/// Background colors
uint32_t m_bgColor1, m_bgColor2;
/// Background of selected items
uint32_t m_selColor;
/// Pointer on the last selected item in the list
VarList::Elem_t *m_pLastSelected;
/// Image of the control
OSGraphics *m_pImage;
/// Last position
int m_lastPos;
/// Method called when the list variable is modified
virtual void onUpdate( Subject<VarList> &rList );
/// Method called when the position variable of the list is modified
virtual void onUpdate( Subject<VarPercent> &rPercent );
/// Called when the position is set
virtual void onPositionChange();
/// Draw the image of the control
void makeImage();
};
#endif
/*****************************************************************************
* ctrl_move.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_move.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "ctrl_move.hpp"
#include "../events/evt_generic.hpp"
#include "../events/evt_mouse.hpp"
#include "../events/evt_motion.hpp"
#include "../src/generic_window.hpp"
#include "../src/window_manager.hpp"
#include "../utils/position.hpp"
CtrlMove::CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager,
CtrlFlat &rCtrl, GenericWindow &rWindow,
const UString &rHelp ):
CtrlFlat( pIntf, rHelp ), m_fsm( pIntf ),
m_rWindowManager( rWindowManager ),
m_rCtrl( rCtrl ), m_rWindow( rWindow ),
m_cmdMovingMoving( this, &transMovingMoving ),
m_cmdStillMoving( this, &transStillMoving ),
m_cmdMovingStill( this, &transMovingStill )
{
m_pEvt = NULL;
m_xPos = 0;
m_yPos = 0;
// States
m_fsm.addState( "moving" );
m_fsm.addState( "still" );
// Transitions
m_fsm.addTransition( "moving", "mouse:left:up:none", "still",
&m_cmdMovingStill );
m_fsm.addTransition( "still", "mouse:left:down:none", "moving",
&m_cmdStillMoving );
m_fsm.addTransition( "moving", "motion", "moving", &m_cmdMovingMoving );
m_fsm.setState( "still" );
}
bool CtrlMove::mouseOver( int x, int y ) const
{
return m_rCtrl.mouseOver( x, y );
}
void CtrlMove::draw( OSGraphics &rImage, int xDest, int yDest )
{
m_rCtrl.draw( rImage, xDest, yDest );
}
void CtrlMove::setLayout( GenericLayout *pLayout, const Position &rPosition )
{
CtrlGeneric::setLayout( pLayout, rPosition );
// Set the layout of the decorated control as well
m_rCtrl.setLayout( pLayout, rPosition );
}
const Position *CtrlMove::getPosition() const
{
return m_rCtrl.getPosition();
}
void CtrlMove::handleEvent( EvtGeneric &rEvent )
{
m_pEvt = &rEvent;
m_fsm.handleTransition( rEvent.getAsString() );
// Transmit the event to the decorated control
// XXX: Is it really a good idea?
m_rCtrl.handleEvent( rEvent );
}
void CtrlMove::transStillMoving( SkinObject *pCtrl )
{
CtrlMove *pThis = (CtrlMove*)pCtrl;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
pThis->m_xPos = pEvtMouse->getXPos();
pThis->m_yPos = pEvtMouse->getYPos();
pThis->captureMouse();
pThis->m_rWindowManager.startMove( &pThis->m_rWindow );
}
void CtrlMove::transMovingMoving( SkinObject *pCtrl )
{
CtrlMove *pThis = (CtrlMove*)pCtrl;
EvtMotion *pEvtMotion = (EvtMotion*)pThis->m_pEvt;
int xNewLeft = pEvtMotion->getXPos() - pThis->m_xPos +
pThis->m_rWindow.getLeft();
int yNewTop = pEvtMotion->getYPos() - pThis->m_yPos +
pThis->m_rWindow.getTop();
pThis->m_rWindowManager.move( &pThis->m_rWindow, xNewLeft, yNewTop );
}
void CtrlMove::transMovingStill( SkinObject *pCtrl )
{
CtrlMove *pThis = (CtrlMove*)pCtrl;
pThis->releaseMouse();
pThis->m_rWindowManager.stopMove();
}
/*****************************************************************************
* ctrl_move.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_move.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_MOVE_HPP
#define CTRL_MOVE_HPP
#include "../commands/cmd_generic.hpp"
#include "../utils/fsm.hpp"
#include "ctrl_flat.hpp"
class GenericWindow;
class WindowManager;
/// Control for moving windows
class CtrlMove: public CtrlFlat
{
public:
CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager,
CtrlFlat &rCtrl, GenericWindow &rWindow,
const UString &rHelp );
virtual ~CtrlMove() {}
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the decorated control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Set the position and the associated layout of the decorated control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
/// Get the position of the decorated control in the layout, if any
virtual const Position *getPosition() const;
static void transMovingMoving( SkinObject *pCtrl );
static void transStillMoving( SkinObject *pCtrl );
static void transMovingStill( SkinObject *pCtrl );
private:
FSM m_fsm;
/// Window manager
WindowManager &m_rWindowManager;
/// Decorated CtrlFlat
CtrlFlat &m_rCtrl;
/// The window moved by this control
GenericWindow &m_rWindow;
/// The last received event
EvtGeneric *m_pEvt;
/// Position of the click that started the move
int m_xPos, m_yPos;
/// Callbacks
Callback m_cmdMovingMoving;
Callback m_cmdStillMoving;
Callback m_cmdMovingStill;
};
#endif
/*****************************************************************************
* ctrl_radialslider.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_radialslider.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <math.h>
#include "ctrl_radialslider.hpp"
#include "../events/evt_mouse.hpp"
#include "../src/generic_bitmap.hpp"
#include "../src/generic_window.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp"
#include "../utils/position.hpp"
#include "../utils/var_percent.hpp"
CtrlRadialSlider::CtrlRadialSlider( intf_thread_t *pIntf,
const GenericBitmap &rBmpSeq, int numImg,
VarPercent &rVariable, double minAngle,
double maxAngle, const UString &rHelp ):
CtrlGeneric( pIntf, rHelp ), m_fsm( pIntf ), m_numImg( numImg ),
m_rVariable( rVariable ), m_minAngle( minAngle ), m_maxAngle( maxAngle ),
m_cmdUpDown( this, &transUpDown ), m_cmdDownUp( this, &transDownUp ),
m_cmdMove( this, &transMove ), m_position( 0 ), m_lastPos( 0 )
{
// Build the images of the sequence
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
m_pImgSeq = pOsFactory->createOSGraphics( rBmpSeq.getWidth(),
rBmpSeq.getHeight() );
m_pImgSeq->drawBitmap( rBmpSeq, 0, 0 );
m_width = rBmpSeq.getWidth();
m_height = rBmpSeq.getHeight() / numImg;
// States
m_fsm.addState( "up" );
m_fsm.addState( "down" );
// Transitions
m_fsm.addTransition( "up", "mouse:left:down", "down", &m_cmdUpDown );
m_fsm.addTransition( "down", "mouse:left:up", "up", &m_cmdDownUp );
m_fsm.addTransition( "down", "motion", "down", &m_cmdMove );
// Initial state
m_fsm.setState( "up" );
// Observe the variable
m_rVariable.addObserver( this );
}
CtrlRadialSlider::~CtrlRadialSlider()
{
m_rVariable.delObserver( this );
SKINS_DELETE( m_pImgSeq );
}
void CtrlRadialSlider::handleEvent( EvtGeneric &rEvent )
{
// Save the event to use it in callbacks
m_pEvt = &rEvent;
m_fsm.handleTransition( rEvent.getAsString() );
}
bool CtrlRadialSlider::mouseOver( int x, int y ) const
{
return m_pImgSeq->hit( x, y + m_position * m_height );
}
void CtrlRadialSlider::draw( OSGraphics &rImage, int xDest, int yDest )
{
rImage.drawGraphics( *m_pImgSeq, 0, m_position * m_height, xDest, yDest,
m_width, m_height );
}
void CtrlRadialSlider::onUpdate( Subject<VarPercent> &rVariable )
{
m_position = (int)( m_rVariable.get() * m_numImg );
notifyLayout();
}
void CtrlRadialSlider::transUpDown( SkinObject *pCtrl )
{
CtrlRadialSlider *pThis = (CtrlRadialSlider*)pCtrl;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Change the position of the cursor, in non-blocking mode
pThis->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), false );
pThis->captureMouse();
}
void CtrlRadialSlider::transDownUp( SkinObject *pCtrl )
{
CtrlRadialSlider *pThis = (CtrlRadialSlider*)pCtrl;
pThis->releaseMouse();
}
void CtrlRadialSlider::transMove( SkinObject *pCtrl )
{
CtrlRadialSlider *pThis = (CtrlRadialSlider*)pCtrl;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Change the position of the cursor, in blocking mode
pThis->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), true );
}
void CtrlRadialSlider::setCursor( int posX, int posY, bool blocking )
{
// Get the position of the control
const Position *pPos = getPosition();
if( !pPos )
{
return;
}
// Compute the position relative to the center
int x = posX - pPos->getLeft() - m_width / 2;
int y = posY - pPos->getTop() - m_width / 2;
// Compute the polar coordinates. angle is -(-j,OM)
double r = sqrt(x*x + y*y);
if( r == 0 )
{
return;
}
double angle = acos(y/r);
if( x > 0 )
{
angle = 2*M_PI - angle;
}
if( angle >= m_minAngle && angle <= m_maxAngle )
{
double newVal = (angle - m_minAngle) / (m_maxAngle - m_minAngle);
// Avoid too fast moves of the cursor if blocking mode
if( !blocking || fabs( m_rVariable.get() - newVal ) < 0.5 )
{
m_rVariable.set( newVal );
}
}
}
/*****************************************************************************
* ctrl_radialslider.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_radialslider.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_RADIALSLIDER_HPP
#define CTRL_RADIALSLIDER_HPP
#include "ctrl_generic.hpp"
#include "../utils/fsm.hpp"
#include "../utils/observer.hpp"
class GenericBitmap;
class OSGraphics;
class VarPercent;
/// Radial slider
class CtrlRadialSlider: public CtrlGeneric, public Observer<VarPercent>
{
public:
/// Create a radial slider with the given image, which must be
/// composed of numImg subimages of the same size
CtrlRadialSlider( intf_thread_t *pIntf, const GenericBitmap &rBmpSeq,
int numImg, VarPercent &rVariable, double minAngle,
double maxAngle, const UString &rHelp );
virtual ~CtrlRadialSlider();
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
private:
/// Finite state machine of the control
FSM m_fsm;
/// Number of sub-images in the slider image
int m_numImg;
/// Variable associated to the slider
VarPercent &m_rVariable;
/// Min and max angles of the button
double m_minAngle, m_maxAngle;
/// Callbacks objects
Callback m_cmdUpDown;
Callback m_cmdDownUp;
Callback m_cmdMove;
/// Position of the cursor
int m_position;
/// Size of an image
int m_width, m_height;
/// The last received event
EvtGeneric *m_pEvt;
/// Sequence of images
OSGraphics *m_pImgSeq;
/// Last saved position
int m_lastPos;
/// Callback functions
static void transUpDown( SkinObject *pCtrl );
static void transDownUp( SkinObject *pCtrl );
static void transMove( SkinObject *pCtrl );
/// Method called when the observed variable is modified
virtual void onUpdate( Subject<VarPercent> &rVariable );
/// Change the position of the cursor, with the given position of
/// the mouse (relative to the layout). Is blocking is true, the
/// the cursor cannot do more than a half turn
void setCursor( int posX, int posY, bool blocking );
};
#endif
/*****************************************************************************
* ctrl_resize.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_resize.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "ctrl_resize.hpp"
#include "../events/evt_generic.hpp"
#include "../events/evt_mouse.hpp"
#include "../events/evt_motion.hpp"
#include "../src/generic_layout.hpp"
#include "../utils/position.hpp"
#include "../commands/async_queue.hpp"
#include "../commands/cmd_resize.hpp"
CtrlResize::CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl,
GenericLayout &rLayout, const UString &rHelp ):
CtrlFlat( pIntf, rHelp ), m_fsm( pIntf ), m_rCtrl( rCtrl ),
m_rLayout( rLayout ), m_cmdResizeResize( this, &transResizeResize ),
m_cmdStillResize( this, &transStillResize ),
m_cmdResizeStill( this, &transResizeStill )
{
m_pEvt = NULL;
m_xPos = 0;
m_yPos = 0;
// States
m_fsm.addState( "resize" );
m_fsm.addState( "still" );
// Transitions
m_fsm.addTransition( "resize", "mouse:left:up:none", "still",
&m_cmdResizeStill );
m_fsm.addTransition( "still", "mouse:left:down:none", "resize",
&m_cmdStillResize );
m_fsm.addTransition( "resize", "motion", "resize", &m_cmdResizeResize );
m_fsm.setState( "still" );
}
bool CtrlResize::mouseOver( int x, int y ) const
{
return m_rCtrl.mouseOver( x, y );
}
void CtrlResize::draw( OSGraphics &rImage, int xDest, int yDest )
{
m_rCtrl.draw( rImage, xDest, yDest );
}
void CtrlResize::setLayout( GenericLayout *pLayout, const Position &rPosition )
{
CtrlGeneric::setLayout( pLayout, rPosition );
// Set the layout of the decorated control as well
m_rCtrl.setLayout( pLayout, rPosition );
}
const Position *CtrlResize::getPosition() const
{
return m_rCtrl.getPosition();
}
void CtrlResize::handleEvent( EvtGeneric &rEvent )
{
m_pEvt = &rEvent;
m_fsm.handleTransition( rEvent.getAsString() );
// Transmit the event to the decorated control
// XXX: Is it really a good idea?
m_rCtrl.handleEvent( rEvent );
}
void CtrlResize::transStillResize( SkinObject *pCtrl )
{
CtrlResize *pThis = (CtrlResize*)pCtrl;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
pThis->m_xPos = pEvtMouse->getXPos();
pThis->m_yPos = pEvtMouse->getYPos();
pThis->captureMouse();
pThis->m_width = pThis->m_rLayout.getWidth();
pThis->m_height = pThis->m_rLayout.getHeight();
}
void CtrlResize::transResizeResize( SkinObject *pCtrl )
{
CtrlResize *pThis = (CtrlResize*)pCtrl;
EvtMotion *pEvtMotion = (EvtMotion*)pThis->m_pEvt;
int newWidth = pEvtMotion->getXPos() - pThis->m_xPos + pThis->m_width;
int newHeight = pEvtMotion->getYPos() - pThis->m_yPos + pThis->m_height;
// Check boundaries
if( newWidth < pThis->m_rLayout.getMinWidth() )
{
newWidth = pThis->m_rLayout.getMinWidth();
}
if( newWidth > pThis->m_rLayout.getMaxWidth() )
{
newWidth = pThis->m_rLayout.getMaxWidth();
}
if( newHeight < pThis->m_rLayout.getMinHeight() )
{
newHeight = pThis->m_rLayout.getMinHeight();
}
if( newHeight > pThis->m_rLayout.getMaxHeight() )
{
newHeight = pThis->m_rLayout.getMaxHeight();
}
// Create a resize command
CmdGeneric *pCmd = new CmdResize( pThis->getIntf(), pThis->m_rLayout,
newWidth, newHeight );
// Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
pQueue->remove( "resize" );
pQueue->push( CmdGenericPtr( pCmd ) );
}
void CtrlResize::transResizeStill( SkinObject *pCtrl )
{
CtrlResize *pThis = (CtrlResize*)pCtrl;
pThis->releaseMouse();
}
/*****************************************************************************
* ctrl_resize.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_resize.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_RESIZE_HPP
#define CTRL_RESIZE_HPP
#include "ctrl_flat.hpp"
#include "../commands/cmd_generic.hpp"
#include "../utils/fsm.hpp"
class GenericLayout;
/// Control decorator for resizing windows
class CtrlResize: public CtrlFlat
{
public:
CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl,
GenericLayout &rLayout, const UString &rHelp );
virtual ~CtrlResize() {}
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the decorated control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Set the position and the associated layout of the decorated control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
/// Get the position of the decorated control in the layout, if any
virtual const Position *getPosition() const;
static void transResizeResize( SkinObject *pCtrl );
static void transStillResize( SkinObject *pCtrl );
static void transResizeStill( SkinObject *pCtrl );
private:
FSM m_fsm;
/// Decorated CtrlFlat
CtrlFlat &m_rCtrl;
/// The layout resized by this control
GenericLayout &m_rLayout;
/// The last received event
EvtGeneric *m_pEvt;
/// Position of the click that started the resizing
int m_xPos, m_yPos;
/// Callbacks
Callback m_cmdResizeResize;
Callback m_cmdStillResize;
Callback m_cmdResizeStill;
// Size of the layout, before resizing
int m_width, m_height;
};
#endif
This diff is collapsed.
/*****************************************************************************
* ctrl_slider.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_slider.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_SLIDER_HPP
#define CTRL_SLIDER_HPP
#include "ctrl_generic.hpp"
#include "../utils/bezier.hpp"
#include "../utils/fsm.hpp"
#include "../utils/observer.hpp"
class GenericBitmap;
class OSGraphics;
class VarPercent;
class VarBool;
/// Cursor of a slider
class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>,
public Observer<VarBool>
{
public:
/// Create a cursor with 3 images (which are NOT copied, be careful)
/// If pVisible is NULL, the control is always visible
CtrlSliderCursor( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
const GenericBitmap &rBmpOver,
const GenericBitmap &rBmpDown,
const Bezier &rCurve, VarPercent &rVariable,
VarBool *pVisible, const UString &rTooltip,
const UString &rHelp );
virtual ~CtrlSliderCursor();
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Get the text of the tooltip
virtual UString getTooltipText() const { return m_tooltip; }
private:
/// Finite state machine of the control
FSM m_fsm;
/// Variable associated to the cursor
VarPercent &m_rVariable;
/// Visibility variable
VarBool *m_pVisible;
/// Tooltip text
const UString m_tooltip;
/// Initial size of the control
int m_width, m_height;
/// Callback objects
Callback m_cmdOverDown;
Callback m_cmdDownOver;
Callback m_cmdOverUp;
Callback m_cmdUpOver;
Callback m_cmdMove;
Callback m_cmdScroll;
/// Position of the cursor
int m_xPosition, m_yPosition;
/// Last saved position of the cursor (stored as a percentage)
double m_lastPercentage;
/// Offset between the mouse pointer and the center of the cursor
int m_xOffset, m_yOffset;
/// The last received event
EvtGeneric *m_pEvt;
/// Images of the cursor in the differents states
OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
/// Current image
OSGraphics *m_pImg;
/// Bezier curve of the slider
const Bezier m_curve;
/// Callback functions
static void transOverDown( SkinObject *pCtrl );
static void transDownOver( SkinObject *pCtrl );
static void transOverUp( SkinObject *pCtrl );
static void transUpOver( SkinObject *pCtrl );
static void transMove( SkinObject *pCtrl );
static void transScroll( SkinObject *pCtrl );
/// Method called when the position variable is modified
virtual void onUpdate( Subject<VarPercent> &rVariable );
/// Method called when the visibility variable is modified
virtual void onUpdate( Subject<VarBool> &rVariable );
/// Methode to compute the resize factors
void getResizeFactors( double &rFactorX, double &rFactorY ) const;
};
/// Slider background
class CtrlSliderBg: public CtrlGeneric
{
public:
/// If pVisible is NULL, the control is always visible
CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor,
const Bezier &rCurve, VarPercent &rVariable,
int thickness, VarBool *pVisible, const UString &rHelp );
virtual ~CtrlSliderBg() {}
/// Tell whether the mouse is over the control
virtual bool mouseOver( int x, int y ) const;
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
private:
/// Cursor of the slider
CtrlSliderCursor &m_rCursor;
/// Variable associated to the slider
VarPercent &m_rVariable;
/// Thickness of the curve
int m_thickness;
/// Visibility variable
VarBool *m_pVisible;
/// Bezier curve of the slider
const Bezier m_curve;
/// Initial size of the control
int m_width, m_height;
/// Methode to compute the resize factors
void getResizeFactors( double &rFactorX, double &rFactorY ) const;
/// Method called when the visibility variable is modified
virtual void onUpdate( Subject<VarBool> &rVariable );
};
#endif
/*****************************************************************************
* ctrl_text.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_text.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "ctrl_text.hpp"
#include "../events/evt_generic.hpp"
#include "../events/evt_mouse.hpp"
#include "../src/generic_bitmap.hpp"
#include "../src/generic_font.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp"
#include "../src/os_timer.hpp"
#include "../utils/position.hpp"
#include "../utils/ustring.hpp"
#include "../utils/var_text.hpp"
#define MOVING_TEXT_STEP 3
#define MOVING_TEXT_DELAY 200
#define SEPARATOR_STRING " "
CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
const GenericFont &rFont, const UString &rHelp,
uint32_t color ):
CtrlGeneric( pIntf, rHelp ), m_fsm( pIntf ), m_rVariable( rVariable ),
m_cmdToManual( this, &transToManual ),
m_cmdManualMoving( this, &transManualMoving ),
m_cmdManualStill( this, &transManualStill ),
m_cmdMove( this, &transMove ),
m_pEvt( NULL ), m_rFont( rFont ), m_color( color ),
m_pImg( NULL ), m_pImgDouble( NULL ), m_pCurrImg( NULL ),
m_xPos( 0 ), m_xOffset( 0 )
{
m_pTimer = OSFactory::instance( getIntf() )->createOSTimer(
Callback( this, &updateText ) );
// States
m_fsm.addState( "still" );
m_fsm.addState( "moving" );
m_fsm.addState( "manual1" );
m_fsm.addState( "manual2" );
m_fsm.addState( "outStill" );
m_fsm.addState( "outMoving" );
// Transitions
m_fsm.addTransition( "still", "mouse:left:down", "manual1",
&m_cmdToManual );
m_fsm.addTransition( "manual1", "mouse:left:up", "moving",
&m_cmdManualMoving );
m_fsm.addTransition( "moving", "mouse:left:down", "manual2",
&m_cmdToManual );
m_fsm.addTransition( "manual2", "mouse:left:up", "still",
&m_cmdManualStill );
m_fsm.addTransition( "manual1", "motion", "manual1", &m_cmdMove );
m_fsm.addTransition( "manual2", "motion", "manual2", &m_cmdMove );
m_fsm.addTransition( "still", "leave", "outStill" );
m_fsm.addTransition( "outStill", "enter", "still" );
m_fsm.addTransition( "moving", "leave", "outMoving" );
m_fsm.addTransition( "outMoving", "enter", "moving" );
// Initial state
m_fsm.setState( "outStill" );
// Observe the variable
m_rVariable.addObserver( this );
// Set the text
displayText( m_rVariable.get() );
}
CtrlText::~CtrlText()
{
m_rVariable.delObserver( this );
if( m_pTimer )
{
delete m_pTimer;
}
if( m_pImg )
{
delete m_pImg;
}
if( m_pImgDouble )
{
delete m_pImgDouble;
}
}
void CtrlText::handleEvent( EvtGeneric &rEvent )
{
// Save the event to use it in callbacks
m_pEvt = &rEvent;
m_fsm.handleTransition( rEvent.getAsString() );
}
bool CtrlText::mouseOver( int x, int y ) const
{
if( m_pCurrImg )
{
// We have 3 different ways of deciding when to return true here:
// 1) the mouse is exactly over the text (so if you click between two
// letters, the text control doesn't catch the event)
// 2) the mouse is over the rectangle of the control
// 3) the mouse is over the rectangle of the visible text
// I don't know which one is the best...
#if 0
return( x >= 0 && x < getPosition()->getWidth()
&& m_pCurrImg->hit( x - m_xPos, y ) );
#endif
#if 1
return( x >= 0 && x < getPosition()->getWidth()
&& y >= 0 && y < getPosition()->getHeight() );
#endif
#if 0
return( x >= 0 && x < getPosition()->getWidth()
&& y >= 0 && y < getPosition()->getHeight()
&& x < m_pCurrImg->getWidth() && x < m_pCurrImg->getHeight() );
#endif
}
else
{
return false;
}
}
void CtrlText::draw( OSGraphics &rImage, int xDest, int yDest )
{
if( m_pCurrImg )
{
// Compute the dimensions to draw
int width = min( m_pCurrImg->getWidth() + m_xPos,
getPosition()->getWidth() );
int height = min( m_pCurrImg->getHeight(), getPosition()->getHeight() );
// Draw the current image
rImage.drawBitmap( *m_pCurrImg, -m_xPos, 0, xDest, yDest,
width, height );
}
}
void CtrlText::setText( const UString &rText, uint32_t color )
{
// Change the color
if( color != 0xFFFFFFFF )
{
m_color = color;
}
// Change the text
m_rVariable.set( rText );
}
void CtrlText::onUpdate( Subject<VarText> &rVariable )
{
displayText( m_rVariable.get() );
}
void CtrlText::displayText( const UString &rText )
{
m_pTimer->stop();
// Create the images ('normal' and 'double') from the text
// 'Normal' image
if( m_pImg )
{
delete m_pImg;
}
m_pImg = m_rFont.drawString( rText, m_color );
// 'Double' image
const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText;
if( m_pImgDouble )
{
delete m_pImgDouble;
}
m_pImgDouble = m_rFont.drawString( doubleStringWithSep, m_color );
// Update the current image used, as if the control size had changed
onChangePosition();
// XXX: will this always work?
m_fsm.setState( "outStill" );
notifyLayout();
}
void CtrlText::onChangePosition()
{
if( getPosition() )
{
if( m_pImg->getWidth() < getPosition()->getWidth() )
{
m_pCurrImg = m_pImg;
}
else
{
m_pCurrImg = m_pImgDouble;
}
}
else
{
// m_pImg is a better default value than m_pImgDouble, but anyway we
// don't care because the control is never drawn without position :)
m_pCurrImg = m_pImg;
}
}
void CtrlText::transToManual( SkinObject *pCtrl )
{
CtrlText *pThis = (CtrlText*)pCtrl;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Compute the offset
pThis->m_xOffset = pEvtMouse->getXPos() - pThis->m_xPos;
pThis->m_pTimer->stop();
pThis->captureMouse();
}
void CtrlText::transManualMoving( SkinObject *pCtrl )
{
CtrlText *pThis = (CtrlText*)pCtrl;
pThis->releaseMouse();
// Start the automatic movement, but only if the text is wider than the
// control
if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
{
// The current image may have been set incorrectly in displayText(), so
// set the correct value
pThis->m_pCurrImg = pThis->m_pImgDouble;
pThis->m_pTimer->start( MOVING_TEXT_DELAY, false );
}
}
void CtrlText::transManualStill( SkinObject *pCtrl )
{
CtrlText *pThis = (CtrlText*)pCtrl;
pThis->releaseMouse();
}
void CtrlText::transMove( SkinObject *pCtrl )
{
CtrlText *pThis = (CtrlText*)pCtrl;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Do nothing if the text fits in the control
if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
{
// The current image may have been set incorrectly in displayText(), so
// we set the correct value
pThis->m_pCurrImg = pThis->m_pImgDouble;
// Compute the new position of the left side, and make sure it is
// in the correct range
pThis->m_xPos = (pEvtMouse->getXPos() - pThis->m_xOffset);
pThis->adjust( pThis->m_xPos );
pThis->notifyLayout();
}
}
void CtrlText::updateText( SkinObject *pCtrl )
{
CtrlText *pThis = (CtrlText*)pCtrl;
pThis->m_xPos -= MOVING_TEXT_STEP;
pThis->adjust( pThis->m_xPos );
pThis->notifyLayout();
}
void CtrlText::adjust( int &position )
{
// {m_pImgDouble->getWidth() - m_pImg->getWidth()} is the period of the
// bitmap; remember that the string used to generate m_pImgDouble is of the
// form: "foo foo", the number of spaces being a parameter
position %= m_pImgDouble->getWidth() - m_pImg->getWidth();
if( position > 0 )
{
position -= m_pImgDouble->getWidth() - m_pImg->getWidth();
}
}
/*****************************************************************************
* ctrl_text.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_text.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef CTRL_TEXT_HPP
#define CTRL_TEXT_HPP
#include "ctrl_generic.hpp"
#include "../utils/fsm.hpp"
#include "../utils/observer.hpp"
#include <string>
class GenericFont;
class GenericBitmap;
class OSTimer;
class UString;
class VarText;
/// Class for control text
class CtrlText: public CtrlGeneric, public Observer<VarText>
{
public:
/// Create a text control with the optional given color
CtrlText( intf_thread_t *pIntf, VarText &rVariable,
const GenericFont &rFont, const UString &rHelp,
uint32_t color = 0 );
virtual ~CtrlText();
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
/// Check whether coordinates are inside the control
virtual bool mouseOver( int x, int y ) const;
/// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Set the text of the control, with an optional color
/// This takes effect immediatly
void setText( const UString &rText, uint32_t color = 0xFFFFFFFF );
private:
/// Finite state machine of the control
FSM m_fsm;
/// Variable associated to the control
VarText &m_rVariable;
/// Callback objects
Callback m_cmdToManual;
Callback m_cmdManualMoving;
Callback m_cmdManualStill;
Callback m_cmdMove;
/// The last received event
EvtGeneric *m_pEvt;
/// Font used to render the text
const GenericFont &m_rFont;
/// Color of the text
uint32_t m_color;
/// Image of the text
GenericBitmap *m_pImg;
/// Image of the text, repeated twice and with some blank between;
/// useful to display a 'circular' moving text...
GenericBitmap *m_pImgDouble;
/// Current image (should always be equal to m_pImg or m_pImgDouble)
GenericBitmap *m_pCurrImg;
/// Position of the left side of the moving text
int m_xPos;
/// Offset between the mouse pointer and the left side of the
/// moving text
int m_xOffset;
/// Timer to move the text
OSTimer *m_pTimer;
/// Callback functions
static void transToManual( SkinObject *pCtrl );
static void transManualMoving( SkinObject *pCtrl );
static void transManualStill( SkinObject *pCtrl );
static void transMove( SkinObject *pCtrl );
/// Callback for the timer
static void updateText( SkinObject *pCtrl );
/// Method called when the observed variable is modified
virtual void onUpdate( Subject<VarText> &rVariable );
/// Display the text on the control
void displayText( const UString &rText );
/// Helper function to set the position in the correct interval
void adjust( int &position );
/// Update the behaviour of the text whenever the control size changes
virtual void onChangePosition();
};
#endif
/*****************************************************************************
* evt_enter.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: evt_enter.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef EVT_ENTER_HPP
#define EVT_ENTER_HPP
#include "evt_input.hpp"
/// Mouse enter event
class EvtEnter: public EvtInput
{
public:
EvtEnter( intf_thread_t *pIntf ): EvtInput( pIntf ) {}
virtual ~EvtEnter() {}
/// Return the type of event
virtual const string getAsString() const { return "enter"; }
};
#endif
/*****************************************************************************
* evt_focus.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: evt_focus.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef EVT_FOCUS_HPP
#define EVT_FOCUS_HPP
#include "evt_generic.hpp"
/// Focus change event
class EvtFocus: public EvtGeneric
{
public:
EvtFocus( intf_thread_t *pIntf, bool focus ): EvtGeneric( pIntf ),
m_focus( focus ) {}
virtual ~EvtFocus() {}
/// Return the type of event
virtual const string getAsString() const
{
return ( m_focus ? "focus:in" : "focus:out" );
}
private:
/// true for a focus in, and false for a focus out
bool m_focus;
};
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
* evt_leave.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: evt_leave.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef EVT_LEAVE_HPP
#define EVT_LEAVE_HPP
#include "evt_input.hpp"
/// Mouse leave event
class EvtLeave: public EvtInput
{
public:
EvtLeave( intf_thread_t *pIntf ): EvtInput( pIntf ) {}
virtual ~EvtLeave() {}
/// Return the type of event
virtual const string getAsString() const { return "leave"; }
};
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment