예제 #1
0
        public static double GetPixelPerUnit(RulerUnit unit)
        {
            double result = 1;

            switch (unit)
            {
            case RulerUnit.Pixel:
                result = 1;
                break;

            case RulerUnit.Inch:
                result = 96;
                break;

            case RulerUnit.Foot:
                result = 1152;
                break;

            case RulerUnit.Millimeter:
                result = 3.7795;
                break;

            case RulerUnit.Centimeter:
                result = 37.795;
                break;
            }

            return(result);
        }
예제 #2
0
        public static string Abbreviate(RulerUnit unit)
        {
            switch (unit)
            {
            case RulerUnit.Pixel:
                return("px");

            case RulerUnit.Display:
                return("ds");

            case RulerUnit.Document:
                return("dc");

            case RulerUnit.Inch:
                return("in");

            case RulerUnit.Millimeter:
                return("mm");

            case RulerUnit.Point:
                return("pt");

            default:
                return("");
            }
        }
예제 #3
0
    public static string Format(Type type, RulerUnit unit, float value)
    {
        // Break the Value Apart into Measures
        var splitValues = Split(type, unit, value);

        return(Format(type, unit, splitValues));
    }
예제 #4
0
    /// <summary>
    /// Formats splitValues for Calculator View Output.  E.g.   4.5ft   becomes   4ft 5in
    /// @TODO - Metric type not implemented
    /// </summary>
    public static string FormatCalculator(Type type, RulerUnit unit, float value)
    {
        if (value == 0f)
        {
            return("0");
        }

        bool isNegative = false;

        if (value < 0f)
        {
            value     *= -1f;
            isNegative = true;
        }
        // Break the Value Apart into Measures
        var splitValues = Split(type, unit, value);

        // Build the String
        string txt = "";

        switch (type)
        {
        case Type.Metric:

            // @TODO - Implement
            break;

        case Type.Standard:

            if (splitValues[2] > 0f)
            {
                txt = splitValues[2] + "ft";
            }
            if (splitValues[1] > 0f && splitValues[0] > 0f)
            {
                // fraction
                txt += splitValues[1] + "&" + new Rational((long)splitValues[0], 16).ToString() + "in";
            }
            else if (splitValues[1] > 0f)
            {
                txt += splitValues[1] + "in";
            }
            else if (splitValues[0] > 0f)
            {
                txt += new Rational((long)splitValues[0], 16).ToString() + "in";
            }

            break;

        default:
            throw new ArgumentException("Units: FormatCalculator() Invalid type argument.");
        }
        if (isNegative)
        {
            return("-" + txt);
        }
        return(txt);
    }
예제 #5
0
    public static string RulerName(RulerUnit rulerUnit)
    {
        int unit_i = (int)rulerUnit;

        if (unit_i < k_DefaultRulerNames.Length)
        {
            return(k_DefaultRulerNames[unit_i]);
        }
        return(null);
    }
예제 #6
0
    public static string Format(Type type, RulerUnit highUnit, float[] splitValues)
    {
        // Build the String
        string txt = "";

        switch (type)
        {
        case Type.Metric:
            switch (highUnit)
            {
            case RulerUnit.Millimeters:
                txt = splitValues[0] + "mm";
                break;

            case RulerUnit.Centimeters:
                txt  = splitValues[1] + "cm - ";
                txt += splitValues[0] + "mm";
                break;

            case RulerUnit.Meters:
                txt  = splitValues[2] + "m ";
                txt += splitValues[1] + "cm - ";
                txt += splitValues[0] + "mm";
                break;
            }
            break;

        case Type.Standard:
            switch (highUnit)
            {
            case RulerUnit.Sixteenths:
                txt = new Rational((long)splitValues[0], (long)16).ToString() + "\"";
                break;

            case RulerUnit.Inches:
                txt  = splitValues[1] + " - ";
                txt += new Rational((long)splitValues[0], (long)16).ToString() + "\"";
                break;

            case RulerUnit.Feet:
                txt  = splitValues[2] + "' ";
                txt += splitValues[1] + " - ";
                txt += new Rational((long)splitValues[0], (long)16).ToString() + "\"";
                break;
            }
            break;

        default:
            throw new ArgumentException("Units: Format() Invalid type argument.");
        }
        return(txt);
    }
