1 /*
2 * sprite_switch.c: �����å����ץ饤����ͭ�ν���
3 *
4 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
5 * 1998- <masaki-c@is.aist-nara.ac.jp>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 /* $Id: sprite_switch.c,v 1.1 2003/04/22 16:29:52 chikama Exp $ */
23
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <glib.h>
28
29 #include "portab.h"
30 #include "ags.h"
31 #include "sact.h"
32 #include "sactsound.h"
33 #include "sprite.h"
34
35 static int eventCB_switch(sprite_t *sp, agsevent_t *e);
36 static void cb_remove(sprite_t *sp);
37
38
39 // �����å����ץ饤�ȤΥ��٥�Ƚ���
eventCB_switch(sprite_t * sp,agsevent_t * e)40 static int eventCB_switch(sprite_t *sp, agsevent_t *e) {
41 int update = 0;
42
43 switch(e->type) {
44 case AGSEVENT_BUTTON_PRESS:
45 if (e->d3 != AGSEVENT_BUTTON_LEFT) return 0;
46
47 // �ܥ������Υ��ץ饤�Ȥ�����С������ɽ��
48 if (sp->cg3) {
49 sp->curcg = sp->cg3;
50 update++;
51 }
52
53 sp->pressed = TRUE;
54 break;
55
56 case AGSEVENT_BUTTON_RELEASE:
57 if (e->d3 != AGSEVENT_BUTTON_LEFT) return 0;
58
59 // �����ˤ���Ȥ��� forcus�������äƤ���Ȥ��������ʤ��Τǡ�
60 // curcg �� cg2 ���᤻�Ф褤
61 if (sp->cg2) {
62 sp->curcg = sp->cg2;
63 update++;
64 }
65
66 // press���줿���ץ饤�Ȥ�release���줿���ץ饤�Ȥ�Ʊ�����
67 // �ˤΤߡ����Υ��ץ饤�Ȥ������줿��Ƚ��
68 if (sp->pressed) {
69 sact.sp_result_sw = sp->no;
70 sact.waitkey = sp->no;
71 if (sp->numsound2) {
72 ssnd_play(sp->numsound2);
73 }
74 }
75 sp->pressed = FALSE;
76 break;
77 }
78
79 if (update) {
80 sp_updateme(sp);
81 }
82
83 return update;
84 }
85
86 // ���ץ饤�Ⱥ�����ν���
cb_remove(sprite_t * sp)87 static void cb_remove(sprite_t *sp) {
88 // event listener ��
89 spev_remove_eventlistener(sp);
90 }
91
92
93 /*
94 sp_new �λ��˥��ץ饤�Ȥμ�����ν����
95 @param sp: ��������륹�ץ饤��
96 */
sp_sw_setup(sprite_t * sp)97 int sp_sw_setup(sprite_t *sp) {
98 spev_add_eventlistener(sp, eventCB_switch);
99 sp->remove = cb_remove;
100 return OK;
101 }
102