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
|
/*
* sprite_get.c: åA/Bץ饤ͭν
*
* 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_get.c,v 1.1 2003/04/22 16:29:52 chikama Exp $ */
#include "config.h"
#include <stdio.h>
#include <glib.h>
#include "portab.h"
#include "ags.h"
#include "sact.h"
#include "sprite.h"
#include "sactsound.h"
static void cb_defocused_swsp(gpointer s, gpointer data);
static int eventCB_GET(sprite_t *sp, agsevent_t *e);
static void cb_remove(sprite_t *sp);
/*
ץ饤Ȥξõ
dragϤޤäץ饤ȤϾõ
*/
static void cb_defocused_swsp(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);
}
}
//åȥץ饤ȤΥ٥Ƚ
static int eventCB_GET(sprite_t *sp, agsevent_t *e) {
int update = 0;
switch(e->type) {
case AGSEVENT_BUTTON_PRESS:
if (e->d3 != AGSEVENT_BUTTON_LEFT) break;
// dragϻΥޥΰֵϿ
sp->u.get.dragging = TRUE;
sp->u.get.dragstart.x = e->d1;
sp->u.get.dragstart.y = e->d2;
if (sp->cg3) {
sp->curcg = sp->cg3;
update++;
sp_updateme(sp);
}
// ץ饤Ȥɽ˻ä
sact.draggedsp = sp;
sact.dropped = FALSE;
// ץ饤Ȥϡɽˤ
if (sp->expsp) {
g_slist_foreach(sp->expsp, cb_defocused_swsp, &update);
}
// SpriteSoundСĤ餹
if (sp->numsound2) {
ssnd_play(sp->numsound2);
}
break;
case AGSEVENT_BUTTON_RELEASE:
// ɤΥܥǤɥå|λ
if (!sp->u.get.dragging) break;
sact.dropped = TRUE;
break;
case AGSEVENT_MOUSE_MOTION:
{
int newx, newy;
// MOUSE MOTION draggˤƤФʤ
//
// 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);
if (newx != sp->cur.x || newy != sp->cur.y) {
sp_updateme(sp);
sp->cur.x = newx;
sp->cur.y = newy;
update++;
sp_updateme(sp);
}
break;
}}
return update;
}
// ץ饤Ⱥν
static void cb_remove(sprite_t *sp) {
spev_remove_eventlistener(sp);
}
/*
sp_new λ˥ץ饤Ȥμν
@param sp: 륹ץ饤
*/
int sp_get_setup(sprite_t *sp) {
spev_add_eventlistener(sp, eventCB_GET);
sp->remove = cb_remove;
return OK;
}
|