ClampIndex() private method

private ClampIndex ( int val, int max ) : int
val int
max int
return int
Ejemplo n.º 1
0
    /// <summary>
    /// Add a border around the specified color buffer with the width and height of a single pixel all around.
    /// The returned color buffer will have its width and height increased by 2.
    /// </summary>

    static public Color32[] AddBorder(Color32[] colors, int width, int height)
    {
        int w2 = width + 2;
        int h2 = height + 2;

        Color32[] c2 = new Color32[w2 * h2];

        for (int y2 = 0; y2 < h2; ++y2)
        {
            int y1 = NGUIMath.ClampIndex(y2 - 1, height);

            for (int x2 = 0; x2 < w2; ++x2)
            {
                int x1 = NGUIMath.ClampIndex(x2 - 1, width);
                int i2 = x2 + y2 * w2;
                c2[i2] = colors[x1 + y1 * width];

                if (x2 == 0 || x2 + 1 == w2 || y2 == 0 || y2 + 1 == h2)
                {
                    c2[i2].a = 0;
                }
            }
        }
        return(c2);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Add a border around the sprite that extends the existing edge pixels.
    /// </summary>

    void AddClampedBorder(UISpriteData sprite)
    {
        List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width - se.borderLeft - se.borderRight;
            int h1 = se.tex.height - se.borderBottom - se.borderTop;

            int w2 = se.tex.width + 2;
            int h2 = se.tex.height + 2;

            Color32[] c1 = se.tex.GetPixels32();
            Color32[] c2 = new Color32[w2 * h2];

            for (int y2 = 0; y2 < h2; ++y2)
            {
                int y1 = se.borderBottom + NGUIMath.ClampIndex(y2 - se.borderBottom - 1, h1);

                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int x1 = se.borderLeft + NGUIMath.ClampIndex(x2 - se.borderLeft - 1, w1);
                    c2[x2 + y2 * w2] = c1[x1 + y1 * se.tex.width];
                }
            }

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            ++se.borderLeft;
            ++se.borderRight;
            ++se.borderTop;
            ++se.borderBottom;

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
Ejemplo n.º 3
0
 static public int ClampIndex_s(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         System.Int32 a1;
         checkType(l, 1, out a1);
         System.Int32 a2;
         checkType(l, 2, out a2);
         var ret = NGUIMath.ClampIndex(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Ejemplo n.º 4
0
 static public int ClampIndex_s(IntPtr l)
 {
     try {
         System.Int32 a1;
         checkType(l, 1, out a1);
         System.Int32 a2;
         checkType(l, 2, out a2);
         var ret = NGUIMath.ClampIndex(a1, a2);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Ejemplo n.º 5
0
 static public int ClampIndex_s(IntPtr l)
 {
     try {
         System.Int32 a1;
         checkType(l, 1, out a1);
         System.Int32 a2;
         checkType(l, 2, out a2);
         var ret = NGUIMath.ClampIndex(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    /// <summary>
    /// Add a dark shadowy outline around the sprite, giving it some visual depth.
    /// </summary>

    void AddDepth(UISpriteData sprite)
    {
        List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width;
            int h1 = se.tex.height;

            int w2 = w1 + 2;
            int h2 = h1 + 2;

            Color32[] c1 = se.tex.GetPixels32();
            Color32[] c2 = new Color32[w2 * h2];

            for (int y2 = 0; y2 < h2; ++y2)
            {
                int y1 = NGUIMath.ClampIndex(y2 - 1, h1);

                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int x1 = NGUIMath.ClampIndex(x2 - 1, w1);
                    int i2 = x2 + y2 * w2;
                    c2[i2] = c1[x1 + y1 * w1];

                    if (x2 == 0 || x2 + 1 == w2 || y2 == 0 || y2 + 1 == h2)
                    {
                        c2[i2].a = 0;
                    }
                }
            }

            for (int y2 = 0; y2 < h2; ++y2)
            {
                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int     index = x2 + y2 * w2;
                    Color32 uc    = c2[index];
                    if (uc.a == 255)
                    {
                        continue;
                    }

                    Color original = uc;
                    float val      = original.a * 4f;
                    int   count    = 4;
                    float div1     = 1f / 255f;
                    float div2     = 2f / 255f;

                    if (x2 != 0)
                    {
                        val   += c2[x2 - 1 + y2 * w2].a * div2;
                        count += 2;
                    }

                    if (x2 + 1 != w2)
                    {
                        val   += c2[x2 + 1 + y2 * w2].a * div2;
                        count += 2;
                    }

                    if (y2 != 0)
                    {
                        val   += c2[x2 + (y2 - 1) * w2].a * div2;
                        count += 2;
                    }

                    if (y2 + 1 != h2)
                    {
                        val   += c2[x2 + (y2 + 1) * w2].a * div2;
                        count += 2;
                    }

                    if (x2 != 0 && y2 != 0)
                    {
                        val += c2[x2 - 1 + (y2 - 1) * w2].a * div1;
                        ++count;
                    }

                    if (x2 != 0 && y2 + 1 != h2)
                    {
                        val += c2[x2 - 1 + (y2 + 1) * w2].a * div1;
                        ++count;
                    }

                    if (x2 + 1 != w2 && y2 != 0)
                    {
                        val += c2[x2 + 1 + (y2 - 1) * w2].a * div1;
                        ++count;
                    }

                    if (x2 + 1 != w2 && y2 + 1 != h2)
                    {
                        val += c2[x2 + 1 + (y2 + 1) * w2].a * div1;
                        ++count;
                    }

                    val /= count;

                    Color shadow = new Color(0f, 0f, 0f, val);
                    shadow    = Color.Lerp(original, shadow, mAlpha);
                    c2[index] = Color.Lerp(shadow, original, original.a);
                }
            }

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            ++se.borderLeft;
            ++se.borderRight;
            ++se.borderTop;
            ++se.borderBottom;

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
Ejemplo n.º 7
0
 public unsafe static long $Invoke9(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(NGUIMath.ClampIndex(*(int *)args, *(int *)(args + 1))));
 }