当前位置: 首页>>代码示例>>C++>>正文


C++ Surface::StretchTo方法代码示例

本文整理汇总了C++中Surface::StretchTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Surface::StretchTo方法的具体用法?C++ Surface::StretchTo怎么用?C++ Surface::StretchTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Surface的用法示例。


在下文中一共展示了Surface::StretchTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Render

    bool Render(const RenderTarget &inTarget, const RenderState &inState)
    {
        Surface *s = mFill->bitmapData;
        double bmp_scale_x = 1.0/s->Width();
        double bmp_scale_y = 1.0/s->Height();
        // Todo:skew
        bool is_stretch = (inState.mTransform.mMatrix->m00!=1.0 ||
                           inState.mTransform.mMatrix->m11!=1.0) &&
                          ( inState.mTransform.mMatrix->m00 > 0 &&
                            inState.mTransform.mMatrix->m11 > 0  );

        for(int i=0; i<mTileData.size(); i++)
        {
            TileData &data= mTileData[i];

            BlendMode blend = data.mHasColour ? ( mBlendMode==bmAdd ? bmTintedAdd : bmTinted ):
                              mBlendMode;
            UserPoint corner(data.mPos);
            UserPoint pos = inState.mTransform.mMatrix->Apply(corner.x,corner.y);

            if (s->Format()==pfAlpha && !is_stretch && mBlendMode==bmNormal && data.mHasColour /* integer co-ordinate?*/ )
            {
                unsigned int col = inState.mColourTransform->Transform(data.mColour|0xff000000);
                s->BlitTo(inTarget, data.mRect, (int)(pos.x), (int)(pos.y), blend, 0, col);
            }
            else if ( (is_stretch || data.mHasTrans) )
            {
                // Can use stretch if there is no skew and no colour transform...
                if (!data.mHasColour && (!data.mHasTrans) &&  mBlendMode==bmNormal )
                {
                    UserPoint p0 = pos;
                    pos = inState.mTransform.mMatrix->Apply(corner.x+data.mRect.w,corner.y+data.mRect.h);
                    s->StretchTo(inTarget, data.mRect, DRect(p0.x,p0.y,pos.x,pos.y,true));
                }
                else
                {
                    int tile_alpha = 256;
                    bool just_alpha = (data.mHasColour) &&
                                      ((data.mColour&0x00ffffff ) == 0x00ffffff);
                    if (data.mHasColour && mBlendMode==bmNormal)
                    {
                        tile_alpha = data.mColour>>24;
                        if (tile_alpha>0) tile_alpha++;
                    }
                    // Create alpha mask...
                    UserPoint p[4];
                    p[0] = inState.mTransform.mMatrix->Apply(corner.x,corner.y);
                    if (data.mHasTrans)
                    {
                        p[1] = inState.mTransform.mMatrix->Apply(
                                   corner.x + data.mRect.w*data.mTransX.x,
                                   corner.y + data.mRect.w*data.mTransY.x);
                        p[2] = inState.mTransform.mMatrix->Apply(
                                   corner.x + data.mRect.w*data.mTransX.x + data.mRect.h*data.mTransX.y,
                                   corner.y + data.mRect.w*data.mTransY.x + data.mRect.h*data.mTransY.y );
                        p[3] = inState.mTransform.mMatrix->Apply(
                                   corner.x + data.mRect.h*data.mTransX.y,
                                   corner.y + data.mRect.h*data.mTransY.y );
                    }
                    else
                    {
                        p[1] = inState.mTransform.mMatrix->Apply(corner.x+data.mRect.w,corner.y);
                        p[2] = inState.mTransform.mMatrix->Apply(corner.x+data.mRect.w,corner.y+data.mRect.h);
                        p[3] = inState.mTransform.mMatrix->Apply(corner.x,corner.y+data.mRect.h);
                    }

                    Extent2DF extent;
                    extent.Add(p[0]);
                    extent.Add(p[1]);
                    extent.Add(p[2]);
                    extent.Add(p[3]);

                    // Get bounding pixel rect
                    Rect rect = inState.mTransform.GetTargetRect(extent);

                    // Intersect with clip rect ...
                    Rect visible_pixels = rect.Intersect(inState.mClipRect);
                    if (!visible_pixels.HasPixels())
                        continue;

                    Rect alpha_rect(visible_pixels);
                    bool offscreen_buffer = mBlendMode!=bmNormal;
                    if (offscreen_buffer)
                    {
                        for(int i=0; i<4; i++)
                        {
                            p[i].x -= visible_pixels.x;
                            p[i].y -= visible_pixels.y;
                        }
                        alpha_rect.x -= visible_pixels.x;
                        alpha_rect.y -= visible_pixels.y;
                    }

                    int aa = 1;
                    SpanRect *span = new SpanRect(alpha_rect,aa);
                    for(int i=0; i<4; i++)
                        span->Line00(
                            Fixed10( p[i].x, p[i].y  ),
                            Fixed10( p[(i+1)&3].x, p[(i+1)&3].y) );

//.........这里部分代码省略.........
开发者ID:evaluation-alex,项目名称:nme,代码行数:101,代码来源:TileRenderer.cpp

示例2: Render

   bool Render(const RenderTarget &inTarget, const RenderState &inState)
   {
      #define orthoTol 1e-6

      Surface *s = mFill->bitmapData;
      double bmp_scale_x = 1.0/s->Width();
      double bmp_scale_y = 1.0/s->Height();
      
      bool is_base_ortho = fabs(inState.mTransform.mMatrix->m01)< orthoTol  && fabs(inState.mTransform.mMatrix->m10)< orthoTol;
      float sx = inState.mTransform.mMatrix->m00;
      float sy = inState.mTransform.mMatrix->m11;
      bool is_base_identity = is_base_ortho && fabs(sx-1.0)<orthoTol && fabs(sy-1.0)<orthoTol;

      //int blits = 0;
      //int stretches = 0;
      //int renders = 0;

      for(int i=0;i<mTileData.size();i++)
      {
         TileData &data= mTileData[i];

         BlendMode blend = data.mHasColour ? ( mBlendMode==bmAdd ? bmTintedAdd : bmTinted ):
                                               mBlendMode;
         UserPoint corner(data.mPos);
         UserPoint pos = inState.mTransform.mMatrix->Apply(corner.x,corner.y);

         bool is_ortho = is_base_ortho && (!data.mHasTrans || fabs(data.mTransX.y)<orthoTol);
         bool is_identity = data.mHasTrans ?
                           is_ortho && fabs(sx*data.mTransX.x-1.0)<orthoTol && fabs(sy*data.mTransY.y-1)<orthoTol :
                           is_base_identity;

         if ( !is_identity )
         {
            // Can use stretch if there is no skew and no colour transform...
            if (!data.mHasColour && mBlendMode==bmNormal && is_ortho )
            {
               UserPoint p0 = pos;
               if (data.mHasTrans)
                  pos = inState.mTransform.mMatrix->Apply(corner.x+data.mRect.w*data.mTransX.x,
                                                          corner.y+data.mRect.h*data.mTransY.y);
               else
                  pos = inState.mTransform.mMatrix->Apply(corner.x+data.mRect.w,corner.y+data.mRect.h);

               s->StretchTo(inTarget, data.mRect, DRect(p0.x,p0.y,pos.x,pos.y,true));

               //stretches++;
            }
            else
            {
               //renders++;

               int tile_alpha = 256;
               bool just_alpha = (data.mHasColour) &&
                                 ((data.mColour&0x00ffffff ) == 0x00ffffff);
               if (data.mHasColour && mBlendMode==bmNormal)
               { 
                  tile_alpha = data.mColour>>24;
                  if (tile_alpha>0) tile_alpha++;
               }
               // Create alpha mask...
               UserPoint p[4];
               p[0] = inState.mTransform.mMatrix->Apply(corner.x,corner.y);
               if (data.mHasTrans)
               {
                  p[1] = inState.mTransform.mMatrix->Apply(
                            corner.x + data.mRect.w*data.mTransX.x,
                            corner.y + data.mRect.w*data.mTransY.x);
                  p[2] = inState.mTransform.mMatrix->Apply(
                            corner.x + data.mRect.w*data.mTransX.x + data.mRect.h*data.mTransX.y,
                            corner.y + data.mRect.w*data.mTransY.x + data.mRect.h*data.mTransY.y );
                  p[3] = inState.mTransform.mMatrix->Apply(
                            corner.x + data.mRect.h*data.mTransX.y,
                            corner.y + data.mRect.h*data.mTransY.y );
               }
               else
               {
                  p[1] = inState.mTransform.mMatrix->Apply(corner.x+data.mRect.w,corner.y);
                  p[2] = inState.mTransform.mMatrix->Apply(corner.x+data.mRect.w,corner.y+data.mRect.h);
                  p[3] = inState.mTransform.mMatrix->Apply(corner.x,corner.y+data.mRect.h);
               }

               Extent2DF extent;
               extent.Add(p[0]);
               extent.Add(p[1]);
               extent.Add(p[2]);
               extent.Add(p[3]);
               
               // Get bounding pixel rect
               Rect rect = inState.mTransform.GetTargetRect(extent);
               
               // Intersect with clip rect ...
               Rect visible_pixels = rect.Intersect(inState.mClipRect);
               if (!visible_pixels.HasPixels())
                  continue;
               
               Rect alpha_rect(visible_pixels);
               bool offscreen_buffer = mBlendMode!=bmNormal;
               if (offscreen_buffer)
               {
                  for(int i=0;i<4;i++)
//.........这里部分代码省略.........
开发者ID:haxenme,项目名称:nme,代码行数:101,代码来源:TileRenderer.cpp


注:本文中的Surface::StretchTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。