PageRenderTime 501ms CodeModel.GetById 180ms app.highlight 62ms RepoModel.GetById 181ms app.codeStats 0ms

/src/ftk_animation_scale.c

http://ftk.googlecode.com/
C | 147 lines | 93 code | 25 blank | 29 comment | 12 complexity | db256983ecd11e22b83f5760d1c0afea MD5 | raw file
  1/*
  2 * File: ftk_animation_scale.c
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   scale animation
  5 *
  6 * Copyright (c) 2009 - 2011  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2011-03-26 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#include "ftk_log.h"
 33#include "ftk_globals.h"
 34#include "ftk_animation_scale.h"
 35
 36typedef struct _AnimationScalePrivInfo
 37{
 38	float end;
 39	float start;
 40	int duration;
 41	int alpha_enable;
 42	FtkBitmap* back_win;
 43	FtkBitmap* front_win;
 44	FtkRect back_win_rect;
 45	FtkRect front_win_rect;
 46}PrivInfo;
 47
 48static Ret   ftk_animation_scale_step(FtkAnimation* thiz)
 49{
 50	FtkRect r = {0};
 51	FtkRect dst_r = {0};
 52
 53	float percent = 0;
 54	DECL_PRIV(thiz, priv);
 55
 56	r = priv->back_win_rect;
 57	if(r.width > 0 && r.height > 0)
 58	{
 59		ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->back_win, &r, &r, 0xff);
 60		ftk_logd("%s:%d %d %d %d %d\n", __func__, __LINE__, r.x, r.y, r.width, r.height);
 61	}
 62
 63	percent = priv->start + (priv->end - priv->start) * ftk_animation_get_percent(thiz);
 64
 65	r = priv->front_win_rect;
 66	dst_r.width = (int)(r.width * percent);
 67	dst_r.height = (int)(r.height * percent);
 68
 69	if(dst_r.width > 0 && dst_r.height > 0)
 70	{
 71		int alpha = priv->alpha_enable ? (int)(0xff * percent) & 0xff : 0xff;
 72		dst_r.x = r.x + (r.width - dst_r.width)/2;
 73		dst_r.y = r.y + (r.height - dst_r.height)/2;
 74		ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->front_win, &r, &dst_r, alpha);
 75	}
 76	
 77	r = priv->back_win_rect;
 78	r.x = FTK_MIN(r.x, dst_r.y);
 79	r.y = FTK_MIN(r.y, dst_r.y);
 80	r.width = FTK_MAX(r.width, dst_r.width);
 81	r.height = FTK_MAX(r.height, dst_r.height);
 82
 83	ftk_logd("%s:%d %d %d %d %d\n", __func__, __LINE__, r.x, r.y, r.width, r.height);
 84	ftk_canvas_show(ftk_shared_canvas(), ftk_default_display(), &r, r.x, r.y);
 85
 86	return RET_OK;
 87}
 88
 89static Ret   ftk_animation_scale_reset(FtkAnimation* thiz, FtkBitmap* old_win, FtkBitmap* new_win,
 90	FtkRect* old_win_rect, FtkRect* new_win_rect)
 91{
 92	DECL_PRIV(thiz, priv);
 93	const char* src = ftk_animation_get_param(thiz, "src");
 94	const char* alpha_enable = ftk_animation_get_param(thiz, "alpha");
 95	return_val_if_fail(src != NULL, RET_FAIL);
 96
 97	priv->alpha_enable = alpha_enable != NULL && strcmp(alpha_enable, "enable") == 0;
 98	priv->start = ftk_animation_get_param_float(thiz, "from", 1.0);
 99	priv->end = ftk_animation_get_param_float(thiz, "to", 1.0);
100
101	if(strstr(src, "new_window") != NULL)
102	{
103		priv->back_win = old_win;
104		priv->back_win_rect = *old_win_rect;
105		
106		priv->front_win = new_win;
107		priv->front_win_rect = *new_win_rect;
108	}
109	else
110	{
111		priv->back_win = new_win;
112		priv->back_win_rect = *new_win_rect;
113		
114		priv->front_win = old_win;
115		priv->front_win_rect = *old_win_rect;
116	}
117
118	ftk_logd("%s: src=%s start=%f end=%f old(%d %d %d %d) new(%d %d %d %d)",
119		__func__, src, priv->start, priv->end, 
120		old_win_rect->x, old_win_rect->y, old_win_rect->width, old_win_rect->height,
121		new_win_rect->x, new_win_rect->y, new_win_rect->width, new_win_rect->height);
122
123	return RET_OK;
124}
125
126static void  ftk_animation_scale_destroy(FtkAnimation* thiz)
127{
128	FTK_FREE(thiz);
129
130	return;
131}
132
133FtkAnimation* ftk_animation_scale_create(void)
134{
135	FtkAnimation* thiz = FTK_NEW_PRIV(FtkAnimation);
136
137	if(thiz != NULL)
138	{
139		ftk_animation_set_name(thiz,  "scale");
140		thiz->step      = ftk_animation_scale_step;
141		thiz->reset     = ftk_animation_scale_reset;
142		thiz->destroy   = ftk_animation_scale_destroy;
143	}
144
145	return thiz;
146}
147