protected TextButton(Rectangle bounds, string text, Font textFont, Color textColor, CombinedAlignment textAlignment, int depth = 0) { Bounds = bounds; Text = text; TextFont = textFont; TextColor = textColor; TextAlignment = textAlignment; Depth = depth; }
public void Draw(string str, Point pos, Color color, CombinedAlignment alignment = CombinedAlignment.TopLeft, int depth = 0) { if (!Loaded) throw new NotLoadedException(); //replace tab with 4 spaces because SDL.SDL_SDL_ttf.TTF_doesn't str = str.Replace("\t", " "); //create rows by splitting on newline character string[] rows = str.Split('\n'); IntPtr[] rowTextures = new IntPtr[rows.Length]; //add independent drawjob for each line for (int i = 0; i < rows.Length; i++) { //leave blank if there's no use for a texture there (whitespace) if (String.IsNullOrWhiteSpace(rows[i])) { rowTextures[i] = IntPtr.Zero; continue; } Tuple<string, Color> key = new Tuple<string, Color>(rows[i], color); if (Textures.ContainsKey(key)) //use an already rendered texture { rowTextures[i] = Textures[key]; TexturesDrawsUnused[key] = 0; } else //generate a new texture { IntPtr textSurface = SDL_ttf.TTF_RenderUTF8_Blended(Handle, rows[i], color); rowTextures[i] = SDL.SDL_CreateTextureFromSurface(Game.RendererHandle, textSurface); SDL.SDL_FreeSurface(textSurface); Textures.Add(key, rowTextures[i]); TexturesDrawsUnused.Add(key, 0); } uint format; int access, w, h; SDL.SDL_QueryTexture(rowTextures[i], out format, out access, out w, out h); float horizontalOffset = 0f; float verticalOffset = 0f; //horizontal alignment if (alignment.HasFlag((CombinedAlignment)HorizontalAlignment.Center)) horizontalOffset = -w / 2f; if (alignment.HasFlag((CombinedAlignment)HorizontalAlignment.Right)) horizontalOffset = -w; //vertical alignment if (alignment.HasFlag((CombinedAlignment)VerticalAlignment.Top)) verticalOffset = i * LineHeight; if (alignment.HasFlag((CombinedAlignment)VerticalAlignment.Middle)) verticalOffset = -rows.Length * LineHeight / 2f + i * LineHeight; if (alignment.HasFlag((CombinedAlignment)VerticalAlignment.Bottom)) verticalOffset = -rows.Length * LineHeight + i * LineHeight; Point texturePos = pos + new Point(horizontalOffset, verticalOffset); Point textureSize = new Point(w, h); DrawX.DrawJobs.Add(new TextureDrawJob(depth, new Rectangle(texturePos, textureSize), rowTextures[i], new Rectangle(Point.Zero, new Point(w, h)), new ComplexRectangle(texturePos, textureSize))); } }
public FullImageButton(Point position, Sprite sprite, string text, Font textFont, Color textColor, CombinedAlignment textAlignment = CombinedAlignment.MiddleCenter, int depth = 0) : this(new Rectangle(position, sprite.FrameSize), sprite, text, textFont, textColor, textAlignment, depth) { }
public FullImageButton(Rectangle bounds, Sprite sprite, string text, Font textFont, Color textColor, CombinedAlignment textAlignment = CombinedAlignment.MiddleCenter, int depth = 0) : base(bounds, text, textFont, textColor, textAlignment, depth) { Sprite = sprite; }
public AlignmentAssociation this[CombinedAlignment key] { get { return(this.FirstOrDefault(aa => aa.Key == key)); } }
public static void SetEditorRole(DependencyObject obj, CombinedAlignment value) { obj.SetValue(EditorRoleProperty, value); }
public static void Draw(string str, Font font, Point pos, Color color, CombinedAlignment alignment = CombinedAlignment.TopLeft, int depth = 0) { font.Draw(str, pos, color, alignment, depth); }