2003-09-11 02:46:56 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
*/
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/** \file
|
|
|
|
* Content for image/x-riscos-sprite (RISC OS implementation).
|
|
|
|
*
|
|
|
|
* No conversion is necessary: we can render RISC OS sprites directly under
|
|
|
|
* RISC OS.
|
|
|
|
*
|
|
|
|
* Unfortunately we have to make a copy of the bitmap data, because sprite areas
|
|
|
|
* need a length word at the start.
|
|
|
|
*/
|
|
|
|
|
2003-09-11 02:46:56 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2004-02-27 20:45:19 +03:00
|
|
|
#include "oslib/osspriteop.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-09-11 02:46:56 +04:00
|
|
|
#include "netsurf/content/content.h"
|
2004-11-06 22:34:24 +03:00
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-08-15 23:06:24 +04:00
|
|
|
#include "netsurf/riscos/image.h"
|
2003-09-11 02:46:56 +04:00
|
|
|
#include "netsurf/riscos/sprite.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
2004-02-27 20:45:19 +03:00
|
|
|
#include "netsurf/utils/messages.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_SPRITE
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new CONTENT_SPRITE.
|
|
|
|
*
|
|
|
|
* A new empty sprite area is allocated.
|
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool sprite_create(struct content *c, const char *params[])
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
c->data.sprite.data = malloc(4);
|
|
|
|
if (!c->data.sprite.data) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return false;
|
|
|
|
}
|
2003-09-11 22:37:25 +04:00
|
|
|
c->data.sprite.length = 4;
|
2004-06-11 00:41:26 +04:00
|
|
|
return true;
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/**
|
|
|
|
* Process data for a CONTENT_SPRITE.
|
|
|
|
*
|
|
|
|
* The data is just copied into the sprite area.
|
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool sprite_process_data(struct content *c, char *data, unsigned int size)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
2004-06-11 00:41:26 +04:00
|
|
|
char *sprite_data;
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
sprite_data = realloc(c->data.sprite.data,
|
|
|
|
c->data.sprite.length + size);
|
|
|
|
if (!sprite_data) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
c->data.sprite.data = sprite_data;
|
|
|
|
memcpy((char*)(c->data.sprite.data) + c->data.sprite.length,
|
|
|
|
data, size);
|
2003-09-11 02:46:56 +04:00
|
|
|
c->data.sprite.length += size;
|
|
|
|
c->size += size;
|
2004-06-11 00:41:26 +04:00
|
|
|
return true;
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/**
|
|
|
|
* Convert a CONTENT_SPRITE for display.
|
|
|
|
*
|
|
|
|
* No conversion is necessary. We merely read the sprite dimensions.
|
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool sprite_convert(struct content *c, int width, int height)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
|
|
|
os_error *error;
|
|
|
|
int w, h;
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2003-12-27 03:11:57 +03:00
|
|
|
osspriteop_area *area = (osspriteop_area*)c->data.sprite.data;
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
/* fill in the size (first word) of the area */
|
2003-09-12 23:51:17 +04:00
|
|
|
area->size = c->data.sprite.length;
|
2003-09-11 22:37:25 +04:00
|
|
|
|
|
|
|
error = xosspriteop_read_sprite_info(osspriteop_PTR,
|
2004-06-11 00:41:26 +04:00
|
|
|
area,
|
2004-11-06 22:34:24 +03:00
|
|
|
(osspriteop_id) ((char *) area + area->first),
|
2004-06-11 00:41:26 +04:00
|
|
|
&w, &h, NULL, NULL);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosspriteop_read_sprite_info: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
msg_data.error = error->errmess;
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2003-09-11 02:46:56 +04:00
|
|
|
|
|
|
|
c->width = w;
|
|
|
|
c->height = h;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->title = malloc(100);
|
|
|
|
if (c->title)
|
|
|
|
snprintf(c->title, 100, messages_get("SpriteTitle"), c->width,
|
2004-11-06 22:34:24 +03:00
|
|
|
c->height, c->data.sprite.length);
|
2003-09-11 02:46:56 +04:00
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2004-06-11 00:41:26 +04:00
|
|
|
return true;
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_SPRITE and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
2003-09-11 02:46:56 +04:00
|
|
|
void sprite_destroy(struct content *c)
|
|
|
|
{
|
2004-06-11 00:41:26 +04:00
|
|
|
free(c->data.sprite.data);
|
|
|
|
free(c->title);
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/**
|
|
|
|
* Redraw a CONTENT_SPRITE.
|
|
|
|
*/
|
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
bool sprite_redraw(struct content *c, int x, int y,
|
2004-06-11 00:41:26 +04:00
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2004-11-06 22:34:24 +03:00
|
|
|
float scale, colour background_colour)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
2004-11-06 22:34:24 +03:00
|
|
|
return image_redraw(c->data.sprite.data,
|
|
|
|
ro_plot_origin_x + x * 2,
|
|
|
|
ro_plot_origin_y - y * 2,
|
|
|
|
width, height,
|
|
|
|
c->width,
|
|
|
|
c->height,
|
|
|
|
background_colour,
|
|
|
|
false, false, false,
|
|
|
|
IMAGE_PLOT_OS);
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
2004-11-06 22:34:24 +03:00
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|