<commit_before>/*****************************************************************************
 * ctrl_text.cpp
 *****************************************************************************
 * Copyright (C) 2003 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME>     <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 1
#define MOVING_TEXT_DELAY 30
#define SEPARATOR_STRING "   "


CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
                    const GenericFont &rFont, const UString &rHelp,
                    uint32_t color, VarBool *pVisible, VarBool *pFocus,
                    Scrolling_t scrollMode, Align_t alignment ):
    CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
    m_rVariable( rVariable ), m_cmdToManual( this ),
    m_cmdManualMoving( this ), m_cmdManualStill( this ),
    m_cmdMove( this ), m_pEvt( NULL ), m_rFont( rFont ),
    m_color( color ), m_scrollMode( scrollMode ), m_alignment( alignment ),
    m_pFocus( pFocus), m_pImg( NULL ), m_pImgDouble( NULL ),
    m_pCurrImg( NULL ), m_xPos( 0 ), m_xOffset( 0 ),
    m_cmdUpdateText( this )
{
    m_pTimer = OSFactory::instance( pIntf )->createOSTimer( m_cmdUpdateText );

    // 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", "leave", "outStill" );
    m_fsm.addTransition( "outStill", "enter", "still" );
    if( m_scrollMode == kManual )
    {
        m_fsm.addTransition( "still", "mouse:left:down", "manual1",
                             &m_cmdToManual );
        m_fsm.addTransition( "manual1", "mouse:left:up", "still",
                             &m_cmdManualStill );
        m_fsm.addTransition( "manual1", "motion", "manual1", &m_cmdMove );
    }
    else if( m_scrollMode == kAutomatic )
    {
        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( "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 );
    delete m_pTimer;
    delete m_pImg;
    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<commit_msg>skins2: fix initial text state to reflect documentation<commit_after>/*****************************************************************************
 * ctrl_text.cpp
 *****************************************************************************
 * Copyright (C) 2003 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME>     <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 1
#define MOVING_TEXT_DELAY 30
#define SEPARATOR_STRING "   "


CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
                    const GenericFont &rFont, const UString &rHelp,
                    uint32_t color, VarBool *pVisible, VarBool *pFocus,
                    Scrolling_t scrollMode, Align_t alignment ):
    CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
    m_rVariable( rVariable ), m_cmdToManual( this ),
    m_cmdManualMoving( this ), m_cmdManualStill( this ),
    m_cmdMove( this ), m_pEvt( NULL ), m_rFont( rFont ),
    m_color( color ), m_scrollMode( scrollMode ), m_alignment( alignment ),
    m_pFocus( pFocus), m_pImg( NULL ), m_pImgDouble( NULL ),
    m_pCurrImg( NULL ), m_xPos( 0 ), m_xOffset( 0 ),
    m_cmdUpdateText( this )
{
    m_pTimer = OSFactory::instance( pIntf )->createOSTimer( m_cmdUpdateText );

    // 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", "leave", "outStill" );
    m_fsm.addTransition( "outStill", "enter", "still" );
    if( m_scrollMode == kManual )
    {
        m_fsm.addTransition( "still", "mouse:left:down", "manual1",
                             &m_cmdToManual );
        m_fsm.addTransition( "manual1", "mouse:left:up", "still",
                             &m_cmdManualStill );
        m_fsm.addTransition( "manual1", "motion", "manual1", &m_cmdMove );
    }
    else if( m_scrollMode == kAutomatic )
    {
        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( "moving", "leave", "outMoving" );
        m_fsm.addTransition( "outMoving", "enter", "moving" );
    }

    // Initial state
    m_fsm.setState( (m_scrollMode != kAutomatic) ? "outStill" : "outMoving" );

    // Observe the variable
    m_rVariable.addObserver( this );

    // Set the text
    displayText( m_rVariable.get() );
}


CtrlText::~CtrlText()
{
    m_rVariable.delObserver( this );
    delete m_pTimer;
    delete m_pImg;
    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
{'fraction_non_alphanumeric': 0.1747605633802817, 'fraction_numerical': 0.008450704225352112, 'mean_word_length': 3.1207056638811514, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6070243', 'n_tokens_mistral': 2942, 'n_tokens_neox': 2767, 'n_words': 711}