⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fad.button.c

📁 嵌入式linux环境下的一个FLASH播放器(支持FLASH7.0以下版本)
💻 C
字号:
/** * libFAD - Flash Animation Decode library * Copyright (C) 2005-2006 VGSystem Technologies, Inc. * * libFAD is the legal property of its developers, whose names are too numerous * to list here.  Please refer to the COPYRIGHT file distributed with this * source distribution. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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 Library 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: fad.button.c,v 1.19 2006/02/24 10:43:18 wrxzzj Exp $ */#include "fad.button.h"#include "fad.tags.h"#include "fad.bits.h"/**button record max*/#define FAD_BTNRD_MAX 30enum {  FAD_BTN_EVT_UP,  FAD_BTN_EVT_DOWN,  FAD_BTN_EVT_OVER,	FAD_BTN_EVT_END};enum {	FAD_BTN_POS_IN,	FAD_BTN_POS_OUT};#define MKSTA(evt, pos) (evt|(pos<<2))#define STA2IDX(sta) (sta&0x03)#define STA2POS(sta) ((sta&0x04)>>2)/**#define STA_SET_MOD(sta) (sta|=0x80)#define STA_CHK_MOD(sta) (sta < 0)#define STA_CLR_MOD(sta) (sta^=0x80)*/typedef struct {  fad_object_t base;  rect_t hitarea;	cairo_matrix_t hitmx;  u8_t* br_array[FAD_BTNRD_MAX];  u8_t* bs; /**button sound*/  u8_t*  bc; /**byte code address*/  u32_t  bc_size; /**byte code size*/  u8_t ver, oldsta, newsta;  dynarray_t *dict;	fad_frame_t frame;} button_t;static fad_object_t* _button_do_copy(fad_object_t *fo) {  button_t* btn = (button_t* )fo, *new = NULL;	new = calloc(1, sizeof(button_t));	*new = *btn;	return (fad_object_t *)new;}static void _button_do_free(fad_object_t* fo) {  button_t* btn = (button_t* )fo;	fad_frame_finish(&btn->frame);}static s32_t _button_proc_mbevt(fad_object_t *fo, u8_t evt, s32_t x, s32_t y) {  button_t* btn = (button_t* )fo;  if(fad_point_in_rect(&btn->hitarea, x, y))		btn->newsta = MKSTA(evt, FAD_BTN_POS_IN);  else		btn->newsta = MKSTA(FAD_BTN_EVT_UP, FAD_BTN_POS_OUT);  return btn->newsta!=btn->oldsta ? FAD_TRUE : FAD_FALSE;}static void _button_get_rect(fad_object_t* fo, rect_t *rt) {}static u8_t _button_do_render(fad_object_t* fo, fad_render_t* render, dl_node_t *node) {  button_t* btn = (button_t* )fo;  bits_t bits;  dl_node_t* new = NULL;	dl_header_t *dlhdr = NULL;  u16_t depth, id;  u8_t idx = 0, ret = FAD_TRUE;  fad_object_t *obj = NULL;  cairo_matrix_t tempMX;	if(btn->newsta == btn->oldsta) {		//printf("button status unchanged, sta = %x\n", STA2IDX(btn->newsta));	  fad_frame_render_graphics(&btn->frame, node);		return FAD_TRUE;	}	if(STA2IDX(btn->newsta) != FAD_BTN_EVT_END)    btn->oldsta = btn->newsta;	else		btn->newsta = btn->oldsta;  if(FAD_DL_NODE_CHK_BTNMX(node->attr)) {    cairo_matrix_multiply(&tempMX, &node->mx, &btn->hitmx);    fad_rect_do_matrix(&btn->hitarea, &tempMX);    printf("button matrix = (%f, %f, %f, %f, %f, %f)\n", tempMX.xx, tempMX.xy, tempMX.x0, tempMX.yy, tempMX.yx, tempMX.y0);    printf("new hitarea(%f, %f, %f, %f)\n", btn->hitarea.x0/20.00, btn->hitarea.y0/20.00, btn->hitarea.x1/20.00, btn->hitarea.y1/20.00);    FAD_DL_NODE_CLR_BTNMX(node->attr);  }	idx = STA2IDX(btn->oldsta);	dlhdr = &btn->frame.dlhdr;	dl_header_finish(dlhdr);  //printf("BUTTON.sta = %x doing render\n", idx);  for(; idx < FAD_BTNRD_MAX; idx+=FAD_BTN_EVT_END) {    if(btn->br_array[idx] == NULL)      break;    bits_init(&bits);    bits_buffer(&bits, btn->br_array[idx]);    id = bits_get_u16(&bits);    obj = btn->dict->get(btn->dict, id);    if(obj == NULL) {      FAD_ERROR("cann't found BUTTON.obj in dictionary\n");      continue;    }    depth = bits_get_u16(&bits);    new = calloc(1, sizeof(dl_node_t));    new->depth = depth;    dlhdr->put(dlhdr, new);		if(obj->do_copy)			new->fo = obj->do_copy(obj);		else			new->fo = obj;    new->flag = 0x04;    bits_get_matrix(&bits, &new->mx);    if(btn->ver == 2) {      new->flag |= 0x08;      bits_get_rgbaxform(&bits, &new->cx);    }    new->ctx = NULL;		FAD_DL_NODE_SET_MATRIX(new->attr);    FAD_DL_NODE_SET_VER(new->attr, 2);    printf("ADD BUTTON RECORD: br_array[%d]=(%x, %d), fo = (%x, %s), depth = %d\n", idx, btn->br_array[idx], id, new->fo, fad_object_type_to_string(new->fo->type), new->depth);    printf("matrix = (%f, %f, %f, %f, %f, %f)\n", new->mx.xx, new->mx.xy, new->mx.x0, new->mx.yy, new->mx.yx, new->mx.y0);    bits_finish(&bits);  }	fad_frame_render_graphics(&btn->frame, node);  return ret;}s32_t button_cxform_decode(fad_frame_t* frame, fad_stream_t* s) {  button_t* btn = NULL;  u16_t id;}s32_t button_sound_decode(fad_frame_t* frame, fad_stream_t* s) {  button_t* btn = NULL;  u16_t id;  id = bits_get_u16(&s->bits);  btn = (button_t* )s->dict->get(s->dict, id);  if(btn == NULL)    return -1;  btn->bs = (u8_t* )bits_tell(&s->bits);  return 0;}s32_t button_decode(fad_frame_t* frame, fad_stream_t* s) {  button_t* btn = NULL;  u16_t id, offset;  u8_t flag, btn2flag, hitflag = FAD_FALSE;  u8_t down=FAD_BTN_EVT_DOWN, over= FAD_BTN_EVT_OVER, up = FAD_BTN_EVT_UP;  btn = calloc(1, sizeof(button_t));  if(btn == NULL)    goto error;  id = bits_get_u16(&s->bits);  btn->base.do_render = _button_do_render ;  btn->base.do_free = _button_do_free;  btn->base.do_copy = _button_do_copy;  btn->base.get_rect = _button_get_rect;  btn->base.proc_mbevt = _button_proc_mbevt;  btn->base.type = FO_TYPE_BUTTON;	fad_frame_init(&btn->frame);	btn->frame.render = frame->render;  btn->dict = s->dict;  btn->oldsta = MKSTA(FAD_BTN_EVT_UP, FAD_BTN_POS_OUT);	btn->newsta = MKSTA(FAD_BTN_EVT_END, FAD_BTN_POS_OUT);  if(s->tag_id == TAG_DEFINEBUTTON2) {    btn2flag = bits_get_u8(&s->bits);    offset   = bits_get_u16(&s->bits);  }  do {    u8_t *btnrd = NULL;    u16_t id;    fad_object_t *fo = NULL;    flag = bits_get_u8(&s->bits);    if(flag == 0)      break;    btnrd = bits_tell(&s->bits);    if(flag&0x08) {			u16_t id = bits_get_u16(&s->bits);      if(hitflag==FAD_FALSE) {        fo = s->dict->get(s->dict, id);        if(fo && fo->get_rect)          fo->get_rect(fo, &btn->hitarea);			  //printf("obj = %x(%s), id = %x, hitarea(%f, %f, %f, %f)\n", fo, fad_object_type_to_string(fo->type), id, btn->hitarea.x0/20.00, btn->hitarea.y0/20.00, btn->hitarea.x1/20.00, btn->hitarea.y1/20.00);      }      bits_seek_nbytes(&s->bits, 2);    } else {      bits_seek_nbytes(&s->bits, 4);    }    if(flag&0x04) {      if(btn->br_array[down] && down<FAD_BTNRD_MAX)        down += FAD_BTN_EVT_END;      btn->br_array[down] = btnrd;    }    if(flag&0x02) {      if(btn->br_array[over] && over<FAD_BTNRD_MAX)        over += FAD_BTN_EVT_END;      btn->br_array[over] = btnrd;    }    if(flag&0x01) {      if(btn->br_array[up] && up<FAD_BTNRD_MAX)        up += FAD_BTN_EVT_END;      btn->br_array[up] = btnrd;    }		if(hitflag==FAD_FALSE && flag&0x08) {			bits_get_matrix(&s->bits, &btn->hitmx);      if(fo && fo->get_rect)        hitflag = FAD_TRUE;    } else      bits_get_matrix(&s->bits, NULL);    if(s->tag_id == TAG_DEFINEBUTTON2)      bits_get_rgbaxform(&s->bits, NULL);  } while(1);  btn->bc = bits_tell(&s->bits);  s->dict->put(s->dict, btn, id);  //printf("hitmatrix = (%f, %f, %f, %f, %f, %f)\n", btn->hitmx.xx, btn->hitmx.xy, btn->hitmx.x0, btn->hitmx.yy, btn->hitmx.yx, btn->hitmx.y0);  FAD_ERROR("append button to dictionary, id = %d, btn = %x, tag len = %d\n", id, btn, s->tag_len);  return 0;error:  s->err = FAD_ERROR_MEM;  return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -