private void ResetYieldIfEmpty()
 {
     if (listBoxItemIngredients.Items.Count > 1)
     {
         return;
     }
     checkBoxEnabled.SelectionChanged -= checkBoxEnabled_SelectionChanged;
     checkBoxEnabled.IsSelected        = false;
     checkBoxEnabled.SelectionChanged += checkBoxEnabled_SelectionChanged;
     buttonYield.Text         = "0";
     labelUnits.Content       = MeasurementUnit.ToString() + Types.Strings.S;
     _extendedIngredientYield = null;
 }
Esempio n. 2
0
 private void PopulateUnitsButtonDropDown()
 {
     foreach (MeasurementUnit unit in Enum.GetValues(typeof(MeasurementUnit)))
     {
         string            str          = "MeasurementUnit." + unit.ToString();
         string            abbreviation = PdnResources.GetString(str + ".Abbreviation").Trim(unitAbreviationTrimChars);
         string            description  = PdnResources.GetString(str + ".Plural");
         ToolStripMenuItem item         = new ToolStripMenuItem {
             Text = description,
             Tag  = new LocalizedMeasurementUnit(unit, description, abbreviation)
         };
         this.unitsButton.DropDownItems.Add(item);
     }
 }
 public void SetMeasurementUnit(MeasurementUnit unit, bool update)
 {
     if (update && (MeasurementUnit != unit) && ExtendedIngredientYield.HasValue &&
         (ExtendedIngredientYield.Value > 0) &&
         (unit != MeasurementUnit.Unit) && (unit != MeasurementUnit.None) &&
         ((unit.IsVolume() && MeasurementUnit.IsVolume()) || (unit.IsWeight() && MeasurementUnit.IsWeight())))
     {
         ExtendedIngredientYield = UnitConversion.Convert(ExtendedIngredientYield.Value,
                                                          MeasurementUnit, unit);
         buttonYield.Text = (ExtendedIngredientYield.Value.ToString(CultureInfo.InvariantCulture));
     }
     MeasurementUnit    = unit;
     labelUnits.Content = MeasurementUnit.ToString() + Types.Strings.S;
 }
Esempio n. 4
0
        public void SaveToFile(IniFile ini)
        {
            if (ini == null)
            {
                throw new ArgumentNullException("ini");
            }

            ini.WriteBool("Common", "HideClosedTanks", fHideClosedTanks);
            ini.WriteBool("Common", "ExitOnClose", fExitOnClose);
            ini.WriteInteger("Common", "InterfaceLang", fInterfaceLang);
            ini.WriteBool("Common", "HideAtStartup", fHideAtStartup);
            ini.WriteInteger("Common", "NotificationInterval", fNotificationInterval);
            ini.WriteBool("Common", "HideLosses", fHideLosses);

            ini.WriteString("Data", "LengthUoM", fLengthUoM.ToString());
            ini.WriteString("Data", "VolumeUoM", fVolumeUoM.ToString());
            ini.WriteString("Data", "MassUoM", fMassUoM.ToString());
            ini.WriteString("Data", "TemperatureUoM", fTemperatureUoM.ToString());

            ini.WriteBool("DAS", "ChannelEnabled", fChannelEnabled);
            ini.WriteString("DAS", "ChannelName", fChannelName);
            ini.WriteString("DAS", "ChannelParameters", fChannelParameters);
        }
