2007-11-16 18:25:45 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2010-02-01 21:25:40 +00:00
|
|
|
* Copyright (C) 2001-2010 David Capello
|
2007-09-18 23:57:02 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-09-26 18:59:32 +00:00
|
|
|
#include "gui/jmanager.h"
|
|
|
|
#include "gui/jsystem.h"
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2010-09-18 20:36:21 +00:00
|
|
|
#include "app.h"
|
2008-02-12 15:56:47 +00:00
|
|
|
#include "file/fli/fli.h"
|
2007-09-18 23:57:02 +00:00
|
|
|
#include "modules/gui.h"
|
|
|
|
|
2008-10-01 01:27:51 +00:00
|
|
|
static bool my_callback();
|
2008-01-07 15:10:17 +00:00
|
|
|
static void my_play_fli(const char *filename, bool loop, bool fullscreen,
|
|
|
|
bool (*callback)());
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
void play_fli_animation(const char *filename, bool loop, bool fullscreen)
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
2010-09-18 20:36:21 +00:00
|
|
|
if (App::instance()->isGui()) {
|
2007-09-18 23:57:02 +00:00
|
|
|
PALETTE backup;
|
|
|
|
|
2007-09-26 19:34:06 +00:00
|
|
|
jmanager_free_mouse();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* hide the mouse */
|
2007-09-26 19:34:06 +00:00
|
|
|
jmouse_hide();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* get the current color palette */
|
2007-09-26 19:34:06 +00:00
|
|
|
get_palette(backup);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* clear the screen */
|
2007-09-26 19:34:06 +00:00
|
|
|
clear(ji_screen);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* clear the keyboard buffer */
|
2007-09-26 19:34:06 +00:00
|
|
|
clear_keybuf();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* play the fli */
|
2007-09-26 19:34:06 +00:00
|
|
|
my_play_fli(filename, loop, fullscreen, my_callback);
|
2008-01-07 15:10:17 +00:00
|
|
|
/* play_fli(filename, ji_screen, loop, my_callback); */
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* clear the screen */
|
2007-09-26 19:34:06 +00:00
|
|
|
clear(ji_screen);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* restore the color palette */
|
2007-09-26 19:34:06 +00:00
|
|
|
set_palette(backup);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* show the mouse cursor */
|
2007-09-26 19:34:06 +00:00
|
|
|
jmouse_show();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* wait while the user has pushed some mouse button */
|
|
|
|
do {
|
2007-09-26 19:34:06 +00:00
|
|
|
jmouse_poll();
|
|
|
|
} while (jmouse_b(0));
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* clear again the keyboard buffer */
|
2007-09-26 19:34:06 +00:00
|
|
|
clear_keybuf();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2007-09-26 19:34:06 +00:00
|
|
|
jmanager_refresh_screen();
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 01:27:51 +00:00
|
|
|
static bool my_callback()
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
2007-09-26 19:34:06 +00:00
|
|
|
jmouse_poll();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
return (keypressed() || jmouse_b(0));
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
/* my_play_fli */
|
|
|
|
|
|
|
|
static int speed_timer;
|
|
|
|
|
2008-10-01 01:27:51 +00:00
|
|
|
static void speed_timer_callback()
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
|
|
|
speed_timer++;
|
|
|
|
}
|
|
|
|
|
2007-12-11 20:05:18 +00:00
|
|
|
END_OF_STATIC_FUNCTION(speed_timer_callback);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2007-12-11 20:05:18 +00:00
|
|
|
static void my_play_fli(const char *filename, bool loop, bool fullscreen,
|
|
|
|
bool (*callback)())
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
|
|
|
unsigned char cmap[768];
|
|
|
|
unsigned char omap[768];
|
|
|
|
s_fli_header fli_header;
|
|
|
|
BITMAP *bmp, *old;
|
|
|
|
int x, y, w, h;
|
|
|
|
PALETTE pal;
|
|
|
|
int frpos;
|
|
|
|
int done;
|
|
|
|
int c, i;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
/* open the file to read in binary mode */
|
2007-12-11 20:05:18 +00:00
|
|
|
f = fopen(filename, "rb");
|
2007-09-18 23:57:02 +00:00
|
|
|
if (!f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* read the header */
|
2007-12-11 20:05:18 +00:00
|
|
|
fli_read_header(f, &fli_header);
|
|
|
|
fseek(f, 128, SEEK_SET);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2007-12-11 20:05:18 +00:00
|
|
|
bmp = create_bitmap_ex(8, fli_header.width, fli_header.height);
|
|
|
|
old = create_bitmap_ex(8, fli_header.width, fli_header.height);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* stretch routine doesn't support bitmaps of different color depths */
|
2007-09-26 19:34:06 +00:00
|
|
|
if (bitmap_color_depth(ji_screen) != 8)
|
2010-01-30 16:43:13 +00:00
|
|
|
fullscreen = false;
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
w = fli_header.width;
|
|
|
|
h = fli_header.height;
|
|
|
|
|
|
|
|
if (fullscreen) {
|
|
|
|
double scale;
|
|
|
|
|
|
|
|
if (JI_SCREEN_W-bmp->w > JI_SCREEN_H-bmp->h)
|
|
|
|
scale = (double)JI_SCREEN_W / (double)w;
|
|
|
|
else
|
|
|
|
scale = (double)JI_SCREEN_H / (double)h;
|
|
|
|
|
|
|
|
w = (double)w * (double)scale;
|
|
|
|
h = (double)h * (double)scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = JI_SCREEN_W/2 - w/2;
|
|
|
|
y = JI_SCREEN_H/2 - h/2;
|
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
LOCK_VARIABLE(speed_timer);
|
|
|
|
LOCK_FUNCTION(speed_timer_callback);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
speed_timer = 0;
|
2008-01-07 15:10:17 +00:00
|
|
|
install_int_ex(speed_timer_callback, MSEC_TO_TIMER(fli_header.speed));
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
frpos = 0;
|
2010-01-30 16:43:13 +00:00
|
|
|
done = false;
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
/* read the frame */
|
2007-12-11 20:05:18 +00:00
|
|
|
fli_read_frame(f, &fli_header,
|
|
|
|
(unsigned char *)old->dat, omap,
|
|
|
|
(unsigned char *)bmp->dat, cmap);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
if ((!frpos) || (memcmp (omap, cmap, 768) != 0)) {
|
|
|
|
for (c=i=0; c<256; c++) {
|
|
|
|
pal[c].r = cmap[i++]>>2;
|
|
|
|
pal[c].g = cmap[i++]>>2;
|
|
|
|
pal[c].b = cmap[i++]>>2;
|
|
|
|
}
|
2008-01-07 15:10:17 +00:00
|
|
|
set_palette(pal);
|
|
|
|
memcpy(omap, cmap, 768);
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fullscreen)
|
2007-09-20 00:32:35 +00:00
|
|
|
stretch_blit(bmp, ji_screen,
|
|
|
|
0, 0, fli_header.width, fli_header.height, x, y, w, h);
|
2007-09-18 23:57:02 +00:00
|
|
|
else
|
2007-09-20 00:32:35 +00:00
|
|
|
blit(bmp, ji_screen, 0, 0, x, y, w, h);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2007-09-20 00:32:35 +00:00
|
|
|
jmanager_refresh_screen();
|
|
|
|
gui_feedback();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if ((*callback) ()) {
|
2010-01-30 16:43:13 +00:00
|
|
|
done = true;
|
2007-09-18 23:57:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (speed_timer <= 0);
|
|
|
|
|
|
|
|
if ((++frpos) >= fli_header.frames) {
|
|
|
|
if (!loop)
|
|
|
|
break;
|
|
|
|
else {
|
2008-01-07 15:10:17 +00:00
|
|
|
fseek(f, 128, SEEK_SET);
|
2007-09-18 23:57:02 +00:00
|
|
|
frpos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
blit(bmp, old, 0, 0, 0, 0, fli_header.width, fli_header.height);
|
2007-09-18 23:57:02 +00:00
|
|
|
speed_timer--;
|
|
|
|
}
|
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
destroy_bitmap(bmp);
|
|
|
|
destroy_bitmap(old);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
fclose(f);
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
|