Exemple #1
0
            /// <summary>
            /// Sets the RelativeSize value of a given Creature object.
            /// <para>Will operate on the Creature object's CharacteristicDictionary only if the target key ("RelativeSize") already exists.</para>
            /// </summary>
            /// <param name="creature"></param>
            /// <param name="relativeSize"></param>
            public static void SetRelativeSize(this Creature creature, RelativeSize relativeSize)
            {
                if (creature.CharacteristicDictionary.ContainsKey("RelativeSize"))
                {
                    var setRelativeSize = (CharaRelativeSize)creature.CharacteristicDictionary["RelativeSize"];

                    setRelativeSize.RelativeSize = relativeSize;
                }
            }
        public async Task <ActionResult> Details(int id = 0)
        {
            RelativeSize RelativeSize = await DB.RelativeSizes.FindAsync(id);

            if (RelativeSize == null)
            {
                return(HttpNotFound());
            }
            return(PartialView(RelativeSize));
        }
        public async Task <ActionResult> Delete(int id)
        {
            RelativeSize RelativeSize = await DB.RelativeSizes.FindAsync(id);

            DB.RelativeSizes.Remove(RelativeSize);
            await DB.SaveChangesAsync();

            TempData["Msg"] = "تمت عملية الحذف بنجاح";
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit(RelativeSize RelativeSize)
        {
            if (ModelState.IsValid)
            {
                DB.Entry(RelativeSize).State = EntityState.Modified;
                await DB.SaveChangesAsync();

                TempData["Msg"] = "تم التعديل بنجاح";
                return(RedirectToAction("Index"));
            }
            return(PartialView(RelativeSize));
        }
        public async Task <ActionResult> Create(RelativeSize RelativeSize)
        {
            if (ModelState.IsValid)
            {
                DB.RelativeSizes.Add(RelativeSize);
                await DB.SaveChangesAsync();

                TempData["msg"] = "تمت عملية الاضافة بنجاح";
                return(RedirectToAction("Index"));
            }
            return(PartialView(RelativeSize));
        }
        public UILabel(int font, string text, Color color, RelativePoint origin, RelativeSize height, RelativeSize width = null, OriginLocation anchor = OriginLocation.Center, TextFittingModes mode = TextFittingModes.ByHeightExtend) : base()
        {
            IgnoreMouse = true;
            FittingMode = mode;
            Text        = text;
            Font        = font;

            if (width == null)
            {
                width = RelativeSize.FullWidth;
            }

            DefaultMaterial.Color = color;
            Rect = new RelativeRect(origin.X, origin.Y, width, height, anchor);
        }
        public UIImage(string texture, RelativePoint origin, OriginLocation anchor = OriginLocation.Center, RelativeSize _width = null, RelativeSize _height = null) : base()
        {
            IgnoreMouse = true;

            RelativeSize height = _height;
            RelativeSize width  = _width;

            DefaultMaterial = new GUIMaterial(texture, Color.White);
            CheckMaterial();

            if (CurrentMaterial == null || CurrentMaterial.DiffuseTexture == null || CurrentMaterial.DiffuseTexture.PixelSize.X == 0 || CurrentMaterial.DiffuseTexture.PixelSize.Y == 0)
            {
                return;
            }

            if (width == null && height == null)
            {
                // going raw.
                width           = new RelativeSize();
                width.Raw       = true;
                width.Paramater = CurrentMaterial.DiffuseTexture.PixelSize.X;

                height           = new RelativeSize();
                height.Raw       = true;
                height.Paramater = CurrentMaterial.DiffuseTexture.PixelSize.Y;
            }
            else if (width == null)
            {
                width = RelativeTools.GetRelativeWidthInAspect(height, CurrentMaterial.DiffuseTexture.PixelSize.X, CurrentMaterial.DiffuseTexture.PixelSize.Y);
            }
            else if (height == null)
            {
                height = RelativeTools.GetRelativeHeightInAspect(width, CurrentMaterial.DiffuseTexture.PixelSize.X, CurrentMaterial.DiffuseTexture.PixelSize.Y);
            }

            Rect = new RelativeRect(origin.X, origin.Y, width, height, anchor);
        }
Exemple #8
0
 internal static double SqNiveau(this IParameterProvider parameters, Func <IParameterProvider, double> metric, RelativeSize relativeSize, Calibration calibration)
 {
     return(100.0 / System.Math.Pow(1.5, relativeSize(metric(parameters), parameters) / calibration(metric(parameters), parameters)));
 }
        public override void Resize(int x, int y)
        {
            LastParentSize.X = x;
            LastParentSize.Y = y;

            RelativeSize heightCache = Rect.Height;
            RelativeSize widthCache  = Rect.Width;

            float pixelWidth = widthCache.ToScreen(x, y);

            ActualFontSize = GetNominalFontHeight(Rect.Height.ToScreen(LastParentSize));
            float textWidth = 0;

            string effectiveText = Text;

            switch (FittingMode)
            {
            case TextFittingModes.ByHeightExtend:
                break;

            case TextFittingModes.ByHeightTrim:
                effectiveText = String.Copy(Text);

                textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X;

                while (textWidth > pixelWidth)
                {
                    if (textWidth > pixelWidth * 2)
                    {
                        effectiveText = effectiveText.Substring(0, effectiveText.Length / 2);
                    }
                    else
                    {
                        effectiveText = effectiveText.Substring(0, effectiveText.Length - 1);
                    }

                    textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X;
                }
                break;

            case TextFittingModes.ByHeightReverseTrim:
                effectiveText = String.Copy(Text);

                textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X;

                while (textWidth > pixelWidth)
                {
                    if (textWidth > pixelWidth * 2)
                    {
                        effectiveText = effectiveText.Substring(effectiveText.Length / 2);
                    }
                    else
                    {
                        effectiveText = effectiveText.Substring(1);
                    }

                    textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X;
                }
                break;

            case TextFittingModes.ByWidth:
                textWidth = FontManager.MeasureText(Font, ActualFontSize, Text).X;

                while (textWidth > pixelWidth)
                {
                    ActualFontSize -= 1;
                    if (ActualFontSize <= 5)     // that's the smallest we can go, it just wont' fit
                    {
                        break;
                    }

                    textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X;
                }
                break;
            }

            DrawInfo = FontManager.DrawText(Font, ActualFontSize, effectiveText);
            if (DrawInfo == null)
            {
                return;
            }

            Rect.Width      = new RelativeSize(DrawInfo.Size.X, true);
            Rect.Width.Mode = RelativeSize.SizeModes.Raw;

            Rect.Height      = new RelativeSize(DrawInfo.Size.Y, true);
            Rect.Height.Mode = RelativeSize.SizeModes.Raw;

            Rect.Resize(x, y);
            var pixelSize = Rect.GetPixelSize();

            if (CurrentMaterial == null || CurrentMaterial.DiffuseTexture != DrawInfo.CachedTexture)
            {
                CurrentMaterial = GUIManager.GetMaterial(DrawInfo.CachedTexture, DefaultMaterial.Color);
            }

            ShapeBuffer.TexturedRect(this, Rect);

            foreach (var child in Children)
            {
                child.Resize(pixelSize);
            }

            Rect.Height = heightCache;
            Rect.Width  = widthCache;
        }
Exemple #10
0
        public override void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            if (Math.Abs(buttons.WheelTick) > 0 && TextLabels.Count > 1)
            {
                SetSelectedIndex(SelectedIndex + buttons.WheelTick);
            }

            if (!buttons.PrimaryClick || ParentCanvas == null || ParentCanvas.PopupEnabled() || TextLabels.Count < 2)
            {
                return;
            }

            float width  = Rect.GetPixelSize().X;
            float height = Rect.GetPixelSize().Y;

            Vector2 origin = Rect.GetPixelOrigin();

            float availableDist = width - (height * 2);

            if (location.X < origin.X + height || location.X > origin.X + availableDist + height)
            {
                return;
            }

            Vector2 thisOrigin = GetScreenOrigin();

            float thisCenterY = thisOrigin.Y + (height * 0.5f);

            float totalheight = (MenuCommon.ButtonSpacing.Paramater + (height * 1)) * TextLabels.Count;

            totalheight += MenuCommon.ButtonSpacing.Paramater * 1;

            float halfHeight = totalheight * 0.5f;

            float screenHeight = ParentCanvas.BoundWindow.Height;

            // see where the popup will land on the screen.

            OriginLocation originAllignment = OriginLocation.LowerLeft;

            if (totalheight > screenHeight)  // it won't fit, center it
            {
                originAllignment = OriginLocation.MiddleLeft;
            }
            else
            {
                if (thisCenterY - halfHeight > 0 && thisCenterY + halfHeight <= screenHeight)
                {
                    originAllignment = OriginLocation.MiddleLeft; // it'll fit centered, that looks better
                }
                else
                {
                    // it won't fit centered, so put it on the other side of the screen from where the button is
                    if (thisCenterY > halfHeight)
                    {
                        originAllignment = OriginLocation.UpperLeft;
                    }
                    else
                    {
                        originAllignment = OriginLocation.LowerLeft;
                    }
                }
            }

            if (originAllignment == OriginLocation.UpperLeft)
            {
                thisOrigin.Y += height;
            }
            else if (originAllignment == OriginLocation.MiddleLeft)
            {
                thisOrigin.Y += height * 0.5f;
            }

            RelativeRect rect = new RelativeRect(new RelativeLoc(thisOrigin.X, RelativeLoc.Edge.Raw), new RelativeLoc(thisOrigin.Y, RelativeLoc.Edge.Raw), RelativeSize.FixedPixelSize(width), RelativeSize.FixedPixelSize(totalheight), originAllignment);

            var popup = new UIPanel(rect, ThemeManager.GetThemeAsset("ui/SelectorPopupBackground.png"));

            popup.FillMode    = UIFillModes.SmartStprite;
            popup.IgnoreMouse = false;

            VerticalLayoutGroup vertgroup = MenuCommon.SetupCommonColumn(new RelativeRect(RelativeLoc.XCenter, RelativeLoc.YCenter, RelativeSize.ThreeQuarterWidth, rect.Height, OriginLocation.Center));

            vertgroup.FirstElementHasSpacing = true;

            foreach (var label in TextLabels)
            {
                MenuButton button = new MenuButton(new RelativeRect(), label);
                button.Tag      = label;
                button.Clicked += PopupButton_Clicked;
                if (label == GetText())
                {
                    button.Check();
                }

                vertgroup.AddChild(button);
            }
            popup.AddChild(vertgroup);

            ParentCanvas.SetPopupElement(popup);
        }
Exemple #11
0
 internal static double SqNiveau(this IParameterProvider parameters, Func<IParameterProvider, double> metric, RelativeSize relativeSize, Calibration calibration)
 {
     return 100.0 / System.Math.Pow(1.5, relativeSize(metric(parameters), parameters) / calibration(metric(parameters), parameters));
 }
 public CharaRelativeSize(RelativeSize relativeSize)
 {
     RelativeSize = relativeSize;
 }