Esempio n. 5
0
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            if (points.Length >= 4)
            {
                PdnGraphicsPath path = new PdnGraphicsPath();

                switch (this.curveType)
                {
                default:
                case CurveType.Spline:
                    path.AddCurve(points);
                    break;

                case CurveType.Bezier:
                    path.AddBezier(points[0], points[1], points[2], points[3]);
                    break;
                }

                path.Flatten(Utility.IdentityMatrix, flattenConstant);
                return(path);
            }
            else //if (points.Length <= 2)
            {
                PointF a = points[0];
                PointF b = points[points.Length - 1];

                if (0 != (ModifierKeys & Keys.Shift) && a != b)
                {
                    ConstrainPoints(ref a, ref b);
                }

                double          angle                = -180.0 * Math.Atan2(b.Y - a.Y, b.X - a.X) / Math.PI;
                MeasurementUnit units                = AppWorkspace.Units;
                double          offsetXPhysical      = Document.PixelToPhysicalX(b.X - a.X, units);
                double          offsetYPhysical      = Document.PixelToPhysicalY(b.Y - a.Y, units);
                double          offsetLengthPhysical = Math.Sqrt(offsetXPhysical * offsetXPhysical + offsetYPhysical * offsetYPhysical);

                string numberFormat;
                string unitsAbbreviation;

                if (units != MeasurementUnit.Pixel)
                {
                    string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                    unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                    numberFormat      = "F2";
                }
                else
                {
                    unitsAbbreviation = string.Empty;
                    numberFormat      = "F0";
                }

                string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

                string statusText = string.Format(
                    this.statusTextFormat,
                    offsetXPhysical.ToString(numberFormat),
                    unitsAbbreviation,
                    offsetYPhysical.ToString(numberFormat),
                    unitsAbbreviation,
                    offsetLengthPhysical.ToString("F2"),
                    unitsString,
                    angle.ToString("F2"));

                SetStatus(this.lineToolIcon, statusText);

                if (a == b)
                {
                    return(null);
                }
                else
                {
                    PdnGraphicsPath path   = new PdnGraphicsPath();
                    PointF[]        spline = LineToSpline(a, b, controlPointCount);
                    path.AddCurve(spline);
                    path.Flatten(Utility.IdentityMatrix, flattenConstant);
                    return(path);
                }
            }
        }
Esempio n. 6
0
        private void RenderGradient()
        {
            ColorBgra startColor = AppEnvironment.PrimaryColor;
            ColorBgra endColor   = AppEnvironment.SecondaryColor;

            if (this.shouldSwapColors)
            {
                if (AppEnvironment.GradientInfo.AlphaOnly)
                {
                    // In transparency mode, the color values don't matter. We just need to reverse
                    // and invert the alpha values.
                    byte startAlpha = startColor.A;
                    startColor.A = (byte)(255 - endColor.A);
                    endColor.A   = (byte)(255 - startAlpha);
                }
                else
                {
                    Utility.Swap(ref startColor, ref endColor);
                }
            }

            PointF startPointF = this.startPoint;
            PointF endPointF   = this.endPoint;

            if (this.shouldConstrain)
            {
                if (this.mouseNub == this.startNub)
                {
                    ConstrainPoints(endPointF, ref startPointF);
                }
                else
                {
                    ConstrainPoints(startPointF, ref endPointF);
                }
            }

            RestoreSavedRegion();

            Surface   surface    = ((BitmapLayer)DocumentWorkspace.ActiveLayer).Surface;
            PdnRegion clipRegion = DocumentWorkspace.Selection.CreateRegion();

            SaveRegion(clipRegion, clipRegion.GetBoundsInt());

            RenderGradient(surface, clipRegion, AppEnvironment.GetCompositingMode(), startPointF, startColor, endPointF, endColor);

            using (PdnRegion simplified = Utility.SimplifyAndInflateRegion(clipRegion, Utility.DefaultSimplificationFactor, 0))
            {
                DocumentWorkspace.ActiveLayer.Invalidate(simplified);
            }

            clipRegion.Dispose();

            // Set up status bar text
            double          angle                = -180.0 * Math.Atan2(endPointF.Y - startPointF.Y, endPointF.X - startPointF.X) / Math.PI;
            MeasurementUnit units                = AppWorkspace.Units;
            double          offsetXPhysical      = Document.PixelToPhysicalX(endPointF.X - startPointF.X, units);
            double          offsetYPhysical      = Document.PixelToPhysicalY(endPointF.Y - startPointF.Y, units);
            double          offsetLengthPhysical = Math.Sqrt(offsetXPhysical * offsetXPhysical + offsetYPhysical * offsetYPhysical);

            string numberFormat;
            string unitsAbbreviation;

            if (units != MeasurementUnit.Pixel)
            {
                string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                numberFormat      = "F2";
            }
            else
            {
                unitsAbbreviation = string.Empty;
                numberFormat      = "F0";
            }

            string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

            string statusText = string.Format(
                this.helpTextWhileAdjustingFormat,
                offsetXPhysical.ToString(numberFormat),
                unitsAbbreviation,
                offsetYPhysical.ToString(numberFormat),
                unitsAbbreviation,
                offsetLengthPhysical.ToString("F2"),
                unitsString,
                angle.ToString("F2"));

            SetStatus(this.toolIcon, statusText);

            // Make sure everything is on screen.
            Update();
        }
