3dPageCloudColor.cpp
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:11k
源码类别:

OpenGL

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // 3dPageCloudColor.cpp : implementation file
  3. //
  4. // glOOP (OpenGL Object Oriented Programming library)
  5. // Copyright (c) Craig Fahrnbach 1997, 1998
  6. //
  7. // OpenGL is a registered trademark of Silicon Graphics
  8. //
  9. //
  10. // This program is provided for educational and personal use only and
  11. // is provided without guarantee or warrantee expressed or implied.
  12. //
  13. // Commercial use is strickly prohibited without written permission
  14. // from ImageWare Development.
  15. //
  16. // This program is -not- in the public domain.
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "glOOP.h"
  21. #include "MyColorPaletteWnd.h"
  22. #include "EditColorDlg.h"
  23. #include "3dObjectDialog.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char BASED_CODE THIS_FILE[] = __FILE__;
  27. #endif
  28. //////////////////////////////////////////////////////////////////
  29. // C3dPageCloudColor
  30. IMPLEMENT_DYNCREATE(C3dPageCloudColor, CPropertyPage)
  31. /////////////////////////////////////////////////////////////////////////////
  32. // C3dPageCloudColor dialog construction
  33. C3dPageCloudColor::C3dPageCloudColor()
  34. :CPropertyPage(C3dPageCloudColor::IDD)
  35. {
  36. m_pWorld  = NULL;
  37. m_pObject = NULL;
  38. m_pWndCloudPreview = new CMyCloudWnd;
  39. //{{AFX_DATA_INIT(C3dPageCloudColor)
  40. m_iColorSelect = 0;
  41. m_iSolidColor = -1;
  42. m_bReflect = FALSE;
  43. m_iTextureWrap = 0;
  44. //}}AFX_DATA_INIT
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // C3dPageCloudColor Destructor
  48. C3dPageCloudColor::~C3dPageCloudColor()
  49. {
  50. if(m_pWndCloudPreview)
  51. delete m_pWndCloudPreview;
  52. }
  53. void C3dPageCloudColor::DoDataExchange(CDataExchange* pDX)
  54. {
  55. CPropertyPage::DoDataExchange(pDX);
  56. //{{AFX_DATA_MAP(C3dPageCloudColor)
  57. DDX_Control(pDX, IDC_SLIDER_OPACITY, m_SliderOpacity);
  58. DDX_Control(pDX, IDC_COMBO_GRIDSIZE, m_ComboGridSize);
  59. DDX_Text(pDX, IDC_TILE, m_iTextureWrap);
  60. DDV_MinMaxInt(pDX, m_iTextureWrap, 1, 32767);
  61. //}}AFX_DATA_MAP
  62. }
  63. BEGIN_MESSAGE_MAP(C3dPageCloudColor, CPropertyPage)
  64. //{{AFX_MSG_MAP(C3dPageCloudColor)
  65. ON_WM_DRAWITEM()
  66. ON_BN_CLICKED(IDC_EDGE_BUTTON_COLOR_WND, OnEdgeButtonColorWnd)
  67. ON_BN_CLICKED(IDC_HIGHLIGHT_BUTTON_COLOR_WND, OnHighlightButtonColorWnd)
  68. ON_CBN_SELCHANGE(IDC_COMBO_GRIDSIZE, OnSelchangeComboGridsize)
  69. ON_EN_CHANGE(IDC_TILE, OnChangeTextureWrap)
  70. ON_WM_HSCROLL()
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. /////////////////////////////////////////////////////////////////////////////
  74. // C3dPageCloudColor operations
  75. void C3dPageCloudColor::PaintButtonWnd(CWnd* pWnd, C3dColor* pColor) 
  76. {
  77. CRect rect; // window rect
  78. CDC* pDC; // pointer to a device context
  79. // Get the size of the gradient window
  80. pWnd->GetWindowRect(&rect);
  81. // Get a pointer to the windows device context
  82. pDC = pWnd->GetDC();
  83. if(pDC)
  84. pDC->FillSolidRect(0,
  85.    0,
  86.    rect.right-rect.left,
  87.    rect.bottom-rect.top,
  88.    COLORREF RGB(pColor->m_fColor[0]*255,
  89. pColor->m_fColor[1]*255,
  90. pColor->m_fColor[2]*255));
  91. ReleaseDC(pDC);
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // C3dPageCloudColor message handlers
  95. BOOL C3dPageCloudColor::OnInitDialog() 
  96. {
  97. // let the base class do the default work
  98. CPropertyPage::OnInitDialog();
  99. if(!m_pWorld)
  100. return FALSE;
  101. if(!m_pWndCloudPreview->m_pCloudObject)
  102. {
  103. AfxMessageBox("Not enough memory to create preview window.", MB_OK);
  104. return FALSE;
  105. }
  106. // Create the owner drawn button color window
  107. CRect rect;
  108. GetDlgItem(IDC_EDGE_BUTTON_COLOR_WND)->GetWindowRect(&rect);
  109. ScreenToClient(&rect);
  110. m_wndEdgeButtonColor.Create(NULL, // lpszClassName
  111. NULL, // lpszWindowName
  112. WS_CHILD | WS_VISIBLE | // dwStyle
  113. WS_DLGFRAME,
  114. rect, // rect
  115. this, // CWnd* pParentWnd
  116. IDC_EDGE_BUTTON_COLOR_WND, // UINT  nID
  117. 0); // pContext
  118. GetDlgItem(IDC_HIGHLIGHT_BUTTON_COLOR_WND)->GetWindowRect(&rect);
  119. ScreenToClient(&rect);
  120. m_wndHighlightButtonColor.Create(NULL, // lpszClassName
  121. NULL, // lpszWindowName
  122. WS_CHILD | WS_VISIBLE | // dwStyle
  123. WS_DLGFRAME,
  124. rect, // rect
  125. this, // CWnd* pParentWnd
  126. IDC_HIGHLIGHT_BUTTON_COLOR_WND, // UINT  nID
  127. 0); // pContext
  128. GetDlgItem(IDC_CLOUD_PREVIEW_WND)->GetWindowRect(&rect);
  129. ScreenToClient(&rect);
  130. m_pWndCloudPreview->Create(NULL, // dwExtStyle
  131. NULL, // lpszClassName
  132. NULL, // lpszWindowName
  133. WS_CHILD | WS_VISIBLE | // dwStyle
  134. WS_DLGFRAME,
  135. rect, // rect
  136. this, // CWnd* pParentWnd
  137. IDC_CLOUD_PREVIEW_WND, // UINT  nID
  138. 0); // pContext
  139. // Fill our combo boxes and set the default selections:
  140. // Reset or clear the contents of the light Type combo box
  141. m_ComboGridSize.ResetContent();
  142. // Load the light type selections
  143. m_ComboGridSize.AddString("32 x 32 Grid");
  144. m_ComboGridSize.AddString("64 x 64 Grid");
  145. m_ComboGridSize.AddString("128 x 128 Grid");
  146. m_ComboGridSize.AddString("256 x 256 Grid");
  147. m_ComboGridSize.AddString("512 x 512 Grid");
  148. // Set a default selection  (brute force method..)
  149. // (I'm sure there is some algorthium, but I'm 
  150. //  anxious..)
  151. if(m_pObject->m_iSize == 5)
  152. m_ComboGridSize.SetCurSel(0);
  153. if(m_pObject->m_iSize == 6)
  154. m_ComboGridSize.SetCurSel(1);
  155. if(m_pObject->m_iSize == 7)
  156. m_ComboGridSize.SetCurSel(2);
  157. if(m_pObject->m_iSize == 8)
  158. m_ComboGridSize.SetCurSel(3);
  159. if(m_pObject->m_iSize == 9)
  160. m_ComboGridSize.SetCurSel(4);
  161. // Set our Opacity slider, scaled by 100
  162. m_SliderOpacity.SetRange(0, 100, TRUE);
  163. m_SliderOpacity.SetPos((int)(sqrt(m_pObject->m_fOpacity)*100));
  164. // Set the initial Texture Tile size
  165. m_iTextureWrap = m_pObject->m_iTextureWrap;
  166. // Initialize our preview window cloud object
  167. C3dObjectCloud::CopyParameters(m_pObject, m_pWndCloudPreview->m_pCloudObject);
  168. m_pWndCloudPreview->m_pCloudObject->m_bBuildLists = TRUE;
  169. // Dialog box is being initialized (FALSE)
  170. // or data is being retrieved (TRUE).
  171. UpdateData(FALSE);
  172. return TRUE;  // return TRUE unless you set the focus to a control
  173.               // EXCEPTION: OCX Property Pages should return FALSE
  174. }
  175. void C3dPageCloudColor::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
  176. {
  177. CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
  178. C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
  179. if(nIDCtl == IDC_EDGE_BUTTON_COLOR_WND && m_wndEdgeButtonColor.m_hWnd)
  180. PaintButtonWnd(&m_wndEdgeButtonColor, &pCloud->m_Color);
  181. if(nIDCtl == IDC_HIGHLIGHT_BUTTON_COLOR_WND && m_wndHighlightButtonColor.m_hWnd)
  182. PaintButtonWnd(&m_wndHighlightButtonColor, &pCloud->m_ColorHighlight);
  183. }
  184. void C3dPageCloudColor::OnEdgeButtonColorWnd() 
  185. {
  186. C3dColor SelColor;
  187. // The property page settings have been modified, so 
  188. // Enable (TRUE) or disable (FALSE) the Apply Now button
  189. SetModified(TRUE);
  190. C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
  191. if(m_pWorld) 
  192. {
  193. SelColor.SetColor4fv(&pCloud->m_Color);
  194. // Create the dialog
  195. CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &SelColor, this);
  196. // Invoke the modal dialog box and return the
  197. // dialog-box result when done.
  198. if(colorDlg.DoModal() == IDOK)
  199. {
  200. // Save any changes the user may have made
  201. pCloud->m_Color.SetColor4fv(&colorDlg.m_Color);
  202. // Repaint the color button
  203. PaintButtonWnd(&m_wndEdgeButtonColor, &colorDlg.m_Color);
  204. // Reinitialize our preview terrain data and update the window
  205. pCloud->m_bBuildLists = TRUE;
  206. m_pWndCloudPreview->RedrawWindow();
  207. }
  208. }
  209. }
  210. void C3dPageCloudColor::OnHighlightButtonColorWnd() 
  211. {
  212. C3dColor SelColor;
  213. // The property page settings have been modified, so 
  214. // Enable (TRUE) or disable (FALSE) the Apply Now button
  215. SetModified(TRUE);
  216. C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
  217. if(m_pWorld) 
  218. {
  219. SelColor.SetColor4fv(&pCloud->m_ColorHighlight);
  220. // Create the dialog
  221. CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &SelColor, this);
  222. // Invoke the modal dialog box and return the
  223. // dialog-box result when done.
  224. if(colorDlg.DoModal() == IDOK)
  225. {
  226. // Save any changes the user may have made
  227. pCloud->m_ColorHighlight.SetColor4fv(&colorDlg.m_Color);
  228. // Repaint the color button
  229. PaintButtonWnd(&m_wndHighlightButtonColor, &colorDlg.m_Color);
  230. // Reinitialize our preview terrain data and update the window
  231. pCloud->m_bBuildLists = TRUE;
  232. m_pWndCloudPreview->RedrawWindow();
  233. }
  234. }
  235. }
  236. void C3dPageCloudColor::OnSelchangeComboGridsize() 
  237. {
  238. // The property page settings have been modified, so 
  239. // Enable (TRUE) or disable (FALSE) the Apply Now button
  240. SetModified(TRUE);
  241. C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
  242. // Get the zero-based index of the item selected
  243. int count = m_ComboGridSize.GetCurSel();
  244. if(count == 0)
  245. pCloud->m_iSize = 5;
  246. if(count == 1)
  247. pCloud->m_iSize = 6;
  248. if(count == 2)
  249. pCloud->m_iSize = 7;
  250. if(count == 3)
  251. pCloud->m_iSize = 8;
  252. if(count == 4)
  253. pCloud->m_iSize = 9;
  254. // Reinitialize our preview terrain data and update the window
  255. pCloud->m_bBuildLists = TRUE;
  256. m_pWndCloudPreview->RedrawWindow();
  257. }
  258. void C3dPageCloudColor::OnChangeTextureWrap() 
  259. {
  260. // The property page settings have been modified, so 
  261. // Enable (TRUE) or disable (FALSE) the Apply Now button
  262. SetModified(TRUE);
  263. // Dialog box is being initialized (FALSE)
  264. // or data is being retrieved (TRUE).
  265. UpdateData(TRUE);
  266. m_pWndCloudPreview->m_pCloudObject->m_iTextureWrap = m_iTextureWrap;
  267. // Reinitialize our preview terrain data and update the window
  268. m_pWndCloudPreview->m_pCloudObject->m_bBuildLists = TRUE;
  269. m_pWndCloudPreview->RedrawWindow();
  270. }
  271. void C3dPageCloudColor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  272. {
  273. // The property page settings have been modified, so 
  274. // Enable (TRUE) or disable (FALSE) the Apply Now button
  275. SetModified(TRUE);
  276. C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
  277. // Get the position of our slider controls.
  278. int posn = m_SliderOpacity.GetPos();
  279. pCloud->m_fOpacity = (float)(posn/100.f)*(posn/100.f);
  280. // Reinitialize our preview terrain data and update the window
  281. pCloud->m_bBuildLists = TRUE;
  282. m_pWndCloudPreview->RedrawWindow();
  283. CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  284. }
  285. void C3dPageCloudColor::OnOK() 
  286. {
  287. CPropertyPage::OnOK();
  288. }
  289. BOOL C3dPageCloudColor::OnApply() 
  290. {
  291. // The property page settings have been modified, so 
  292. // Enable (TRUE) or disable (FALSE) the Apply Now button
  293. SetModified(FALSE);
  294. // Dialog box is being initialized (FALSE)
  295. // or data is being retrieved (TRUE).
  296. UpdateData(TRUE);
  297. // Copy the parameters from the preview window to our terrain object
  298. C3dObjectCloud::CopyParameters(m_pWndCloudPreview->m_pCloudObject, m_pObject);
  299. // Force the object to rebuild its' display list
  300. m_pObject->m_bBuildLists = TRUE;
  301. return CPropertyPage::OnApply();
  302. }