home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / 3d / irit / grapdrvs / wnt_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  13.6 KB  |  294 lines

  1. /*****************************************************************************
  2. *   A Windows NT driver - regular NT graphics calls.                 *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <windows.h>
  9. #include "irit_sm.h"
  10. #include "genmat.h"
  11. #include "iritprsr.h"
  12. #include "allocate.h"
  13. #include "attribut.h"
  14. #include "ip_cnvrt.h"
  15. #include "cagd_lib.h"
  16. #include "symb_lib.h"
  17. #include "iritgrap.h"
  18. #include "wntdrvs.h"
  19.  
  20. /*****************************************************************************
  21. * DESCRIPTION:                                                               M
  22. * Redraw the viewing window.                             M
  23. *                                                                            *
  24. * PARAMETERS:                                                                M
  25. *   none                                                                 M
  26. *                                                                            *
  27. * RETURN VALUE:                                                              M
  28. *   void                                                                 M
  29. *                                                                            *
  30. * KEYWORDS:                                                                  M
  31. *   IGRedrawViewWindow                                                       M
  32. *****************************************************************************/
  33. void IGRedrawViewWindow(void)
  34. {
  35.     RedrawViewWindow(IGhWndView, WM_PAINT, 0);
  36. }
  37.  
  38. /*****************************************************************************
  39. * DESCRIPTION:                                                               M
  40. * Redraw the viewing window.                             M
  41. *                                                                            *
  42. * PARAMETERS:                                                                M
  43. *   hWnd:     Handle on window to draw to.                                   M
  44. *   wMsg:     Event to handle.                                               M
  45. *   wParam:   Some parameters of event.                                      M
  46. *                                                                            *
  47. * RETURN VALUE:                                                              M
  48. *   int:      Window's condition.                                            M
  49. *                                                                            *
  50. * KEYWORDS:                                                                  M
  51. *   RedrawViewWindow                                                         M
  52. *****************************************************************************/
  53. int RedrawViewWindow(HWND hWnd, UINT wMsg, WPARAM wParam)
  54. {
  55.     PAINTSTRUCT ps;
  56.  
  57.     if (wMsg != WM_PAINT)
  58.     return 0;
  59.  
  60.     switch (IGGlblViewMode) {         /* Update the current view. */
  61.     case IG_VIEW_ORTHOGRAPHIC:
  62.         GEN_COPY(IGGlblCrntViewMat, IritPrsrViewMat, sizeof(MatrixType));
  63.         break;
  64.     case IG_VIEW_PERSPECTIVE:
  65.         MatMultTwo4by4(IGGlblCrntViewMat, IritPrsrViewMat,
  66.                             IritPrsrPrspMat);
  67.         break;
  68.     }
  69.  
  70.     if (IGCurrenthDC = BeginPaint(hWnd, &ps)) {
  71.     RECT rect;
  72.     IPObjectStruct *PObj;
  73.  
  74.     GetClientRect(hWnd, &rect);
  75.     FillRect(IGCurrenthDC, &rect, IGBackGroundBrush);
  76.  
  77.     /* Slim chance that a race will oocur if the following test and set */
  78.     /* is done simultanuously. Should use semaphors probably.        */
  79.     while (IGGlblDisplayListIsUsed)
  80.         IritSleep(10);
  81.     IGGlblDisplayListIsUsed = TRUE;
  82.  
  83.     for (PObj = IGGlblDisplayList, IGGlblAbortKeyPressed = FALSE;
  84.          PObj != NULL && !IGGlblAbortKeyPressed;
  85.          PObj = PObj -> Pnext)
  86.         IGDrawObject(PObj);
  87.  
  88.     IGGlblDisplayListIsUsed = FALSE;
  89.  
  90.     if (IGCurrenthPen)
  91.             DeleteObject(SelectObject(IGCurrenthDC, IGCurrenthPen));
  92.     EndPaint(hWnd, &ps);
  93.     IGCurrenthDC = 0;
  94.     IGCurrenthPen = 0;
  95.     }
  96.  
  97.     return 0;
  98. }
  99.  
  100. /*****************************************************************************
  101. * DESCRIPTION:                                                               M
  102. * Low level 2D drawing routine. Coordinates are normalized to -1 to 1 by     M
  103. * this time.                                                                 M
  104. *                                                                            *
  105. * PARAMETERS:                                                                M
  106. *   X, Y:    Coordinates of 2D location to move to.                          M
  107. *                                                                            *
  108. * RETURN VALUE:                                                              M
  109. *   void                                                                     M
  110. *                                                                            *
  111. * KEYWORDS:                                                                  M
  112. *   IGMoveTo2D                                                               M
  113. *****************************************************************************/
  114. void IGMoveTo2D(RealType X, RealType Y)
  115. {
  116.     int x, y;
  117.  
  118.     MoveToEx(IGCurrenthDC, x = WNT_MAP_X_COORD(X), y = WNT_MAP_Y_COORD(Y), NULL);
  119. }
  120.  
  121. /*****************************************************************************
  122. * DESCRIPTION:                                                               M
  123. * Low level 2D drawing routine. Coordinates are normalized to -1 to 1 by     M
  124. * this time.                                                                 M
  125. *                                                                            *
  126. * PARAMETERS:                                                                M
  127. *   X, Y:    Coordinates of 2D location to draw to.                          M
  128. *                                                                            *
  129. * RETURN VALUE:                                                              M
  130. *   void                                                                     M
  131. *                                                                            *
  132. * KEYWORDS:                                                                  M
  133. *   IGLineTo2D                                                               M
  134. *****************************************************************************/
  135. void IGLineTo2D(RealType X, RealType Y)
  136. {
  137.     int x, y;
  138.  
  139.     LineTo(IGCurrenthDC, x = WNT_MAP_X_COORD(X), y = WNT_MAP_Y_COORD(Y));
  140. }
  141.  
  142. /*****************************************************************************
  143. * DESCRIPTION:                                                               M
  144. * Sets the intensity of a color (high or low).                     M
  145. *                                                                            *
  146. * PARAMETERS:                                                                M
  147. *   High:     TRUE for high, FALSE for low.                                  M
  148. *                                                                            *
  149. * RETURN VALUE:                                                              M
  150. *   void                                                                     M
  151. *                                                                            *
  152. * KEYWORDS:                                                                  M
  153. *   IGSetColorIntensity                                                      M
  154. *****************************************************************************/
  155. void IGSetColorIntensity(int High)
  156. {
  157.     if (!IGCurrenthDC)
  158.     return;
  159.     if (IGCurrenthPen)
  160.         DeleteObject(SelectObject(IGCurrenthDC, IGCurrenthPen));
  161.     IGCurrenthPen = 
  162.     SelectObject(IGCurrenthDC, CreatePen(PS_SOLID, IGGlblLineWidth,
  163.                          High ? IGCrntColorHighIntensity
  164.                               : IGCrntColorLowIntensity));
  165.  
  166.     IGGlblIntensityHighState = High;
  167. }
  168.  
  169. /*****************************************************************************
  170. * DESCRIPTION:                                                               M
  171. * Sets the color of an object according to its color/rgb attributes.         M
  172. *   If object has an RGB attribute it will be used. Otherwise, if the object M
  173. * has a COLOR attribute it will use. Otherwise, WHITE will be used.         M
  174. *                                                                            *
  175. * PARAMETERS:                                                                M
  176. *   PObj:      To set the drawing color to its color.                        M
  177. *                                                                            *
  178. * RETURN VALUE:                                                              M
  179. *   void                                                                     M
  180. *                                                                            *
  181. * KEYWORDS:                                                                  M
  182. *   IGSetColorObj                                                            M
  183. *****************************************************************************/
  184. void IGSetColorObj(IPObjectStruct *PObj)
  185. {
  186.     int c, Color[3];
  187.  
  188.     if (AttrGetObjectRGBColor(PObj, &Color[0], &Color[1], &Color[2])) {
  189.     IGSetColorRGB(Color);
  190.     }
  191.     else if ((c = AttrGetObjectColor(PObj)) != IP_ATTR_NO_COLOR) {
  192.     IGSetColorIndex(c);
  193.     }
  194.     else {
  195.     /* Use white as default color: */
  196.     IGSetColorIndex(IG_IRIT_WHITE);
  197.     }
  198. }
  199.  
  200. /*****************************************************************************
  201. * DESCRIPTION:                                                               M
  202. * Sets the line width to draw the given object, in pixels.             M
  203. *                                                                            *
  204. * PARAMETERS:                                                                M
  205. *   Width:    In pixels of lines to draw with.                               M
  206. *                                                                            *
  207. * RETURN VALUE:                                                              M
  208. *   void                                                                     M
  209. *                                                                            *
  210. * KEYWORDS:                                                                  M
  211. *   IGSetWidthObj                                                            M
  212. *****************************************************************************/
  213. void IGSetWidthObj(int Width)
  214. {
  215. }
  216.  
  217. /*****************************************************************************
  218. * DESCRIPTION:                                                               *
  219. * Sets the color according to the given color index.                     *
  220. *                                                                            *
  221. * PARAMETERS:                                                                *
  222. *   color:     Index of color to use. Must be between 0 and IG_MAX_COLOR.    *
  223. *                                                                            *
  224. * RETURN VALUE:                                                              *
  225. *   void                                                                     *
  226. *****************************************************************************/
  227. void IGSetColorIndex(int color)
  228. {
  229.     IGSetColorIndex2(color, IGGlblLineWidth);
  230. }
  231.  
  232. /*****************************************************************************
  233. * DESCRIPTION:                                                               *
  234. * Sets the color/width according to the given color index/width.            *
  235. *                                                                            *
  236. * PARAMETERS:                                                                *
  237. *   color:     Index of color to use. Must be between 0 and IG_MAX_COLOR.    *
  238. *   width:     In pixel, for line draw.                                      *
  239. *                                                                            *
  240. * RETURN VALUE:                                                              *
  241. *   void                                                                     *
  242. *****************************************************************************/
  243. void IGSetColorIndex2(int color, int width)
  244. {
  245.     if (color > IG_MAX_COLOR)
  246.     color = IG_IRIT_WHITE;
  247.  
  248.     IGCrntColorHighIntensity = IGColorsHighIntensity[color];
  249.     IGCrntColorLowIntensity = IGColorsLowIntensity[color];
  250.  
  251.     if (!IGCurrenthDC)
  252.     return;
  253.     if (IGCurrenthPen)
  254.         DeleteObject(SelectObject(IGCurrenthDC, IGCurrenthPen));
  255.     IGCurrenthPen = SelectObject(IGCurrenthDC, CreatePen(PS_SOLID, width,
  256.                             IGCrntColorHighIntensity));
  257.  
  258.     IGGlblIntensityHighState = TRUE;
  259. }
  260.  
  261.  
  262. /*****************************************************************************
  263. * DESCRIPTION:                                                               *
  264. * Sets the color according to the given RGB values.                 *
  265. *                                                                            *
  266. * PARAMETERS:                                                                *
  267. *   Color:      An RGB vector of integer values between 0 and 255.           *
  268. *                                                                            *
  269. * RETURN VALUE:                                                              *
  270. *   void                                                                     *
  271. *****************************************************************************/
  272. void IGSetColorRGB(int Color[3])
  273. {
  274.     IGCrntColorHighIntensity = GetNearestColor(IGCurrenthDC,
  275.                            RGB(Color[0],
  276.                            Color[1],
  277.                            Color[2]));
  278.     IGCrntColorLowIntensity = GetNearestColor(IGCurrenthDC,
  279.                           RGB(Color[0] / 2,
  280.                           Color[1] / 2,
  281.                           Color[2] / 2));
  282.  
  283.  
  284.     if (!IGCurrenthDC)
  285.     return;
  286.     if (IGCurrenthPen)
  287.         DeleteObject(SelectObject(IGCurrenthDC, IGCurrenthPen));
  288.  
  289.     IGCurrenthPen = SelectObject(IGCurrenthDC, CreatePen(PS_SOLID, 1,
  290.                             IGCrntColorHighIntensity));
  291.  
  292.     IGGlblIntensityHighState = TRUE;
  293. }
  294.