/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 14 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2004 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include "ImgPF.h" static L_BOOL HandWavDialog_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam); static L_BOOL HandWavDialog_OnPaint (HWND hWnd); static L_BOOL HandWavDialog_OnCommand (HWND hWnd, L_INT nID, HWND hWndCtl, L_UINT codeNotify); static L_BOOL HandWavDialog_OnHScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos); static L_BOOL HandWavDialog_OnMouseMove (HWND hWnd, L_INT nX, L_INT nY, UINT keyFlags); static L_BOOL HandWavDialog_OnLButtonUp (HWND hWnd, L_INT, L_INT, UINT); static L_BOOL HandWavDialog_OnLButtonDown(HWND hWnd, L_BOOL , L_INT, L_INT, UINT); static L_VOID HandWavDialog_OnTimer (HWND hWnd, L_INT nID); static L_BOOL ChangeUserPoints (L_INT, L_INT, L_INT, LPHNDDLGDATA); static L_VOID DeleteUserPoint (L_INT, L_INT, L_INT, LPHNDDLGDATA ); static L_VOID GetHandWavBuf (HWND hWnd, LPHNDDLGDATA pHndDlgData); static L_VOID AddPoint (L_INT nX, L_INT nY, LPHNDDLGDATA pHndDlgData); static L_VOID InitUserPoint (HWND hWnd, LPHNDDLGDATA pHndDlgData); static L_VOID L_ApplyFilter (HWND hWnd); static L_VOID PointTrans (LPPOINT TmpPoint, LPHNDDLGDATA pHndDlgData); static L_VOID RotatePoint (LPPOINT, POINT, LPHNDDLGDATA, L_BOOL ); static L_VOID RotateBuffer (LPPOINT, L_INT, POINT, LPHNDDLGDATA); #define HND_CURVE 0x0000 #define HND_LINE 0x0001 #define GUB_CURVE 0x0000 #define GUB_LINEAR 0x0001 L_BOOL CALLBACK HandWavDlgProc (HWND hWnd, L_UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { HANDLE_MSG (hWnd, WM_COMMAND, HandWavDialog_OnCommand); HANDLE_MSG (hWnd, WM_INITDIALOG, HandWavDialog_OnInitDialog); HANDLE_MSG (hWnd, WM_HSCROLL, HandWavDialog_OnHScroll); HANDLE_MSG (hWnd, WM_PAINT, HandWavDialog_OnPaint); HANDLE_MSG (hWnd, WM_MOUSEMOVE, HandWavDialog_OnMouseMove); HANDLE_MSG (hWnd, WM_LBUTTONDOWN, HandWavDialog_OnLButtonDown); HANDLE_MSG (hWnd, WM_LBUTTONUP, HandWavDialog_OnLButtonUp); HANDLE_MSG (hWnd, WM_TIMER, HandWavDialog_OnTimer); case WM_USER_UPDATEVIEW: StatusProc.ProgressValue = 100; L_ApplyFilter (hWnd); break; } return FALSE; } static L_BOOL HandWavDialog_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam) { LPHNDDLGDATA pHndDlgData; HWND hWndParent; pCHILDDATA pData; RECT Rect; L_CHAR buffer[5]; L_INT RectWidth, cxClient, cyClient; L_INT nRangeMax[] = {1000, 100, 360}; L_INT nRangeMin[] = {10, 1, -360}; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); pHndDlgData = (LPHNDDLGDATA)lParam; MoveDialogToMiddle(hWnd); SetWindowLong(hWnd, GWL_USERDATA, (LONG) pHndDlgData); //MEMDISK...// MemorizeAndCopyBitmap (hWndParent, &pHndDlgData->Bitmap); MakeRectangleWindow(hWnd, IDC_HND_WAVSH_TXT); //MoveWindow (GetDlgItem(hWnd, IDC_HND_WAVSH_TXT), 25, 195, 210, 210, TRUE); GetClientRect(GetDlgItem(hWnd , IDC_HND_WAVSH_TXT), &Rect); cxClient = Rect.right - Rect.left; cyClient = Rect.bottom - Rect.top; RectWidth = (L_INT)(cxClient/sqrt(2.0)); pHndDlgData->WndRect.left = (cxClient - RectWidth)/2; pHndDlgData->WndRect.top = (cyClient - RectWidth)/2; pHndDlgData->WndRect.right = RectWidth + (cxClient - RectWidth)/2; pHndDlgData->WndRect.bottom = RectWidth + (cyClient - RectWidth)/2; Trackbar_SetRange(GetDlgItem(hWnd, IDC_HND_SCALE_SLD), FALSE, 10, 1000); Trackbar_SetRange(GetDlgItem(hWnd, IDC_HND_FREQ_SLD), FALSE, 1, 100); SetNumericEditBox(GetDlgItem(hWnd, IDC_HND_SCALE_EDT), 0.10, 10.00, 0.01, 2, TRUE); SetNumericEditBox(GetDlgItem(hWnd, IDC_HND_FREQ_EDT), 1, 100, 1, 0, FALSE); SetNumericEditBox(GetDlgItem(hWnd, IDC_HND_ANGL_EDT), -360, 360, 1, 0, FALSE); Trackbar_SetRange(GetDlgItem(hWnd, IDC_HND_ANGL_SLD), TRUE, -360, 360); Trackbar_SetPos (GetDlgItem(hWnd, IDC_HND_ANGL_SLD), TRUE, 0); ComboBox_AddString(GetDlgItem(hWnd, IDC_HND_WAVSH_COM), TEXT("Curve")); ComboBox_AddString(GetDlgItem(hWnd, IDC_HND_WAVSH_COM), TEXT("Line")); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_HND_WAVSH_COM), 0); ComboBox_AddString(GetDlgItem(hWnd, IDC_HND_FILL_COM), TEXT("Fill Color")); ComboBox_AddString(GetDlgItem(hWnd, IDC_HND_FILL_COM), TEXT("Repeat Edge")); ComboBox_AddString(GetDlgItem(hWnd, IDC_HND_FILL_COM), TEXT("No Change")); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_HND_FILL_COM), 0); ComboBox_AddString(GetDlgItem(hWnd, IDC_HND_MOD_COM), TEXT("Period")); ComboBox_AddString(GetDlgItem(hWnd, IDC_HND_MOD_COM), TEXT("Freqeuncy")); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_HND_MOD_COM), 0); Trackbar_SetPos (GetDlgItem(hWnd, IDC_HND_SCALE_SLD), TRUE, 1); Trackbar_SetPos (GetDlgItem(hWnd, IDC_HND_FREQ_SLD), TRUE, 1); Edit_LimitText(GetDlgItem(hWnd, IDC_HND_SCALE_EDT), 5); _gcvt( 1.0, 5, buffer ); SetWindowTextA(GetDlgItem(hWnd, IDC_HND_SCALE_EDT), buffer); Progress_SetRange(StatusProc.ProgWnd, 0, 100); Progress_SetPos(StatusProc.ProgWnd, 0); StatusProc.bProgress = TRUE; StatusProc.DlgWnd = hWnd; StatusProc.bInvalidate = FALSE; StatusProc.bEnd = FALSE; StatusProc.ProgressValue = 100; StatusProc.ProgWnd = GetDlgItem(hWnd, IDC_HND_PROG); Rect = pHndDlgData->WndRect; cxClient = Rect.right - Rect.left + 1; cyClient = Rect.bottom - Rect.top + 1; pHndDlgData->pCrvelm = (L_INT L_FAR *)malloc(cxClient* sizeof(L_INT)); pHndDlgData->pBuf = (L_INT L_FAR *)malloc(cxClient* sizeof(L_INT)); pHndDlgData->nUserPntCnt= 2; InitUserPoint(hWnd, pHndDlgData); GetHandWavBuf(hWnd, pHndDlgData); pHndDlgData->pCrvPnt = (LPPOINT)malloc(cyClient * sizeof(POINT)); SetDlgItemInt(hWnd, IDC_HND_FREQ_EDT, 100, FALSE); SetDlgItemInt(hWnd, IDC_HND_ANGL_EDT, 0, FALSE); memset ( pHndDlgData->nPostionH, 0, 4 * sizeof(L_INT)); pHndDlgData->nPostionH[0] = 100; pHndDlgData->nPostionH[1] = 100; pHndDlgData->uColFlag = FILL_CLR; pHndDlgData->uScale = 100; pHndDlgData->uFreq = 100; pHndDlgData->nAngle = 0; pData->uTimerID = SetTimer(hWnd, 1, 100, NULL); return ( TRUE ); } static L_VOID HandWavDialog_OnTimer(HWND hWnd, L_INT nID) { Dialog_Timer(nID); } static L_BOOL HandWavDialog_OnPaint (HWND hWnd) { PAINTSTRUCT ps; HDC hdc, hdcMemo; RECT Rect, ClntRect; L_INT cxClient, cyClient; HBITMAP hBitmap; HPEN hPen; HPEN hOldPen; HBRUSH hOldBrush; HBRUSH hbrush; L_INT nCount, nBufCnt; L_INT nDivCnt; POINT ptCenter, pTmp; L_INT x1, y1, x2, y2; LPPOINT pPntBuf; LPHNDDLGDATA pHndDlgData; pHndDlgData = (LPHNDDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); GetClientRect(GetDlgItem(hWnd , IDC_HND_WAVSH_TXT), &ClntRect); Rect = pHndDlgData->WndRect; cxClient = Rect.right - Rect.left; cyClient = Rect.bottom - Rect.top; nDivCnt = 6; pPntBuf = (LPPOINT)malloc((cxClient + 1) * sizeof(POINT)); ptCenter.x = cxClient/2 + Rect.left; ptCenter.y = cyClient/2 + Rect.top; hdc = BeginPaint(GetDlgItem(hWnd, IDC_HND_WAVSH_TXT), &ps); hBitmap = CreateCompatibleBitmap(hdc, ClntRect.right - ClntRect.left, ClntRect.bottom - ClntRect.top); hdcMemo = CreateCompatibleDC(hdc); SelectObject(hdcMemo, hBitmap); FillRect(hdcMemo, &ClntRect, (HBRUSH) (COLOR_WINDOW + 2)); hbrush = CreateSolidBrush(RGB(0, 0, 0)); SelectObject(hdcMemo, hbrush); hPen = CreatePen(PS_SOLID, 0, RGB(255, 255, 255)); SelectObject(hdcMemo, hPen); Ellipse(hdcMemo, 0, 0, ClntRect.right - ClntRect.left, ClntRect.bottom - ClntRect.top); for(nCount=0 ; nCount <= nDivCnt; nCount++) { x1 = Rect.left; y1 = nCount * (cyClient)/nDivCnt + Rect.top; x2 = (cxClient) + Rect.left; y2 = nCount * (cyClient)/nDivCnt + Rect.top; for(nBufCnt = 0; nBufCnt <= cxClient; nBufCnt++) { pPntBuf[nBufCnt].y = (L_INT)(((((L_DOUBLE)y2 - y1)/(x2 - x1)) * (nBufCnt - x1)) + y1); pPntBuf[nBufCnt].x = nBufCnt + Rect.left; } RotateBuffer(pPntBuf, cxClient + 1, ptCenter, pHndDlgData); Polyline(hdcMemo, pPntBuf, cxClient + 1); } for(nCount=0;nCount <= nDivCnt; nCount++) { x1 = nCount*(cxClient)/nDivCnt + Rect.left; y1 = Rect.top; x2 = nCount*(cxClient)/nDivCnt + Rect.left; y2 = cyClient + Rect.top; for(nBufCnt = 0; nBufCnt <= cxClient; nBufCnt++) { pPntBuf[nBufCnt].x = (L_INT)(((((L_DOUBLE)x2 - x1)/(y2 - y1)) * (nBufCnt - y1)) + x1); pPntBuf[nBufCnt].y = nBufCnt + Rect.top; } RotateBuffer(pPntBuf, cxClient + 1, ptCenter, pHndDlgData); Polyline(hdcMemo, pPntBuf, cxClient + 1); } hbrush = CreateSolidBrush(RGB(255, 255, 0)); hOldBrush = SelectObject(hdcMemo, hbrush); for(nCount=0;nCount<(L_INT) pHndDlgData->nUserPntCnt;nCount++) { pTmp.x = pHndDlgData->UserPoint[nCount].x + Rect.left; pTmp.y = pHndDlgData->UserPoint[nCount].y + Rect.top; RotatePoint(&pTmp, ptCenter, pHndDlgData, FALSE); Ellipse(hdcMemo, pTmp.x - 3, pTmp.y - 3, pTmp.x + 3, pTmp.y + 3); } hPen = CreatePen(PS_SOLID, 0, RGB(100, 255, 130)); hOldPen = SelectObject(hdcMemo, hPen); for(nCount = 0; nCount <= cxClient; nCount++) { pHndDlgData->pCrvPnt[nCount].x = nCount + Rect.left; pHndDlgData->pCrvPnt[nCount].y = (L_INT) (pHndDlgData->pCrvelm[nCount]) + Rect.left; } RotateBuffer(pHndDlgData->pCrvPnt, cxClient + 1, ptCenter, pHndDlgData); Polyline(hdcMemo, pHndDlgData->pCrvPnt, cxClient + 1); StretchBlt(hdc, 0, 0, ClntRect.right - ClntRect.left, ClntRect.bottom - ClntRect.top, hdcMemo, 0, 0, ClntRect.right - ClntRect.left, ClntRect.bottom, SRCCOPY); DeleteDC (hdcMemo); DeleteBitmap(hBitmap); DeletePen (hPen); DeleteBrush (hbrush); DeleteBrush (hOldBrush); DeletePen (hOldPen); EndPaint(GetDlgItem(hWnd, IDC_HND_WAVSH_TXT), &ps); GetClientRect(GetDlgItem(hWnd , IDC_HND_COLOR_TXT), &Rect); hdc = BeginPaint(GetDlgItem(hWnd, IDC_HND_COLOR_TXT), &ps); hbrush = CreateSolidBrush( pHndDlgData->crColor); FillRect(hdc, &Rect, !ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_HND_FILL_COM)) ? hbrush : (HBRUSH) COLOR_WINDOW); DeleteObject (hbrush); EndPaint(GetDlgItem(hWnd, IDC_HND_COLOR_TXT), &ps); if(pPntBuf) free(pPntBuf); return FALSE; } static L_BOOL HandWavDialog_OnCommand (HWND hWnd, L_INT nID, HWND hWndCtl, L_UINT codeNotify) { LPHNDDLGDATA pHndDlgData; HWND hWndParent; L_INT nRangeMax[] = {1000, 100, 360}; L_INT nRangeMin[] = {10 , 1, -360}; HWND hCtl; pCHILDDATA pData; L_INT nValue; L_DOUBLE dValue; L_INT nIndex; L_CHAR pText[5]; COLORREF crColor; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); pHndDlgData = (LPHNDDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); switch (nID) { case IDC_HND_SCALE_EDT: case IDC_HND_FREQ_EDT: case IDC_HND_ANGL_EDT: if(codeNotify == EN_CHANGE) { nValue = GetDlgItemInt(hWnd, nID, NULL, TRUE); hCtl = GetDlgItem(hWnd, nID + 3); nIndex = nID - IDC_HND_SCALE_EDT; if(nIndex == 0) { GetWindowTextA(hWndCtl, pText, 5); dValue = atof(pText); nValue = (L_INT)(dValue * 100); } if(nValue >= nRangeMin[nIndex] && nValue <= nRangeMax[nIndex]) { pHndDlgData->nPostionH[nIndex] = nValue; Trackbar_SetPos (hCtl, TRUE, nValue); } else { if(nValue > nRangeMax[nIndex]) { if(!nIndex) { _gcvt( nRangeMax[nIndex]/100.0, 5, pText ); SetWindowTextA(GetDlgItem(hWnd, IDC_HND_SCALE_EDT), pText); } else { SetDlgItemInt(hWnd, nID, nRangeMax[nIndex], TRUE); nValue = nRangeMax[nIndex]; } } else { if(nValue == 0) return TRUE; else { if(!nIndex) { _gcvt( nRangeMin[nIndex]/100.0, 5, pText ); SetWindowTextA(GetDlgItem(hWnd, IDC_HND_SCALE_EDT), pText); } else { SetDlgItemInt(hWnd, nID, nRangeMin[nIndex], TRUE); nValue = nRangeMin[nIndex]; } } } } switch (nIndex) { case 0: if( pHndDlgData->uScale == (L_UINT)nValue) return TRUE; pHndDlgData->uScale = nValue; break; case 1: if( pHndDlgData->uFreq == (L_UINT)nValue) return TRUE; pHndDlgData->uFreq = nValue; break; case 2: if( pHndDlgData->nAngle == nValue) return TRUE; pHndDlgData->nAngle = nValue; InvalidateRect(hWnd, NULL, FALSE); break; } L_ApplyFilter (hWnd); } break; case IDC_HND_MOD_COM: if (codeNotify == CBN_SELCHANGE) { nIndex = (ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_HND_MOD_COM)) << 4); if ( pHndDlgData->uColFlag != ((pHndDlgData->uColFlag & 0xFFFFFF0F) | nIndex) ) { pHndDlgData->uColFlag = pHndDlgData->uColFlag & 0xFFFFFF0F; pHndDlgData->uColFlag = pHndDlgData->uColFlag | nIndex; InvalidateRect(hWndCtl, NULL, FALSE); L_ApplyFilter (hWnd); } } break; case IDC_HND_WAVSH_COM: if (codeNotify == CBN_SELCHANGE) { if (pHndDlgData->uFlag != ComboBox_GetCurSel(hWndCtl)) { pHndDlgData->uFlag = ComboBox_GetCurSel(hWndCtl); GetHandWavBuf(hWnd, pHndDlgData); InvalidateRect(hWndCtl, NULL, FALSE); InvalidateRect(hWnd, NULL, FALSE); L_ApplyFilter (hWnd); } } break; case IDC_HND_COLOR_BTN: crColor = pHndDlgData->crColor; pHndDlgData->crColor = ShowColorDialog(hWnd, crColor); if (crColor != pHndDlgData->crColor) { InvalidateRect(hWnd, NULL, FALSE); L_ApplyFilter (hWnd); } break; case IDC_HND_FILL_COM: if (codeNotify == CBN_SELCHANGE) { nIndex = (ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_HND_FILL_COM))); if ( pHndDlgData->uColFlag != ((pHndDlgData->uColFlag & 0xFFFFFFF0) | nIndex) ) { EnableWindow(GetDlgItem(hWnd, IDC_HND_COLOR_BTN), !ComboBox_GetCurSel(hWndCtl)); EnableWindow(GetDlgItem(hWnd, IDC_HND_COLOR_TXT), !ComboBox_GetCurSel(hWndCtl)); pHndDlgData->uColFlag = pHndDlgData->uColFlag & 0xFFFFFFF0; pHndDlgData->uColFlag = pHndDlgData->uColFlag | nIndex; InvalidateRect(hWndCtl, NULL, FALSE); InvalidateRect(hWnd, NULL, FALSE); L_ApplyFilter (hWnd); } } break; case IDCANCEL: StatusProc.bProgress = FALSE; StatusProc.bKillProgress = TRUE ; StatusProc.ProgressValue = 100 ; if(pHndDlgData->pCrvelm) { free(pHndDlgData->pCrvelm); pHndDlgData->pCrvelm = NULL; } if(pHndDlgData->pBuf) { free(pHndDlgData->pBuf); pHndDlgData->pBuf = NULL; } EndDialog(hWnd, FALSE); break; case IDOK: ShowStatusWindow(FALSE); StatusProc.bStillWork = TRUE; StatusProc.bInvalidate = TRUE; StatusProc.bEnd = TRUE; EndDialog(hWnd, TRUE); break; } return TRUE; } L_BOOL HandWavDialog_OnLButtonUp (HWND hWnd, L_INT nX, L_INT nY, UINT keyFlags) { LPHNDDLGDATA pHndDlgData; pHndDlgData = (LPHNDDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); ReleaseCapture(); if( pHndDlgData->bChange || pHndDlgData->bAdd || pHndDlgData->bDel) { SetCursor(LoadCursor(NULL, IDC_SIZEALL)); pHndDlgData->bChange = FALSE; pHndDlgData->bAdd = FALSE; pHndDlgData->bDel = FALSE; L_ApplyFilter (hWnd); } return TRUE; } L_BOOL HandWavDialog_OnLButtonDown (HWND hWnd, L_BOOL fDoubleClick, L_INT nX, L_INT nY, UINT keyFlags) { POINT TmpPoint; RECT Rect; L_INT nyPos; L_INT cxClient; L_INT cyClient; L_INT nCount; LPHNDDLGDATA pHndDlgData; POINT ptCenter; pHndDlgData = (LPHNDDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); Rect = pHndDlgData->WndRect; OffsetRect(&Rect, -1 * Rect.left, -1 * Rect.top); cxClient = pHndDlgData->WndRect.right - pHndDlgData->WndRect.left; cyClient = pHndDlgData->WndRect.bottom - pHndDlgData->WndRect.top; ptCenter.x = cxClient/2; ptCenter.y = cyClient/2; TmpPoint.x = nX; TmpPoint.y = nY; ClientToScreen(hWnd, &TmpPoint); ScreenToClient( GetDlgItem(hWnd, IDC_HND_WAVSH_TXT), &TmpPoint); PointTrans(&TmpPoint, pHndDlgData); RotatePoint(&TmpPoint, ptCenter, pHndDlgData, TRUE); if (PtInRect(&Rect, TmpPoint)) { nyPos = (L_INT) pHndDlgData->pCrvelm[TmpPoint.x]; SetCapture(hWnd); if(TmpPoint.y < nyPos + 30 && TmpPoint.y > nyPos - 30) { SetCursor(LoadCursor(NULL, IDC_SIZEALL)); for(nCount=0; nCount <= (L_INT) pHndDlgData->nUserPntCnt;nCount++) { SetRect(&Rect, pHndDlgData->UserPoint[nCount].x - 5, pHndDlgData->UserPoint[nCount].y - 30, pHndDlgData->UserPoint[nCount].x + 5, pHndDlgData->UserPoint[nCount].y + 30); if (PtInRect(&Rect, TmpPoint)) { pHndDlgData->bChange = TRUE; pHndDlgData->nPoint = nCount; if(TmpPoint.x < pHndDlgData->UserPoint[0].x) { pHndDlgData->nPoint= nCount; } if(TmpPoint.x > pHndDlgData->UserPoint[ pHndDlgData->nUserPntCnt - 1].x) pHndDlgData->nPoint= pHndDlgData->nUserPntCnt - 1; if(!ChangeUserPoints(TmpPoint.x, TmpPoint.y, pHndDlgData->nPoint, pHndDlgData)) DeleteUserPoint(TmpPoint.x, TmpPoint.y, pHndDlgData->nPoint, pHndDlgData); GetHandWavBuf(hWnd, pHndDlgData); InvalidateRect(hWnd, NULL, FALSE); return TRUE; } } pHndDlgData->nUserPntCnt++; AddPoint(TmpPoint.x, TmpPoint.y, pHndDlgData); GetHandWavBuf(hWnd, pHndDlgData); InvalidateRect(hWnd, NULL, FALSE); return TRUE; } } return FALSE; } L_BOOL HandWavDialog_OnMouseMove (HWND hWnd, L_INT nX, L_INT nY, UINT keyFlags) { POINT TmpPoint; RECT Rect; L_INT nyPos; L_INT cxClient; L_INT cyClient; L_INT nCount; POINT ptCenter; L_BOOL bCurs = FALSE; LPHNDDLGDATA pHndDlgData; pHndDlgData = (LPHNDDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); Rect = pHndDlgData->WndRect; OffsetRect(&Rect, -1 * Rect.left, -1 * Rect.top); cxClient = pHndDlgData->WndRect.right - pHndDlgData->WndRect.left; cyClient = pHndDlgData->WndRect.bottom - pHndDlgData->WndRect.top; ptCenter.x = cxClient/2; ptCenter.y = cyClient/2; TmpPoint.x = nX; TmpPoint.y = nY; ClientToScreen(hWnd, &TmpPoint); ScreenToClient( GetDlgItem(hWnd, IDC_HND_WAVSH_TXT), &TmpPoint); PointTrans(&TmpPoint, pHndDlgData); RotatePoint(&TmpPoint, ptCenter, pHndDlgData, TRUE); if (PtInRect(&Rect, TmpPoint)) { nyPos = (L_INT) pHndDlgData->pCrvelm[TmpPoint.x]; if(TmpPoint.y < nyPos + 30 && TmpPoint.y > nyPos - 30) { SetCursor(LoadCursor(NULL, IDC_CROSS)); } for(nCount = 0; nCount <= (L_INT) pHndDlgData->nUserPntCnt; nCount++) { SetRect(&Rect, pHndDlgData->UserPoint[nCount].x - 5, pHndDlgData->UserPoint[nCount].y - 30, pHndDlgData->UserPoint[nCount].x + 5, pHndDlgData->UserPoint[nCount].y + 30); if (PtInRect(&Rect, TmpPoint)) { bCurs = TRUE; break; } } if(bCurs) SetCursor(LoadCursor(NULL, IDC_SIZEALL)); if( pHndDlgData->bChange) { if(!ChangeUserPoints(TmpPoint.x, TmpPoint.y, pHndDlgData->nPoint, pHndDlgData)) DeleteUserPoint(TmpPoint.x, TmpPoint.y, pHndDlgData->nPoint, pHndDlgData); GetHandWavBuf(hWnd, pHndDlgData); InvalidateRect(hWnd, NULL, FALSE); } return FALSE; } return FALSE; } static L_BOOL HandWavDialog_OnHScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos) { L_INT nCtrlID, nIndex; LPHNDDLGDATA pHndDlgData; L_CHAR buffer[5]; pHndDlgData = (LPHNDDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); nCtrlID = GetWindowLong (hWndCtl, GWL_ID); nIndex = nCtrlID - IDC_HND_SCALE_SLD; switch(nIndex) { case 0: _gcvt(Trackbar_GetPos(hWndCtl) /100.0, 5, buffer ); SetWindowTextA(GetDlgItem(hWnd, IDC_HND_SCALE_EDT), buffer); break; case 1: SetDlgItemInt(hWnd, IDC_HND_FREQ_EDT, Trackbar_GetPos(hWndCtl), TRUE); break; case 2: SetDlgItemInt(hWnd, IDC_HND_ANGL_EDT, Trackbar_GetPos(hWndCtl), TRUE); break; } return TRUE; } L_VOID L_ApplyFilter (HWND hWnd) { pCHILDDATA pData; L_INT nRet = 0; HWND hWndParent; LPHNDDLGDATA pHndDlgData; L_INT cxClient, cyClient; if ( 100 != StatusProc.ProgressValue ) { StatusProc.bKillProgress = TRUE ; return ; } pHndDlgData = (LPHNDDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); cxClient= pHndDlgData->WndRect.right - pHndDlgData->WndRect.left; cyClient= pHndDlgData->WndRect.bottom - pHndDlgData->WndRect.top; FreeMemorizedBitmap (hWndParent); //MEMDISK// L_CopyBitmap(&pData->LeadBitmap, &pHndDlgData->Bitmap, sizeof(BITMAPHANDLE)); nRet = L_FreeHandWaveBitmap(&pData->LeadBitmap, pHndDlgData->pBuf, cxClient, pHndDlgData->uScale, pHndDlgData->uFreq, pHndDlgData->nAngle * 100, pHndDlgData->crColor, pHndDlgData->uColFlag); if(nRet == SUCCESS) { InvalidateRect(hWndParent, NULL, FALSE); StatusProc.ProgressValue = 100; Progress_SetPos(StatusProc.ProgWnd , 0); if(StatusProc.bEnd) { StatusProc.bProgress = FALSE; StatusProc.bKillProgress = TRUE ; if(pHndDlgData->pCrvelm) { free(pHndDlgData->pCrvelm); pHndDlgData->pCrvelm = NULL; } if(pHndDlgData->pBuf) { free(pHndDlgData->pBuf); pHndDlgData->pBuf = NULL; } } } } static L_BOOL ChangeUserPoints(L_INT nX, L_INT nY, L_INT Point, LPHNDDLGDATA pHndDlgData) { if(Point == 0 || Point == (L_INT) pHndDlgData->nUserPntCnt - 1) { if(Point == (L_INT) pHndDlgData->nUserPntCnt-1 && nX < pHndDlgData->UserPoint[ pHndDlgData->nUserPntCnt - 2].x + 5) return TRUE; if(Point == 0 && nX > pHndDlgData->UserPoint[1].x - 5) return TRUE; pHndDlgData->UserPoint[Point].y = nY; return TRUE; } if(nX <= pHndDlgData->UserPoint[Point-1].x || nX >= pHndDlgData->UserPoint[Point+1].x) return FALSE; pHndDlgData->UserPoint[Point].x = nX; pHndDlgData->UserPoint[Point].y = nY; return TRUE; } static L_VOID DeleteUserPoint(L_INT nX, L_INT nY, L_INT Point, LPHNDDLGDATA pHndDlgData) { L_INT nCount; if (Point == 0 || Point == (L_INT) pHndDlgData->nUserPntCnt) return; pHndDlgData->bDel = TRUE; for(nCount = Point; nCount < (L_INT) pHndDlgData->nUserPntCnt; nCount++) { pHndDlgData->UserPoint[nCount].x = pHndDlgData->UserPoint[nCount+1].x; pHndDlgData->UserPoint[nCount].y = pHndDlgData->UserPoint[nCount+1].y; } pHndDlgData->bChange = FALSE; pHndDlgData->nUserPntCnt--; } L_VOID GetHandWavBuf(HWND hWnd, LPHNDDLGDATA pHndDlgData) { L_INT cxClient; L_INT cyClient; L_INT nCount; L_INT nPtCurveNo; cxClient= pHndDlgData->WndRect.right - pHndDlgData->WndRect.left; cyClient= pHndDlgData->WndRect.bottom - pHndDlgData->WndRect.top; L_GetCurvePoints( pHndDlgData->pBuf, pHndDlgData->UserPoint, pHndDlgData->nUserPntCnt, &nPtCurveNo, pHndDlgData->uFlag); for(nCount = 0;nCount < nPtCurveNo;nCount++) { pHndDlgData->pBuf[nCount] = pHndDlgData->pBuf[nCount]; pHndDlgData->pCrvelm[nCount] = pHndDlgData->pBuf[nCount]/1000; pHndDlgData->pBuf[nCount] = (cyClient/2) * 1000 - pHndDlgData->pBuf[nCount]; } } L_VOID AddPoint(L_INT nX, L_INT nY, LPHNDDLGDATA pHndDlgData) { L_INT nCount; L_INT nShift; for(nCount = 0;nCount < (L_INT) pHndDlgData->nUserPntCnt;nCount++) { if (nX < pHndDlgData->UserPoint[nCount].x) break; } for(nShift = pHndDlgData->nUserPntCnt - 1;nShift > nCount;nShift--) { pHndDlgData->UserPoint[nShift].x = pHndDlgData->UserPoint[nShift-1].x; pHndDlgData->UserPoint[nShift].y = pHndDlgData->UserPoint[nShift-1].y; } pHndDlgData->UserPoint[nCount].x = nX; pHndDlgData->UserPoint[nCount].y = nY; pHndDlgData->nPoint = nCount; pHndDlgData->bChange= TRUE; pHndDlgData->bAdd= FALSE; } L_VOID InitUserPoint(HWND hWnd, LPHNDDLGDATA pHndDlgData) { pHndDlgData->bChange = FALSE; pHndDlgData->bAdd = FALSE; pHndDlgData->UserPoint[0].x = 0; pHndDlgData->UserPoint[0].y = (pHndDlgData->WndRect.bottom - pHndDlgData->WndRect.top)/2; pHndDlgData->UserPoint[1].x = (pHndDlgData->WndRect.right - pHndDlgData->WndRect.left); pHndDlgData->UserPoint[1].y = (pHndDlgData->WndRect.bottom - pHndDlgData->WndRect.top)/2; } L_VOID PointTrans(LPPOINT TmpPoint, LPHNDDLGDATA pHndDlgData) { TmpPoint->x = TmpPoint->x - pHndDlgData->WndRect.left; TmpPoint->y = TmpPoint->y - pHndDlgData->WndRect.top; } L_VOID RotatePoint(LPPOINT pRotPoint, POINT ptCenter, LPHNDDLGDATA pHndDlgData, L_BOOL bNegative) { L_DOUBLE dcos, dsin; POINT nTmp; L_INT nAngle; nTmp.x = pRotPoint->x; nTmp.y = pRotPoint->y; if(bNegative) nAngle = (pHndDlgData->nAngle) - 90; else nAngle = -1 * (pHndDlgData->nAngle) + 90; dcos = cos(nAngle * 3.14 / 180.0); dsin = sin( nAngle * 3.14 / 180.0); pRotPoint->x = (long)(dcos * (nTmp.x - ptCenter.x) - dsin * (nTmp.y - ptCenter.y) + ptCenter.x); pRotPoint->y = (long)(dsin * (nTmp.x - ptCenter.x) + dcos * (nTmp.y - ptCenter.y) + ptCenter.y); } L_VOID RotateBuffer(LPPOINT pRotBuf, L_INT uBufSize, POINT ptCenter, LPHNDDLGDATA pHndDlgData) { L_DOUBLE dcos, dsin; POINT nTmp; L_INT nAngle; L_INT nCount; nAngle = -1 * (pHndDlgData->nAngle) + 90; dcos = cos(nAngle * 3.14 / 180.0); dsin = sin( nAngle * 3.14 / 180.0); for(nCount = 0; nCount < uBufSize; nCount++) { nTmp.x = pRotBuf[nCount].x; nTmp.y = pRotBuf[nCount].y; pRotBuf[nCount].x = (long)(dcos * (nTmp.x - ptCenter.x) - dsin * (nTmp.y - ptCenter.y) + ptCenter.x); pRotBuf[nCount].y = (long)(dsin * (nTmp.x - ptCenter.x) + dcos * (nTmp.y - ptCenter.y) + ptCenter.y); } }