00001
00002
00003
00004
00005
00006
00007 #include "Volumizer.h"
00008
00009 HWND matDlg;
00010 histo_handle *cur_handle;
00011
00015 ATOM RegisterSwatchClass(HINSTANCE hInstance)
00016 {
00017 WNDCLASSEX wcex;
00018
00019 wcex.cbSize = sizeof(WNDCLASSEX);
00020
00021 wcex.style = CS_HREDRAW | CS_VREDRAW;
00022 wcex.lpfnWndProc = SwatchProc;
00023 wcex.cbClsExtra = 0;
00024 wcex.cbWndExtra = 0;
00025 wcex.hInstance = hInstance;
00026 wcex.hIcon = NULL;
00027 wcex.hCursor = LoadCursor(NULL, IDC_HAND);
00028 wcex.hbrBackground = NULL;
00029 wcex.lpszMenuName = NULL;
00030 wcex.lpszClassName = L"ColorSwatch";
00031 wcex.hIconSm = NULL;
00032
00033 return RegisterClassEx(&wcex);
00034 }
00035
00040 LRESULT CALLBACK SwatchProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00041 {
00042 PAINTSTRUCT ps;
00043 HDC hdc;
00044
00045 static COLORREF custcolors[16];
00046
00047 switch (message)
00048 {
00049 case WM_LBUTTONDOWN:
00051 CHOOSECOLOR cc;
00052
00053 float *curcol;
00054
00055 if (GetDlgItem(matDlg, IDC_DIFFUSE) == hWnd)
00056 curcol = cur_handle->col_diffuse;
00057 else if (GetDlgItem(matDlg, IDC_AMBIENT) == hWnd)
00058 curcol = cur_handle->col_ambient;
00059 else if (GetDlgItem(matDlg, IDC_SPECULAR) == hWnd)
00060 curcol = cur_handle->col_specular;
00061
00062 cc.lStructSize = sizeof(cc);
00063 cc.hwndOwner = hWnd;
00064 cc.hInstance = 0;
00065 cc.lpCustColors = custcolors;
00066 cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
00067
00068 cc.rgbResult = RGB(curcol[0] * 256, curcol[1] * 256, curcol[2] * 256);
00069
00070 if (ChooseColor(&cc))
00071 {
00072 curcol[0] = (float)GetRValue(cc.rgbResult) / 256.0f;
00073 curcol[1] = (float)GetGValue(cc.rgbResult) / 256.0f;
00074 curcol[2] = (float)GetBValue(cc.rgbResult) / 256.0f;
00075 }
00076
00077 InvalidateRect(hWnd, NULL, FALSE);
00078 UpdateWindow(hWnd);
00079
00080 break;
00081 case WM_PAINT:
00083 hdc = BeginPaint(hWnd, &ps);
00084
00085 RECT rect;
00086 HBRUSH hbr;
00087
00088 GetClientRect(hWnd, &rect);
00089
00090 if (GetDlgItem(matDlg, IDC_DIFFUSE) == hWnd)
00091 {
00092 hbr = CreateSolidBrush(RGB((cur_handle->col_diffuse[0] * 256),
00093 (cur_handle->col_diffuse[1] * 256),
00094 (cur_handle->col_diffuse[2] * 256)));
00095 }
00096 else if (GetDlgItem(matDlg, IDC_AMBIENT) == hWnd)
00097 {
00098 hbr = CreateSolidBrush(RGB((cur_handle->col_ambient[0] * 256),
00099 (cur_handle->col_ambient[1] * 256),
00100 (cur_handle->col_ambient[2] * 256)));
00101 }
00102 else if (GetDlgItem(matDlg, IDC_SPECULAR) == hWnd)
00103 {
00104 hbr = CreateSolidBrush(RGB((cur_handle->col_specular[0] * 256),
00105 (cur_handle->col_specular[1] * 256),
00106 (cur_handle->col_specular[2] * 256)));
00107 }
00108
00109 FillRect(hdc, &rect, hbr);
00110
00111 DeleteObject(hbr);
00112
00113 EndPaint(hWnd, &ps);
00114 break;
00115 case WM_DESTROY:
00116 break;
00117 default:
00118 return DefWindowProc(hWnd, message, wParam, lParam);
00119 }
00120 return 0;
00121 }
00122
00126 BOOL CALLBACK MaterialEditorProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
00127 {
00128 char exponent[20];
00129
00130 switch (message)
00131 {
00132 case WM_INITDIALOG:
00134 matDlg = hDlg;
00135
00136 swprintf((LPWSTR)exponent, L"%1.2f", cur_handle->spec_exponent);
00137
00138 SendMessage(GetDlgItem(hDlg, IDC_EXPONENT), WM_SETTEXT, 0, (LPARAM)exponent);
00139
00140 SendMessage(GetDlgItem(hDlg, IDC_ALPHA), TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0,100));
00141 SendMessage(GetDlgItem(hDlg, IDC_ALPHA), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(cur_handle->out_alpha * 100.0f));
00142
00143 SendMessage(GetDlgItem(hDlg, IDC_GRADIENT), TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0,100));
00144 SendMessage(GetDlgItem(hDlg, IDC_GRADIENT), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(cur_handle->gradient * 100.0f));
00145
00146 return TRUE;
00147 case WM_HSCROLL:
00149 if (LOWORD(wParam) == SB_ENDSCROLL)
00150 return 0;
00151
00152 if ((HWND)lParam == GetDlgItem(hDlg, IDC_ALPHA))
00153 {
00154 cur_handle->out_alpha = (float)(SendMessage((HWND)lParam, TBM_GETPOS, 0, 0)) / 100.0f;
00155
00156 DrawHistogram(wnd_histogram);
00157 }
00158
00159 if ((HWND)lParam == GetDlgItem(hDlg, IDC_GRADIENT))
00160 {
00161 cur_handle->gradient = (float)(SendMessage((HWND)lParam, TBM_GETPOS, 0, 0)) / 100.0f;
00162 }
00163
00164 return 0;
00165 case WM_COMMAND:
00167 if (LOWORD(wParam) == IDOK)
00168 {
00169 SendMessage(GetDlgItem(hDlg, IDC_EXPONENT), WM_GETTEXT, 10, (LPARAM)exponent);
00170
00171 cur_handle->spec_exponent = (float)_wtof((LPWSTR)exponent);
00172
00173 EndDialog(hDlg, 0);
00174 return TRUE;
00175 }
00176 break;
00177 }
00178 return FALSE;
00179 }
00180
00184 void EditTransferHandle(histo_handle *handle,
00185 HWND hWndParent
00186 )
00187 {
00189 cur_handle = handle;
00190
00192 DialogBox(hInst, MAKEINTRESOURCE(IDD_MATERIAL), hWndParent, MaterialEditorProc);
00193
00195 DrawHistogram(wnd_histogram);
00196
00198 RayRender();
00199 }