Skip to content

Tips & Tricks

Edison Hua edited this page May 22, 2022 · 37 revisions

Helpful Tips

  • You can call tr := TextRender(text, backgroundstyles, textstyles) by itself. Use this one-line format to save time and space!

  • You can use object notation TextRender("Alert!", {time:3000, color:"Blue"}) instead of string notation TextRender("Alert!", "time:3000 color:Blue").

  • Object Notation extends to nested elements as well.

    tr := TextRender("Und über uns ziehen lila Wolken in die Nacht" , {color: "#F9E27E"} , { font: "Century Gothic" , size: 60 , color: "#F88958" , outline: [5, "Indigo"] , dropShadow: { horizontal: 5 , vertical: 5 , blur: 0 , color: "#009DA7"}}) ; what

  • To draw multiple layers, call tr.Draw(text) multiple times, then call tr.Render() with blank parameters to render all those draws on screen.

  • If you need to display text on screen temporarily, take advantage of the time syntax: TextRender("Au revoir", "time:3000") — this will display "Au revoir" for 3 seconds! Note that this can be used without assigning the expression to a variable!

  • If you are memory-conscious, be sure to call FreeMemory() immediately after to reduce memory usage by over 60%.

  • Tired of objects being clipped by the edges of the screen? Try RenderOnScreen() instead.

  • Place SetBatchLines -1 at the top of your script for a 2x speedup.

Styling Text

  • Setting the quality of the text to ClearType will improve the overall look of the text on mostly opaque backgrounds. By default, ClearType is only enabled when the background color is completely opaque. Example: q:5
  • Increase the readability without increasing font size, by setting the outline stroke to 1. This creates a pseudo-bold effect. For small font sizes, it will decrease the space between letters, saving you on-screen real estate! Example: outline:(stroke:1px) or o:(1px)
  • Use an alternative rendering process by setting the outline stroke to 0 pixels. Whether this is an improvement depends on the font and font size used. Example: outline:(stroke:0px) or o:(0px)
  • Speed up text rendering by setting the text quality to 0. This will disable anti-aliasing. Create a cool stencil effect with quality:0 color:None outline:(stroke:1px color:Black)!
  • Avoid using the glow parameter in outline. It's very slow and will delay your render time. If you must use it, choose an number less than 5px. Anything more will slow down your script exponentially.
  • Create a interesting effect by making the text "eat" through the background. Use color:Delete or color:Erase as the text color.
  • If the text color is omitted, it defaults to white or black depending on the background color!
  • The text position can be independent of the background. Use x and y to position your text off the background box.

Styling Background

  • If you want to set the background to be transparent, you can use c:None, c:Off, c:Clear, or c:Transparent. Don't use w:0 or h:0. Even though they work - they act weird changing your x and y positions.
  • A random color can help keep your background boxes fresh. Try color:Random2 for a random solid color.

Methods and Properties

  • Although text cannot be rendered off screen with Render(), the whole picture can be recovered with Save(), RenderToBitmap(), and RenderToHBitmap().
  • RenderOnScreen() will render the entire canvas. Although it preforms slower than Render(), it is optimized to fall back to Render() when the entire object is in the visible screen area. It's the best of both worlds!
  • Using RenderOnScreen() may cause objects to be mispositioned. That's why Render() is the default.
  • Save() must be called after Render(), or subsequent drawing operations will have cleared what is being saved.
  • The window handle can be retrieved with tr.hwnd.
  • tr.x, tr.y, may be inaccurate when it comes to off screen coordinates. To retrieve the exact coordinates try WindowLeft, WindowTop, WindowRight, WindowBottom, WindowWidth, and WindowHeight. If the user has moved the window you will have to use WinGetPos instead.
  • To avoid rendering to the screen, use Flush() instead. This does the same thing as Render() without modifying the screen.
  • You must clean up any pointers returned by CopyToBitmap() and RenderToBitmap() with DllCall("gdiplus\GdipDisposeImage", "ptr", pBitmap). Likewise for CopyToHBitmap() and RenderToHBitmap(), DllCall("DeleteObject", "ptr", hbm) must be called.
  • Use tr.GUID to check if the internal graphics has been changed and use tr.Hash() to check if two internal graphics states are identical.

Advanced Tricks

  • Methods can be chained, as in tr.Draw(text1).Draw(text2).Render()
Clone this wiki locally