예제 #7
0
    /// <summary>
    /// アイテム(目盛)更新処理
    /// </summary>
    /// <param name="itemCount">対象アイテム</param>
    /// <param name="obj">対象アイテムのオブジェクト</param>
    public void OnUpdateItem(int itemCount, GameObject obj)
    {
        if (itemCount < 0 || itemCount >= itemNumMax)
        {
            obj.SetActive(false);
        }
        else
        {
            obj.SetActive(true);
            RulerUnit ru = obj.GetComponent <RulerUnit>();

            ru.ID = itemCount;

            if (itemCount < paddingItemNum || itemCount > (itemNumMax - paddingItemNum))
            {
                // 両端のパディング
                ru.SetUnit(RulerUnit.scaleType.None, "");
            }
            else if (isTimeMode &&
                     ((itemCount - paddingItemNum - scaleBoldStartNum) % scaleTypeTimeStepNum == 0))
            {
                // 大目盛り(時間)
                decimal  countnum  = rulerMinValue + ((itemCount - paddingItemNum) * rulerStepValue);
                TimeSpan timespan  = new TimeSpan(0, (int)countnum, 0);
                string   valuetext = timespan.Hours.ToString("00") + ":" + timespan.Minutes.ToString("00");
                ru.SetUnit(RulerUnit.scaleType.Bold, valuetext, onEnterCenterMark);
            }
            else if (isTimeMode)
            {
                // 小目盛り(時間)
                ru.SetUnit(RulerUnit.scaleType.Normal, "", onEnterCenterMark);
            }
            else if ((itemCount - paddingItemNum - scaleBoldStartNum) % scaleTypeBoldStepNum == 0)
            {
                // 大目盛り
                string valuetext = (rulerMinValue + ((itemCount - paddingItemNum) * rulerStepValue)).ToString("0");
                ru.SetUnit(RulerUnit.scaleType.Bold, valuetext, onEnterCenterMark);
            }
            else if ((itemCount - paddingItemNum - scaleBoldStartNum) % scaleTypeMiddleStepNum == 0)
            {
                // 中目盛り
                ru.SetUnit(RulerUnit.scaleType.Middle, "", onEnterCenterMark);
            }
            else
            {
                // 小目盛り
                ru.SetUnit(RulerUnit.scaleType.Normal, "", onEnterCenterMark);
            }
        }
    }
예제 #8
0
 //Constructors
 public Ruler()
 {
     InitializeComponent();
     Component.Instance.GetLicense(typeof(Ruler), this);
     mFont            = new Font("Microsoft Sans Serif", 7.0F);
     mUnit            = RulerUnit.Pixel;
     mMajor           = 100;
     mMinor           = 10;
     mMid             = 50;
     mStart           = 0;
     mZoom            = 100;
     mScaleFactor     = 1;
     mUnitScaleFactor = new PointF(1, 1);
     mOrientation     = RulerOrientation.Top;
     mBorderStyle     = RulerBorderStyle.Edge;
     mDrawGuides      = true;
     mGradientColor   = BackColor;
 }
예제 #9
0
		//Constructors
		public Ruler()
		{
			InitializeComponent();
			Component.Instance.GetLicense(typeof(Ruler), this);
			mFont = new Font("Microsoft Sans Serif",7.0F);
			mUnit = RulerUnit.Pixel;
			mMajor = 100;
			mMinor = 10;
			mMid = 50;
			mStart = 0;
			mZoom = 100;
			mScaleFactor = 1;
			mUnitScaleFactor = new PointF(1,1);
			mOrientation = RulerOrientation.Top;
			mBorderStyle = RulerBorderStyle.Edge;
			mDrawGuides = true;
			mGradientColor = BackColor;
		}
예제 #10
0
        //Constructors
        public Ruler()
        {
            InitializeComponent();

            _font            = new Font("Microsoft Sans Serif", 7.0F);
            _unit            = RulerUnit.Pixel;
            _major           = 100;
            _minor           = 10;
            _mid             = 50;
            _start           = 0;
            _zoom            = 100;
            _scaleFactor     = 1;
            _unitScaleFactor = new PointF(1, 1);
            _orientation     = RulerOrientation.Top;
            _borderStyle     = RulerBorderStyle.Edge;
            _drawGuides      = true;
            _gradientColor   = BackColor;
        }
예제 #11
0
 private GraphicsUnit ConvertUnit(RulerUnit rulerUnit)
 {
     return((GraphicsUnit)Enum.Parse(typeof(GraphicsUnit), rulerUnit.ToString()));
 }
예제 #12
0
		public static string Abbreviate(RulerUnit unit)
		{
			switch (unit)
			{
				case RulerUnit.Pixel:
					return "px";
				case RulerUnit.Display:
					return "ds";
				case RulerUnit.Document:
					return "dc";
				case RulerUnit.Inch:
					return "in";
				case RulerUnit.Millimeter:
					return "mm";
				case RulerUnit.Point:
					return "pt";
				default:
					return "";
			}
		}
예제 #13
0
		private GraphicsUnit ConvertUnit(RulerUnit rulerUnit)
		{
			return (GraphicsUnit) Enum.Parse(typeof(GraphicsUnit),rulerUnit.ToString());
		}
