event.c
来自「适合KS8695X」· C语言 代码 · 共 1,116 行 · 第 1/3 页
C
1,116 行
else if (EVT.count < EVENTQSIZE) {
/* Add a new joystick movement event */
EVT.oldJoyMove = EVT.freeHead;
memset(&evt,0,sizeof(evt));
evt.what = EVT_JOYMOVE;
evt.message = EVT.joyButState;
evt.where_x = EVT.joyPrev[0];
evt.where_y = EVT.joyPrev[1];
evt.relative_x = EVT.joyPrev[2];
evt.relative_y = EVT.joyPrev[3];
addEvent(&evt);
}
_EVT_restoreInt(ps);
}
/* Read the joystick buttons, and post events to reflect the change
* in state for the joystick buttons.
*/
if (newButState != EVT.joyButState) {
if (EVT.count < EVENTQSIZE) {
/* Add a new joystick click event */
ps = _EVT_disableInt();
memset(&evt,0,sizeof(evt));
evt.what = EVT_JOYCLICK;
evt.message = newButState;
EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0];
EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1];
EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2];
EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3];
addEvent(&evt);
_EVT_restoreInt(ps);
}
EVT.joyButState = newButState;
}
}
}
/****************************************************************************
DESCRIPTION:
Calibrates the joystick upper left position
HEADER:
event.h
REMARKS:
This function can be used to zero in on better joystick calibration factors,
which may work better than the default simplistic calibration (which assumes
the joystick is centered when the event library is initialised).
To use this function, ask the user to hold the stick in the upper left
position and then have them press a key or button. and then call this
function. This function will then read the joystick and update the
calibration factors.
Usually, assuming that the stick was centered when the event library was
initialized, you really only need to call EVT_joySetLowerRight since the
upper left position is usually always 0,0 on most joysticks. However, the
safest procedure is to call all three calibration functions.
SEE ALSO:
EVT_joySetUpperLeft, EVT_joySetLowerRight, EVT_joyIsPresent
****************************************************************************/
void EVTAPI EVT_joySetUpperLeft(void)
{
_EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyMin);
}
/****************************************************************************
DESCRIPTION:
Calibrates the joystick lower right position
HEADER:
event.h
REMARKS:
This function can be used to zero in on better joystick calibration factors,
which may work better than the default simplistic calibration (which assumes
the joystick is centered when the event library is initialised).
To use this function, ask the user to hold the stick in the lower right
position and then have them press a key or button. and then call this
function. This function will then read the joystick and update the
calibration factors.
Usually, assuming that the stick was centered when the event library was
initialized, you really only need to call EVT_joySetLowerRight since the
upper left position is usually always 0,0 on most joysticks. However, the
safest procedure is to call all three calibration functions.
SEE ALSO:
EVT_joySetUpperLeft, EVT_joySetCenter, EVT_joyIsPresent
****************************************************************************/
void EVTAPI EVT_joySetLowerRight(void)
{
_EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyMax);
}
/****************************************************************************
DESCRIPTION:
Calibrates the joystick center position
HEADER:
event.h
REMARKS:
This function can be used to zero in on better joystick calibration factors,
which may work better than the default simplistic calibration (which assumes
the joystick is centered when the event library is initialised).
To use this function, ask the user to hold the stick in the center
position and then have them press a key or button. and then call this
function. This function will then read the joystick and update the
calibration factors.
Usually, assuming that the stick was centered when the event library was
initialized, you really only need to call EVT_joySetLowerRight since the
upper left position is usually always 0,0 on most joysticks. However, the
safest procedure is to call all three calibration functions.
SEE ALSO:
EVT_joySetUpperLeft, EVT_joySetLowerRight, EVT_joySetCenter
****************************************************************************/
void EVTAPI EVT_joySetCenter(void)
{
_EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyCenter);
}
#endif
/****************************************************************************
DESCRIPTION:
Posts a user defined event to the event queue
HEADER:
event.h
RETURNS:
True if event was posted, false if event queue is full.
PARAMETERS:
what - Type code for message to post
message - Event specific message to post
modifiers - Event specific modifier flags to post
REMARKS:
This routine is used to post user defined events to the event queue.
SEE ALSO:
EVT_flush, EVT_getNext, EVT_peekNext, EVT_halt
****************************************************************************/
ibool EVTAPI EVT_post(
ulong which,
ulong what,
ulong message,
ulong modifiers)
{
event_t evt;
uint ps;
if (EVT.count < EVENTQSIZE) {
/* Save information in event record */
ps = _EVT_disableInt();
evt.which = which;
evt.when = _EVT_getTicks();
evt.what = what;
evt.message = message;
evt.modifiers = modifiers;
addEvent(&evt); /* Add to EVT.tail of event queue */
_EVT_restoreInt(ps);
return true;
}
else
return false;
}
/****************************************************************************
DESCRIPTION:
Flushes all events of a specified type from the event queue.
PARAMETERS:
mask - Mask specifying the types of events that should be removed
HEADER:
event.h
REMARKS:
Flushes (removes) all pending events of the specified type from the event
queue. You may combine the masks for different event types with a simple
logical OR.
SEE ALSO:
EVT_getNext, EVT_halt, EVT_peekNext
****************************************************************************/
void EVTAPI EVT_flush(
ulong mask)
{
event_t evt;
do { /* Flush all events */
EVT_getNext(&evt,mask);
} while (evt.what != EVT_NULLEVT);
}
/****************************************************************************
DESCRIPTION:
Halts until and event of the specified type is recieved.
HEADER:
event.h
PARAMETERS:
evt - Pointer to
mask - Mask specifying the types of events that should be removed
REMARKS:
This functions halts exceution until an event of the specified type is
recieved into the event queue. It does not flush the event queue of events
before performing the busy loop. However this function does throw away
any events other than the ones you have requested via the event mask, to
avoid the event queue filling up with unwanted events (like EVT_KEYUP or
EVT_MOUSEMOVE events).
SEE ALSO:
EVT_getNext, EVT_flush, EVT_peekNext
****************************************************************************/
void EVTAPI EVT_halt(
event_t *evt,
ulong mask)
{
do { /* Wait for an event */
if (mask & (EVT_JOYEVT))
EVT_pollJoystick();
EVT_getNext(evt,EVT_EVERYEVT);
} while (!(evt->what & mask));
}
/****************************************************************************
DESCRIPTION:
Peeks at the next pending event in the event queue.
HEADER:
event.h
RETURNS:
True if an event is pending, false if not.
PARAMETERS:
evt - Pointer to structure to return the event info in
mask - Mask specifying the types of events that should be removed
REMARKS:
Peeks at the next pending event of the specified type in the event queue. The
mask parameter is used to specify the type of events to be peeked at, and
can be any logical combination of any of the flags defined by the
EVT_eventType enumeration.
In contrast to EVT_getNext, the event is not removed from the event queue.
You may combine the masks for different event types with a simple logical OR.
SEE ALSO:
EVT_flush, EVT_getNext, EVT_halt
****************************************************************************/
ibool EVTAPI EVT_peekNext(
event_t *evt,
ulong mask)
{
int evtID;
uint ps;
if (EVT.heartBeat)
EVT.heartBeat(EVT.heartBeatParams);
_EVT_pumpMessages(); /* Pump all messages into queue */
EVT.mouseMove(EVT.mx,EVT.my); /* Move the mouse cursor */
evt->what = EVT_NULLEVT; /* Default to null event */
if (EVT.count) {
/* It is possible that an event be posted while we are trying
* to access the event queue. This would create problems since
* we may end up with invalid data for our event queue pointers. To
* alleviate this, all interrupts are suspended while we manipulate
* our pointers.
*/
ps = _EVT_disableInt(); /* disable interrupts */
for (evtID = EVT.head; evtID != -1; evtID = EVT.evtq[evtID].next) {
if (EVT.evtq[evtID].what & mask)
break; /* Found an event */
}
if (evtID == -1) {
_EVT_restoreInt(ps);
return false; /* Event was not found */
}
*evt = EVT.evtq[evtID]; /* Return the event */
_EVT_restoreInt(ps);
if (evt->what & EVT_KEYEVT)
_EVT_maskKeyCode(evt);
}
return evt->what != EVT_NULLEVT;
}
/****************************************************************************
DESCRIPTION:
Retrieves the next pending event from the event queue.
PARAMETERS:
evt - Pointer to structure to return the event info in
mask - Mask specifying the types of events that should be removed
HEADER:
event.h
RETURNS:
True if an event was pending, false if not.
REMARKS:
Retrieves the next pending event from the event queue, and stores it in a
event_t structure. The mask parameter is used to specify the type of events
to be removed, and can be any logical combination of any of the flags defined
by the EVT_eventType enumeration.
The what field of the event contains the event code of the event that was
extracted. All application specific events should begin with the EVT_USEREVT
code and build from there. Since the event code is stored in an integer,
there is a maximum of 32 different event codes that can be distinguished.
You can store extra information about the event in the message field to
distinguish between events of the same class (for instance the button used in
a EVT_MOUSEDOWN event).
If an event of the specified type was not in the event queue, the what field
of the event will be set to NULLEVT, and the return value will return false.
Note: You should /always/ use the EVT_EVERYEVT mask for extracting events
from your main event loop handler. Using a mask for only a specific
type of event for long periods of time will cause the event queue to
fill up with events of the type you are ignoring, eventually causing
the application to hang when the event queue becomes full.
SEE ALSO:
EVT_flush, EVT_halt, EVT_peekNext
****************************************************************************/
ibool EVTAPI EVT_getNext(
event_t *evt,
ulong mask)
{
int evtID,next,prev;
uint ps;
if (EVT.heartBeat)
EVT.heartBeat(EVT.heartBeatParams);
_EVT_pumpMessages(); /* Pump all messages into queue */
EVT.mouseMove(EVT.mx,EVT.my); /* Move the mouse cursor */
evt->what = EVT_NULLEVT; /* Default to null event */
if (EVT.count) {
/* It is possible that an event be posted while we are trying
* to access the event queue. This would create problems since
* we may end up with invalid data for our event queue pointers. To
* alleviate this, all interrupts are suspended while we manipulate
* our pointers.
*/
ps = _EVT_disableInt(); /* disable interrupts */
for (evtID = EVT.head; evtID != -1; evtID = EVT.evtq[evtID].next) {
if (EVT.evtq[evtID].what & mask)
break; /* Found an event */
}
if (evtID == -1) {
_EVT_restoreInt(ps);
return false; /* Event was not found */
}
next = EVT.evtq[evtID].next;
prev = EVT.evtq[evtID].prev;
if (prev != -1)
EVT.evtq[prev].next = next;
else
EVT.head = next;
if (next != -1)
EVT.evtq[next].prev = prev;
else
EVT.tail = prev;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?