#include "ImgPF.h" static L_BOOL MTls_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam); static L_VOID MTls_OnCommand (HWND hWnd, L_INT nID, HWND hWndCtl, L_UINT uCodeNotify); static L_VOID MTls_OnHScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos); static L_VOID MTls_OnTimer (HWND hWnd, L_INT nID); static L_BOOL MTls_OnPaint (HWND hWnd); static L_VOID L_ApplyFilter (HWND hWnd); static LRESULT CALLBACK Mouse(L_INT nCode, WPARAM wParam, LPARAM lParam) { LPMSCTLSDLGDATA pMscTlsDlgData; LPMOUSEHOOKSTRUCT pMouseHook; HWND hWndParent; pCHILDDATA pData; RECT rcRect; POINT TmpPoint; DWORD dwStyle; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); pMscTlsDlgData = (LPMSCTLSDLGDATA)GetWindowLong(hGlobalWnd, GWL_USERDATA); pMouseHook = (LPMOUSEHOOKSTRUCT)lParam; GetWindowRect(hGlobalWnd, &rcRect); if (PtInRect(&rcRect, pMouseHook->pt)) return 0; switch(LOWORD(wParam)) { case WM_NCMOUSEMOVE: TmpPoint = pMouseHook->pt; if (PtInRect(&rcRect, TmpPoint)) break; if (pMscTlsDlgData->bPushed) { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); } else { dwStyle = GetWindowLong (hWndParent, GWL_STYLE); if ((WS_VSCROLL & dwStyle) || (WS_HSCROLL & dwStyle)) PostMessage(hWndParent, WM_USER_CHANGECURSOR, (WPARAM)hInst, (LONG)MAKEINTRESOURCE(IDC_CURS11)); ScreenToClient(hWndParent, &pMouseHook->pt); GetClientRect(hGlobalWnd, &rcRect); if (!PtInRect(&rcRect, pMouseHook->pt)) SendMessage((hWndParent), WM_MOUSEMOVE, wParam, MAKELPARAM((pMouseHook->pt.x), (pMouseHook->pt.y))); } break; case WM_NCLBUTTONDOWN: TmpPoint = pMouseHook->pt; if (PtInRect(&rcRect, TmpPoint)) break; if (pMscTlsDlgData->bPushed) { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); ScreenToClient(hWndParent, &pMouseHook->pt); GetClientRect(hWndParent, &rcRect); if (PtInRect(&pData->rcView, pMouseHook->pt)) { if (L_BitmapHasRgn(&pData->LeadBitmap)) { L_GetBitmapRgnBounds(&pData->LeadBitmap, NULL, &rcRect); TmpPoint.x = pMouseHook->pt.x + pData->nHScrollPos; TmpPoint.y = pMouseHook->pt.y + pData->nVScrollPos; if (!PtInRect(&rcRect, TmpPoint)) return CallNextHookEx(pMscTlsDlgData->hMouseHook , nCode, wParam, lParam); } pData->ptCenter.x = pMscTlsDlgData->uxCenter = pMouseHook->pt.x + pData->nHScrollPos; pData->ptCenter.y = pMscTlsDlgData->uyCenter = pMouseHook->pt.y + pData->nVScrollPos; SetDlgItemInt(hGlobalWnd, IDC_MTLS_XCNR_EDT, pMscTlsDlgData->uxCenter, TRUE); SetDlgItemInt(hGlobalWnd, IDC_MTLS_YCNR_EDT, pMscTlsDlgData->uyCenter, TRUE); InvalidateRect(hWndParent, NULL, FALSE); L_ApplyFilter (hGlobalWnd); PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); } else { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_ARROW); } } else { dwStyle = GetWindowLong (hWndParent, GWL_STYLE); if ((WS_VSCROLL & dwStyle) || (WS_HSCROLL & dwStyle)) PostMessage(hWndParent, WM_USER_CHANGECURSOR, (WPARAM)hInst, (LONG)MAKEINTRESOURCE(IDC_CURS11)); ScreenToClient(hWndParent, &pMouseHook->pt); SendMessage(hWndParent, WM_LBUTTONDOWN, wParam, MAKELPARAM((pMouseHook->pt.x), (pMouseHook->pt.y))); } break; case WM_NCLBUTTONUP: TmpPoint = pMouseHook->pt; if (PtInRect(&rcRect, TmpPoint)) break; if (pMscTlsDlgData->bPushed) { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); } else { dwStyle = GetWindowLong (hWndParent, GWL_STYLE); if ((WS_VSCROLL & dwStyle) || (WS_HSCROLL & dwStyle)) PostMessage(hWndParent, WM_USER_CHANGECURSOR, (WPARAM)hInst, (LONG)MAKEINTRESOURCE(IDC_CURS11)); ScreenToClient(hWndParent, &pMouseHook->pt); GetClientRect(hGlobalWnd, &rcRect); if (!PtInRect(&rcRect, pMouseHook->pt)) SendMessage(hWndParent, WM_LBUTTONUP, wParam, MAKELPARAM((pMouseHook->pt.x), (pMouseHook->pt.y))); } break; } if (pMscTlsDlgData) { if (LOWORD(wParam) >= WM_NCMOUSEMOVE && LOWORD(wParam) <= WM_NCMBUTTONDBLCLK) return TRUE; else return CallNextHookEx(pMscTlsDlgData->hMouseHook , nCode, wParam, lParam); } else return FALSE; } L_BOOL CALLBACK MosaicDlgProc(HWND hWnd, L_UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { HANDLE_MSG(hWnd, WM_INITDIALOG, MTls_OnInitDialog); HANDLE_MSG(hWnd, WM_COMMAND, MTls_OnCommand); HANDLE_MSG(hWnd, WM_PAINT, MTls_OnPaint); HANDLE_MSG(hWnd, WM_HSCROLL, MTls_OnHScroll); HANDLE_MSG(hWnd, WM_TIMER, MTls_OnTimer); case WM_USER_UPDATEVIEW: StatusProc.ProgressValue = 100; L_ApplyFilter(hWnd); break; } return FALSE; } static L_BOOL MTls_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM Data) { HWND hWndParent; pCHILDDATA pData; LPMSCTLSDLGDATA pMscTlsDlgData; L_INT nIndex; RECT rcRgn; L_INT nRangeMax[] = {0, 0, 0, 0, 255, 100, 15}; L_INT nRangeMin[] = {1, 1, 0, 0, 0, 0, 1}; L_INT nPosInit[] = {17, 17, 0, 0, 0, 60, 4}; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA(hWndParent); pMscTlsDlgData = (LPMSCTLSDLGDATA)(Data); pData->bCross = FALSE; EnableWindow(GetDlgItem(hWnd, IDC_MTLS_POS_BTN), pData->bCross); hGlobalWnd = hWnd; SetWindowLong(hWnd, GWL_USERDATA, (LONG)pMscTlsDlgData); MemorizeAndCopyBitmap (hWndParent, &pMscTlsDlgData->LeadBitmap); L_GetBitmapRgnBounds(&pMscTlsDlgData->LeadBitmap, NULL, &rcRgn); MoveDialogToMiddle(hWnd); if (Is16Bit(&pData->LeadBitmap)) nRangeMax[4] = 0xffff; nRangeMax[0] = (rcRgn.right - rcRgn.left); nRangeMax[1] = (rcRgn.bottom - rcRgn.top); nRangeMax[2] = nRangeMax[0] - 1; nRangeMax[3] = nRangeMax[1] - 1; nPosInit[2] = (rcRgn.right - rcRgn.left) >> 1; nPosInit[3] = (rcRgn.bottom - rcRgn.top) >> 1; pData->ptCenter.x = (rcRgn.right + rcRgn.left) / 2; pData->ptCenter.y = (rcRgn.bottom + rcRgn.top) / 2; pMscTlsDlgData->nSldBaseID = IDC_MTLS_WDTH_SLD; pMscTlsDlgData->nEdtBaseID = IDC_MTLS_WDTH_EDT; pMscTlsDlgData->nSlideNum = 7; pMscTlsDlgData->uShadowAngle = SHADOW_SE; pMscTlsDlgData->uShadowType = MSCT_SHADOWGRAY >> 4; pMscTlsDlgData->uMosaicType = MSCT_CART; /* border color check here */ pMscTlsDlgData->uWidth = nPosInit[0]; pMscTlsDlgData->uHeight = nPosInit[1]; pMscTlsDlgData->uxCenter = nPosInit[2]; pMscTlsDlgData->uyCenter = nPosInit[3]; pMscTlsDlgData->uShadowThreshold = nPosInit[4]; pMscTlsDlgData->uOpacity = nPosInit[5]; pMscTlsDlgData->uPenWidth = nPosInit[6]; pMscTlsDlgData->BColor = RGB(0, 0, 0); pMscTlsDlgData->TColor = RGB(50, 50, 50); StatusProc.bProgress = TRUE; StatusProc.bInvalidate = FALSE; StatusProc.bKillProgress = FALSE; StatusProc.bEnd = FALSE; StatusProc.DlgWnd = hWnd; StatusProc.ProgressValue = 100; StatusProc.ProgWnd = GetDlgItem(hWnd, IDC_MTLS_PROG); Progress_SetRange(GetDlgItem(hWnd, IDC_MTLS_PROG), 0, 100); Progress_SetPos (GetDlgItem(hWnd, IDC_MTLS_PROG), 0); ComboBox_AddString(GetDlgItem(hWnd, IDC_MTLS_TYPE_COM), "Cartesian"); ComboBox_AddString(GetDlgItem(hWnd, IDC_MTLS_TYPE_COM), "Polar"); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_MTLS_TYPE_COM), 0); ComboBox_AddString(GetDlgItem(hWnd, IDC_MTLS_SHDW_COM), "None"); ComboBox_AddString(GetDlgItem(hWnd, IDC_MTLS_SHDW_COM), "Colored"); ComboBox_AddString(GetDlgItem(hWnd, IDC_MTLS_SHDW_COM), "Gray"); ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_MTLS_SHDW_COM), 2); for(nIndex = 0; nIndex < pMscTlsDlgData->nSlideNum; nIndex++) { Trackbar_SetTheRange(GetDlgItem(hWnd, pMscTlsDlgData->nSldBaseID + nIndex), TRUE, nRangeMin[nIndex], nRangeMax[nIndex]); SetNumericEditBox(GetDlgItem(hWnd, pMscTlsDlgData->nEdtBaseID + nIndex), nRangeMin[nIndex], nRangeMax[nIndex], 1, 0, FALSE); SetDlgItemInt(hWnd, pMscTlsDlgData->nEdtBaseID + nIndex, nPosInit[nIndex], FALSE); } CreateAngleControl(GetDlgItem(hWnd, IDC_MTLS_ANGL_TXT), IDC_MTLS_ANGL_EDT, FROM_0_TO_8, 1, APPLY_ON_MOVE); SetDlgItemInt(hWnd, IDC_MTLS_ANGL_EDT, 7, TRUE); DrawAngleControl(GetDlgItem(hWnd, IDC_MTLS_ANGL_TXT), 7); pMscTlsDlgData->bPushed = FALSE; pMscTlsDlgData->hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_MOUSE)); SendMessage(GetDlgItem(hWnd, IDC_MTLS_POS_BTN), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(HICON)pMscTlsDlgData->hIcon); pMscTlsDlgData->hMouseHook = SetWindowsHookEx(WH_MOUSE, Mouse, hInst, GetCurrentThreadId()); pData->uTimerID = SetTimer(hWnd, 1, 100, NULL); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_XCNR_EDT), FALSE); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_XCNR_SLD), FALSE); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_YCNR_EDT), FALSE); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_YCNR_SLD), FALSE); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_POS_BTN), FALSE); ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); L_ApplyFilter(hWnd); return TRUE; } static L_VOID MTls_OnTimer (HWND hWnd, L_INT nID) { Dialog_Timer(nID); } static L_VOID MTls_OnCommand(HWND hWnd, L_INT nID, HWND hWndCtl, L_UINT uCodeNotify) { HWND hWndParent; LPMSCTLSDLGDATA pMscTlsDlgData; pCHILDDATA pData; RECT rcRgn; L_INT nValue, nIndex; COLORREF crColor; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA(hWndParent); pMscTlsDlgData = (LPMSCTLSDLGDATA)GetWindowLong(hWnd, GWL_USERDATA); L_GetBitmapRgnBounds(&pMscTlsDlgData->LeadBitmap, NULL, &rcRgn); switch(nID) { case IDOK: pData->bCross = FALSE; ShowStatusWindow(FALSE); StatusProc.bStillWork = TRUE; StatusProc.bInvalidate = TRUE; StatusProc.bEnd = TRUE; UnhookWindowsHookEx(pMscTlsDlgData->hMouseHook); DestroyIcon(pMscTlsDlgData->hIcon); InvalidateRect(hWndParent, NULL, FALSE); EndDialog(hWnd, TRUE); break; case IDCANCEL: pData->bCross = FALSE; StatusProc.bProgress = FALSE; StatusProc.bKillProgress = TRUE ; StatusProc.ProgressValue = 100 ; UnhookWindowsHookEx(pMscTlsDlgData->hMouseHook); DestroyIcon(pMscTlsDlgData->hIcon); EndDialog(hWnd, FALSE); break; case IDC_MTLS_POS_BTN: pMscTlsDlgData->bPushed = Button_GetCheck(hWndCtl); break; case IDC_MTLS_TYPE_COM: nIndex = ComboBox_GetCurSel(hWndCtl); if (uCodeNotify == CBN_SELCHANGE) { if (pMscTlsDlgData->uMosaicType == (L_UINT)nIndex) break; EnableWindow(GetDlgItem(hWnd, IDC_MTLS_HGT_EDT), !nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_HGT_SLD), !nIndex); SetWindowText(GetDlgItem(hWnd, IDC_MTLS_WDTH_TXT), !nIndex ? TEXT("Width"): TEXT("Size")); pData->bCross = nIndex; EnableWindow(GetDlgItem(hWnd, IDC_MTLS_XCNR_EDT), nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_XCNR_SLD), nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_YCNR_EDT), nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_YCNR_SLD), nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_POS_BTN), nIndex); pMscTlsDlgData->uMosaicType = nIndex; L_ApplyFilter(hWnd); } break; case IDC_MTLS_ANGL_EDT: nValue = GetDlgItemInt(hWnd, nID, NULL, TRUE); if (nValue == 8) nValue = 0; if ((uCodeNotify == EN_CHANGE) && ((L_UINT)nValue != pMscTlsDlgData->uShadowAngle)) { pMscTlsDlgData->uShadowAngle = nValue; DrawAngleControl(GetDlgItem(hWnd, IDC_MTLS_ANGL_TXT), nValue); L_ApplyFilter(hWnd); } break; case IDC_MTLS_SHDW_COM: nIndex = ComboBox_GetCurSel(hWndCtl); if (uCodeNotify == CBN_SELCHANGE) { if (pMscTlsDlgData->uShadowType == (L_UINT)nIndex) break; EnableWindow(GetDlgItem(hWnd, IDC_MTLS_ANGL_EDT ), nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_ANGL_TXT), nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_SHDW_EDT), nIndex); EnableWindow(GetDlgItem(hWnd, IDC_MTLS_SHDW_SLD), nIndex); pMscTlsDlgData->uShadowType = nIndex; L_ApplyFilter(hWnd); } break; case IDC_MTLS_BCLR_BTN: UnhookWindowsHookEx(pMscTlsDlgData->hMouseHook); crColor = pMscTlsDlgData->BColor; pMscTlsDlgData->BColor = ShowColorDialog(hWnd, crColor); pMscTlsDlgData->hMouseHook = SetWindowsHookEx(WH_MOUSE, Mouse, hInst, GetCurrentThreadId()); if (crColor != pMscTlsDlgData->BColor) { InvalidateRect(hWnd, NULL, FALSE); L_ApplyFilter(hWnd); } break; case IDC_MTLS_TCLR_BTN: UnhookWindowsHookEx(pMscTlsDlgData->hMouseHook); crColor = pMscTlsDlgData->TColor; pMscTlsDlgData->TColor = ShowColorDialog(hWnd, crColor); pMscTlsDlgData->hMouseHook = SetWindowsHookEx(WH_MOUSE, Mouse, hInst, GetCurrentThreadId()); if (crColor != pMscTlsDlgData->TColor) { InvalidateRect(hWnd, NULL, FALSE); L_ApplyFilter(hWnd); } break; } if(nID >= (L_INT)pMscTlsDlgData->nEdtBaseID && nID <(L_INT)(pMscTlsDlgData->nEdtBaseID + pMscTlsDlgData->nSlideNum)) { if(uCodeNotify == EN_CHANGE) { nIndex = nID - pMscTlsDlgData->nEdtBaseID; nValue = GetDlgItemInt(hWnd, nID, NULL, FALSE); Trackbar_SetPos(GetDlgItem(hWnd, nID + pMscTlsDlgData->nSlideNum), TRUE, nValue); switch(nIndex) { case 0: if(pMscTlsDlgData->uWidth == (L_UINT)nValue) return; pMscTlsDlgData->uWidth = (L_UINT)nValue; break; case 1: if(pMscTlsDlgData->uHeight == (L_UINT)nValue) return; pMscTlsDlgData->uHeight = (L_UINT)nValue; break; case 2: if(pMscTlsDlgData->uxCenter == (L_UINT)nValue) return; pData->ptCenter.x = pMscTlsDlgData->uxCenter = (L_UINT)nValue; break; case 3: if(pMscTlsDlgData->uyCenter == (L_UINT)nValue) return; pData->ptCenter.y = pMscTlsDlgData->uyCenter = (L_UINT)nValue; break; case 4: if (pMscTlsDlgData->uShadowThreshold == (L_UINT)nValue) return; pMscTlsDlgData->uShadowThreshold = (L_UINT)nValue; break; case 5: if(pMscTlsDlgData->uOpacity == (L_UINT)nValue) return; pMscTlsDlgData->uOpacity = (L_UINT)nValue; break; case 6: if(pMscTlsDlgData->uPenWidth == (L_UINT)nValue) return; pMscTlsDlgData->uPenWidth = (L_UINT)nValue; break; } L_ApplyFilter(hWnd); } } } static L_BOOL MTls_OnPaint(HWND hWnd) { HBRUSH hBrush; LPMSCTLSDLGDATA pMscTlsDlgData; PAINTSTRUCT ps; HDC hDC; RECT rcRect; pMscTlsDlgData = (LPMSCTLSDLGDATA)GetWindowLong(hWnd, GWL_USERDATA); GetClientRect(GetDlgItem(hWnd, IDC_MTLS_BCLR_TXT), &rcRect); hDC = BeginPaint(GetDlgItem(hWnd, IDC_MTLS_BCLR_TXT), &ps); hBrush = CreateSolidBrush(pMscTlsDlgData->BColor); FillRect(hDC, &rcRect, hBrush); DeleteBrush(hBrush); EndPaint(GetDlgItem(hWnd, IDC_MTLS_BCLR_TXT), &ps); GetClientRect(GetDlgItem(hWnd, IDC_MTLS_TCLR_TXT), &rcRect); hDC = BeginPaint(GetDlgItem(hWnd, IDC_MTLS_TCLR_TXT), &ps); hBrush = CreateSolidBrush(pMscTlsDlgData->TColor); FillRect(hDC, &rcRect, hBrush); DeleteBrush(hBrush); EndPaint(GetDlgItem(hWnd, IDC_MTLS_TCLR_TXT), &ps); return FALSE; } static L_VOID MTls_OnHScroll(HWND hWnd, HWND hWndCtl, L_UINT uCode, L_INT nPos) { LPMSCTLSDLGDATA pMscTlsDlgData = (LPMSCTLSDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); SetDlgItemInt(hWnd, GetDlgCtrlID(hWndCtl) - pMscTlsDlgData->nSlideNum, Trackbar_GetPos(hWndCtl), FALSE); } static L_VOID L_ApplyFilter(HWND hWnd) { pCHILDDATA pData; L_INT nRet = 0; HWND hWndParent; LPMSCTLSDLGDATA pMscTlsDlgData; MOSAICTILESINFO MscTlsParams; if ( 100 != StatusProc.ProgressValue ) { StatusProc.bKillProgress = TRUE ; return ; } pMscTlsDlgData = (LPMSCTLSDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = (pCHILDDATA)GetWindowLong(hWndParent, GWL_USERDATA); FreeMemorizedBitmap (hWndParent); //MEMDISK// L_CopyBitmap(&pData->LeadBitmap, &pMscTlsDlgData->LeadBitmap, sizeof(BITMAPHANDLE)); MscTlsParams.uStructSize = sizeof(MOSAICTILESINFO); MscTlsParams.uTileWidth = pMscTlsDlgData->uWidth; MscTlsParams.uTileHeight = pMscTlsDlgData->uHeight; MscTlsParams.ptCenter.x = pMscTlsDlgData->uxCenter; MscTlsParams.ptCenter.y = pMscTlsDlgData->uyCenter; MscTlsParams.uOpacity = pMscTlsDlgData->uOpacity; MscTlsParams.uPenWidth = pMscTlsDlgData->uPenWidth; MscTlsParams.crBorderColor = pMscTlsDlgData->BColor; MscTlsParams.crTilesColor = pMscTlsDlgData->TColor; MscTlsParams.uShadowAngle = pMscTlsDlgData->uShadowAngle; MscTlsParams.uShadowThreshold = pMscTlsDlgData->uShadowThreshold; MscTlsParams.uFlags = pMscTlsDlgData->uMosaicType | (pMscTlsDlgData->uShadowType << 4); nRet = L_MosaicTilesBitmap(&pData->LeadBitmap, &MscTlsParams); if(nRet == SUCCESS) { InvalidateRect(hWndParent, NULL, TRUE); StatusProc.ProgressValue = 100; Progress_SetPos(StatusProc.ProgWnd , 0); if(StatusProc.bEnd) { StatusProc.bProgress = FALSE; StatusProc.bKillProgress = TRUE ; } } }