void InitSpin( HWND hDlg, LFIXED fSetX, LFIXED fSetY, int flag) /************************************************************************/ { LPIMAGE lpImage; LPFRAME lpFrame; LFIXED fMin, fMax; RECT iRect; int res; if( !( lpImage = GetActiveImage() ) ) return; lpFrame = ImgGetBaseEditFrame( lpImage ); ImgGetImageRect( lpImage, &iRect ); res = FrameResolution( lpFrame ); if (flag & 1) { fMax = FGET( iRect.right, res ); fMin = FGET( -iRect.right, res ); InitDlgItemSpinFixed( hDlg, IDC_POS_X, fSetX, YES, fMin, fMax ); } if (flag & 2) { fMax = FGET( iRect.bottom, res ); fMin = FGET( -iRect.bottom, res ); InitDlgItemSpinFixed( hDlg, IDC_POS_Y, fSetY, YES, fMin, fMax ); } SetUnitLabels(hDlg); }
void StatusOfRectangle( /***********************************************************************/ LPRECT lpRect, LFIXED fScale) { STRING szUnit, szString1, szString2, szString3, szString4; LPSTR lpUnit; RECT rFile; int Resolution; OrderRect( lpRect, &rFile ); if ( fScale ) { Resolution = 1000; ScaleRect( &rFile, fScale ); } else if (lpImage) Resolution = FrameResolution( ImgGetBaseEditFrame(lpImage) ); if ( AstralStr( Control.Units-IDC_PREF_UNITINCHES+IDS_INCHES, &lpUnit ) ) { lstrcpy( szUnit, lpUnit ); MessageStatus( IDS_RECT_STATUS, Unit2String( FGET( RectWidth(&rFile), Resolution ), szString1 ), Unit2String( FGET( RectHeight(&rFile), Resolution ), szString2), (LPSTR)szUnit, Unit2String( FGET( rFile.left, Resolution ), szString3 ), Unit2String( FGET( rFile.top, Resolution ), szString4 ) ); } }
LOCAL BOOL Pos_OnInitDialog(HWND hDlg, HWND hWndFocus, LPARAM lParam) /************************************************************************/ { RECT rSel; LPIMAGE lpImage; LPFRAME lpFrame; LFIXED XPos, YPos; int res; if(!(lpImage = GetActiveImage())) return(FALSE); lpFrame = ImgGetBaseEditFrame( lpImage ); res = FrameResolution( lpFrame ); ImgGetSelObjectRect(lpImage, &rSel, YES); XPos = FGET(rSel.left, res); YPos = FGET(rSel.top, res); CheckComboItem( hDlg, IDC_PREF_UNITS, IDC_PREF_UNITINCHES, IDC_PREF_UNITPIXELS, IDC_PREF_UNITINCHES ); lpPosParms = (LPPOSOBJECTS_PARMS)lParam; Edit.SaveUnits = Control.Units; SetUnitResolution( 0 ); InitSpin( hDlg, XPos, YPos,3); CenterPopup( hDlg ); return(TRUE); }
void AlignIcons( HWND hDlg, LPALIGNOBJECTS_PARMS lpAlignParms ) /************************************************************************/ { RECT bRect, cRect; int xOffset, yOffset, i, wind; LFIXED vSpace, hSpace, fx, fy; HWND hWnd; GetClientRect( hWnd = GetDlgItem( hDlg, IDC_ALIGN_GRID ), &bRect ); vSpace = FGET( RectHeight( &bRect ) - ( ALIGN_NUM_OBJECTS * ICON_HEIGHT ), ALIGN_NUM_OBJECTS - 1 ); hSpace = FGET( RectWidth( &bRect ) - ( ALIGN_NUM_OBJECTS * ICON_WIDTH ), ALIGN_NUM_OBJECTS - 1 ); fx = fy = 0; for( i = 0, wind = GW_CHILD; i < ALIGN_NUM_OBJECTS; i++, wind = GW_HWNDNEXT ) { hWnd = GetWindow( hWnd, wind ); GetClientRect( hWnd, &cRect ); cRect.right -= 1; cRect.bottom -= 1; MapWindowPoints( hWnd, GetDlgItem( hDlg, IDC_ALIGN_GRID ), ( LPPOINT )&cRect, 2 ); ShowWindow( hWnd, SW_HIDE ); ObjAlign( &bRect, &cRect, lpAlignParms, vSpace, hSpace, &xOffset, &yOffset, &fx, &fy ); OffsetRect( &cRect, xOffset, yOffset ); MoveWindow( hWnd, cRect.left, cRect.top, RectWidth( &cRect ), RectHeight( &cRect ), TRUE ); UpdateWindow( GetDlgItem( hDlg, IDC_ALIGN_GRID ) ); ShowWindow( hWnd, SW_SHOWNA ); } }
BOOL CExpandImageDlg::PreDoModal (LPVOID lpVoid) { LPIMAGE lpImage = NULL; LPFRAME lpFrame; if(lpImage = GetImage()) { lpFrame = ImgGetBaseEditFrame(lpImage); m_Units = m_SaveUnits = Control.Units; m_Crop.top = m_Crop.left = 0; m_Crop.right = lpImage->npix - 1; m_Crop.bottom = lpImage->nlin - 1; m_Resolution = m_CropResolution = m_OrigResolution = FrameResolution(lpFrame); m_Depth = FrameDepth(lpFrame); } else { m_Resolution = m_CropResolution = 75; m_Depth = 1; } m_Width = m_OrigWidth = FGET(m_Crop.right - m_Crop.left + 1, m_CropResolution); m_Height = m_OrigHeight = FGET(m_Crop.bottom - m_Crop.top + 1, m_CropResolution); m_Left = m_Top = 0; m_FillColor.gray = 255; return CPPViewModalDlg::PreDoModal(); }
LOCAL int Palette_GetEntry( HWND hWindow, int x, int y, BOOL fClosest ) /***********************************************************************/ { LPPALETTE lpPalette; RECT ClientRect; int iRowIncr, iColIncr, iWidth, iHeight, iRows, iCols; int iStart, iEntry, r, c; int x1, x2, y1, y2, iMinDist, iDist, dx, dy, iClosest; LFIXED xrate, yrate; lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE); if (!lpPalette || !lpPalette->iColors) return(-1); // get ClientRect and allocate buffer for SuperBlt GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart); iWidth = RectWidth(&ClientRect); iHeight = RectHeight(&ClientRect); yrate = FGET(iHeight, iRows); xrate = FGET(iWidth, iCols); x -= ClientRect.left; y -= ClientRect.top; iMinDist = INT_MAX; iClosest = -1; for (r = 0; r < iRows; ++r) { y1 = FMUL(r, yrate); y2 = FMUL(r+1, yrate) - 1; dy = min(abs(y-y1), abs(y-y2)); iEntry = iStart + (r * iRowIncr); for (c = 0; c < iCols; ++c) { if (iEntry < lpPalette->iColors || fClosest) { x1 = FMUL(c, xrate); x2 = FMUL(c+1, xrate) - 1; if (y >= y1 && y <= y2 && x >= x1 && x <= x2) return(iEntry); else if (fClosest) { dx = min(abs(x-x1), abs(x-x2)); iDist = min(dx, dy); if (iDist < iMinDist) { iClosest = iEntry; iMinDist = iDist; } } } iEntry += iColIncr; } } return(iClosest); }
VOID CSizeImageDlg::DoSizeInits( ) { HWND hDlg = GetSafeHwnd(); LPFRAME lpFrame; LPIMAGE lpImage = GetImage(); FRMDATATYPE Type = FDT_RGBCOLOR; ImgGetInfo(lpImage, NULL, NULL, NULL, &Type); /* Be careful to set all values before doing a SetDlg... with them */ /* The Edit structure is a temorary holding area for sizing dialog boxes */ m_Distortable = NO; m_MaintainSize = NO; m_ScaleX = m_ScaleY = 100; if ( lpImage ) { lpFrame = ImgGetBaseEditFrame(lpImage); m_Crop.left = m_Crop.top = 0; m_Crop.right = lpImage->npix - 1; m_Crop.bottom = lpImage->nlin - 1; m_Resolution = m_CropResolution = m_OrigResolution = FrameResolution(lpFrame); m_Depth = FrameDepth(lpFrame); } else { m_Resolution = m_CropResolution = 75; m_Depth = 1; } m_Angle = 0; m_Width = FGET( CROPWIDTH(), m_CropResolution ); m_Height = FGET( CROPHEIGHT(), m_CropResolution ); CheckDlgButton( IDC_DISTORT, m_Distortable); CheckDlgButton( IDC_SMARTSIZE, m_SmartSize ); CheckDlgButton( IDC_MAINTAINSIZE, m_MaintainSize ); ControlEnable(hDlg, IDC_DISTORT, !m_MaintainSize); ControlEnable(hDlg, IDC_MAINTAINSIZE, !m_Distortable ); ControlEnable( hDlg, IDC_SMARTSIZE, !m_MaintainSize && !m_Distortable && CANDOTRANSPARENCY(Type)); InitDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES, 0L, FGET(9999,1) ); InitDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES, 0L, FGET(9999,1) ); InitDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, YES, 1, 10000 ); InitDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, YES, 1, 10000 ); InitDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO, 1, 10000 ); ImageMemory( hDlg, IDC_MEMORY, m_Width, m_Height, m_Resolution, m_Depth ); CheckComboItem(hDlg, IDC_PREF_UNITS, IDC_PREF_UNITFIRST, IDC_PREF_UNITLAST, m_Units); SetUnitLabels(); }
/*************************************************************************** ZoomBoundRect Takes sugested position and size for the zoom window in owner coords. Will set the inputs to allowed values. ***************************************************************************/ void ZoomBoundRect(int *x, int *y, int *width, int *height) { LPIMAGE lpMyImage; RECT rZoom; int borderW, borderH, oldwidth, oldheight; LFIXED fRatio, fPreposedRatio; if (!hZoomWindow) return; lpMyImage = (LPIMAGE)GetImagePtr (hZoomWindow ); if (!lpMyImage) return; // compute size or border GetWindowRect(hZoomWindow, &rZoom); oldwidth = rZoom.right - rZoom.left; oldheight = rZoom.bottom - rZoom.top; GetClientRect(hZoomWindow, &rZoom); borderW = oldwidth -(rZoom.right - rZoom.left); borderH = oldheight -(rZoom.bottom - rZoom.top); // GetClientRect(hOwner, &rOwner); // be sure the zoom widow is not larger than window // *width = Min(*width, rOwner.right - rOwner.left); // *height = Min(*height, rOwner.bottom - rOwner.top); // be sure aspect ratios are the same fPreposedRatio = FGET(*width-borderW, *height-borderH); fRatio = FGET(lpMyImage->npix, lpMyImage->nlin); // is it good enough? oldwidth = WHOLE(fRatio*(*height-borderH)); if (oldwidth == (*width - borderW)) return; if (fPreposedRatio > fRatio) { // width too big *width = FMUL(*height-borderH, fRatio); *width += borderW; } else if (fPreposedRatio < fRatio) { // height top big *height = FMUL(*width-borderW, FGET(lpMyImage->nlin, lpMyImage->npix)); *height += borderH; } // *x = Bound (*x, -*width/2, rOwner.right-*width/2); // *y = Bound (*y, -*height/2, rOwner.bottom-*height/2); return; }
void Control2Image( LPINT lpx, LPINT lpy ) /************************************************************************/ { int x, y; LFIXED xrate, yrate; xrate = FGET( iImageWidth, RectWidth(&rControl) ); yrate = FGET( iImageHeight, RectHeight(&rControl) ); x = *lpx; *lpx = FMUL( x - rControl.left, xrate ); y = *lpy; *lpy = FMUL( y - rControl.top, yrate ); }
void Image2Control( LPINT lpx, LPINT lpy ) /************************************************************************/ { int x, y; LFIXED xrate, yrate; xrate = FGET( RectWidth(&rControl), iImageWidth ); yrate = FGET( RectHeight(&rControl), iImageHeight ); x = *lpx; *lpx = rControl.left + FMUL( x, xrate ); y = *lpy; *lpy = rControl.top + FMUL( y, yrate ); }
//************************************************************************ // lut_draw_grid // PARAMETERS: // HDC hDC- Can NOT be NULL. // LPRECT lpArea- The area to update. // DESCRIPTION: // draws the grid at the given spacing (map coords). //************************************************************************ LOCAL VOID lut_draw_grid(LPLUTCTL lpdata, HDC hDC, LPRECT lpArea) //*********************************************************************** { LFIXED rate; HPEN hOldPen, hPen; int i, val, offset, maxval; int gridX = lpdata->gridX; int gridY = lpdata->gridY; RECT rArea; POINT point; // subtract one cause we are using MoveTo, LineTo rArea = *lpArea; --rArea.right; // we can draw on left and right pixels --rArea.bottom; // we can draw on top and bottom pixels hPen = DrawTools.GetBtnFacePen(); hOldPen = (HPEN)SelectObject( hDC, hPen ); // do vertical lines if (gridX) { maxval = RectWidth(&rArea)-1; // max x value rate = FGET(maxval, MAXVAL); offset = rArea.left; for (i=gridX; i<256; i+=gridX) { val = offset + FMUL(i, rate); MoveToEx( hDC, val, rArea.top, &point); // add one cause LineTo doesn't draw on endpoint LineTo( hDC, val, rArea.bottom+1); } } // do horizontal lines if (gridY) { maxval = RectHeight(&rArea)-1; // max y value rate = FGET(maxval, MAXVAL); offset = rArea.bottom; for (i=gridY; i<256; i+=gridY) { val = offset - FMUL(i, rate); MoveToEx( hDC, rArea.left, val, &point); // add one cause LineTo doesn't draw on endpoint LineTo( hDC, rArea.right+1, val); } } SelectObject( hDC, hOldPen ); }
void View1TO1() { int x, y, res, ratio; LFIXED fixed; HDC hDC; HWND hWnd; LPDISPLAY lpDisplay; LPIMAGE lpImage; if (hWnd = GetActiveDoc()) { lpImage = GetImagePtr(hWnd); lpDisplay = GetDisplayPtr(hWnd); hDC = GetDC( PictPubApp.Get_hWndAstral() ); x = GetDeviceCaps( hDC, HORZRES ); // in pixels ReleaseDC( PictPubApp.Get_hWndAstral(), hDC ); fixed = FGET( FUNITY, Control.ScreenWidth ); if (res = FMUL( x, fixed)) // in pixels/inch { ratio = ( 100L * res ) / FrameResolution(ImgGetBaseEditFrame(lpImage)); x = ( lpDisplay->FileRect.left + lpDisplay->FileRect.right ) / 2; y = ( lpDisplay->FileRect.top + lpDisplay->FileRect.bottom ) / 2; Zoom( hWnd, x, y, ratio, NO, View.ZoomWindow ); } } }
LOCAL BOOL Palette_SelectRect(HWND hWindow, int iSelect, LPRECT lpSelectRect) /***********************************************************************/ { RECT ClientRect; int iRowIncr, iColIncr, iWidth, iHeight, iRows, iCols; int iStart, iEntry, r, c; LFIXED xrate, yrate; LPPALETTE lpPalette; lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE); if (!lpPalette || !lpPalette->iColors) return(FALSE); // get ClientRect and allocate buffer for SuperBlt GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart); iWidth = RectWidth(&ClientRect); iHeight = RectHeight(&ClientRect); yrate = FGET(iHeight, iRows); xrate = FGET(iWidth, iCols); for (r = 0; r < iRows; ++r) { iEntry = iStart + (r * iRowIncr); for (c = 0; c < iCols; ++c) { if (iEntry == iSelect) { lpSelectRect->top = ClientRect.top + FMUL(r, yrate); lpSelectRect->bottom = ClientRect.top + FMUL(r+1, yrate) - 1; lpSelectRect->left = ClientRect.left + FMUL(c, xrate); lpSelectRect->right = ClientRect.left + FMUL(c+1, xrate) - 1; return(TRUE); } iEntry += iColIncr; } } return(FALSE); }
void TShearX( LPTFORM lpTForm, int height, int dx ) /***********************************************************************/ { LFIXED b; unsigned int h; h = lsqrt(((long)height * (long)height) + ((long)dx * (long)dx)); b = FGET(dx, h); lpTForm->ax += FIXMUL( lpTForm->ay, b ); lpTForm->bx += FIXMUL( lpTForm->by, b ); lpTForm->cx += FIXMUL( lpTForm->cy, b ); }
void TShearY( LPTFORM lpTForm, int width, int dy ) /***********************************************************************/ { LFIXED a; unsigned int h; h = lsqrt(((long)width * (long)width) + ((long)dy * (long)dy)); a = FGET(dy, h); lpTForm->ay += FIXMUL( lpTForm->ax, a ); lpTForm->by += FIXMUL( lpTForm->bx, a ); lpTForm->cy += FIXMUL( lpTForm->cx, a ); }
void ddaline( int x1, int y1, int x2, int y2, LPPOINTFUNC lpPointFunction ) /************************************************************************/ { int x, y, ix, iy; LFIXED dx, dy, ax, ay; if ( x1 > x2 ) { x = x1 - x2; ix = -1; } else { x = x2 - x1; ix = 1; } if ( y1 > y2 ) { y = y1 - y2; iy = -1; } else { y = y2 - y1; iy = 1; } if ( x < y ) { dy = UNITY; dx = FGET( x, y ); } else { dx = UNITY; dy = FGET( y, x ); } /* Initialize the ax accumulator with half the dx increment */ /* plus one half for rounding off */ ax = HALF; //( dx + UNITY )/2; //ax &= 0xFFFFL; ay = HALF; //( dy + UNITY )/2; //ay &= 0xFFFFL; x = x1; y = y1; while (1) { (*lpPointFunction)( x, y ); /* use x, y */ if ( x == x2 && y == y2 ) break; if ( ( ax += dx ) > UNITY ) { ax -= UNITY; x += ix; } if ( ( ay += dy ) > UNITY ) { ay -= UNITY; y += iy; } } }
LOCAL void PalPicker_GetRect( HWND hWindow, int r, int c, LPRECT lpRect) /***********************************************************************/ { RECT ClientRect; int iWidth, iHeight; LFIXED xrate, yrate; GetClientRect(hWindow, &ClientRect); InflateRect(&ClientRect, -3, -3); WindowsToAstralRect(&ClientRect); iWidth = RectWidth(&ClientRect); iHeight = RectHeight(&ClientRect); yrate = FGET(iHeight, 16); xrate = FGET(iWidth, 16); lpRect->left = FMUL(c, xrate) + 1; lpRect->right = FMUL(c+1, xrate) - 2; lpRect->top = FMUL(r, yrate) + 1; lpRect->bottom = FMUL(r+1, yrate) - 2; OffsetRect(lpRect, ClientRect.left, ClientRect.top); }
/************************************************************************ ComputeZoomDisp Computes and sets values for the lpDisplay. ************************************************************************/ void ComputeZoomDisp() { LPDISPLAY lpMyDisplay; RECT area; int fileH, fileW, dispH, dispW; int x, y; LPIMAGE lpMyImage; if (!hZoomWindow) return; lpMyDisplay = (LPDISPLAY)GetDisplayPtr(hZoomWindow); lpMyImage = (LPIMAGE)GetImagePtr (hZoomWindow ); if (!lpMyDisplay) return; GetClientRect(hZoomWindow, &area); dispH = area.bottom - area.top; dispW = area.right - area.left; x = 0; y = 0; // set lpDisplay lpMyDisplay->DispRect.left = x; lpMyDisplay->DispRect.right = x+dispW-1; lpMyDisplay->DispRect.top =y ; lpMyDisplay->DispRect.bottom = y+dispH-1; fileW = lpMyImage->npix; fileH = lpMyImage->nlin; lpMyDisplay->FileRect.left = x; lpMyDisplay->FileRect.top = y; lpMyDisplay->FileRect.right = x + fileW - 1; lpMyDisplay->FileRect.bottom = y + fileH - 1; lpMyDisplay->FileRate = FGET(fileW, dispW); BoundRect( &lpMyDisplay->FileRect, 0, 0, lpMyImage->npix-1, lpMyImage->nlin-1 ); }
BOOL CanZoom( HWND hWnd, LFIXED FileRate, LPRECT lpFileRect, LPRECT lpDispRect ) /************************************************************************/ { LFIXED DispRate; long lFileWidth, lFileHeight; int iDispWidth, iDispHeight; LPIMAGE lpImage; lpImage = GetImagePtr(hWnd); if (FileRate != 0) // FileRate passed in DispRate = FGET(FUNITY, FileRate); else // Displaying a FileRect { // calculate DispRate using this FileRect and // DispRect. iDispWidth = RectWidth(lpDispRect); iDispHeight = RectHeight(lpDispRect); DispRate = ScaleToFit(&iDispWidth, &iDispHeight, RectWidth(lpFileRect), RectHeight(lpFileRect)); } // Calculate eventual size in File coordinates using // this DispRate. This calculation is done by most // of the viewing routines and has the possibility // of overflow. Usually in these routines when the // calculation is made it is too late to turn back // so those routines call CanZoom() before doing // anything that is unreversible. lFileWidth = FMUL(lpImage->npix, DispRate); lFileHeight = FMUL(lpImage->nlin, DispRate); // Although MAXINT is 32767, I decided to use 30000 just // for some slop and my own paranoia return(lFileWidth > 0L && lFileWidth <= MAX_IMAGE_WIDTH && lFileHeight > 0L && lFileHeight <= MAX_IMAGE_HEIGHT); }
VOID CExpandImageDlg::DoExpandInits( ) /***********************************************************************/ { long Color; HWND hWnd = GetSafeHwnd(); InitDlgItemSpinFixed(hWnd, IDC_HEIGHT, m_Height, YES, 0L, FGET(9999,1) ); InitDlgItemSpinFixed(hWnd, IDC_WIDTH, m_Width, YES, 0L, FGET(9999,1) ); InitDlgItemSpinFixed(hWnd, IDC_EXPANDLEFT, m_Left, YES, 0L, FGET(9999,1) ); InitDlgItemSpinFixed(hWnd, IDC_EXPANDRIGHT,m_Width-m_OrigWidth-m_Left, YES, 0L, FGET(9999,1) ); InitDlgItemSpinFixed(hWnd, IDC_EXPANDTOP, m_Top, YES, 0L, FGET(9999,1) ); InitDlgItemSpinFixed(hWnd, IDC_EXPANDBOTTOM,m_Height-m_OrigHeight-m_Top, YES, 0L, FGET(9999,1) ); ImageMemory( hWnd, IDC_MEMORY, m_Width, m_Height, m_Resolution,m_Depth ); CheckComboItem(hWnd,IDC_PREF_UNITS, IDC_PREF_UNITFIRST,IDC_PREF_UNITLAST, m_Units); ControlEnable(hWnd, IDOK, FALSE); SetUnitLabels(hWnd); SetColorInfo(&m_FillColor, &m_FillColor, CS_GRAY); CopyRGB( &m_FillColor.rgb, &Color ); SetWindowLong( ::GetDlgItem(hWnd,IDC_FILLINCOLOR), GWL_ACTIVE, Color ); }
void TInvert( LPTFORM lpTForm ) /***********************************************************************/ { LFIXED ax, bx, cx, ay, by, cy; LFIXED term1, term2, term3; ax = lpTForm->ax; ay = lpTForm->ay; bx = lpTForm->bx; by = lpTForm->by; cx = lpTForm->cx; cy = lpTForm->cy; /* ax*by - bx*ay */ term1 = FIXMUL( ax, by ) - FIXMUL( bx, ay ); /* cy*bx - cx*by */ term2 = FIXMUL( cy, bx ) - FIXMUL( cx, by ); /* cx*ay - cy*ax */ term3 = FIXMUL( cx, ay ) - FIXMUL( cy, ax ); lpTForm->ax = FGET( by, term1 ); lpTForm->bx = FGET( -bx, term1 ); lpTForm->cx = FGET( term2, term1 ); lpTForm->ay = FGET( -ay, term1 ); lpTForm->by = FGET( ax, term1 ); lpTForm->cy = FGET( term3, term1 ); }
BOOL CSizeImageDlg::DoSizeControls( ITEMID id, UINT codeNotify, BOOL bResAdjust ) { BOOL bResult = TRUE; HWND hDlg = GetSafeHwnd(); BOOL Bool; long x, y; int npix, nlin; HWND hWnd, hControl; RECT rArea; LFIXED scale; LPIMAGE lpImage; FRMDATATYPE Type; lpImage = GetImage(); ImgGetInfo(lpImage, NULL, NULL, NULL, &Type); npix = CROPWIDTH(); nlin = CROPHEIGHT(); switch( id ) { case IDC_SMARTSIZE: m_SmartSize = !m_SmartSize; CheckDlgButton( IDC_SMARTSIZE, m_SmartSize ); break; case IDC_MAINTAINSIZE: m_MaintainSize = !m_MaintainSize; if (m_MaintainSize) m_Distortable = NO; ControlEnable(hDlg, IDC_DISTORT, !m_MaintainSize); ControlEnable(hDlg, IDC_SMARTSIZE, !m_MaintainSize); Bool = !m_MaintainSize || m_Units != IDC_PREF_UNITPIXELS; ControlEnable(hDlg, IDC_WIDTH, Bool); ControlEnable(hDlg, IDC_HEIGHT, Bool); ControlEnable(hDlg, IDC_SCALEX, Bool); ControlEnable(hDlg, IDC_SCALEY, Bool); if (m_MaintainSize) { m_Resolution = m_CropResolution = m_OrigResolution; m_Width = FGET( npix, m_CropResolution ); m_Height = FGET( nlin, m_CropResolution ); SetUnitResolution( m_CropResolution ); SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO ); SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES ); SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES ); } CheckDlgButton( IDC_MAINTAINSIZE, m_MaintainSize ); CheckDlgButton( IDC_SMARTSIZE, !m_MaintainSize && m_SmartSize ); break; case IDC_PREF_UNITS: { WORD wUnits; if ( !(wUnits = HandleCombo( hDlg, id, codeNotify )) ) break; m_Units = wUnits; SetUnitInfo((UNIT_TYPE)(m_Units-IDC_PREF_UNITINCHES), m_UnitRes, m_Points); CheckComboItem(hDlg, IDC_PREF_UNITS, IDC_PREF_UNITFIRST, IDC_PREF_UNITLAST, m_Units); Bool = !m_MaintainSize || m_Units != IDC_PREF_UNITPIXELS; ControlEnable(hDlg, IDC_WIDTH, Bool); ControlEnable(hDlg, IDC_HEIGHT, Bool); ControlEnable(hDlg, IDC_SCALEX, Bool); ControlEnable(hDlg, IDC_SCALEY, Bool); if (m_MaintainSize && m_Units == IDC_PREF_UNITPIXELS) { m_CropResolution = m_Resolution; SetUnitResolution( m_CropResolution ); m_Width = FGET( npix, m_CropResolution ); m_Height = FGET( nlin, m_CropResolution ); y = FMUL( m_CropResolution, m_Height ); m_ScaleY = ((y*100L) + nlin/2) / nlin; SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO ); x = FMUL( m_CropResolution, m_Width ); m_ScaleX = ((x*100L) + npix/2) / npix; SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO ); } SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES ); SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES ); SetUnitLabels(); } break; case IDC_DISTORT: m_Distortable = !m_Distortable; CheckDlgButton( IDC_DISTORT, m_Distortable ); if (m_Distortable) m_MaintainSize = NO; ControlEnable(hDlg, IDC_MAINTAINSIZE, !m_MaintainSize); if ( m_ScaleX != m_ScaleY ) { m_ScaleX = m_ScaleY; x = (((long)npix * m_ScaleX)+50L)/100L; m_Width = FGET( x, m_CropResolution ); SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES ); SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO ); } CheckDlgButton( IDC_SMARTSIZE,m_SmartSize && !m_Distortable); ControlEnable( hDlg, IDC_SMARTSIZE, !m_Distortable && CANDOTRANSPARENCY(Type)); ControlEnable(hDlg, IDC_MAINTAINSIZE, !m_Distortable && lpImage); if ( Page.PrintNumeric ) break; if ( !(hWnd = ::GetDlgItem( hDlg,IDC_PRINTVIEWPAGE)) ) break; if ( !(hControl = ::GetDlgItem( hDlg,IDC_PRINTVIEWIMAGE)) ) break; SetLongBit(hControl, GWL_STYLE, IS_RATIO_CONSTRAIN, !m_Distortable ); if (!m_Distortable) { ::GetWindowRect(hControl, &rArea); ::ScreenToClient(hWnd, (LPPOINT)&rArea.left); ::ScreenToClient(hWnd, (LPPOINT)&rArea.right); ::MoveWindow(hControl, rArea.left, rArea.top, RectWidth(&rArea)-1, RectHeight(&rArea)-1, TRUE); } break; case IDC_HEIGHT: if ( ::GetFocus() != ::GetDlgItem( hDlg,id ) ) break; if ( codeNotify != EN_CHANGE ) break; m_Height = GetDlgItemSpinFixed( hDlg, IDC_HEIGHT, &Bool, YES); if (m_MaintainSize) { scale = FGET(FUNITY, m_Height); m_Resolution = FMUL(nlin, scale); SetUnitResolution( m_Resolution ); SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO ); } // y = number of new pixels x 100 y = FMUL( m_CropResolution, m_Height ); // calculate scale factor = (new pixels * 100) / old pixels m_ScaleY = ((y * 100L) + nlin/2) / nlin; SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO ); if ( !m_Distortable ) { m_ScaleX = m_ScaleY; x = (((long)npix * (long)y) + (nlin/2))/ (long)nlin; m_Width = FGET( x, m_CropResolution ); SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES ); SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO ); } ImageMemory( hDlg, IDC_MEMORY, m_MaintainSize ? FGET(npix,1) : m_Width, m_MaintainSize ? FGET(nlin,1) : m_Height, m_MaintainSize ? 1 : m_Resolution, m_Depth ); break; case IDC_WIDTH: if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; m_Width = GetDlgItemSpinFixed( hDlg, IDC_WIDTH, &Bool, YES ); if (m_MaintainSize) { scale = FGET(FUNITY, m_Width); m_Resolution = FMUL(npix, scale); SetUnitResolution( m_Resolution ); SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO ); } x = FMUL( m_CropResolution, m_Width ); m_ScaleX = ((x * 100L) + npix/2L) / (long)npix; SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO ); if ( !m_Distortable ) { m_ScaleY = m_ScaleX; y = (((long)nlin * (long)x) + (npix/2))/ (long)npix; m_Height = FGET( y, m_CropResolution ); SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES ); SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO ); } ImageMemory( hDlg, IDC_MEMORY, m_MaintainSize ? FGET(npix,1) : m_Width, m_MaintainSize ? FGET(nlin,1) : m_Height, m_MaintainSize ? 1 : m_Resolution, m_Depth ); break; case IDC_RES: if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; m_Resolution = GetDlgItemSpin( hDlg, IDC_RES, &Bool, NO ); if ( m_Resolution <= 0 ) m_Resolution = 2; if (m_MaintainSize) { m_Width = FGET(npix, m_Resolution); m_Height = FGET(nlin, m_Resolution); SetUnitResolution( m_Resolution ); if (m_Units != IDC_PREF_UNITPIXELS) { SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES ); SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES ); y = FMUL( m_CropResolution, m_Height ); m_ScaleY = ((y*100L) + nlin/2) / nlin; SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO ); x = FMUL( m_CropResolution, m_Width ); m_ScaleX = ((x*100L) + npix/2) / npix; SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO ); } } if ( m_Units == IDC_PREF_UNITPIXELS ) { if ( bResAdjust ) { // Extract the values again (inch values changed) m_CropResolution = m_Resolution; SetUnitResolution( m_Resolution ); ::SetFocus( hWnd = ::GetDlgItem( hDlg,IDC_HEIGHT ) ); FORWARD_WM_COMMAND(hDlg, IDC_HEIGHT, hWnd, EN_CHANGE, ::SendMessage); ::SetFocus( hWnd = ::GetDlgItem( hDlg,IDC_WIDTH ) ); FORWARD_WM_COMMAND(hDlg, IDC_WIDTH, hWnd, EN_CHANGE, ::SendMessage); ::SetFocus( ::GetDlgItem( hDlg,id ) ); } else { // Change the edit box SetUnitResolution( m_Resolution ); SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES); SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES ); } } ImageMemory( hDlg, IDC_MEMORY, m_MaintainSize ? FGET(npix,1) : m_Width, m_MaintainSize ? FGET(nlin,1) : m_Height, m_MaintainSize ? 1 : m_Resolution, m_Depth ); break; case IDC_SCALEX: if ( GetFocus() != GetDlgItem( id ) ) break; if ( codeNotify != EN_CHANGE ) break; m_ScaleX = GetDlgItemSpin( hDlg, IDC_SCALEX, &Bool, NO ); x = (((long)npix * m_ScaleX)+50L)/100L; m_Width = FGET( x, m_CropResolution ); SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES ); if (m_MaintainSize) { scale = FGET(FUNITY, m_Width); m_Resolution = FMUL(npix, scale); SetUnitResolution( m_Resolution ); SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO ); } if ( !m_Distortable ) { m_ScaleY = m_ScaleX; y = (((long)nlin * m_ScaleY)+50)/100L; m_Height = FGET( y, m_CropResolution ); SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES ); SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO ); } ImageMemory( hDlg, IDC_MEMORY, m_MaintainSize ? FGET(npix,1) : m_Width, m_MaintainSize ? FGET(nlin,1) : m_Height, m_MaintainSize ? 1 : m_Resolution, m_Depth ); break; case IDC_SCALEY: if ( GetFocus() != GetDlgItem( id ) ) break; if ( codeNotify != EN_CHANGE ) break; m_ScaleY = GetDlgItemSpin( hDlg, IDC_SCALEY, &Bool, NO ); y = (((long)nlin * m_ScaleY)+50)/100L; m_Height = FGET( y, m_CropResolution ); SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES ); if (m_MaintainSize) { scale = FGET(FUNITY, m_Height); m_Resolution = FMUL(nlin, scale); SetUnitResolution( m_Resolution ); SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO ); } if ( !m_Distortable ) { m_ScaleX = m_ScaleY; x = (((long)npix * m_ScaleX)+50L)/100L; m_Width = FGET( x, m_CropResolution ); SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES); SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO ); } ImageMemory( hDlg, IDC_MEMORY, m_MaintainSize ? FGET(npix,1) : m_Width, m_MaintainSize ? FGET(nlin,1) : m_Height, m_MaintainSize ? 1 : m_Resolution, m_Depth ); break; case IDC_MEMORY: default: bResult = FALSE; break; } return bResult; }
void ObjAlign( LPRECT bRect, LPRECT oRect, LPALIGNOBJECTS_PARMS lpAlignParms, LFIXED vSpace, LFIXED hSpace, LPINT xOffset, LPINT yOffset, LPLFIXED fx, LPLFIXED fy ) /************************************************************************/ { switch( lpAlignParms->HorzAlign ) { case HA_RIGHT: *xOffset = ( bRect->right - RectWidth( oRect ) ) - oRect->left; break; case HA_LEFT: *xOffset = bRect->left - oRect->left; break; case HA_CENTER: *xOffset = bRect->left + FINT( FGET( RectWidth( bRect ), 2 ) - FGET( RectWidth( oRect ), 2 ) ) - oRect->left; break; case HA_EQUAL: if( *fx == 0 ) { *xOffset = bRect->left - oRect->left; *fx = TOFIXED( RectWidth( oRect ) + bRect->left ) + hSpace; } else { *xOffset = FINT( *fx ) - oRect->left; *fx += TOFIXED( RectWidth( oRect ) ) + hSpace; } break; case HA_NONE: *xOffset = 0; break; } switch( lpAlignParms->VertAlign ) { case VA_TOP: *yOffset = bRect->top - oRect->top; break; case VA_BOTTOM: *yOffset = ( bRect->bottom - RectHeight( oRect ) ) - oRect->top; break; case VA_MID: *yOffset = bRect->top + FINT( FGET( RectHeight( bRect ), 2 ) - FGET( RectHeight( oRect ), 2 ) ) - oRect->top; break; case VA_EQUAL: if( *fy == 0 ) { *yOffset = bRect->top - oRect->top; *fy = TOFIXED( RectHeight( oRect ) + bRect->top ) + vSpace; } else { *yOffset = FINT( *fy ) - oRect->top; *fy += TOFIXED( RectHeight( oRect ) ) + vSpace; } break; case VA_NONE: *yOffset = 0; break; } }
void ComputeFileRect( HWND hWnd, int x, int y, LFIXED FileRate ) /************************************************************************/ { int fx, fy, DispWidth, DispHeight, dx, dy; LFIXED DispRate; LPIMAGE lpImage; LPDISPLAY lpDisplay; // A NULL FileRate is a signal that FileRect was just initialized // and doesn't need recalculating if ( !FileRate) return; lpImage = GetImagePtr(hWnd); lpDisplay = GetDisplayPtr(hWnd); // FileRect will be recomputed from FileRate and a center point (x,y) DispWidth = RectWidth( &lpDisplay->DispRect ); DispHeight = RectHeight( &lpDisplay->DispRect ); DispRate = FGET(FUNITY, lpDisplay->FileRate); dx = FMUL(lpImage->npix, DispRate); dy = FMUL(lpImage->nlin, DispRate); // FileRate == 1 is a special case for handling iconic state // otherwise handle normally if ( FileRate == TINYRATE) // Display all of image - iconic state { fx = lpImage->npix; fy = lpImage->nlin; lpDisplay->ViewPercentage = 0; } else { // if image fits or is smaller than display surface // use maximum FileRect, otherwise use current FileRate if (dx <= DispWidth) fx = lpImage->npix; else fx = FMUL( DispWidth, FileRate ); if (dy <= DispHeight) fy = lpImage->nlin; else fy = FMUL( DispHeight, FileRate ); } if (x == -1 && y == -1) // special signal to use old XY { x = lpDisplay->FileRect.left; y = lpDisplay->FileRect.top; } else { x -= ( fx / 2 ); y -= ( fy / 2 ); } if ( x < 0 ) x = 0; if ( y < 0 ) y = 0; if ( x + fx - 1 >= lpImage->npix ) x = lpImage->npix - fx; if ( y + fy - 1 >= lpImage->nlin ) y = lpImage->nlin - fy; lpDisplay->FileRect.left = x; lpDisplay->FileRect.top = y; lpDisplay->FileRect.right = x + fx - 1; lpDisplay->FileRect.bottom = y + fy - 1; BoundRect( &lpDisplay->FileRect, 0, 0, lpImage->npix-1, lpImage->nlin-1 ); }
void ComputeDispRect(HWND hWnd) /************************************************************************/ { int w, h, dx, dy; int iWidth, iHeight, iImageWidth, iImageHeight; LFIXED DispRate; RECT DispRect; BOOL bZoomed, bIconic; LPIMAGE lpImage; LPDISPLAY lpDisplay; lpImage = GetImagePtr(hWnd); lpDisplay = GetDisplayPtr(hWnd); BOOL bInPlaceFrameType = FALSE; HWND hMDIWindow = hWnd; CWnd *pWnd = CWnd::FromHandle(hMDIWindow); if (pWnd->IsKindOf(RUNTIME_CLASS(CServerView))) { hMDIWindow = pWnd->GetParentFrame()->GetSafeHwnd(); bInPlaceFrameType = ((CServerView*)pWnd)->GetDocument()->IsInPlaceActive(); } // get max size of client area with no scrollbars GetDispRect(hWnd, &DispRect, 1, 1); w = RectWidth(&DispRect); h = RectHeight(&DispRect); // If we have no FileRate to this point, it means somebody wants // to display a specific FileRect. Calculate a FileRate so that // we can calculate a DispRect. This is necessary because it is // possible (when the window is maximized for example) that the // FileRect requested will not fill up the window, so it would // need to be recalculated. It is assumed that scrollbars would // not be needrf and should not be needed if the calculation is // done correctly, which hopefully it is. if (!lpDisplay->FileRate) { iWidth = w; iHeight = h; DispRate = ScaleToFit(&iWidth, &iHeight, RectWidth(&lpDisplay->FileRect), RectHeight(&lpDisplay->FileRect)); lpDisplay->FileRate = FGET(FUNITY, DispRate); } if (lpDisplay->FileRate == TINYRATE) // Iconic { iWidth = w; iHeight = h; iImageWidth = lpImage->npix; iImageHeight = lpImage->nlin; DispRate = ScaleToFit(&iWidth, &iHeight, iImageWidth, iImageHeight); //--------------------------------------------------------------------- // NOTE!! added bInPlaceFrameType here because Insitu needs to be able // to scale over 100%. //--------------------------------------------------------------------- if (!bInPlaceFrameType && (DispRate > FGET(1, 1))) { DispRate = FGET(1, 1); iWidth = FMUL(iImageWidth, DispRate); iHeight = FMUL(iImageHeight, DispRate); } } else // if (lpDisplay->FileRate) // Specific FileRate { // Calulate how much space is needed at this FileRate DispRate = FGET(FUNITY, lpDisplay->FileRate); iImageWidth = FMUL(lpImage->npix, DispRate); iImageHeight = FMUL(lpImage->nlin, DispRate); // See if scrollbars will be necessary and get the // appropriate DispRect if so if (iImageWidth > w && iImageHeight > h) { GetDispRect(hWnd, &DispRect, 2, 2); } else if (iImageWidth > w) { GetDispRect(hWnd, &DispRect, 2, 1); h = RectHeight(&DispRect); if (iImageHeight > h) { GetDispRect(hWnd, &DispRect, 2, 2); } } else if (iImageHeight > h) { GetDispRect(hWnd, &DispRect, 1, 2); w = RectWidth(&DispRect); if (iImageWidth > w) { GetDispRect(hWnd, &DispRect, 2, 2); } } w = RectWidth(&DispRect); h = RectHeight(&DispRect); iWidth = w; iHeight = h; // Clip the DispRect size to the amount needed for image if (iImageWidth < iWidth) iWidth = iImageWidth; if (iImageHeight < iHeight) iHeight = iImageHeight; } bIconic = IsIconic(hMDIWindow); bZoomed = IsZoomed(hMDIWindow); if (bZoomed || bIconic) { dy = RectHeight(&DispRect) - iHeight; dy /= 2; dx = RectWidth(&DispRect) - iWidth; dx /= 2; lpDisplay->DispRect.top = DispRect.top + dy; lpDisplay->DispRect.left = DispRect.left + dx; } else { lpDisplay->DispRect.top = DispRect.top; lpDisplay->DispRect.left = DispRect.left; } lpDisplay->DispRect.bottom = lpDisplay->DispRect.top + iHeight - 1; lpDisplay->DispRect.right = lpDisplay->DispRect.left + iWidth - 1; }
void CalcFullViewWindowSize( LPRECT lpWindowRect, LPRECT lpFileRect, LFIXED FileRate, int npix, int nlin, int x, int y, BOOL fHasRulers, BOOL fClipToImage ) /************************************************************************/ { int dx, dy, sx, sy, rs, iImageWidth, iImageHeight, iWidth, iHeight; LFIXED DispRate; int minsize; // normal window - to goal is to size the window to fit the view // If FileRate == 0 or 1, then we make the window as big as possible // for the FileRect provided. If FileRate != 0, then we make the // the window as big as possible to fit the image at that FileRate. // If the fClipToImage flag and FileRate == 0, then we do not let // the FileRate go over 100%. This is used for a caller who wants // to display the image pixel for pixel, if possible. if (x < 0 || y < 0) GetDocumentPosition(&x, &y); dx = 2 * GetSystemMetrics(SM_CXFRAME); dy = GetSystemMetrics(SM_CYCAPTION) + (2*GetSystemMetrics(SM_CYFRAME)) - 1; // get size of scrollbars and rulers for use later GetScrollBarSize(&sx, &sy); rs = GetRulerSize(); // determine maximum area for window to occupy if (IsIconic(PictPubApp.Get_hWndAstral())) *lpWindowRect = rClient; else GetClientRect(PictPubApp.Get_hClientAstral(), lpWindowRect); lpWindowRect->top = y; lpWindowRect->left = x; lpWindowRect->right -= dx; lpWindowRect->bottom -= (dy + GetSystemMetrics(SM_CYFRAME)); // start with this maximum Client Area size minsize = MIN_WINDOW_SIZE+rs; iWidth = RectWidth(lpWindowRect); if ( iWidth < minsize ) iWidth = minsize; iHeight = RectHeight(lpWindowRect); if ( iHeight < minsize ) iHeight = minsize; // If we already have a FileRate, calculate new size of window // based on the image size if (FileRate > TINYRATE) { // calculate size of area for total image at this // FileRate DispRate = FGET(FUNITY, FileRate); iImageWidth = FMUL(npix, DispRate); iImageHeight = FMUL(nlin, DispRate); // add in additional space for rulers if necessary if (fHasRulers) { iImageWidth += rs; iImageHeight += rs; } if (iImageWidth > iWidth && iImageHeight < iHeight) iImageHeight += sy; if (iImageHeight > iHeight && iImageWidth < iWidth) iImageWidth += sx; // see if we don't need the total width // otherwise, use the maximum if (iImageWidth < iWidth) iWidth = iImageWidth; // see if we don't need the total height // otherwise, use the maximum if (iImageHeight < iHeight) iHeight = iImageHeight; } // if we have no FileRate, then somebody wants a specific // FileRect, figure out how big the window needs to be and // whether we need rulers else { // get width and height of area to be displayed iImageWidth = RectWidth(lpFileRect); iImageHeight = RectHeight(lpFileRect); // reduce the maximum area if we have rulers if (fHasRulers) { iWidth -= rs; iHeight -= rs; } // reduce the maximum area if we need scrollbars if (lpFileRect->left != 0 || lpFileRect->right != npix-1 || lpFileRect->top != 0 || lpFileRect->bottom != nlin-1) { iWidth -= sx; iHeight -= sy; } // scale maximum client area size (not including rulers and // scrollbars) to fit aspect ratio of FileRect DispRate = ScaleToFit(&iWidth, &iHeight, iImageWidth, iImageHeight); // if caller wants to clip to hires to achieve 100% view, // clip. But only if hires is smaller if (iImageWidth <= iWidth && iImageHeight <= iHeight && fClipToImage) { iWidth = iImageWidth; iHeight = iImageHeight; } // add ruler size back into client area if (fHasRulers) { iWidth += rs; iHeight += rs; } // add scrollbar size back into client area if (lpFileRect->left != 0 || lpFileRect->right != npix-1 || lpFileRect->top != 0 || lpFileRect->bottom != nlin-1) { iWidth += sx; iHeight += sy; } } // Calculate new window size based on iWidth and iHeight */ lpWindowRect->right = lpWindowRect->left + iWidth + dx - 1; lpWindowRect->bottom = lpWindowRect->top + iHeight + dy - 1; }
//======================================================================= // int CurveToPoints // lpPoints: Bezier handle points. // type: BEZIER_MARKER is the only type supported. // lpOutputPoints: Result. - must be at least MAX_BEZIER_OUT or NULL // // returns the number of points written (or needed if !lpOutputPoints) //======================================================================= int CurveToPoints(LPPOINT lpPoints, int type, LPPOINT lpOutputPoints ) //======================================================================= { int n, t, i, nOutPoints, lastx, lasty, x, y; int nMaxPoints; int nPoints; LFIXED tscale, fdx, fdy, tscalebase; FPOINT ptR[MAX_BEZIER_IN]; LPFPOINT R; LPPOINT P; if (type != BEZIER_MARKER) return(0); nPoints = BEZIER_IN; // determine the maximum number of points we will want (may effect quality) x = y = INT_MAX; lastx = lasty = INT_MIN; for (i=0;i<nPoints;i++) { x = min(x, lpPoints[i].x); y = min(y, lpPoints[i].y); lastx = max(lastx, lpPoints[i].x); lasty = max(lasty, lpPoints[i].y); } // get delta x = lastx-x; y = lasty-y; nMaxPoints = (x+y)/4; nMaxPoints = bound(nMaxPoints, 5, MAX_BEZIER_OUT); // Transformer(lpTForm, lpPoints, &lastx, &lasty); if (lpOutputPoints) *lpOutputPoints++ = *lpPoints; //lastx,lasty; nOutPoints = 1; tscalebase = FGET( 1, nMaxPoints ); tscale = 0; for ( t=1; t<nMaxPoints; t++ ) { R = ptR; P = lpPoints; n = nPoints; tscale += tscalebase; while (--n >= 0) { // FTransformer(lpTForm, P, &R->fx, &R->fy); R->fx = MAKEFIXED(P->x); R->fy = MAKEFIXED(P->y); R++; P++; } n = nPoints - 1; while ( --n >= 0 ) { R = ptR; for ( i=0; i<=n; i++ ) { fdx = (R+1)->fx - R->fx; fdy = (R+1)->fy - R->fy; R->fx += FIXMUL( fdx, tscale ); R->fy += FIXMUL( fdy, tscale ); R++; } } x = WHOLE(ptR[0].fx); y = WHOLE(ptR[0].fy); if (x != lastx || y != lasty) { lastx = x; lasty = y; if (lpOutputPoints) { lpOutputPoints->x = lastx; lpOutputPoints->y = lasty; lpOutputPoints++; } ++nOutPoints; } } n = nPoints - 1; x = WHOLE(ptR[n].fx); y = WHOLE(ptR[n].fy); if (x != lastx || y != lasty) { if (lpOutputPoints) { lpOutputPoints->x = x; lpOutputPoints->y = y; } ++nOutPoints; } return( nOutPoints ); }
static int ComputeZoom( HWND hWnd, int x, int y, int value, BOOL fIncremental, LFIXED *lfFileRate, int *Percentage ) /************************************************************************/ { LFIXED DispRate; int OldPercentage, iImageWidth, iImageHeight; LPIMAGE lpImage; LPDISPLAY lpDisplay; HWND hMDIWindow = hWnd; CWnd *pWnd = CWnd::FromHandle(hMDIWindow); if (pWnd->IsKindOf(RUNTIME_CLASS(CServerView))) hMDIWindow = pWnd->GetParentFrame()->GetSafeHwnd(); if (IsIconic(hMDIWindow)) return(FALSE); lpImage = GetImagePtr(hWnd); lpDisplay = GetDisplayPtr(hWnd); // Compute the viewing percentage, if necessary if ( !(*Percentage = lpDisplay->ViewPercentage) ) *Percentage = FMUL( 100, lpDisplay->DispRate ); // Compute the NEW viewing percentage, and DispRate if ( fIncremental ) { if (value < 0) { if (*Percentage > 100) { if (*Percentage % 100 != 0) *Percentage -= *Percentage % 100; else *Percentage -= 100; } else if (*Percentage <= 1) *Percentage = 0; else { OldPercentage = *Percentage; *Percentage = 100; while (*Percentage >= OldPercentage) *Percentage = (*Percentage+1)/2; } } else if (value > 0) { if (*Percentage > 32600) *Percentage = 0; else if (*Percentage >= 50) *Percentage = ((*Percentage+100)/100) * 100; else if (*Percentage) { OldPercentage = (*Percentage * 2) + 1; *Percentage = 100; while (*Percentage > OldPercentage) *Percentage = (*Percentage+1)/2; } else *Percentage = 1; } } else if (value > 0 && value < 32700) *Percentage = value; else *Percentage = 0; // do we have a valid zoom percentage? if (!*Percentage) return(FALSE); // can we mathematically support this percentage? DispRate = FGET( *Percentage, 100 ); /* DispRate */ *lfFileRate = FGET( 100, *Percentage ); /* FileRate */ if (!CanZoom(hWnd, *lfFileRate, &lpDisplay->FileRect, &lpDisplay->DispRect)) { return(FALSE); } // is our display surface too small? iImageWidth = FMUL(lpImage->npix, DispRate); iImageHeight = FMUL(lpImage->nlin, DispRate); if (iImageHeight < 1 || iImageWidth < 1) { return(FALSE); } return(TRUE); }
// Uses Mapping.Quarter_HSacrifice & Mapping.Quarter_SSacrifice // to set the highlights midtones and shaddows. void CToneBalanceDlg::set_sacrifice(LPQUARTERSTRUCT lpData, WORD wChannel) { LPMAP lpMap; LPDWORD lpHisto; BOOL bInv; LONG lSum, lSearch, lTotal; int hi, lo, i; // get the map & set its invert flags lpMap = tone_activate_channel( wChannel ); lpHisto = get_histo(lpData->lpHistos, wChannel, &bInv); // determine initail values hi = 170; lo = 85; if (lpHisto) { // Find the total of all entries to scale lTotal = 0; for ( i=0; i<256; i++ ) lTotal += lpHisto[i]; // find the sacrafice lSearch = bInv ? m_nHSacrifice:m_nSSacrifice; lSearch = FMUL( lTotal, FGET( lSearch, 100 ) ); lSum = -1; for ( i=0; i<255; i++ ) { lSum += lpHisto[i]; if ( lSum >= lSearch ) break; } lo = i; // find the sacrafice lSearch = bInv ? m_nSSacrifice:m_nHSacrifice; lSearch = FMUL( lTotal, FGET( lSearch, 100 ) ); lSum = -1; for ( i=255; i>0; i-- ) { lSum += lpHisto[i]; if ( lSum >= lSearch ) break; } hi = i; } if (bInv) { hi = 255-hi; lo = 255-lo; } i = lo; lo = min(lo,hi); hi = max(i,hi); // setup the map if (wChannel == IDC_DO_ALL) ResetMapEx( lpMap, 3, NO, YES); else ResetMap( lpMap, 3, NO ); lpMap->Pnt[0].x = lo; lpMap->Pnt[1].x = lo + (hi-lo)/2; lpMap->Pnt[2].x = hi; }
//************************************************************************ // lut_draw // PARAMETERS: // LPRECT lpArea- The area to update. // BOOL bOn- draw ON or draw OFF? // // DESCRIPTION: // Draws the given range from lpData. If lpData==NULL then it // will use lpdata->Map (setup in lut_compute). Draws handles // unless (dwFlags & MS_NOHANDLES). // RETURNS: // //************************************************************************ LOCAL void lut_draw(LPLUTCTL lpdata, HDC hDC, LPRECT lpArea, BOOL bOn) //*********************************************************************** { LFIXED rateX, rateY, lVal; BOOL bInvX = FALSE, bInvY = FALSE; POINT offset; POINT DataOut[256]; int OldROP; int i, lut, nLuts, maxx, maxy, num; LPTR lpLut; RGBS rgb; HPEN hOldPen, hPen; RECT rArea; POINT point; if ((lpdata->nLuts <= 0) || !lpdata->lpLut) return; // subtract one cause we are using PolyLine rArea = *lpArea; --rArea.bottom; --rArea.right; // bInvX = (lpdata->dwStyle & MS_INVERTX); // bInvY = (lpdata->dwStyle & MS_INVERTY); offset.x = (bInvX ? rArea.right : rArea.left); offset.y = (bInvY ? rArea.top: rArea.bottom); for (lut = 0; lut < lpdata->nLuts; ++lut) { // determine source data lpLut = lpdata->lpLut; lpLut += lut; nLuts = lpdata->nLuts; maxx = RectWidth(&rArea)-1; maxy = RectHeight(&rArea)-1; rateX = FGET(maxx, MAXVAL); rateY = FGET(maxy, MAXVAL); // convert to screen coords if (rateX < FUNITY) { // go through pixels rateX = FGET(MAXVAL, maxx); num = maxx+1; for (i=0; i<num; i++) { DataOut[i].x = i; DataOut[i].y = FMUL(lpLut[FMUL(i,rateX)*nLuts], rateY); } } else { // go through map lVal = 0; num = 256; for (i=0; i<num;i++) { DataOut[i].x = FROUND(lVal); DataOut[i].y = FMUL(lpLut[i*nLuts], rateY); lVal += rateX; } } // convert to screen coords for (i=0; i<num;i++) { DataOut[i].x = (bInvX ? (offset.x-DataOut[i].x) : (offset.x+DataOut[i].x)); DataOut[i].y = (bInvY ? (offset.y+DataOut[i].y) : (offset.y-DataOut[i].y)); } // draw line rgb = lpdata->Colors[lut]; hPen = CreatePen(PS_SOLID, 1, RGB(rgb.red, rgb.green, rgb.blue)); hOldPen = (HPEN)SelectObject(hDC, hPen); Polyline(hDC, DataOut, num); // make sure we draw on endpoint MoveToEx(hDC, DataOut[num-1].x, DataOut[num-1].y, &point); LineTo(hDC, DataOut[num-1].x+1, DataOut[num-1].y-1); SelectObject(hDC, hOldPen); DeleteObject(hPen); } }