static VisualTextLine()
 {
     formatter           = TextFormatter.Create();
     paragraphProperties = new SimpleParagraphProperties {
         defaultTextRunProperties = TextConfiguration.GetGlobalTextRunProperties()
     };
 }
Example #2
0
 static VisualElement()
 {
     Symbol        = GetSymbol();
     runProperties = TextConfiguration.GetGlobalTextRunProperties();
     textSource    = new SimpleTextSource(Symbol, runProperties);
     charSize      = TextConfiguration.GetCharSize();
 }
        public static VisualTextLine Create(IEnumerable <string> linesToCollapse, string precedingText, string followingText, int index, string collapseRepresentation)
        {
            var textSourceBeforeCollapse = new SimpleTextSource(precedingText, TextConfiguration.GetGlobalTextRunProperties());
            var textSourceAfterCollapse  = new SimpleTextSource(followingText, TextConfiguration.GetGlobalTextRunProperties());

            return(new CollapsedVisualTextLine(
                       linesToCollapse.Select(line => new SimpleTextSource(line, TextConfiguration.GetGlobalTextRunProperties())), textSourceBeforeCollapse, textSourceAfterCollapse, index, collapseRepresentation));
        }
Example #4
0
        private void UpdateSize()
        {
            var maxLineLen = (from VisualTextLine line in visuals select line.RenderedText.Length).Concat(new[] { 0 }).Max();
            var charHeight = TextConfiguration.GetCharSize().Height;

            Width  = maxLineLen * TextConfiguration.GetCharSize().Width;
            Height = Convert.ToInt32(visuals.Count * charHeight);
        }
Example #5
0
 public sealed record State(
     string TextId,
     string Value,
     string CreatedByUser,
     DateTime CreatedUtc,
     bool IsPublic,
     bool IsArchived,
     TextConfiguration Configuration) : IIdentifiable
Example #6
0
        private void UpdateSize()
        {
            var h = linesCount * TextConfiguration.GetCharSize().Height;

            if (h > ActualHeight)
            {
                Height = h;
            }
        }
Example #7
0
        public TextView(ICaretViewReadonly caretViewReader)
        {
            updatingAlgorithm    = new TextUpdatingAlgorithm();
            removingAlgorithm    = new TextRemovingAlgorithm();
            collapsingAlgorithm  = new TextCollapsingAlgorithm();
            parsingAlgorithm     = new TextParsingAlgorithm();
            this.caretViewReader = caretViewReader;

            visuals.Add(new SingleVisualTextLine(new SimpleTextSource(string.Empty, TextConfiguration.GetGlobalTextRunProperties()), 0));
        }
        private bool CanExecuteMouseMove(MouseEventArgs mouseEvent)
        {
            var docPosition = mouseEvent.GetPosition(caretView).GetDocumentPosition(TextConfiguration.GetCharSize());

            if (docPosition.Line < 0 || docPosition.Line >= textViewReader.LinesCount)
            {
                return(false);
            }

            return(docPosition.Column >= 0);
        }
Example #9
0
        public void DrawFolding(FoldingStates state, int top)
        {
            var symbol        = state == FoldingStates.EXPANDED ? "-" : "+";
            var runProperties = TextConfiguration.GetGlobalTextRunProperties();
            var formattedText = GetFormattedText(symbol, runProperties);
            var textLocation  = new Point(5, top);

            using (var drawingContext = RenderOpen()) {
                drawingContext.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Black, 1), new Rect(4, top + 2, 10, 9));
                drawingContext.DrawText(formattedText, textLocation);
            }
        }
