public void Draw(RenderTarget rt) { DateTime now = DateTime.Now; Text message = new Text("", myFont); message.CharacterSize = 14; int removeCount = 0; foreach(KeyValuePair<DateTime, String> pair in msgList){ message.DisplayedString += pair.Value + "\n"; if((now - pair.Key).TotalSeconds > messageLifeTime) removeCount++; } msgList.RemoveRange(0, removeCount); message.Position = new Vector2f(14, rt.Height - 54 - message.GetRect().Height); rt.Draw(message); if(writing){ Text display = new Text("say : " + toWrite + "_", myFont); display.CharacterSize = 14; display.Position = new Vector2f(14, rt.Height - 36 - display.GetRect().Height); rt.Draw(display); } }
bool FormatMessage() { FormattedMessage.Clear(); if (Words.Count <= 0) return false; Text text = new Text(string.Empty, Info.Font, Info.Size); text.Style = Info.Styles; int wordCount = 0; text.DisplayedString += Words[wordCount++]; if (text.GetRect().Height > Info.MaxDimension.Y) return false; if (text.GetRect().Width > Info.MaxDimension.X) return CutWord(0); while (wordCount < Words.Count) { text.DisplayedString += (text.DisplayedString == string.Empty ? "" : " ") + Words[wordCount]; if (text.GetRect().Width > Info.MaxDimension.X) { text.DisplayedString = text.DisplayedString.Substring( 0, text.DisplayedString.Length - (Words[wordCount].Length + (text.DisplayedString.Length <= Words[wordCount].Length ? 0 : 1))); text.DisplayedString += "\n" + Words[wordCount]; if (text.GetRect().Height > Info.MaxDimension.Y) { text.DisplayedString = text.DisplayedString.Substring( 0, text.DisplayedString.Length - (Words[wordCount].Length + 1)); FormattedMessage.Add(text.DisplayedString); text.DisplayedString = string.Empty; continue; } } if (text.GetRect().Width > Info.MaxDimension.X) return CutWord(wordCount); ++wordCount; } if (text.DisplayedString != string.Empty) FormattedMessage.Add(text.DisplayedString); return true; }
/// <summary> /// Cut a word that does not fit in one row placing a '-' at the limit. /// </summary> /// <param name="wordIndex">Index of word that must be cut.</param> /// <returns>True if the operation is successful.</returns> bool CutWord(int wordIndex) { string word = Words[wordIndex]; Text text = new Text(word, Info.Font, Info.Size); text.Style = Info.Styles; int count = 0; while (text.GetRect().Width > Info.MaxDimension.X) { if (count > 0) text.DisplayedString = text.DisplayedString.Substring(0, text.DisplayedString.Length - 1); text.DisplayedString = text.DisplayedString.Substring(0, word.Length - ++count); text.DisplayedString += "-"; } Words.Insert(wordIndex, text.DisplayedString); Words[wordIndex + 1] = word.Substring(word.Length - count); FormatMessage(); return true; }
//UTILS private void DrawPlayersPseudo() { foreach (NetworkClient c in otherClients.Values){ Text pseudo = new Text(c.Pseudo, myFont); pseudo.CharacterSize = 12; pseudo.Color = Color.White; pseudo.Position = c.Player.Position - new Vector2f(pseudo.GetRect().Width / 2 - c.Player.Bbox.Width / 2, 20); world.Draw(pseudo); } }
private static void Render(RenderTarget r) { if (!NeedsRedraw) { return; } for (int i = 0; i < Walls.GetLength(0); i++) for (int j = 0; j < Walls.GetLength(1); j++) if (!Walls[i, j] && !VisitedWalls[i, j]) target.SetPixel((uint) i + 1, (uint) j + 1, ForegroundColor); else target.SetPixel((uint) i + 1, (uint) j + 1, BackgroundColor); if (!Solving) target.SetPixel((uint) CurrentCell.X*2 + 1, (uint) CurrentCell.Y*2 + 1, CurrentCellColor); if (FinishedGenerating) target.SetPixel((uint) EndCell.X*2 + 1, (uint) EndCell.Y*2 + 1, EndCellColor); if (Solving) { for (int i = 0; i < VisitedWalls.GetLength(0); i++) for (int j = 0; j < VisitedWalls.GetLength(1); j++) if (VisitedWalls[i, j]) target.SetPixel((uint) i + 1, (uint) j + 1, VisitedCellColor); foreach (IntPair i in CellStack) target.SetPixel((uint) i.X + 1, (uint) i.Y + 1, PathColor); target.SetPixel((uint) (CurrentCell.X*(Solving ? 1 : 2) + 1), (uint) CurrentCell.Y + 1, CurrentCellColor); } target.SetPixel((uint) StartCell.X*2 + 1, (uint) StartCell.Y*2 + 1, BeginCellColor); var celltext = new Text((1/((RenderWindow) r).GetFrameTime()).ToString()); celltext.Position = new Vector2(0, r.Height - celltext.GetRect().Height); celltext.Color = BackgroundColor; r.Draw(new Sprite {Image = target, Scale = new Vector2(10, 10)}); r.Draw(Shape.Rectangle(celltext.GetRect(), ForegroundColor)); r.Draw(celltext); }
//TODO Clean with a drawtext method public void Draw(RenderTarget rt) { float maxX = 0; Vector2f position = new Vector2f(2,0); Text text = new Text("", Screen.ARIAL); if(current == null) text.DisplayedString = "Logical Drives"; else text.DisplayedString = current.FullName; text.CharacterSize = 12; rt.Draw(text); position.Y += text.GetRect().Height + 4; float startY = position.Y; int index = 0; foreach(DirectoryInfo d in directories){ if(index == cursor) text.Color = Color.Yellow; else text.Color = Color.White; if(current == null) text.DisplayedString = d.Name; else text.DisplayedString = "\\" + d.Name; if(text.GetRect().Top + text.GetRect().Height > rt.Height - 10){ position.X += maxX + 2; position.Y = startY; maxX = 0; } text.Position = position; rt.Draw(text); position.Y += text.GetRect().Height + 4; index++; maxX = Math.Max(maxX, text.GetRect().Width); } if(!load && current != null){ if(index == cursor) text.Color = Color.Yellow; else text.Color = Color.White; if(editMode == NEWDIRECTORY) text.DisplayedString = newName + "_"; else text.DisplayedString = "New directory"; if(text.GetRect().Top + text.GetRect().Height > rt.Height - 10){ position.X += maxX + 2; position.Y = startY; maxX = 0; } text.Position = position; rt.Draw(text); position.Y += text.GetRect().Height + 4; index++; maxX = Math.Max(maxX, text.GetRect().Width); } foreach(FileInfo f in files){ if(index == cursor) text.Color = Color.Yellow; else text.Color = Color.White; text.DisplayedString = f.Name; if(text.GetRect().Top + text.GetRect().Height > rt.Height - 10){ position.X += maxX + 2; position.Y = startY; maxX = 0; } text.Position = position; rt.Draw(text); position.Y += text.GetRect().Height + 4; index++; maxX = Math.Max(maxX, text.GetRect().Width); } if(!load && current != null){ if(index == cursor) text.Color = Color.Yellow; else text.Color = Color.White; if(editMode == NEWFILE) text.DisplayedString = newName + "_"; else text.DisplayedString = "New file"; if(text.GetRect().Top + text.GetRect().Height > rt.Height - 10){ position.X += maxX + 2; position.Y = startY; maxX = 0; } text.Position = position; rt.Draw(text); position.Y += text.GetRect().Height + 4; index++; maxX = Math.Max(maxX, text.GetRect().Width); } }