gif fixes, going to pic mouse events
This commit is contained in:
parent
accef4412c
commit
46dffb9660
|
@ -226,24 +226,53 @@ int gfx_parse_color (
|
||||||
|
|
||||||
struct _anigif_t;
|
struct _anigif_t;
|
||||||
|
|
||||||
|
struct agspawn {
|
||||||
|
SDL_Rect clip;
|
||||||
|
img_t bg;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
#define AGSPAWN_BLOCK 8
|
||||||
struct _anigif_t {
|
struct _anigif_t {
|
||||||
struct _anigif_t *next;
|
struct _anigif_t *next;
|
||||||
struct _anigif_t *prev;
|
struct _anigif_t *prev;
|
||||||
int cur_frame;
|
int cur_frame;
|
||||||
int nr_frames;
|
int nr_frames;
|
||||||
int loop;
|
int loop;
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int drawn;
|
int drawn;
|
||||||
int active;
|
int active;
|
||||||
int delay;
|
int delay;
|
||||||
img_t bg;
|
int spawn_nr;
|
||||||
SDL_Rect clip;
|
struct agspawn *spawn;
|
||||||
AG_Frame frames[0];
|
AG_Frame frames[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _anigif_t *anigif_t;
|
typedef struct _anigif_t *anigif_t;
|
||||||
|
|
||||||
|
static int anigif_spawn(anigif_t ag, int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
int nr;
|
||||||
|
SDL_Rect clip;
|
||||||
|
SDL_GetClipRect(screen, &clip);
|
||||||
|
//gfx_free_image(ag->bg);
|
||||||
|
if (!ag->spawn && !(ag->spawn = malloc(AGSPAWN_BLOCK * sizeof(struct agspawn))))
|
||||||
|
return -1;
|
||||||
|
nr = ag->spawn_nr + 1;
|
||||||
|
if (!(nr % AGSPAWN_BLOCK)) { /* grow */
|
||||||
|
void *p = realloc(ag->spawn, AGSPAWN_BLOCK * sizeof(struct agspawn) *
|
||||||
|
((nr / AGSPAWN_BLOCK) + 1));
|
||||||
|
if (!p)
|
||||||
|
return -1;
|
||||||
|
ag->spawn = p;
|
||||||
|
}
|
||||||
|
ag->spawn[ag->spawn_nr].x = x;
|
||||||
|
ag->spawn[ag->spawn_nr].y = y;
|
||||||
|
ag->spawn[ag->spawn_nr].clip = clip;
|
||||||
|
ag->spawn[ag->spawn_nr].bg = gfx_grab_screen(x, y, w, h);
|
||||||
|
ag->spawn_nr = nr;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static anigif_t anim_gifs = NULL;
|
static anigif_t anim_gifs = NULL;
|
||||||
|
|
||||||
static int anigif_drawn_nr = 0;
|
static int anigif_drawn_nr = 0;
|
||||||
|
@ -263,23 +292,23 @@ static void anigif_disposal(anigif_t g)
|
||||||
{
|
{
|
||||||
SDL_Rect dest;
|
SDL_Rect dest;
|
||||||
SDL_Rect clip;
|
SDL_Rect clip;
|
||||||
|
int i = 0;
|
||||||
img_t *img = NULL;
|
img_t *img = NULL;
|
||||||
AG_Frame *frame;
|
AG_Frame *frame;
|
||||||
frame = &g->frames[g->cur_frame];
|
frame = &g->frames[g->cur_frame];
|
||||||
SDL_GetClipRect(screen, &clip);
|
SDL_GetClipRect(screen, &clip);
|
||||||
|
|
||||||
dest.x = g->x;
|
dest.x = 0; //g->x;
|
||||||
dest.y = g->y;
|
dest.y = 0; //g->y;
|
||||||
|
|
||||||
switch (frame->disposal) {
|
switch (frame->disposal) {
|
||||||
case AG_DISPOSE_NA:
|
case AG_DISPOSE_NA:
|
||||||
case AG_DISPOSE_NONE: /* just show next frame */
|
case AG_DISPOSE_NONE: /* just show next frame */
|
||||||
break;
|
break;
|
||||||
case AG_DISPOSE_RESTORE_BACKGROUND:
|
case AG_DISPOSE_RESTORE_BACKGROUND:
|
||||||
img = g->bg;
|
// img = g->bg;
|
||||||
dest.w = Surf(img)->w;
|
// dest.w = Surf(img)->w;
|
||||||
dest.h = Surf(img)->h;
|
// dest.h = Surf(img)->h;
|
||||||
break;
|
break;
|
||||||
case AG_DISPOSE_RESTORE_PREVIOUS:
|
case AG_DISPOSE_RESTORE_PREVIOUS:
|
||||||
if (g->cur_frame) {
|
if (g->cur_frame) {
|
||||||
|
@ -291,15 +320,28 @@ static void anigif_disposal(anigif_t g)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SDL_SetClipRect(screen, &g->clip);
|
for (i = 0; i < g->spawn_nr; i++) {
|
||||||
|
SDL_Rect dst;
|
||||||
|
SDL_SetClipRect(screen, &g->spawn[i].clip);
|
||||||
|
dst = dest;
|
||||||
|
|
||||||
|
dst.x += g->spawn[i].x;
|
||||||
|
dst.y += g->spawn[i].y;
|
||||||
|
if (frame->disposal == AG_DISPOSE_RESTORE_BACKGROUND) {
|
||||||
|
img = g->spawn[i].bg;
|
||||||
|
dst.w = Surf(img)->w;
|
||||||
|
dst.h = Surf(img)->h;
|
||||||
|
}
|
||||||
if (img) { /* draw bg */
|
if (img) { /* draw bg */
|
||||||
SDL_BlitSurface(Surf(img), NULL, screen, &dest);
|
SDL_BlitSurface(Surf(img), NULL, screen, &dst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SDL_SetClipRect(screen, &clip);
|
SDL_SetClipRect(screen, &clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void anigif_frame(anigif_t g)
|
static void anigif_frame(anigif_t g)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
SDL_Rect dest;
|
SDL_Rect dest;
|
||||||
SDL_Rect clip;
|
SDL_Rect clip;
|
||||||
|
|
||||||
|
@ -307,13 +349,15 @@ static void anigif_frame(anigif_t g)
|
||||||
frame = &g->frames[g->cur_frame];
|
frame = &g->frames[g->cur_frame];
|
||||||
SDL_GetClipRect(screen, &clip);
|
SDL_GetClipRect(screen, &clip);
|
||||||
|
|
||||||
dest.x = g->x + frame->x;
|
|
||||||
dest.y = g->y + frame->y;
|
|
||||||
dest.w = frame->surface->w;
|
dest.w = frame->surface->w;
|
||||||
dest.h = frame->surface->h;
|
dest.h = frame->surface->h;
|
||||||
|
|
||||||
SDL_SetClipRect(screen, &g->clip);
|
for (i = 0; i < g->spawn_nr; i++) {
|
||||||
|
dest.x = g->spawn[i].x + frame->x;
|
||||||
|
dest.y = g->spawn[i].y + frame->y;
|
||||||
|
SDL_SetClipRect(screen, &g->spawn[i].clip);
|
||||||
SDL_BlitSurface(frame->surface, NULL, screen, &dest);
|
SDL_BlitSurface(frame->surface, NULL, screen, &dest);
|
||||||
|
}
|
||||||
g->delay = timer_counter;
|
g->delay = timer_counter;
|
||||||
SDL_SetClipRect(screen, &clip);
|
SDL_SetClipRect(screen, &clip);
|
||||||
}
|
}
|
||||||
|
@ -359,11 +403,22 @@ static anigif_t anigif_del(anigif_t g)
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void anigif_free_spawn(anigif_t g)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < g->spawn_nr; i++)
|
||||||
|
gfx_free_image(g->spawn[i].bg);
|
||||||
|
if (g->spawn) {
|
||||||
|
free(g->spawn);
|
||||||
|
g->spawn = NULL;
|
||||||
|
g->spawn_nr = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void anigif_free(anigif_t g)
|
static void anigif_free(anigif_t g)
|
||||||
{
|
{
|
||||||
AG_FreeSurfaces(g->frames, g->nr_frames);
|
AG_FreeSurfaces(g->frames, g->nr_frames);
|
||||||
gfx_free_image(g->bg);
|
anigif_free_spawn(g);
|
||||||
free(g);
|
free(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,17 +763,11 @@ void gfx_draw(img_t p, int x, int y)
|
||||||
dest.h = pixbuf->h;
|
dest.h = pixbuf->h;
|
||||||
ag = is_anigif(pixbuf);
|
ag = is_anigif(pixbuf);
|
||||||
if (ag) {
|
if (ag) {
|
||||||
SDL_Rect clip;
|
anigif_spawn(ag, x, y, dest.w, dest.w);
|
||||||
SDL_GetClipRect(screen, &clip);
|
|
||||||
ag->clip = clip;
|
|
||||||
ag->x = x;
|
|
||||||
ag->y = y;
|
|
||||||
if (!ag->drawn)
|
if (!ag->drawn)
|
||||||
anigif_drawn_nr ++;
|
anigif_drawn_nr ++;
|
||||||
ag->drawn = 1;
|
ag->drawn = 1;
|
||||||
ag->active = 1;
|
ag->active = 1;
|
||||||
gfx_free_image(ag->bg);
|
|
||||||
ag->bg = gfx_grab_screen(x, y, dest.w, dest.h);
|
|
||||||
anigif_frame(ag);
|
anigif_frame(ag);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -742,6 +791,7 @@ void gfx_dispose_gif(img_t p)
|
||||||
if (ag->drawn)
|
if (ag->drawn)
|
||||||
anigif_drawn_nr --;
|
anigif_drawn_nr --;
|
||||||
ag->drawn = 0;
|
ag->drawn = 0;
|
||||||
|
anigif_free_spawn(ag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,13 +849,17 @@ int gfx_is_drawn_gifs(void)
|
||||||
|
|
||||||
void gfx_update_gif(img_t img)
|
void gfx_update_gif(img_t img)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
anigif_t ag;
|
anigif_t ag;
|
||||||
ag = is_anigif(img);
|
ag = is_anigif(img);
|
||||||
if (!ag)
|
if (!ag)
|
||||||
return;
|
return;
|
||||||
if (!ag->drawn || !ag->active)
|
if (!ag->drawn || !ag->active)
|
||||||
return;
|
return;
|
||||||
gfx_update(ag->x, ag->y, gfx_img_w(img), gfx_img_h(img));
|
for (i = 0; i < ag->spawn_nr; i++) {
|
||||||
|
gfx_update(ag->spawn[i].x, ag->spawn[i].y,
|
||||||
|
gfx_img_w(img), gfx_img_h(img));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfx_draw_wh(img_t p, int x, int y, int w, int h)
|
void gfx_draw_wh(img_t p, int x, int y, int w, int h)
|
||||||
|
@ -1533,6 +1587,24 @@ void _txt_layout_free(layout_t lay)
|
||||||
layout->lines = NULL;
|
layout->lines = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
word_t txt_layout_words(layout_t lay, word_t v)
|
||||||
|
{
|
||||||
|
struct word *w = (struct word*)v;
|
||||||
|
struct layout *layout = (struct layout *)lay;
|
||||||
|
struct line *line;
|
||||||
|
if (!layout)
|
||||||
|
return NULL;
|
||||||
|
if (!w) {
|
||||||
|
if (!(line = layout->lines))
|
||||||
|
return NULL;
|
||||||
|
w = line->words;
|
||||||
|
} else {
|
||||||
|
line = w->line;
|
||||||
|
w = w->next;
|
||||||
|
}
|
||||||
|
for (; !w && line->next; line = line->next, w = line->words);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
void txt_layout_free(layout_t lay)
|
void txt_layout_free(layout_t lay)
|
||||||
{
|
{
|
||||||
struct layout *layout = (struct layout *)lay;
|
struct layout *layout = (struct layout *)lay;
|
||||||
|
@ -1918,6 +1990,8 @@ void xref_update(xref_t pxref, int x, int y, clear_fn clear, update_fn update)
|
||||||
|
|
||||||
void txt_layout_draw_ex(layout_t lay, struct line *line, int x, int y, int off, int height, clear_fn clear)
|
void txt_layout_draw_ex(layout_t lay, struct line *line, int x, int y, int off, int height, clear_fn clear)
|
||||||
{
|
{
|
||||||
|
void *v;
|
||||||
|
img_t img;
|
||||||
struct layout *layout = (struct layout*)lay;
|
struct layout *layout = (struct layout*)lay;
|
||||||
// struct line *line;
|
// struct line *line;
|
||||||
struct word *word;
|
struct word *word;
|
||||||
|
@ -1925,6 +1999,8 @@ void txt_layout_draw_ex(layout_t lay, struct line *line, int x, int y, int off,
|
||||||
// gfx_clip(x, y, layout->w, layout->h);
|
// gfx_clip(x, y, layout->w, layout->h);
|
||||||
if (!lay)
|
if (!lay)
|
||||||
return;
|
return;
|
||||||
|
for (v = NULL; (img = txt_layout_images(lay, &v)); )
|
||||||
|
gfx_dispose_gif(img);
|
||||||
if (!line)
|
if (!line)
|
||||||
line = layout->lines;
|
line = layout->lines;
|
||||||
for (; line; line= line->next) {
|
for (; line; line= line->next) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ typedef void* fnt_t;
|
||||||
typedef void* layout_t;
|
typedef void* layout_t;
|
||||||
typedef void* textbox_t;
|
typedef void* textbox_t;
|
||||||
typedef void* xref_t;
|
typedef void* xref_t;
|
||||||
|
typedef void* word_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int r;
|
int r;
|
||||||
int g;
|
int g;
|
||||||
|
@ -96,6 +98,7 @@ extern void txt_layout_active_color(layout_t lay, color_t link);
|
||||||
extern void txt_layout_link_style(layout_t lay, int style);
|
extern void txt_layout_link_style(layout_t lay, int style);
|
||||||
extern int txt_layout_add_img(layout_t lay, const char *name, img_t img);
|
extern int txt_layout_add_img(layout_t lay, const char *name, img_t img);
|
||||||
extern img_t txt_layout_images(layout_t lay, void **v); /* enumerator */
|
extern img_t txt_layout_images(layout_t lay, void **v); /* enumerator */
|
||||||
|
extern word_t txt_layout_words(layout_t lay, word_t w); /* enumerator */
|
||||||
extern void txt_layout_size(layout_t lay, int *w, int *h);
|
extern void txt_layout_size(layout_t lay, int *w, int *h);
|
||||||
extern textbox_t txt_box(int w, int h);
|
extern textbox_t txt_box(int w, int h);
|
||||||
extern layout_t txt_box_layout(textbox_t tbox);
|
extern layout_t txt_box_layout(textbox_t tbox);
|
||||||
|
|
Reference in a new issue