Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.4 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: loginit.cxx
  3. *
  4. * Copyright (c) 1997 Microsoft Corporation
  5. *
  6. \**************************************************************************/
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <math.h>
  10. #include <sys/types.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13. #include "uidemo.hxx"
  14. #include "logon.hxx"
  15. #include "logobj.hxx"
  16. static void InitMotion();
  17. static BOOL
  18. SetNextPos( LOG_OBJECT *pObj )
  19. {
  20. static float inc = 0.1f;
  21. static float max = 2.0f;
  22. pObj->dest[0] += inc;
  23. pObj->dest[1] += inc;
  24. if( (pObj->dest[0] > max) ||
  25. (pObj->dest[1] > max) )
  26. return FALSE;
  27. return TRUE;
  28. }
  29. static void DrawTestSequence(void)
  30. {
  31. int i;
  32. BOOL bTransitionOver = TRUE;
  33. float updatesPerSecond;
  34. LOG_OBJECT *pObj;
  35. static BOOL bRed = TRUE;
  36. // Clear current rect of object
  37. ClearWindow();
  38. // Calculate next position for each object
  39. for (i = 0; i < nLogObj; i++) {
  40. if( bSwapHints )
  41. // Add current rect of object
  42. AddSwapHintRect( &pLogObj[i]->rect );
  43. // SetNextPos returns TRUE if object still moving, else FALSE
  44. if( SetNextPos( pLogObj[i] ) )
  45. bTransitionOver = FALSE;
  46. // Calc new rect for the object
  47. CalcObjectWindowRect( pLogObj[i] );
  48. if( bSwapHints )
  49. // Add new rect of object
  50. AddSwapHintRect( &pLogObj[i]->rect );
  51. }
  52. DrawObjects( FALSE );
  53. #if 0
  54. if( !bRed ) {
  55. //mf: test to make sure swap rects working
  56. glPushMatrix();
  57. glColor3f( 0.0f, 1.0f, 0.0f );
  58. glTranslatef( -3.5f, 0.0f, 0.0f );
  59. DrawQuad( 0.5f );
  60. glPopMatrix();
  61. }
  62. #endif
  63. Flush();
  64. // Print timing information if required
  65. if( bDebugMode ) {
  66. char szMsg[80];
  67. if( bTransitionOver ) {
  68. sprintf(szMsg, "%s: %.2lf sec, %s",
  69. "Transition time ",
  70. transitionTimer.Stop(), "Press <space> to restart" );
  71. // Print transition timing info in title bar
  72. SetWindowText( mtkWin->GetHWND(), szMsg );
  73. } else if( frameRateTimer.Update( 1, &updatesPerSecond ) ) {
  74. sprintf(szMsg, "%s: %.2lf frames/sec",
  75. "",
  76. updatesPerSecond );
  77. // Print frame timing info in title bar
  78. SetWindowText( mtkWin->GetHWND(), szMsg );
  79. }
  80. }
  81. if( bTransitionOver ) {
  82. InitMotion(); // start over
  83. }
  84. bRed = !bRed;
  85. if( bRed )
  86. glColor3f( 1.0f, 0.0f, 0.0f );
  87. else
  88. glColor3f( 0.0f, 0.0f, 1.0f );
  89. }
  90. static void
  91. InitMotion()
  92. {
  93. for (int i = 0; i < nLogObj; i++) {
  94. pLogObj[i]->Reset();
  95. }
  96. MoveObjectsToRestPosition();
  97. }
  98. BOOL RunTestSequence()
  99. {
  100. SS_DBGPRINT( "RunTestSequence()\n" );
  101. // Set GL attributes
  102. glDisable( GL_CULL_FACE );
  103. glColor3f( 1.0f, 0.0f, 0.0f );
  104. glDisable( GL_TEXTURE_2D );
  105. InitMotion();
  106. // Calc window rects of the quads
  107. UpdateLocalTransforms( UPDATE_ALL );
  108. CalcObjectWindowRects();
  109. // Timers
  110. if( bDebugMode ) {
  111. frameRateTimer.Reset();
  112. frameRateTimer.Start();
  113. transitionTimer.Reset();
  114. transitionTimer.Start();
  115. }
  116. // Clear window
  117. ClearAll();
  118. // Set mtk callbacks
  119. mtkWin->SetKeyDownFunc(Key);
  120. mtkWin->SetDisplayFunc( DrawTestSequence );
  121. mtkWin->SetAnimateFunc( DrawTestSequence );
  122. return mtkWin->Exec();
  123. }