[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]
[XaraXtreme-commits] Commit Complete
Commit by : luke
Repository : xara
Revision : 1761
Date : Mon Sep 25 14:09:51 BST 2006
Changed paths:
M /Trunk/XaraLX/Kernel/bitfilt.cpp
M /Trunk/XaraLX/Kernel/bitfilt.h
M /Trunk/XaraLX/Kernel/nodebmp.cpp
Add same optimsations to bitmap drag from gallery, as were added to bitmap import
Diff:
Index: Trunk/XaraLX/Kernel/bitfilt.h
===================================================================
--- Trunk/XaraLX/Kernel/bitfilt.h (revision 1760)
+++ Trunk/XaraLX/Kernel/bitfilt.h (revision 1761)
@@ -311,6 +311,9 @@
static BOOL GetZoomOnImport() { return s_fZoomOnImport; }
static void SetZoomOnImport( BOOL fFlag ) { s_fZoomOnImport = fFlag; }
+ static BOOL GetWarnedZoomOnImport() { return s_fWarnedZoomOnImport; }
+ static void SetWarnedZoomOnImport( BOOL fFlag ) { s_fWarnedZoomOnImport = fFlag; }
+
protected:
// Something to mark if this is a meant as a Preview Bitmap or not
BOOL IsPreviewBitmap;
@@ -516,4 +519,51 @@
BMP_DEPTH m_RenderDepth;
};
+
+/********************************************************************************************
+
+> inline LONG GridLock(LONG Position, LONG GridSize)
+
+ Author: Neville from Jason code in coldlog.cpp
+ Created: 22/9/97
+ Inputs: Position - The X/Y position, in millipoints
+ GridSize - the size of the grid to lock to, in millipoints
+ Returns: Position, locked (by rounding) to a grid of the given size, and offset by
+ half a grid.
+ Purpose: Grid-locks a given plotting position to lie over a grid (usually the
+ output device-pixel grid). The result is shifted by half the grid size to
+ grid-lock to the _center_ of a pixel rather than the edges.
+ Note: stolen from ColourEditDlg/PreviewDialog rendering routines
+ Hoisted into header file, since useful for anything that uses bitmaps
+
+********************************************************************************************/
+
+inline INT32 GridLock(INT32 Position, INT32 GridSize)
+{
+ // By truncating down to the nearest grid point, and adding half the grid value,
+ // we achieve rounding to the nearest offset-grid position.
+
+ // NOTE:
+ // The original algorithm incorrectly rounded negative numbers towards
+ // zero. Negative numbers should be rounded towards negative infinity.
+ // The algorithm has been corrected by always rounding a positive number
+ // and restoring the original sign of the number after rounding.
+
+ BOOL bNegative = FALSE; // Assume the number is positive
+
+ if (Position < 0) // If the number if not positive
+ { // note the fact and make positive
+ bNegative = TRUE;
+ Position = -Position;
+ }
+
+ Position += GridSize / 2;
+ Position -= Position % GridSize;
+
+ if (bNegative) // If the number was negative
+ Position = -Position; // restore the sign
+
+ return (Position);
+}
+
#endif
Index: Trunk/XaraLX/Kernel/nodebmp.cpp
===================================================================
--- Trunk/XaraLX/Kernel/nodebmp.cpp (revision 1760)
+++ Trunk/XaraLX/Kernel/nodebmp.cpp (revision 1761)
@@ -119,6 +119,9 @@
//#include "scrcamvw.h"
#include "cliptype.h"
#include "attrmap.h"
+#include "spread.h"
+#include "zoomops.h"
+#include "bitfilt.h"
#include "colormgr.h"
//#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
@@ -2759,12 +2762,10 @@
KernelBitmap* KernelBmp = (KernelBitmap*)(void *)pOpParam->Param1;
PageDropInfo* pDropInfo = (PageDropInfo*)(void *)pOpParam->Param2;
-// Document* pDoc = pDropInfo->pDoc;
+ DocView* pDocView = DocView::GetCurrent();
Spread* pSpread = pDropInfo->pSpread;
DocCoord DropPos = pDropInfo->DropPos;
- DocRect BoundsRect;
- BitmapInfo Info;
NodeBitmap* pNodeBitmap = new NodeBitmap();
if ((pNodeBitmap == NULL) || (!pNodeBitmap->SetUpPath(12,12)))
@@ -2778,29 +2779,109 @@
delete KernelBmp;
}
+ {
+ DocRect BoundsRect;
+ BitmapInfo Info;
+
+ // Import worked - try to add the bitmap object into the tree.
+ // First, set the rectangle to the right size for the bitmap...
+ pNodeBitmap->GetBitmap()->ActualBitmap->GetInfo(&Info);
+
+ const INT32 HPixelSize = ( pDocView->GetPixelWidth() + 0.5 ).MakeLong(); // Size of output pixel in millipoints
+ const INT32 VPixelSize = ( pDocView->GetPixelHeight() + 0.5 ).MakeLong();// Size of output pixel in millipoints
+
+ // Make sure that this is snapped to a pixel grid
+ BoundsRect.lo.x = DropPos.x - ( Info.RecommendedWidth / 2 );
+ BoundsRect.lo.y = DropPos.y - ( Info.RecommendedHeight / 2 );
+ BoundsRect.lo.x = GridLock(BoundsRect.lo.x, HPixelSize);
+ BoundsRect.lo.y = GridLock(BoundsRect.lo.y, VPixelSize);
+ // And now add in the rest of the bounds
+ BoundsRect.hi.x = BoundsRect.lo.x + Info.RecommendedWidth;
+ BoundsRect.hi.y = BoundsRect.lo.y + Info.RecommendedHeight;
+ BoundsRect.hi.x = GridLock(BoundsRect.hi.x, HPixelSize);
+ BoundsRect.hi.y = GridLock(BoundsRect.hi.y, VPixelSize);
+
+ // And set this in our bitmap node
+ pNodeBitmap->CreateShape(BoundsRect);
+
+ // Set the default attrs
+ // This Must be done before the NodeBitmap is inserted into the tree
+ if (!pNodeBitmap->ApplyDefaultBitmapAttrs(this))
+ goto EndOp;
+
+ // Insert the node
+ if (!DoInsertNewNode(pNodeBitmap, pSpread, TRUE))
+ {
+ // It didn't work - delete the sub-tree we just created.
+ delete pNodeBitmap;
+ goto EndOp;
+ }
- pNodeBitmap->GetBitmap()->ActualBitmap->GetInfo(&Info);
+ // Get the spread's bounding rectangle and convert it to spread coords.
+ DocRect SpreadRect = pSpread->GetPasteboardRect();
+ pSpread->DocCoordToSpreadCoord(&SpreadRect);
- BoundsRect.lo.x = DropPos.x - (Info.RecommendedWidth/2);
- BoundsRect.lo.y = DropPos.y - (Info.RecommendedHeight/2);
- BoundsRect.hi.x = DropPos.x + (Info.RecommendedWidth/2);
- BoundsRect.hi.y = DropPos.y + (Info.RecommendedHeight/2);
+ // If bounding box off the spread - limit it to the edge of the spread:
- // And set this in our bitmap node
- pNodeBitmap->CreateShape(BoundsRect);
+ // (a) Horizontal adjustment
+ DocCoord Offset(0,0);
+ if (BoundsRect.lo.x < SpreadRect.lo.x)
+ Offset.x += (SpreadRect.lo.x - BoundsRect.lo.x);
+ else if (BoundsRect.hi.x > SpreadRect.hi.x)
+ Offset.x -= (BoundsRect.hi.x - SpreadRect.hi.x);
- // Set the default attrs
- // This Must be done before the NodeBitmap is inserted into the tree
- if (!pNodeBitmap->ApplyDefaultBitmapAttrs(this))
- goto EndOp;
-
- // Insert the node
- if (!DoInsertNewNode(pNodeBitmap, pSpread, TRUE))
- {
- // It didn't work - delete the sub-tree we just created.
- delete pNodeBitmap;
- goto EndOp;
- }
+ // (b) Vertical adjustment (most useful to clip hi co-ords)
+ if (BoundsRect.hi.y > SpreadRect.hi.y)
+ Offset.y -= (BoundsRect.hi.y - SpreadRect.hi.y);
+ else
+ if (BoundsRect.lo.y < SpreadRect.lo.y)
+ Offset.y += (SpreadRect.lo.y - BoundsRect.lo.y);
+
+ // Actually do the translation if needed
+ if( 0 != Offset.x ||
+ 0 != Offset.y )
+ {
+ Offset.x = GridLock(Offset.x, HPixelSize);
+ Offset.y = GridLock(Offset.y, VPixelSize);
+
+ // Build the matrix and transform the bitmap to the correct place
+ Trans2DMatrix Xlate(Offset.x, Offset.y);
+ pNodeBitmap->Transform(Xlate);
+ }
+
+ // Does the bitmap fit with our current view?
+ DocRect docrectBounds = pNodeBitmap->GetBoundingRect();
+ DocRect docrectView = pDocView->GetDocViewRect( pSpread );
+ pSpread->DocCoordToSpreadCoord( &docrectView );
+ if( ( docrectBounds.lo.x < docrectView.lo.x ||
+ docrectBounds.lo.y < docrectView.lo.y ||
+ docrectBounds.hi.x > docrectView.hi.x ||
+ docrectBounds.hi.y > docrectView.hi.y ) &&
+ BaseBitmapFilter::GetZoomOnImport() )
+ {
+ // No, zoom out so the all the bitmap can be seen
+ OpZoomFitRectDescriptor* pOpDesc = (OpZoomFitRectDescriptor*)OpDescriptor::FindOpDescriptor( OPTOKEN_ZOOMRECT );
+ if( NULL != pOpDesc )
+ {
+ pOpDesc->SetZoomRect( docrectBounds );
+ pOpDesc->Invoke();
+ }
+
+ // Keep user informed about the zoom operation
+ if( !BaseBitmapFilter::GetWarnedZoomOnImport() )
+ {
+ ErrorInfo Info;
+ memset( &Info, 0, sizeof(Info) );
+ Info.ErrorMsg = _R(IDS_ZOOM_ON_IMAGE_IMPORT);
+ Info.Button[0] = _R(IDS_OK);
+ Info.Button[1] = _R(IDS_DONT_SHOW_AGAIN);
+ Info.OK = 1;
+ if( _R(IDS_DONT_SHOW_AGAIN) == UINT32(InformMessage( &Info )) )
+ BaseBitmapFilter::SetWarnedZoomOnImport( TRUE );
+ }
+ }
+ }
+
ok = TRUE;
EndOp:
Index: Trunk/XaraLX/Kernel/bitfilt.cpp
===================================================================
--- Trunk/XaraLX/Kernel/bitfilt.cpp (revision 1760)
+++ Trunk/XaraLX/Kernel/bitfilt.cpp (revision 1761)
@@ -669,51 +669,7 @@
return 0;
}
-/********************************************************************************************
-> inline INT32 GridLock(INT32 Position, INT32 GridSize)
-
- Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xxxxxxxx> from Jason code in coldlog.cpp
- Created: 22/9/97
- Inputs: Position - The X/Y position, in millipoints
- GridSize - the size of the grid to lock to, in millipoints
- Returns: Position, locked (by rounding) to a grid of the given size, and offset by
- half a grid.
- Purpose: Grid-locks a given plotting position to lie over a grid (usually the
- output device-pixel grid). The result is shifted by half the grid size to
- grid-lock to the _center_ of a pixel rather than the edges.
- Note: stolen from ColourEditDlg/PreviewDialog rendering routines
-
-********************************************************************************************/
-
-inline INT32 GridLock(INT32 Position, INT32 GridSize)
-{
- // By truncating down to the nearest grid point, and adding half the grid value,
- // we achieve rounding to the nearest offset-grid position.
-
- // NOTE:
- // The original algorithm incorrectly rounded negative numbers towards
- // zero. Negative numbers should be rounded towards negative infinity.
- // The algorithm has been corrected by always rounding a positive number
- // and restoring the original sign of the number after rounding.
-
- BOOL bNegative = FALSE; // Assume the number is positive
-
- if (Position < 0) // If the number if not positive
- { // note the fact and make positive
- bNegative = TRUE;
- Position = -Position;
- }
-
- Position += GridSize / 2;
- Position -= Position % GridSize;
-
- if (bNegative) // If the number was negative
- Position = -Position; // restore the sign
-
- return (Position);
-}
-
/********************************************************************************************
> BOOL BaseBitmapFilter::DoImport(SelOperation *Op, CCLexFile* pFile,
Xara