public override Label CreateLabel(IFontBuddy font, IFontBuddy highlightedFont = null) { return(new QuestionLabel(CorrectAnswer, Text, font, highlightedFont) { Vertical = VerticalAlignment.Center, Horizontal = HorizontalAlignment.Center }); }
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); }
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); }
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); }
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); }
private Vector2 MeasureText(IFontBuddy font) { if (!string.IsNullOrEmpty(Text) && null != font) { return(font.MeasureString(Text)); } else { return(Vector2.Zero); } }
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(); }
/// <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 }; }
protected override void LoadContent() { base.LoadContent(); _spriteBatch = new SpriteBatch(_graphics.GraphicsDevice); _font = new FontBuddy(); _font.LoadContent(Content, "ArialBlack24"); _time = new GameClock(); _time.Start(); }
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); }
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); }
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); }
/// <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); }
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); } }
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>(); }
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); }
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); } }
public QuestionMenuEntry(string text, FlashCard flashCard, bool correctAnswer, IFontBuddy font) : base(text, font) { Init(flashCard, correctAnswer); }
public QuestionLabel(bool isCorrectAnswer, string text, IFontBuddy font, IFontBuddy highlightedFont) : base(text, font, highlightedFont) { Init(isCorrectAnswer); }