Example #10
0
    public async ValueTask <ActionResult <string> > GenerateTextValue(
        int length,
        TextStructure textStructure = TextStructure.Text,
        string?language             = "en",
        int maxShouldContainErrors  = 10,
        int maxShouldContainSlow    = 10)
    {
        if (language == null)
        {
            language = "en";
        }

        var shouldContain = new List <string>();

        if (Profile.Type == ProfileType.User)
        {
            // Personalize text generation.
            var data = await _typingReportGerenator.GenerateStandardUserStatisticsAsync(Profile.ProfileId, language);

            shouldContain.AddRange(data.KeyPairs
                                   .Where(x => x.FromKey?.Length == 1 && x.ToKey.Length == 1)
                                   .OrderByDescending(x => x.MistakesToSuccessRatio)
                                   .Select(x => $"{x.FromKey}{x.ToKey}")
                                   .Take(maxShouldContainErrors));

            shouldContain.AddRange(data.KeyPairs
                                   .Where(x => x.FromKey?.Length == 1 && x.ToKey.Length == 1)
                                   .OrderByDescending(x => x.AverageDelay)
                                   .Select(x => $"{x.FromKey}{x.ToKey}")
                                   .Take(maxShouldContainSlow));
        }

        _logger.LogDebug("Generating text for user {ProfileId} containing {@Contains}.", ProfileId, shouldContain);

        //var textValue = await _textGenerator.GenerateTextAsync(new TextGenerationConfigurationDto(length, shouldContain, textType, language));
        var config = Texts.TextGenerationConfiguration.SelfImprovement(
            new(language), textStructure: textStructure, shouldContain: shouldContain);
        var generatedText = await _textsClient.GenerateTextAsync(config, EndpointAuthentication.Service, default);

        var textValue = generatedText.Value;

        var textId = await _textRepository.NextIdAsync();

        var configuration = new TextConfiguration(
            TextType.Generated,
            new Typing.TextGenerationConfiguration(length, shouldContain, config.GetTextGenerationType()),
            language);

        var text = new Text(textId, textValue, ProfileId, DateTime.UtcNow, false, configuration);
        await _textRepository.SaveAsync(text);

        return(Ok(textId));
    }
Example #11
0
        public void Redraw(int num)
        {
            var fontColor  = SharedEditorConfiguration.GetLinesColumnFontColor();
            var typeface   = SharedEditorConfiguration.GetTypeface();
            var fontHeight = TextConfiguration.GetCharSize().Height;

            using (var drawingContext = RenderOpen()) {
                drawingContext.DrawText(
                    new FormattedText(num.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontHeight, fontColor),
                    new Point(0, fontHeight * (num - 1)));
            }
        }
Example #12
0
        public SelectionInfo LineSelection(MouseButtonEventArgs mouseEvent)
        {
            var clickPosition = mouseEvent.GetPosition(parent).GetDocumentPosition(TextConfiguration.GetCharSize());
            var startPosition = new TextPosition(column: 0, line: clickPosition.Line);
            var endPosition   = new TextPosition(column: textViewReader.GetLineLength(clickPosition.Line), line: clickPosition.Line);
            var cursorColumn  = clickPosition.Line + 1 < textViewReader.LinesCount ? 0 : textViewReader.GetLineLength(clickPosition.Line);
            var cursorLine    = clickPosition.Line + 1 < textViewReader.LinesCount ? clickPosition.Line + 1 : clickPosition.Line;

            return(new SelectionInfo {
                StartPosition = startPosition,
                EndPosition = endPosition,
                CursorPosition = new TextPosition(column: cursorColumn, line: cursorLine)
            });
        }
Example #13
0
        private void RedrawFolds()
        {
            visuals.Clear();

            foreach (var kvp in GetClosedFoldingInfos())
            {
                var symbol = new VisualElementSymbol();
                var top    = (int)kvp.Key.Position.GetPositionRelativeToParent(TextConfiguration.GetCharSize()).Y;

                symbol.DrawFolding(kvp.Key.State, top);

                visuals.Add(symbol);
            }
        }
Example #14
0
        private void OnScrollChanged(object sender, ScrollChangedEventArgs evt)
        {
            if (evt.VerticalChange != 0)
            {
                var firstIdx = (int)Math.Round(evt.VerticalOffset / TextConfiguration.GetCharSize().Height);
                var lastIdx  = (int)Math.Round((evt.VerticalOffset + evt.ViewportHeight) / TextConfiguration.GetCharSize().Height);

                Postbox.InstanceFor(GetHashCode()).Put(new ScrollChangedMessage {
                    FirstVisibleLineIndex = firstIdx,
                    LastVisibleLineIndex  = lastIdx,
                    LinesScrolled         = Math.Abs((int)Math.Ceiling(evt.VerticalChange / TextConfiguration.GetCharSize().Height))
                });
            }
        }
