Ticket #1634: mythgesture.patch

File mythgesture.patch, 3.9 KB (added by florinbaiduc, 14 years ago)

Patch for adding new gestures

  • mythgesture.cpp

    old new  
    3636#include <qmap.h>
    3737
    3838#include "mythgesture.h"
     39#include "iostream.h"
     40
    3941
    4042using namespace std;
    4143
     
    6163    scale_ratio(scale_ratio), bin_percent(bin_percent)
    6264{
    6365    /* default to an invalid event */
    64     last_gesture = MythGestureEvent::MaxGesture;
     66    last_gesture = MythGestureEvent::WrongGesture;
    6567
    6668    /* create new private information */
    6769    p = new MythGesturePrivate();
     
    9092    p->sequences.insert("98741",MythGestureEvent::LeftThenUp);
    9193    p->sequences.insert("12369",MythGestureEvent::RightThenDown);
    9294    p->sequences.insert("78963",MythGestureEvent::RightThenUp);
     95       
     96        /*ClockWise rotation*/
     97        p->sequences.insert("123698741",MythGestureEvent::ClockWise);
     98        p->sequences.insert("236987412",MythGestureEvent::ClockWise);
     99        p->sequences.insert("369874123",MythGestureEvent::ClockWise);
     100        p->sequences.insert("698741236",MythGestureEvent::ClockWise);
     101        p->sequences.insert("987412369",MythGestureEvent::ClockWise);
     102        p->sequences.insert("874123698",MythGestureEvent::ClockWise);
     103        p->sequences.insert("741236987",MythGestureEvent::ClockWise);
     104        p->sequences.insert("412369874",MythGestureEvent::ClockWise);
     105        p->sequences.insert("123698741",MythGestureEvent::ClockWise);
     106       
     107        /*CounterClockWise rotation*/
     108       
     109        p->sequences.insert("147896321",MythGestureEvent::CounterClockWise);
     110        p->sequences.insert("214789632",MythGestureEvent::CounterClockWise);
     111        p->sequences.insert("321478963",MythGestureEvent::CounterClockWise);
     112        p->sequences.insert("632147896",MythGestureEvent::CounterClockWise);
     113        p->sequences.insert("963214789",MythGestureEvent::CounterClockWise);
     114        p->sequences.insert("896321478",MythGestureEvent::CounterClockWise);
     115        p->sequences.insert("789632147",MythGestureEvent::CounterClockWise);
     116        p->sequences.insert("478963214",MythGestureEvent::CounterClockWise);
     117        p->sequences.insert("147896321",MythGestureEvent::CounterClockWise);
     118       
     119       
     120               
     121        //steps
     122        p->sequences.insert("78523",MythGestureEvent::StepUp);
     123        p->sequences.insert("12589",MythGestureEvent::StepDown);
     124       
     125        //double steps
     126        p->sequences.insert("74563",MythGestureEvent::DoubleStepUp);
     127        p->sequences.insert("14569",MythGestureEvent::DoubleStepDown);
     128       
     129       
     130       
     131       
     132       
     133        p->sequences.insert("1235789",MythGestureEvent::Z);
     134       
     135       
     136       
     137       
     138       
     139       
    93140}
    94141
    95142/* comments in header */
    96143void MythGesture::adjustExtremes(int x, int y)
    97144{
    98     min_x = min(min_x, x);
    99     max_x = max(max_y, x);
    100     min_y = min(min_y, y);
    101     max_y = max(max_y, y);
     145   if (((int) x) < min_x) min_x = (int) x;
     146   if (((int) x) > max_x) max_x = (int) x;
     147   if (((int) y) < min_y) min_y = (int) y;
     148   if (((int) y) > max_y) max_y = (int) y;
    102149}
    103150
    104151bool MythGesture::recording(void) const
     
    122169{
    123170    p->m.lock();
    124171
     172    QString trans;
    125173    if (m_recording)
    126174    {
    127175        m_recording = false;
    128176
    129177        /* translate before resetting maximums */
    130         last_gesture = p->sequences[translate()];
     178        trans=translate();
     179        cout <<trans<<"\n";
     180        if(p->sequences.find(trans)!=p->sequences.end())
     181                last_gesture = p->sequences[trans];
     182        else
     183                last_gesture = MythGestureEvent::WrongGesture;
     184       
    131185
    132186        min_x = min_y = 10000;
    133187        max_x = max_y = -1;
     
    252306    }
    253307
    254308    /* add the last run of points to the sequence */
    255     sequence += '0' + current_bin;
    256     sequence_count++;
     309    if(sequence_count<=9){
     310                sequence += '0' + current_bin;
     311        sequence_count++;
     312    }
    257313   
    258314    /* bail out on error cases */
    259315    if (sequence_count > max_sequence)
     
    343399    "LeftThenDown",
    344400    "RightThenUp",
    345401    "RightThenDown",
     402    "ClockWise",
     403    "CounterClockWise",
     404    "StepUp",
     405    "StepDown",
     406    "DoubleStepUp",
     407    "DoubleStepDown",
     408    "Z",
    346409    "Click",
    347     "MaxGesture"
     410    "WrongGesture"
    348411};
    349412
    350413/* comments in header */