﻿// Decompiled with JetBrains decompiler
// Type: WBTextExtensions
// Assembly: Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 19851F1B-4780-4223-BA01-2C20F2CD781E
// Assembly location: C:\Users\CGA Computer\Desktop\LEGO Universe Stuff\LOCO Server\Unity Web Player Extractor\Saved Files\LOCO Server.unity3d_unpacked\Assembly-CSharp.dll

using UnityEngine;

public static class WBTextExtensions
{
  public static void SmartClip(this SpriteText spriteText, Vector3 topLeft, Vector3 bottomRight, bool clipX, bool clipY)
  {
    float num1 = spriteText.TotalWidth * (float) ((Component) spriteText).get_transform().get_lossyScale().x;
    float num2 = (float) ((double) spriteText.GetDisplayLineCount() * (double) spriteText.LineSpan * ((Component) spriteText).get_transform().get_lossyScale().y);
    Vector3 position = ((Component) spriteText).get_gameObject().get_transform().get_position();
    float num3 = 0.0f;
    float num4 = 0.0f;
    float num5 = num1 * 0.5f;
    float num6 = num2 * 0.5f;
    switch (spriteText.Anchor)
    {
      case SpriteText.Anchor_Pos.Upper_Left:
        num3 = num5;
        num4 = -num6;
        break;
      case SpriteText.Anchor_Pos.Upper_Center:
        num4 = -num6;
        break;
      case SpriteText.Anchor_Pos.Upper_Right:
        num3 = -num5;
        num4 = -num6;
        break;
      case SpriteText.Anchor_Pos.Middle_Left:
        num3 = num5;
        break;
      case SpriteText.Anchor_Pos.Middle_Right:
        num3 = -num5;
        break;
      case SpriteText.Anchor_Pos.Lower_Left:
        num3 = num5;
        break;
      case SpriteText.Anchor_Pos.Lower_Center:
        num4 = num6;
        break;
      case SpriteText.Anchor_Pos.Lower_Right:
        num3 = -num5;
        break;
    }
    Vector3 vector3_1;
    // ISSUE: explicit reference operation
    ((Vector3) @vector3_1).\u002Ector((float) position.x - num5 + num3, (float) position.y + num6 + num4, (float) position.z);
    Vector3 vector3_2;
    // ISSUE: explicit reference operation
    ((Vector3) @vector3_2).\u002Ector((float) position.x + num5 + num3, (float) position.y - num6 + num4, (float) position.z);
    float num7 = 0.0f;
    float num8 = 0.0f;
    float num9 = 0.0f;
    float num10 = 0.0f;
    if (clipX)
    {
      if (vector3_1.x < topLeft.x)
        num7 = (float) (vector3_1.x - topLeft.x);
      else if (vector3_2.x > bottomRight.x)
        num8 = (float) (vector3_2.x - bottomRight.x);
    }
    if (clipY)
    {
      if (vector3_1.y > topLeft.y)
        num9 = (float) (vector3_1.y - topLeft.y);
      else if (vector3_2.y < bottomRight.y)
        num10 = (float) (vector3_2.y - bottomRight.y);
    }
    if ((double) num7 != 0.0 || (double) num8 != 0.0 || ((double) num9 != 0.0 || (double) num10 != 0.0))
    {
      float num11 = (float) vector3_1.x - num7;
      float num12 = (float) vector3_2.x - num8;
      float num13 = (float) vector3_1.y - num9;
      float num14 = (float) vector3_2.y - num10;
      float num15 = Mathf.Clamp(num11, (float) topLeft.x, (float) bottomRight.x);
      float num16 = Mathf.Clamp(num12, (float) topLeft.x, (float) bottomRight.x);
      float num17 = Mathf.Clamp(num13, (float) bottomRight.y, (float) topLeft.y);
      float num18 = Mathf.Clamp(num14, (float) bottomRight.y, (float) topLeft.y);
      Rect3D clippingRect = spriteText.ClippingRect;
      if ((double) num15 != clippingRect.topLeft.x || (double) num17 != clippingRect.topLeft.y || ((double) num16 != clippingRect.topRight.x || (double) num17 != clippingRect.topRight.y) || ((double) num15 != clippingRect.bottomLeft.x || (double) num18 != clippingRect.bottomLeft.y))
      {
        spriteText.ClippingRect = new Rect3D(new Vector3(num15, num17, (float) position.z), new Vector3(num16, num17, (float) position.z), new Vector3(num15, num18, (float) position.z));
      }
      else
      {
        if (spriteText.Clipped)
          return;
        spriteText.Clipped = true;
      }
    }
    else
    {
      if (!spriteText.Clipped)
        return;
      spriteText.Clipped = false;
    }
  }
}
