📄 animate_n.cpp
字号:
lib::timer::time_type t = this->m_timer->elapsed(); lib::color_t cl = this->m_animate_f->at(t); if(this->m_aattrs->is_additive()) regs.cl += cl; // add else regs.cl = cl; // override }};class underlying_to_color_animation : public underlying_to_animation<lib::color_t> { public: underlying_to_color_animation(context_type *ctx, const node *n, animate_attrs *aattrs) : underlying_to_animation<lib::color_t>(ctx, n, aattrs) {} void read_dom_value(common::animation_destination *dst, animate_registers& regs) const { regs.cl = dst->get_region_color(m_aattrs->get_target_attr(), true); } bool set_animated_value(common::animation_destination *dst, animate_registers& regs) const { lib::color_t cl = dst->get_region_color(m_aattrs->get_target_attr(), false); if(cl != regs.cl || IGNORE_ATTR_COMP) { AM_DBG { lib::timer::time_type t = m_timer->elapsed(); lib::logger::get_logger()->debug("%s(%ld) -> 0x%x", m_aattrs->get_target_attr().c_str(), t, regs.cl); } dst->set_region_color(m_aattrs->get_target_attr(), regs.cl); return true; } return false; } void apply_self_effect(animate_registers& regs) const { if(!m_animate_f) return; lib::timer::time_type t = m_timer->elapsed(); regs.cl = m_animate_f->at(t, regs.cl); // override }};////////////////////////////////////template <class F>class zindex_animation : public linear_values_animation<F, common::zindex_t> { public: zindex_animation(time_node_context *ctx, const node *n, animate_attrs *aattrs) : linear_values_animation<F, common::zindex_t>(ctx, n, aattrs) {} void read_dom_value(common::animation_destination *dst, animate_registers& regs) const { regs.zi = dst->get_region_zindex(true); } bool set_animated_value(common::animation_destination *dst, animate_registers& regs) const { common::zindex_t zi = dst->get_region_zindex(false); if(zi != regs.zi || IGNORE_ATTR_COMP) { AM_DBG { lib::timer::time_type t = this->m_timer->elapsed(); lib::logger::get_logger()->debug("%s(%ld) -> %d", this->m_aattrs->get_target_attr().c_str(), t, regs.zi); } dst->set_region_zindex(regs.zi); return true; } return false; } void apply_self_effect(animate_registers& regs) const { if(!this->m_animate_f) return; lib::timer::time_type t = this->m_timer->elapsed(); common::zindex_t zi = this->m_animate_f->at(t); if(this->m_aattrs->is_additive()) regs.zi += zi; // add else regs.zi = zi; // override }};class underlying_to_zindex_animation : public underlying_to_animation<common::zindex_t> { public: underlying_to_zindex_animation(context_type *ctx, const node *n, animate_attrs *aattrs) : underlying_to_animation<int>(ctx, n, aattrs) {} void read_dom_value(common::animation_destination *dst, animate_registers& regs) const { regs.zi = dst->get_region_zindex(true); } bool set_animated_value(common::animation_destination *dst, animate_registers& regs) const { common::zindex_t zi = dst->get_region_zindex(false); if(zi != regs.zi || IGNORE_ATTR_COMP) { AM_DBG { lib::timer::time_type t = m_timer->elapsed(); lib::logger::get_logger()->debug("%s(%ld) -> %d", m_aattrs->get_target_attr().c_str(), t, regs.zi); } dst->set_region_zindex(regs.zi); return true; } return false; } void apply_self_effect(animate_registers& regs) const { if(!m_animate_f) return; lib::timer::time_type t = m_timer->elapsed(); common::zindex_t zi = m_animate_f->at(t, regs.zi); regs.zi = zi; // override }};////////////////////////////////////// values_motion_animation//// A values_motion_animation may be used for all position animations except for "to" and "path" animations// // Animateable region/subregion attributes: "position"template <class F>class values_motion_animation : public linear_values_animation<F, lib::point> { public: values_motion_animation(time_node_context *ctx, const node *n, animate_attrs *aattrs) : linear_values_animation<F, lib::point>(ctx, n, aattrs) {} void read_dom_value(common::animation_destination *dst, animate_registers& regs) const { common::region_dim left = dst->get_region_dim("left", true); common::region_dim top = dst->get_region_dim("top", true); regs.pt.x = left.get_as_int(); regs.pt.y = top.get_as_int(); } bool set_animated_value(common::animation_destination *dst, animate_registers& regs) const { region_dim left = dst->get_region_dim("left", false); region_dim top = dst->get_region_dim("top", false); lib::point pt(left.get_as_int(), top.get_as_int()); if(pt != regs.pt || IGNORE_ATTR_COMP) { AM_DBG { lib::timer::time_type t = this->m_timer->elapsed(); lib::logger::get_logger()->debug("%s(%ld) -> %s", this->m_aattrs->get_target_attr().c_str(), t, ::repr(regs.pt).c_str()); } dst->set_region_dim("left", common::region_dim(regs.pt.x)); dst->set_region_dim("top", common::region_dim(regs.pt.y)); return true; } return false; } void apply_self_effect(animate_registers& regs) const { if(!this->m_animate_f) return; lib::timer::time_type t = this->m_timer->elapsed(); lib::point pt = this->m_animate_f->at(t); if(this->m_aattrs->is_additive()) regs.pt += pt; // add else regs.pt = pt; // override }};class underlying_to_motion_animation : public underlying_to_animation<lib::point> { public: underlying_to_motion_animation(context_type *ctx, const node *n, animate_attrs *aattrs) : underlying_to_animation<lib::point>(ctx, n, aattrs) {} void read_dom_value(common::animation_destination *dst, animate_registers& regs) const { common::region_dim left = dst->get_region_dim("left", true); common::region_dim top = dst->get_region_dim("top", true); regs.pt.x = left.get_as_int(); regs.pt.y = top.get_as_int(); } bool set_animated_value(common::animation_destination *dst, animate_registers& regs) const { region_dim left = dst->get_region_dim("left", false); region_dim top = dst->get_region_dim("top", false); lib::point pt(left.get_as_int(), top.get_as_int()); if(pt != regs.pt || IGNORE_ATTR_COMP) { AM_DBG { lib::timer::time_type t = m_timer->elapsed(); lib::logger::get_logger()->debug("%s(%ld) -> %s", m_aattrs->get_target_attr().c_str(), t, ::repr(regs.pt).c_str()); } dst->set_region_dim("left", common::region_dim(regs.pt.x)); dst->set_region_dim("top", common::region_dim(regs.pt.y)); return true; } return false; } void apply_self_effect(animate_registers& regs) const { if(!m_animate_f) return; lib::timer::time_type t = m_timer->elapsed(); lib::point pt = m_animate_f->at(t, regs.pt); regs.pt = pt; // override }};class soundalign_animation : public animate_node { public: soundalign_animation(context_type *ctx, const node *n, animate_attrs *aattrs); ~soundalign_animation(); void read_dom_value(common::animation_destination *dst, animate_registers& regs) const; bool set_animated_value(common::animation_destination *dst, animate_registers& regs) const; void apply_self_effect(animate_registers& regs) const; private: std::vector<common::sound_alignment> m_values;};soundalign_animation::soundalign_animation(context_type *ctx, const node *n, animate_attrs *aattrs): animate_node(ctx, n, aattrs){ m_aattrs->get_values(m_values); assert(m_values.size() == 1);}soundalign_animation::~soundalign_animation(){}voidsoundalign_animation::read_dom_value(common::animation_destination *dst, animate_registers& regs) const{ regs.sa = dst->get_region_soundalign(true);}boolsoundalign_animation::set_animated_value(common::animation_destination *dst, animate_registers& regs) const{ common::sound_alignment sa = dst->get_region_soundalign(false); if (sa != regs.sa) { dst->set_region_soundalign(regs.sa); return true; } return false;}voidsoundalign_animation::apply_self_effect(animate_registers& regs) const{ regs.sa = m_values[0];}////////////////////////////////////// animate_node factory functions// private static animate_node* animate_node::new_regdim_animation(context_type *ctx, const node *n, animate_attrs *aattrs) { typedef common::region_dim attr_t; if(aattrs->is_discrete()) { typedef discrete_map_f<attr_t> F; return new regdim_animation<F>(ctx, n, aattrs); } else if(aattrs->get_animate_type() == "to") { return new underlying_to_regdim_animation(ctx, n, aattrs); } typedef linear_map_f<attr_t> F; return new regdim_animation<F>(ctx, n, aattrs);}// private static animate_node* animate_node::new_color_animation(context_type *ctx, const node *n, animate_attrs *aattrs) { typedef lib::color_t attr_t; if(aattrs->is_discrete()) { typedef discrete_map_f<attr_t> F; return new color_animation<F>(ctx, n, aattrs); } else if(aattrs->get_animate_type() == "to") { return new underlying_to_color_animation(ctx, n, aattrs); } typedef linear_map_f<attr_t> F; return new color_animation<F>(ctx, n, aattrs);}// private static animate_node* animate_node::new_zindex_animation(context_type *ctx, const node *n, animate_attrs *aattrs) { typedef common::zindex_t attr_t; if(aattrs->is_discrete()) { typedef discrete_map_f<attr_t> F; return new zindex_animation<F>(ctx, n, aattrs); } else if(aattrs->get_animate_type() == "to") { return new underlying_to_zindex_animation(ctx, n, aattrs); } typedef linear_map_f<attr_t> F; return new zindex_animation<F>(ctx, n, aattrs);}animate_node* animate_node::new_soundalign_animation(context_type *ctx, const node *n, animate_attrs *aattrs) { typedef common::sound_alignment attr_t; assert(aattrs->is_discrete()); typedef discrete_map_f<attr_t> F; return new soundalign_animation(ctx, n, aattrs);}// private static animate_node* animate_node::new_position_animation(context_type *ctx, const node *n, animate_attrs *aattrs) { typedef lib::point attr_t; if(aattrs->is_discrete()) { typedef discrete_map_f<attr_t> F; return new values_motion_animation<F>(ctx, n, aattrs); } else if(aattrs->get_animate_type() == "to") { return new underlying_to_motion_animation(ctx, n, aattrs); } typedef linear_map_f<attr_t> F; return new values_motion_animation<F>(ctx, n, aattrs);}// public static animate_node* animate_node::new_instance(context_type *ctx, const node *n, const node* tparent) { animate_attrs *aattrs = new animate_attrs(n, tparent); // Placeholder if(aattrs->get_animate_type() == "invalid") return new animate_node(ctx, n, aattrs); // Implemented animations if(aattrs->get_target_attr_type() == "reg_dim") { return new_regdim_animation(ctx, n, aattrs); } else if(aattrs->get_target_attr_type() == "color") { return new_color_animation(ctx, n, aattrs); } else if(aattrs->get_target_attr() == "z-index") { return new_zindex_animation(ctx, n, aattrs); } else if(aattrs->get_target_attr() == "position") { return new_position_animation(ctx, n, aattrs); } else if(aattrs->get_target_attr() == "soundAlign") { return new_soundalign_animation(ctx, n, aattrs); } // Not implemented return new animate_node(ctx, n, aattrs);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -