public override Vector2 PermaDraw(PermaMenuItemEntry context, Vector2 position) { var pos = position; var size = context.PermaRenderSize; var activeStyle = context.MenuConfig.GeneralConfig.ActiveStyle.Value; var styleConfig = activeStyle.StyleConfig.PermaShow; var border = styleConfig.Border; context.Renderer.DrawTexture(activeStyle.Item, new RectangleF(position.X, position.Y, size.X, size.Y)); pos += new Vector2(border.Thickness[0] + styleConfig.LineWidth, border.Thickness[1]); var font = styleConfig.Font; context.Renderer.DrawText(pos, $"{context.RootMenuName} > {context.Name}", font.Color, font.Size, font.Family); var sliderPos = Vector2.Zero; sliderPos.X = (position.X + size.X) - border.Thickness[2] - styleConfig.ArrowSize.X; sliderPos.Y = pos.Y; context.Renderer.DrawTexture( context.ValueBinding.GetValue <bool>() ? activeStyle.Checked : activeStyle.Unchecked, new RectangleF(sliderPos.X, sliderPos.Y, styleConfig.ArrowSize.X, styleConfig.ArrowSize.Y)); position.Y += size.Y; return(position); }
public override Vector2 GetPermaSize(PermaMenuItemEntry context) { var totalSize = base.GetPermaSize(context); var styleConfig = context.MenuConfig.GeneralConfig.ActiveStyle.Value.StyleConfig; totalSize.X += styleConfig.TextSpacing + styleConfig.ArrowSize.X; // TODO: use own bool view style options totalSize.Y = Math.Max(totalSize.Y, styleConfig.ArrowSize.Y); // border missing for y return(totalSize); }
public virtual Vector2 GetPermaSize(PermaMenuItemEntry context) { var totalSize = Vector2.Zero; var styleConfig = context.MenuConfig.GeneralConfig.ActiveStyle.Value.StyleConfig.PermaShow; var border = styleConfig.Border; totalSize.X += border.Thickness[0] + border.Thickness[2]; totalSize.Y += border.Thickness[1] + border.Thickness[3]; var font = styleConfig.Font; context.PermaTextSize = context.Renderer.MessureText($"{context.RootMenuName} > {context.Name}", font.Size, font.Family); totalSize += context.PermaTextSize; return(totalSize); }
private void VisitItem(MenuEntry parent, object instance, MenuEntry rootMenu) { var type = instance.GetType(); var propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var propertyInfo in propertyInfos.OrderBy(x => this.Order(propertyInfos, x)).ToArray()) { var menuItemAttribute = propertyInfo.GetCustomAttribute <ItemAttribute>(); if (menuItemAttribute == null) { continue; } var propertyValue = propertyInfo.GetValue(instance); if (propertyValue == null) { throw new NullReferenceException($"{type.FullName} {propertyInfo.Name}"); } var menuItemName = menuItemAttribute.Name; if (string.IsNullOrEmpty(menuItemName)) { menuItemName = propertyInfo.Name; } this.context.Container.BuildUp(propertyValue); var textureAttribute = propertyInfo.GetCustomAttribute <TextureAttribute>(); textureAttribute?.Load(this.context.Renderer); var view = this.viewRepository.GetView(propertyInfo.PropertyType); MenuItemEntry menuItemEntry; if (propertyInfo.GetCustomAttribute <PermaShowAttribute>() != null) { var tmp = new PermaMenuItemEntry( menuItemName, textureAttribute?.TextureKey, view, this.context.Renderer, this.MenuConfig, new ValuePropertyBinding(instance, propertyInfo)); tmp.RootMenuName = rootMenu.Name; this.permaItemEntries.Add(tmp); menuItemEntry = tmp; } else { menuItemEntry = new MenuItemEntry( menuItemName, textureAttribute?.TextureKey, view, this.context.Renderer, this.MenuConfig, new ValuePropertyBinding(instance, propertyInfo)); } var tooltip = propertyInfo.GetCustomAttribute <TooltipAttribute>(); if (tooltip != null) { menuItemEntry.Tooltip = tooltip.Text; } parent.AddChild(menuItemEntry); } }
public virtual Vector2 PermaDraw(PermaMenuItemEntry context, Vector2 position) { return(position); }