For editor, replace use of ui_mega_process() with event_process(), with the editor's own default event handler; add EVENT_MOUSE_MOVED event with event_mouse_get_delta() accessor; add event_key_get() to replace ugly casting; rename mouse_get_button() with event_mouse_get_button() to keep with name convention; only send idle events when there are no input events so editor still works properly (or the same anyway); add and use event_send() function for input events (including idle)
This commit is contained in:
parent
010f7fb6d6
commit
2bd3385abd
|
@ -1,5 +1,9 @@
|
|||
D1X-Rebirth Changelog
|
||||
|
||||
20110113
|
||||
--------
|
||||
arch/include/event.h, arch/include/key.h, arch/include/mouse.h, arch/sdl/event.c, arch/sdl/key.c, arch/sdl/mouse.c, editor/med.c, include/ui.h, main/automap.c, main/gamecntl.c, main/inferno.c, main/inferno.h, main/kconfig.c, main/kmatrix.c, main/menu.c, main/net_ipx.c, main/net_udp.c, main/newmenu.c, main/scores.c, main/titles.c, ui/file.c, ui/keypress.c, ui/menu.c, ui/menubar.c, ui/message.c, ui/mouse.c, ui/popup.c, ui/window.c: For editor, replace use of ui_mega_process() with event_process(), with the editor's own default event handler; add EVENT_MOUSE_MOVED event with event_mouse_get_delta() accessor; add event_key_get() to replace ugly casting; rename mouse_get_button() with event_mouse_get_button() to keep with name convention; only send idle events when there are no input events so editor still works properly (or the same anyway); add and use event_send() function for input events (including idle)
|
||||
|
||||
20110111
|
||||
--------
|
||||
main/net_udp.c: Fixed Menu setting for AllowedItems which was broken due to changed return value of newmenu_do1
|
||||
|
|
|
@ -10,6 +10,8 @@ typedef enum event_type
|
|||
|
||||
EVENT_MOUSE_BUTTON_DOWN,
|
||||
EVENT_MOUSE_BUTTON_UP,
|
||||
EVENT_MOUSE_DOUBLE_CLICKED, // editor only for now
|
||||
EVENT_MOUSE_MOVED,
|
||||
|
||||
EVENT_KEY_COMMAND,
|
||||
|
||||
|
@ -40,6 +42,9 @@ void event_flush();
|
|||
void set_default_handler(int (*handler)(d_event *event));
|
||||
int call_default_handler(d_event *event);
|
||||
|
||||
// Send an event to the front window as first priority, then the default handler
|
||||
void event_send(d_event *event);
|
||||
|
||||
// Sends input, idle and draw events to event handlers
|
||||
void event_process();
|
||||
|
||||
|
|
|
@ -28,12 +28,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#define KEY_REPEAT_DELAY 1000
|
||||
#define KEY_REPEAT_INTERVAL 100
|
||||
|
||||
typedef struct d_event_keycommand
|
||||
{
|
||||
event_type type; // EVENT_KEY_COMMAND
|
||||
int keycode;
|
||||
} d_event_keycommand;
|
||||
|
||||
//==========================================================================
|
||||
// This installs the int9 vector and initializes the keyboard in buffered
|
||||
// ASCII mode. key_close simply undoes that.
|
||||
|
@ -65,6 +59,7 @@ extern void key_flush(); // Clears the 256 char buffer
|
|||
extern int key_checkch(); // Returns 1 if a char is waiting
|
||||
extern int key_getch(); // Gets key if one waiting other waits for one.
|
||||
extern int key_inkey(); // Gets key if one, other returns 0.
|
||||
extern int event_key_get(d_event *event); // Get the keycode from the EVENT_KEY_COMMAND event
|
||||
extern int key_peekkey(); // Same as inkey, but doesn't remove key from buffer.
|
||||
|
||||
extern unsigned char key_ascii();
|
||||
|
|
|
@ -38,9 +38,10 @@ struct d_event;
|
|||
extern void mouse_flush(); // clears all mice events...
|
||||
extern void mouse_init(void);
|
||||
extern void mouse_close(void);
|
||||
int mouse_get_button(struct d_event *event);
|
||||
extern int event_mouse_get_button(struct d_event *event);
|
||||
extern void mouse_get_pos( int *x, int *y, int *z );
|
||||
extern void mouse_get_delta( int *dx, int *dy, int *dz );
|
||||
extern void event_mouse_get_delta(struct d_event *event, int *dx, int *dy, int *dz);
|
||||
extern int mouse_get_btns();
|
||||
extern void mouse_set_pos( int x, int y);
|
||||
extern fix64 mouse_button_down_time(int button);
|
||||
|
|
|
@ -32,11 +32,13 @@ void event_poll()
|
|||
SDL_Event event;
|
||||
int clean_uniframe=1;
|
||||
window *wind = window_get_front();
|
||||
|
||||
int idle = 1;
|
||||
|
||||
// If the front window changes, exit this loop, otherwise unintended behavior can occur
|
||||
// like pressing 'Return' really fast at 'Difficulty Level' causing multiple games to be started
|
||||
while ((wind == window_get_front()) && SDL_PollEvent(&event))
|
||||
{
|
||||
idle = 0;
|
||||
switch(event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
|
@ -71,6 +73,16 @@ void event_poll()
|
|||
}
|
||||
}
|
||||
|
||||
// Send the idle event if there were no other events
|
||||
if (idle)
|
||||
{
|
||||
d_event event;
|
||||
|
||||
event.type = EVENT_IDLE;
|
||||
event_send(&event);
|
||||
return;
|
||||
}
|
||||
|
||||
mouse_cursor_autohide();
|
||||
}
|
||||
|
||||
|
@ -104,6 +116,19 @@ int call_default_handler(d_event *event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void event_send(d_event *event)
|
||||
{
|
||||
window *wind;
|
||||
|
||||
if ((wind = window_get_front()))
|
||||
{
|
||||
if (!window_send_event(wind, event))
|
||||
call_default_handler(event);
|
||||
}
|
||||
else
|
||||
call_default_handler(event);
|
||||
}
|
||||
|
||||
// Process the first event in queue, sending to the appropriate handler
|
||||
// This is the new object-oriented system
|
||||
// Uses the old system for now, but this may change
|
||||
|
@ -114,22 +139,10 @@ void event_process(void)
|
|||
|
||||
event_poll(); // send input events first
|
||||
|
||||
// Doing this prevents problems when an idle event can create a newmenu,
|
||||
// Doing this prevents problems when a draw event can create a newmenu,
|
||||
// such as some network menus when they report a problem
|
||||
if (window_get_front() != wind)
|
||||
return;
|
||||
|
||||
event.type = EVENT_IDLE;
|
||||
if ((wind = window_get_front()))
|
||||
{
|
||||
if (!window_send_event(wind, &event))
|
||||
call_default_handler(&event);
|
||||
}
|
||||
else
|
||||
call_default_handler(&event);
|
||||
|
||||
if (window_get_front() != wind)
|
||||
return;
|
||||
|
||||
event.type = EVENT_WINDOW_DRAW; // then draw all visible windows
|
||||
for (wind = window_get_first(); wind != NULL; wind = window_get_next(wind))
|
||||
|
|
|
@ -313,6 +313,12 @@ key_props key_properties[256] = {
|
|||
{ "", 255, -1 }, // 255
|
||||
};
|
||||
|
||||
typedef struct d_event_keycommand
|
||||
{
|
||||
event_type type; // EVENT_KEY_COMMAND
|
||||
int keycode;
|
||||
} d_event_keycommand;
|
||||
|
||||
char *key_text[256];
|
||||
|
||||
int key_ismodlck(int keycode)
|
||||
|
@ -449,25 +455,18 @@ void key_handler(SDL_KeyboardEvent *event)
|
|||
if (key_command || unicode_frame_buffer[0] != '\0')
|
||||
{
|
||||
d_event_keycommand event;
|
||||
window *wind;
|
||||
|
||||
event.type = EVENT_KEY_COMMAND;
|
||||
event.keycode = key_command;
|
||||
if ((wind = window_get_front()))
|
||||
{
|
||||
con_printf(CON_DEBUG, "Sending event EVENT_KEY_COMMAND: %s %s %s %s %s %s\n",
|
||||
(key_command & KEY_METAED) ? "META" : "",
|
||||
(key_command & KEY_DEBUGGED) ? "DEBUG" : "",
|
||||
(key_command & KEY_CTRLED) ? "CTRL" : "",
|
||||
(key_command & KEY_ALTED) ? "ALT" : "",
|
||||
(key_command & KEY_SHIFTED) ? "SHIFT" : "",
|
||||
key_properties[key_command & 0xff].key_text
|
||||
);
|
||||
if (!window_send_event(wind, (d_event *)&event))
|
||||
call_default_handler((d_event *)&event);
|
||||
}
|
||||
else
|
||||
call_default_handler((d_event *)&event);
|
||||
con_printf(CON_DEBUG, "Sending event EVENT_KEY_COMMAND: %s %s %s %s %s %s\n",
|
||||
(key_command & KEY_METAED) ? "META" : "",
|
||||
(key_command & KEY_DEBUGGED) ? "DEBUG" : "",
|
||||
(key_command & KEY_CTRLED) ? "CTRL" : "",
|
||||
(key_command & KEY_ALTED) ? "ALT" : "",
|
||||
(key_command & KEY_SHIFTED) ? "SHIFT" : "",
|
||||
key_properties[key_command & 0xff].key_text
|
||||
);
|
||||
event_send((d_event *)&event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -568,6 +567,12 @@ int key_inkey()
|
|||
return key;
|
||||
}
|
||||
|
||||
int event_key_get(d_event *event)
|
||||
{
|
||||
Assert(event->type == EVENT_KEY_COMMAND);
|
||||
return ((d_event_keycommand *)event)->keycode;
|
||||
}
|
||||
|
||||
int key_peekkey()
|
||||
{
|
||||
int key = 0;
|
||||
|
|
|
@ -35,6 +35,12 @@ typedef struct d_event_mousebutton
|
|||
int button;
|
||||
} d_event_mousebutton;
|
||||
|
||||
typedef struct d_event_mouse_moved
|
||||
{
|
||||
event_type type; // EVENT_MOUSE_MOVED
|
||||
short dx, dy, dz;
|
||||
} d_event_mouse_moved;
|
||||
|
||||
void mouse_init(void)
|
||||
{
|
||||
memset(&Mouse,0,sizeof(Mouse));
|
||||
|
@ -71,7 +77,6 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
|
|||
|
||||
int button = button_remap[mbe->button - 1]; // -1 since SDL seems to start counting at 1
|
||||
d_event_mousebutton event;
|
||||
window *wind;
|
||||
|
||||
if (GameArg.CtlNoMouse)
|
||||
return;
|
||||
|
@ -79,6 +84,8 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
|
|||
Mouse.cursor_time = timer_query();
|
||||
|
||||
if (mbe->state == SDL_PRESSED) {
|
||||
d_event_mouse_moved event2 = { EVENT_MOUSE_MOVED, 0, 0, 0 };
|
||||
|
||||
Mouse.buttons[button].pressed = 1;
|
||||
Mouse.buttons[button].time_went_down = timer_query();
|
||||
Mouse.buttons[button].num_downs++;
|
||||
|
@ -86,9 +93,18 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
|
|||
if (button == MBTN_Z_UP) {
|
||||
Mouse.delta_z += Z_SENSITIVITY;
|
||||
Mouse.z += Z_SENSITIVITY;
|
||||
event2.dz = Z_SENSITIVITY;
|
||||
} else if (button == MBTN_Z_DOWN) {
|
||||
Mouse.delta_z -= Z_SENSITIVITY;
|
||||
Mouse.z -= Z_SENSITIVITY;
|
||||
event2.dz = -1*Z_SENSITIVITY;
|
||||
}
|
||||
|
||||
if (event2.dz)
|
||||
{
|
||||
//con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_MOVED, relative motion %d,%d,%d\n",
|
||||
// event2.dx, event2.dy, event2.dz);
|
||||
event_send((d_event *)&event2);
|
||||
}
|
||||
} else {
|
||||
Mouse.buttons[button].pressed = 0;
|
||||
|
@ -99,25 +115,40 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
|
|||
event.type = (mbe->state == SDL_PRESSED) ? EVENT_MOUSE_BUTTON_DOWN : EVENT_MOUSE_BUTTON_UP;
|
||||
event.button = button;
|
||||
|
||||
if ((wind = window_get_front()))
|
||||
{
|
||||
con_printf(CON_DEBUG, "Sending event %s, button %d, coords %d,%d,%d\n",
|
||||
(mbe->state == SDL_PRESSED) ? "EVENT_MOUSE_BUTTON_DOWN" : "EVENT_MOUSE_BUTTON_UP", event.button, Mouse.x, Mouse.y, Mouse.z);
|
||||
if (!window_send_event(wind, (d_event *)&event))
|
||||
call_default_handler((d_event *)&event);
|
||||
}
|
||||
else
|
||||
call_default_handler((d_event *)&event);
|
||||
con_printf(CON_DEBUG, "Sending event %s, button %d, coords %d,%d,%d\n",
|
||||
(mbe->state == SDL_PRESSED) ? "EVENT_MOUSE_BUTTON_DOWN" : "EVENT_MOUSE_BUTTON_UP", event.button, Mouse.x, Mouse.y, Mouse.z);
|
||||
event_send((d_event *)&event);
|
||||
}
|
||||
|
||||
void mouse_motion_handler(SDL_MouseMotionEvent *mme)
|
||||
{
|
||||
d_event_mouse_moved event;
|
||||
|
||||
if (GameArg.CtlNoMouse)
|
||||
return;
|
||||
|
||||
Mouse.cursor_time = timer_query();
|
||||
Mouse.x += mme->xrel;
|
||||
Mouse.y += mme->yrel;
|
||||
|
||||
event.type = EVENT_MOUSE_MOVED;
|
||||
event.dx = mme->xrel;
|
||||
event.dy = mme->yrel;
|
||||
event.dz = 0; // handled in mouse_button_handler
|
||||
|
||||
// filter delta?
|
||||
if (PlayerCfg.MouseFilter)
|
||||
{
|
||||
event.dx = (event.dx + Mouse.old_delta_x) * 0.5;
|
||||
event.dy = (event.dy + Mouse.old_delta_y) * 0.5;
|
||||
}
|
||||
|
||||
Mouse.old_delta_x = event.dx;
|
||||
Mouse.old_delta_y = event.dy;
|
||||
|
||||
//con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_MOVED, relative motion %d,%d,%d\n",
|
||||
// event.dx, event.dy, event.dz);
|
||||
event_send((d_event *)&event);
|
||||
}
|
||||
|
||||
void mouse_flush() // clears all mice events...
|
||||
|
@ -175,7 +206,16 @@ void mouse_get_delta( int *dx, int *dy, int *dz )
|
|||
Mouse.delta_z = 0;
|
||||
}
|
||||
|
||||
int mouse_get_button(d_event *event)
|
||||
void event_mouse_get_delta(d_event *event, int *dx, int *dy, int *dz)
|
||||
{
|
||||
Assert(event->type == EVENT_MOUSE_MOVED);
|
||||
|
||||
*dx = ((d_event_mouse_moved *)event)->dx;
|
||||
*dy = ((d_event_mouse_moved *)event)->dy;
|
||||
*dz = ((d_event_mouse_moved *)event)->dz;
|
||||
}
|
||||
|
||||
int event_mouse_get_button(d_event *event)
|
||||
{
|
||||
Assert((event->type == EVENT_MOUSE_BUTTON_DOWN) || (event->type == EVENT_MOUSE_BUTTON_UP));
|
||||
return ((d_event_mousebutton *)event)->button;
|
||||
|
|
11
editor/med.c
11
editor/med.c
|
@ -29,10 +29,11 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include <time.h>
|
||||
|
||||
#include "inferno.h"
|
||||
#include "window.h"
|
||||
#include "messagebox.h"
|
||||
#include "segment.h"
|
||||
#include "gr.h"
|
||||
#include "event.h"
|
||||
#include "window.h"
|
||||
#include "messagebox.h"
|
||||
#include "ui.h"
|
||||
#include "editor.h"
|
||||
#include "gamesave.h"
|
||||
|
@ -1047,6 +1048,8 @@ void editor(void)
|
|||
ui_pad_goto(padnum);
|
||||
|
||||
gamestate_restore_check();
|
||||
|
||||
set_default_handler(ui_event_handler);
|
||||
|
||||
while (Function_mode == FMODE_EDITOR) {
|
||||
|
||||
|
@ -1063,7 +1066,7 @@ void editor(void)
|
|||
|
||||
//do editor stuff
|
||||
gr_set_curfont(editor_font);
|
||||
ui_mega_process();
|
||||
event_process();
|
||||
last_keypress &= ~KEY_DEBUGGED; // mask off delete key bit which has no function in editor.
|
||||
ui_window_do_gadgets(EditorWindow);
|
||||
do_robot_window();
|
||||
|
@ -1349,6 +1352,8 @@ void editor(void)
|
|||
}
|
||||
}
|
||||
|
||||
set_default_handler(standard_handler);
|
||||
|
||||
// _MARK_("end of editor");//Nuked to compile -KRB
|
||||
|
||||
set_warn_func(msgbox_warning);
|
||||
|
|
|
@ -20,6 +20,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#ifndef _UI_H
|
||||
#define _UI_H
|
||||
|
||||
struct d_event;
|
||||
|
||||
typedef struct {
|
||||
char description[100];
|
||||
char * buttontext[17];
|
||||
|
@ -258,7 +260,8 @@ int PopupMenu( int NumItems, char * text[] );
|
|||
extern void ui_mouse_init();
|
||||
extern grs_bitmap * ui_mouse_set_pointer( grs_bitmap * new );
|
||||
|
||||
extern void ui_mouse_process();
|
||||
extern int ui_mouse_button_process(struct d_event *event);
|
||||
extern int ui_mouse_motion_process(struct d_event *event);
|
||||
extern void ui_mouse_hide();
|
||||
extern void ui_mouse_show();
|
||||
|
||||
|
@ -285,6 +288,7 @@ extern void ui_draw_listbox( UI_GADGET_LISTBOX * listbox );
|
|||
extern UI_GADGET_LISTBOX *ui_add_gadget_listbox(UI_WINDOW *wnd, short x, short y, short w, short h, short numitems, char **list);
|
||||
|
||||
extern void ui_mega_process();
|
||||
extern int ui_event_handler(struct d_event *event);
|
||||
|
||||
extern void ui_get_button_size( char * text, int * width, int * height );
|
||||
|
||||
|
|
|
@ -360,7 +360,7 @@ extern int set_segment_depths(int start_seg, ubyte *segbuf);
|
|||
|
||||
int automap_key_command(window *wind, d_event *event, automap *am)
|
||||
{
|
||||
int c = ((d_event_keycommand *)event)->keycode;
|
||||
int c = event_key_get(event);
|
||||
|
||||
switch (c)
|
||||
{
|
||||
|
|
|
@ -233,7 +233,7 @@ int pause_handler(window *wind, d_event *event, char *msg)
|
|||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
key = ((d_event_keycommand *)event)->keycode;
|
||||
key = event_key_get(event);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
|
@ -1399,7 +1399,7 @@ int ReadControls(d_event *event)
|
|||
|
||||
if (event->type == EVENT_KEY_COMMAND)
|
||||
{
|
||||
key = ((d_event_keycommand *)event)->keycode;
|
||||
key = event_key_get(event);
|
||||
|
||||
if (con_events(key) && con_render)
|
||||
return 1;
|
||||
|
|
|
@ -222,7 +222,7 @@ int standard_handler(d_event *event)
|
|||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
key = ((d_event_keycommand *)event)->keycode;
|
||||
key = event_key_get(event);
|
||||
|
||||
// Don't let modifier(s) on their own do something unless we explicitly want that
|
||||
// (e.g. if it's a game control like fire primary)
|
||||
|
|
|
@ -22,6 +22,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
|
||||
#include <setjmp.h>
|
||||
|
||||
struct d_event;
|
||||
|
||||
#if defined(__APPLE__) || defined(macintosh)
|
||||
#define KEY_MAC(x) x
|
||||
#else
|
||||
|
@ -58,4 +60,7 @@ extern int Function_mode; //in game or editor?
|
|||
extern int Screen_mode; //editor screen or game screen?
|
||||
extern int MacHog;
|
||||
|
||||
// Default event handler for everything except the editor
|
||||
int standard_handler(struct d_event *event);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -628,7 +628,7 @@ int kconfig_key_command(window *wind, d_event *event, kc_menu *menu)
|
|||
{
|
||||
int i,k;
|
||||
|
||||
k = ((d_event_keycommand *)event)->keycode;
|
||||
k = event_key_get(event);
|
||||
|
||||
// when changing, process no keys instead of ESC
|
||||
if (menu->changing && (k != -2 && k != KEY_ESC))
|
||||
|
@ -812,13 +812,13 @@ int kconfig_handler(window *wind, d_event *event, kc_menu *menu)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (mouse_get_button(event) == MBTN_RIGHT)
|
||||
if (event_mouse_get_button(event) == MBTN_RIGHT)
|
||||
{
|
||||
if (!menu->changing)
|
||||
window_close(wind);
|
||||
return 1;
|
||||
}
|
||||
else if (mouse_get_button(event) != MBTN_LEFT)
|
||||
else if (event_mouse_get_button(event) != MBTN_LEFT)
|
||||
return 0;
|
||||
|
||||
menu->mouse_state = (event->type == EVENT_MOUSE_BUTTON_DOWN);
|
||||
|
@ -1037,7 +1037,7 @@ void kc_change_mousebutton( kc_menu *menu, d_event *event, kc_item * item )
|
|||
{
|
||||
int n,i,b;
|
||||
|
||||
b = mouse_get_button(event);
|
||||
b = event_mouse_get_button(event);
|
||||
|
||||
for (i=0; i<menu->nitems; i++)
|
||||
{
|
||||
|
|
|
@ -194,7 +194,7 @@ int kmatrix_ipx_handler(window *wind, d_event *event, kmatrix_ipx_screen *km)
|
|||
switch (event->type)
|
||||
{
|
||||
case EVENT_KEY_COMMAND:
|
||||
k = ((d_event_keycommand *)event)->keycode;
|
||||
k = event_key_get(event);
|
||||
switch( k )
|
||||
{
|
||||
case KEY_ENTER:
|
||||
|
@ -472,7 +472,7 @@ int kmatrix_handler(window *wind, d_event *event, kmatrix_screen *km)
|
|||
switch (event->type)
|
||||
{
|
||||
case EVENT_KEY_COMMAND:
|
||||
k = ((d_event_keycommand *)event)->keycode;
|
||||
k = event_key_get(event);
|
||||
switch( k )
|
||||
{
|
||||
case KEY_ESC:
|
||||
|
|
|
@ -219,7 +219,7 @@ int player_menu_keycommand( listbox *lb, d_event *event )
|
|||
char **items = listbox_get_items(lb);
|
||||
int citem = listbox_get_citem(lb);
|
||||
|
||||
switch (((d_event_keycommand *)event)->keycode)
|
||||
switch (event_key_get(event))
|
||||
{
|
||||
case KEY_CTRLED+KEY_D:
|
||||
if (citem > 0)
|
||||
|
@ -409,7 +409,7 @@ int main_menu_handler(newmenu *menu, d_event *event, int *menu_choice )
|
|||
|
||||
case EVENT_KEY_COMMAND:
|
||||
// Don't allow them to hit ESC in the main menu.
|
||||
if (((d_event_keycommand *)event)->keycode==KEY_ESC)
|
||||
if (event_key_get(event)==KEY_ESC)
|
||||
return 1;
|
||||
break;
|
||||
|
||||
|
@ -652,7 +652,7 @@ int demo_menu_keycommand( listbox *lb, d_event *event )
|
|||
char **items = listbox_get_items(lb);
|
||||
int citem = listbox_get_citem(lb);
|
||||
|
||||
switch (((d_event_keycommand *)event)->keycode)
|
||||
switch (event_key_get(event))
|
||||
{
|
||||
case KEY_CTRLED+KEY_D:
|
||||
if (citem >= 0)
|
||||
|
@ -1356,7 +1356,7 @@ int select_file_handler(listbox *menu, d_event *event, browser *b)
|
|||
#ifdef _WIN32
|
||||
case EVENT_KEY_COMMAND:
|
||||
{
|
||||
if (((d_event_keycommand *)event)->keycode == KEY_CTRLED + KEY_D)
|
||||
if (event_key_get(event) == KEY_CTRLED + KEY_D)
|
||||
{
|
||||
newmenu_item *m;
|
||||
char *text = NULL;
|
||||
|
|
|
@ -622,7 +622,7 @@ int net_ipx_endlevel_poll( newmenu *menu, d_event *event, int *secret )
|
|||
switch (event->type)
|
||||
{
|
||||
case EVENT_KEY_COMMAND:
|
||||
if (((d_event_keycommand *)event)->keycode != KEY_ESC)
|
||||
if (event_key_get(event) != KEY_ESC)
|
||||
return 0;
|
||||
|
||||
{
|
||||
|
@ -3049,7 +3049,7 @@ int net_ipx_join_poll( newmenu *menu, d_event *event, void *menu_text )
|
|||
switch (event->type)
|
||||
{
|
||||
case EVENT_KEY_COMMAND:
|
||||
key = ((d_event_keycommand *)event)->keycode;
|
||||
key = event_key_get(event);
|
||||
|
||||
if ( IPX_allow_socket_changes ) {
|
||||
int osocket;
|
||||
|
@ -3828,7 +3828,7 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n
|
|||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
k = ((d_event_keycommand *)event)->keycode;
|
||||
k = event_key_get(event);
|
||||
switch (k)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
|
|
|
@ -386,7 +386,7 @@ static int manual_join_game_handler(newmenu *menu, d_event *event, direct_join *
|
|||
switch (event->type)
|
||||
{
|
||||
case EVENT_KEY_COMMAND:
|
||||
if (dj->connecting && ((d_event_keycommand *)event)->keycode == KEY_ESC)
|
||||
if (dj->connecting && event_key_get(event) == KEY_ESC)
|
||||
{
|
||||
dj->connecting = 0;
|
||||
items[6].text = blank;
|
||||
|
@ -530,7 +530,7 @@ int net_udp_list_join_poll( newmenu *menu, d_event *event, direct_join *dj )
|
|||
break;
|
||||
case EVENT_KEY_COMMAND:
|
||||
{
|
||||
int key = ((d_event_keycommand *)event)->keycode;
|
||||
int key = event_key_get(event);
|
||||
if (key == KEY_PAGEUP)
|
||||
{
|
||||
NLPage--;
|
||||
|
@ -4444,7 +4444,7 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n
|
|||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
k = ((d_event_keycommand *)event)->keycode;
|
||||
k = event_key_get(event);
|
||||
switch (k)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
|
|
|
@ -853,7 +853,7 @@ int newmenu_mouse(window *wind, d_event *event, newmenu *menu, int button)
|
|||
int newmenu_key_command(window *wind, d_event *event, newmenu *menu)
|
||||
{
|
||||
newmenu_item *item = &menu->items[menu->citem];
|
||||
int k = ((d_event_keycommand *)event)->keycode;
|
||||
int k = event_key_get(event);
|
||||
int old_choice, i;
|
||||
char *Temp,TempVal;
|
||||
int changed = 0;
|
||||
|
@ -1514,7 +1514,7 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu)
|
|||
case EVENT_MOUSE_BUTTON_DOWN:
|
||||
case EVENT_MOUSE_BUTTON_UP:
|
||||
{
|
||||
int button = mouse_get_button(event);
|
||||
int button = event_mouse_get_button(event);
|
||||
menu->mouse_state = event->type == EVENT_MOUSE_BUTTON_DOWN;
|
||||
return newmenu_mouse(wind, event, menu, button);
|
||||
}
|
||||
|
@ -1848,7 +1848,7 @@ int listbox_mouse(window *wind, d_event *event, listbox *lb, int button)
|
|||
|
||||
int listbox_key_command(window *wind, d_event *event, listbox *lb)
|
||||
{
|
||||
int key = ((d_event_keycommand *)event)->keycode;
|
||||
int key = event_key_get(event);
|
||||
int rval = 1;
|
||||
|
||||
switch(key) {
|
||||
|
@ -2096,7 +2096,7 @@ int listbox_handler(window *wind, d_event *event, listbox *lb)
|
|||
case EVENT_MOUSE_BUTTON_DOWN:
|
||||
case EVENT_MOUSE_BUTTON_UP:
|
||||
{
|
||||
int button = mouse_get_button(event);
|
||||
int button = event_mouse_get_button(event);
|
||||
lb->mouse_state = event->type == EVENT_MOUSE_BUTTON_DOWN;
|
||||
return listbox_mouse(wind, event, lb, button);
|
||||
}
|
||||
|
|
|
@ -331,7 +331,7 @@ int scores_handler(window *wind, d_event *event, scores_menu *menu)
|
|||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
k = ((d_event_keycommand *)event)->keycode;
|
||||
k = event_key_get(event);
|
||||
switch( k ) {
|
||||
case KEY_CTRLED+KEY_R:
|
||||
if ( menu->citem < 0 ) {
|
||||
|
|
|
@ -90,7 +90,7 @@ int title_handler(window *wind, d_event *event, title_screen *ts)
|
|||
switch (event->type)
|
||||
{
|
||||
case EVENT_MOUSE_BUTTON_DOWN:
|
||||
if (mouse_get_button(event) != 0)
|
||||
if (event_mouse_get_button(event) != 0)
|
||||
return 0;
|
||||
else if (ts->allow_keys)
|
||||
{
|
||||
|
@ -1059,7 +1059,7 @@ int briefing_handler(window *wind, d_event *event, briefing *br)
|
|||
break;
|
||||
|
||||
case EVENT_MOUSE_BUTTON_DOWN:
|
||||
if (mouse_get_button(event) == 0)
|
||||
if (event_mouse_get_button(event) == 0)
|
||||
{
|
||||
if (br->new_screen)
|
||||
{
|
||||
|
@ -1080,7 +1080,7 @@ int briefing_handler(window *wind, d_event *event, briefing *br)
|
|||
|
||||
case EVENT_KEY_COMMAND:
|
||||
{
|
||||
int key = ((d_event_keycommand *)event)->keycode;
|
||||
int key = event_key_get(event);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "event.h"
|
||||
#include "physfsx.h"
|
||||
#include "fix.h"
|
||||
#include "pstypes.h"
|
||||
|
@ -193,7 +194,7 @@ int ui_get_filename( char * filename, char * Filespec, char * message )
|
|||
|
||||
while( 1 )
|
||||
{
|
||||
ui_mega_process();
|
||||
event_process();
|
||||
ui_window_do_gadgets(wnd);
|
||||
|
||||
if ( Button2->pressed )
|
||||
|
|
|
@ -23,6 +23,7 @@ static char rcsid[] = "$Id: keypress.c,v 1.1.1.1 2006/03/17 19:52:24 zicodxx Exp
|
|||
#include "fix.h"
|
||||
#include "pstypes.h"
|
||||
#include "gr.h"
|
||||
#include "event.h"
|
||||
#include "ui.h"
|
||||
#include "key.h"
|
||||
|
||||
|
@ -121,7 +122,7 @@ int GetKeyCode(char * text)
|
|||
|
||||
while(1)
|
||||
{
|
||||
ui_mega_process();
|
||||
event_process();
|
||||
ui_window_do_gadgets(wnd);
|
||||
|
||||
if (last_keypress > 0)
|
||||
|
|
|
@ -22,6 +22,7 @@ static char rcsid[] = "$Id: menu.c,v 1.1.1.1 2006/03/17 19:52:19 zicodxx Exp $";
|
|||
#include "fix.h"
|
||||
#include "pstypes.h"
|
||||
#include "gr.h"
|
||||
#include "event.h"
|
||||
#include "ui.h"
|
||||
|
||||
|
||||
|
@ -98,7 +99,7 @@ int MenuX( int x, int y, int NumButtons, char * text[] )
|
|||
|
||||
while(choice==0)
|
||||
{
|
||||
ui_mega_process();
|
||||
event_process();
|
||||
ui_window_do_gadgets(wnd);
|
||||
|
||||
for (i=0; i<NumButtons; i++ )
|
||||
|
|
|
@ -18,6 +18,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "fix.h"
|
||||
#include "pstypes.h"
|
||||
#include "gr.h"
|
||||
#include "event.h"
|
||||
#include "ui.h"
|
||||
#include "key.h"
|
||||
#include "cfile.h"
|
||||
|
@ -578,7 +579,7 @@ void menubar_do( int keypress )
|
|||
|
||||
while (state > 0 )
|
||||
{
|
||||
ui_mega_process();
|
||||
event_process();
|
||||
switch(state)
|
||||
{
|
||||
case 1:
|
||||
|
|
|
@ -22,6 +22,7 @@ static char rcsid[] = "$Id: message.c,v 1.1.1.1 2006/03/17 19:52:21 zicodxx Exp
|
|||
#include "fix.h"
|
||||
#include "pstypes.h"
|
||||
#include "gr.h"
|
||||
#include "event.h"
|
||||
#include "ui.h"
|
||||
#include "key.h"
|
||||
|
||||
|
@ -151,7 +152,7 @@ int MessageBoxN( short xc, short yc, int NumButtons, char * text, char * Button[
|
|||
|
||||
while(choice==0)
|
||||
{
|
||||
ui_mega_process();
|
||||
event_process();
|
||||
ui_window_do_gadgets(wnd);
|
||||
|
||||
for (i=0; i<NumButtons; i++ )
|
||||
|
|
96
ui/mouse.c
96
ui/mouse.c
|
@ -20,7 +20,11 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include "event.h"
|
||||
#include "u_mem.h"
|
||||
#include "error.h"
|
||||
#include "console.h"
|
||||
#include "fix.h"
|
||||
#include "pstypes.h"
|
||||
#include "gr.h"
|
||||
|
@ -128,23 +132,22 @@ void ui_mouse_hide()
|
|||
#endif
|
||||
}
|
||||
|
||||
void ui_mouse_process()
|
||||
int ui_mouse_motion_process(d_event *event)
|
||||
{
|
||||
int buttons,w,h;
|
||||
#ifndef __MSDOS__
|
||||
int new_x, new_y;
|
||||
buttons = SDL_GetMouseState(&new_x,&new_y);
|
||||
Mouse.dx = new_x - Mouse.x;
|
||||
Mouse.dy = new_y - Mouse.y;
|
||||
#else
|
||||
int w,h;
|
||||
int mx, my, mz;
|
||||
|
||||
Mouse.dx = Mouse.new_dx;
|
||||
Mouse.dy = Mouse.new_dy;
|
||||
buttons = Mouse.new_buttons;
|
||||
#endif
|
||||
Assert(event->type == EVENT_MOUSE_MOVED);
|
||||
event_mouse_get_delta(event, &mx, &my, &mz);
|
||||
|
||||
Mouse.dx = mx;
|
||||
Mouse.dy = my;
|
||||
|
||||
Mouse.x += Mouse.dx;
|
||||
Mouse.y += Mouse.dy;
|
||||
//Mouse.x += Mouse.dx;
|
||||
//Mouse.y += Mouse.dy;
|
||||
mouse_get_pos(&mx, &my, &mz);
|
||||
Mouse.x = mx;
|
||||
Mouse.y = my;
|
||||
|
||||
w = grd_curscreen->sc_w;
|
||||
h = grd_curscreen->sc_h;
|
||||
|
@ -182,35 +185,66 @@ void ui_mouse_process()
|
|||
}
|
||||
#endif /* __MSDOS__*/
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// straight from mouse.c's counterpart in arch/sdl
|
||||
typedef struct d_event_mousebutton
|
||||
{
|
||||
event_type type;
|
||||
int button;
|
||||
} d_event_mousebutton;
|
||||
|
||||
int ui_mouse_button_process(d_event *event)
|
||||
{
|
||||
// int mx, my, mz;
|
||||
int button = -1;
|
||||
int pressed;
|
||||
|
||||
Assert((event->type == EVENT_MOUSE_BUTTON_DOWN) || (event->type == EVENT_MOUSE_BUTTON_UP) || (event->type == EVENT_IDLE));
|
||||
|
||||
if (event->type != EVENT_IDLE)
|
||||
button = event_mouse_get_button(event);
|
||||
|
||||
// Get the mouse's position
|
||||
//mouse_get_pos(&mx, &my, &mz);
|
||||
//Mouse.x = mx;
|
||||
//Mouse.y = my;
|
||||
|
||||
pressed = event->type == EVENT_MOUSE_BUTTON_DOWN;
|
||||
|
||||
Mouse.b1_last_status = Mouse.b1_status;
|
||||
Mouse.b2_last_status = Mouse.b2_status;
|
||||
Mouse.b1_status &= (BUTTON_PRESSED | BUTTON_RELEASED);
|
||||
Mouse.b2_status &= (BUTTON_PRESSED | BUTTON_RELEASED);
|
||||
|
||||
if (event->type == EVENT_IDLE)
|
||||
return 0;
|
||||
|
||||
if ( Mouse.backwards== 0 )
|
||||
{
|
||||
if (buttons & MOUSE_LBTN )
|
||||
Mouse.b1_status = BUTTON_PRESSED;
|
||||
else
|
||||
Mouse.b1_status = BUTTON_RELEASED;
|
||||
if (buttons & MOUSE_RBTN )
|
||||
Mouse.b2_status = BUTTON_PRESSED;
|
||||
else
|
||||
Mouse.b2_status = BUTTON_RELEASED;
|
||||
if (button == MBTN_LEFT)
|
||||
Mouse.b1_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED;
|
||||
else if (button == MBTN_RIGHT)
|
||||
Mouse.b2_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED;
|
||||
} else {
|
||||
if (buttons & MOUSE_LBTN )
|
||||
Mouse.b2_status = BUTTON_PRESSED;
|
||||
else
|
||||
Mouse.b2_status = BUTTON_RELEASED;
|
||||
if (buttons & MOUSE_RBTN )
|
||||
Mouse.b1_status = BUTTON_PRESSED;
|
||||
else
|
||||
Mouse.b1_status = BUTTON_RELEASED;
|
||||
if (button == MBTN_LEFT)
|
||||
Mouse.b2_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED;
|
||||
else if (button == MBTN_RIGHT)
|
||||
Mouse.b1_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED;
|
||||
}
|
||||
|
||||
if ((Mouse.b1_status & BUTTON_PRESSED) && (Mouse.b1_last_status & BUTTON_RELEASED) )
|
||||
{
|
||||
if ((timer_query() <= Mouse.time_lastpressed + F1_0/5)) //&& (Mouse.moved==0)
|
||||
{
|
||||
d_event_mousebutton event = { EVENT_MOUSE_DOUBLE_CLICKED, MBTN_LEFT };
|
||||
Mouse.b1_status |= BUTTON_DOUBLE_CLICKED;
|
||||
con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_DOUBLE_CLICKED, button %d, coords %d,%d\n",
|
||||
event.button, Mouse.x, Mouse.y);
|
||||
event_send((d_event *)&event);
|
||||
}
|
||||
|
||||
Mouse.moved = 0;
|
||||
Mouse.time_lastpressed = timer_query();
|
||||
|
@ -224,6 +258,8 @@ void ui_mouse_process()
|
|||
Mouse.b2_status |= BUTTON_JUST_PRESSED;
|
||||
else if ((Mouse.b2_status & BUTTON_RELEASED) && (Mouse.b2_last_status & BUTTON_PRESSED) )
|
||||
Mouse.b2_status |= BUTTON_JUST_RELEASED;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ui_mouse_flip_buttons()
|
||||
|
|
|
@ -19,6 +19,7 @@ static char rcsid[] = "$Id: popup.c,v 1.1.1.1 2006/03/17 19:52:22 zicodxx Exp $"
|
|||
#include "fix.h"
|
||||
#include "pstypes.h"
|
||||
#include "gr.h"
|
||||
#include "event.h"
|
||||
#include "ui.h"
|
||||
#include "mouse.h"
|
||||
|
||||
|
@ -123,7 +124,7 @@ int PopupMenu( int NumButtons, char * text[] )
|
|||
|
||||
while(choice==0)
|
||||
{
|
||||
ui_mega_process();
|
||||
event_process();
|
||||
ui_window_do_gadgets(wnd);
|
||||
|
||||
for (i=0; i<NumButtons; i++ )
|
||||
|
|
72
ui/window.c
72
ui/window.c
|
@ -65,13 +65,12 @@ static UI_EVENT * EventBuffer = NULL;
|
|||
static int Record = 0;
|
||||
static int RecordFlags = 0;
|
||||
|
||||
static short MouseDX=0, MouseDY=0, MouseButtons=0;
|
||||
|
||||
static unsigned char SavedState[256];
|
||||
|
||||
static int PlaybackSpeed = 1;
|
||||
|
||||
extern void ui_draw_frame( short x1, short y1, short x2, short y2 );
|
||||
extern void save_screen_shot(int automap_flag); // avoids conflict with FrameCount when including game.h
|
||||
|
||||
// 1=1x faster, 2=2x faster, etc
|
||||
void ui_set_playback_speed( int speed )
|
||||
|
@ -336,6 +335,7 @@ int ui_get_idle_seconds()
|
|||
return (timer_query() - last_event)/F1_0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void ui_mega_process()
|
||||
{
|
||||
int mx, my, mz;
|
||||
|
@ -586,6 +586,74 @@ void ui_mega_process()
|
|||
ui_mouse_process();
|
||||
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
// Base level event handler
|
||||
// Mainly for setting global variables for state-based event polling,
|
||||
// which will eventually be replaced with direct event handling
|
||||
// so we could then stick with standard_handler in inferno.c
|
||||
int ui_event_handler(d_event *event)
|
||||
{
|
||||
timer_update();
|
||||
last_keypress = 0;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case EVENT_MOUSE_BUTTON_DOWN:
|
||||
case EVENT_MOUSE_BUTTON_UP:
|
||||
ui_mouse_button_process(event);
|
||||
last_event = timer_query();
|
||||
break;
|
||||
|
||||
case EVENT_MOUSE_MOVED:
|
||||
ui_mouse_motion_process(event);
|
||||
last_event = timer_query();
|
||||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
last_keypress = event_key_get(event);
|
||||
last_event = timer_query();
|
||||
|
||||
switch (last_keypress)
|
||||
{
|
||||
#ifdef macintosh
|
||||
case KEY_COMMAND + KEY_SHIFTED + KEY_3:
|
||||
#endif
|
||||
case KEY_PRINT_SCREEN:
|
||||
{
|
||||
gr_set_current_canvas(NULL);
|
||||
save_screen_shot(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
case KEY_ALTED+KEY_ENTER:
|
||||
case KEY_ALTED+KEY_PADENTER:
|
||||
gr_toggle_fullscreen();
|
||||
return 1;
|
||||
|
||||
#ifndef NDEBUG
|
||||
case KEY_BACKSP:
|
||||
Int3();
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_IDLE:
|
||||
// Make sure button pressing works correctly
|
||||
// Won't be needed when all of the editor uses mouse button events rather than polling
|
||||
return ui_mouse_button_process(event);
|
||||
|
||||
case EVENT_QUIT:
|
||||
//Quitting = 1;
|
||||
return 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ui_wprintf( UI_WINDOW * wnd, char * format, ... )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue