/// <summary> /// 保存用户自定义风格 /// </summary> /// <param name="presentAreaKey">呈现区域标识</param> /// <param name="ownerId">OwnerId</param> /// <param name="customStyle">自定义风格实体</param> public void Save(string presentAreaKey, long ownerId, CustomStyle customStyle) { PetaPocoDatabase database = CreateDAO(); database.OpenSharedConnection(); CustomStyleEntity entity = Get(presentAreaKey, ownerId); string customStyleXml = Serialize(customStyle); if (entity != null) { customStyle.LastModified = DateTime.UtcNow; entity.CustomStyle = customStyle; entity.SerializedCustomStyle = customStyleXml; entity.LastModified = DateTime.UtcNow; database.Update(entity); } else { entity = CustomStyleEntity.New(); entity.CustomStyle = customStyle; entity.PresentAreaKey = presentAreaKey; entity.OwnerId = ownerId; entity.SerializedCustomStyle = customStyleXml; database.Insert(entity); } database.CloseSharedConnection(); cacheService.Set(GetCacheKey_CustomStyleEntity(presentAreaKey, ownerId), entity, CachingExpirationType.UsualSingleObject); }
public StyleDTO(CustomStyle source) { Name = source.Name; Font = source.OriginalFont; DefFont = source.UseDefaultFont; Foreground = source.OriginalForeground.ToInt(); DefForeground = source.UseDefaultForeground; Background = source.OriginalBackground.ToInt(); DefBackground = source.UseDefaultBackground; Opacity = source.OriginalOpacity; DefOpacity = source.UseDefaultOpacity; Size = source.OriginalSize; DefSize = source.UseDefaultSize; Italic = source.OriginalItalic; DefItalic = source.UseDefaultItalic; Bold = source.OriginalBold; DefBold = source.UseDefaultBold; Underline = source.OriginalUnderline; DefUnderline = source.UseDefaultUnderline; Strikethrough = source.OriginalStrikethrough; DefStrikethrough = source.UseDefaultStrikethrough; }
private void OnGUI() { if (Score > HighScore) { HighScore = Score; if (HighScore > savedHighScore) { IsNewHighScore = true; } } var labelStyle = CustomStyle.GetLabelStyle(); labelStyle.alignment = TextAnchor.UpperRight; var contentScore = new GUIContent(string.Format("Score: {0:000000}", Score)); var contentHigh = new GUIContent(string.Format("High Score: {0:000000}", HighScore)); var sizeScore = labelStyle.CalcSize(contentScore); var sizeHigh = labelStyle.CalcSize(contentHigh); var height = sizeScore.y + sizeHigh.y; GUILayout.BeginArea(new Rect(Screen.width / 2 - 5, 5, Screen.width / 2, height)); { GUILayout.BeginVertical(); { GUILayout.Label(contentScore); GUILayout.Label(contentHigh); } GUILayout.EndVertical(); } GUILayout.EndArea(); }
public IEnumerable <IResult> EditLegend(string name) { var styles = Env.Query(s => s.Query <CustomStyle>().ToArray()).Result; var style = styles.FirstOrDefault(s => s.Name == name); if (style == null) { yield break; } var isDirty = false; style.PropertyChanged += (sender, args) => { isDirty = true; }; foreach (var result in CustomStyle.Edit(style)) { yield return(result); } if (!isDirty) { yield break; } Env.Query(s => s.Update(style)).LogResult(); StyleHelper.BuildStyles(App.Current.Resources, styles); Bus.SendMessage(styles); }
public static List <CustomStyle> GetDefaultStyles(Dictionary <string, DataTrigger> defaults) { var styles = GetTypes() .SelectMany(t => t.GetProperties().Select(p => Tuple.Create(p, p.GetCustomAttributes(typeof(StyleAttribute), true).OfType <StyleAttribute>().ToArray()))) .SelectMany(t => t.Item2.Select(a => Tuple.Create(t.Item1, a))) .ToArray(); return(styles.Select(t => { var appStyle = new CustomStyle { Name = t.Item2.GetName(t.Item1), Description = t.Item2.Description, }; var trigger = defaults.GetValueOrDefault(appStyle.Name) ?? Background(DefaultColor.Color); var background = trigger.Setters.OfType <Setter>().FirstOrDefault(s => s.Property == Control.BackgroundProperty); var foreground = trigger.Setters.OfType <Setter>().FirstOrDefault(s => s.Property == Control.ForegroundProperty); if (background != null && background.Value is SolidColorBrush) { appStyle.Background = ((SolidColorBrush)background.Value).Color.ToString(); appStyle.IsBackground = true; } else if (foreground != null && foreground.Value is SolidColorBrush) { appStyle.Foreground = ((SolidColorBrush)foreground.Value).Color.ToString(); } return String.IsNullOrEmpty(appStyle.Description) ? null : appStyle; }) .Where(s => s != null).ToList()); }
public void ItalicAttribute_GetDefaultValue() { var style = new CustomStyle(); style.UseDefaultItalic = true; Assert.Equal(DefaultStyle.Instance.Italic, style.Italic); }
public void SizeAttribute_GetDefaultValue() { var style = new CustomStyle(); style.UseDefaultSize = true; Assert.Equal(DefaultStyle.Instance.Size, style.Size); }
public void UnderlineAttribute_GetDefaultValue() { var style = new CustomStyle(); style.UseDefaultUnderline = true; Assert.Equal(DefaultStyle.Instance.Underline, style.Underline); }
public void BackgroundAttribute_GetDefaultValue() { var style = new CustomStyle(); style.UseDefaultBackground = true; Assert.Equal(DefaultStyle.Instance.Background, style.Background); }
public void Name() { var style = new CustomStyle(); var viewModel = new StyleViewModel(style, null); viewModel.Name = "Note"; Assert.Equal(viewModel.Name, style.Name); }
public void StrikethroughAttribute_GetDefaultValue() { var style = new CustomStyle(); style.UseDefaultStrikethrough = true; Assert.Equal(DefaultStyle.Instance.Strikethrough, style.Strikethrough); }
public void OpacityAttribute_GetDefaultValue() { var style = new CustomStyle(); style.UseDefaultOpacity = true; Assert.Equal(DefaultStyle.Instance.Opacity, style.Opacity); }
public void UnderlineAttribute_GetValue() { var style = new CustomStyle(); var value = true; style.Underline = value;; Assert.Equal(value, style.Underline); }
public void BackgroundAttribute_GetValue() { var style = new CustomStyle(); var color = Colors.Red; style.Background = color; Assert.Equal(color, style.Background); }
public void ForegroundAttribute_GetDefaultValue() { var style = new CustomStyle(); style.Foreground = Colors.Red; style.UseDefaultForeground = true; Assert.Equal(DefaultStyle.Instance.Foreground, style.Foreground); }
public void FontAttribute_GetDefaultValue() { var style = new CustomStyle(); style.Font = "Arial"; style.UseDefaultFont = true; Assert.Equal(DefaultStyle.Instance.Font, style.Font); }
public void FontAttribute_GetValue() { var style = new CustomStyle(); var arial = "Arial"; style.Font = arial; Assert.Equal(arial, style.Font); }
public void OpacityAttribute_GetValue() { var style = new CustomStyle(); var value = 1.0d; style.Opacity = value;; Assert.Equal(value, style.Opacity); }
public void StrikethroughAttribute_GetValue() { var style = new CustomStyle(); var value = true; style.Strikethrough = value;; Assert.Equal(value, style.Strikethrough); }
public void SizeAttribute_GetValue() { var style = new CustomStyle(); var value = 1.0d; style.Size = value;; Assert.Equal(value, style.Size); }
public void ItalicAttribute_GetValue() { var style = new CustomStyle(); var value = true; style.Italic = value;; Assert.Equal(value, style.Italic); }
public void BoldAttribute_GetValue() { var style = new CustomStyle(); var value = true; style.Bold = value;; Assert.Equal(value, style.Bold); }
/// <summary> /// 把CustomStyleEntity对象转换成xml /// </summary> /// <param name="customStyle">被转换的对象</param> /// <returns>序列化后的xml字符串</returns> private string Serialize(CustomStyle customStyle) { string xml = null; if (customStyle != null) { xml = Json.Encode(customStyle); } return(xml); }
public void BackgroundAttribute_GetDefaultValueVS() { DefaultStyle.Instance.VSBackground = Colors.Purple; DefaultStyle.Instance.UseVSBackground = true; var style = new CustomStyle(); style.UseDefaultBackground = true; Assert.Equal(Colors.Transparent, style.Background); }
/// <summary> /// 获取预置的配色方案 /// </summary> /// <param name="presentAreaKey"></param> public IEnumerable <CustomStyle> GetColorSchemes(string presentAreaKey) { string cacheKey = "ColorSchemes-" + presentAreaKey; List <CustomStyle> customStyles = cacheService.Get <List <CustomStyle> >(cacheKey); if (customStyles == null) { customStyles = new List <CustomStyle>(); XElement colorSchemesElement = XElement.Load(WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/Custom/ColorScheme.config", presentAreaKey))); if (colorSchemesElement != null) { IEnumerable <XElement> colorSchemeElements = colorSchemesElement.Elements("colorScheme"); foreach (XElement colorSchemeElement in colorSchemeElements) { Dictionary <string, string> definedColours = new Dictionary <string, string>(); CustomStyle customStyle = new CustomStyle(); var isDarkAttr = colorSchemeElement.Attribute("isDark"); bool isDark = false; if (isDarkAttr != null) { bool.TryParse(isDarkAttr.Value, out isDark); } customStyle.IsDark = isDark; var imageUrlAttr = colorSchemeElement.Attribute("imageUrl"); if (imageUrlAttr != null) { customStyle.ImageUrl = imageUrlAttr.Value; } IEnumerable <XElement> colorElements = colorSchemeElement.Elements("color"); foreach (XElement colorElement in colorElements) { var labelAttr = colorElement.Attribute("label"); if (labelAttr == null) { continue; } string colorLabel = labelAttr.Value; var valueAttr = colorElement.Attribute("value"); if (valueAttr == null) { continue; } definedColours[colorLabel] = valueAttr.Value; } customStyle.DefinedColours = definedColours; customStyles.Add(customStyle); } } cacheService.Add(cacheKey, customStyles, CachingExpirationType.RelativelyStable); } return(customStyles); }
public void Size() { var style = new CustomStyle(); var viewModel = new StyleViewModel(style, null); viewModel.Size = 0.4; Assert.Equal(viewModel.Size, style.Size); // testing UseDefault viewModel.UseDefaultSize = true; Assert.True(style.UseDefaultSize); Assert.Equal(defaults.Size, style.Size); Assert.Equal(defaults.Size, viewModel.Size); }
public void Opacity() { var style = new CustomStyle(); var viewModel = new StyleViewModel(style, null); viewModel.Opacity = 0.4; Assert.Equal(viewModel.Opacity, style.Opacity); // testing UseDefault viewModel.UseDefaultOpacity = true; Assert.True(style.UseDefaultOpacity); Assert.Equal(defaults.Opacity, style.Opacity); Assert.Equal(defaults.Opacity, viewModel.Opacity); }
public void Background() { var style = new CustomStyle(); var viewModel = new StyleViewModel(style, null); viewModel.Background = Colors.Purple; Assert.Equal(viewModel.Background, style.Background); // testing UseDefault viewModel.UseDefaultBackground = true; Assert.True(style.UseDefaultBackground); Assert.Equal(defaults.Background, style.Background); Assert.Equal(defaults.Background, viewModel.Background); }
public void Strikethrough() { var style = new CustomStyle(); var viewModel = new StyleViewModel(style, null); viewModel.Strikethrough = true; Assert.Equal(viewModel.Strikethrough, style.Strikethrough); // testing UseDefault viewModel.UseDefaultStrikethrough = true; Assert.True(style.UseDefaultStrikethrough); Assert.Equal(defaults.Strikethrough, style.Strikethrough); Assert.Equal(defaults.Strikethrough, viewModel.Strikethrough); }
public void Underline() { var style = new CustomStyle(); var viewModel = new StyleViewModel(style, null); viewModel.Underline = true; Assert.Equal(viewModel.Underline, style.Underline); // testing UseDefault viewModel.UseDefaultUnderline = true; Assert.True(style.UseDefaultUnderline); Assert.Equal(defaults.Underline, style.Underline); Assert.Equal(defaults.Underline, viewModel.Underline); }