예제 #1
0
    public virtual void SetupEffect(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture)
    {
      if (!UpdateBounds(ref verts))
        return;
      float w = _vertsBounds.Width;
      float h = _vertsBounds.Height;
      float xoff = _vertsBounds.X;
      float yoff = _vertsBounds.Y;
      if (adaptVertsToBrushTexture)
        for (int i = 0; i < verts.Length; i++)
        {
          PositionColoredTextured vert = verts[i];
          float x = vert.X;
          float u = x - xoff;
          u /= w;

          float y = vert.Y;
          float v = y - yoff;
          v /= h;

          if (u < 0) u = 0;
          if (u > 1) u = 1;
          if (v < 0) v = 0;
          if (v > 1) v = 1;
          unchecked
          {
            Color4 color = ColorConverter.FromColor(Color.White);
            vert.Color = color.ToBgra();
          }
          vert.Tu1 = u;
          vert.Tv1 = v;
          vert.Z = zOrder;
          verts[i] = vert;
        }
    }
예제 #2
0
    protected bool UpdateBounds(ref PositionColoredTextured[] verts)
    {
      if (verts == null)
      {
        _vertsBounds = RectangleF.Empty;
        return false;
      }
      float minx = float.MaxValue;
      float miny = float.MaxValue;
      float maxx = 0;
      float maxy = 0;
      foreach (PositionColoredTextured vert in verts)
      {
        if (vert.X < minx) minx = vert.X;
        if (vert.Y < miny) miny = vert.Y;

        if (vert.X > maxx) maxx = vert.X;
        if (vert.Y > maxy) maxy = vert.Y;
      }
      _vertsBounds = new RectangleF(minx, miny, maxx - minx, maxy - miny);
      return true;
    }
예제 #3
0
 public override void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture)
 {
   Allocate();
   base.SetupBrush(parent, ref verts, zOrder, adaptVertsToBrushTexture);
 }
예제 #4
0
    public void PerformLayout(RenderContext localRenderContext)
    {
      if (!_performLayout)
        return;
      _performLayout = false;

      // Setup background brush
      if (Background != null)
      {
        SizeF actualSize = new SizeF((float) ActualWidth, (float) ActualHeight);

        RectangleF rect = new RectangleF(ActualPosition.X - 0.5f, ActualPosition.Y - 0.5f,
            actualSize.Width + 0.5f, actualSize.Height + 0.5f);

        PositionColoredTextured[] verts = new PositionColoredTextured[6];
        verts[0].Position = new Vector3(rect.Left, rect.Top, 1.0f);
        verts[1].Position = new Vector3(rect.Left, rect.Bottom, 1.0f);
        verts[2].Position = new Vector3(rect.Right, rect.Bottom, 1.0f);
        verts[3].Position = new Vector3(rect.Left, rect.Top, 1.0f);
        verts[4].Position = new Vector3(rect.Right, rect.Top, 1.0f);
        verts[5].Position = new Vector3(rect.Right, rect.Bottom, 1.0f);
        Background.SetupBrush(this, ref verts, localRenderContext.ZOrder, true);
        PrimitiveBuffer.SetPrimitiveBuffer(ref _backgroundContext, ref verts, PrimitiveType.TriangleList);
      }
      else
        PrimitiveBuffer.DisposePrimitiveBuffer(ref _backgroundContext);
    }
예제 #5
0
    protected void CreateQuad(BitmapCharacter c, float sizeScale, float x, float y, ref List<PositionColoredTextured> verts)
    {
      x += c.XOffset;
      y += c.YOffset;
      PositionColoredTextured tl = new PositionColoredTextured(
          x * sizeScale, y * sizeScale, 1.0f,
          (c.X + 0.5f) / _charSet.Width,
          c.Y / (float) _charSet.Height,
          0
          );
      PositionColoredTextured br = new PositionColoredTextured(
          (x + c.Width) * sizeScale,
          (y + c.Height) * sizeScale,
          1.0f,
          (c.X + c.Width) / (float) _charSet.Width,
          (c.Y + c.Height - 0.5f) / _charSet.Height,
          0
          );
      PositionColoredTextured bl = new PositionColoredTextured(tl.X, br.Y, 1.0f, tl.Tu1, br.Tv1, 0);
      PositionColoredTextured tr = new PositionColoredTextured(br.X, tl.Y, 1.0f, br.Tu1, tl.Tv1, 0);

      verts.Add(tl);
      verts.Add(bl);
      verts.Add(tr);

      verts.Add(tr);
      verts.Add(bl);
      verts.Add(br);
    }
