/src/ftk_animation_expand.c
C | 315 lines | 238 code | 48 blank | 29 comment | 47 complexity | 1682153831e48d0e60631c3348f4d2f1 MD5 | raw file
1/* 2 * File: ftk_animation_expand.c 3 * Author: Li XianJing <xianjimli@hotmail.com> 4 * Brief: expand 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_expand.h" 35 36typedef struct _AnimationExpandPrivInfo 37{ 38 int push; 39 float end; 40 float start; 41 int duration; 42 int alpha_enable; 43 const char* base; 44 FtkBitmap* back_win; 45 FtkBitmap* front_win; 46 FtkRect back_win_rect; 47 FtkRect front_win_rect; 48}PrivInfo; 49 50static Ret ftk_animation_expand_step_base_left(FtkAnimation* thiz, float percent) 51{ 52 FtkRect r = {0}; 53 FtkRect dst_r = {0}; 54 DECL_PRIV(thiz, priv); 55 56 r = priv->back_win_rect; 57 if(r.width > 0 && r.height > 0) 58 { 59 dst_r = r; 60 if(priv->push) 61 { 62 int offset = (int)(priv->front_win_rect.width * percent); 63 dst_r.x = dst_r.x + offset; 64 dst_r.width = r.width = r.width - offset; 65 } 66 67 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->back_win, &r, &dst_r, 0xff); 68 } 69 70 r = priv->front_win_rect; 71 r.width = (int)(r.width * percent); 72 if(r.width > 0 && r.height > 0) 73 { 74 int alpha = priv->alpha_enable ? (int)(0xff * percent) & 0xff : 0xff; 75 dst_r = r; 76 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->front_win, &r, &dst_r, alpha); 77 } 78 79 return RET_OK; 80} 81 82static Ret ftk_animation_expand_step_base_top(FtkAnimation* thiz, float percent) 83{ 84 FtkRect r = {0}; 85 FtkRect dst_r = {0}; 86 DECL_PRIV(thiz, priv); 87 88 r = priv->back_win_rect; 89 if(r.width > 0 && r.height > 0) 90 { 91 dst_r = r; 92 if(priv->push) 93 { 94 int offset = (int)(priv->front_win_rect.height * percent); 95 dst_r.y = dst_r.y + offset; 96 dst_r.height = r.height = r.height - offset; 97 } 98 99 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->back_win, &r, &dst_r, 0xff); 100 } 101 102 r = priv->front_win_rect; 103 r.height = (int)(r.height * percent); 104 if(r.width > 0 && r.height > 0) 105 { 106 int alpha = priv->alpha_enable ? (int)(0xff * percent) & 0xff : 0xff; 107 dst_r = r; 108 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->front_win, &r, &dst_r, alpha); 109 } 110 111 return RET_OK; 112} 113 114static Ret ftk_animation_expand_step_base_right(FtkAnimation* thiz, float percent) 115{ 116 FtkRect r = {0}; 117 FtkRect dst_r = {0}; 118 DECL_PRIV(thiz, priv); 119 120 r = priv->back_win_rect; 121 if(r.width > 0 && r.height > 0) 122 { 123 dst_r = r; 124 if(priv->push) 125 { 126 int offset = (int)(priv->front_win_rect.width * percent); 127 r.x = r.x + offset; 128 dst_r.width = r.width = r.width - offset; 129 } 130 131 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->back_win, &r, &dst_r, 0xff); 132 } 133 134 r = priv->front_win_rect; 135 r.width = (int)(r.width * percent); 136 r.x = priv->front_win_rect.width - r.width; 137 if(r.width > 0 && r.height > 0) 138 { 139 int alpha = priv->alpha_enable ? (int)(0xff * percent) & 0xff : 0xff; 140 dst_r = r; 141 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->front_win, &r, &dst_r, alpha); 142 } 143 144 return RET_OK; 145} 146 147static Ret ftk_animation_expand_step_base_bottom(FtkAnimation* thiz, float percent) 148{ 149 FtkRect r = {0}; 150 FtkRect dst_r = {0}; 151 DECL_PRIV(thiz, priv); 152 153 r = priv->back_win_rect; 154 if(r.width > 0 && r.height > 0) 155 { 156 dst_r = r; 157 if(priv->push) 158 { 159 int offset = (int)(priv->front_win_rect.height * percent); 160 r.y = r.y + offset; 161 dst_r.height = r.height = r.height - offset; 162 } 163 164 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->back_win, &r, &dst_r, 0xff); 165 } 166 167 r = priv->front_win_rect; 168 r.height = (int)(r.height * percent); 169 r.y = r.y + priv->front_win_rect.height - r.height; 170 if(r.width > 0 && r.height > 0) 171 { 172 int alpha = priv->alpha_enable ? (int)(0xff * percent) & 0xff : 0xff; 173 dst_r = r; 174 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->front_win, &r, &dst_r, alpha); 175 } 176 177 return RET_OK; 178} 179 180static Ret ftk_animation_expand_step_base_center(FtkAnimation* thiz, float percent) 181{ 182 FtkRect r = {0}; 183 FtkRect dst_r = {0}; 184 DECL_PRIV(thiz, priv); 185 186 r = priv->back_win_rect; 187 if(r.width > 0 && r.height > 0) 188 { 189 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->back_win, &r, &r, 0xff); 190 } 191 192 r = priv->front_win_rect; 193 r.width = (int)(r.width * percent); 194 r.height = (int)(r.height * percent); 195 196 if(r.width > 0 && r.height > 0) 197 { 198 int alpha = priv->alpha_enable ? (int)(0xff * percent) & 0xff : 0xff; 199 dst_r = r; 200 dst_r.x = r.x + (priv->front_win_rect.width - r.width)/2; 201 dst_r.y = r.y + (priv->front_win_rect.height - r.height)/2; 202 r.x = dst_r.x; 203 r.y = dst_r.y; 204 205 ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->front_win, &r, &dst_r, alpha); 206 } 207 208 return RET_OK; 209} 210 211static Ret ftk_animation_expand_step(FtkAnimation* thiz) 212{ 213 FtkRect rf = {0}; 214 FtkRect rs = {0}; 215 float percent = 0; 216 DECL_PRIV(thiz, priv); 217 const char* base = ftk_animation_get_param(thiz, "base"); 218 return_val_if_fail(base != NULL, RET_FAIL); 219 220 percent = priv->start + (priv->end - priv->start) * ftk_animation_get_percent(thiz); 221 222 if(strcmp(base, "left") == 0) 223 { 224 ftk_animation_expand_step_base_left(thiz, percent); 225 } 226 else if(strcmp(base, "top") == 0) 227 { 228 ftk_animation_expand_step_base_top(thiz, percent); 229 } 230 else if(strcmp(base, "right") == 0) 231 { 232 ftk_animation_expand_step_base_right(thiz, percent); 233 } 234 else if(strcmp(base, "bottom") == 0) 235 { 236 ftk_animation_expand_step_base_bottom(thiz, percent); 237 } 238 else 239 { 240 ftk_animation_expand_step_base_center(thiz, percent); 241 } 242 243 rf = priv->back_win_rect; 244 rs = priv->front_win_rect; 245 rf.x = FTK_MIN(rf.x, rs.x); 246 rf.y = FTK_MIN(rf.y, rs.y); 247 rf.width = FTK_MAX(rf.width, rs.width); 248 rf.height = FTK_MAX(rf.height, rs.height); 249 250 ftk_canvas_show(ftk_shared_canvas(), ftk_default_display(), &rf, rf.x, rf.y); 251 252 return RET_OK; 253} 254 255static Ret ftk_animation_expand_reset(FtkAnimation* thiz, FtkBitmap* old_win, FtkBitmap* new_win, 256 FtkRect* old_win_rect, FtkRect* new_win_rect) 257{ 258 DECL_PRIV(thiz, priv); 259 const char* src = ftk_animation_get_param(thiz, "src"); 260 const char* push = ftk_animation_get_param(thiz, "push"); 261 const char* alpha_enable = ftk_animation_get_param(thiz, "alpha"); 262 return_val_if_fail(src != NULL, RET_FAIL); 263 264 priv->start = ftk_animation_get_param_float(thiz, "from", 1.0); 265 priv->end = ftk_animation_get_param_float(thiz, "to", 1.0); 266 priv->push = push != NULL && strcmp(push, "true") == 0; 267 priv->alpha_enable = alpha_enable != NULL && strcmp(alpha_enable, "enable") == 0; 268 269 if(strstr(src, "new_window") != NULL) 270 { 271 priv->back_win = old_win; 272 priv->back_win_rect = *old_win_rect; 273 274 priv->front_win = new_win; 275 priv->front_win_rect = *new_win_rect; 276 } 277 else 278 { 279 priv->back_win = new_win; 280 priv->back_win_rect = *new_win_rect; 281 282 priv->front_win = old_win; 283 priv->front_win_rect = *old_win_rect; 284 } 285 286 ftk_logd("%s: src=%s start=%f end=%f old(%d %d %d %d) new(%d %d %d %d)", 287 __func__, src, priv->start, priv->end, 288 old_win_rect->x, old_win_rect->y, old_win_rect->width, old_win_rect->height, 289 new_win_rect->x, new_win_rect->y, new_win_rect->width, new_win_rect->height); 290 291 return RET_OK; 292} 293 294static void ftk_animation_expand_destroy(FtkAnimation* thiz) 295{ 296 FTK_FREE(thiz); 297 298 return; 299} 300 301FtkAnimation* ftk_animation_expand_create(void) 302{ 303 FtkAnimation* thiz = FTK_NEW_PRIV(FtkAnimation); 304 305 if(thiz != NULL) 306 { 307 ftk_animation_set_name(thiz, "expand"); 308 thiz->step = ftk_animation_expand_step; 309 thiz->reset = ftk_animation_expand_reset; 310 thiz->destroy = ftk_animation_expand_destroy; 311 } 312 313 return thiz; 314} 315