コード例 #1
0
 public GradientBrushTexture(GradientStopCollection stops)
 {
     _assetId++;
     _stops = new List <GradientStopData>(stops.Count);
     foreach (GradientStop stop in stops)
     {
         _stops.Add(GradientStopData.FromGradientStop(stop));
     }
     _name = String.Format("GradientBrushTexture#{0}", _assetId);
     Allocate();
 }
コード例 #2
0
        private static void CreatePartialGradient(byte[] data, GradientStopData stopBegin, GradientStopData stopEnd)
        {
            const float width = GRADIENT_TEXTURE_WIDTH;
            const int   offY  = GRADIENT_TEXTURE_WIDTH * 4;

            Color4 colorStart  = ColorConverter.FromColor(stopBegin.Color);
            Color4 colorEnd    = ColorConverter.FromColor(stopEnd.Color);
            int    offsetStart = (int)(stopBegin.Offset * width);
            int    offsetEnd   = (int)(stopEnd.Offset * width);

            int clampedStart = Math.Max(0, offsetStart);
            int clampedEnd   = Math.Min(GRADIENT_TEXTURE_WIDTH, offsetEnd);

            float distance = offsetEnd - offsetStart;

            for (int x = clampedStart; x < clampedEnd; ++x)
            {
                float step = (x - offsetStart) / distance;
                float r    = step * (colorEnd.Red - colorStart.Red);
                r += colorStart.Red;

                float g = step * (colorEnd.Green - colorStart.Green);
                g += colorStart.Green;

                float b = step * (colorEnd.Blue - colorStart.Blue);
                b += colorStart.Blue;

                float a = step * (colorEnd.Alpha - colorStart.Alpha);
                a += colorStart.Alpha;

                a *= 255;
                r *= 255;
                g *= 255;
                b *= 255;

                int offx = x * 4;
                data[offx]     = (byte)b;
                data[offx + 1] = (byte)g;
                data[offx + 2] = (byte)r;
                data[offx + 3] = (byte)a;

                data[offY + offx]     = (byte)b;
                data[offY + offx + 1] = (byte)g;
                data[offY + offx + 2] = (byte)r;
                data[offY + offx + 3] = (byte)a;
            }
        }
コード例 #3
0
    private static void CreatePartialGradient(byte[] data, GradientStopData stopBegin, GradientStopData stopEnd)
    {
      const float width = GRADIENT_TEXTURE_WIDTH;
      const int offY = GRADIENT_TEXTURE_WIDTH * 4;

      Color4 colorStart = ColorConverter.FromColor(stopBegin.Color);
      Color4 colorEnd = ColorConverter.FromColor(stopEnd.Color);
      int offsetStart = (int) (stopBegin.Offset * width);
      int offsetEnd = (int) (stopEnd.Offset * width);

      int clampedStart = Math.Max(0, offsetStart);
      int clampedEnd = Math.Min(GRADIENT_TEXTURE_WIDTH, offsetEnd);

      float distance = offsetEnd - offsetStart;
      for (int x = clampedStart; x < clampedEnd; ++x)
      {
        float step = (x - offsetStart) / distance;
        float r = step * (colorEnd.Red - colorStart.Red);
        r += colorStart.Red;

        float g = step * (colorEnd.Green - colorStart.Green);
        g += colorStart.Green;

        float b = step * (colorEnd.Blue - colorStart.Blue);
        b += colorStart.Blue;

        float a = step * (colorEnd.Alpha - colorStart.Alpha);
        a += colorStart.Alpha;

        a *= 255;
        r *= 255;
        g *= 255;
        b *= 255;

        int offx = x * 4;
        data[offx] = (byte) b;
        data[offx + 1] = (byte) g;
        data[offx + 2] = (byte) r;
        data[offx + 3] = (byte) a;

        data[offY + offx] = (byte) b;
        data[offY + offx + 1] = (byte) g;
        data[offY + offx + 2] = (byte) r;
        data[offY + offx + 3] = (byte) a;
      }
    }