예제 #6
0
 public override void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture)
 {
   base.SetupBrush(parent, ref verts, zOrder, adaptVertsToBrushTexture);
   if (ServiceRegistration.Get<IPlayerManager>(false) == null)
     ServiceRegistration.Get<ILogger>().Debug("VideoBrush.SetupBrush: Player manager not found");
 }
예제 #7
0
    public override void Setup(RectangleF ownerRect, float zOrder, bool skinNeutralAR)
    {
      PositionColoredTextured[] verts = new PositionColoredTextured[4];

      // Upper left
      verts[0].X = ownerRect.Left;
      verts[0].Y = ownerRect.Top;
      verts[0].Color = 0;
      verts[0].Tu1 = 0.0f;
      verts[0].Tv1 = 0.0f;
      verts[0].Z = zOrder;

      // Bottom left
      verts[1].X = ownerRect.Left;
      verts[1].Y = ownerRect.Bottom;
      verts[1].Color = 0;
      verts[1].Tu1 = 0.0f;
      verts[1].Tv1 = 1.0f;
      verts[1].Z = zOrder;

      // Bottom right
      verts[2].X = ownerRect.Right;
      verts[2].Y = ownerRect.Bottom;
      verts[2].Color = 0;
      verts[2].Tu1 = 1.0f;
      verts[2].Tv1 = 1.0f;
      verts[2].Z = zOrder;

      // Upper right
      verts[3].X = ownerRect.Right;
      verts[3].Y = ownerRect.Top;
      verts[3].Color = 0;
      verts[3].Tu1 = 1.0f;
      verts[3].Tv1 = 0.0f;
      verts[3].Z = zOrder;

      PrimitiveBuffer.SetPrimitiveBuffer(ref _primitiveBuffer, ref verts, PrimitiveType.TriangleFan);

      _frameSize = skinNeutralAR ? ImageContext.AdjustForSkinAR(ownerRect.Size) : ownerRect.Size;
      _imageContext.FrameSize = _frameSize;
    }
    public static PositionColoredTextured[] CreateQuad_Fan(float left, float top, float right, float bottom,
      float uLeft, float vTop, float uRight, float vBottom,
      float zPos, Color4 color)
    {
      PositionColoredTextured[] verts = new PositionColoredTextured[4];

      // Upper left
      verts[0].X = left;
      verts[0].Y = top;
      verts[0].Color = color.ToBgra();
      verts[0].Tu1 = uLeft;
      verts[0].Tv1 = vTop;
      verts[0].Z = zPos;

      // Bottom left
      verts[1].X = left;
      verts[1].Y = bottom;
      verts[1].Color = color.ToBgra();
      verts[1].Tu1 = uLeft;
      verts[1].Tv1 = vBottom;
      verts[1].Z = zPos;

      // Bottom right
      verts[2].X = right;
      verts[2].Y = bottom;
      verts[2].Color = color.ToBgra();
      verts[2].Tu1 = uRight;
      verts[2].Tv1 = vBottom;
      verts[2].Z = zPos;

      // Upper right
      verts[3].X = right;
      verts[3].Y = top;
      verts[3].Color = color.ToBgra();
      verts[3].Tu1 = uRight;
      verts[3].Tv1 = vTop;
      verts[3].Z = zPos;

      return verts;
    }
예제 #9
0
 public override void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture)
 {
   base.SetupBrush(parent, ref verts, zOrder, adaptVertsToBrushTexture);
   _visualTexture = ContentManager.Instance.GetRenderTexture(_renderTextureKey);
   _visualSurface = ContentManager.Instance.GetRenderTarget(_renderSurfaceKey);
   _screen = parent.Screen;
   PrepareVisual();
 }
