diff --git a/modules/NIGHTDLL/nt_event.c b/modules/NIGHTDLL/nt_event.c index 5583038..200d5c3 100644 --- a/modules/NIGHTDLL/nt_event.c +++ b/modules/NIGHTDLL/nt_event.c @@ -33,7 +33,7 @@ static void cb_waitkey_simple(agsevent_t *e) { switch (e->type) { case AGSEVENT_BUTTON_RELEASE: case AGSEVENT_KEY_RELEASE: - night.waitkey = e->d3; + night.waitkey = e->code; break; } } @@ -59,15 +59,15 @@ void ntev_callback(agsevent_t *e) { return; } - if (e->type == AGSEVENT_KEY_PRESS && e->d3 == KEY_CTRL) { + if (e->type == AGSEVENT_KEY_PRESS && e->code == KEY_CTRL) { night.waitskiplv = 2; - night.waitkey = e->d3; + night.waitkey = e->code; return; } - if (e->type == AGSEVENT_KEY_RELEASE && e->d3 == KEY_CTRL) { + if (e->type == AGSEVENT_KEY_RELEASE && e->code == KEY_CTRL) { night.waitskiplv = 0; - night.waitkey = e->d3; + night.waitkey = e->code; return; } diff --git a/modules/NIGHTDLL/nt_msg.c b/modules/NIGHTDLL/nt_msg.c index bb2b544..d0d072b 100644 --- a/modules/NIGHTDLL/nt_msg.c +++ b/modules/NIGHTDLL/nt_msg.c @@ -392,13 +392,11 @@ static void is_in_icon() { static void cb_keyrelease(agsevent_t *e) { - int x = e->d1, y = e->d2; - - switch (e->d3) { + switch (e->code) { case AGSEVENT_BUTTON_LEFT: #if 0 if (is_in_icon()) { - do_icon(x, y); + do_icon(e->mousex, e->mousey); break; } #endif @@ -408,19 +406,15 @@ static void cb_keyrelease(agsevent_t *e) { // unhide(); break; } - night.waitkey = e->d3; + night.waitkey = e->code; break; } } static void cb_mousemove(agsevent_t *e) { - int x = e->d1, y = e->d2; - // 音声mute/メッセージスキップ/メッセージ枠消去の領域に // マウスが移動したら、その部分のアイコンを変化させる - - } // メッセージ表示時に、キー入力を促すアニメーションの設定 diff --git a/modules/SACT/sprite_event.c b/modules/SACT/sprite_event.c index f2a4d61..2293773 100644 --- a/modules/SACT/sprite_event.c +++ b/modules/SACT/sprite_event.c @@ -213,7 +213,7 @@ static void cb_waitkey_simple(agsevent_t *e) { switch (e->type) { case AGSEVENT_KEY_PRESS: - if (e->d3 == KEY_Z) { + if (e->code == KEY_Z) { cur = sdl_getTicks(); if (!sact.zhiding) { slist_foreach(sact.sp_zhide, cb_defocused_zkey, &update); @@ -242,7 +242,7 @@ static void cb_waitkey_simple(agsevent_t *e) { // fall through case AGSEVENT_KEY_RELEASE: - switch(e->d3) { + switch(e->code) { case KEY_Z: cur = sdl_getTicks(); if (500 < (cur - sact.zofftime) || !sact.zdooff) { @@ -258,7 +258,7 @@ static void cb_waitkey_simple(agsevent_t *e) { sact.waittype = KEYWAIT_BACKLOG; break; default: - sact.waitkey = e->d3; + sact.waitkey = e->code; break; } } @@ -292,7 +292,7 @@ void cb_waitkey_sprite(agsevent_t *e) { // 右クリックキャンセル // drag中でない時のみ、キャンセルを受け付ける if (e->type == AGSEVENT_BUTTON_RELEASE && - e->d3 == AGSEVENT_BUTTON_RIGHT) { + e->code == AGSEVENT_BUTTON_RIGHT) { sact.waitkey = 0; return; } @@ -311,7 +311,7 @@ void cb_waitkey_sprite(agsevent_t *e) { // dragg中の sprite は無視する if (sp == sact.draggedsp) continue; - if (focused_sp == NULL && sp_is_insprite(sp, e->d1, e->d2)) { + if (focused_sp == NULL && sp_is_insprite(sp, e->mousex, e->mousey)) { /* focusを得ている sprite */ @@ -388,7 +388,7 @@ static void cb_waitkey_selection(agsevent_t *e) { static void cb_waitkey_backlog(agsevent_t *e) { switch (e->type) { case AGSEVENT_KEY_RELEASE: - switch (e->d3) { + switch (e->code) { case KEY_ESC: sblog_end(); sact.waittype = KEYWAIT_MESSAGE; @@ -409,14 +409,14 @@ static void cb_waitkey_backlog(agsevent_t *e) { break; case AGSEVENT_BUTTON_RELEASE: - if (e->d3 == AGSEVENT_BUTTON_RIGHT) { + if (e->code == AGSEVENT_BUTTON_RIGHT) { sblog_end(); sact.waittype = KEYWAIT_MESSAGE; } break; case AGSEVENT_MOUSE_WHEEL: - if (e->d3 > 0) + if (e->code > 0) sblog_pagenext(); else sblog_pagepre(); @@ -434,15 +434,15 @@ void spev_callback(agsevent_t *e) { } if (sact.waittype != KEYWAIT_BACKLOG) { - if (e->type == AGSEVENT_KEY_PRESS && e->d3 == KEY_CTRL) { + if (e->type == AGSEVENT_KEY_PRESS && e->code == KEY_CTRL) { sact.waitskiplv = 2; - sact.waitkey = e->d3; + sact.waitkey = e->code; return; } - if (e->type == AGSEVENT_KEY_RELEASE && e->d3 == KEY_CTRL) { + if (e->type == AGSEVENT_KEY_RELEASE && e->code == KEY_CTRL) { sact.waitskiplv = 0; - sact.waitkey = e->d3; + sact.waitkey = e->code; return; } } diff --git a/modules/SACT/sprite_get.c b/modules/SACT/sprite_get.c index 586a9af..c8483c3 100644 --- a/modules/SACT/sprite_get.c +++ b/modules/SACT/sprite_get.c @@ -58,12 +58,12 @@ static int eventCB_GET(sprite_t *sp, agsevent_t *e) { switch(e->type) { case AGSEVENT_BUTTON_PRESS: - if (e->d3 != AGSEVENT_BUTTON_LEFT) break; + if (e->code != AGSEVENT_BUTTON_LEFT) break; // drag開始時のマウスの位置記録 sp->u.get.dragging = TRUE; - sp->u.get.dragstart.x = e->d1; - sp->u.get.dragstart.y = e->d2; + sp->u.get.dragstart.x = e->mousex; + sp->u.get.dragstart.y = e->mousey; if (sp->cg3) { sp->curcg = sp->cg3; @@ -104,8 +104,8 @@ static int eventCB_GET(sprite_t *sp, agsevent_t *e) { // if (!sp->u.get.dragging) break; // マウスの現在位置により新しい場所を計算 - newx = sp->loc.x + (e->d1 - sp->u.get.dragstart.x); - newy = sp->loc.y + (e->d2 - sp->u.get.dragstart.y); + newx = sp->loc.x + (e->mousex - sp->u.get.dragstart.x); + newy = sp->loc.y + (e->mousey - sp->u.get.dragstart.y); if (newx != sp->cur.x || newy != sp->cur.y) { sp_updateme(sp); sp->cur.x = newx; diff --git a/modules/SACT/sprite_keywait.c b/modules/SACT/sprite_keywait.c index 529efcd..aa138e1 100644 --- a/modules/SACT/sprite_keywait.c +++ b/modules/SACT/sprite_keywait.c @@ -135,13 +135,13 @@ int sp_keywait(int *vOK, int *vRND, int *vD01, int *vD02, int *vD03, int timeout { // とりあえず、現在のマウス位置を送って、switch sprite の // 状態を更新しておく - agsevent_t agse; MyPoint p; sys_getMouseInfo(&p, FALSE); - agse.type = AGSEVENT_MOUSE_MOTION; - agse.d1 = p.x; - agse.d2 = p.y; - agse.d3 = 0; + agsevent_t agse = { + .type = AGSEVENT_MOUSE_MOTION, + .mousex = p.x, + .mousey = p.y + }; spev_callback(&agse); } diff --git a/modules/SACT/sprite_put.c b/modules/SACT/sprite_put.c index bfc528e..a72992e 100644 --- a/modules/SACT/sprite_put.c +++ b/modules/SACT/sprite_put.c @@ -40,7 +40,7 @@ static int eventCB_PUT(sprite_t *sp, agsevent_t *e) { switch(e->type) { case AGSEVENT_BUTTON_PRESS: - if (e->d3 != AGSEVENT_BUTTON_LEFT) return 0; + if (e->code != AGSEVENT_BUTTON_LEFT) return 0; // ボタン押下時のスプライトがあれば、それを表示 if (sp->cg3) { diff --git a/modules/SACT/sprite_sel.c b/modules/SACT/sprite_sel.c index e501c3b..01c0143 100644 --- a/modules/SACT/sprite_sel.c +++ b/modules/SACT/sprite_sel.c @@ -77,7 +77,7 @@ static boolean sp_is_insprite2(sprite_t *sp, int x, int y, int margin) { // マウスが移動したときの callback static void cb_select_move(agsevent_t *e) { - int x = e->d1, y = e->d2; + int x = e->mousex, y = e->mousey; sprite_t *sp = sact.sp[sact.sel.spno]; boolean newstate; int newindex; @@ -115,12 +115,12 @@ static void cb_select_move(agsevent_t *e) { // ボタンがリリースされたときの callback static void cb_select_release(agsevent_t *e) { - int x = e->d1, y = e->d2; + int x = e->mousex, y = e->mousey; sprite_t *sp = sact.sp[sact.sel.spno]; boolean st; int iy; - switch (e->d3) { + switch (e->code) { case AGSEVENT_BUTTON_LEFT: st = sp_is_insprite2(sp, x, y, sact.sel.frame_dot); iy = (y - (sp->cur.y + sact.sel.frame_dot)) / (sact.sel.font_size + sact.sel.linespace); diff --git a/modules/SACT/sprite_switch.c b/modules/SACT/sprite_switch.c index 4480086..3fbf59b 100644 --- a/modules/SACT/sprite_switch.c +++ b/modules/SACT/sprite_switch.c @@ -41,7 +41,7 @@ static int eventCB_switch(sprite_t *sp, agsevent_t *e) { switch(e->type) { case AGSEVENT_BUTTON_PRESS: - if (e->d3 != AGSEVENT_BUTTON_LEFT) return 0; + if (e->code != AGSEVENT_BUTTON_LEFT) return 0; // ボタン押下時のスプライトがあれば、それを表示 if (sp->cg3) { @@ -53,7 +53,7 @@ static int eventCB_switch(sprite_t *sp, agsevent_t *e) { break; case AGSEVENT_BUTTON_RELEASE: - if (e->d3 != AGSEVENT_BUTTON_LEFT) return 0; + if (e->code != AGSEVENT_BUTTON_LEFT) return 0; // ここにくるときは forcusが当たっているときしかこないので、 // curcg は cg2 に戻せばよい diff --git a/src/ags.h b/src/ags.h index 449ac28..d6ded07 100644 --- a/src/ags.h +++ b/src/ags.h @@ -78,24 +78,27 @@ typedef struct agsurface agsurface_t; // for SDL_surface #define PIXEL_AT(suf, x, y) ((suf)->pixels + (y) * (suf)->pitch + (x) * (suf)->format->BytesPerPixel) -struct _agsevent { +typedef struct { int type; - int d1, d2, d3; + int code; + int mousex, mousey; +} agsevent_t; + +enum agsevent_type { + AGSEVENT_MOUSE_MOTION, + AGSEVENT_BUTTON_PRESS, + AGSEVENT_BUTTON_RELEASE, + AGSEVENT_KEY_PRESS, + AGSEVENT_KEY_RELEASE, + AGSEVENT_TIMER, + AGSEVENT_MOUSE_WHEEL, }; -typedef struct _agsevent agsevent_t; - -#define AGSEVENT_MOUSE_MOTION 1 -#define AGSEVENT_BUTTON_PRESS 2 -#define AGSEVENT_BUTTON_RELEASE 3 -#define AGSEVENT_KEY_PRESS 4 -#define AGSEVENT_KEY_RELEASE 5 -#define AGSEVENT_TIMER 6 -#define AGSEVENT_MOUSE_WHEEL 7 - -#define AGSEVENT_BUTTON_LEFT 1 -#define AGSEVENT_BUTTON_MID 2 -#define AGSEVENT_BUTTON_RIGHT 3 +enum agsevent_button { + AGSEVENT_BUTTON_LEFT, + AGSEVENT_BUTTON_MID, + AGSEVENT_BUTTON_RIGHT, +}; enum mouse_warp_mode { MOUSE_WARP_DISABLED, diff --git a/src/sdl_event.c b/src/sdl_event.c index e72442a..c92c456 100644 --- a/src/sdl_event.c +++ b/src/sdl_event.c @@ -89,20 +89,16 @@ static int mouse_to_agsevent(int button) { } EMSCRIPTEN_KEEPALIVE -void send_agsevent(int type, int code) { +void send_agsevent(enum agsevent_type type, int code) { if (!nact->ags.eventcb) return; - agsevent_t agse; - agse.type = type; - agse.d1 = mousex; - agse.d2 = mousey; - agse.d3 = code; + agsevent_t agse = { + .type = type, + .code = code, + .mousex = mousex, + .mousey = mousey + }; nact->ags.eventcb(&agse); // Async in emscripten - -#ifdef __EMSCRIPTEN__ - // HACK: this ensures that callers of this function are instrumented. - emscripten_sleep(0); -#endif } // Improves map navigation of Rance4 v2. See also the function comment of