public void Draw(TextBuilder text, TextBatcher textBatcher, DemoSet demoSet, Vector2 position, float textHeight, Vector3 textColor, Font font) { if (TrackingInput) { text.Clear().Append("Swap demo to: "); if (TargetDemoIndex >= 0) { text.Append(TargetDemoIndex); } else { text.Append("_"); } textBatcher.Write(text, position, textHeight, textColor, font); var lineSpacing = textHeight * 1.1f; position.Y += textHeight * 0.5f; textHeight *= 0.8f; for (int i = 0; i < demoSet.Count; ++i) { position.Y += lineSpacing; text.Clear().Append(demoSet.GetName(i)); textBatcher.Write(text.Clear().Append(i).Append(": ").Append(demoSet.GetName(i)), position, textHeight, textColor, font); } } }
public override void Render(Renderer renderer, Camera camera, Input input, TextBuilder text, Font font) { renderer.TextBatcher.Write(text.Clear().Append("Substep count: ").Append(timestepper.SubstepCount), new Vector2(16, renderer.Surface.Resolution.Y - 64), 16, new Vector3(1), font); renderer.TextBatcher.Write(text.Clear().Append("Solver iteration count: ").Append(Simulation.Solver.IterationCount), new Vector2(16, renderer.Surface.Resolution.Y - 48), 16, new Vector3(1), font); renderer.TextBatcher.Write(text.Clear().Append("Press Z/X to change substep count, C/V to change solver iteration count."), new Vector2(16, renderer.Surface.Resolution.Y - 32), 16, new Vector3(1), font); rolloverInfo.Render(renderer, camera, input, text, font); base.Render(renderer, camera, input, text, font); }
public static void RenderIncomingLog(Renderer Renderer, Vector2 Position, float FontSize, Vector3 FontColor, Font FontType) { List <Message> ReversedInLog = new List <Message>(); IncomingLog.ForEach((Message) => { ReversedInLog.Add(new Message(Message)); }); ReversedInLog.Reverse(); Renderer.TextBatcher.Write(IncomingLogText.Clear().Append("---Incoming Packets Log---"), Position, FontSize, FontColor, FontType); Position.Y += FontSize * 1.5f; foreach (Message Message in ReversedInLog) { Renderer.TextBatcher.Write(IncomingLogText.Clear().Append(Message.MessageContent), Position, FontSize, FontColor, FontType); Position.Y += FontSize * 1.2f; } }
//Renders the current contents of each log to the window UI public static void RenderOutgoingLog(Renderer Renderer, Vector2 Position, float FontSize, Vector3 FontColor, Font FontType) { //Create a reversed copy of the outgoing messages log List <Message> ReversedOutLog = new List <Message>(); OutgoingLog.ForEach((Message) => { ReversedOutLog.Add(new Message(Message)); }); ReversedOutLog.Reverse(); Renderer.TextBatcher.Write(OutgoingLogText.Clear().Append("---Outgoing Packets Log---"), Position, FontSize, FontColor, FontType); Position.Y += FontSize * 1.5f; foreach (Message Message in ReversedOutLog) { Renderer.TextBatcher.Write(OutgoingLogText.Clear().Append(Message.MessageContent), Position, FontSize, FontColor, FontType); Position.Y += FontSize * 1.2f; } }
public override void Render(Renderer renderer, Camera camera, Input input, TextBuilder text, Font font) { RenderCount++; text.Clear().Append(_currentStats); renderer.TextBatcher.Write(text, new Vector2(20, renderer.Surface.Resolution.Y - 20), 16, new Vector3(1, 1, 1), font); }
public override void Render(Renderer renderer, Camera camera, Input input, TextBuilder text, Font font) { float textHeight = 16; var position = new Vector2(32, renderer.Surface.Resolution.Y - textHeight * 9); renderer.TextBatcher.Write(text.Clear().Append("Toggle character: C"), position, textHeight, new Vector3(1), font); position.Y += textHeight * 1.2f; character.CharacterInputt.RenderControls(position, textHeight, renderer.TextBatcher, text, font); character.CharacterInputt.UpdateCameraPosition(camera); base.Render(renderer, camera, input, text, font); }
protected override void OnFocusDeactivate() { Alex.Instance.IsMouseVisible = false; TextBuilder.Clear(); Value = string.Empty; ResetTabComplete(); TextElement.Text = string.Empty; Dismiss(); }
public void Dismiss() { //Enabled = false; //Focused = false; _scrollValue = 0; TextBuilder.Clear(); Value = string.Empty; TextElement.Text = string.Empty; }
public List <string> SplitOfChar(string value, char c) { List <string> s = new List <string>(); using (TextBuilder b = new TextBuilder()) { for (int i = 0; i < value.Length; i++) { if (i == value.Length - 1) { b.Append(value[i]); s.Add(b.ToString()); b.Clear(); } if (value[i] == c) { s.Add(b.ToString()); b.Clear(); } } } return(s); }
public bool StringContains(string value, string searchvalue) { bool b = false; using (TextBuilder builder = new TextBuilder()) { for (int i = 0; i < value.Length; i++) { if (char.IsWhiteSpace(value[i])) { if (builder.Length > 0) { if (builder.ToString() == searchvalue) { b = true; builder.Clear(); break; } } } if (i == value.Length - 1) { builder.Append(value[i]); if (builder.Length > 0) { if (builder.ToString() == searchvalue) { b = true; builder.Clear(); break; } } } } } return(b); }
//Renders all the messages to the window UI public static void RenderLog(Renderer Renderer, Vector2 Position, float FontSize, Vector3 FontColor, Font FontType) { //Create a reversed copy of the previous messages log List <Message> ReversedMessages = new List <Message>(); LogMessages.ForEach((Message) => { ReversedMessages.Add(new Message(Message)); }); ReversedMessages.Reverse(); //Loop through and render each message to the UI foreach (Message Message in ReversedMessages) { //Display each message on its own line, then move down to the next line for the next message Renderer.TextBatcher.Write(LogText.Clear().Append(Message.MessageContent), Position, FontSize, FontColor, FontType); Position.Y += FontSize * 1.2f; } }
public void FetchForOneToOneByTextBuilder() { TextBuilder textBuilder = new TextBuilder(@" select * from customers c"); textBuilder.Append(@" inner join {{join}} on c.businessId = b.businessId", new { join = "business b" }); textBuilder.Append(@" inner join customerPurchases cp on {{on}} order by {{order}}", new { on = "c.customerId = cp.customerId", order = "c.customerId, cp.no" }); string sql = textBuilder.Generate(); IDagentDatabase database = new DagentDatabase("SQLite"); List <CustomerWithBusiness> customers = database.Query <CustomerWithBusiness>(sql) .Unique("customerId") .Each((model, row) => { row.Map(model, x => x.Business, "businessName").Do(); row.Map(model, x => x.CustomerPurchases, "no").Do(); }) .List(); ValidList(customers); sql = textBuilder.Clear().Generate(); Assert.AreEqual("", sql); }
/// <summary> /// Converts the given HTML to plain text and returns the result. /// </summary> /// <param name="html">HTML to be converted</param> /// <returns>Resulting plain text</returns> public string Convert(string html) { // Initialize state variables _text = new TextBuilder(); _html = html; _pos = 0; // Process input while (!EndOfText) { if (Peek() == '<') { // HTML tag bool selfClosing; var tag = ParseTag(out selfClosing); // Handle special tag cases if (tag == "body") { // Discard content before <body> _text.Clear(); } else if (tag == "/body") { // Discard content after </body> _pos = _html.Length; } else if (tag == "pre") { // Enter preformatted mode _text.Preformatted = true; EatWhitespaceToNextLine(); } else if (tag == "/pre") { // Exit preformatted mode _text.Preformatted = false; } string value; if (_tags.TryGetValue(tag, out value)) { _text.Write(value); } if (_ignoreTags.Contains(tag)) { EatInnerContent(tag); } } else if (Char.IsWhiteSpace(Peek())) { // Whitespace (treat all as space) _text.Write(_text.Preformatted ? Peek() : ' '); MoveAhead(); } else { // Other text _text.Write(Peek()); MoveAhead(); } } // Return result return(HttpUtility.HtmlDecode(_text.ToString())); }
public override void Render(Renderer renderer, Camera camera, Input input, TextBuilder text, Font font) { text.Clear().Append("Press Q to launch a ball!"); renderer.TextBatcher.Write(text, new Vector2(20, renderer.Surface.Resolution.Y - 20), 16, new Vector3(1, 1, 1), font); base.Render(renderer, camera, input, text, font); }
/// <summary> /// Converts the given HTML to plain text and returns the result. /// </summary> /// <param name="html">HTML to be converted</param> /// <returns>Resulting plain text</returns> public string Convert(string html) { // Initialize state variables _text = new TextBuilder(); _html = html; _pos = 0; var lastLink = string.Empty; // Process input while (!EndOfText) { if (Peek() == '<') { // HTML tag bool selfClosing; Dictionary<string, string> attributes; string tag = ParseTag(out selfClosing, out attributes); // Handle special tag cases if (tag == "body") { // Discard content before <body> _text.Clear(); } else if (tag == "/body") { // Discard content after </body> _pos = _html.Length; } else if (tag == "pre") { // Enter preformatted mode _text.Preformatted = true; EatWhitespaceToNextLine(); } else if (tag == "/pre") { // Exit preformatted mode _text.Preformatted = false; } else if (tag == "a") { // Store link mode if (attributes.ContainsKey("href")) { lastLink = attributes["href"]; } } else if (tag == "/a") { // Write link if (!string.IsNullOrWhiteSpace(lastLink)) { _text.Write(string.Format(" ({0})", lastLink)); lastLink = string.Empty; } } string value; if (_tags.TryGetValue(tag, out value)) _text.Write(value); if (_ignoreTags.Contains(tag)) EatInnerContent(tag); } else if (Char.IsWhiteSpace(Peek())) { // Whitespace (treat all as space) _text.Write(_text.Preformatted ? Peek() : ' '); MoveAhead(); } else { // Other text _text.Write(Peek()); MoveAhead(); } } // Return result return HttpUtility.HtmlDecode(_text.ToString()); }
/// <summary> /// Converts the given HTML to plain text and returns the result. /// </summary> /// <param name="html">HTML to be converted</param> /// <returns>Resulting plain text</returns> public string Convert(string html) { // Initialize state variables _text = new TextBuilder(); _html = html; _pos = 0; // Process input while (!EndOfText) { if (Peek() == '<') { // HTML tag bool selfClosing; string tag = ParseTag(out selfClosing); // Handle special tag cases if (tag == "body") { // Discard content before <body> _text.Clear(); } else if (tag == "/body") { // Discard content after </body> _pos = _html.Length; } else if (tag == "pre") { // Enter preformatted mode _text.Preformatted = true; EatWhitespaceToNextLine(); } else if (tag == "/pre") { // Exit preformatted mode _text.Preformatted = false; } string value; if (_tags.TryGetValue(tag, out value)) _text.Write(value); if (_ignoreTags.Contains(tag)) EatInnerContent(tag); } else if (Char.IsWhiteSpace(Peek())) { // Whitespace (treat all as space) _text.Write(_text.Preformatted ? Peek() : ' '); MoveAhead(); } else { // Other text _text.Write(Peek()); MoveAhead(); } } // Return result return HttpUtility.HtmlDecode(_text.ToString()); }
public override void Render(Renderer renderer, TextBuilder text, Font font) { text.Clear().Append("Press Q to create an ICO."); renderer.TextBatcher.Write(text, new Vector2(20, renderer.Surface.Resolution.Y - 20), 16, new Vector3(1, 1, 1), font); base.Render(renderer, text, font); }
public override void Render(Renderer renderer, Camera camera, Input input, TextBuilder text, Font font) { text.Clear().Append("Press Z to shoot a bullet, press X to super shootie patootie!"); renderer.TextBatcher.Write(text, new Vector2(20, renderer.Surface.Resolution.Y - 20), 16, new Vector3(1, 1, 1), font); base.Render(renderer, camera, input, text, font); }
public void Draw(TextBuilder characters, UILineBatcher lines, TextBatcher text) { //Collect information to define data window ranges. int minX = int.MaxValue; int maxX = int.MinValue; var minY = double.MaxValue; var maxY = double.MinValue; for (int i = 0; i < graphSeries.Count; ++i) { var data = graphSeries[i].Data; if (minX > data.Start) { minX = data.Start; } if (maxX < data.End) { maxX = data.End; } for (int j = data.Start; j < data.End; ++j) { var value = data[j]; if (minY > value) { minY = value; } if (maxY < value) { maxY = value; } } } //If no data series contain values, then just use a default size. if (minY == float.MinValue) { minY = 0; maxY = 1; } //You could make use of this earlier to avoid comparisons but it doesn't really matter! if (description.ForceVerticalAxisMinimumToZero) { minY = 0; if (maxY < 0) { maxY = 1; } } //Calculate the data span that takes into account rounding. We want intervals to be evenly spaced, but also to match nicely rounded numbers. //That means the span must be equal to some rounded number multiplied by the number of intervals. var yDataSpan = maxY - minY; var yIntervalCount = description.TargetVerticalTickCount + 1; var rawIntervalLength = yDataSpan / yIntervalCount; var roundingOffset = 0.5 * Math.Pow(0.1, description.VerticalIntervalLabelRounding); yDataSpan = Math.Round(rawIntervalLength * description.VerticalIntervalValueScale + roundingOffset, description.VerticalIntervalLabelRounding) * (yIntervalCount / description.VerticalIntervalValueScale); //Draw the graph body axes. var lowerLeft = description.BodyMinimum + new Vector2(0, description.BodySpan.Y); var upperRight = description.BodyMinimum + new Vector2(description.BodySpan.X, 0); var lowerRight = description.BodyMinimum + description.BodySpan; lines.Draw(description.BodyMinimum, lowerLeft, description.AxisLineRadius, description.BodyLineColor); lines.Draw(lowerLeft, lowerRight, description.AxisLineRadius, description.BodyLineColor); //Draw axis labels. characters.Clear().Append(description.HorizontalAxisLabel); var baseAxisLabelDistance = description.IntervalTickLength + description.IntervalTextHeight * description.LineSpacingMultiplier; var verticalAxisLabelDistance = baseAxisLabelDistance + 2 * description.VerticalTickTextPadding; var horizontalAxisLabelDistance = baseAxisLabelDistance + 2 * description.HorizontalTickTextPadding + description.AxisLabelHeight * description.LineSpacingMultiplier; text.Write(characters, lowerLeft + new Vector2((description.BodySpan.X - GlyphBatch.MeasureLength(characters, description.Font, description.AxisLabelHeight)) * 0.5f, horizontalAxisLabelDistance), description.AxisLabelHeight, description.TextColor, description.Font); characters.Clear().Append(description.VerticalAxisLabel); text.Write(characters, description.BodyMinimum + new Vector2(-verticalAxisLabelDistance, (description.BodySpan.Y + GlyphBatch.MeasureLength(characters, description.Font, description.AxisLabelHeight)) * 0.5f), description.AxisLabelHeight, new Vector2(0, -1), description.TextColor, description.Font); //Position tickmarks, tick labels, and background lines along the axes. { var xDataIntervalSize = (maxX - minX) / (description.TargetHorizontalTickCount + 1f); var previousTickValue = int.MinValue; float valueToPixels = description.BodySpan.X / (maxX - minX); for (int i = 0; i < description.TargetHorizontalTickCount + 2; ++i) { //Round pen offset such that the data tick lands on an integer. var valueAtTick = i * xDataIntervalSize; var tickValue = (int)Math.Round(valueAtTick); if (tickValue == previousTickValue) { //Don't bother creating redundant ticks. continue; } previousTickValue = tickValue; var penPosition = lowerLeft + new Vector2(tickValue * valueToPixels, 0); var tickEnd = penPosition + new Vector2(0, description.IntervalTickLength); var backgroundEnd = penPosition - new Vector2(0, description.BodySpan.Y); lines.Draw(penPosition, tickEnd, description.IntervalTickRadius, description.BodyLineColor); lines.Draw(penPosition, backgroundEnd, description.BackgroundLineRadius, description.BodyLineColor); characters.Clear().Append(tickValue); text.Write(characters, tickEnd + new Vector2(GlyphBatch.MeasureLength(characters, description.Font, description.IntervalTextHeight) * -0.5f, description.HorizontalTickTextPadding + description.IntervalTextHeight * description.LineSpacingMultiplier), description.IntervalTextHeight, description.TextColor, description.Font); } } { var yDataIntervalSize = yDataSpan / (description.TargetVerticalTickCount + 1f); var previousTickValue = double.MinValue; //Note the inclusion of the scale. Rounding occurs post-scale; moving back to pixels requires undoing the scale. var valueToPixels = description.BodySpan.Y / (yDataSpan * description.VerticalIntervalValueScale); for (int i = 0; i < description.TargetVerticalTickCount + 2; ++i) { var tickValue = Math.Round((minY + yDataIntervalSize * i) * description.VerticalIntervalValueScale, description.VerticalIntervalLabelRounding); if (tickValue == previousTickValue) { //Don't bother creating redundant ticks. continue; } previousTickValue = tickValue; var penPosition = lowerLeft - new Vector2(0, (float)(tickValue * valueToPixels)); var tickEnd = penPosition - new Vector2(description.IntervalTickLength, 0); var backgroundEnd = penPosition + new Vector2(description.BodySpan.X, 0); lines.Draw(penPosition, tickEnd, description.IntervalTickRadius, description.BodyLineColor); lines.Draw(penPosition, backgroundEnd, description.BackgroundLineRadius, description.BodyLineColor); characters.Clear().Append(tickValue, description.VerticalIntervalLabelRounding); text.Write(characters, tickEnd + new Vector2(-description.VerticalTickTextPadding, 0.5f * GlyphBatch.MeasureLength(characters, description.Font, description.IntervalTextHeight)), description.IntervalTextHeight, new Vector2(0, -1), description.TextColor, description.Font); } } //Draw the line graphs on top of the body. { var dataToPixelsScale = new Vector2(description.BodySpan.X / (maxX - minX), (float)(description.BodySpan.Y / yDataSpan)); Vector2 DataToScreenspace(int x, double y) { var graphCoordinates = new Vector2(x - minX, (float)(y - minY)) * dataToPixelsScale; var screenCoordinates = graphCoordinates; screenCoordinates.Y = description.BodySpan.Y - screenCoordinates.Y; screenCoordinates += description.BodyMinimum; return(screenCoordinates); } for (int i = 0; i < graphSeries.Count; ++i) { var series = graphSeries[i]; var data = series.Data; var count = data.End - data.Start; if (count > 0) { var previousScreenPosition = DataToScreenspace(data.Start, data[data.Start]); if (count > 1) { for (int j = data.Start + 1; j < data.End; ++j) { var currentScreenPosition = DataToScreenspace(j, data[j]); lines.Draw(previousScreenPosition, currentScreenPosition, series.LineRadius, series.LineColor); previousScreenPosition = currentScreenPosition; } } else { //Only one datapoint. Draw a zero length line just to draw a dot. (The shader can handle it without producing nans.) lines.Draw(previousScreenPosition, previousScreenPosition, series.LineRadius, series.LineColor); } } } } //Draw the legend entry last. Alpha blending will put it on top in case the legend is positioned on top of the body. { var penPosition = description.LegendMinimum; var legendLineSpacing = description.LegendNameHeight * 1.5f; penPosition.Y += legendLineSpacing; for (int i = 0; i < graphSeries.Count; ++i) { var series = graphSeries[i]; var lineStart = new Vector2(penPosition.X, penPosition.Y); var lineEnd = lineStart + new Vector2(description.LegendLineLength, -0.7f * description.LegendNameHeight); lines.Draw(lineStart, lineEnd, series.LineRadius, series.LineColor); var textStart = new Vector2(lineEnd.X + series.LineRadius + description.LegendNameHeight * 0.2f, penPosition.Y); characters.Clear().Append(series.Name); text.Write(characters, textStart, description.LegendNameHeight, description.TextColor, description.Font); penPosition.Y += legendLineSpacing; } } }
//Draws the current content typed into the command input field public void Render(Renderer Renderer, Vector2 Position, float FontSize, Vector3 FontColor, Font FontType) { Renderer.TextBatcher.Write(TextBuilder.Clear().Append(PreInput + MessageInput), Position, FontSize, FontColor, FontType); }
protected override bool OnKeyInput(char character, Keys key) { if (Focused) { if (key == Keys.Tab) { if (_hasTabCompleteResults) { DoTabComplete(true); _prevWasTab = true; return(true); } if (TextBuilder.Length == 0) { return(true); } TextBuilder.CursorPosition = 1; string text = TextBuilder.GetAllBehindCursor(out _tabCompletePosition); if (text.StartsWith('/')) { _tabCompletePosition += 1; text = text.Substring(1, text.Length - 1); } ChatProvider?.RequestTabComplete(text, out _latestTransactionId); return(true); } else if (key == Keys.Enter) { SubmitMessage(); ResetTabComplete(); } else if (key == Keys.Up && _currentNode != null) { if (_submittedMessages.Last != null && _currentNode != _submittedMessages.Last) { _currentNode = _submittedMessages.Last; } else if (_currentNode.Previous != null) { _currentNode = _currentNode.Previous; } TextBuilder.Clear(); TextBuilder.Append(_currentNode.Value); } else if (key == Keys.Down && _currentNode != null) { var next = _currentNode.Next; if (next != null) { TextBuilder.Clear(); TextBuilder.Append(next.Value); } } else { int prevLength = TextBuilder.Length; base.OnKeyInput(character, key); if (TextBuilder.Length != prevLength) { ResetTabComplete(); } } return(true); } return(false); }