Esempio n. 7
0
        protected override void OnGetStatus(out ImageResource image, out string text)
        {
            string            str;
            PointDouble       startPoint;
            PointDouble       endPoint;
            double            length;
            double            num4;
            string            str2;
            string            str3;
            ShapesToolChanges changes = base.Changes;

            switch (this.State)
            {
            case TransactedToolState.Drawing:
                if (changes == null)
                {
                    break;
                }
                goto Label_003A;

            case TransactedToolState.Dirty:
            case TransactedToolState.Editing:
                goto Label_003A;
            }
            base.OnGetStatus(out image, out text);
            return;

Label_003A:
            if (this.State == TransactedToolState.Dirty)
            {
                str = PdnResources.GetString("LineTool.StatusText.NotAdjusting.Format");
            }
            else
            {
                str = PdnResources.GetString("LineTool.StatusText.Format");
            }
            if (changes.ShapeRenderData.OutlineDraw.IsEmpty)
            {
                startPoint = changes.StartPoint;
                endPoint   = changes.EndPoint;
                length     = 0.0;
                num4       = 0.0;
            }
            else
            {
                PointAndTangentDouble pointAtLength = changes.ShapeRenderData.OutlineDraw.GetPointAtLength(0.0);
                PointAndTangentDouble num12         = changes.ShapeRenderData.OutlineDraw.GetPointAtLength(double.PositiveInfinity);
                startPoint = pointAtLength.Point;
                endPoint   = num12.Point;
                length     = changes.ShapeRenderData.OutlineDraw.GetLength();
                num4       = (-180.0 * Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X)) / 3.1415926535897931;
            }
            MeasurementUnit units = base.AppWorkspace.Units;
            PointDouble     num5  = new PointDouble(base.Document.PixelToPhysicalX(startPoint.X, units), base.Document.PixelToPhysicalY(startPoint.Y, units));
            PointDouble     num6  = new PointDouble(base.Document.PixelToPhysicalX(endPoint.X, units), base.Document.PixelToPhysicalY(endPoint.Y, units));
            VectorDouble    num7  = (VectorDouble)(num6 - num5);
            double          num8  = base.Document.PixelToPhysicalX(length, units);
            double          num9  = base.Document.PixelToPhysicalY(length, units);
            double          num10 = (num8 + num9) / 2.0;

            if (units != MeasurementUnit.Pixel)
            {
                str3 = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Abbreviation");
                str2 = "F2";
            }
            else
            {
                str3 = string.Empty;
                str2 = "F0";
            }
            string str4 = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");
            string str5 = string.Format(str, new object[] { num7.X.ToString(str2), str3, num7.Y.ToString(str2), str3, num10.ToString("F2"), str4, num4.ToString("F2") });

            image = base.Image;
            text  = str5;
        }
