/// <summary> /// asemble report /// </summary> /// <param name="fileName"></param> /// <param name="bw"></param> public void CreateReport(string fileName, BackgroundWorker bw) { try { int mapcols = 0; if (InitNewExcelFile(fileName)) { InitDataModel(); List <string> tics = GetTics(); double total = 0, inc = 100.0 / tics.Count; int fg = ColorExtensions.TranslateToExcelColor(System.Drawing.Color.FromArgb(0, 0, 0)); int bg = ColorExtensions.TranslateToExcelColor(System.Drawing.Color.FromArgb(217, 217, 217)); int black = ColorExtensions.TranslateToExcelColor(System.Drawing.Color.FromArgb(255, 255, 255)); palette = GetPalette(); mapPalatte = GetMapPallate(); int row = 1, col = 1; //font this.activeWorksheet.wrapText(1, 1, 2, 15); this.activeWorksheet.Center(1, 1, 2, 15); this.activeWorksheet.SetFont(14, 1, 1, 2, 15); //colom widths this.activeWorksheet.ColumnWidth(col++, 20); this.activeWorksheet.ColumnWidth(col++, 16.43); this.activeWorksheet.ColumnWidth(col++, 26.71); this.activeWorksheet.ColumnWidth(col++, 28.29); this.activeWorksheet.ColumnWidth(col++, 21.71); this.activeWorksheet.ColumnWidth(col++, 33.14); for (int i = 1; i <= 7; i++) { this.activeWorksheet.ColumnWidth(col++, 17.57); } //header col = 7; this.activeWorksheet.setMergedCellTo(row, col, "Capability Implementation", 3, back, black); col += 4; this.activeWorksheet.setMergedCellTo(row++, col, "Information Protection", 3, mapPalatte[4][0], black); col = 1; this.activeWorksheet.setCellTo(row, col++, "TIC Capability Mapping", bg, fg, true); this.activeWorksheet.setCellTo(row, col++, "Domain", bg, fg, true); this.activeWorksheet.setCellTo(row, col++, "Container", bg, fg, true); this.activeWorksheet.setCellTo(row, col++, "Capability", bg, fg, true); this.activeWorksheet.setCellTo(row, col++, "Capability Details", bg, fg, true); this.activeWorksheet.setCellTo(row, col++, "Description", bg, fg, true); mapcols = col; int start = col; this.activeWorksheet.setCellTo(row, col++, "Capability Implementation: Low Impact", mapPalatte[col - start - 1][0], fg, false); this.activeWorksheet.setCellTo(row, col++, "Capability Implementation: Moderate Impact", mapPalatte[col - 9][0], fg, false); this.activeWorksheet.setCellTo(row, col++, "Capability Implementation: High Impact", mapPalatte[col - start - 1][0], fg, false); this.activeWorksheet.setCellTo(row, col++, "PM Controls", mapPalatte[col - start - 1][0], fg, false); this.activeWorksheet.setCellTo(row, col++, "Info protection: Low Impact", mapPalatte[col - start - 1][0], fg, false); this.activeWorksheet.setCellTo(row, col++, "Info protection: Moderate Impact", mapPalatte[col - start - 1][0], fg, false); this.activeWorksheet.setCellTo(row, col++, "Info protection: High Impact", mapPalatte[col - start - 1][0], fg, false); this.activeWorksheet.Border(2, 1, 2, 13); this.activeWorksheet.SetHeight(1, 30); row++; foreach (string tic in tics) { //sort by tic col = 1; this.activeWorksheet.setCellTo(row, col++, tic); List <Context.Capabilities> list = GetCaps(tic); double sub = inc / list.Count; PrintCompactCaps(list, ref row, ref col, ref total, sub, bw); row++; } this.activeWorksheet.SetFont(12, 3, 1, row, 20); this.activeWorksheet.Center(3, 1, row, 1); this.activeWorksheet.Border(1, start, row - 2, start + 6); this.activeWorksheet.fit(3, 3, row, 20); } } catch (Exception e) { string s = e.Message; } finally { CloseSaveExcel(); } }
public static void RenderSpriteLine(DynamicFontRenderer renderer, UIMarkupToken token, Vector3 position, UIRenderData destination) { string[] args = token.GetAttribute(0)?.m_Value?.value?.Split(new char[] { ',' }, 3); if (args == null || args.Length != 3) { LogUtils.DoErrorLog($"INVALID ARGUMENT: {token.GetAttribute(0)?.m_Value?.value ?? "<NULL>"}"); return; } UITextureAtlas.SpriteInfo spriteInfo = renderer.spriteAtlas[args[0]]; if (spriteInfo == null) { CODebugBase <InternalLogChannel> .Warn(InternalLogChannel.UI, "Missing sprite " + args[0] + " in " + renderer.spriteAtlas.name); } else { var midLine = new Vector3(position.x, position.y - (((UIDynamicFont)renderer.font).baseline * renderer.textScale / 2)); Texture2D texture = renderer.spriteAtlas.texture; float calcHeight = ((UIDynamicFont)renderer.font).baseline * renderer.textScale * 2f; float calcProportion = spriteInfo.region.width * texture.width / (spriteInfo.region.height * texture.height); float calcWidth = Mathf.CeilToInt(calcHeight * calcProportion); int height = Mathf.CeilToInt(calcHeight); int width = Mathf.CeilToInt(calcWidth); Color32 bgColor = ColorExtensions.FromRGB(args[1]); Color32 color2 = ApplyOpacity(renderer, bgColor); var size = new Vector3(width, height); Vector2 textDimensions = MeasureTextWidth(renderer, args[2], renderer.textScale, out Vector2 yBounds); float imageProportions = width / spriteInfo.width; float borderWidth = renderer.textScale * 2; float textBoundHeight = height - (spriteInfo.border.vertical * imageProportions) - borderWidth; float textBoundWidth = width - (spriteInfo.border.horizontal * imageProportions) - borderWidth; var textAreaSize = new Vector4((spriteInfo.border.left * imageProportions) + (borderWidth / 2), (-spriteInfo.border.top + spriteInfo.border.bottom) * imageProportions / 2, textBoundWidth, textBoundHeight); float textScale = renderer.textScale; float multipler = Mathf.Min(Mathf.Min(3.5f, textAreaSize.z / textDimensions.x), Mathf.Min(3.5f, textAreaSize.w / textDimensions.y)); if (multipler > 1) { textScale *= 1 + ((multipler - 1) / 2.1f); multipler = 1; textDimensions = MeasureTextWidth(renderer, args[2], textScale, out yBounds); } float midLineOffset = (((UIDynamicFont)renderer.font).baseline / 2 * renderer.textScale); Color contrastColor = KlyteMonoUtils.ContrastColor(bgColor); RenderSprite(renderer.spriteBuffer, new RenderOptions { atlas = renderer.spriteAtlas, color = contrastColor, fillAmount = 1f, flip = UISpriteFlip.None, offset = position - new Vector3(0, -(height / 2) + midLineOffset), pixelsToUnits = renderer.pixelRatio, size = size, spriteInfo = spriteInfo }); RenderSprite(renderer.spriteBuffer, new RenderOptions { atlas = renderer.spriteAtlas, color = color2, fillAmount = 1f, flip = UISpriteFlip.None, offset = position - new Vector3(0, -(height / 2) + midLineOffset) + (new Vector3(borderWidth, -borderWidth) / 2), pixelsToUnits = renderer.pixelRatio, size = size - new Vector3(borderWidth, borderWidth), spriteInfo = spriteInfo }); midLineOffset = ((UIDynamicFont)renderer.font).baseline * textScale; Vector3 targetTextPos = midLine + VectorUtils.XY_(textAreaSize) + (new Vector3(textAreaSize.z - (textDimensions.x * multipler), -textDimensions.y) / 2); RenderText(renderer, args[2], targetTextPos, multipler, destination, textScale, contrastColor, bgColor); } }
public void BroadcastAddCubeBlock(CubeBlockEntity cubeBlock) { try { Type packedStructType = CubeGridEntity.InternalType.GetNestedType(CubeGridEntity.CubeGridPackedCubeBlockClass); Object packedStruct = Activator.CreateInstance(packedStructType); MyCubeBlockDefinition def = MyDefinitionManager.Static.GetCubeBlockDefinition(cubeBlock.ObjectBuilder); //Set def id BaseObject.SetEntityFieldValue(packedStruct, "35E024D9E3B721592FB9B6FC1A1E239A", (DefinitionIdBlit)def.Id); //Set position BaseObject.SetEntityFieldValue(packedStruct, "5C3938C9B8CED1D0057CCF12F04329AB", cubeBlock.Position); //Set block size BaseObject.SetEntityFieldValue(packedStruct, "0DDB53EB9299ECC9826DF9A47E5E4F38", new Vector3UByte(def.Size)); //Set block margins BaseObject.SetEntityFieldValue(packedStruct, "4045ED59A8C93DE0B41218EF2E947E55", new Vector3B(0, 0, 0)); BaseObject.SetEntityFieldValue(packedStruct, "096897446D5BD5243D3D6E5C53CE1772", new Vector3B(0, 0, 0)); //Set block margin scale BaseObject.SetEntityFieldValue(packedStruct, "E28B9725868E18B339D1E0594EF14444", new Vector3B(0, 0, 0)); //Set orientation Quaternion rot; cubeBlock.BlockOrientation.GetQuaternion(out rot); BaseObject.SetEntityFieldValue(packedStruct, "F1AAFF5C8F200592F313BC7E02140A38", Base6Directions.GetForward(rot)); BaseObject.SetEntityFieldValue(packedStruct, "E80AA7B84131E39F9F88209A109EED59", Base6Directions.GetUp(rot)); //Set color BaseObject.SetEntityFieldValue(packedStruct, "556976F2528411FF5F95FC75DC13FEED", ColorExtensions.PackHSVToUint(cubeBlock.ColorMaskHSV)); object[] parameters = { packedStruct, new HashSet <Vector3UByte>(), cubeBlock.EntityId, MyRandom.Instance.CreateRandomSeed() }; BaseObject.InvokeEntityMethod(m_netManager, CubeGridNetManagerBroadcastAddCubeBlockMethod, parameters); } catch (Exception ex) { ApplicationLog.BaseLog.Error(ex); } }
private void TrySetGradientBarFill(TKChartColumnSeries columnSeries, TXFC.CartesianSeries xfSeries) { XF.Color xfStartColor = EXAMPLE.GradientBarsEffect.GetStartColor(xfSeries); XF.Color xfEndColor = EXAMPLE.GradientBarsEffect.GetEndColor(xfSeries); if (xfStartColor == XF.Color.Default || xfEndColor == XF.Color.Default) { return; } columnSeries.Style.Palette = CreatePalette(ColorExtensions.ToUIColor(xfStartColor), ColorExtensions.ToUIColor(xfEndColor)); }
/// <inheritdoc/> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var brush = value as SolidColorBrush; if (brush != null) { value = brush.Color; } if (value is Color) { var color = (Color)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } if (value is Color3) { var color = (Color3)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return((Color)color); } if (targetType == typeof(Color3)) { return(color); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbToString(color.ToRgb())); } } if (value is Color4) { var color = (Color4)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return((Color)color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } if (value is System.Windows.Media.Color) { var wpfColor = (System.Windows.Media.Color)value; if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(wpfColor)); } var color = new Color(wpfColor.R, wpfColor.G, wpfColor.B, wpfColor.A); if (targetType == typeof(System.Windows.Media.Color)) { return(color); } if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } var stringColor = value as string; if (stringColor != null) { var intValue = ColorExtensions.StringToRgba(stringColor); if (targetType == typeof(Color)) { return(Color.FromRgba(intValue)); } if (targetType == typeof(Color3)) { return(new Color3(intValue)); } if (targetType == typeof(Color4)) { return(new Color4(intValue)); } if (targetType == typeof(System.Windows.Media.Color)) { return(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255))); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255)))); } if (targetType == typeof(string)) { return(stringColor); } } #if DEBUG if (value == null || value == DependencyProperty.UnsetValue) { return(DependencyProperty.UnsetValue); } throw new NotSupportedException("Requested conversion is not supported."); #else return(DependencyProperty.UnsetValue); #endif }
protected override byte GetValue(int index) { //return (Math.Round((double)(this[index + RedIndex] + this[index + GreenIndex] + this[index]) / 3) < 128) return((ColorExtensions.GetBt601Value(this[index + RedIndex], this[index + GreenIndex], this[index]) < 128) ? Byte.MinValue : Byte.MaxValue); }
public static void LoadGridData(GridView viewTable, GridData data) { using (new UsingProcessor(() => viewTable.BeginUpdate(), () => viewTable.EndUpdate())) { viewTable.GridControl.ForceInitialize(); if (data.Parameters != null) { var gridProperties = new GridProperties((GridView)viewTable); gridProperties.ApplyParameters(data.Parameters); } if (data.ColumnOrder != null && data.ColumnOrder.Count > 0) { var visibleColumns = new List <GridColumn>(); bool hasSummaries = false; int i = 0; foreach (var field in data.ColumnOrder) { if (string.IsNullOrWhiteSpace(field.ColumnName)) { continue; } var column = viewTable.Columns.ColumnByFieldName(field.ColumnName); if (column != null) { column.Visible = true; column.VisibleIndex = i++; visibleColumns.Add(column); column.Summary.Clear(); if (!string.IsNullOrWhiteSpace(field.Summary)) { var summaries = Utils.SplitString(field.Summary, ','); foreach (var summary in summaries) { if (Enum.TryParse <SummaryItemType>(summary, out SummaryItemType summaryType)) { column.Summary.Add(summaryType); hasSummaries = true; } } } } } if (hasSummaries) { viewTable.OptionsView.ShowFooter = true; } } using (new UsingProcessor(() => viewTable.BeginSort(), () => viewTable.EndSort())) { viewTable.ClearGrouping(); viewTable.ClearSorting(); var sortInfos = new List <GridColumnSortInfo>(); int groupColumnCount = 0; if (data.GroupBy != null && data.GroupBy.Count > 0) { foreach (var group in data.GroupBy) { if (string.IsNullOrWhiteSpace(group.ColumnName)) { continue; } var sortAscending = true; var colName = group.ColumnName; if (string.Compare(group.SortOrder, "desc", true) == 0) { sortAscending = false; } var column = viewTable.Columns.ColumnByFieldName(colName); if (column != null) { var colSortInfo = new GridColumnSortInfo(column, sortAscending ? ColumnSortOrder.Ascending : ColumnSortOrder.Descending); sortInfos.Add(colSortInfo); groupColumnCount++; } } } if (data.OrderBy != null && data.OrderBy.Count > 0) { foreach (var orderBy in data.OrderBy) { if (string.IsNullOrWhiteSpace(orderBy.ColumnName)) { continue; } var sortAscending = true; var colName = orderBy.ColumnName; if (string.Compare(orderBy.SortOrder, "desc", true) == 0) { sortAscending = false; } var column = viewTable.Columns.ColumnByFieldName(colName); if (column != null) { var colSortInfo = new GridColumnSortInfo(column, sortAscending ? ColumnSortOrder.Ascending : ColumnSortOrder.Descending); sortInfos.Add(colSortInfo); } } } viewTable.SortInfo.ClearAndAddRange(sortInfos.ToArray(), groupColumnCount); } if (data.FormatConditions != null && data.FormatConditions.Count > 0) { viewTable.FormatConditions.Clear(); foreach (var formatCondition in data.FormatConditions) { GridColumn column = null, targetColumn = null; if (!string.IsNullOrWhiteSpace(formatCondition.ColumnName)) { column = viewTable.Columns.ColumnByFieldName(formatCondition.ColumnName); } if (!string.IsNullOrWhiteSpace(formatCondition.TargetColumn)) { targetColumn = viewTable.Columns.ColumnByFieldName(formatCondition.TargetColumn); } var formatRule = Utils.NonNullString(formatCondition.FormatRule).ToLower(); switch (formatRule) { case "expression": var expression = formatCondition.Expression; if (!string.IsNullOrWhiteSpace(expression)) { var formatExpression = new FormatConditionRuleExpression() { Expression = expression }; var ruleExpression = new GridFormatRule { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = (column == null) || formatCondition.ApplyToRow, Rule = formatExpression }; ApplyFormatting(formatExpression, formatCondition); viewTable.FormatRules.Add(ruleExpression); } break; case "databar": if (column != null) { var ruleDataBar = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatDataBar = new FormatConditionRuleDataBar(); if (string.IsNullOrWhiteSpace(formatCondition.BackColor)) { formatCondition.BackColor = formatCondition.DataBar; } if (!string.IsNullOrWhiteSpace(formatCondition.AppearanceName)) { formatDataBar.PredefinedName = formatCondition.AppearanceName; } else { ApplyAppearance(formatDataBar.Appearance, formatCondition); } ruleDataBar.Rule = formatDataBar; viewTable.FormatRules.Add(ruleDataBar); } break; case "iconset": if (column != null) { if (!Enum.TryParse(formatCondition.IconSet, out IconSetType iconSetType)) { iconSetType = IconSetType.Arrows5; } var ruleIconSet = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatIconSet = new FormatConditionRuleIconSet() { IconSet = GetPredefinedIconSet(iconSetType) }; ruleIconSet.Rule = formatIconSet; viewTable.FormatRules.Add(ruleIconSet); } break; case "colorscale": if (column != null) { string colorScale = formatCondition.ColorScale; if (string.IsNullOrWhiteSpace(colorScale)) { colorScale = "White,Red"; } if (!string.IsNullOrWhiteSpace(colorScale)) { var scales = colorScale.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (scales != null && scales.Length == 2) { var ruleColorScale2 = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatColorScale2 = new FormatConditionRule2ColorScale { MinimumColor = ColorExtensions.FromHtmlColor(scales[0], Color.White), MaximumColor = ColorExtensions.FromHtmlColor(scales[1], Color.Black) }; ruleColorScale2.Rule = formatColorScale2; viewTable.FormatRules.Add(ruleColorScale2); } else if (scales != null && scales.Length >= 3) //Use first 3 colors if more are specified { var ruleColorScale3 = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatColorScale3 = new FormatConditionRule3ColorScale { MinimumColor = ColorExtensions.FromHtmlColor(scales[0], Color.White), MiddleColor = ColorExtensions.FromHtmlColor(scales[1], Color.Gray), MaximumColor = ColorExtensions.FromHtmlColor(scales[2], Color.Black) }; ruleColorScale3.Rule = formatColorScale3; viewTable.FormatRules.Add(ruleColorScale3); } } } break; case "aboveaverage": if (column != null) { var ruleAboveAverage = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatAboveAverage = new FormatConditionRuleAboveBelowAverage() { AverageType = FormatConditionAboveBelowType.Above }; ApplyFormatting(formatAboveAverage, formatCondition); ruleAboveAverage.Rule = formatAboveAverage; viewTable.FormatRules.Add(ruleAboveAverage); } break; case "belowaverage": if (column != null) { var ruleBelowAverage = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatBelowAverage = new FormatConditionRuleAboveBelowAverage() { AverageType = FormatConditionAboveBelowType.Below }; ApplyFormatting(formatBelowAverage, formatCondition); ruleBelowAverage.Rule = formatBelowAverage; viewTable.FormatRules.Add(ruleBelowAverage); } break; case "aboveorequalaverage": if (column != null) { var ruleAboveAverage = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatAboveAverage = new FormatConditionRuleAboveBelowAverage() { AverageType = FormatConditionAboveBelowType.EqualOrAbove }; ApplyFormatting(formatAboveAverage, formatCondition); ruleAboveAverage.Rule = formatAboveAverage; viewTable.FormatRules.Add(ruleAboveAverage); } break; case "beloworequalaverage": if (column != null) { var ruleBelowAverage = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatBelowAverage = new FormatConditionRuleAboveBelowAverage() { AverageType = FormatConditionAboveBelowType.EqualOrBelow }; ApplyFormatting(formatBelowAverage, formatCondition); ruleBelowAverage.Rule = formatBelowAverage; viewTable.FormatRules.Add(ruleBelowAverage); } break; case "unique": if (column != null) { var ruleUnique = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatUnique = new FormatConditionRuleUniqueDuplicate() { FormatType = FormatConditionUniqueDuplicateType.Unique }; ApplyFormatting(formatUnique, formatCondition); ruleUnique.Rule = formatUnique; viewTable.FormatRules.Add(ruleUnique); } break; case "duplicate": if (column != null) { var ruleDuplicate = new GridFormatRule() { Column = column, ColumnApplyTo = targetColumn, ApplyToRow = formatCondition.ApplyToRow }; var formatDuplicate = new FormatConditionRuleUniqueDuplicate() { FormatType = FormatConditionUniqueDuplicateType.Unique }; ApplyFormatting(formatDuplicate, formatCondition); ruleDuplicate.Rule = formatDuplicate; viewTable.FormatRules.Add(ruleDuplicate); } break; case "top": if (column != null) { var rankTop = formatCondition.Rank; var isPercent = !string.IsNullOrWhiteSpace(rankTop) && rankTop.EndsWith("%"); var strRankTop = isPercent ? rankTop[0..^ 1].TrimEnd() : rankTop;
// Generating a palette with numberofcolors, array[numberofcolors][4] where [i][0] = R ; [i][1] = G ; [i][2] = B ; [i][3] = A public static Color[] GeneratePalette(int numberOfColors) { if (numberOfColors < 8) { return(GenerateGrayscale(numberOfColors)); } // Number of points on each edge on the RGB color cube total var colorQNumTotal = (int)Math.Floor(Math.Pow(numberOfColors, 1.0 / 3.0)) * 3; var rgbCube = GenerateRgbCube(numberOfColors); // RGB color cube used for part of the palette; the rest is random return(new Color[numberOfColors].Initialize(i => i < colorQNumTotal ? rgbCube.ElementAt(i) : ColorExtensions.RandomColor())); }
public static System.Windows.Media.Color ToSandboxMediaColor(this SerializableVector3 hsv) { var vColor = ColorExtensions.HSVtoColor(new Vector3(hsv.X, (hsv.Y + 1f) / 2f, (hsv.Z + 1f) / 2f)); return(System.Windows.Media.Color.FromArgb(vColor.A, vColor.R, vColor.G, vColor.B)); }
private static void SetContent(Window hostWindow, UIElement content) { hostWindow.Content = content; ColorExtensions.ReInitAccentColorChanged(); }
internal static void PopulateGenericMenu <T>(IPropertyValueEntry <T> entry, GenericMenu genericMenu) { Color color; if (entry.TypeOfValue == typeof(Color)) { color = (Color)(object)entry.SmartValue; } else { color = (Color32)(object)entry.SmartValue; } Color colorInClipboard; bool hasColorInClipboard = ColorExtensions.TryParseString(EditorGUIUtility.systemCopyBuffer, out colorInClipboard); if (genericMenu.GetItemCount() > 0) { genericMenu.AddSeparator(""); } genericMenu.AddItem(new GUIContent("Copy RGBA"), false, () => { EditorGUIUtility.systemCopyBuffer = entry.SmartValue.ToString(); }); genericMenu.AddItem(new GUIContent("Copy HEX"), false, () => { EditorGUIUtility.systemCopyBuffer = "#" + ColorUtility.ToHtmlStringRGBA(color); }); genericMenu.AddItem(new GUIContent("Copy Color Code Declaration"), false, () => { EditorGUIUtility.systemCopyBuffer = ColorExtensions.ToCSharpColor(color); }); if (hasColorInClipboard) { genericMenu.ReplaceOrAdd("Paste", false, () => { entry.Property.Tree.DelayActionUntilRepaint(() => { SetEntryValue(entry, colorInClipboard); }); GUIHelper.RequestRepaint(); }); } else if (Clipboard.CanPaste(typeof(Color)) || Clipboard.CanPaste(typeof(Color32))) { genericMenu.ReplaceOrAdd("Paste", false, () => { entry.Property.Tree.DelayActionUntilRepaint(() => { SetEntryValue(entry, Clipboard.Paste()); }); GUIHelper.RequestRepaint(); }); } else { genericMenu.AddDisabledItem(new GUIContent("Paste")); } }
private void ChangeResource(string resName, string newValue) { if (!string.IsNullOrEmpty(newValue)) { if (Application.Current.Resources.Contains(resName)) { Application.Current.Resources.Remove(resName); } if (resName.Contains("Size")) { int newSize = 0; if (int.TryParse(newValue, out newSize)) { Application.Current.Resources.Add(resName, newSize); } } else { // first, check for the system resources if (App.Current.Resources.Contains(newValue)) { Application.Current.Resources.Add(resName, Application.Current.Resources[newValue]); } // try to parse color else { try { Application.Current.Resources.Add(resName, new SolidColorBrush(ColorExtensions.FromString(newValue))); } catch { } } } } }
/// <summary> /// Draws color-box /// </summary> protected override void OnPaint(PaintEventArgs e) { // Base painting base.OnPaint(e); // Get graphics context Graphics g = e.Graphics; // Draw colored highlight border using (Pen pen = new Pen(ColorExtensions.AddRGB(Component.SourceTheme.DARK_BASED ? 70 : -70, Color))) { // Rectangular color-box if (Type == ColorBoxType.Circle) { // Turn on anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Clear control using (SolidBrush brush = new SolidBrush(Color)) g.FillEllipse(brush, new Rectangle(new Point(0, 0), new Size(ClientRectangle.Width - 1, ClientRectangle.Height - 1))); // Draw border g.DrawEllipse(pen, new Rectangle(new Point(0, 0), new Size(ClientRectangle.Width - 1, ClientRectangle.Height - 1))); // Turn off anti-aliasing g.SmoothingMode = SmoothingMode.Default; } // Circular color-box if (Type == ColorBoxType.Rectangle) { // Clear control g.Clear(Color); // Draw border g.DrawRectangle(pen, new Rectangle(new Point(0, 0), new Size(ClientRectangle.Width - 1, ClientRectangle.Height - 1))); } } // Is border enabled? if (Selected) { // Calculate foreground color Color foreColor = (ColorExtensions.PerceivedBrightness(Color) > 130 ? Color.Black : Color.White); } // Check-box's height int height = 19; // Middle of check-box int b = Height / 2 - height / 2; // Check-mark points _checkmark = new Point[] { new Point(7, b + 8), new Point(8, b + 9), new Point(9, b + 10), new Point(10, b + 11), new Point(11, b + 12), new Point(12, b + 11), new Point(13, b + 10), new Point(14, b + 9), new Point(15, b + 8), new Point(16, b + 7), new Point(17, b + 6), new Point(18, b + 5), }; // Draws check-mark in animation if (_a == 10 && Selected == true) { // Draws two check-marks with 1 width of pen. Setting pen's // width to 2 pixels causes one missing pixel at bottom of the // check-mark. DrawCheckmarkIn(g); DrawCheckmarkIn(g, 1, 1); } // Draws check-mark out animation if (_a == 10 && Selected == false) { // Draws two check-marks with 1 width of pen. Setting pen's // width to 2 pixels causes one missing pixel at bottom of the // check-mark. DrawCheckmarkOut(g); DrawCheckmarkOut(g, 1, 1); } }
public QColor(float r, float g, float b, float a, bool from256 = true) { SetColor(from256 ? ColorExtensions.ColorFrom256(r, g, b, a) : new Color(r, g, b, a)); }
public QColor(float rDark, float gDark, float bDark, float aDark, float rLight, float gLight, float bLight, float aLight, bool from256 = true) { _dark = from256 ? ColorExtensions.ColorFrom256(rDark, gDark, bDark, aDark) : new Color(rDark, gDark, bDark, aDark); _light = from256 ? ColorExtensions.ColorFrom256(rLight, gLight, bLight, aLight) : new Color(rLight, gLight, bLight, aLight); }
public static SerializableVector3 ToSandboxHsvColor(this System.Windows.Media.Color color) { var vColor = ColorExtensions.ColorToHSV(new Color(color.R, color.G, color.B)); return(new SerializableVector3(vColor.X, vColor.Y * 2f - 1f, vColor.Z * 2f - 1f)); }
private static void generateMapImage() { int mapSize; int width; //#if UNITY_WEBGL if (devMode) { mapSize = 20000; width = 150 + Rand.Get.Next(60); } else { //mapSize = 25000; //width = 170 + Random.Next(65); //mapSize = 30000; //width = 180 + Random.Next(65); mapSize = 40000; width = 250 + Rand.Get.Next(40); } // 140 is sqrt of 20000 //int width = 30 + Random.Next(12); // 140 is sqrt of 20000 //#else // int mapSize = 40000; // int width = 200 + Random.Next(80); //#endif Texture2D mapImage = new Texture2D(width, mapSize / width); // standard for webGL Color emptySpaceColor = Color.black; //.setAlphaToZero(); mapImage.setColor(emptySpaceColor); int amountOfProvince = mapImage.width * mapImage.height / 140 + Rand.Get.Next(5); //amountOfProvince = 400 + Rand.random2.Next(100); for (int i = 0; i < amountOfProvince; i++) { mapImage.SetPixel(mapImage.getRandomX(), mapImage.getRandomY(), ColorExtensions.getRandomColor()); } int emptyPixels = 1;//non zero Color currentColor = mapImage.GetPixel(0, 0); int emergencyExit = 0; while (emptyPixels != 0 && emergencyExit < 100) { emergencyExit++; emptyPixels = 0; for (int j = 0; j < mapImage.height; j++) // circle by province { for (int i = 0; i < mapImage.width; i++) { currentColor = mapImage.GetPixel(i, j); if (currentColor == emptySpaceColor) { emptyPixels++; } else if (currentColor.a == 1f) { mapImage.drawRandomSpot(i, j, currentColor); } } } mapImage.setAlphaToMax(); } mapImage.Apply(); mapTexture = new MyTexture(mapImage); Texture2D.Destroy(mapImage); }
/// <summary> /// Draw item /// </summary> protected override void OnDrawItem(Graphics g, Rectangle bounds) { // Base call base.OnDrawItem(g, bounds); // Default height Height = DIP.Set(70); // String format // Converts alignment types StringFormat format = new StringFormat(); int lNum = (int)Math.Log((double)TextAlign, 2); format.LineAlignment = (StringAlignment)(lNum / 4); format.Alignment = (StringAlignment)(lNum % 4); // Creates color of secondary text Color color = (Owner.Component.SourceTheme.DARK_BASED) ? ColorExtensions.AddRGB(-120, Owner.Component.SourceTheme.COMPONENT_FOREGROUND.Normal) : ColorExtensions.AddRGB(100, Owner.Component.SourceTheme.COMPONENT_FOREGROUND.Normal); // Draws secondary text using (SolidBrush brush = new SolidBrush(color)) g.DrawString(SecondaryText, new Font("Segoe UI", 8), brush, new Rectangle(Bounds.X + 10, Bounds.Y + 12, Bounds.Width - 20, Bounds.Height), format); // Draws primary text using (SolidBrush brush = new SolidBrush(Selected ? Owner.Accent : Owner.Component.SourceTheme.COMPONENT_FOREGROUND.Normal.ToColor())) g.DrawString(PrimaryText, new Font("Segoe UI", 9), brush, new Rectangle(Bounds.X + 10, Bounds.Y - 12, Bounds.Width - 20, Bounds.Height), format); }
/// <summary> /// Draw /// </summary> protected override void OnPaint(PaintEventArgs e) { // Base painting base.OnPaint(e); // Get graphics context Graphics g = e.Graphics; // Client rectangle Rectangle rc = ClientRectangle; // Clear control g.Clear(Parent.BackColor); // Update background color of labels _leftLabel.BackColor = InnerTextBox.BackColor; _rightLabel.BackColor = InnerTextBox.BackColor; // Fill color Color fill = Enabled ? Component.SourceTheme.COMPONENT_BACKGROUND.Normal.ToColor() : Component.SourceTheme.COMPONENT_BACKGROUND.Disabled.ToColor(); // TextBox background color InnerTextBox.BackColor = fill; // Control outline colors Color backgroundColor = fill; // Fill background using (SolidBrush backroundBrush = new SolidBrush(backgroundColor)) g.FillRectangle(backroundBrush, rc); // Draw control outline Color frameColor = ColorExtensions.Mix(Color.FromArgb(_accentAlpha, Enabled ? Component.Accent : Component.SourceTheme.COMPONENT_BORDER.Disabled.ToColor()), Enabled ? Component.SourceTheme.COMPONENT_BORDER.Normal.ToColor() : Component.SourceTheme.COMPONENT_BORDER.Disabled.ToColor()); // Draw borders using (Pen framePen = new Pen(frameColor)) { // Top border if (drawTopBorder) { g.DrawLine(framePen, new Point(0, 0), new Point(Width, 0)); } // Bottom border if (drawBottomBorder) { g.DrawLine(framePen, new Point(0, Height - 1), new Point(Width, Height - 1)); } // Left border if (drawLeftBorder) { g.DrawLine(framePen, new Point(0, 0), new Point(0, Height - 1)); } // Right border if (drawRightBorder) { g.DrawLine(framePen, new Point(Width - 1, 0), new Point(Width - 1, Height - 1)); } } }
set => m_colorList = value?.Select(x => ColorExtensions.FromRGB(x))?.ToList() ?? new List <Color32>();
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); //ToDo move this down - just before command initializations // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var dte = (DTE) await GetServiceAsync(typeof(DTE)); Assumes.Present(dte); var dte2 = (DTE2) await GetServiceAsync(typeof(SDTE)); Assumes.Present(dte2); solService = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution; Assumes.Present(solService); var rdt = await GetServiceAsync(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; Assumes.Present(rdt); //! Set globals DteRefs.Package = this; DteRefs.DTE = dte; DteRefs.DTE2 = dte2; DteRefs.Solution = solService; DteRefs.RDT = rdt; //! Activate MEF ActivateMEF(); //! Get VS editor's background color var vsProperties = dte.Properties["FontsAndColors", "TextEditor"]; var fontsAndColors = vsProperties.Item("FontsAndColorsItems").Object as FontsAndColorsItems; var plainText = fontsAndColors.Item("Plain Text"); //! Set VS editor's background in configs var bg = ColorExtensions.FromInt((int)plainText.Background); commentConfigs.Defaults.VSBackground = Color.FromArgb(255, bg.R, bg.G, bg.B); //! Register classifications //? This might be redundant! clsService.SyncWithConfigs(); //! Hook events solService.AdviseSolutionEvents(ViewModelLocator.Instance, out var cookie); var events = dte2.Events as Events2; if (events != null) { ViewModelLocator.Instance.SubscribeToEvents(events); } //! Handle solution load if (await IsSolutionLoadedAsync()) { //todo Remove this if not used //! Only handle it if it's solution, and ignore it if it's a folder. //solService.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out var value); //if (await IsSolutionLoadedAsync()) //HandleOpenSolution(); // ViewModelLocator.Instance.Scanner.ScanSolution(); } await BookmarksListCommand.InitializeAsync(this); await SettingsCommand.InitializeAsync(this); }
/// <inheritdoc/> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var brush = value as SolidColorBrush; if (brush != null) { value = brush.Color; } if (value is Color) { var color = (Color)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } if (value is Color3) { var color = (Color3)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return((Color)color); } if (targetType == typeof(Color3)) { return(color); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbToString(color.ToRgb())); } } if (value is Color4) { var color = (Color4)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return((Color)color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } if (value is System.Windows.Media.Color) { var wpfColor = (System.Windows.Media.Color)value; if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(wpfColor)); } var color = new Color(wpfColor.R, wpfColor.G, wpfColor.B, wpfColor.A); if (targetType == typeof(System.Windows.Media.Color)) { return(color); } if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } if (value is string) { var stringColor = value as string; uint intValue = 0xFF000000; if (stringColor.StartsWith("#")) { if (stringColor.Length == "#000".Length && UInt32.TryParse(stringColor.Substring(1, 3), NumberStyles.HexNumber, null, out intValue)) { intValue = ((intValue & 0x00F) << 16) | ((intValue & 0x00F) << 20) | ((intValue & 0x0F0) << 4) | ((intValue & 0x0F0) << 8) | ((intValue & 0xF00) >> 4) | ((intValue & 0xF00) >> 8) | (0xFF000000); } if (stringColor.Length == "#000000".Length && UInt32.TryParse(stringColor.Substring(1, 6), NumberStyles.HexNumber, null, out intValue)) { intValue = ((intValue & 0x000000FF) << 16) | (intValue & 0x0000FF00) | ((intValue & 0x00FF0000) >> 16) | (0xFF000000); } if (stringColor.Length == "#00000000".Length && UInt32.TryParse(stringColor.Substring(1, 8), NumberStyles.HexNumber, null, out intValue)) { intValue = ((intValue & 0x000000FF) << 16) | (intValue & 0x0000FF00) | ((intValue & 0x00FF0000) >> 16) | (intValue & 0xFF000000); } } if (targetType == typeof(Color)) { return(Color.FromRgba(intValue)); } if (targetType == typeof(Color3)) { return(new Color3(intValue)); } if (targetType == typeof(Color4)) { return(new Color4(intValue)); } if (targetType == typeof(System.Windows.Media.Color)) { return(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255))); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255)))); } if (targetType == typeof(string)) { return(stringColor); } } throw new NotSupportedException("Requested conversion is not supported."); }
/// <summary> /// Draw /// </summary> protected override void OnPaint(PaintEventArgs e) { // Base call base.OnPaint(e); // Graphics Graphics g = e.Graphics; // Clear control g.Clear(Parent.BackColor); // Fill color, text and border Color fill = new Color(); Color border = new Color(); Color hover = new Color(); Color foreground = new Color(); if (Enabled) { // Enabled fill = Component.SourceTheme.COMPONENT_BACKGROUND.Normal.ToColor(); border = Component.SourceTheme.COMPONENT_BORDER.Normal.ToColor(); foreground = Component.SourceTheme.COMPONENT_FOREGROUND.Normal.ToColor(); hover = Component.SourceTheme.COMPONENT_FILL.Hover.ToColor(); } else { // Disabled fill = Component.SourceTheme.COMPONENT_BACKGROUND.Disabled.ToColor(); border = Component.SourceTheme.COMPONENT_BORDER.Disabled.ToColor(); foreground = Component.SourceTheme.COMPONENT_FOREGROUND.Disabled.ToColor(); hover = Component.SourceTheme.COMPONENT_FILL.Disabled.ToColor(); } // Draw background using (SolidBrush brush = new SolidBrush(fill)) g.FillPath(brush, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set((10)))); // Anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Draw border if (!_state) { using (Pen pen = new Pen(!Checked ? Component.SourceTheme.COMPONENT_BORDER.Normal.ToColor() : Component.Accent, 1)) g.DrawPath(pen, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set(10))); } // Draw mouse hover effect using (SolidBrush brush = new SolidBrush(Color.FromArgb(_hoverAlpha, hover))) g.FillPath(brush, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set(3))); // Animation - inner circle using (SolidBrush brush = new SolidBrush(Enabled ? Component.Accent : Component.SourceTheme.COMPONENT_FILL.Disabled.ToColor())) g.FillPath(brush, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), Convert.ToInt32(_radius))); // Animation - border tint using (Pen pen = new Pen(ColorExtensions.Mix(Color.FromArgb(_tintAlpha, Enabled ? Component.Accent : Component.SourceTheme.COMPONENT_BORDER.Disabled.ToColor()), border))) g.DrawEllipse(pen, new Rectangle(0, 0, DIP.Set(20), DIP.Set(20))); // Anti-aliasing g.SmoothingMode = SmoothingMode.Default; // Draw text using (SolidBrush brush = new SolidBrush(foreground)) g.DrawString(Text, Font, brush, new Point(25 + DIP.Set(8), 2)); }
public XDocument ToDGML() { return(ToDGML(a => a.ToString() ?? "[null]", a => ColorExtensions.ToHtmlColor(a.GetType().FullName.GetHashCode()))); }
/// <summary> /// Frame Renewal /// </summary> /// <param name="gameTime"></param> /// <param name="otherScreenHasFocus"></param> /// <param name="coveredByOtherScreen"></param> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); _shadowColor = ColorExtensions.Rainbow(gameTime); }
public HSLColor(string hex) { var color = ColorExtensions.FromString(hex); SetRGB(color.A, color.R, color.G, color.B); }
public override Color GetColor() => ColorExtensions.Random();
public QColor(float r, float g, float b, float a, bool from256 = true) { _dark = from256 ? ColorExtensions.ColorFrom256(r, g, b, a) : new Color(r, g, b, a); _light = from256 ? ColorExtensions.ColorFrom256(r, g, b, a) : new Color(r, g, b, a); }
public override string ToString() { return($"{(ColorMaskPacked.HasValue ? Utils.ColorMaskToHSVText(ColorExtensions.UnpackHSVFromUint(ColorMaskPacked.Value)) : "(NoColor)")}/{(Skin.HasValue ? Skin.Value.ToString() : "(NoSkinIndex)")}"); }
/// <summary> /// Draw click effect /// </summary> private void DrawClick(PaintEventArgs e) { // Control's graphics object Graphics g = e.Graphics; // ClickEffect if (_clickEffect != ClickEffect.None) { // Color of click effect Color color; Color fill = (_customColor) ? Component.Accent : Component.SourceTheme.COMPONENT_FILL.Normal.ToColor(); if (Component.SourceTheme.DARK_BASED == true) { // Dark based themes color = Color.FromArgb(_clickAlpha, ColorExtensions.AddRGB(150, fill)); } else { // Light based themes color = Color.FromArgb(_clickAlpha, ColorExtensions.AddRGB(-150, fill)); } // Draws click effect // Set up anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Ripple if (_clickEffect == ClickEffect.Ripple) { // Ink's brush and graphics path GraphicsPath ink = Draw.GetEllipsePath(_mouseClickPosition, (int)_radius); // Draws ripple click effect using (SolidBrush brush = new SolidBrush(color)) g.FillPath(brush, ink); } // Square if (_clickEffect == ClickEffect.Square || _clickEffect == ClickEffect.SquareRotate) { // Square's brush and graphics path GraphicsPath square = Draw.GetSquarePath(_mouseClickPosition, (int)_radius); // Rotates square if (_clickEffect == ClickEffect.SquareRotate) { Matrix matrix = new Matrix(); matrix.RotateAt(_rotation, _mouseClickPosition); square.Transform(matrix); } // Draws square click effect using (SolidBrush brush = new SolidBrush(color)) g.FillPath(brush, square); } // Remove anti-aliasing g.SmoothingMode = SmoothingMode.Default; } }