Example #1
0
 public override Label CreateLabel(IFontBuddy font, IFontBuddy highlightedFont = null)
 {
     return(new QuestionLabel(CorrectAnswer, Text, font, highlightedFont)
     {
         Vertical = VerticalAlignment.Center,
         Horizontal = HorizontalAlignment.Center
     });
 }
Example #2
0
        public static bool NeedsToShrink(string text, float scale, int rowWidth, IFontBuddy font)
        {
            //measure the text
            var textSize = font.MeasureString(text) * scale;

            //get the ratio to scale the width to fit
            return(textSize.X > rowWidth);
        }
Example #3
0
        public static float ShrinkToFit(string text, int rowWidth, IFontBuddy font)
        {
            //measure the text
            var textSize = font.MeasureString(text);

            //get the ratio to scale the width to fit
            return(textSize.X > rowWidth ? rowWidth / textSize.X : 1f);
        }
Example #4
0
 public TextEdit(string text, IFontBuddy font, IFontBuddy highlightedFont = null)
 {
     OnClick  += CreateTextPad;
     TextLabel = new Label(text, font, highlightedFont)
     {
         Horizontal = this.Horizontal,
         Vertical   = this.Vertical,
     };
     AddItem(TextLabel);
 }
Example #5
0
        public static List <string> BreakTextIntoList(string text, int rowWidth, IFontBuddy font)
        {
            //Check for invalid parameters or text that fits on a single line
            if ((rowWidth <= 0) || string.IsNullOrEmpty(text) || (font.MeasureString(text).X <= rowWidth))
            {
                return(new List <string> {
                    text
                });
            }

            //Break the text up into words
            string[] words = text.Split(' ');

            //Add words to the list until they go over the length
            List <string> lines       = new List <string>();
            int           currentWord = 0;

            while (currentWord < words.Length)
            {
                int    wordsThisLine = 0;
                string line          = string.Empty;
                while (currentWord < words.Length)
                {
                    string testLine = line;
                    if (testLine.Length < 1)
                    {
                        testLine += words[currentWord];
                    }
                    else if ((testLine[testLine.Length - 1] == '.') ||
                             (testLine[testLine.Length - 1] == '?') ||
                             (testLine[testLine.Length - 1] == '!'))
                    {
                        //Add two spaces at the end of a sentence
                        testLine += "  " + words[currentWord];
                    }
                    else
                    {
                        //Add a space in between words
                        testLine += " " + words[currentWord];
                    }

                    if ((wordsThisLine > 0) && (font.MeasureString(testLine).X > rowWidth))
                    {
                        //The latest word put it over the line width, but make sure not to add empty lines
                        break;
                    }

                    line = testLine;
                    wordsThisLine++;
                    currentWord++;
                }
                lines.Add(line);
            }
            return(lines);
        }
Example #6
0
 private Vector2 MeasureText(IFontBuddy font)
 {
     if (!string.IsNullOrEmpty(Text) && null != font)
     {
         return(font.MeasureString(Text));
     }
     else
     {
         return(Vector2.Zero);
     }
 }
Example #7
0
        public Label(string text, IFontBuddy font, IFontBuddy highlightedFont = null)
        {
            _fontSize = FontSize.Medium;
            Text      = text;
            Clickable = true;

            //hold onto the provided fonts
            Font            = font;
            HighlightedFont = highlightedFont;
            CalculateRect();
        }
Example #8
0
        /// <summary>
        /// Constructs a new menu entry with the specified text.
        /// </summary>
        public MenuEntry(string text, IFontBuddy font, IFontBuddy highlightedFont = null)
        {
            _text      = text;
            Horizontal = HorizontalAlignment.Center;
            Vertical   = VerticalAlignment.Top;

            Label = new Label(Text, font, highlightedFont)
            {
                Vertical   = VerticalAlignment.Top,
                Horizontal = HorizontalAlignment.Center
            };
        }
Example #9
0
        protected override void LoadContent()
        {
            base.LoadContent();

            _spriteBatch = new SpriteBatch(_graphics.GraphicsDevice);

            _font = new FontBuddy();
            _font.LoadContent(Content, "ArialBlack24");

            _time = new GameClock();
            _time.Start();
        }
Example #10
0
        private void JapaneseGame()
        {
            fontSmall = new FontBuddyPlus();
            fontSmall.LoadContent(Content, "NotoSansJP-Bold", true, StyleSheet.SmallFontSize);
            fontMedium = new FontBuddyPlus();
            fontMedium.LoadContent(Content, "NotoSansJP-Bold", true, StyleSheet.MediumFontSize);

            _cards = new Deck(@"Japanese\Animals.xml")
            {
                Language1 = "English",
                Language2 = "Japanese"
            };
            _cards.ReadXmlFile(Content);
        }
Example #11
0
        public void LabelTests_Setup()
        {
            var font = new Mock <IFontBuddy>()
            {
                CallBase = true
            };

            font.Setup(x => x.MeasureString(It.IsAny <string>()))
            .Returns(new Vector2(30f, 40f));
            _font = font.Object;

            _screen = new Mock <IScreen>();

            _text = new TextEdit("test", _font);
        }
Example #12
0
        public void Setup()
        {
            var resolution = new Mock <IResolution>();

            resolution.Setup(x => x.ScreenArea).Returns(new Rectangle(0, 0, 1280, 720));
            Resolution.Init(resolution.Object);

            var font = new Mock <IFontBuddy>()
            {
                CallBase = true
            };

            font.Setup(x => x.MeasureString(It.IsAny <string>()))
            .Returns(new Vector2(30f, 40f));
            _font = font.Object;

            _screen = new Mock <IScreen>();

            _entry = new MenuEntry("test", _font);
            _entry.LoadContent(_screen.Object);
        }
Example #13
0
        /// <summary>
        /// setup a question screen from a deck of flash cards
        /// </summary>
        /// <param name="cards"></param>
        public QuestionScreen(Deck cards, ContentManager content = null, IFontBuddy fontSmall = null, IFontBuddy fontMedium = null) :
            base("", content)
        {
            this.FontSmall  = fontSmall;
            this.FontMedium = fontMedium;

            Deck                  = cards;
            QuestionTime          = 6f;
            CoveredByOtherScreens = false;
            CoverOtherScreens     = true;

            //this screen should transition on really slow for effect
            Transition.OnTime = 0.5f;

            //set up the question
            AnsweredCorrect = false;
            AnswerChosen    = false;
            TimeRanOut      = false;

            cards.GetQuestion(out correctQuestion, out correctAnswer, out wrongQuestions, out wrongAnswers);
        }
Example #14
0
 private void CreateTranslationLabel(IFontBuddy font, StackLayout questionStack, Translation translation)
 {
     try
     {
         QuestionWordLabel = new QuestionLabel(false, translation.Word, font, font)
         {
             Vertical         = VerticalAlignment.Center,
             Horizontal       = HorizontalAlignment.Center,
             Highlightable    = false,
             TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop),
             Scale            = 1.2f,
         };
         QuestionWordLabel.ShrinkToFit(Resolution.TitleSafeArea.Width);
         questionStack.AddItem(QuestionWordLabel);
         questionStack.AddItem(new Shim(0, 8));
     }
     catch (Exception ex)
     {
         ScreenManager.ErrorScreen(ex);
         throw new Exception($"Error creating menu entry for {translation.Word}", ex);
     }
 }
Example #15
0
        public void LabelStack_Setup()
        {
            _stack = new StackLayout();

            var font = new Mock <IFontBuddy>()
            {
                CallBase = true
            };

            font.Setup(x => x.MeasureString(It.IsAny <string>()))
            .Returns(new Vector2(70f, 80f));
            _largeFont = font.Object;

            font = new Mock <IFontBuddy>()
            {
                CallBase = true
            };
            font.Setup(x => x.MeasureString(It.IsAny <string>()))
            .Returns(new Vector2(30f, 40f));
            _mediumFont = font.Object;

            _screen = new Mock <IScreen>();
        }
Example #16
0
        public static Vector2 JustifiedPosition(string text, Vector2 position, Justify justification, float scale, IFontBuddy font)
        {
            //Get the correct location
            Vector2 textSize = (!string.IsNullOrEmpty(text) ? (font.MeasureString(text) * scale) : Vector2.Zero);

            switch (justification)
            {
            //left = use teh x value (no cahnge)

            case Justify.Right:
            {
                //move teh x value
                position.X -= textSize.X;
            }
            break;

            case Justify.Center:
            {
                //move teh x value
                position.X -= (textSize.X / 2.0f);
            }
            break;
            }

            return(position);
        }
Example #17
0
 protected virtual QuestionMenuEntry CreateQuestionMenuEntry(string text, FlashCard flashCard, bool correctAnswer, IFontBuddy font)
 {
     try
     {
         return(new QuestionMenuEntry(text, flashCard, correctAnswer, font)
         {
             TransitionObject = new WipeTransitionObject(TransitionWipeType.PopBottom),
         });
     }
     catch (Exception ex)
     {
         ScreenManager.ErrorScreen(ex);
         throw new Exception($"Error creating menu entry for {text}", ex);
     }
 }
Example #18
0
 public QuestionMenuEntry(string text, FlashCard flashCard, bool correctAnswer, IFontBuddy font)
     : base(text, font)
 {
     Init(flashCard, correctAnswer);
 }
Example #19
0
 public QuestionLabel(bool isCorrectAnswer, string text, IFontBuddy font, IFontBuddy highlightedFont)
     : base(text, font, highlightedFont)
 {
     Init(isCorrectAnswer);
 }