Exemple #1
0
static int
draw_child(struct sprite *s, struct srt *srt, struct sprite_trans * ts) {
	struct sprite_trans temp;
	struct matrix temp_matrix;
	struct sprite_trans *t = trans_mul(&s->t, ts, &temp, &temp_matrix);
	switch (s->type) {
	case TYPE_PICTURE:
		switch_program(t, PROGRAM_PICTURE);
		sprite_drawquad(s->s.pic, srt, t);
		return 0;
	case TYPE_POLYGON:
		switch_program(t, PROGRAM_PICTURE);
		sprite_drawpolygon(s->s.poly, srt, t);
		return 0;
	case TYPE_LABEL:
		if (s->data.text) {
			switch_program(t, s->s.label->edge ? PROGRAM_TEXT_EDGE : PROGRAM_TEXT);
			label_draw(s->data.text, s->s.label,srt,t);
		}
		return 0;
	case TYPE_ANCHOR:
		anchor_update(s, srt, t);
		return 0;
	case TYPE_ANIMATION:
		break;
	case TYPE_PANNEL:
		if (s->data.scissor) {
			// enable scissor
			set_scissor(s->s.pannel, srt, t);
			return 1;
		} else {
			return 0;
		}
	default:
		// todo : invalid type
		return 0;
	}
	// draw animation
	struct pack_animation *ani = s->s.ani;
	int frame = real_frame(s) + s->start_frame;
	struct pack_frame * pf = &ani->frame[frame];
	int i;
	int scissor = 0;
	for (i=0;i<pf->n;i++) {
		struct pack_part *pp = &pf->part[i];
		int index = pp->component_id;
		struct sprite * child = s->data.children[index];
		if (child == NULL || child->visible == false) {
			continue;
		}
		struct sprite_trans temp2;
		struct matrix temp_matrix2;
		struct sprite_trans *ct = trans_mul(&pp->t, t, &temp2, &temp_matrix2);
		scissor += draw_child(child, srt, ct);
	}
	for (i=0;i<scissor;i++) {
		scissor_pop();
	}
	return 0;
}
Exemple #2
0
int
drawsprite(struct render_buffer *rb, struct sprite *s, struct sprite_trans * ts) {
    struct sprite_trans temp;
    struct matrix temp_matrix;
    struct sprite_trans *t = sprite_trans_mul(&s->t, ts, &temp, &temp_matrix);
    switch (s->type) {
    case TYPE_PICTURE:
        return drawquad(rb, s->s.pic, t);
    case TYPE_POLYGON:
        return drawpolygon(rb, s->s.poly, t);
    case TYPE_ANIMATION: {
        struct pack_animation *ani = s->s.ani;
        int frame = s->frame % s->total_frame;
        if (frame < 0) {
            frame += s->total_frame;
        }
        frame += s->start_frame;
        struct pack_frame * pf = OFFSET_TO_POINTER(struct pack_frame, s->pack, ani->frame);
        pf = &pf[frame];
        int i;
        for (i=0; i<pf->n; i++) {
            struct pack_part *pp = OFFSET_TO_POINTER(struct pack_part, s->pack, pf->part);
            pp = &pp[i];
            int index = pp->component_id;
            struct sprite * child = s->data.children[index];
            if (child == NULL || (child->flags & SPRFLAG_INVISIBLE)) {
                continue;
            }
            struct sprite_trans temp2;
            struct matrix temp_matrix2;
            struct sprite_trans *ct = sprite_trans_mul2(s->pack, &pp->t, t, &temp2, &temp_matrix2);
            int r = drawsprite(rb, child, ct);
            if (r)
                return r;
        }
        return 0;
    }
    case TYPE_LABEL:
        if (s->data.rich_text) {
            // don't support draw label to renderbuffer
            return -1;
        }
        return 0;
    case TYPE_ANCHOR:
        if (s->data.anchor->ps) {
            return -1;
        }
        anchor_update(s, t);
        return 0;
    case TYPE_PANNEL:
        if (s->data.scissor) {
            return -1;
        } else {
            return 0;
        }
    }
    return -1;
}