javauis/m2g_qt/inc/M2GUtils.h
changeset 57 59b3b4473dc8
parent 56 abc41079b313
child 64 0ea12c182930
equal deleted inserted replaced
56:abc41079b313 57:59b3b4473dc8
     1 /*
       
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  General functions
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef M2GUTILS_H
       
    19 #define M2GUTILS_H
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <gdi.h> // DisplayMode, Draw, BitBlt
       
    23 #include <fbs.h> // CFbsBitmap
       
    24 #include "M2GGeneral.h"
       
    25 #include <QPixmap>
       
    26 
       
    27 M2G_NS_START
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // DATA TYPES
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 class CFbsBitmapDevice;
       
    37 class CFbsBitGc;
       
    38 
       
    39 // FUNCTION PROTOTYPES
       
    40 
       
    41 // CLASS DECLARATION
       
    42 
       
    43 
       
    44 //For UI Thread Execution.
       
    45 #include "CSynchronization.h"
       
    46 
       
    47 #define M2G_DO_LOCK CSynchronization::InstanceL()->Lock();
       
    48 
       
    49 
       
    50 //TODO Have to Raise Exception in case we find any error.
       
    51 #define M2G_DO_UNLOCK(aEnv) {\
       
    52                     TInt errorCode = CSynchronization::InstanceL()->GetErrorCode();\
       
    53                     CSynchronization::InstanceL()->Unlock();\
       
    54                     }\
       
    55 
       
    56 /**
       
    57  * @class M2GBitmapUtils
       
    58  * @brief Static methods for alpha blending and bitmaps
       
    59  */
       
    60 
       
    61 class M2GBitmapUtils
       
    62 {
       
    63 public: // STATIC METHODS
       
    64     /**
       
    65      * Blits two bitmap
       
    66      * @since Series S60 3.0
       
    67      * @param aTarget Target bitmap.
       
    68      * @param aSource Source bitmap.
       
    69      * @param aPoint Position for the top left corner of the bitmap.
       
    70      * @param aRect  Rectangle defining the piece of the bitmap to be drawn.
       
    71      * @param aSourceMask Mask.
       
    72      * @return M2G_OK if ok
       
    73      */
       
    74     static TInt BitBlt(CFbsBitmap& aTarget,
       
    75                        const CFbsBitmap& aSource,
       
    76                        const TPoint& aPoint,
       
    77                        const TRect* aRect = NULL,
       
    78                        const CFbsBitmap* aSourceMask = NULL);
       
    79 
       
    80     static TInt BitBlt(CBitmapContext& aTargetContext,
       
    81                        const CFbsBitmap& aSource,
       
    82                        const TPoint& aPoint,
       
    83                        const TRect* aRect,
       
    84                        const CFbsBitmap* aSourceMask,
       
    85                        /*MSwtClient* aClientHandle,*/
       
    86                        TBool aUseNativeClear = EFalse);
       
    87     
       
    88     static TInt BitQBlt(QImage& aTargetQimage,
       
    89                                 const QImage& aSourceQimage,
       
    90                                 const TPoint& aPoint,
       
    91                                 const TRect* aRect,
       
    92                                 const CFbsBitmap* aSourceMask);
       
    93     
       
    94     /**
       
    95      * Checks if two bitmap are equal.
       
    96      * @since Series S60 3.0
       
    97      * @param aLhs Left side bitmap
       
    98      * @param aRhs Right side bitmap
       
    99      * @return ETrue if bitmaps are equal.
       
   100      */
       
   101     inline static TBool Equals(const CFbsBitmap& aLhs, const CFbsBitmap& aRhs)
       
   102     {
       
   103         return (aLhs.SizeInPixels() == aRhs.SizeInPixels());
       
   104     }
       
   105 
       
   106     /**
       
   107      * Checks if a bitmap has same values as given values.
       
   108      * @since Series S60 3.0
       
   109      * @param aBitmap Bitmap
       
   110      * @param aSz Size in pixels.
       
   111      * @param aMode Display mode.
       
   112      * @return ETrue if bitmaps are equal.
       
   113      */
       
   114     inline static TBool Equals(
       
   115         const CFbsBitmap& aBitmap,
       
   116         const TSize& aSz,
       
   117         const TDisplayMode* aMode)
       
   118     {
       
   119         return (((aBitmap.SizeInPixels() == aSz) &&
       
   120                  ((aMode == NULL) || (aBitmap.DisplayMode() == *aMode))
       
   121                 ) ? ETrue : EFalse);
       
   122     }
       
   123 
       
   124     /**
       
   125      * Return byte per pixel
       
   126      * @since Series S60 3.1
       
   127      * @param aBitmap
       
   128      * @param aRhs Right side bitmap
       
   129      * @return ETrue if bitmaps are equal.
       
   130      */
       
   131     inline static TInt BytesPerPixel(const CFbsBitmap& aBitmap)
       
   132     {
       
   133         switch (aBitmap.DisplayMode())
       
   134         {
       
   135         case EGray256 :
       
   136         case EColor256 :
       
   137             return 1;
       
   138         case EColor64K :
       
   139             return 2;
       
   140         case EColor16M :
       
   141         case EColor16MU :
       
   142         case EColor16MA :
       
   143             return 4;
       
   144         default :
       
   145             return 0;
       
   146         }
       
   147     }
       
   148 
       
   149 };
       
   150 
       
   151 /**
       
   152  * @class TM2GRenderRect
       
   153  * @brief Class for handling rendering rectangle
       
   154  */
       
   155 class TM2GRenderRect : public TRect
       
   156 {
       
   157 private:
       
   158     // NOTE ELength should be always the last one and indexing
       
   159     // should start from 0
       
   160     enum TArrayIndexes
       
   161     {
       
   162         EAnchorX = 0,
       
   163         EAnchorY = 1,
       
   164         EClipX = 2,
       
   165         EClipY = 3,
       
   166         EClipW = 4,
       
   167         EClipH = 5,
       
   168         ELength
       
   169     };
       
   170 
       
   171 public: // METHODS
       
   172     /**
       
   173      * Ctor
       
   174      * @since Series S60 3.0
       
   175      * @param aAnchorX X anchor
       
   176      * @param aAnchorY Y anchor
       
   177      * @param aClipX Clip x
       
   178      * @param aClipY Clip y
       
   179      * @param aClipWidth Clip width
       
   180      * @param aClipHeight Clip height
       
   181      */
       
   182     TM2GRenderRect(
       
   183         TInt aAnchorX, TInt aAnchorY,
       
   184         TInt aClipX, TInt aClipY,
       
   185         TInt aClipW, TInt aClipH);
       
   186 
       
   187     /**
       
   188      * Ctor
       
   189      * @since Series S60 3.0
       
   190      * @param aDimensions Dimensions. @see TArrayIndexes.
       
   191      * @param aLength Array length
       
   192      */
       
   193     TM2GRenderRect(TInt* aDimensions, TInt aLength);
       
   194 
       
   195     /**
       
   196      * Copy ctor
       
   197      * @since Series S60 3.0
       
   198      * @param aRd
       
   199      */
       
   200     TM2GRenderRect(const TM2GRenderRect& aRd);
       
   201 
       
   202     /**
       
   203      * Assignment operator
       
   204      * @since Series S60 3.0
       
   205      * @param aRd
       
   206      * @return TM2GRenderRect
       
   207      */
       
   208     TM2GRenderRect& operator=(const TM2GRenderRect& aRd);
       
   209 
       
   210     /**
       
   211      * Dtor
       
   212      * @since Series S60 3.0
       
   213      */
       
   214     virtual ~TM2GRenderRect();
       
   215 
       
   216     /**
       
   217      * Returns x anchor
       
   218      * @since Series S60 3.0
       
   219      * @return X anchor
       
   220      */
       
   221     inline TInt GetAnchorX()
       
   222     {
       
   223         return iAnchorX;
       
   224     }
       
   225 
       
   226     /**
       
   227      * Returns y anchor
       
   228      * @since Series S60 3.0
       
   229      * @return Y anchor
       
   230      */
       
   231     inline TInt GetAnchorY()
       
   232     {
       
   233         return iAnchorY;
       
   234     }
       
   235 
       
   236     /**
       
   237      * Returns clip height
       
   238      * @since Series S60 3.0
       
   239      * @return Clip height
       
   240      */
       
   241     inline TInt GetClipH()
       
   242     {
       
   243         return Height();
       
   244     }
       
   245 
       
   246     /**
       
   247      * Returns x clip
       
   248      * @since Series S60 3.0
       
   249      * @return X clip
       
   250      */
       
   251     inline TInt GetClipX()
       
   252     {
       
   253         return iTl.iX;
       
   254     }
       
   255 
       
   256     /**
       
   257      * Returns y clip
       
   258      * @since Series S60 3.0
       
   259      * @return Y clip
       
   260      */
       
   261     inline TInt GetClipY()
       
   262     {
       
   263         return iTl.iY;
       
   264     }
       
   265 
       
   266     /**
       
   267      * Returns clip width
       
   268      * @since Series S60 3.0
       
   269      * @return Clip width
       
   270      */
       
   271     inline TInt GetClipW()
       
   272     {
       
   273         return Width();
       
   274     }
       
   275 
       
   276     /**
       
   277      * Sets x anchor
       
   278      * @since Series S60 3.0
       
   279      * @param aX X anchor
       
   280      */
       
   281     inline void SetAnchorX(TInt aX)
       
   282     {
       
   283         iAnchorX = aX;
       
   284     }
       
   285 
       
   286     /**
       
   287      * Sets y anchor
       
   288      * @since Series S60 3.0
       
   289      * @param aY Y anchor
       
   290      */
       
   291     inline void SetAnchorY(TInt aY)
       
   292     {
       
   293         iAnchorY = aY;
       
   294     }
       
   295 
       
   296     /**
       
   297      * Sets clip height
       
   298      * @since Series S60 3.0
       
   299      * @param aH Clip height
       
   300      */
       
   301     inline void SetClipH(TInt aH)
       
   302     {
       
   303         SetHeight(aH);
       
   304     }
       
   305 
       
   306     /**
       
   307      * Sets x clip
       
   308      * @since Series S60 3.0
       
   309      * @param aX X clip
       
   310      */
       
   311     inline void SetClipX(TInt aX)
       
   312     {
       
   313         iTl.iX = aX;
       
   314     }
       
   315 
       
   316     /**
       
   317      * Sets y clip
       
   318      * @since Series S60 3.0
       
   319      * @param aY Y clip
       
   320      */
       
   321     inline void SetClipY(TInt aY)
       
   322     {
       
   323         iTl.iY = aY;
       
   324     }
       
   325 
       
   326     /**
       
   327      * Sets clip width
       
   328      * @since Series S60 3.0
       
   329      * @param aW Clip width
       
   330      */
       
   331     inline void SetClipW(TInt aW)
       
   332     {
       
   333         SetWidth(aW);
       
   334     }
       
   335 
       
   336 public: // STATIC METHODS
       
   337     /**
       
   338      * Gets region size
       
   339      * @since Series S60 3.0
       
   340      * @param aRect Render dimensions
       
   341      * @param aSz Source surface size
       
   342      * @return Region size to be paint
       
   343      */
       
   344     static TSize GetRegionSizeInPixels(
       
   345         TM2GRenderRect& aRect,
       
   346         const TSize& aSz);
       
   347 
       
   348 public: // VARIABLES
       
   349     TInt iAnchorX;
       
   350     TInt iAnchorY;
       
   351 };
       
   352 
       
   353 
       
   354 /**
       
   355  * @class TM2GBitmapLock
       
   356  * @brief Bitmap autolocker
       
   357  */
       
   358 class TM2GBitmapLock
       
   359 {
       
   360 public: // METHODS
       
   361     /**
       
   362      * Ctor
       
   363      * @param aBitmap Bitmap
       
   364      * @param aLock If ETrue then bitmap is locked by ctor.
       
   365      */
       
   366     TM2GBitmapLock(const CFbsBitmap* aBitmap, TBool aLock = ETrue);
       
   367 
       
   368     /**
       
   369      * Dtor
       
   370      * @since Series S60 3.0
       
   371      */
       
   372     virtual ~TM2GBitmapLock();
       
   373 
       
   374     /**
       
   375      * Locks bitmap heap
       
   376      * @since Series S60 3.0
       
   377      */
       
   378     void Lock();
       
   379 
       
   380     /**
       
   381      * Unlocks bitmap heap
       
   382      * @since Series S60 3.0
       
   383      */
       
   384     void Unlock();
       
   385 
       
   386 protected: // METHODS
       
   387     /**
       
   388      * Copy ctor
       
   389      * @since Series S60 3.0
       
   390      * @param aRd
       
   391      */
       
   392     TM2GBitmapLock(const TM2GBitmapLock& aRd);
       
   393 
       
   394     /**
       
   395      * Assignment operator
       
   396      * @since Series S60 3.0
       
   397      * @param aRd
       
   398      * @return TM2GBitmapLock
       
   399      */
       
   400     TM2GBitmapLock& operator=(const TM2GBitmapLock& aRd);
       
   401 
       
   402 public: // VARIABLES
       
   403     const CFbsBitmap* iBitmap;
       
   404     TBool iIsLocked;
       
   405 };
       
   406 class TSWTBitBlt/*: public MSwtFunctor*/
       
   407 {
       
   408 public:
       
   409     TSWTBitBlt(CBitmapContext& aTargetContext,
       
   410                const TPoint& aPoint,
       
   411                const CFbsBitmap* aBitmap,
       
   412                const TRect* aSourceRect,
       
   413                const CFbsBitmap* aMaskBitmap,
       
   414                TBool aUseNativeClear);
       
   415 
       
   416     void operator()() const;
       
   417     CBitmapContext& iTargetContext;
       
   418     const TPoint iPoint;
       
   419     const CFbsBitmap* iBitmap;
       
   420     const TRect* iRect;
       
   421     const CFbsBitmap* iMaskBitmap;
       
   422     TBool iUseNativeClear;
       
   423 };
       
   424 M2G_NS_END
       
   425 
       
   426 
       
   427 #endif // M2GUTILS_H