animation.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "./animation.h"
  2. #include "./common.h"
  3. BOOL Animation_Initialize(ANIMATIONDATA *animation, UINT durationMs)
  4. {
  5. if (NULL == animation)
  6. return FALSE;
  7. if (FALSE == QueryPerformanceFrequency(&animation->frequency))
  8. return FALSE;
  9. QueryPerformanceCounter(&animation->completion);
  10. animation->completion.QuadPart += animation->frequency.QuadPart*durationMs/1000LL;
  11. return TRUE;
  12. }
  13. BOOL Animation_BeginStep(ANIMATIONDATA *animation)
  14. {
  15. if (NULL == animation || FALSE == QueryPerformanceCounter(&animation->stepBegin))
  16. return FALSE;
  17. return TRUE;
  18. }
  19. BOOL Animation_EndStep(ANIMATIONDATA *animation, size_t stepsRemaining)
  20. {
  21. if (NULL == animation || FALSE == QueryPerformanceCounter(&animation->stepEnd))
  22. return FALSE;
  23. if (0 == stepsRemaining || animation->stepEnd.QuadPart >= animation->completion.QuadPart)
  24. return TRUE;
  25. LARGE_INTEGER sleep;
  26. sleep.QuadPart = (animation->completion.QuadPart - animation->stepEnd.QuadPart) -
  27. (stepsRemaining * (animation->stepEnd.QuadPart - animation->stepBegin.QuadPart));
  28. if (stepsRemaining > 1)
  29. sleep.QuadPart /= (stepsRemaining -1);
  30. if (sleep.QuadPart <= 0)
  31. return TRUE;
  32. sleep.QuadPart += animation->stepEnd.QuadPart;
  33. do
  34. {
  35. SleepEx(0, FALSE);
  36. QueryPerformanceCounter(&animation->stepEnd);
  37. } while(sleep.QuadPart > animation->stepEnd.QuadPart);
  38. return TRUE;
  39. }
  40. BOOL Animation_SetWindowPos(HWND hwnd, INT x, INT y, INT cx, INT cy, UINT flags, HDC hdc, INT contextX, INT contextY)
  41. {
  42. if (NULL == hwnd ||
  43. FALSE == SetWindowPos(hwnd, NULL, x, y, cx, cy,
  44. flags | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOCOPYBITS))
  45. {
  46. return FALSE;
  47. }
  48. UINT windowStyle = GetWindowStyle(hwnd);
  49. POINT origPoint;
  50. SetViewportOrgEx(hdc, contextX, contextY, &origPoint);
  51. if (0 == (WS_VISIBLE & windowStyle))
  52. SetWindowLongPtr(hwnd, GWL_STYLE, windowStyle | WS_VISIBLE);
  53. if (FALSE == LoginBox_PrintWindow(hwnd, hdc, 0))
  54. SendMessage(hwnd, WM_PRINT, (WPARAM)hdc, (LPARAM)(PRF_CLIENT | PRF_ERASEBKGND | PRF_CHILDREN | PRF_NONCLIENT));
  55. if (0 == (WS_VISIBLE & windowStyle))
  56. SetWindowLongPtr(hwnd, GWL_STYLE, windowStyle & ~WS_VISIBLE);
  57. SetViewportOrgEx(hdc, origPoint.x, origPoint.y, NULL);
  58. return TRUE;
  59. }