home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Graphics / sKulpt / skulpt-src / Dialogs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-28  |  25.7 KB  |  732 lines

  1. #define STRICT
  2.  
  3. // Includes standard Windows
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <memory.h>
  10. #include <stdio.h>
  11.  
  12. // Includes D3D
  13. #define  D3D_OVERLOADS
  14. #include <ddraw.h>
  15. #include <d3d.h>
  16. #include <d3dx.h>
  17.  
  18. // Includes utilitaires D3D
  19. #include "d3dmath.h"
  20. #include "d3dutil.h"
  21. #include "D3DEnum.h"
  22.  
  23. // Ids Resources
  24. #include "resource.h"
  25.  
  26. // Constantes
  27. #include "const.h"
  28.  
  29. // Types
  30. #include "types.h"
  31.  
  32. // Variables globales projet
  33. #include "vars.h"
  34.  
  35. // Prototypes fonctions autres modules
  36. #include "proto.h"
  37.  
  38. // Macros
  39. #include "macros.h"
  40.  
  41. // Variables statiques au module
  42. static D3DCOLOR cbAmbient, cbBack;
  43. static SCROLLINFO Si;
  44.  
  45. // Gestion du dialog éclairage général
  46. BOOL CALLBACK bGlobLightDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  47. {
  48.     int wmId, wmEvent, nScrollCode, nPos;
  49.     HWND hwndScrollBar;
  50.  
  51.     Si.cbSize = sizeof(Si);
  52.  
  53.     switch( uMsg )
  54.     {
  55.     case WM_COMMAND :
  56.          wmId    = LOWORD(wParam); // Remember, these are...
  57.          wmEvent = HIWORD(wParam); // ...different for Win32!
  58.  
  59.          switch (wmId)
  60.          {
  61.             case IDRESET:    // Restaurer les valeurs initiales
  62.                 // Restaurer les valeurs
  63.                 cAmbient = cbAmbient;
  64.                 cBack = cbBack;
  65.                  
  66.                 // Repositionner les états du pipe D3D
  67.                 vSetD3DState();
  68.  
  69.                 // Repositionner les curseurs des sliders
  70.                 Si.fMask = SIF_POS;
  71.                 Si.nPos = (cAmbient & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RA), SB_CTL, &Si, TRUE);
  72.                 Si.nPos = (cAmbient & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GA), SB_CTL, &Si, TRUE);
  73.                 Si.nPos = cAmbient & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BA), SB_CTL, &Si, TRUE);
  74.                 Si.nPos = (cBack & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RF), SB_CTL, &Si, TRUE);
  75.                 Si.nPos = (cBack & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GF), SB_CTL, &Si, TRUE);
  76.                 Si.nPos = cBack & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BF), SB_CTL, &Si, TRUE);
  77.                 break;
  78.  
  79.             case IDCANCEL:    // Restaurer les valeurs initiales et quitter
  80.                 // Restaurer les valeurs
  81.                 cAmbient = cbAmbient;
  82.                 cBack = cbBack;
  83.  
  84.                 // Repositionner les états du pipe D3D
  85.                 vSetD3DState();
  86.                 vForce3DRefresh(XDC_MODE_COMPLET);
  87.  
  88.                 // ATTENTION pas de break, on continue...
  89.  
  90.             case IDOK:    // Fin dialogue
  91.                 EndDialog(hWnd, 0);
  92.                 break;
  93.          }
  94.          return TRUE;
  95.          break;
  96.  
  97.      case WM_HSCROLL :    // Scroll slider
  98.          // Récupérer les valeurs de scroll
  99.          nScrollCode = (int) LOWORD(wParam);  // scroll bar value 
  100.          nPos = (short int) HIWORD(wParam);   // scroll box position 
  101.          hwndScrollBar = (HWND) lParam;       // handle to scroll bar 
  102.          
  103.          // Si scrolling slider
  104.          if (nScrollCode == SB_THUMBTRACK)
  105.          {
  106.              switch(GetDlgCtrlID(hwndScrollBar))
  107.              {
  108.                  case IDC_RA :
  109.                      cAmbient &= 0xff00ffff;
  110.                       cAmbient |= nPos << 16;
  111.                      // Mettre à jour les variables d'état du pipe D3D
  112.                      vSetD3DState();
  113.                      break;
  114.                  case IDC_GA :
  115.                      cAmbient &= 0xffff00ff;
  116.                       cAmbient |= nPos << 8;
  117.                      // Mettre à jour les variables d'état du pipe D3D
  118.                      vSetD3DState();
  119.                      break;
  120.                  case IDC_BA :
  121.                      cAmbient &= 0xffffff00;
  122.                       cAmbient |= nPos;
  123.                      // Mettre à jour les variables d'état du pipe D3D
  124.                      vSetD3DState();
  125.                      break;
  126.                  case IDC_RF :
  127.                      cBack &= 0xff00ffff;
  128.                       cBack |= nPos << 16;
  129.                      break;
  130.                  case IDC_GF :
  131.                      cBack &= 0xffff00ff;
  132.                       cBack |= nPos << 8;
  133.                      break;
  134.                  case IDC_BF :
  135.                      cBack &= 0xffffff00;
  136.                       cBack |= nPos;
  137.                      break;
  138.              }
  139.  
  140.              // Ajuster la position du slider
  141.              Si.fMask = SIF_POS;
  142.              Si.nPos = nPos;
  143.              SetScrollInfo(GetDlgItem(hWnd, GetDlgCtrlID(hwndScrollBar)), SB_CTL, &Si, TRUE);
  144.                              
  145.             // Redessiner la 3D
  146.             vSetD3DState();
  147.             vForce3DRefresh(XDC_MODE_COMPLET);
  148.  
  149.          }
  150.          return TRUE;
  151.          break;
  152.  
  153.      case WM_INITDIALOG :
  154.          // Positionner les sliders
  155.          Si.fMask = SIF_POS | SIF_RANGE;
  156.          Si.nMin = 0;
  157.          Si.nMax = 255;
  158.          
  159.          Si.nPos = (cAmbient & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RA), SB_CTL, &Si, TRUE);
  160.          Si.nPos = (cAmbient & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GA), SB_CTL, &Si, TRUE);
  161.          Si.nPos = cAmbient & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BA), SB_CTL, &Si, TRUE);
  162.          Si.nPos = (cBack & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RF), SB_CTL, &Si, TRUE);
  163.          Si.nPos = (cBack & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GF), SB_CTL, &Si, TRUE);
  164.          Si.nPos = cBack & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BF), SB_CTL, &Si, TRUE);
  165.  
  166.          // Mémoriser les valeurs initiales
  167.          cbAmbient = cAmbient;
  168.          cbBack = cBack;
  169.          return TRUE;
  170.          break;
  171.     }
  172.  
  173.     return FALSE;
  174. }
  175.  
  176. // Gestion du dialog expand
  177. BOOL CALLBACK bExpandDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  178. {
  179.     int wmId, wmEvent, nScrollCode, nPos;
  180.     HWND hwndScrollBar;
  181.     int iCnt;
  182.     static D3DVECTOR dVect;
  183.     int iLock = 0;
  184.     char cVal[5];
  185.     static int iExpandLock;
  186.     float fExpandFactor;
  187.  
  188.     Si.cbSize = sizeof(Si);
  189.  
  190.     switch( uMsg )
  191.     {
  192.     case WM_COMMAND :
  193.          wmId    = LOWORD(wParam); // Remember, these are...
  194.          wmEvent = HIWORD(wParam); // ...different for Win32!
  195.  
  196.          switch (wmId)
  197.          {
  198.             case IDAPPLY:
  199.                 goto __ExpandInit;
  200.  
  201.             case IDCANCEL:    // Quitter
  202.             case IDRESET:
  203.                 for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
  204.                     if (bIsVertexSelected(iCnt))
  205.                         Vertices[iCnt].vPoint = Vertices[iCnt].vPointBack;
  206.                 for (iCnt = 0 ; iCnt <= iTriaLastUsed ; iCnt++)
  207.                     if (bIsTrianglePartiallySelected(iCnt))
  208.                         bUpdateD3DTri(iCnt);
  209.                 vForce2DRefresh(XDC_MODE_COMPLET);
  210.                 vForce3DRefresh(XDC_MODE_COMPLET);
  211.                 if (wmId == IDRESET) goto __ExpandInitSliders;
  212.  
  213.             case IDOK:    // Appliquer les modifs
  214.                 EndDialog(hWnd, 0);
  215.                 break;
  216.  
  217.             case IDC_LOCK:
  218.                 iExpandLock = SendDlgItemMessage(hWnd, IDC_LOCK, BM_GETCHECK, (WPARAM) 0, 0L);
  219.                 break;
  220.          }
  221.          return TRUE;
  222.  
  223.      case WM_HSCROLL :    // Scroll slider
  224.          // Récupérer les valeurs de scroll
  225.          nScrollCode = (int) LOWORD(wParam);  // scroll bar value 
  226.          nPos = (short int) HIWORD(wParam);   // scroll box position 
  227.          hwndScrollBar = (HWND) lParam;       // handle to scroll bar 
  228.          
  229.          // Si scrolling slider
  230.          if (nScrollCode == SB_THUMBTRACK)
  231.          {
  232.              sprintf(cVal, "%d%%", nPos);
  233.              fExpandFactor = (float) nPos / 100.f;
  234.              Si.fMask = SIF_POS;
  235.              Si.nPos = nPos;
  236.  
  237.              if (iExpandLock)
  238.              {
  239.                 for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
  240.                     if (bIsVertexSelected(iCnt))
  241.                     {
  242.                         Vertices[iCnt].vPoint.x = dVect.x + (Vertices[iCnt].vPointBack.x - dVect.x) * fExpandFactor;
  243.                         Vertices[iCnt].vPoint.y = dVect.y + (Vertices[iCnt].vPointBack.y - dVect.y) * fExpandFactor;
  244.                         Vertices[iCnt].vPoint.z = dVect.z + (Vertices[iCnt].vPointBack.z - dVect.z) * fExpandFactor;
  245.                     }
  246.  
  247.                 SendDlgItemMessage(hWnd, IDC_EXV, WM_SETTEXT, 0, (long)&cVal[0]);
  248.                 SendDlgItemMessage(hWnd, IDC_EYV, WM_SETTEXT, 0, (long)&cVal[0]);
  249.                 SendDlgItemMessage(hWnd, IDC_EZV, WM_SETTEXT, 0, (long)&cVal[0]);
  250.                 SetScrollInfo(GetDlgItem(hWnd, IDC_EX), SB_CTL, &Si, TRUE);
  251.                 SetScrollInfo(GetDlgItem(hWnd, IDC_EY), SB_CTL, &Si, TRUE);
  252.                 SetScrollInfo(GetDlgItem(hWnd, IDC_EZ), SB_CTL, &Si, TRUE);
  253.              }
  254.              else
  255.              {
  256.                  switch(GetDlgCtrlID(hwndScrollBar))
  257.                  {
  258.                      case IDC_EX :
  259.                         SendDlgItemMessage(hWnd, IDC_EXV, WM_SETTEXT, 0, (long)&cVal[0]);
  260.                         for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
  261.                             if (bIsVertexSelected(iCnt))
  262.                                 Vertices[iCnt].vPoint.x = dVect.x + (Vertices[iCnt].vPointBack.x - dVect.x) * fExpandFactor;
  263.                          break;
  264.                      case IDC_EY :
  265.                         SendDlgItemMessage(hWnd, IDC_EYV, WM_SETTEXT, 0, (long)&cVal[0]);
  266.                         for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
  267.                             if (bIsVertexSelected(iCnt))
  268.                                 Vertices[iCnt].vPoint.y = dVect.y + (Vertices[iCnt].vPointBack.y - dVect.y) * fExpandFactor;
  269.                          break;
  270.                      case IDC_EZ :
  271.                         SendDlgItemMessage(hWnd, IDC_EZV, WM_SETTEXT, 0, (long)&cVal[0]);
  272.                         for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
  273.                             if (bIsVertexSelected(iCnt))
  274.                                 Vertices[iCnt].vPoint.z = dVect.z + (Vertices[iCnt].vPointBack.z - dVect.z) * fExpandFactor;
  275.                          break;
  276.                  }
  277.                 SetScrollInfo(GetDlgItem(hWnd, GetDlgCtrlID(hwndScrollBar)), SB_CTL, &Si, TRUE);
  278.              }
  279.                              
  280.             // Redessiner la 3D
  281.             for (iCnt = 0 ; iCnt <= iTriaLastUsed ; iCnt++)
  282.                 if (bIsTrianglePartiallySelected(iCnt))
  283.                     bUpdateD3DTri(iCnt);
  284.             vForce2DRefresh(XDC_MODE_COMPLET);
  285.             vForce3DRefresh(XDC_MODE_COMPLET);
  286.          }
  287.          return TRUE;
  288.  
  289.     case WM_INITDIALOG :
  290.         SendDlgItemMessage(hWnd, IDC_LOCK, BM_SETCHECK, (WPARAM) iExpandLock, 0L);
  291.  
  292. __ExpandInit:
  293.         // Déterminer le barycentre de la sélection (on travaille par rapport à lui)
  294.         dVect = vCenter();
  295.  
  296. __ExpandInitSliders:
  297.         // Positionner les sliders
  298.         Si.fMask = SIF_POS | SIF_RANGE;
  299.         Si.nMin = 0;    // Mini
  300.         Si.nMax = 200;    // Maxi
  301.         Si.nPos = 100;    // Position initiale
  302.         sprintf(cVal, "%d%%", Si.nPos);
  303.          
  304.         SetScrollInfo(GetDlgItem(hWnd, IDC_EX), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDC_EXV, WM_SETTEXT, 0, (long)&cVal[0]);
  305.         SetScrollInfo(GetDlgItem(hWnd, IDC_EY), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDC_EYV, WM_SETTEXT, 0, (long)&cVal[0]);
  306.         SetScrollInfo(GetDlgItem(hWnd, IDC_EZ), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDC_EZV, WM_SETTEXT, 0, (long)&cVal[0]);
  307.  
  308.         return TRUE;
  309.     }
  310.  
  311.     return FALSE;
  312. }
  313.  
  314. // Gestion du dialog props sphère
  315. BOOL CALLBACK bSphereDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  316. {
  317.     int wmId, wmEvent;
  318.     int iH, iV;        // Subdivisions horizontales & verticales
  319.     char cBuf[12];
  320.  
  321.     switch( uMsg )
  322.     {
  323.     case WM_COMMAND :
  324.          wmId    = LOWORD(wParam); // Remember, these are...
  325.          wmEvent = HIWORD(wParam); // ...different for Win32!
  326.  
  327.          switch (wmId)
  328.          {
  329.             case IDCANCEL:
  330.                 EndDialog(hWnd, -1);
  331.                 break;
  332.  
  333.             case IDOK:    // Fin dialogue
  334.                 SendDlgItemMessage(hWnd, IDC_SH, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iH = atoi(cBuf); 
  335.                 SendDlgItemMessage(hWnd, IDC_SV, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iV = atoi(cBuf); 
  336.                 if ((iH > 0) && (iV > 0))
  337.                     EndDialog(hWnd, iV << 16 | iH);
  338.                 else
  339.                 {
  340.                     vTrace("*** E0008 : définition impossible (SH : %d, sV : %d)", iH, iV);
  341.                     EndDialog(hWnd, -1);
  342.                 }
  343.                 break;
  344.          }
  345.          return TRUE;
  346.          break;
  347.  
  348.      case WM_INITDIALOG :
  349.          iH = HIWORD(lParam); sprintf(cBuf, "%d", iH);  SendDlgItemMessage(hWnd, IDC_SH, WM_SETTEXT, 0, (LPARAM) cBuf);
  350.          iV = LOWORD(lParam); sprintf(cBuf, "%d", iV);  SendDlgItemMessage(hWnd, IDC_SV, WM_SETTEXT, 0, (LPARAM) cBuf);
  351.          return TRUE;
  352.          break;
  353.     }
  354.  
  355.     return FALSE;
  356. }
  357.  
  358. // Gestion du dialog props répliquer hélice
  359. BOOL CALLBACK bHelixDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  360. {
  361.     int wmId;
  362.     static int iRot, iTrans, iDP, iAP, iP;        // Degrés par pas, avance par pas, nombre de pas
  363.     static BOOL bLierClones = TRUE;
  364.     char cBuf[12];
  365.     D3DVECTOR vShift = D3DVECTOR(0.f, 0.f, 0.f);;
  366.     D3DMATRIX mRot;
  367.     float fAngle;
  368.  
  369.     switch( uMsg )
  370.     {
  371.     case WM_COMMAND :
  372.          wmId    = LOWORD(wParam);
  373.  
  374.          switch (wmId)
  375.          {
  376.             // Bouton lier clones
  377.             case IDC_LCL:
  378.                 bLierClones = SendDlgItemMessage(hWnd, IDC_LCL, BM_GETCHECK, (WPARAM) 0, 0L);
  379.                 break;
  380.  
  381.             // Boutons sélection rotation autour axe X/Y/Z...
  382.             case IDC_RX:
  383.             case IDC_RY:
  384.             case IDC_RZ:
  385.                 iRot = wmId;
  386.                 break;
  387.  
  388.             // Boutons sélection translation autour axe X/Y/Z...
  389.             case IDC_TX:
  390.             case IDC_TY:
  391.             case IDC_TZ:
  392.                 iTrans = wmId;
  393.                 break;
  394.  
  395.             // Annuler
  396.             case IDCANCEL:
  397.                 EndDialog(hWnd, -1);
  398.                 break;
  399.  
  400.             // Appliquer la transformation
  401.             case IDOK:
  402.                 // Récupérer l'angle par pas, l'avance par pas, le nombre de pas
  403.                 SendDlgItemMessage(hWnd, IDC_DP, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iDP = atoi(cBuf); 
  404.                 SendDlgItemMessage(hWnd, IDC_AP, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iAP = atoi(cBuf); 
  405.                 SendDlgItemMessage(hWnd, IDC_P, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iP = atoi(cBuf); 
  406.  
  407.                 // Moduler l'angle @360°
  408.                 iDP = iDP % 360;
  409.  
  410.                 // Calculer l'angle en radians
  411.                 fAngle = g_2_PI * (float) iDP / 360.f;
  412.  
  413.                 // Si moins de 1 pas stop
  414.                 if (iP < 1) EndDialog(hWnd, -1);
  415.  
  416.                 // Calculer la matrice de rotation en fonction de l'axe et de l'angle choisis
  417.                 switch(iRot)
  418.                 {
  419.                     case IDC_RY : D3DUtil_SetRotateYMatrix(mRot, -fAngle); break;
  420.                     case IDC_RZ : D3DUtil_SetRotateZMatrix(mRot, fAngle);  break;
  421.                     case IDC_RX : D3DUtil_SetRotateXMatrix(mRot, -fAngle); break;
  422.                 }
  423.  
  424.                 // Calculer le vecteur d'avance en fonction de l'axe et de l'avance
  425.                 switch(iTrans)
  426.                 {
  427.                     case IDC_TY : vShift.y += ((float) iAP / 10.f); break;
  428.                     case IDC_TZ : vShift.z += ((float) iAP / 10.f); break;
  429.                     case IDC_TX : vShift.x += ((float) iAP / 10.f); break;
  430.                 }
  431.  
  432.                 // Pour chaque pas...
  433.                 for (int iPas = 0 ; iPas < iP ; iPas ++)
  434.                 {
  435.                     // Préparer un clone de la sélection, qui se retrouve sélectionné (en désélectionnant le reste)
  436.                     bCloneSelection(vShift, bLierClones ? XDC_MODE_EXTRUDE : XDC_MODE_CLONE);
  437.  
  438.                     // Appliquer la matrice aux sommets sélectionnés
  439.                     for (int iVert = 0 ; iVert <= iVertLastUsed ; iVert++)
  440.                         if (bIsVertexSelected(iVert))
  441.                         {
  442.                             // Changer de repère => Cursor1
  443.                             D3DVECTOR vTrans = Vertices[iVert].vPoint - Cursor1;
  444.                         
  445.                             // Appliquer la rotation au point translaté
  446.                             D3DMath_VectorMatrixMultiply(vTrans,
  447.                                                          vTrans,
  448.                                                          mRot);
  449.  
  450.                             // Remettre dans le repère d'origine
  451.                             Vertices[iVert].vPoint = vTrans + Cursor1;
  452.                         }
  453.                     
  454.                     // Recalculer les sommets des triangles ayant des sommets sélectionnés
  455.                     for (int iTriangle = 0 ; iTriangle <= iTriaLastUsed ; iTriangle++)
  456.                         if (bIsTrianglePartiallySelected(iTriangle))
  457.                            bUpdateD3DTri(iTriangle);
  458.                 }
  459.  
  460.                 // Redessiner la 2D
  461.                 vForce2DRefresh(XDC_MODE_COMPLET);
  462.                 // Redessiner la 3D
  463.                 vForce3DRefresh(XDC_MODE_COMPLET);
  464.  
  465.                 EndDialog(hWnd, 0);
  466.                 break;
  467.          }
  468.          return TRUE;
  469.  
  470.      case WM_INITDIALOG :
  471.         switch(lWActive)
  472.         {
  473.             case XDC_WID_TOP : // X et Z
  474.                 iRot = IDC_RY;
  475.                 iTrans = IDC_TY;
  476.                 break;
  477.  
  478.             case XDC_WID_FACE : // X et Y
  479.                 iRot = IDC_RZ;
  480.                 iTrans = IDC_TZ;
  481.                 break;
  482.             
  483.             case XDC_WID_SIDE : // Z et Y
  484.                 iRot = IDC_RX;
  485.                 iTrans = IDC_TX;
  486.                 break;
  487.         }
  488.  
  489.         SendDlgItemMessage(hWnd, IDC_LCL, BM_SETCHECK, (WPARAM) bLierClones, 0L);
  490.         SendDlgItemMessage(hWnd, iRot, BM_SETCHECK, (WPARAM) 1, 0L);
  491.         SendDlgItemMessage(hWnd, iTrans, BM_SETCHECK, (WPARAM) 1, 0L);
  492.          
  493.         sprintf(cBuf, "%d", iDP);  SendDlgItemMessage(hWnd, IDC_DP, WM_SETTEXT, 0, (LPARAM) cBuf);
  494.         sprintf(cBuf, "%d", iAP);  SendDlgItemMessage(hWnd, IDC_AP, WM_SETTEXT, 0, (LPARAM) cBuf);
  495.         sprintf(cBuf, "%d", iP);   SendDlgItemMessage(hWnd, IDC_P, WM_SETTEXT, 0, (LPARAM) cBuf);
  496.         return TRUE;
  497.     }
  498.     return FALSE;
  499. }
  500.  
  501.  
  502. // Gestion du dialog facettes
  503. BOOL CALLBACK bFaceDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  504. {
  505.     int wmId, wmEvent, nScrollCode, nPos, iCnt;
  506.     HWND hwndScrollBar;
  507.     char cVal[5];
  508.     float fValue;
  509.  
  510.     Si.cbSize = sizeof(Si);
  511.  
  512.     switch( uMsg )
  513.     {
  514.     case WM_COMMAND :
  515.          wmId    = LOWORD(wParam); // Remember, these are...
  516.          wmEvent = HIWORD(wParam); // ...different for Win32!
  517.  
  518.          switch (wmId)
  519.          {
  520.             case IDCANCEL:
  521.             case IDOK:    // Fin dialogue
  522.                 EndDialog(hWnd, -1);
  523.                 break;
  524.          }
  525.          return TRUE;
  526.          break;
  527.  
  528.      case WM_HSCROLL :    // Scroll slider
  529.         // Récupérer les valeurs de scroll
  530.         nScrollCode = (int) LOWORD(wParam);  // scroll bar value 
  531.         nPos = (short int) HIWORD(wParam);   // scroll box position 
  532.         hwndScrollBar = (HWND) lParam;       // handle to scroll bar 
  533.          
  534.         // Si scrolling slider
  535.         if (nScrollCode == SB_THUMBTRACK)
  536.         {
  537.             fValue = (float) nPos / 100.f;
  538.  
  539.             for (int iTriangle = 0 ; iTriangle <= iTriaLastUsed ; iTriangle++)
  540.                 if (bIsTriangleSelected(iTriangle))
  541.                 {
  542.                     D3DMATERIAL7 *pMtrl = &(Materials[Triangles[iTriangle].iMtrl].mtrl);
  543.                     switch(GetDlgCtrlID(hwndScrollBar))
  544.                     {
  545.                         case IDC_D_A:    pMtrl -> diffuse.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
  546.                         case IDC_D_R:    pMtrl -> diffuse.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
  547.                         case IDC_D_G:    pMtrl -> diffuse.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
  548.                         case IDC_D_B:    pMtrl -> diffuse.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
  549.  
  550.                         case IDC_A_A:    pMtrl -> ambient.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
  551.                         case IDC_A_R:    pMtrl -> ambient.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
  552.                         case IDC_A_G:    pMtrl -> ambient.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
  553.                         case IDC_A_B:    pMtrl -> ambient.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
  554.  
  555.                         case IDC_S_A:    pMtrl -> specular.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
  556.                         case IDC_S_R:    pMtrl -> specular.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
  557.                         case IDC_S_G:    pMtrl -> specular.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
  558.                         case IDC_S_B:    pMtrl -> specular.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
  559.                         case IDC_S_P:    pMtrl -> power = fValue; sprintf(cVal, "P %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_P, WM_SETTEXT, 0, (long)&cVal[0]); break;
  560.  
  561.                         case IDC_E_A:    pMtrl -> emissive.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
  562.                         case IDC_E_R:    pMtrl -> emissive.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
  563.                         case IDC_E_G:    pMtrl -> emissive.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
  564.                         case IDC_E_B:    pMtrl -> emissive.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
  565.                     }
  566.                 }
  567.             Si.fMask = SIF_POS;
  568.             Si.nPos = nPos;
  569.             SetScrollInfo(GetDlgItem(hWnd, GetDlgCtrlID(hwndScrollBar)), SB_CTL, &Si, TRUE);
  570.                              
  571.             // Redessiner la 3D
  572.             vForce3DRefresh(XDC_MODE_COMPLET);
  573.         }
  574.         return TRUE;
  575.  
  576.     case WM_INITDIALOG :
  577.         // Positionner les sliders sur la moyenne de la sélection
  578.         Si.fMask = SIF_POS | SIF_RANGE;
  579.         Si.nMin = 0;    // Mini
  580.         Si.nMax = 100;    // Maxi
  581.  
  582.         {
  583.             D3DMATERIAL7 Mtrl;
  584.             ZeroMemory(&Mtrl, sizeof(D3DMATERIAL7));
  585.  
  586.             iCnt = 0;
  587.  
  588.             for (int iTriangle = 0 ; iTriangle <= iTriaLastUsed ; iTriangle++)
  589.                 if (bIsTriangleSelected(iTriangle))
  590.                 {
  591.                     D3DMATERIAL7 *pMtrl = &(Materials[Triangles[iTriangle].iMtrl].mtrl);
  592.                     iCnt++;
  593.                     Mtrl.diffuse.a += pMtrl -> diffuse.a;
  594.                     Mtrl.diffuse.r += pMtrl -> diffuse.r;
  595.                     Mtrl.diffuse.g += pMtrl -> diffuse.g;
  596.                     Mtrl.diffuse.b += pMtrl -> diffuse.b;
  597.  
  598.                     Mtrl.ambient.a += pMtrl -> ambient.a;
  599.                     Mtrl.ambient.r += pMtrl -> ambient.r;
  600.                     Mtrl.ambient.g += pMtrl -> ambient.g;
  601.                     Mtrl.ambient.b += pMtrl -> ambient.b;
  602.  
  603.                     Mtrl.specular.a += pMtrl -> specular.a;
  604.                     Mtrl.specular.r += pMtrl -> specular.r;
  605.                     Mtrl.specular.g += pMtrl -> specular.g;
  606.                     Mtrl.specular.b += pMtrl -> specular.b;
  607.                     Mtrl.power += pMtrl -> power;
  608.  
  609.                     Mtrl.emissive.a += pMtrl -> emissive.a;
  610.                     Mtrl.emissive.r += pMtrl -> emissive.r;
  611.                     Mtrl.emissive.g += pMtrl -> emissive.g;
  612.                     Mtrl.emissive.b += pMtrl -> emissive.b;
  613.                 }
  614.  
  615.             if (iCnt == 0) iCnt = 1;
  616.  
  617.             Si.nPos = (int) (100.f * Mtrl.diffuse.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_A, WM_SETTEXT, 0, (long)&cVal[0]);
  618.             Si.nPos = (int) (100.f * Mtrl.diffuse.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_R, WM_SETTEXT, 0, (long)&cVal[0]);
  619.             Si.nPos = (int) (100.f * Mtrl.diffuse.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_G, WM_SETTEXT, 0, (long)&cVal[0]);
  620.             Si.nPos = (int) (100.f * Mtrl.diffuse.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_B, WM_SETTEXT, 0, (long)&cVal[0]);
  621.  
  622.             Si.nPos = (int) (100.f * Mtrl.ambient.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_A, WM_SETTEXT, 0, (long)&cVal[0]);
  623.             Si.nPos = (int) (100.f * Mtrl.ambient.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_R, WM_SETTEXT, 0, (long)&cVal[0]);
  624.             Si.nPos = (int) (100.f * Mtrl.ambient.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_G, WM_SETTEXT, 0, (long)&cVal[0]);
  625.             Si.nPos = (int) (100.f * Mtrl.ambient.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_B, WM_SETTEXT, 0, (long)&cVal[0]);
  626.  
  627.             Si.nPos = (int) (100.f * Mtrl.specular.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_A, WM_SETTEXT, 0, (long)&cVal[0]);
  628.             Si.nPos = (int) (100.f * Mtrl.specular.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_R, WM_SETTEXT, 0, (long)&cVal[0]);
  629.             Si.nPos = (int) (100.f * Mtrl.specular.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_G, WM_SETTEXT, 0, (long)&cVal[0]);
  630.             Si.nPos = (int) (100.f * Mtrl.specular.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_B, WM_SETTEXT, 0, (long)&cVal[0]);
  631.             Si.nPos = (int) (100.f * Mtrl.power / iCnt); sprintf(cVal, "P %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_P), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_P, WM_SETTEXT, 0, (long)&cVal[0]);
  632.  
  633.             Si.nPos = (int) (100.f * Mtrl.emissive.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_A, WM_SETTEXT, 0, (long)&cVal[0]);
  634.             Si.nPos = (int) (100.f * Mtrl.emissive.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_R, WM_SETTEXT, 0, (long)&cVal[0]);
  635.             Si.nPos = (int) (100.f * Mtrl.emissive.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_G, WM_SETTEXT, 0, (long)&cVal[0]);
  636.             Si.nPos = (int) (100.f * Mtrl.emissive.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_B, WM_SETTEXT, 0, (long)&cVal[0]);
  637.         }
  638.  
  639.         return TRUE;
  640.     }
  641.  
  642.     return FALSE;
  643. }
  644.  
  645. // Gestion du dialog trous dans forme à remplir
  646. BOOL CALLBACK bHoleDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  647. {
  648.     int wmId, wmEvent;
  649.     char cBuf[12];
  650.  
  651.     switch( uMsg )
  652.     {
  653.         case WM_COMMAND :
  654.              wmId    = LOWORD(wParam); // Remember, these are...
  655.              wmEvent = HIWORD(wParam); // ...different for Win32!
  656.  
  657.              switch (wmId)
  658.              {
  659.                 case IDC_FADE:
  660.                     bFillAndRemoveEdges = (bFillAndRemoveEdges ? FALSE : TRUE);
  661.                     goto _HUpdate;
  662.                     break;
  663.  
  664.                 case IDRESET:
  665.                     iHoles = 0;
  666.                     goto _HUpdate;
  667.                     break;
  668.  
  669.                 case IDOK:    // Fin dialogue
  670.                     hHoleDlgActive = NULL;
  671.                     SendDlgItemMessage(hWnd, IDC_SH, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iHoles = atoi(cBuf); 
  672.                     if (iHoles >= XDC_MAX_HOLES)
  673.                     {
  674.                         vTrace("*** E0009 : trop de trous");
  675.                         iHoles = 0;
  676.                     }
  677.                     EndDialog(hWnd, 0);
  678.                     break;
  679.              }
  680.              return TRUE;
  681.              break;
  682.  
  683.          case WM_INITDIALOG :
  684.             hHoleDlgActive = hWnd;
  685.             iHoles = 0;
  686.  
  687.          case WM_USER + 1:
  688. _HUpdate:
  689.             SendDlgItemMessage(hWnd, IDC_FADE, BM_SETCHECK, (WPARAM) bFillAndRemoveEdges, 0L);
  690.              sprintf(cBuf, "%d", iHoles);  SendDlgItemMessage(hWnd, IDC_SH, WM_SETTEXT, 0, (LPARAM) cBuf);
  691.             SetForegroundWindow(hWnd);
  692.             return TRUE;
  693.     }
  694.  
  695.     return FALSE;
  696. }
  697.  
  698. // Gestion du dialog props sphère
  699. BOOL CALLBACK bStringDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  700. {
  701.     int wmId, wmEvent;
  702.  
  703.     switch( uMsg )
  704.     {
  705.     case WM_COMMAND :
  706.          wmId    = LOWORD(wParam); // Remember, these are...
  707.          wmEvent = HIWORD(wParam); // ...different for Win32!
  708.  
  709.          switch (wmId)
  710.          {
  711.             case IDCANCEL:
  712.                 EndDialog(hWnd, -1);
  713.                 break;
  714.  
  715.             case IDOK:    // Fin dialogue
  716.                 SendDlgItemMessage(hWnd, IDC_SH, WM_GETTEXT, sizeof(cString) - 1, (LPARAM) cString); 
  717.                 EndDialog(hWnd, 0);
  718.                 break;
  719.          }
  720.          return TRUE;
  721.          break;
  722.  
  723.      case WM_INITDIALOG :
  724.          SendDlgItemMessage(hWnd, IDC_SH, WM_SETTEXT, 0, (LPARAM) cString); 
  725.          return TRUE;
  726.          break;
  727.     }
  728.  
  729.     return FALSE;
  730. }
  731.  
  732.