Esempio n. 8
0
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            PointF     a = points[0];
            PointF     b = points[points.Length - 1];
            RectangleF rect;

            if ((ModifierKeys & Keys.Shift) != 0)
            {
                PointF dir    = new PointF(b.X - a.X, b.Y - a.Y);
                float  len    = (float)Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y);
                PointF center = new PointF((a.X + b.X) / 2.0f, (a.Y + b.Y) / 2.0f);
                float  radius = len / 2.0f;
                rect = Utility.RectangleFromCenter(center, radius);
            }
            else
            {
                rect = Utility.PointsToRectangle(a, b);
            }

            if (rect.Width == 0 || rect.Height == 0)
            {
                return(null);
            }

            PdnGraphicsPath path = new PdnGraphicsPath();

            path.AddEllipse(rect);
            path.Flatten(Utility.IdentityMatrix, 0.10f);

            MeasurementUnit units = AppWorkspace.Units;

            double widthPhysical  = Math.Abs(Document.PixelToPhysicalX(rect.Width, units));
            double heightPhysical = Math.Abs(Document.PixelToPhysicalY(rect.Height, units));
            double areaPhysical   = Math.PI * (widthPhysical / 2.0) * (heightPhysical / 2.0);

            string numberFormat;
            string unitsAbbreviation;

            if (units != MeasurementUnit.Pixel)
            {
                string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                numberFormat      = "F2";
            }
            else
            {
                unitsAbbreviation = string.Empty;
                numberFormat      = "F0";
            }

            string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

            string statusText = string.Format(
                this.statusTextFormat,
                widthPhysical.ToString(numberFormat),
                unitsAbbreviation,
                heightPhysical.ToString(numberFormat),
                unitsAbbreviation,
                areaPhysical.ToString(numberFormat),
                unitsString);

            this.SetStatus(this.ellipseToolIcon, statusText);
            return(path);
        }
        protected override PdnGraphicsPath CreateShapePath(PointF[] points)
        {
            PointF     a = points[0];
            PointF     b = points[points.Length - 1];
            RectangleF rect;
            float      radius = 10;

            if ((ModifierKeys & Keys.Shift) != 0)
            {
                rect = Utility.PointsToConstrainedRectangle(a, b);
            }
            else
            {
                rect = Utility.PointsToRectangle(a, b);
            }

            PdnGraphicsPath path = this.GetRoundedRect(rect, radius);

            path.Flatten();

            if (path.PathPoints[0] != path.PathPoints[path.PathPoints.Length - 1])
            {
                path.AddLine(path.PathPoints[0], path.PathPoints[path.PathPoints.Length - 1]);
                path.CloseFigure();
            }

            MeasurementUnit units          = AppWorkspace.Units;
            double          widthPhysical  = Math.Abs(Document.PixelToPhysicalX(rect.Width, units));
            double          heightPhysical = Math.Abs(Document.PixelToPhysicalY(rect.Height, units));
            double          areaPhysical   = widthPhysical * heightPhysical;

            string numberFormat;
            string unitsAbbreviation;

            if (units != MeasurementUnit.Pixel)
            {
                string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                numberFormat      = "F2";
            }
            else
            {
                unitsAbbreviation = string.Empty;
                numberFormat      = "F0";
            }

            string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

            string statusText = string.Format(
                this.statusTextFormat,
                widthPhysical.ToString(numberFormat),
                unitsAbbreviation,
                heightPhysical.ToString(numberFormat),
                unitsAbbreviation,
                areaPhysical.ToString(numberFormat),
                unitsString);

            this.SetStatus(this.roundedRectangleToolIcon, statusText);

            return(path);
        }
