public override void Draw(DrawProperty dp) { if (string.IsNullOrEmpty(Text)) { return; } // Yellow bar var r = dp.PaneRect.Clone(); r.LT = ScreenPos.From(r.L, 0); r.RB = ScreenPos.From(r.R, 2); dp.Graphics.FillRectangle(_(r), BackgroundColor); // Active Template name (Back ground) var tf = new CanvasTextFormat { FontFamily = "Coureir New", FontSize = 11.0f, FontWeight = FontWeights.Normal, WordWrapping = CanvasWordWrapping.NoWrap, }; r.RB = r.LT + GraphicUtil.MeasureString(dp.Canvas, Text, tf) + ScreenSize.From(10, 10); dp.Graphics.FillRectangle(_(r), BackgroundColor); // Active Template name (Text) dp.Graphics.TextAntialiasing = CanvasTextAntialiasing.ClearType; dp.Graphics.DrawText(Text, 4, 2, ColorUtil.GetNegativeColor(BackgroundColor), tf); }
/// <summary> /// Draw 7-seg image /// </summary> /// <param name="dp"></param> /// <param name="format"></param> /// <remarks> /// Format: /// 0-9 ... draw number /// * ... draw Dark 8 /// . ... draw Dot at last position /// , ... draw Dot at last position (dark) /// : ... draw colon /// ; ... draw colon(dark) /// ! ... draw half space /// _ ... draw space /// \b ... back space (1/4) /// </remarks> public void Draw(DrawProperty dp, string format, ScreenPos pos, ScreenY height) { if (LoadStatus != 1) { return; } var x = ScreenX.From(0); var sz0 = ScreenSize.From(Bitmaps['*'].SizeInPixels.Width, Bitmaps['*'].SizeInPixels.Height); var z = height / sz0.Height; var sz = sz0 * z; var sr = ScreenRect.FromLTWH(0, 0, sz.Width, sz.Height); foreach (var c in format) { if (SpaceAdjust.TryGetValue(c, out var adjust)) { x += sz.Width * adjust; } var bmp = Bitmaps.GetValueOrDefault(c, null); if (bmp != null) { dp.Graphics.DrawImage(bmp, _(sr + pos + x)); } x += sz.Width; } }
/// <summary> /// Initialize feature /// </summary> public override void OnInitialInstance() { base.OnInitialInstance(); Pane.Target = Pane["ToolBox"]; // Tool box background Parts.Add(Pane.Target, new PartsToolBox { }, LAYER.ToolButtonBox); var x = ScreenX.From(0); var y = ScreenY.From(48); var btnSize = ScreenSize.From(24, 24); var marginY = ScreenY.From(8); for (var i = 0; i < Buttons.Count; i++) { var btn = Buttons[i]; btn.Name = string.IsNullOrEmpty(btn.Name) ? btn.GetType().Name : btn.Name; btn.Size = btnSize; btn.Location = CodePos <ScreenX, ScreenY> .From(x, y); var dmy = btn.Load(View); // dmy = thread control Parts.Add(Pane.Target, btn, LAYER.ToolButtons); y += btnSize.Height + marginY; } }
public override void Draw(DrawProperty dp) { if (Seg7?.IsLoaded == false) { return; } var pos = dp.PaneRect.RB - ScreenSize.From(420, 40); var now = Parent.Now; Seg7.Draw(dp, "****,!**,!**_**\b;\b**\b;\b**", pos, Height); if (now != DateTime.MinValue) { var timestr = $"{now.Year}.!{StrUtil.Right($"_{now.Month}", 2)}.!{StrUtil.Right($"_{now.Day}", 2)}_{StrUtil.Right($"_{now.Hour}", 2)}\b:\b{StrUtil.Right($"0{now.Minute}", 2)}\b:\b{StrUtil.Right($"0{now.Second}", 2)}"; Seg7.Draw(dp, timestr, pos, Height); // Sim Time Caption dp.Graphics.DrawText($"Sim time :", pos.X - ScreenX.From(8), pos.Y + ScreenY.From(20), Colors.Cyan, new CanvasTextFormat { FontFamily = "Tahoma", FontSize = 11f, FontWeight = FontWeights.Normal, HorizontalAlignment = CanvasHorizontalAlignment.Right, }); } // Current Local Time dp.Graphics.DrawText($"Actual time : {DateTime.Now.ToString(TimeUtil.FormatYMDHMS)}", dp.PaneRect.R - ScreenX.From(64), pos.Y - ScreenY.From(24), Colors.DarkGray, new CanvasTextFormat { FontFamily = "Tahoma", FontSize = 11f, FontWeight = FontWeights.Normal, HorizontalAlignment = CanvasHorizontalAlignment.Right, }); }
/// <summary> /// title bar design /// </summary> /// <param name="dp"></param> /// <param name="sr">log panel drawing area</param> /// <returns></returns> protected virtual ScreenY drawTitleBar(DrawProperty dp, ScreenRect sr) { var _bd = new CanvasSolidColorBrush(dp.Canvas, Color.FromArgb(64, 0, 0, 0)); var titleHeight = 8; var w3 = sr.Width / 4; var pst = new ScreenPos[] { ScreenPos.From(sr.LT.X, sr.LT.Y + titleHeight + 16), ScreenPos.From(sr.LT.X, sr.LT.Y), ScreenPos.From(sr.RB.X, sr.LT.Y), }; var psb = new ScreenPos[] { ScreenPos.From(sr.RB.X, sr.LT.Y + titleHeight), ScreenPos.From(sr.RB.X - w3, sr.LT.Y + titleHeight + 2), ScreenPos.From(sr.RB.X - w3 * 2, sr.LT.Y + titleHeight + 8), ScreenPos.From(sr.RB.X - w3 * 3, sr.LT.Y + titleHeight + 16), ScreenPos.From(sr.LT.X, sr.LT.Y + titleHeight + 16), }; var ps = pst.Union(psb).ToList(); var path = new CanvasPathBuilder(dp.Canvas); path.BeginFigure(ps[0]); for (var i = 1; i < ps.Count; i++) { path.AddLine(ps[i]); } path.EndFigure(CanvasFigureLoop.Closed); var geo = CanvasGeometry.CreatePath(path); dp.Graphics.FillGeometry(geo, _bd); // edge highlight for (var i = 1; i < pst.Length; i++) { dp.Graphics.DrawLine(pst[i - 1], pst[i], Color.FromArgb(96, 255, 255, 255)); } // edge shadow for (var i = 1; i < psb.Length; i++) { dp.Graphics.DrawLine(psb[i - 1], psb[i], Color.FromArgb(96, 0, 0, 0)); } // title bar design var btr = sr.Clone(); btr.RB = ScreenPos.From(btr.LT.X + ScreenX.From(24), btr.LT.Y + ScreenY.From(12)); btr = btr + ScreenPos.From(4, 4); var imgttl = Assets.Image("LogPanelTitileDesign"); if (imgttl != null) { dp.Graphics.DrawImage(imgttl, btr.LT + ScreenSize.From(-3, -14)); } btr = btr + ScreenX.From(50); // title filter buttons var btn1 = Assets.Image("btnLogPanel"); var btn0 = Assets.Image("btnLogPanelOff"); if (btn1 != null && btn0 != null) { var ctfb = new CanvasTextFormat { FontFamily = "Arial", FontSize = 10.0f, FontWeight = FontWeights.Normal, FontStyle = FontStyle.Italic, }; foreach ((var lv, var caption) in new (LLV, string)[] { (LLV.ERR, "e"), (LLV.WAR, "w"), (LLV.INF, "i"), (LLV.DEV, "d") })
/// <summary> /// check font size /// </summary> /// <param name="resourceCreator">canvas</param> /// <param name="text">measure text</param> /// <param name="textFormat">the text format</param> /// <param name="limitedToWidth">0=auto</param> /// <param name="limitedToHeight">0=auto</param> /// <returns></returns> public static ScreenSize MeasureString(ICanvasResourceCreator resourceCreator, string text, CanvasTextFormat textFormat, float limitedToWidth = 0.0f, float limitedToHeight = 0.0f) { var tmp = textFormat.WordWrapping; if (limitedToHeight < 0.001f && limitedToWidth < 0.001f) { textFormat.WordWrapping = CanvasWordWrapping.NoWrap; } var layout = new CanvasTextLayout(resourceCreator, text, textFormat, limitedToWidth, limitedToHeight); textFormat.WordWrapping = tmp; return(ScreenSize.From(layout.DrawBounds.Width, layout.DrawBounds.Height)); }
public override void Draw(DrawProperty dp) { if (string.IsNullOrEmpty(Text) || string.IsNullOrWhiteSpace(Text)) { return; } var tf = new CanvasTextFormat { FontFamily = "Segoe UI", FontSize = 11.0f, FontStyle = FontStyle.Normal, FontStretch = FontStretch.Normal, FontWeight = FontWeights.Normal, WordWrapping = CanvasWordWrapping.NoWrap, Direction = CanvasTextDirection.LeftToRightThenTopToBottom, HorizontalAlignment = CanvasHorizontalAlignment.Left, LineSpacing = 2.0f, OpticalAlignment = CanvasOpticalAlignment.Default, Options = CanvasDrawTextOptions.Default, VerticalAlignment = CanvasVerticalAlignment.Top, VerticalGlyphOrientation = CanvasVerticalGlyphOrientation.Default, }; var ssz0 = GraphicUtil.MeasureString(dp.Canvas, Text, tf); var ssz = ssz0.Clone(); var sp = ScreenPos.From(Location.X.Cx, Location.Y.Cy); if (IsUpperPositionDefault) { sp += ScreenX.From(8); sp -= ScreenY.From(32); } else { sp -= ssz.Width; // adjust tooltip position sp += ScreenY.From(24); } if (sp.X < 0) { sp.X = ScreenX.From(0); } var sr = ScreenRect.From(sp, ssz + ScreenSize.From(12, 12)); sp += ScreenPos.From(6, 4); // padding dp.Graphics.FillRectangle(_(sr), Color.FromArgb(0xee, 0xdd, 0xdd, 0xdd)); dp.Graphics.DrawRectangle(_(sr), Color.FromArgb(0xff, 0x88, 0x88, 0x88)); dp.Graphics.DrawText(Text, sp + ssz0.Height, Color.FromArgb(0xff, 0x00, 0x00, 0x00), tf); }
/// <summary> /// Visualize /// </summary> /// <param name="dp"></param> public override void Draw(DrawProperty dp) { // Connector grip size var lcsz = LayoutSize.From(PositionerX(CodeX <Distance> .From(Width), null), PositionerY(null, CodeY <Distance> .From(Height))); var scsz = ScreenSize.From(dp.Pane, lcsz); // Process Size var spsz0 = ScreenSize.From(dp.Pane, LayoutSize.From(PositionerX(CodeX <Distance> .From(ProcessFrom.Width), null), PositionerY(null, CodeY <Distance> .From(ProcessFrom.Height)))); var spsz1 = ScreenSize.From(dp.Pane, LayoutSize.From(PositionerX(CodeX <Distance> .From(ProcessTo.Width), null), PositionerY(null, CodeY <Distance> .From(ProcessTo.Height)))); var sc0 = ProcessFrom.GetScreenPos(dp.Pane); var sc1 = ProcessTo.GetScreenPos(dp.Pane); _angle0 = GeoEu.Angle(sc0.X.Sx, sc0.Y.Sy, sc1.X.Sx, sc1.Y.Sy); var k0 = GeoEu.GetLocationOfInscribedSquareInCircle(_angle0); var sr0 = ScreenRect.FromCS(ScreenPos.From(sc0.X + k0.X * (spsz0.Width + scsz.Width) / MathUtil.Root2, sc0.Y + -k0.Y * (spsz0.Height + scsz.Height) / MathUtil.Root2), scsz); var a1 = GeoEu.Angle(sc1.X.Sx, sc1.Y.Sy, sc0.X.Sx, sc0.Y.Sy); var k1 = GeoEu.GetLocationOfInscribedSquareInCircle(a1); var sr1 = ScreenRect.FromCS(ScreenPos.From(sc1.X + k1.X * (spsz1.Width + scsz.Width) / MathUtil.Root2, sc1.Y + -k1.Y * (spsz1.Height + scsz.Height) / MathUtil.Root2), scsz); _p0 = sr0.C + ScreenPos.From(k0.X * sr0.Width / MathUtil.Root2, -k0.Y * sr0.Height / MathUtil.Root2); _p1 = sr1.C; // from: on the grip edge switch (State) { case States.SELECTING: dp.Graphics.DrawLine(_(_p0), _(_p1), Colors.Red); break; case States.HOVER: dp.Graphics.DrawLine(_(_p0), _(_p1), Colors.Cyan); break; default: dp.Graphics.DrawLine(_(_p0), _(_p1), Colors.White); break; } dp.Graphics.DrawRectangle(_(sr0), Colors.White); dp.Graphics.FillRectangle(_(sr1), Colors.White); }
/// <summary> /// Drawing main /// </summary> /// <param name="dp"></param> public override void Draw(DrawProperty dp) { var lpos = GetLayoutPos(); var sc = ScreenPos.From(dp.Pane, lpos); var lsiz = LayoutSize.From(PositionerX(CodeX <Distance> .From(Width), null), PositionerY(null, CodeY <Distance> .From(Height))); var ssiz = ScreenSize.From(dp.Pane, lsiz); var sr = ScreenRect.FromCWH(sc, ssiz.Width, ssiz.Height); if (IsSelected) { // draw the requested position indicator (on the inscribed square in the circle) var A = GetAngle(lpos); var lposIn = GetLayoutPos(A); var scIn = ScreenPos.From(dp.Pane, lposIn); var srIn = ScreenRect.FromCWH(scIn, ssiz.Width, ssiz.Height); dp.Graphics.DrawLine(_(scIn), _(sc), ConnectingColor); if (Design == Designs.IN) { dp.Graphics.FillRectangle(_(srIn), Colors.DarkGray); } else { dp.Graphics.DrawRectangle(_(srIn), Colors.DarkGray); } // draw selected color dp.Graphics.DrawRectangle(_(sr), SelectingColor, 4f); dp.Graphics.FillRectangle(_(sr), SelectingColor); } if (Design == Designs.IN) { dp.Graphics.FillRectangle(_(sr), GetColor(dp)); } else { dp.Graphics.DrawRectangle(_(sr), GetColor(dp)); } SelectableSize = sr.ToSize(); }
/// <summary> /// Drawing main /// </summary> /// <param name="dp"></param> public override void Draw(DrawProperty dp) { var sc = GetScreenPos(dp.Pane); var lsiz = LayoutSize.From(PositionerX(CodeX <Distance> .From(Width), null), PositionerY(null, CodeY <Distance> .From(Height))); var ssiz = ScreenSize.From(dp.Pane, lsiz); var sr = ScreenRect.FromCWH(sc, ssiz.Width, ssiz.Height); SelectableSize = sr.ToSize(); dp.Graphics.DrawRectangle(_(sr), GetColor(dp)); if (IsConnecting) { dp.Graphics.DrawRectangle(_(sr), ConnectingColor, 4f); return; } if (IsSelected) { dp.Graphics.DrawRectangle(_(sr), SelectingColor, 4f); return; } }