Switch d_event subclasses to C++ inheritance

This commit is contained in:
Kp 2014-10-04 18:05:26 +00:00
parent 3714c0c645
commit 8750b6a4ad
4 changed files with 21 additions and 26 deletions

View file

@ -32,15 +32,13 @@ static struct joyinfo {
ubyte button_last_state[JOY_MAX_BUTTONS]; // for HAT movement only
} Joystick;
struct d_event_joystickbutton
struct d_event_joystickbutton : d_event
{
event_type type;
int button;
};
struct d_event_joystick_moved
struct d_event_joystick_moved : d_event
{
event_type type; // EVENT_JOYSTICK_MOVED
int axis;
int value;
};
@ -70,7 +68,7 @@ void joy_button_handler(SDL_JoyButtonEvent *jbe)
event.type = (jbe->type == SDL_JOYBUTTONDOWN) ? EVENT_JOYSTICK_BUTTON_DOWN : EVENT_JOYSTICK_BUTTON_UP;
event.button = button;
con_printf(CON_DEBUG, "Sending event %s, button %d", (jbe->type == SDL_JOYBUTTONDOWN) ? "EVENT_JOYSTICK_BUTTON_DOWN" : "EVENT_JOYSTICK_JOYSTICK_UP", event.button);
event_send((d_event *)&event);
event_send(&event);
}
void joy_hat_handler(SDL_JoyHatEvent *jhe)
@ -98,14 +96,14 @@ void joy_hat_handler(SDL_JoyHatEvent *jhe)
event.type = EVENT_JOYSTICK_BUTTON_DOWN;
event.button = hat+hbi;
con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_BUTTON_DOWN, button %d", event.button);
event_send((d_event *)&event);
event_send(&event);
}
else if(Joystick.button_last_state[hat+hbi] && !Joystick.button_state[hat+hbi]) //last_state down, current state up
{
event.type = EVENT_JOYSTICK_BUTTON_UP;
event.button = hat+hbi;
con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_BUTTON_UP, button %d", event.button);
event_send((d_event *)&event);
event_send(&event);
}
}
}
@ -125,7 +123,7 @@ int joy_axis_handler(SDL_JoyAxisEvent *jae)
event.axis = axis;
event.value = Joystick.axis_value[axis] = jae->value/256;
con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_MOVED, axis: %d, value: %d",event.axis, event.value);
event_send((d_event *)&event);
event_send(&event);
return 1;
}

View file

@ -35,9 +35,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
UI_GADGET * selected_gadget;
struct event_gadget
struct event_gadget : d_event
{
event_type type;
UI_GADGET *gadget;
};
@ -214,9 +213,9 @@ window_event_result ui_gadget_send_event(UI_DIALOG *dlg, event_type type, UI_GAD
event.gadget = gadget;
if (gadget->parent)
return ui_gadget_do(dlg, gadget->parent, (d_event *) &event);
return ui_gadget_do(dlg, gadget->parent, &event);
return window_send_event(ui_dialog_get_window(dlg), (d_event *) &event);
return window_send_event(ui_dialog_get_window(dlg), &event);
}
UI_GADGET *ui_event_get_gadget(d_event *event)

View file

@ -304,9 +304,8 @@ const array<key_props, 256> key_properties = {{
{ "W95", 255, SDLK_WORLD_95 }, // 255
}};
struct d_event_keycommand
struct d_event_keycommand : d_event
{
event_type type; // EVENT_KEY_COMMAND/RELEASE
int keycode;
};
@ -432,7 +431,7 @@ void key_handler(SDL_KeyboardEvent *kevent)
(keycode & KEY_SHIFTED) ? "SHIFT" : "",
key_properties[keycode & 0xff].key_text
);
event_send((d_event *)&event);
event_send(&event);
}
}

View file

@ -31,15 +31,13 @@ static struct mouseinfo {
fix64 cursor_time;
} Mouse;
struct d_event_mousebutton
struct d_event_mousebutton : d_event
{
event_type type;
int button;
};
struct d_event_mouse_moved
struct d_event_mouse_moved : d_event
{
event_type type; // EVENT_MOUSE_MOVED
short dx, dy, dz;
};
@ -57,7 +55,7 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
{
// to bad, SDL buttons use a different mapping as descent expects,
// this is at least true and tested for the first three buttons
int button_remap[17] = {
static const array<int, 17> button_remap{{
MBTN_LEFT,
MBTN_MIDDLE,
MBTN_RIGHT,
@ -75,7 +73,7 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
MBTN_14,
MBTN_15,
MBTN_16
};
}};
int button = button_remap[mbe->button - 1]; // -1 since SDL seems to start counting at 1
d_event_mousebutton event;
@ -86,7 +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 };
d_event_mouse_moved event2{};
event2.type = EVENT_MOUSE_MOVED;
Mouse.button_state[button] = 1;
@ -104,7 +103,7 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
{
//con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_MOVED, relative motion %d,%d,%d",
// event2.dx, event2.dy, event2.dz);
event_send((d_event *)&event2);
event_send(&event2);
}
} else {
Mouse.button_state[button] = 0;
@ -115,7 +114,7 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
con_printf(CON_DEBUG, "Sending event %s, button %d, coords %d,%d,%d",
(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);
event_send(&event);
//Double-click support
if (Mouse.button_state[button])
@ -126,7 +125,7 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe)
//event.button = button; // already set the button
con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_DOUBLE_CLICKED, button %d, coords %d,%d",
event.button, Mouse.x, Mouse.y);
event_send((d_event *)&event);
event_send(&event);
}
Mouse.time_lastpressed[button] = Mouse.cursor_time;
@ -154,7 +153,7 @@ void mouse_motion_handler(SDL_MouseMotionEvent *mme)
//con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_MOVED, relative motion %d,%d,%d",
// event.dx, event.dy, event.dz);
event_send((d_event *)&event);
event_send(&event);
}
void mouse_flush() // clears all mice events...