예제 #14
0
    /// <summary>
    /// Convert between Units of the same Type (e.g. Inches to Feet)
    /// </summary>
    public static float Convert(Type type, RulerUnit fromUnit, RulerUnit toUnit, float value)
    {
        // @TODO - Find a Cleaner Approach
        int fromUnit_i = (int)fromUnit;
        int toUnit_i   = (int)toUnit;

        if (type == Type.Metric)
        {
            if (fromUnit_i > 2 || toUnit_i > 2)
            {
                Debug.LogError("Units: Convert() Cannot Convert between different Types.");
                return(0f);
            }
            switch (fromUnit_i)
            {
            case 0:
                if (toUnit_i == 1)
                {
                    return(value * k_MToCm);
                }
                else if (toUnit_i == 2)
                {
                    return(value * k_MToMm);
                }
                break;

            case 1:
                if (toUnit_i == 0)
                {
                    return(value * k_CmToM);
                }
                else if (toUnit_i == 2)
                {
                    return(value * k_CmToMm);
                }
                break;

            case 2:
                if (toUnit_i == 0)
                {
                    return(value * k_MmToM);
                }
                else if (toUnit_i == 1)
                {
                    return(value * k_MmToCm);
                }
                break;
            }
        }
        else
        {
            if (fromUnit_i < 3 || toUnit_i < 3)
            {
                Debug.LogError("Units: Convert() Cannot Convert between different Types.");
                return(0f);
            }
            switch (fromUnit_i)
            {
            case 3:
                if (toUnit_i == 4)
                {
                    return(value * k_FtToIn);
                }
                else if (toUnit_i == 5)
                {
                    return(value * k_FtToSixteenths);
                }
                break;

            case 4:
                if (toUnit_i == 3)
                {
                    return(value * k_InToFt);
                }
                else if (toUnit_i == 5)
                {
                    return(value * k_InToSixteenths);
                }
                break;

            case 5:
                if (toUnit_i == 3)
                {
                    return(value * k_SixteenthsToFt);
                }
                else if (toUnit_i == 4)
                {
                    return(value * k_SixteenthsToIn);
                }
                break;
            }
        }
        return(value);
    }
예제 #15
0
    /// <summary>
    /// 'Type' is Metric or Standard. 'RulerUnit' is the unit of the passed value (e.g. Feet, Inches, Centimeters...)
    /// </summary>
    public static float[] Split(Type type, RulerUnit unit, float value)
    {
        float[] splitValues;
        float   iValue = value; // Intermediate

        switch (type)
        {
        case Type.Metric:
            switch (unit)
            {
            case RulerUnit.Meters:
                splitValues    = new float[3];
                splitValues[2] = Mathf.Floor(iValue);
                iValue        -= splitValues[2];
                splitValues[1] = Mathf.Floor(iValue * k_MToCm);
                iValue        -= splitValues[1] * k_CmToM;
                splitValues[0] = Mathf.Round(iValue * k_MToMm);
                break;

            case RulerUnit.Centimeters:
                splitValues    = new float[2];
                splitValues[1] = Mathf.Floor(iValue);
                iValue        -= splitValues[1];
                splitValues[0] = Mathf.Round(iValue * k_CmToMm);
                break;

            case RulerUnit.Millimeters:
                splitValues    = new float[1];
                splitValues[0] = Mathf.Round(iValue);
                break;

            default:
                throw new ArgumentException("Units: Split() Invalid unit argument.");
            }
            break;

        case Type.Standard:
            switch (unit)
            {
            case RulerUnit.Feet:
                splitValues    = new float[3];
                splitValues[2] = Mathf.Floor(iValue);
                iValue        -= splitValues[2];                // Subtract Feet
                splitValues[1] = Mathf.Floor(iValue * k_FtToIn);
                iValue        -= splitValues[1] * k_InToFt;     // Subtract Inches
                splitValues[0] = Mathf.Round(iValue * k_FtToSixteenths);
                // Carry (i.e. 16/16 sixteenths)
                if (splitValues[0] == 16f)
                {
                    splitValues[1] += 1f;
                    splitValues[0]  = 0f;
                }
                break;

            case RulerUnit.Inches:
                splitValues    = new float[2];
                splitValues[1] = Mathf.Floor(iValue);
                iValue        -= splitValues[1];
                splitValues[0] = Mathf.Round(iValue * k_InToSixteenths);
                // Carry (i.e. 16/16 sixteenths)
                if (splitValues[0] == 16f)
                {
                    splitValues[1] += 1f;
                    splitValues[0]  = 0f;
                }
                break;

            case RulerUnit.Sixteenths:
                splitValues    = new float[1];
                splitValues[0] = Mathf.Round(iValue);
                break;

            default:
                throw new ArgumentException("Units: Split() Invalid unit argument.");
            }
            break;

        default:
            throw new ArgumentException("Units: Split() Invalid type argument.");
        }

        return(splitValues);
    }