Example #15
0
 public void Update(TextConfiguration another)
 {
     this.Color          = another?.Color ?? this?.Color;
     this.FadeIn         = another?.FadeIn ?? this?.FadeIn;
     this.FadeOut        = another?.FadeOut ?? this?.FadeOut;
     this.Orientation    = another?.Orientation ?? this?.Orientation;
     this.Padding        = another?.Padding ?? this?.Padding;
     this.PaddingLine    = another?.PaddingLine ?? this?.PaddingLine;
     this.PaddingSpace   = another?.PaddingSpace ?? this?.PaddingSpace;
     this.Position       = another?.Position ?? this?.Position;
     this.PositionOffset = another?.PositionOffset ?? this?.PositionOffset;
     this.Rotation       = another?.Rotation ?? this?.Rotation;
     this.Scale          = another?.Scale ?? this?.Scale;
     this.RepeatOffset   = another?.RepeatOffset ?? this.RepeatOffset;
 }
Example #16
0
    public async ValueTask <ActionResult> Post(CreateTextDto dto)
    {
        // TODO: Make a global attribute that will ensure that in order to
        // execute endpoint we need USER-authentication and not SERVICE-authentication.
        var textId = await _textRepository.NextIdAsync();

        var configuration = new TextConfiguration(
            TextType.User, null, dto.Language);

        var text = new Text(textId, dto.Value, ProfileId, DateTime.UtcNow, dto.IsPublic, configuration);

        await _textRepository.SaveAsync(text);

        var result = new { textId };

        return(CreatedAtAction(nameof(GetById), result, result));
    }
Example #17
0
        public static Bitmap RenderChar(char c, PixelRenderingOptions options)
        {
            FontFace fallback = FontManager.FontMap.GetFont(0);

            if (c == ' ')
            {
                throw new Exception("A space cannot be rendered in the TextEngine.");
            }

            FontSheet sheet = options.Font.Search(c, options.FontType, out (int i, int x, int y)index) ??
                              fallback.Search(c, options.FontType, out index);

            Rectangle crop = new Rectangle(
                options.Font.Ppu.Width * index.x,
                options.Font.Ppu.Height * index.y,
                options.Font.Ppu.Width,
                options.Font.Ppu.Height);

            using (Bitmap b = new Bitmap(sheet.Path))
            {
                using (Bitmap tmp = b.Clone(crop, b.PixelFormat))
                {
                    if (!options.Font.AutoCrop.HasValue)
                    {
                        crop.Width = TextConfiguration.GetWidth(tmp, tmp.Width);
                    }
                    else
                    {
                        if (options.Font.AutoCrop.Value)
                        {
                            crop.Width = TextConfiguration.GetWidth(tmp, tmp.Width);
                        }
                    }
                    crop.Debug();

                    return(b.Clone(crop, b.PixelFormat));
                }
            }
        }
        public override void Draw()
        {
            var runProperties = TextConfiguration.GetGlobalTextRunProperties();

            using (var drawingContext = RenderOpen()) {
                double top;

                using (var textLine = Formatter.FormatLine(new SimpleTextSource(textBeforeCollapse, runProperties), 0, 96 * 6, ParagraphProperties, null)) {
                    top = Index * textLine.Height;

                    textLine.Draw(drawingContext, new Point(0, top), InvertAxes.None);
                }
                using (var textLine = Formatter.FormatLine(new SimpleTextSource(collapseRepresentation, runProperties), 0, 96 * 6, ParagraphProperties, null)) {
                    textLine.Draw(drawingContext, new Point(TextConfiguration.GetCharSize().Width *textBeforeCollapse.Length, top), InvertAxes.None);
                }
                using (var textLine = Formatter.FormatLine(new SimpleTextSource(textAfterCollapse, runProperties), 0, 96 * 6, ParagraphProperties, null)) {
                    textLine.Draw(drawingContext,
                                  new Point(TextConfiguration.GetCharSize().Width *textBeforeCollapse.Length + TextConfiguration.GetCharSize().Width *collapseRepresentation.Length, top),
                                  InvertAxes.None);
                }
            }
        }
        public void Execute(object parameter)
        {
            var          keyboardEvent = parameter as KeyEventArgs;
            var          mouseEvent    = parameter as MouseButtonEventArgs;
            TextPosition newPos        = null;

            if (keyboardEvent != null)
            {
                newPos = caretView.GetNextPosition(keyboardEvent.Key);
                keyboardEvent.Handled = true;
            }
            else if (mouseEvent != null)
            {
                newPos = mouseEvent.GetPosition(caretView).GetDocumentPosition(TextConfiguration.GetCharSize());
            }
            if (newPos == null)
            {
                return;
            }

            int column = -1, line = -1;

            if (newPos.Column > textViewReader.GetLineLength(newPos.Line))
            {
                column = textViewReader.GetLineLength(newPos.Line);
            }
            if (newPos.Line >= textViewReader.LinesCount)
            {
                line = textViewReader.LinesCount - 1;
            }

            var moveDir = GetMoveDirection(newPos, caretView.CaretPosition);

            newPos = new TextPosition(column > -1 ? column : newPos.Column, line > -1 ? line : newPos.Line);
            newPos = textViewReader.AdjustStep(newPos, moveDir);

            caretView.MoveCursor(newPos);
        }
