public MC_TextBox(string text, Rectangle position, SpriteFont font, Color color, float spacing) { this.text = new WrappedText(text, position.Width, font); sfont = font; c = color; pos = position.Location; this.spacing = spacing; }
public override void DrawThis(Display display) { if (IsEmpty) { return; } string text = ToString(); if (string.IsNullOrWhiteSpace(text)) { return; } if (DrawBackground) { display.DrawRectangle(new Rectangle(TextRectangle.Left, TextRectangle.Top, TextRectangle.Width, TextRectangle.Height + 4), MainSettings.Instance.BackColor); } //get what color text should be based on root screen var color = TextColor; if (TextColor == Color.Transparent) { color = GetRootScreen() is MainScreen ? MainSettings.Instance.TextColor : OverlaySettings.Instance.TextColor; } if (Rectangle.Size == Point.Zero) { display.DrawString(Font, text, Location.ToVector2(), color); } else { //draw text wrapped and aligned in bounding box var bounds = Rectangle; float y = bounds.Top; foreach (var line in WrappedText.Split('\n')) { string trimmed = line.Trim(); var size = Font.MeasureString(trimmed).ToPoint(); //calculate horizontal position of this line int x = HorizontalAlign switch { HorizontalAlign.Center => (bounds.Left + (bounds.Width / 2 - size.X / 2)), HorizontalAlign.Left => bounds.Left, _ => bounds.Right - size.X }; display.DrawString(Font, trimmed, new Vector2(x, y), color); //next line y += size.Y; } } }
/// <summary> /// TextWrapping プロパティが Wrap に設定されている場合での文字列サイズを測定します。 /// また同時に、WrappedText プロパティを利用可能な状態へと設定します。 /// </summary> /// <param name="availableWidth">利用可能な幅。</param> /// <returns>折り返しを考慮した文字列のサイズ。</returns> Vector2 MeasureWrappedTextSize(float availableWidth) { if (WrappedText == null) { WrappedText = new WrappedText(); } WrappedText.Text = Text; WrappedText.Font = Font ?? Screen.Font; WrappedText.FontStretch = FontStretch; WrappedText.ClientWidth = availableWidth; WrappedText.Wrap(); return(WrappedText.MeasuredSize); }
public Task SynchronizeTextAsync(DocumentId documentId, Checksum baseTextChecksum, IEnumerable <TextChange> textChanges, CancellationToken cancellationToken) { return(RunServiceAsync(async() => { using (RoslynLogger.LogBlock(FunctionId.RemoteHostService_SynchronizeTextAsync, Checksum.GetChecksumLogInfo, baseTextChecksum, cancellationToken)) { var service = SolutionService.PrimaryWorkspace.Services.GetService <ISerializerService>(); if (service == null) { return; } var text = await TryGetSourceTextAsync().ConfigureAwait(false); if (text == null) { // it won't bring in base text if it is not there already. // text needed will be pulled in when there is request return; } var newText = new WrappedText(text.WithChanges(textChanges)); var newChecksum = service.CreateChecksum(newText, cancellationToken); // save new text in the cache so that when asked, the data is most likely already there // // this cache is very short live. and new text created above is ChangedText which share // text data with original text except the changes. // so memory wise, this doesn't put too much pressure on the cache. it will not duplicates // same text multiple times. // // also, once the changes are picked up and put into Workspace, normal Workspace // caching logic will take care of the text AssetStorage.TryAddAsset(newChecksum, newText); } async Task <SourceText?> TryGetSourceTextAsync() { // check the cheap and fast one first. // see if the cache has the source text if (AssetStorage.TryGetAsset <SourceText>(baseTextChecksum, out var sourceText)) { return sourceText; } // do slower one // check whether existing solution has it var document = SolutionService.PrimaryWorkspace.CurrentSolution.GetDocument(documentId); if (document == null) { return null; } // check checksum whether it is there. // since we lazily synchronize whole solution (SynchronizePrimaryWorkspaceAsync) when things are idle, // soon or later this will get hit even if text changes got out of sync due to issues in VS side // such as file is first opened and there is no SourceText in memory yet. if (!document.State.TryGetStateChecksums(out var state) || !state.Text.Equals(baseTextChecksum)) { return null; } return await document.GetTextAsync(cancellationToken).ConfigureAwait(false); } }, cancellationToken)); }