예제 #10
0
    protected override void DoPerformLayout(RenderContext context)
    {
      base.DoPerformLayout(context);

      // Setup brushes
      if (Fill != null || ((Stroke != null && StrokeThickness > 0)))
      {
        using (GraphicsPath path = CalculateTransformedPath(ParsePath(), _innerRect))
        {
          if (Fill != null && !_fillDisabled)
          {
            using (GraphicsPathIterator gpi = new GraphicsPathIterator(path))
            {
              PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][];
              using (GraphicsPath subPath = new GraphicsPath())
              {
                for (int i = 0; i < subPathVerts.Length; i++)
                {
                  bool isClosed;
                  gpi.NextSubpath(subPath, out isClosed);
                  PointF[] pathPoints = subPath.PathPoints;
                  TriangulateHelper.Triangulate(pathPoints, 1, out subPathVerts[i]);
                  if (subPathVerts[i] == null)
                    ServiceRegistration.Get<ILogger>().Warn("Failed to triangulate Path \"{0}\"!", Name);
                }
              }
              PositionColoredTextured[] verts;
              GraphicsPathHelper.Flatten(subPathVerts, out verts);
              if (verts != null)
              {
                Fill.SetupBrush(this, ref verts, context.ZOrder, true);
                PrimitiveBuffer.SetPrimitiveBuffer(ref _fillContext, ref verts, PrimitiveType.TriangleList);
              }
            }
          }
          else
            PrimitiveBuffer.DisposePrimitiveBuffer(ref _fillContext);

          if (Stroke != null && StrokeThickness > 0)
          {
            using (GraphicsPathIterator gpi = new GraphicsPathIterator(path))
            {
              PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][];
              using (GraphicsPath subPath = new GraphicsPath())
              {
                for (int i = 0; i < subPathVerts.Length; i++)
                {
                  bool isClosed;
                  gpi.NextSubpath(subPath, out isClosed);
                  PointF[] pathPoints = subPath.PathPoints;
                  TriangulateHelper.TriangulateStroke_TriangleList(pathPoints, (float) StrokeThickness, isClosed, 1, StrokeLineJoin,
                      out subPathVerts[i]);
                }
              }
              PositionColoredTextured[] verts;
              GraphicsPathHelper.Flatten(subPathVerts, out verts);
              if (verts != null)
              {
                Stroke.SetupBrush(this, ref verts, context.ZOrder, true);
                PrimitiveBuffer.SetPrimitiveBuffer(ref _strokeContext, ref verts, PrimitiveType.TriangleList);
              }
            }
          }
          else
            PrimitiveBuffer.DisposePrimitiveBuffer(ref _strokeContext);
        }
      }
    }
예제 #11
0
    /// <summary>
    /// Copies the given vertex data into a vertex buffer, re-allocating it if necessary.
    /// </summary>
    /// <param name="vertices">The vertex data to copy.</param>
    /// <param name="primitiveType">The primitive type to be used when rendering.</param>
    public void Set(ref PositionColoredTextured[] vertices,  PrimitiveType primitiveType)
    {
      if (vertices == null)
      {
        Clear();
        return;
      }
      int numVertices = vertices.Length;
      if (_vertexBuffer == null || numVertices > VertexCount)
        Create(numVertices);

      switch (primitiveType)
      {
        // case PrimitiveType.PointList:
        case PrimitiveType.LineList:
          if (numVertices % 2 != 0 || numVertices < 2)
            ThrowInvalidVertexCount();
          _primitiveCount = numVertices / 2;
          break;
        case PrimitiveType.LineStrip:
          if (numVertices < 2)
            ThrowInvalidVertexCount();
          _primitiveCount = numVertices - 1;
          break;
        case PrimitiveType.TriangleList:
          if (numVertices < 3 || numVertices % 3 != 0)
            ThrowInvalidVertexCount();
          _primitiveCount = numVertices / 3;
          break;
        case PrimitiveType.TriangleStrip:
        case PrimitiveType.TriangleFan:
          if (numVertices < 3)
            ThrowInvalidVertexCount();
          _primitiveCount = numVertices - 2;
          break;
        default:
          throw new NotImplementedException("Unknown PrimitiveType");
      }
      _primitiveType = primitiveType;

      using (DataStream stream = _vertexBuffer.Lock(0, 0, LockFlags.None))
        stream.WriteRange(vertices);
      _vertexBuffer.Unlock();
    }
예제 #12
0
 /// <summary>
 /// Constructor to fully initialise the buffer with the passed vertices.
 /// </summary>
 /// <param name="vertices">The vertex data to copy.</param>
 /// <param name="primitiveType">The primitive type to be used when rendering.</param>
 public PrimitiveBuffer(ref PositionColoredTextured[] vertices, PrimitiveType primitiveType)
 {
   Set(ref vertices, primitiveType);
 }
예제 #13
0
 public static void SetPrimitiveBuffer(ref PrimitiveBuffer _buffer, ref PositionColoredTextured[] verts, PrimitiveType type)
 {
   if (_buffer == null)
     _buffer = new PrimitiveBuffer();
   _buffer.Set(ref verts, type);
 }