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.

228 lines
5.5 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: ssinit.cxx
  3. *
  4. * Main code for common screen saver functions.
  5. *
  6. * Created: 12-24-94 -by- Marc Fortier [marcfo]
  7. *
  8. * Copyright (c) 1994 Microsoft Corporation
  9. \**************************************************************************/
  10. #include <windows.h>
  11. #include <commdlg.h>
  12. #include <scrnsave.h>
  13. #include <GL\gl.h>
  14. #include "tk.h"
  15. #include <math.h>
  16. #include <memory.h>
  17. #include <string.h>
  18. #include <stdarg.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <malloc.h>
  22. #include <time.h>
  23. #include "ssintrnl.hxx"
  24. void *gDataPtr = NULL; // data ptr used with callbacks
  25. // function protos
  26. void (*gReshapeFunc)(int, int, void *) = NULL;
  27. void (*gRepaintFunc)(LPRECT, void *) = NULL;
  28. void (*gUpdateFunc)( void *) = NULL;
  29. void (*gInitFunc)( void *) = NULL;
  30. void (*gFinishFunc)( void *) = NULL;
  31. void (*gFloaterBounceFunc)( void *) = NULL;
  32. // Debug stuff
  33. #if DBG
  34. #ifdef SS_DEBUG
  35. long ssDebugMsg = 1;
  36. long ssDebugLevel = SS_LEVEL_INFO;
  37. #else
  38. long ssDebugMsg = 0;
  39. long ssDebugLevel = SS_LEVEL_ERROR;
  40. #endif
  41. #endif
  42. // Callback functions:
  43. /******************************Public*Routine******************************\
  44. * ss_InitFunc
  45. *
  46. \**************************************************************************/
  47. void
  48. ss_InitFunc(SSINITPROC Func)
  49. {
  50. gInitFunc = Func;
  51. }
  52. /******************************Public*Routine******************************\
  53. * ss_ReshapeFunc
  54. *
  55. \**************************************************************************/
  56. void
  57. ss_ReshapeFunc(SSRESHAPEPROC Func)
  58. {
  59. gReshapeFunc = Func;
  60. if( gpss->psswGL )
  61. gpss->psswGL->ReshapeFunc = gReshapeFunc;
  62. }
  63. /******************************Public*Routine******************************\
  64. * ss_RepaintFunc
  65. *
  66. \**************************************************************************/
  67. void
  68. ss_RepaintFunc(SSREPAINTPROC Func)
  69. {
  70. gRepaintFunc = Func;
  71. if( gpss->psswGL )
  72. gpss->psswGL->RepaintFunc = gRepaintFunc;
  73. }
  74. /******************************Public*Routine******************************\
  75. * ss_UpdateFunc
  76. *
  77. \**************************************************************************/
  78. void
  79. ss_UpdateFunc(SSUPDATEPROC Func)
  80. {
  81. gUpdateFunc = Func;
  82. if( gpss->psswGL )
  83. gpss->psswGL->UpdateFunc = gUpdateFunc;
  84. }
  85. /******************************Public*Routine******************************\
  86. * ss_FinishFunc
  87. *
  88. \**************************************************************************/
  89. void
  90. ss_FinishFunc(SSFINISHPROC Func)
  91. {
  92. gFinishFunc = Func;
  93. if( gpss->psswGL )
  94. gpss->psswGL->FinishFunc = gFinishFunc;
  95. }
  96. /******************************Public*Routine******************************\
  97. * ss_FloaterBounceFunc
  98. *
  99. \**************************************************************************/
  100. void
  101. ss_FloaterBounceFunc(SSFLOATERBOUNCEPROC Func)
  102. {
  103. gFloaterBounceFunc = Func;
  104. if( gpss->psswGL )
  105. gpss->psswGL->FloaterBounceFunc = gFloaterBounceFunc;
  106. }
  107. /******************************Public*Routine******************************\
  108. * ss_DataPtr
  109. *
  110. * Sets data ptr to be sent with callbacks
  111. *
  112. \**************************************************************************/
  113. void
  114. ss_DataPtr( void *data )
  115. {
  116. gDataPtr = data;
  117. if( gpss->psswGL )
  118. gpss->psswGL->DataPtr = gDataPtr;
  119. }
  120. /******************************Public*Routine******************************\
  121. * RandomWindowPos
  122. *
  123. * Sets a new random window position and direction.
  124. *
  125. \**************************************************************************/
  126. void
  127. ss_RandomWindowPos()
  128. {
  129. if( gpss->psswGL )
  130. gpss->psswGL->RandomWindowPos();
  131. }
  132. /******************************Public*Routine******************************\
  133. * ss_SetWindowAspectRatio
  134. *
  135. * Resize the window to conform to the supplied aspect ratio. We do this by
  136. * maintaining the existing width, and adjusting the height.
  137. *
  138. * Window resize seems to be executed synchronously, so gl should be able to
  139. * immediately validate its buffer dimensions (we count on it).
  140. *
  141. * Returns TRUE if new height is different from last, else FALSE.
  142. \**************************************************************************/
  143. BOOL
  144. ss_SetWindowAspectRatio( FLOAT aspect )
  145. {
  146. if( gpss->psswGL )
  147. return gpss->psswGL->SetAspectRatio( aspect );
  148. return FALSE;
  149. }
  150. /******************************Public*Routine******************************\
  151. * ss_GetScreenSize
  152. *
  153. * Returns size of screen saver window
  154. *
  155. \**************************************************************************/
  156. void
  157. ss_GetScreenSize( ISIZE *size )
  158. {
  159. if( gpss->psswMain )
  160. *size = gpss->psswMain->size;
  161. }
  162. /******************************Public*Routine******************************\
  163. * ss_GetHWND
  164. *
  165. * Return HWND of the main window
  166. \**************************************************************************/
  167. HWND
  168. ss_GetHWND()
  169. {
  170. if( gpss->psswMain )
  171. return gpss->psswMain->hwnd;
  172. return NULL;
  173. }
  174. /******************************Public*Routine******************************\
  175. * ss_GetGLHWND
  176. *
  177. * Return HWND of the GL window
  178. \**************************************************************************/
  179. HWND
  180. ss_GetGLHWND()
  181. {
  182. if( gpss->psswGL )
  183. return gpss->psswGL->hwnd;
  184. return NULL;
  185. }
  186. /******************************Public*Routine******************************\
  187. * ss_GetMainPSSW
  188. *
  189. * Return PSSW of top level window
  190. \**************************************************************************/
  191. PSSW
  192. ss_GetMainPSSW()
  193. {
  194. if( gpss->psswMain )
  195. return gpss->psswMain;
  196. return NULL;
  197. }