public override async Task <ImageBase> CacheAppIcon() { ImageBase image; if (string.IsNullOrEmpty(Model.ImageUrl)) { if (!string.IsNullOrEmpty(Model.TileGlyph)) { image = new TextImage { Text = Model.TileGlyph, ImageType = ImageType.Tile, }; } else { image = TextImage.CreateFromName(Title, ImageType.Tile); } } else { image = new FileImage { Url = Model.ImageUrl, ImageType = ImageType.Logo, }; } return(image); }
public void CreateStartScreen() { world = new GameWorld(new Vector2(width, height), language); world.gameState = 0; var backgroundlayer1 = new BackgroundLayer1(world); var backgroundlayer2 = new BackgroundLayer2(world); world.AddObject(backgroundlayer1); world.AddObject(backgroundlayer2); TextImage title = new TextImage(world, "Title"); title.Position = new Vector2(width / 2, height / 2 - 64); title.name = "Title"; title.spriteSizeX = 190; title.spriteSizeY = 16; title.Scale = new Vector2(3, 3); world.AddObject(title); TextImage pressStart = new TextImage(world, "Press"); pressStart.Position = new Vector2(width / 2, height / 2 + 64); pressStart.name = "Press"; pressStart.spriteSizeX = 275; pressStart.spriteSizeY = 47; pressStart.Scale = new Vector2(2, 2); world.AddObject(pressStart); world.pressStart = pressStart; }
private void PasteImage_Loaded(object sender, RoutedEventArgs e) { var window = this.Owner as MainWindow; Editor = window.Model.ActiveEditor; Document = window.Model.ActiveDocument; PasteCommand = new CommandBase((s, args) => { MessageBox.Show("PasteCommand"); }); TextImage.Focus(); if (Clipboard.ContainsImage()) { Button_PasteImage(null, null); } else if (Clipboard.ContainsText()) { string clip = Clipboard.GetText().ToLower(); if ((clip.StartsWith("http://") || clip.StartsWith("https://")) && (clip.Contains(".png") || clip.Contains("jpg"))) { TextImage.Text = clip; SetImagePreview(clip); } } }
/// <summary> /// 清除任何使用中的資源。 /// </summary> /// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } TextImage.releaseAll(); base.Dispose(disposing); }
static void Main(string[] args) { using var bytes = TextImage.RenderImage( new RendererOptions(SystemFonts.Collection.CreateFont("Arial", 12f)), "Hello, world!", Rgba32.CornflowerBlue, Rgba32.White); using var output = File.OpenWrite("File.png"); bytes.SaveAsPng(output); output.Flush(); }
public LeaveLine(string userName) { UserName = userName; Date = DateTime.Now; var icon = TextImage.GetUserImageCode(userName); Text = TextColor.Text + "[" + TextColor.Date + Date.ToShortTimeString() + TextColor.Text + "] " + icon + " " + TextColor.Leave + UserName + TextColor.Text + " left."; }
public SaidExLine(string author, string message) { AuthorName = author; Date = DateTime.Now; Message = message; var icon = TextImage.GetUserImageCode(author); Text = TextColor.Text + "[" + TextColor.Date + Date.ToShortTimeString() + TextColor.Text + "] " + icon + " " + TextColor.Emote + "* " + AuthorName + " " + Message; }
public override async Task <ImageBase> CacheAppIcon() { var icon = Images.FirstOrDefault(i => i.ImageType == ImageType.Logo) ?? TextImage.CreateFromName(Title); if (LinkedPackage != null) { LinkedPackage.AppIconCache = icon; } return(icon); }
//====== ctors protected ScreenTransition(ITextArrayReader prevGameModuleScreenSnapshot, TextCanvas canvas, GameTime gameTime) : base(gameTime) { Verify.NotNull(prevGameModuleScreenSnapshot, nameof(prevGameModuleScreenSnapshot)); this.canvas = Verify.NotNull(canvas, nameof(canvas)); if (prevGameModuleScreenSnapshot.Size.Equals(canvas.Size) == false) { throw new ArgumentException($"Sizes are not equal."); } this.prevGameModuleScreenSnapshot = TextImage.CreateCopyFrom(prevGameModuleScreenSnapshot); }
public override async Task <ImageBase> CacheAppIcon() { try { Guard.IsTrue(Status.IsAtLeast(PackageStatus.Downloaded), nameof(Status)); return(PackagedInstallerHelper.GetAppIcon( (FileInfo)DownloadItem, Type.HasFlag(InstallerType.Bundle))); } catch { return(TextImage.CreateFromName(Title, ImageType.Logo)); } }
private void PasteImage_Loaded(object sender, RoutedEventArgs e) { TextImage.Focus(); if (Clipboard.ContainsText()) { string clip = Clipboard.GetText().ToLower(); if ((clip.StartsWith("http://") || clip.StartsWith("https://")) && (clip.Contains(".png") || clip.Contains("jpg"))) { TextImage.Text = clip; SetImagePreview(clip); } } }
public override async Task <ImageBase> CacheAppIcon() { ImageBase icon = null; if (Model?.IconUrl != null) { icon = new FileImage { Url = Model.IconUrl, ImageType = ImageType.Logo }; } return(icon ?? TextImage.CreateFromName(Model.Title)); }
protected override DataTemplate SelectTemplateCore(object image) { if (image == null) { return(Default); } return(image switch { FileImage _ => File, StreamImage _ => Stream, TextImage _ => Text, ImageBase _ => Default, _ => throw new ArgumentException($"{nameof(image)} must inherit from {nameof(ImageBase)}."), });
//====== public methods public ITextArrayReader RenderImage() { byte[] digits09 = Value.ToString().Select(x => byte.Parse(x.ToString())).ToArray(); int imageWidth = (digits09.Length * 4) - 1; var valueImage = new TextImage(new Size(imageWidth, 5)); for (int i = 0; i < digits09.Length; i++) { var digitImage = TextImage.CreateCopyFrom(BigDigits.GetDigit(digits09[i])); var digitPosition = new Point(i * 4, 0); digitImage.Canvas.Colorize(ForeColor, null); valueImage.Canvas.DrawImage(digitImage, digitPosition); } return(valueImage); }
public FriendJoinedBattleLine(string userName, Battle battle) { Battle = battle; UserName = userName; Date = DateTime.Now; var icon = TextImage.GetUserImageCode(userName); Text = string.Format("{0}[{1}{2}{3}] {4} {5}{6} has joined {7} ({8}) - zk://@join_battle:{9}", TextColor.Text, TextColor.Date, Date.ToShortTimeString(), TextColor.Text, icon, TextColor.Emote, UserName, battle.Title, battle.ModName.Trim(), battle.FounderName); }
private void PasteImage_Loaded(object sender, RoutedEventArgs e) { PasteCommand = new CommandBase((s, args) => { MessageBox.Show("PasteCommand"); }); TextImage.Focus(); if (string.IsNullOrEmpty(Image) && Clipboard.ContainsImage()) { PasteImageFromClipboard(); } else if (string.IsNullOrEmpty(Image) && Clipboard.ContainsText()) { string clip = Clipboard.GetText().ToLower(); if ((clip.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) || clip.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) && (clip.Contains(".png", StringComparison.InvariantCultureIgnoreCase) || clip.Contains("jpg", StringComparison.InvariantCultureIgnoreCase))) { TextImage.Text = clip; SetImagePreview(clip); } } }
public SaidLine(string author, [NotNull] string message, DateTime?date = null) { if (message == null) { throw new ArgumentNullException("message"); } var myName = Program.Conf.LobbyPlayerName; var me = myName == author; var hilite = message.Contains(myName) && !message.StartsWith(string.Format("[{0}]", myName)); AuthorName = author; if (date != null) { Date = date.Value; } else { Date = DateTime.Now; } Message = message; var icon = TextImage.GetUserImageCode(author); var textColor = TextColor.Text; if (me) { textColor = TextColor.History; } else if (hilite) { textColor = TextColor.Error; } Text = TextColor.Text + "[" + TextColor.Date + Date.ToLocalTime().ToShortTimeString() + TextColor.Text + "] " + icon + " " + TextColor.Username + AuthorName + textColor + " " + Message; }
public void Draw(Graphics g, Font font, Color foreColor) { Battle battle; User founder; if (!GetBattleAndFounder(out battle, out founder)) { return; } var x = 1; // margin var y = 3; g.InterpolationMode = InterpolationMode.HighQualityBicubic; Action newLine = () => { x = 1; y += 16; }; Action <string> drawString = text => { TextRenderer.DrawText(g, text, font, new Point(x, y), foreColor); x += (int)Math.Ceiling((double)TextRenderer.MeasureText(g, text, font).Width); }; Action <Image, int, int> drawImage = (image, w, h) => { g.DrawImage(image, x, y, w, h); x += w + 3; }; founder = battle.Founder; drawString("Founder: " + battle.Founder); newLine(); drawString("Map: " + battle.MapName); newLine(); drawString("Players: " + battle.NonSpectatorCount); drawString("Spectators: " + battle.SpectatorCount); drawString("Friends: " + battle.Users.Values.Count(u => Program.FriendManager.Friends.Contains(u.Name))); newLine(); if (founder.IsInGame) { drawImage(ZklResources.boom, 16, 16); if (founder.InGameSince != null) { var timeString = DateTime.UtcNow.Subtract(founder.InGameSince.Value).PrintTimeRemaining(); drawString("The battle has been going on for at least " + timeString + "."); } newLine(); } if (battle.IsPassworded) { drawImage(ZklResources._lock, 16, 16); drawString("Joining requires a password."); newLine(); } newLine(); foreach (var player in battle.Users.Values) { var user = player.LobbyUser; var icon = TextImage.GetUserImage(user.Name); drawImage(icon, 16, 16); Image flag; y += 3; if (Images.CountryFlags.TryGetValue(user.Country, out flag) && flag != null) { drawImage(flag, flag.Width, flag.Height); } else { x += 19; } y -= 3; if (!user.IsBot) { drawImage(Images.GetRank(user.Level), 16, 16); var clan = ServerImagesHandler.GetClanOrFactionImage(user); if (clan.Item1 != null) { drawImage(clan.Item1, 16, 16); } } /* * if (user.IsZkLobbyUser) * { * drawImage(Resources.ZK_logo_square, 16, 16); * }*/ drawString(player.Name); var top10 = Program.SpringieServer.GetTop10Rank(user.Name); if (top10 > 0) { var oldx = x; drawImage(ZklResources.cup, 16, 16); x -= 17; drawString(top10.ToString()); x = oldx + 16; } if (!user.IsBot) { if (user.IsAway) { drawImage(ZklResources.away, 16, 16); } if (user.IsInGame) { drawImage(ZklResources.ingame, 16, 16); } } newLine(); } if (Program.TasClient.MyBattle != null && battle.BattleID == Program.TasClient.MyBattle.BattleID && !String.IsNullOrEmpty(Program.ModStore.ChangedOptions)) { newLine(); drawString("Game Options:"); newLine(); foreach (var line in Program.ModStore.ChangedOptions.Lines().Where(z => !string.IsNullOrEmpty(z))) { drawString(" " + line); newLine(); } } }
public override async Task <ImageBase> CacheAppIcon() { return(TextImage.CreateFromName(ShortTitle)); }
//====== ctors public ScreenBuffer(Size size) : base(size) { buffer = new TextImage(size); }
private void ShowImage(List <TagImg> imgList, bool isHotSpot = false) { Reset(); int columns = imgList.Count / RowCount; int row = 0; if (imgList.Count % RowCount != 0) { columns++; } for (int i = 0; i < columns; i++) { this.grid_Content.ColumnDefinitions.Add(new ColumnDefinition()); } if (this.grid_Content.RowDefinitions.Count != RowCount) { for (int i = 0; i < RowCount; i++) { this.grid_Content.RowDefinitions.Add(new RowDefinition()); } } //暂不做异步加载 for (int i = 0; i < imgList.Count; i++) { string detailUrl = imgList[i].DetailUrl; TextImage image = new TextImage(); image.Width = 300; image.Margin = new Thickness(5); image.Image = imgList[i].Src; image.Text = imgList[i].Alt; image.Cursor = Cursors.Hand; if (isHotSpot) { image.MouseDown += (a, b) => { this.tbox_Keyword.Text = image.Text; btn_Search_Click(null, null); }; } else { image.MouseDown += (a, b) => { string imgUrl = detailUrl; Point p = b.GetPosition(Application.Current.MainWindow); AnimationImageWindow animationDialog = new AnimationImageWindow(); animationDialog.ShowImage(imgUrl, p.X, p.Y); }; } Grid.SetColumn(image, i / RowCount); Grid.SetRow(image, row); this.grid_Content.Children.Add(image); row++; if (row == RowCount) { row = 0; } } }
public override void SetUp() { this.TextImage = new TextImage(); }
/// main game loop /// calls every frame (same as monitor refresh rate) private void CompositionTarget_Rendering(object sender, EventArgs e) { //await Task.Run(new Action(world.GameTick)); world.GameTick(); writeableBmp.Clear(Colors.Black); foreach (GameObject o in world.gameObjects) { o.Draw(writeableBmp); } if (Keyboard.IsKeyDown(Key.Escape)) { if (!pauseHeld) { if (!world.pause) { world.Pause(); } else { world.UnPause(); } } pauseHeld = true; } else { pauseHeld = false; } switch (world.gameState) { case 0: if (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.LeftButton == MouseButtonState.Pressed) { StartGame(); } break; case 1: world.bossHealth.Draw(writeableBmp); world.playerHealth.Draw(writeableBmp); world.waveTimer.Draw(writeableBmp); world.realTimeScore.Draw(writeableBmp); world.rtScoreText.Draw(writeableBmp); break; case 2: world.pauseText.Draw(writeableBmp); break; case 3: world.gameOverText.Draw(writeableBmp); world.pressStart.Draw(writeableBmp); world.scoreText.Draw(writeableBmp); world.scoreNumber.Draw(writeableBmp); if (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.LeftButton == MouseButtonState.Pressed) { StartGame(); } break; } if (world.showGameOver != null && world.gameState == 4) { DebugWrite("game over"); if (world.GameTime() > world.showGameOver.TotalMilliseconds) { world.gameState = 3; TextImage gameOverText = new TextImage(world, "GameOver"); gameOverText.Position = new Vector2(width / 2, height / 2 - 64); gameOverText.name = "GameOver"; gameOverText.spriteSizeX = 105; gameOverText.spriteSizeY = 16; gameOverText.Scale = new Vector2(4, 4); world.gameOverText = gameOverText; TextImage scoreText = new TextImage(world, "Points"); scoreText.name = "Points"; scoreText.spriteSizeX = 71; scoreText.spriteSizeY = 16; scoreText.Position = new Vector2(width / 2 - scoreText.spriteSizeX, height / 2); scoreText.Scale = new Vector2(2, 2); world.scoreText = scoreText; TextImage scoreNumber = new TextImage(world, world.score, false); scoreNumber.name = "font_spreadsheet_x11x16.png"; scoreNumber.spriteSizeX = 11; scoreNumber.spriteSizeY = 16; scoreNumber.Position = new Vector2(width / 2 + 44, height / 2); scoreNumber.Scale = new Vector2(2, 2); world.scoreNumber = scoreNumber; world.pressStart.Position = new Vector2(width / 2, height / 2 + 256); } } Object_Counter.Text = world.gameObjects.Count.ToString(); FPS_Counter.Text = world.GetFPS().ToString(); }
public void Draw(Graphics g, Font font, Color foreColor) { Battle battle; User founder; if (!GetBattle(out battle)) { return; } var fbrush = new SolidBrush(foreColor); var x = 1; // margin var y = 3; g.InterpolationMode = InterpolationMode.HighQualityBicubic; Action newLine = () => { x = 1; y += 16; }; Action <string> drawString = text => { //y -= 3; x += ToolTipHandler.TEXT_X_OFFSET; TextRenderer.DrawText(g, text, font, new Point(x, y + ToolTipHandler.TEXT_Y_OFFSET), Config.TextColor, TextFormatFlags.LeftAndRightPadding); x += TextRenderer.MeasureText(g, text, font).Width; //y += 3; }; Action <Image, int, int> drawImage = (image, w, h) => { g.DrawImage(image, x, y, w, h); x += w + 3; }; drawString("Founder: " + battle.FounderName); newLine(); drawString("Map: " + battle.MapName); newLine(); drawString("Players: " + battle.NonSpectatorCount); drawString("Spectators: " + battle.SpectatorCount); drawString("Friends: " + battle.Users.Count(u => Program.TasClient.Friends.Contains(u.Key))); newLine(); if (battle.IsInGame) { drawImage(Buttons.fight, 16, 16); if (battle.RunningSince != null) { var timeString = DateTime.UtcNow.Subtract(battle.RunningSince.Value).PrintTimeRemaining(); drawString("Battle running for " + timeString + "."); } newLine(); } if (battle.IsPassworded) { drawImage(ZklResources._lock, 16, 16); drawString("Joining requires a password."); newLine(); } newLine(); foreach (var player in battle.Users.Values.Select(u => u.LobbyUser)) { var user = player; var icon = TextImage.GetUserImage(user.Name); drawImage(icon, 16, 16); Image flag; y += 3; if (Images.CountryFlags.TryGetValue(user.Country, out flag) && flag != null) { drawImage(flag, flag.Width, flag.Height); } else { x += 19; } y -= 3; if (!user.IsBot) { drawImage(Images.GetRank(user.Level, user.EffectiveMmElo), 16, 16); var clan = ServerImagesHandler.GetClanOrFactionImage(user); if (clan.Item1 != null) { drawImage(clan.Item1, 16, 16); } } /* * if (user.IsZkLobbyUser) * { * drawImage(Resources.ZK_logo_square, 16, 16); * }*/ drawString(player.Name); if (!user.IsBot) { if (user.IsAway) { drawImage(ZklResources.away, 16, 16); } if (user.IsInGame) { drawImage(Buttons.fight, 16, 16); } } newLine(); } if (Program.TasClient.MyBattle != null && battle.BattleID == Program.TasClient.MyBattle.BattleID && !String.IsNullOrEmpty(Program.ModStore.ChangedOptions)) { newLine(); drawString("Game Options:"); newLine(); foreach (var line in Program.ModStore.ChangedOptions.Lines().Where(z => !string.IsNullOrEmpty(z))) { drawString(" " + line); newLine(); } } fbrush.Dispose(); }
public override void UpdateSettings() { try { string text = Gw2Plugin.Instance.ScriptsManager.FormatString(this.config.GetString("textFormat")); this.oldText = text; this.hideWhenGw2IsInactive = this.config.GetBoolean("hideWhenGw2IsInactive"); FontFamily fontFamily = new FontFamily(this.config.GetString("textFont")); int fontSize = this.config.GetInt("textFontSize"); Color textColor = this.config.GetColor2("textColor"); Color backColor = this.config.GetColor2("backColor"); bool effectBold = this.config.GetBoolean("textBold"); bool effectItalic = this.config.GetBoolean("textItalic"); bool effectUnderline = this.config.GetBoolean("textUnderline"); bool outline = this.config.GetBoolean("outline"); Color outlineColor = outline ? this.config.GetColor2("outlineColor") : Colors.Transparent; double outlineThickness = outline ? this.config.GetFloat("outlineThickness") : 0; bool scrolling = this.config.GetBoolean("scrolling"); int scrollingSpeed = this.config.GetInt("scrollingSpeed"); string scrollingDelimiter = this.config.GetString("scrollingDelimiter"); int scrollingMaxWidth = this.config.GetInt("scrollingMaxWidth"); AlignmentX scrollingAlign = AlignmentX.Left; switch (this.config.GetString("scrollingAlign")) { case "Left": scrollingAlign = AlignmentX.Left; break; case "Center": scrollingAlign = AlignmentX.Center; break; case "Right": scrollingAlign = AlignmentX.Right; break; } bool scrollingLargeOnly = this.config.GetBoolean("scrollingLargeOnly"); this.textImage = new TextImage() { Text = text, FontFamily = fontFamily, FontSize = fontSize, TextColor = textColor, BackColor = backColor, EffectBold = effectBold, EffectItalic = effectItalic, EffectUnderline = effectUnderline, OutlineColor = outlineColor, OutlineThickness = outlineThickness }; if (scrolling) { TextImage scrollingDelimiterImage = new TextImage() { Text = scrollingDelimiter, FontFamily = fontFamily, FontSize = fontSize, TextColor = textColor, BackColor = backColor, EffectBold = effectBold, EffectItalic = effectItalic, EffectUnderline = effectUnderline, OutlineColor = outlineColor, OutlineThickness = outlineThickness }; ScrollingAnimator scrollingAnimator = new ScrollingAnimator() { DelimiterImage = scrollingDelimiterImage, PixelsPerSecond = scrollingSpeed, MaxWidth = scrollingMaxWidth, TextAlign = scrollingAlign, ScrollMode = scrollingLargeOnly ? ScrollMode.TooWideOnly : ScrollMode.ForcedContinuous }; this.textImage.CustomWidth = scrollingMaxWidth; this.textImage.Animators.Add(scrollingAnimator); } this.UpdateTexture(); this.config.Parent.SetInt("cx", this.textImage.CustomWidth ?? this.textImage.Bitmap.PixelWidth); this.config.Parent.SetInt("cy", this.textImage.Bitmap.PixelHeight); this.Size.X = this.textImage.CustomWidth ?? this.textImage.Bitmap.PixelWidth; this.Size.Y = this.textImage.Bitmap.PixelHeight; } catch (Exception ex) { API.Instance.Log("Gw2Plugin: {0}", ex.ToString()); Debug.BreakDebugger(); } }