hovereffect.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // -----------------------------------------------------------
  2. class HoverEffect : ScriptedWidgetEventHandler
  3. {
  4. reference float speed;
  5. reference float amount;
  6. protected float m_orginal_width;
  7. protected float m_orginal_height;
  8. protected Widget m_root;
  9. protected ref AnimatorTimer m_anim;
  10. void HoverEffect()
  11. {
  12. m_anim = new AnimatorTimer();
  13. }
  14. // -----------------------------------------------------------
  15. void OnWidgetScriptInit(Widget w)
  16. {
  17. m_root = w;
  18. m_root.SetHandler(this);
  19. }
  20. // -----------------------------------------------------------
  21. protected void Update()
  22. {
  23. float p = amount * m_anim.GetValue();
  24. m_root.SetSize(m_orginal_width + (m_orginal_width * p), m_orginal_height + (m_orginal_height * p));
  25. float c = 1.0 - (0.5 * m_anim.GetValue());
  26. m_root.SetColor(ARGBF(1, 1, c, c));
  27. }
  28. // -----------------------------------------------------------
  29. override bool OnMouseEnter(Widget w, int x, int y)
  30. {
  31. if ( !m_anim.IsRunning() ) m_root.GetSize(m_orginal_width, m_orginal_height);
  32. m_anim.Animate(1.0, speed);
  33. return false;
  34. }
  35. // -----------------------------------------------------------
  36. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  37. {
  38. m_anim.Animate(0.0, speed);
  39. return false;
  40. }
  41. };