y_tdmorph.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // y_tdmorph - morphs a textdraw from one style to another. You can use this to
  2. // fade them in and out (same location, different colour), move them across the
  3. // screen (same style, different location) or do almost anything else (shrink,
  4. // grow, bounce about etc).
  5. forward MorphTD(Text:td, Style:from, Style:to, speed, pos);
  6. public MorphTD(Text:td, Style:from, Style:to, speed, pos)
  7. {
  8. // Morph a text draw from one style to another.
  9. stock
  10. sFrom[E_TD_DATA],
  11. sTo[E_TD_DATA],
  12. sCur[E_TD_DATA];
  13. // Get the end style.
  14. TD_GetStyle(to, sTo);
  15. if (pos == speed)
  16. {
  17. // Show the TD using the end point only (no interpolation).
  18. // We could add a callback here to indicate that the morph is done.
  19. }
  20. else
  21. {
  22. // Get the start style.
  23. TD_GetStyle(from, sFrom);
  24. // Interpolate.
  25. #define MORPH_TD_FROM_TO(%0) sCur[E_TD_DATA_%0] = (sTo[E_TD_DATA_%0] - sFrom[E_TD_DATA_%0]) * pos / speed + sFrom[E_TD_DATA_%0]
  26. MORPH_TD_FROM_TO(X);
  27. MORPH_TD_FROM_TO(Y);
  28. MORPH_TD_FROM_TO(LX);
  29. MORPH_TD_FROM_TO(LY);
  30. MORPH_TD_FROM_TO(TX);
  31. MORPH_TD_FROM_TO(TY);
  32. MORPH_TD_FROM_TO(COLOUR);
  33. MORPH_TD_FROM_TO(BITS);
  34. MORPH_TD_FROM_TO(BOX);
  35. MORPH_TD_FROM_TO(BG);
  36. #undef MORPH_TD_FROM_TO
  37. // Show the interpolated TD data.
  38. }
  39. }