~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#ifndef DISABLE_SDL
36
36
void SCA_Joystick::OnAxisMotion(SDL_Event* sdl_event)
37
37
{
38
 
        pFillAxes();
39
 
        m_axisnum       = sdl_event->jaxis.axis;
40
 
        m_axisvalue = sdl_event->jaxis.value;
 
38
        if(sdl_event->jaxis.axis >= JOYAXIS_MAX)
 
39
                return;
 
40
        
 
41
        m_axis_array[sdl_event->jaxis.axis]= sdl_event->jaxis.value;
41
42
        m_istrig_axis = 1;
42
43
}
43
44
 
44
 
 
 
45
/* See notes below in the event loop */
45
46
void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
46
47
{
47
 
        m_hatdir = sdl_event->jhat.value;
48
 
        m_hatnum = sdl_event->jhat.hat;
 
48
        if(sdl_event->jhat.hat >= JOYHAT_MAX)
 
49
                return;
 
50
 
 
51
        m_hat_array[sdl_event->jhat.hat]= sdl_event->jhat.value;
49
52
        m_istrig_hat = 1;
50
53
}
51
54
 
 
55
/* See notes below in the event loop */
52
56
void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
53
57
{
54
58
        m_istrig_button = 1;
55
 
        
56
 
        /* this is needed for the "all events" option
57
 
         * so we know if there are no buttons pressed */
58
 
        int i;
59
 
        for (i=0; i<m_buttonmax; i++) {
60
 
                if (SDL_JoystickGetButton(m_private->m_joystick, i)) {
61
 
                        m_buttonnum = i;
62
 
                        return;
63
 
                }
64
 
        }
65
 
        m_buttonnum = -2;
66
59
}
67
60
 
68
61
 
69
62
void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
70
63
{
71
 
        if(sdl_event->jbutton.button >= 0 || sdl_event->jbutton.button <= m_buttonmax)
72
 
        {
73
 
                m_istrig_button = 1;
74
 
                m_buttonnum = sdl_event->jbutton.button;
75
 
        }
 
64
        //if(sdl_event->jbutton.button > m_buttonmax) /* unsigned int so always above 0 */
 
65
        //      return;
 
66
        // sdl_event->jbutton.button;
 
67
        
 
68
        m_istrig_button = 1;
76
69
}
77
70
 
78
71
 
81
74
        m_istrig_axis = m_istrig_button = m_istrig_hat = 0;
82
75
}
83
76
 
84
 
/* only handle events for 1 joystick */
85
 
 
86
77
void SCA_Joystick::HandleEvents(void)
87
78
{
88
79
        SDL_Event               sdl_event;
89
80
        
90
81
        int i;
91
 
        for (i=0; i<JOYINDEX_MAX; i++) {
 
82
        for (i=0; i<m_joynum; i++) { /* could use JOYINDEX_MAX but no reason to */
92
83
                if(SCA_Joystick::m_instance[i])
93
84
                        SCA_Joystick::m_instance[i]->OnNothing(&sdl_event);
94
85
        }
95
86
        
96
 
        if(SDL_PollEvent(&sdl_event))
 
87
        while(SDL_PollEvent(&sdl_event))
97
88
        {
98
89
                /* Note! m_instance[sdl_event.jaxis.which]
99
90
                 * will segfault if over JOYINDEX_MAX, not too nice but what are the chances? */
 
91
                
 
92
                /* Note!, with buttons, this wont care which button is pressed,
 
93
                 * only to set 'm_istrig_button', actual pressed buttons are detected by SDL_JoystickGetButton */
 
94
                
 
95
                /* Note!, if you manage to press and release a button within 1 logic tick
 
96
                 * it wont work as it should */
 
97
                
100
98
                switch(sdl_event.type)
101
99
                {
102
100
                case SDL_JOYAXISMOTION:
111
109
                case SDL_JOYBUTTONDOWN:
112
110
                        SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event);
113
111
                        break;
 
112
#if 0   /* Not used yet */
114
113
                case SDL_JOYBALLMOTION:
115
114
                        SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event);
116
115
                        break;
 
116
#endif
117
117
                default:
118
118
                        printf("SCA_Joystick::HandleEvents, Unknown SDL event, this should not happen\n");
119
119
                        break;