~ubuntu-branches/ubuntu/karmic/pygame/karmic

« back to all changes in this revision

Viewing changes to src/event.c

  • Committer: Bazaar Package Importer
  • Author(s): Joe Wreschnig
  • Date: 2005-09-15 15:10:45 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050915151045-6j7tiaorbf42xqia
Tags: 1.7.1release-1
* New upstream release.
* Remove 64-bit patch from 1.6-0.2, merged upstream.
* Remove SMPEG detection patch from 1.4-1, no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#define PYGAMEAPI_EVENT_INTERNAL
27
27
#include "pygame.h"
28
28
 
 
29
// FIXME: The system message code is only tested on windows, so only
 
30
//          include it there for now.
 
31
#ifdef WIN32
 
32
#include <SDL_syswm.h>
 
33
#endif
 
34
 
29
35
 
30
36
/*this user event object is for safely passing
31
37
 *objects through the event queue.
104
110
        }
105
111
}
106
112
 
 
113
static int PyEvent_FillUserEvent(PyEventObject *e, SDL_Event *event) {
 
114
        UserEventObject *userobj = user_event_addobject(e->dict);
 
115
        if(!userobj)
 
116
                return -1;
107
117
 
 
118
        event->type = e->type;
 
119
        event->user.code = USEROBJECT_CHECK1;
 
120
        event->user.data1 = (void*)USEROBJECT_CHECK2;
 
121
        event->user.data2 = userobj;
 
122
    return 0;
 
123
}
108
124
 
109
125
staticforward PyTypeObject PyEvent_Type;
110
126
static PyObject* PyEvent_New(SDL_Event*);
283
299
        case SDL_VIDEORESIZE:
284
300
                obj = Py_BuildValue("(ii)", event->resize.w, event->resize.h);
285
301
                insobj(dict, "size", obj);
 
302
                insobj(dict, "w", PyInt_FromLong(event->resize.w));
 
303
                insobj(dict, "h", PyInt_FromLong(event->resize.h));
 
304
                break;
 
305
        case SDL_SYSWMEVENT:
 
306
                #ifdef WIN32
 
307
                insobj(dict, "hwnd", PyInt_FromLong((long)(event-> syswm.msg->hwnd)));
 
308
                insobj(dict, "msg", PyInt_FromLong(event-> syswm.msg->msg));
 
309
                insobj(dict, "wparam", PyInt_FromLong(event-> syswm.msg->wParam));
 
310
                insobj(dict, "lparam", PyInt_FromLong(event-> syswm.msg->lParam));
 
311
                #endif
286
312
                break;
287
313
/* SDL_VIDEOEXPOSE and SDL_QUIT have no attributes */
288
314
        }
609
635
    /*DOC*/    "queue for too long, the system may decide your program has locked up.\n"
610
636
    /*DOC*/ ;
611
637
 
612
 
static PyObject* pump(PyObject* self, PyObject* args)
 
638
static PyObject* pygame_pump(PyObject* self, PyObject* args)
613
639
{
614
640
        if(!PyArg_ParseTuple(args, ""))
615
641
                return NULL;
664
690
    /*DOC*/    "queue, this will return an event with type NOEVENT.\n"
665
691
    /*DOC*/ ;
666
692
 
667
 
static PyObject* poll(PyObject* self, PyObject* args)
 
693
static PyObject* pygame_poll(PyObject* self, PyObject* args)
668
694
{
669
695
        SDL_Event event;
670
696
 
879
905
{
880
906
        PyEventObject* e;
881
907
        SDL_Event event;
882
 
        UserEventObject* userobj;
883
908
 
884
909
        if(!PyArg_ParseTuple(args, "O!", &PyEvent_Type, &e))
885
910
                return NULL;
886
911
 
887
912
        VIDEO_INIT_CHECK();
888
913
 
889
 
        userobj = user_event_addobject(e->dict);
890
 
        if(!userobj)
 
914
    if (PyEvent_FillUserEvent(e, &event))
891
915
                return NULL;
892
916
 
893
 
        event.type = e->type;
894
 
        event.user.code = USEROBJECT_CHECK1;
895
 
        event.user.data1 = (void*)USEROBJECT_CHECK2;
896
 
        event.user.data2 = userobj;
897
 
 
898
917
        if(SDL_PushEvent(&event) == -1)
899
918
                return RAISE(PyExc_SDLError, "Event queue full");
900
919
 
1040
1059
        { "set_grab", set_grab, 1, doc_set_grab },
1041
1060
        { "get_grab", get_grab, 1, doc_get_grab },
1042
1061
 
1043
 
        { "pump", pump, 1, doc_pump },
 
1062
        { "pump", pygame_pump, 1, doc_pump },
1044
1063
        { "wait", pygame_wait, 1, doc_wait },
1045
 
        { "poll", poll, 1, doc_poll },
 
1064
        { "poll", pygame_poll, 1, doc_poll },
1046
1065
        { "clear", event_clear, 1, doc_event_clear },
1047
1066
        { "get", event_get, 1, doc_event_get },
1048
1067
        { "peek", event_peek, 1, doc_peek },
1064
1083
    /*DOC*/    "the display has not been initialized and a video mode not set,\n"
1065
1084
    /*DOC*/    "the event queue will not really work.\n"
1066
1085
    /*DOC*/    "\n"
1067
 
    /*DOC*/    "The queue is a stack of Event objects, there are a variety of\n"
1068
 
    /*DOC*/    "ways to access the data on the queue. From simply checking for\n"
 
1086
    /*DOC*/    "The queue is a regular queue of Event objects, there are a variety of\n"
 
1087
    /*DOC*/    "ways to access the events it contains. From simply checking for\n"
1069
1088
    /*DOC*/    "the existance of events, to grabbing them directly off the stack.\n"
1070
1089
    /*DOC*/    "\n"
1071
1090
    /*DOC*/    "All events have a type identifier. This event type is in between\n"
1111
1130
        /* export the c api */
1112
1131
        c_api[0] = &PyEvent_Type;
1113
1132
        c_api[1] = PyEvent_New;
 
1133
        c_api[2] = PyEvent_New2;
 
1134
        c_api[3] = PyEvent_FillUserEvent;
1114
1135
        apiobj = PyCObject_FromVoidPtr(c_api, NULL);
1115
1136
        PyDict_SetItemString(dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
1116
1137
        Py_DECREF(apiobj);