1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
|
/*
* sprite_event.c: SACT mouse/key ٥ȤΥϥɥ
*
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: sprite_event.c,v 1.5 2003/11/09 15:06:13 chikama Exp $ */
#include "config.h"
#include <stdio.h>
#include <glib.h>
#include "portab.h"
#include "system.h"
#include "counter.h"
#include "menu.h"
#include "imput.h"
#include "nact.h"
#include "key.h"
#include "sact.h"
#include "sprite.h"
#include "sactsound.h"
#include "sactlog.h"
/*
SACTSpriteKeyԤåKeyԤʤɤ¸뤿ᡢX|SDL
Key/Mouse ٥ȤäȤˡnact->ags.eventcb()ˤä¾Υ⥸塼
˥٥ȤФǤ褦ˤ
SACTǤϺǽ spev_callback ǥ٥Ȥ褦ˤߤΥԤ
(sact.waittype)ˤäƤ줾Υ٥ȥϥɥƤӽФƤ롣
ߤΤȤ1) åԤ2) ñ㥭Ԥ3) ˥塼Ԥ
4) ץ饤ȥ 5) ХåԤΣĤ롣
1)åԤ
ޤԤġZץ饤ȤξõǤ롣
2)ñ㥭Ԥ
1)Ʊ
3)˥塼Ԥ
˥塼ץνޥưȡ(orܥ)Υ줿Ȥ
ĤνԤ
4)ץ饤Ԥ
SW/GETA/GETB/PUT/SWPUTץ饤ȤγƽԤ
ץ饤ȤֹξΤ˾˽ŤͤɽˤʤäƤ
ץ饤Ȥ˥٥Ȥʤ褦ˤ
-> SpriteKeyԤľ˥ץ饤Ȥֹˤ depth map
ޥΰ֤ˤ륹ץ饤ȤֹǼФ
AlphaޥĤSpriteξ硢ȿǤɽƤΤߤ
depthmapȿǡ
dragΥץ饤ȤϾ˺Ǿ̤ˤ褦ɽޥưΥ٥
Ϻǽ˽롣
5)ХåɽΥԤ
ꥸʥƱΤϤ
*/
static void cb_focused_swsp(gpointer s, gpointer data);
static void cb_defocused_swsp(gpointer s, gpointer data);
static int cb_focused(sprite_t *sp);
static int cb_defocused(sprite_t *sp);
static void cb_waitkey_simple(agsevent_t *e);
static void cb_waitkey_sprite(agsevent_t *e);
static void cb_waitkey_selection(agsevent_t *e);
/*
եץ饤Ȥץ饤ȤϿƤ
ץ饤ȤɽON
*/
static void cb_focused_swsp(gpointer s, gpointer data) {
sprite_t *sp = (sprite_t *)s;
int *update = (int *)data;
boolean oldstate = sp->show;
WARNING("show up spex %d\n", sp->no);
sp->show = TRUE;
if (oldstate != sp->show) {
(*update)++;
sp_updateme(sp);
}
}
/*
եץ饤Ȥץ饤ȤϿƤ
ץ饤ȤɽOFF
*/
static void cb_defocused_swsp(gpointer s, gpointer data) {
sprite_t *sp = (sprite_t *)s;
int *update = (int *)data;
boolean oldstate = sp->show;
WARNING("hide spex %d\n", sp->no);
sp->show = FALSE;
if (oldstate != sp->show) {
(*update)++;
sp_updateme(sp);
}
}
// zkey hide off
static void cb_focused_zkey(gpointer s, gpointer data) {
sprite_t *sp = (sprite_t *)s;
int *update = (int *)data;
boolean oldstate = sp->show;
sp->show = sp->show_save;
if (oldstate != sp->show) {
(*update)++;
sp_updateme(sp);
}
}
// zkey hide on
static void cb_defocused_zkey(gpointer s, gpointer data) {
sprite_t *sp = (sprite_t *)s;
int *update = (int *)data;
boolean oldstate = sp->show;
sp->show = FALSE;
if (oldstate != sp->show) {
(*update)++;
sp_updateme(sp);
sp->show_save = oldstate;
}
}
/*
եץ饤Ȥν
cg2curcgcg2
dragΥץ饤Ȥ
-> PUT/SWPUTץ饤ȤΤȿ
dragΥץ饤Ȥʤ
-> GETA/GETB/SWPUTץ饤ȤΤȿ
*/
static int cb_focused(sprite_t *sp) {
int update = 0;
if (sact.draggedsp) {
if (sp->type != SPRITE_PUT &&
sp->type != SPRITE_SWPUT) return 0;
} else {
if (sp->type == SPRITE_PUT) return 0;
}
if (!sp->focused) {
if (sp->cg2) {
if (sp->curcg != sp->cg2) {
sp_updateme(sp);
}
sp->curcg = sp->cg2;
update++;
}
sp->focused = TRUE;
WARNING("get forcused %d, type %d\n", sp->no, sp->type);
if (sp->numsound1) {
ssnd_play(sp->numsound1);
}
}
return update;
}
/*
եäץ饤Ȥν
curcg cg1 ˥å
*/
static int cb_defocused(sprite_t *sp) {
int update = 0;
if (sp->focused) {
if (sp->curcg != sp->cg1) {
sp_updateme(sp);
}
sp->curcg = sp->cg1;
update++;
sp->focused = FALSE;
WARNING("lost forcused %d\n", sp->no);
}
return update;
}
/*
WaitKeySimplecallback
*/
static void cb_waitkey_simple(agsevent_t *e) {
int cur, update = 0;
switch (e->type) {
case AGSEVENT_KEY_PRESS:
if (e->d3 == KEY_Z) {
cur = get_high_counter(SYSTEMCOUNTER_MSEC);
if (!sact.zhiding) {
g_slist_foreach(sact.sp_zhide, cb_defocused_zkey, &update);
sact.zhiding = TRUE;
sact.zdooff = TRUE;
sact.zofftime = cur;
} else {
sact.zdooff = FALSE;
}
}
break;
case AGSEVENT_BUTTON_RELEASE:
// back log view mode ˰ܹ
if (e->d3 == AGSEVENT_WHEEL_UP ||
e->d3 == AGSEVENT_WHEEL_DN) {
// MessageKey ԤΤȤΤ
if (sact.waittype != KEYWAIT_MESSAGE) break;
sblog_start();
sact.waittype = KEYWAIT_BACKLOG;
break;
}
if (sact.zhiding) {
g_slist_foreach(sact.sp_zhide, cb_focused_zkey, &update);
sact.zhiding = FALSE;
}
// fall through
case AGSEVENT_KEY_RELEASE:
switch(e->d3) {
case KEY_Z:
cur = get_high_counter(SYSTEMCOUNTER_MSEC);
if (500 < (cur - sact.zofftime) || !sact.zdooff) {
g_slist_foreach(sact.sp_zhide, cb_focused_zkey, &update);
sact.zhiding = FALSE;
}
break;
case KEY_PAGEUP:
case KEY_PAGEDOWN:
// MessageKey ԤΤȤΤ
if (sact.waittype != KEYWAIT_MESSAGE) break;
sblog_start();
sact.waittype = KEYWAIT_BACKLOG;
break;
default:
sact.waitkey = e->d3;
break;
}
}
if (update) {
sp_update_clipped();
}
}
/*
WaitKeySpritecallback
*/
static void cb_waitkey_sprite(agsevent_t *e) {
GSList *node;
sprite_t *focused_sp = NULL; // focus Ƥ sprite
sprite_t *defocused_sp = NULL; // focus ä sprite
int update = 0;
// ٥Ȥ̵
switch(e->type) {
case AGSEVENT_KEY_RELEASE:
case AGSEVENT_KEY_PRESS:
return;
}
if (sact.draggedsp) {
// dragsprite˥٥Ȥ
update = sact.draggedsp->eventcb(sact.draggedsp, e);
} else {
// å
// dragǤʤΤߡդ
if (e->type == AGSEVENT_BUTTON_RELEASE &&
e->d3 == AGSEVENT_BUTTON_RIGHT) {
sact.waitkey = 0;
return;
}
}
// forcusƤ sprite focusä sprite õ
for (node = sact.eventlisteners; node; node = node->next) {
sprite_t *sp = (sprite_t *)node->data;
if (sp == NULL) continue;
if (!sp->show) continue;
// freeze֤ǤCGѲʤ
if (sp->freezed_state != 0) continue;
// dragg sprite ̵뤹
if (sp == sact.draggedsp) continue;
if (focused_sp == NULL && sp_is_insprite(sp, e->d1, e->d2)) {
/*
focusƤ sprite
*/
update += cb_focused(sp);
focused_sp = sp;
} else {
/*
ߤΥ֤ˤϤƤֹsprite
¸ߤʤΤǡdefocus νԤ
Υޥư٥ȤˤfocusäΤ
Сcb_decocused(sp) 1 ֤
*/
int ret = cb_defocused(sp);
if (ret > 0) defocused_sp = sp;
update += ret;
}
}
// focus sprite BUTTON٥ȤΤߤ
if (focused_sp && e->type != AGSEVENT_MOUSE_MOTION) {
update += focused_sp->eventcb(focused_sp, e);
}
// ϰϳ(focusƤspriteʤ)åȤβ
if (!focused_sp &&
e->type != AGSEVENT_MOUSE_MOTION &&
sact.numsoundob) {
ssnd_play(sact.numsoundob);
}
// dragǤʤϡץ饤ȤɽõԤ
if (sact.draggedsp == NULL && e->type == AGSEVENT_MOUSE_MOTION) {
// focus ä sprite sprite ξõ
if (defocused_sp) {
sprite_t *sp = defocused_sp;
if (sp->expsp) {
g_slist_foreach(sp->expsp, cb_defocused_swsp, &update);
}
}
// focus sprite sprite ɽ
if (focused_sp) {
sprite_t *sp = focused_sp;
if (sp->expsp) {
g_slist_foreach(sp->expsp, cb_focused_swsp, &update);
}
}
}
// ɽ֤ѹФΰ
if (update) {
sp_update_clipped();
}
}
/*
Window Open callback
*/
static void cb_waitkey_selection(agsevent_t *e) {
switch (e->type) {
case AGSEVENT_BUTTON_RELEASE:
sact.sel.cbrelease(e);
break;
case AGSEVENT_MOUSE_MOTION:
sact.sel.cbmove(e);
break;
}
}
/*
ХåȻ
*/
static void cb_waitkey_backlog(agsevent_t *e) {
switch (e->type) {
case AGSEVENT_KEY_RELEASE:
switch (e->d3) {
case KEY_ESC:
sblog_end();
sact.waittype = KEYWAIT_MESSAGE;
break;
case KEY_PAGEUP:
sblog_pageup();
break;
case KEY_PAGEDOWN:
sblog_pagedown();
break;
case KEY_UP:
sblog_pagenext();
break;
case KEY_DOWN:
sblog_pagepre();
break;
}
break;
case AGSEVENT_BUTTON_RELEASE:
switch(e->d3) {
case AGSEVENT_WHEEL_UP:
sblog_pagenext();
break;
case AGSEVENT_WHEEL_DN:
sblog_pagepre();
break;
case AGSEVENT_BUTTON_RIGHT:
sblog_end();
sact.waittype = KEYWAIT_MESSAGE;
break;
}
break;
}
}
/*
X|SDL Υ٥ȥǥѥå㤫餯ǽξ
*/
void spev_callback(agsevent_t *e) {
// menu open̵
if (nact->popupmenu_opened) {
return;
}
if (sact.waittype != KEYWAIT_BACKLOG) {
if (e->type == AGSEVENT_KEY_PRESS && e->d3 == KEY_CTRL) {
sact.waitskiplv = 2;
sact.waitkey = e->d3;
return;
}
if (e->type == AGSEVENT_KEY_RELEASE && e->d3 == KEY_CTRL) {
sact.waitskiplv = 0;
sact.waitkey = e->d3;
return;
}
}
switch (sact.waittype) {
case KEYWAIT_MESSAGE:
case KEYWAIT_SIMPLE:
cb_waitkey_simple(e);
break;
case KEYWAIT_SPRITE:
cb_waitkey_sprite(e);
break;
case KEYWAIT_SELECT:
cb_waitkey_selection(e);
break;
case KEYWAIT_BACKLOG:
cb_waitkey_backlog(e);
break;
default:
return;
}
}
/*
ƥץ饤Υ٥ callback Ͽ
*/
void spev_add_eventlistener(sprite_t *sp, int (*cb)(sprite_t *, agsevent_t *)) {
sp->eventcb = cb;
sact.eventlisteners = g_slist_append(sact.eventlisteners, sp);
}
/*
Ͽ callback κ
*/
void spev_remove_eventlistener(sprite_t *sp) {
sact.eventlisteners = g_slist_remove(sact.eventlisteners, sp);
}
|