Example #20
0
        public SelectionInfo WordSelection(MouseButtonEventArgs mouseEvent)
        {
            var clickPosition = mouseEvent.GetPosition(parent).GetDocumentPosition(TextConfiguration.GetCharSize());
            var activeLine    = textViewReader.GetVisualLine(clickPosition.Line);
            var lineLength    = textViewReader.GetLineLength(clickPosition.Line);

            int[] selectionRange;

            if (!activeLine.GetCharInfoAt(clickPosition.Column).IsCharacter)
            {
                selectionRange = GetCollapseSelectionRange(clickPosition, activeLine, lineLength);
            }
            else
            {
                selectionRange = GetStandardWordSelectionRange(clickPosition, activeLine, lineLength);
            }

            return(new SelectionInfo {
                StartPosition = new TextPosition(column: selectionRange[0], line: clickPosition.Line),
                EndPosition = new TextPosition(column: selectionRange[1], line: clickPosition.Line),
                CursorPosition = new TextPosition(column: selectionRange[1], line: clickPosition.Line)
            });
        }
        private IEnumerable <PointsPair> GetSelectionPointsForward(TextPosition start, TextPosition end)
        {
            var pairs = new List <PointsPair>();

            for (var i = start.Line; i <= end.Line; i++)
            {
                var tmpStartColumn = 0;
                var tmpStartLine   = i;
                var tmpEndColumn   = 0;
                var tmpEndLine     = i;

                if (i == start.Line)
                {
                    tmpStartColumn = start.Column;
                }

                var lineLen = textViewReader.GetLineLength(i);

                if (i == end.Line)
                {
                    tmpEndColumn = end.Column > lineLen ? lineLen : end.Column;
                }
                else
                {
                    tmpEndColumn = lineLen;
                }

                pairs.Add(new PointsPair {
                    StartingPoint = (new TextPosition(column: tmpStartColumn, line: tmpStartLine)).GetPositionRelativeToParent(TextConfiguration.GetCharSize())
                                    .AlignToVisualLineTop(TextConfiguration.GetCharSize()),
                    EndingPoint = (new TextPosition(column: tmpEndColumn, line: tmpEndLine)).GetPositionRelativeToParent(TextConfiguration.GetCharSize())
                                  .AlignToVisualLineBottom(TextConfiguration.GetCharSize())
                });
            }

            return(pairs);
        }
Example #22
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var viewPort = _graphics.GraphicsDevice.Viewport;

            var screenConfiguration = new GameScreenConfiguration(viewPort.Height, viewPort.Width);
            var levelConfiguration  = new LevelConfiguration(12, Color.Black, 12, 52, Color.Black, 12, 64, Color.Black, 8, Color.Black, 42, 12, 8);
            var textConfiguration   = new TextConfiguration(Color.Black, 2);

            var textTexture = GetPlain2DTexture(textConfiguration.TextSize);
            var texture     = GetPlain2DTexture(1);

            _eventAggregator = new EventAggregator();
            _randomizer      = new Randomizer.Randomizer();
            _keyboardManager = new KeyboardManager(_eventAggregator, TimeSpan.Zero);
            _playerInput     = new PlayerInput(_eventAggregator);
            var collisionManager = new CollisionManager(_eventAggregator);
            var drawer           = new Drawer(_spriteBatch, texture);
            var textDrawer       = new Drawer(_spriteBatch, textTexture);
            var pixelTextDrawer  = new PixelTextDrawer(textDrawer);
            var particleManager  = new ParticleManager(_eventAggregator, drawer, _randomizer);


            var startScreen  = new StartScreen(_eventAggregator, pixelTextDrawer, screenConfiguration, textConfiguration);
            var levelFactory = new LevelFactory(_eventAggregator, screenConfiguration, levelConfiguration);
            var levelManager = new LevelManager(_eventAggregator, levelFactory, collisionManager, particleManager, drawer);
            var gameScreen   = new GameScreen(_eventAggregator, levelManager);

            _screenManager = new ScreenManager(_eventAggregator, startScreen, gameScreen);

            _keyboardManager.Load();
            _playerInput.Load();
            _screenManager.Load();
        }
 private bool CanExecuteMouse(MouseEventArgs mouseEvent) =>
 mouseEvent.LeftButton == MouseButtonState.Pressed &&
 textViewReader.IsInTextRange(mouseEvent.GetPosition(caretView).GetDocumentPosition(TextConfiguration.GetCharSize()));
Example #24
0
        public static Bitmap SetCard(CompactUser u, PixelRenderingOptions options)
        {
            string s = "e";

            s.Debug("This is where the card is being built.");
            // Set the default attributes.
            Bitmap template    = new Bitmap(Locator.ProfileTemplate);
            Bitmap currencyMap = new Bitmap(Locator.CurrencySheet);
            Bitmap iconMap     = new Bitmap(Locator.IconSheet);

            Bitmap tmp = new Bitmap(template.Width, template.Height, template.PixelFormat);

            // Build the display card.
            using (Graphics g = Graphics.FromImage(tmp))
            {
                // Gets the letter rendering options for the username.
                LetterRenderingOptions config = new LetterRenderingOptions(u.Username);
                // Gets the status rendering options.
                StatusRenderingOptions status = new StatusRenderingOptions(u.Status);

                // Reduce the need for constant image opening.
                // This will help reduce constant rebuilding.

                // Size: 150px by 200px.
                // Border: 2px empty
                // 2px pixels
                // 2px empty
                // everything after can be placed.

                // Actual Size: 138px by 188px
                // actual starting x: 6px
                // actual starting y: 6px;
                // actual width: 144px
                // actual height 194px

                int padding     = 2;                         // 2px
                int lineWidth   = 2;                         // 2px
                int borderWidth = (2 * padding) + lineWidth; // 6px
                int avatarWidth = 32;                        // 32px

                // This is the vertical position of where the level and currency need to be.
                // This gets the username size, and shifts it down based on size.
                // This also gets shifted down by the current activity or state.


                Point defaultPoint = new Point(borderWidth, borderWidth);

                // The space after the starting border and avatar, with a 2px padding.
                int afterAvatarX = defaultPoint.X + avatarWidth + padding;

                Point usernamePoint = new Point(afterAvatarX, defaultPoint.Y);
                // This is the base board plus the font size plus padding.
                int usernameHeight = borderWidth + config.Spacing + padding; // 6 + spacing + 2



                int   activityTextSize = 4; // 4px;
                Point activityPoint    = new Point(afterAvatarX, usernameHeight);

                // The position at which the user name is written.
                // Font size used for activity is 4px.
                // To make a new line, it would be 4px + padding.
                int afterFirstActivity = activityPoint.Y + activityTextSize + padding;

                // This is where the second activity line would be placed if one exists
                bool hasSecondActivity = false;

                // this is where you want to see if there's an activity.

                // this sets the text to render.
                string firstActivity = "";                          // the first line for the activity to render.

                int firstActivityTextLimit  = 32;                   // Only 32 letters may be rendered per line.
                int secondActivityTextLimit = 32;                   // Only 32 letters may be rendered per line.

                string secondActivity = "";                         // the second line for the activity to render.
                if (u.Activity.Exists())
                {                                                   // activity does exist
                    firstActivity = u.Activity.Type.ToTypeString(); // Playing, Listening, etc.
                    // deduct the length of the playing type from the limit of the first line.
                    firstActivityTextLimit -= firstActivity.Length;
                    // get the activity name, and check if the name is longer than the limit
                    // if so, set hasSecondActivity to true
                    // and set the second activity text to 32;
                }
                else
                {
                    firstActivity = status.State;
                }



                int   secondActivityX     = afterAvatarX;
                Point secondActivityPoint = new Point(afterAvatarX, afterFirstActivity);

                // The y position of the level balance point after a second activity, if any.
                // 2px padding as default, with 1px added to help make it look nicer.
                int afterSecondActivity = secondActivityPoint.Y + padding + 1;

                // The + 1px is for another layer of padding.
                Point levelBalancePoint =
                    hasSecondActivity ?
                    new Point(afterAvatarX, afterSecondActivity) :
                    new Point(secondActivityPoint.X, secondActivityPoint.Y + 1);


                // This places the identifying state as a visual bar.
                // x: 6px
                // y: 6px + 32px + 1px : 39px // padding should only be one px.
                Point statusBarPoint = new Point(defaultPoint.X, defaultPoint.Y + avatarWidth + 1);


                // Places the template built before this method.

                /*using (Bitmap b = template)
                 * {
                 *  g.DrawImage(b, b.ToRectangle());
                 *  template.Dispose();
                 * }*/
                var borderBrush = new SolidBrush(options.Palette[0]);


                // Size: 150px by 200px.
                // Border: 2px empty
                // 2px pixels
                // 2px empty
                // everything after can be placed.

                // Actual Size: 138px by 188px
                // actual starting x: 6px
                // actual starting y: 6px;
                // actual width: 144px
                // actual height 194px

                // 47 pixels tall - 2px padding on both ends = 43px tall

                // LEFT BORDER
                Rectangle lBorder = new Rectangle(2, 2, 2, 43);

                g.SetClip(lBorder);
                g.FillRectangle(borderBrush, lBorder);

                // RIGHT BORDER
                Rectangle rBorder = new Rectangle(196, 2, 2, 43);

                g.SetClip(rBorder);
                g.FillRectangle(borderBrush, rBorder);

                // TOP BORDER
                Rectangle tBorder = new Rectangle(2, 2, 196, 2);

                g.SetClip(tBorder);
                g.FillRectangle(borderBrush, tBorder);

                // BOTTOM BORDER
                Rectangle bBorder = new Rectangle(2, 43, 196, 2);

                g.SetClip(bBorder);
                g.FillRectangle(borderBrush, bBorder);

                g.ResetClip();

                borderBrush.Dispose();

                // Avatar: 32px by 32px
                // Draw the Avatar onto the graphics.
                using (Bitmap b = Pixelate(u.Avatar, options))
                {
                    g.DrawImage(b, defaultPoint);
                    u.Avatar.Dispose();
                }

                // Place user status bar.
                SetStatus(g, statusBarPoint, status);

                // Place username.
                TextConfiguration.PixelateText(u.Username, usernamePoint, config.Size, tmp, options);

                // Place activity, or state if not doing anything.

                // Place current level.
                // Place icon

                /*using (Bitmap b = iconMap)
                 * {
                 *  // crops the sprite map icon to get the level icon.
                 *  Rectangle levelCrop = new Rectangle(0, 0, 4, iconMap.Height);
                 *  Rectangle coinCrop = new Rectangle(8, 0, iconMap.Height, iconMap.Height);
                 *
                 *  Bitmap icon = iconMap.Clone(levelCrop, iconMap.PixelFormat);
                 *  Bitmap coin = iconMap.Clone(coinCrop, iconMap.PixelFormat);
                 *
                 *  levelBalancePoint.Y -= activityTextSize + padding;
                 *  Rectangle iconSpot = new Rectangle(levelBalancePoint, icon.Size);
                 *  Point balancePoint = new Point(levelBalancePoint.X + 8, levelBalancePoint.Y);
                 *  Rectangle coinSpot = new Rectangle(balancePoint, coin.Size);
                 *
                 *  g.SetClip(iconSpot);
                 *  g.DrawImage(icon, iconSpot);
                 *  g.SetClip(coinSpot);
                 *  g.DrawImage(coin, coinSpot);
                 *
                 *  iconMap.Dispose();
                 *
                 *  // get the position of the level
                 *  // get the position of the coin
                 *  // build.
                 * }*/


                // Place current balance.
                // Place coin icon
                // then place the money amount
                // and if needed, the icon of the money amount.

                // Place experience bar, with the percentage to the next level.
                // first, get the point of where the experience bar is painted.
                // get the width of the experience bar based on the width of the level
                // divide the pixels into segments
                // divide the experience by the segments
                // if experience is higher than a segment, paint.
                // otherwise, leave empty.

                // Close off the entire image, and scale.

                // Send.
            }

            tmp = tmp.Resize(options.Scale);

            return(tmp);
        }
Example #25
0
        public Vector2 Parse(TextObject obj, TextConfiguration config, FontGenerator font, Vector2 pos, int?startTime, int?endTime)
        {
            var currentConfig = config.Clone() as TextConfiguration;

            currentConfig.Update(obj.Config);

            var times = new List <int?>();

            times.Add(0);

            if (currentConfig.RepeatOffset != null)
            {
                times.AddRange(currentConfig.RepeatOffset.ToList());
            }

            var subX = pos.X + (currentConfig.PositionOffset[0] ?? 0f);
            var subY = pos.Y + (currentConfig.PositionOffset[1] ?? 0f);

            foreach (var t in times)
            {
                int?st = (obj.StartTime ?? startTime) + t;
                int?et = (obj.EndTime ?? endTime) + t;


                if (obj.Text == "")
                {
                    // parse inner texts

                    Vector2 cpos = new Vector2(currentConfig.Position[0] ?? pos.X, currentConfig.Position[1] ?? pos.Y);

                    foreach (var i in obj.Texts)
                    {
                        cpos = Parse(i, currentConfig, font, cpos, st, et);
                    }

                    return(new Vector2(currentConfig.Position[0] ?? pos.X, currentConfig.Position[1] ?? pos.Y));;
                }
                else
                {
                    if (st == null || et == null)
                    {
                        Log($"W: Missing startTime or endTime for sentence `{obj.Text}`");
                        return(new Vector2());
                    }

                    // generate

                    subX = pos.X + (currentConfig.PositionOffset[0] ?? 0f);
                    subY = pos.Y + (currentConfig.PositionOffset[1] ?? 0f);
                    foreach (var c in obj.Text)
                    {
                        if (c == '\n')
                        {
                            if (currentConfig.Orientation == 0)
                            {
                                // horizontal
                                subX  = currentConfig.Position[0] ?? 0f + (currentConfig.PositionOffset[0] ?? 0f);
                                subY += currentConfig.PaddingLine[1] ?? 0f;
                            }
                            else
                            {
                                // vertical
                                subY  = currentConfig.Position[1] ?? 0f + (currentConfig.PositionOffset[1] ?? 0f);
                                subX += currentConfig.PaddingLine[0] ?? 0f;
                            }
                        }
                        else if (c == ' ')
                        {
                            if (currentConfig.Orientation == 0)
                            {
                                // horizontal
                                subX += currentConfig.PaddingSpace[0] ?? 0f;
                            }
                            else
                            {
                                // vertical
                                subY += currentConfig.PaddingSpace[1] ?? 0f;
                            }
                        }

                        var texture = font.GetTexture(c.ToString());

                        Vector2 p = new Vector2(subX, subY);
                        //+ texture.OffsetFor(Origin) * FontScale * currentConfig.Scale.Value;

                        if (!texture.IsEmpty)
                        {
                            var sprite = GetLayer(LayerName).CreateSprite(texture.Path, Origin, p);
                            sprite.Scale(st.Value, FontScale * currentConfig.Scale.Value);
                            sprite.Fade(st.Value - currentConfig.FadeIn ?? 0, st.Value, 0, 1);
                            sprite.Fade(et.Value, et.Value + currentConfig.FadeOut ?? 0, 1, 0);
                            sprite.Rotate(st.Value, MathHelper.DegreesToRadians(currentConfig.Rotation ?? 0));

                            if (currentConfig.Orientation == 0)
                            {
                                // horizontal
                                subX += texture.Width * FontScale * currentConfig.Scale.Value;
                            }
                            else
                            {
                                // vertical
                                subY += texture.Height * FontScale * currentConfig.Scale.Value;
                            }
                        }

                        subX += currentConfig.Padding[0] ?? 0;
                        subY += currentConfig.Padding[1] ?? 0;
                    }
                }
            }

            return(new Vector2(subX, subY));
        }
 public static VisualTextLine Create(string text, int index)
 {
     return(new SingleVisualTextLine(new SimpleTextSource(text, TextConfiguration.GetGlobalTextRunProperties()), index));
 }
Example #27
0
 public TextPosition StandardSelection(MouseEventArgs mouseEvent) => mouseEvent.GetPosition(parent).GetDocumentPosition(TextConfiguration.GetCharSize());
Example #28
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var position = e.GetPosition(this).GetDocumentPosition(TextConfiguration.GetCharSize());

            RunFoldingOnClick(position);
        }