Esempio n. 10
0
        public static double Convert(double amount,
                                     MeasurementUnit sourceUnit, MeasurementUnit targetUnit)
        {
            if (sourceUnit == targetUnit)
            {
                return(amount);
            }
            if (sourceUnit.IsVolume() && !targetUnit.IsVolume())
            {
                throw new InvalidOperationException("Trying to convent from a volume to a weight");
            }
            if (sourceUnit.IsWeight() && !targetUnit.IsWeight())
            {
                throw new InvalidOperationException("Trying to convent from a weight to a volume");
            }
            // Cups to X
            if (sourceUnit == MeasurementUnit.Cup)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 236.588237);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 23.6588236);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount * 0.236588236);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 240);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 48);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount * 16);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount * 8);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount / 2);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount / 4);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount / 16);
                }
            }

            // Pints to X
            else if (sourceUnit == MeasurementUnit.Pint)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 473.176473);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 47.3176473);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount * 0.473176473);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 480);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 96);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount * 32);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount * 16);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount * 2);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount / 2);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount / 8);
                }
            }

            // Quarts to X
            else if (sourceUnit == MeasurementUnit.Quart)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 946.352946);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 94.6352946);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount * 0.946362946);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 960);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 192);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount * 64);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount * 32);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount * 4);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount * 2);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount / 4);
                }
            }

            // Gallons to X
            else if (sourceUnit == MeasurementUnit.Gallon)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 3785.41178);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 378.541178);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount * 3.78541178);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 3840);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 768);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount * 256);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount * 128);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount * 16);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount * 8);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount * 4);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount);
                }
            }

            // Mililiters to X
            else if (sourceUnit == MeasurementUnit.Milliliter)
            {
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount / 10);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount / 1000);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 1.01442068);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 0.202884136);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount * 0.0676280454);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount * 0.0338140227);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount * 0.00422675284);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount * 0.00211337642);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount * 0.00105668821);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount * 0.000264172052);
                }
            }

            // Centiliters to X
            else if (sourceUnit == MeasurementUnit.Centiliter)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 10);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount / 100);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 10.1442068);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 2.02884136);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount * 0.676280454);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount * 0.338140227);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount * 0.0422675284);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount * 0.0211337642);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount * 0.0105668821);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount * 0.00264172052);
                }
            }

            // Liters to X
            else if (sourceUnit == MeasurementUnit.Liter)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 1000);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 100);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 1014.42068);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 202.884136);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount * 67.6280454);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount * 33.8140227);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount * 4.22675284);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount * 2.11337642);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount * 1.05668821);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount * 0.264172052);
                }
            }

            // Pinch to X
            else if (sourceUnit == MeasurementUnit.Pinch)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 24.64460795);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 2.464460795);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount * 0.02464460795);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount / 5);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount / 15);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount / 30);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount / 240);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount / 480);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount / 960);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount / 3840);
                }
            }

            // Teaspoon to X
            else if (sourceUnit == MeasurementUnit.Teaspoon)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 4.92892159);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 0.492892159);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount * 0.00492892159);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 15);
                }
                if (targetUnit == MeasurementUnit.Tablespoon)
                {
                    return(amount / 3);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount / 6);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount / 48);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount / 96);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount / 192);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount / 768);
                }
            }

            // Tablespoon to X
            else if (sourceUnit == MeasurementUnit.Tablespoon)
            {
                if (targetUnit == MeasurementUnit.Milliliter)
                {
                    return(amount * 14.7867648);
                }
                if (targetUnit == MeasurementUnit.Centiliter)
                {
                    return(amount * 1.47867648);
                }
                if (targetUnit == MeasurementUnit.Liter)
                {
                    return(amount * 0.147867648);
                }
                if (targetUnit == MeasurementUnit.Pinch)
                {
                    return(amount * 15);
                }
                if (targetUnit == MeasurementUnit.Teaspoon)
                {
                    return(amount * 3);
                }
                if (targetUnit == MeasurementUnit.FluidOunce)
                {
                    return(amount / 2);
                }
                if (targetUnit == MeasurementUnit.Cup)
                {
                    return(amount / 16);
                }
                if (targetUnit == MeasurementUnit.Pint)
                {
                    return(amount / 32);
                }
                if (targetUnit == MeasurementUnit.Quart)
                {
                    return(amount / 64);
                }
                if (targetUnit == MeasurementUnit.Gallon)
                {
                    return(amount / 256);
                }
            }

            else if (sourceUnit == MeasurementUnit.Ounce)
            {
                if (targetUnit == MeasurementUnit.Milligram)
                {
                    return(amount * 0.0283495231);
                }
                if (targetUnit == MeasurementUnit.Gram)
                {
                    return(amount * 28.3495231);
                }
                if (targetUnit == MeasurementUnit.Kilogram)
                {
                    return(amount * 28349.5231);
                }
                if (targetUnit == MeasurementUnit.Pound)
                {
                    return(amount / 16);
                }
            }

            else if (sourceUnit == MeasurementUnit.Pound)
            {
                if (targetUnit == MeasurementUnit.Milligram)
                {
                    return(amount * 453592.37);
                }
                if (targetUnit == MeasurementUnit.Gram)
                {
                    return(amount * 453.59237);
                }
                if (targetUnit == MeasurementUnit.Kilogram)
                {
                    return(amount * 0.45359237);
                }
                if (targetUnit == MeasurementUnit.Ounce)
                {
                    return(amount * 16);
                }
            }

            else if (sourceUnit == MeasurementUnit.Milligram)
            {
                if (targetUnit == MeasurementUnit.Gram)
                {
                    return(amount / 1000);
                }
                if (targetUnit == MeasurementUnit.Kilogram)
                {
                    return(amount / 1000000);
                }
                if (targetUnit == MeasurementUnit.Ounce)
                {
                    return(amount / 28349.5231);
                }
                if (targetUnit == MeasurementUnit.Pound)
                {
                    return(amount / 453592.37);
                }
            }

            else if (sourceUnit == MeasurementUnit.Gram)
            {
                if (targetUnit == MeasurementUnit.Milligram)
                {
                    return(amount * 1000);
                }
                if (targetUnit == MeasurementUnit.Kilogram)
                {
                    return(amount / 1000);
                }
                if (targetUnit == MeasurementUnit.Ounce)
                {
                    return(amount / 28.3495231);
                }
                if (targetUnit == MeasurementUnit.Pound)
                {
                    return(amount / 453.59237);
                }
            }

            else if (sourceUnit == MeasurementUnit.Kilogram)
            {
                if (targetUnit == MeasurementUnit.Milligram)
                {
                    return(amount * 1000000);
                }
                if (targetUnit == MeasurementUnit.Gram)
                {
                    return(amount * 1000);
                }
                if (targetUnit == MeasurementUnit.Ounce)
                {
                    return(amount / 0.0283495231);
                }
                if (targetUnit == MeasurementUnit.Pound)
                {
                    return(amount / 0.45359237);
                }
            }

            throw new NotImplementedException("Conversion not implemented: " + sourceUnit.ToString() + " to " + targetUnit.ToString());
        }
        internal override void Render(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            try
            {
                MapCore mapCore = GetMapCore();
                if (mapCore == null)
                {
                    return;
                }
                g.AntiAliasing = AntiAliasing.None;
                base.Render(g);
                float      num = 4.5f;
                RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
                absoluteRectangle.Inflate(0f - num, 0f - num);
                if (absoluteRectangle.Width < 3f || absoluteRectangle.Height < 3f)
                {
                    return;
                }
                float           num2             = 0f;
                float           num3             = 0f;
                string          arg              = "0";
                string          arg2             = "0";
                MeasurementUnit measurementUnit  = MeasurementUnit.km;
                MeasurementUnit measurementUnit2 = MeasurementUnit.mi;
                float           num4             = absoluteRectangle.Width - 6f;
                float           kilometers       = (float)mapCore.PixelsToKilometers(num4);
                float           miles            = kilometers * KilometersToMiles;
                measurementUnit = AdjustMetricUnit(ref kilometers);
                float num5 = FloorDistance(kilometers);
                float num6 = num5 / kilometers;
                measurementUnit2 = AdjustImperialUnit(ref miles);
                float num7 = FloorDistance(miles);
                float num8 = num7 / miles;
                if (num5 >= 1f && num7 >= 1f)
                {
                    num2 = num4 * num6;
                    num3 = num4 * num8;
                    if (GetMapCore().MapControl.FormatNumberHandler != null)
                    {
                        arg  = GetMapCore().MapControl.FormatNumberHandler(GetMapCore().MapControl, num5, "G");
                        arg2 = GetMapCore().MapControl.FormatNumberHandler(GetMapCore().MapControl, num7, "G");
                    }
                    else
                    {
                        arg  = num5.ToString(CultureInfo.CurrentCulture);
                        arg2 = num7.ToString(CultureInfo.CurrentCulture);
                    }
                }
                else
                {
                    num2 = num4;
                    num3 = num4;
                }
                using (GraphicsPath path = CreateScalePath(absoluteRectangle, (int)num2, (int)num3))
                {
                    using (Brush brush = new SolidBrush(ScaleForeColor))
                    {
                        g.FillPath(brush, path);
                    }
                    using (Pen pen = new Pen(ScaleBorderColor, 1f))
                    {
                        pen.Alignment  = PenAlignment.Center;
                        pen.MiterLimit = 0f;
                        g.DrawPath(pen, path);
                    }
                    StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();
                    stringFormat.FormatFlags = StringFormatFlags.NoWrap;
                    using (Brush brush2 = new SolidBrush(LabelColor))
                    {
                        RectangleF textBounds      = new RectangleF(absoluteRectangle.Left + 3f, absoluteRectangle.Top, num2, absoluteRectangle.Height / 2f - 3f);
                        string     text            = string.Format(CultureInfo.CurrentCulture, "{0} {1}", arg, measurementUnit.ToString(CultureInfo.CurrentCulture));
                        SizeF      textClipSize    = g.MeasureString(text, Font, textBounds.Size, stringFormat);
                        RectangleF layoutRectangle = CreateTextClip(textBounds, textClipSize);
                        g.DrawString(text, Font, brush2, layoutRectangle, stringFormat);
                        RectangleF textBounds2      = new RectangleF(absoluteRectangle.Left + 3f, absoluteRectangle.Top + absoluteRectangle.Height / 2f + 3f, num3, absoluteRectangle.Height / 2f - 3f);
                        string     text2            = string.Format(CultureInfo.CurrentCulture, "{0} {1}", arg2, measurementUnit2.ToString(CultureInfo.CurrentCulture));
                        SizeF      textClipSize2    = g.MeasureString(text2, Font, textBounds2.Size, stringFormat);
                        RectangleF layoutRectangle2 = CreateTextClip(textBounds2, textClipSize2);
                        g.DrawString(text2, Font, brush2, layoutRectangle2, stringFormat);
                    }
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }