private static void SendMessage(Ssd1306 device, string message) { foreach (char character in message) { device.SendData(BasicFont.GetCharacterBytes(character)); } }
public DemoGameImplementation(GameImages gameTextures, GameSounds gameSounds) { _gameTextures = gameTextures; _gameSounds = gameSounds; _yellowFont = new BasicFont(gameTextures.YellowFont); _world = new WorldModel(gameTextures, gameSounds, _yellowFont, gameTextures.Ship.Dimensions.Width, gameTextures.Alien1.Dimensions.Width); }
public WorldModel(GameImages gameTextures, GameSounds gameSounds, BasicFont yellowFont, int shipWidth, int alienWidth) { YellowFont = yellowFont; Images = gameTextures; Sounds = gameSounds; Ship.Width = shipWidth; // Quiz: Why store this? AlienModel.AlienWidth = alienWidth; }
/// <summary>Creates a label with pre-formated text</summary> /// <param name="Parent"></param> /// <param name="Text"></param> /// <param name="Font"></param> /// <param name="FG"></param> /// <param name="LeftPos"></param> /// <param name="TopPos"></param> public BasicFontLabel(Window Parent, BasicFontFormattedText Text, BasicFont Font, ConsoleColor FG, int LeftPos, int TopPos) : base(Parent) { //Maybe at some point it'd be good to check if the formatted text can *fit* but shh this.Font = Font; this.Text = Text.Text; this.FG = FG; this.LeftPos = LeftPos; this.TopPos = TopPos; }
internal static void draw(ref SpriteBatch spriteBatch) { lock (_Locker) { if (_draw) { float currentY = 0; foreach (String s in _MessageList) { spriteBatch.DrawString(BasicFont, s, new Vector2(leftOffset, currentY), Color.OrangeRed); currentY += spacing + BasicFont.MeasureString(s).Y; } } } lock (_DebugMapLocker) { if (_draw) { //float textureScale = 1 / (100 / _DebugGridWidth); int gridScale = (int)((_DebugGridWidth / 10.0f) * Map.CmToPixel); foreach (var point in _DebugMap) { int x = (int)((point.x / 10.0f) * Map.CmToPixel); int y = (int)((point.y / 10.0f) * Map.CmToPixel); Rectangle targetPosition = new Rectangle(x, y, gridScale, gridScale); switch (point.status) { case communication.DebugGridPointStatus.Invalid: _InValidColor.A = (byte)(point.alpha + 50); spriteBatch.Draw(DebugGridTexture, targetPosition, _InValidColor); break; case communication.DebugGridPointStatus.Valid: _ValidColor.A = (byte)(point.alpha + 50); spriteBatch.Draw(DebugGridTexture, targetPosition, _ValidColor); break; case communication.DebugGridPointStatus.Wall: _WallColor.A = (byte)(point.alpha + 50); spriteBatch.Draw(DebugGridTexture, targetPosition, _WallColor); break; case communication.DebugGridPointStatus.Cyan: _WallColor.A = (byte)(point.alpha + 50); spriteBatch.Draw(DebugGridTexture, targetPosition, Color.DarkCyan); break; } } } } }
static void Main(string[] args) { ClockFont = BasicFont.DigitalClockFont; if (args.Length > 0) { if (args[0].ToUpper().EndsWith(".DOD")) { dir = args[0]; } if (args[0].ToUpper().EndsWith(".BFNT")) { FontDir = args[0]; } } MainClock = LoadClock(); MainClock.Init(); if (Collapsed) { Collapse(); } else { Expand(); } MainClock.RunAsync(); string[] ReadSplit; StartAudioVoiceBackend(); do { RenderUtils.SetPos(1, 10); String Read = Console.ReadLine(); Draw.Row(ConsoleColor.Black, Read.Length, 1, 10); Draw.ClearLine(12); RenderUtils.SetPos(0, 12); ReadSplit = Read.Split(' '); Parse(ReadSplit); Save(); } while(ReadSplit[0].ToUpper() != "CLOSE"); MainClock.Stop(); AudioVoiceThread.Abort(); }
private static void SendMessageLine(Ssd1306 device, string message) { int bytesSend = 0; foreach (char character in message) { byte[] chars = BasicFont.GetCharacterBytes(character); device.SendData(chars); bytesSend += chars.Length; } int bytesDiff = Math.Abs(bytesSend - 64); byte[] bytesComplete = new byte[bytesDiff]; device.SendData(bytesComplete); }
public static void Save() { Dictionary <string, string> SaveDict = new Dictionary <string, string> { { "FONT", FontDir }, { "BG", BasicFont.ConsoleColorToColorChar(MainClock.BG) + "" }, { "FG", BasicFont.ConsoleColorToColorChar(MainClock.FG) + "" }, { "MILITTIME", MainClock.MilitaryTime.ToString() }, { "SHOWDATE", MainClock.ShowDate.ToString() }, { "SHOWSECONDS", MainClock.ShowSeconds.ToString() }, { "ADJUSTHOURS", MainClock.HourAdjust.ToString() }, { "AUDIO", Audio.ToString() }, { "VOICE", Voice.ToString() }, { "COLLAPSED", Collapsed.ToString() } }; DOD.Save(SaveDict, dir); }
public static Clock LoadClock() { if (!File.Exists(dir)) { return(DefaultClock()); } Dictionary <String, String> LoadDict = DOD.Load(dir); try { Clock ReturnClock; if (string.IsNullOrWhiteSpace(FontDir)) { FontDir = LoadDict["FONT"]; } if (!string.IsNullOrWhiteSpace(FontDir)) { ReturnClock = new Clock(BasicFont.LoadFromFile(FontDir), 2, 1); } else { ReturnClock = new Clock(2, 1); } ReturnClock.BG = GraphicUtils.ColorCharToConsoleColor(LoadDict["BG"][0]); ReturnClock.FG = GraphicUtils.ColorCharToConsoleColor(LoadDict["FG"][0]); ReturnClock.MilitaryTime = Boolean.Parse(LoadDict["MILITTIME"]); ReturnClock.ShowDate = Boolean.Parse(LoadDict["SHOWDATE"]); ReturnClock.ShowSeconds = Boolean.Parse(LoadDict["SHOWSECONDS"]); ReturnClock.HourAdjust = int.Parse(LoadDict["ADJUSTHOURS"]); Audio = Boolean.Parse(LoadDict["AUDIO"]); Voice = Boolean.Parse(LoadDict["VOICE"]); Collapsed = Boolean.Parse(LoadDict["COLLAPSED"]); return(ReturnClock); } catch (Exception) { Draw.CenterText("There was an error loading file " + dir.Split('\\')[dir.Split('\\').Length - 1], Console.WindowHeight / 2, ConsoleColor.Red, ConsoleColor.Black); RenderUtils.Pause(); Draw.ClearLine(Console.WindowHeight / 2); return(DefaultClock()); } }
protected override void Run() { Font f = new BasicFont(); FontRenderer fr = new FontRenderer(display, f); Desktop desktop = null; WindowManager windowManager = new WindowManager(display, desktop, fr); //windowManager.addWindow(new HelloWorldProgram(windowManager)); int status = 0; while (true) { PrintDebug("Before Step"); status = windowManager.step(); PrintDebug("After Step"); mr.renderMouse(); display.step(); } }
/// <summary>Creates an object to hold the text, but formatted to the given maximum width and maximum height (Based on the provided BasicFont)</summary> /// <param name="Text"></param> /// <param name="MaxWidth"></param> /// <param name="MaxHeight"></param> /// <param name="Font"></param> public BasicFontFormattedText(String Text, BasicFont Font, int MaxWidth, int MaxHeight) { //this is so we can handle \n Text = Text.Replace("\n", " \n "); //Split text into words String[] Words = Text.Split(' '); //Some variables we will need int CurrentWord = 0; List <String> Lines = new List <String>(); int LongestLine = 0; while (CurrentWord < Words.Length && (Lines.Count * Font.Height) < MaxHeight) { String Line = ""; if (Words[CurrentWord].Length * Font.Width > MaxWidth) { Words[CurrentWord] = Words[CurrentWord].Substring(0, MaxWidth - 1); } while (CurrentWord < Words.Length && (((Line.Length + Words[CurrentWord].Replace("\n", "").Length) * Font.Width) < MaxWidth)) { //If we have a next word, and the word's length plus whatever we already have is shorter than the maximum width, add it to the line if (Words[CurrentWord] == "\n") { CurrentWord++; break; } Line += Words[CurrentWord] + " "; CurrentWord++; } //The line is as long as its going to be. Lines.Add(Line); LongestLine = Math.Max(LongestLine, Line.Length); } this.Text = String.Join("\n", Lines.ToArray()); ActualHeight = Lines.Count; ActualWidth = LongestLine; }
public PreviewForm(BasicFont Font) { InitializeComponent(); MyFont = Font; }
public DemoGameImplementation(GameImages gameTextures) { _gameTextures = gameTextures; _yellowFont = new BasicFont(_gameTextures.YellowFont); }
/// <summary>Returns a string formatted to fit in a box of with maximum dimensions of specified width/height</summary> /// <param name="Text"></param> /// <param name="MaxWidth"></param> /// <param name="MaxHeight"></param> /// <param name="Font"></param> /// <returns></returns> public static String Format(String Text, BasicFont Font, int MaxWidth, int MaxHeight) { return(new BasicFontFormattedText(Text, Font, MaxWidth, MaxHeight).Text); }
/// <summary>Creates a label window element of the specified maximum width and maximum height</summary> /// <param name="Parent"></param> /// <param name="Text"></param> /// <param name="Font"></param> /// <param name="MaxWidth"></param> /// <param name="MaxHeight"></param> /// <param name="FG"></param> /// <param name="LeftPos"></param> /// <param name="TopPos"></param> public BasicFontLabel(Window Parent, string Text, BasicFont Font, int MaxWidth, int MaxHeight, ConsoleColor FG, int LeftPos, int TopPos) : this(Parent, new BasicFontFormattedText(Text, Font, Math.Min(Parent.Length - LeftPos, MaxWidth), Math.Min(Parent.Height - TopPos, MaxHeight)), Font, FG, LeftPos, TopPos) { }
/// <summary>Creates a Label Window element</summary> /// <param name="Parent"></param> /// <param name="Text"></param> /// <param name="Font"></param> /// <param name="FG"></param> /// <param name="LeftPos"></param> /// <param name="TopPos"></param> public BasicFontLabel(Window Parent, string Text, BasicFont Font, ConsoleColor FG, int LeftPos, int TopPos) : this(Parent, new BasicFontFormattedText(Text, Font, Parent.Length - LeftPos, Parent.Height - TopPos), Font, FG, LeftPos, TopPos) { }