00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (C) 2010 Dan Leinir Turthra Jensen <admin@leinir.dk> 00004 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 00022 #include "touchinputcomponent.h" 00023 #include "input/inputmanager.h" 00024 00025 #include <core/debughelper.h> 00026 00027 #include <QtCore/QEvent> 00028 #include <QtCore/QDebug> 00029 00030 REGISTER_OBJECTTYPE( GluonEngine, TouchInputComponent ); 00031 00032 using namespace GluonEngine; 00033 00034 TouchInputComponent::TouchInputComponent( QObject* parent ) 00035 : Component( parent ) 00036 , m_actionHeld( false ) 00037 , m_actionStarted( false ) 00038 , m_actionStopped( false ) 00039 , m_touch( 0 ) 00040 { 00041 } 00042 00043 QString TouchInputComponent::category() const 00044 { 00045 return QString( "Input" ); 00046 } 00047 00048 void TouchInputComponent::initialize() 00049 { 00050 if( !m_touch ) 00051 m_touch = GluonInput::InputManager::instance()->touch(); 00052 } 00053 00054 void TouchInputComponent::start() 00055 { 00056 if( m_touch ) 00057 { 00058 m_touch->setEnabled( true ); 00059 } 00060 else 00061 { 00062 debug( "WARNING! No touch found!" ); 00063 } 00064 } 00065 00066 void TouchInputComponent::update( int elapsedMilliseconds ) 00067 { 00068 DEBUG_BLOCK 00069 if( m_actionStarted ) 00070 m_actionStarted = false; 00071 00072 if( m_actionStopped ) 00073 m_actionStopped = false; 00074 00075 if( m_touch && m_touch->buttonPressed( m_touchCode ) ) 00076 { 00077 if( !m_actionHeld ) 00078 { 00079 m_actionStarted = true; 00080 m_actionHeld = true; 00081 } 00082 } 00083 else 00084 { 00085 if( m_actionHeld ) 00086 { 00087 m_actionStopped = true; 00088 m_actionHeld = false; 00089 } 00090 } 00091 } 00092 00093 void TouchInputComponent::stop() 00094 { 00095 if( m_touch ) 00096 { 00097 m_touch->setEnabled( false ); 00098 } 00099 00100 m_actionStopped = false; 00101 m_actionStarted = false; 00102 m_actionHeld = false; 00103 } 00104 00105 bool TouchInputComponent::isActionStarted() 00106 { 00107 return m_actionStarted; 00108 } 00109 00110 bool TouchInputComponent::isActionHeld() 00111 { 00112 return m_actionHeld; 00113 } 00114 00115 bool TouchInputComponent::isActionStopped() 00116 { 00117 return m_actionStopped; 00118 } 00119 00120 TouchInputComponent::TouchName 00121 TouchInputComponent::touchCode() const 00122 { 00123 return m_touchCode; 00124 } 00125 00126 void TouchInputComponent::setTouchCode( TouchInputComponent::TouchName newTouchCode ) 00127 { 00128 m_touchCode = newTouchCode; 00129 } 00130 00131 Q_EXPORT_PLUGIN2( gluon_component_touchinput, GluonEngine::TouchInputComponent ); 00132 00133 #include "touchinputcomponent.moc"