TextRender v1.7 - Draw text on screen

Post your working scripts, libraries and tools for AHK v1.1 and older
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

TextRender v1.7 - Draw text on screen

Post by iseahound » 29 Apr 2021, 21:54

TextRender
  • Standalone library without dependencies.
  • Draws beautiful text on screen.
  • Features background color, text outline, and drop shadow.
  • Renders to the screen, desktop, or behind desktop icons as a wallpaper.
  • Supports events such as OnEvent("LeftMouseDown", callback).
  • Extremely fast and lightweight, capable of rendering at 300+ fps.
Graphics Library
Documentation

Demo Scripts included:
https://github.com/iseahound/TextRender/releases

Full Script

This is a beta release. Suggestions and pull requests welcome. Feel free to share whatever you make I'll include it in future releases or as a showcase. This will be translated to AutoHotkey v2 once the that beta is released.
Last edited by iseahound on 22 May 2022, 00:02, edited 8 times in total.

ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: TextRender v1.01 beta - Draw text on screen

Post by ozzii » 30 Apr 2021, 03:16

Thanks.
This can be useful for changing my classic progress messages

neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: TextRender v1.01 beta - Draw text on screen

Post by neogna2 » 02 May 2021, 04:27

I could not get any of the demos to work.
When I run this minimal script

Code: Select all

#include TextRender.ahk
tr := TextRender("hello world", "time:3000")
return
Esc:: ExitApp
It throws the error
1904: Throw,Exception("Missing TextRender.gdiplusStartup().")

AutoHotkey U32 v1.1.33.07.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.02 beta - Draw text on screen

Post by iseahound » 02 May 2021, 15:29

@neogna2 Thank you for bringing this to my attention. The error was due to an incompatibility with 32-bit AutoHotkey, and is now fixed.

tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: TextRender v1.02 beta - Draw text on screen

Post by tuzi » 06 May 2021, 21:23

that's relly cool.
i love all your projects.
thank you iseahound.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.02 beta - Draw text on screen

Post by iseahound » 18 May 2021, 10:53

I appreciate all the support everyone. Question for anyone whose uses this library: Should I make NoActivate the default? In other words, when the user clicks on a TextRender() window, the focus is shifted away. This can cause changes in other applications, such as the tabs in a web browser going from light to dark. I'm thinking of preventing this behavior.

braddo
Posts: 6
Joined: 05 Jun 2021, 10:28

Re: TextRender v1.05 beta - Draw text on screen

Post by braddo » 25 Jun 2021, 20:03

Is this library intended to be used to make front ends? Are there any videos or visual examples of stuff done with it? Looked at the Github, seems very well documented! ... except maybe the high level, whats it for? type of intro.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.05 beta - Draw text on screen

Post by iseahound » 11 Dec 2021, 12:10

It's just something I was working on, and it became over-engineered. I think the idea was to just create a simple text box that the user could interact with. So, to answer your question, yes, it is meant to create a front-end.

brentor
Posts: 1
Joined: 21 May 2022, 16:53

Re: TextRender v1.5 - Draw text on screen

Post by brentor » 21 May 2022, 17:15

Hi @iseahound, I've been using TextRender in an ambitious, gaming-related project for a couple months and as a seasoned engineer, I appreciate the more modern approach to GUI than AHK's built-in stuff... TextRender is much less insane. Thank you for your work!
The reason I'm posting is that I'm looking to load images as part of the TextRender UI that I'm building (I have something drawn just with the TextRender styles that I want to add pre-drawn images/icons/emojis to).
I see that you include an ImageRender class, but there is no documentation or examples for using this (here or on GitHub). It also seems that by instantiating an ImageRender class, that will work as it's own window/hwnd and therefore images loaded with ImageRender cannot be used as layers in a TextRender graphics buffer.... Which for my project effectively means that every time the user moves a TextRender window associated with an ImageRender image, I have to separately adjust the screen coordinates of each ImageRender image.
Do you have any suggestions for me to handle this in a smarter way (something closer to ImageRender working as TextRender layers), or do you think it would otherwise be a mistake for me to merge the TextRender and ImageRender DrawOnGraphics() functionality to combine these?

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.5 - Draw text on screen

Post by iseahound » 21 May 2022, 23:37

Hi Thanks a lot for your interest! I believe what you are requesting is a DrawImage() and DrawText() function. Currently, I've built out the TextRender() class, which provides all the methods and properties necessary to draw text, and at some point I realized that if I replaced the text drawing function with an image drawing function, it would do the exact same thing.

I don't know exactly what the best choice is from a user perspective, but here are a few options, and you can of course suggest your own.
  • Keep the classes separate, so that Render() can refer to either Image or Text. Include a DrawText() function in an instance of ImageRender, and a DrawImage() function in an instance of TextRender.
  • Merge the two classes, and retain a DrawImage() function.
  • Merge the two classes, but rename Draw to DrawText and DrawImage, Render to RenderText and RenderImage.
Also if you have any suggestions on the integration of ImagePut, that would be helpful too. Currently I'm leaning on removing dependency from ImagePut and supporting only file / url and a few basic types.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: TextRender v1.7 - Draw text on screen

Post by viv » 28 May 2022, 05:12

Can you tell me if V2 version is working properly?
I see that V2 was updated 4 days ago,
but I can't get it to work with the 2# example.

The prompt

Code: Select all

Error in #include file "F:\Documents\Downloads\TextRender.ahk":
     This value of type "Class" has no method named "__New".

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 28 May 2022, 10:09

I can spend some time right now to fix more v2 bugs.

EDIT: Post your code

EDIT 2: Fixed that! Most TextRender code should now work. Remember that the v2 version is still a work in progress, so if you encounter any more bugs, feel free to contact me via the forum or by opening an issue on the GitHub.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: TextRender v1.7 - Draw text on screen

Post by viv » 28 May 2022, 22:57

Thank you very much
It works fine in v2 now
I will do more testing and will give you feedback in github if there are any problems.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: TextRender v1.7 - Draw text on screen

Post by viv » 29 May 2022, 23:19

d.void o.void are undefined at some point

False if undefined in V1
In V2, it must be defined

I added d.void := false to a few conditions before d.void := True
but it doesn't work.

There may be other similar ones such as m.void that I haven't used yet

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 29 May 2022, 23:52

Yes, dropshadow / margin / outline seems to be the last set of bugs. It has to do with the new v2 object system, many things that were easy no longer work. I'll find a clever way to fix this - I think I can just override __Get and ignore __Item

Changes so far: (1.8 prerelease)
  • Creating a new instance of TextRender() with no parameters no longer calls Render().
  • Calling Render() a second time now correctly blanks the screen.
  • Add NoActivate() window style to prevent focus being stolen.
  • Add Sleep(sleep_time, wait_time).
  • Sleep() will wait, then blank for sleep_time in milliseconds.
  • Conform #RRGGBBAA to CSS4 spec. Was previously aarrggbb.
  • Default() is changed to Right-click on close.
Bugfixes
  • Script no longer crashes when #MaxThreads is reached.
  • Restore background when using dropshadow.
  • Global Labels have been removed.
  • Fix possible collision in this.status using rng.
  • Fix Draw("") producing strange artifacts.
  • Justification values (1-3) are now working properly.
  • WindowProc uses critical threads, preventing critical read/write errors.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 01 Jun 2022, 11:24

viv wrote:
29 May 2022, 23:19
d.void o.void are undefined at some point
Everything is fixed. TextRender is now 100% compatible with AutoHotkey v2. Let me know if you find anything else.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: TextRender v1.7 - Draw text on screen

Post by viv » 02 Jun 2022, 02:14

@iseahound

Thanks for the fix, I just tested it and it's working fine


Here to report a small problem that I do not know whether it is a bug or what

I want to implement different styles of headers and body text in the prompt
Since I don't know how to set the style of different text in one Instance
So I used two Instances to implement it

The finished result looks like this
20220602150308.jpg
20220602150308.jpg (8.07 KiB) Viewed 5150 times

Worked very well
But this seems to have a small problem
It works fine when I implement it with a function
If I don't use the function, it reports an error
I don't understand why at all

Here is the sample code

Code: Select all

#SingleInstance Force
#Include <TextRender>

ToolTip("this function")
Tips("test", "123456789987654321", "3000ms")
Tips(title := "", text := "", cooltime := "1000ms")
{
    tr := TextRender().NoActivate().None()
    tr2 := TextRender().NoActivate().None()

    tr.Render(text, "c:Random x:right y:85% t:" cooltime)
    pos := "x:" tr.x + 11 " y:" tr.y - tr.h + 11 " w:" tr.w
    tr2.Render(title, "c:Random " pos " t:" cooltime, "j:left")
}
Sleep(3000)


ToolTip("this will error")

title := "test"
text := "123456789987654321"
cooltime := "3000ms"
tr := TextRender().NoActivate().None()
tr2 := TextRender().NoActivate().None()

tr.Render(text, "c:Random x:right y:85% t:" cooltime)
pos := "x:" tr.x + 11 " y:" tr.y - tr.h + 11 " w:" tr.w
tr2.Render(title, "c:Random " pos " t:" cooltime, "j:left")
Sleep(3000)

ExitApp
This is the error message, and the following two I will not upload up
1.jpg
1.jpg (45.86 KiB) Viewed 5150 times

Since it works properly in the function, it doesn't affect me much
Finally thank you for your work

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: TextRender v1.7 - Draw text on screen

Post by viv » 02 Jun 2022, 02:22

I just tested it.
I found that as soon as two new instances are created in the global, it reports an error
But not if you create a new instance in a function...

Code: Select all

#SingleInstance Force
#Include <TextRender>

fn()

fn()
{
    tr := TextRender()
    tr2 := TextRender()
}

Sleep(1000)

;next will error
tr := TextRender()
tr2 := TextRender()
ExitApp

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 02 Jun 2022, 09:50

I messed around with it, and sadly to say did not come up with any good solutions. In the meantime you can explicitly destroy your objects with tr := "" before ExitApp. This is v2 limitation, but maybe I find a workaround in the future.

Code: Select all

#include *i TextRender%A_TrayMenu%.ahk
#include *i TextRender (for v%true%).ahk
#singleinstance force

title := "test"
text := "123456789987654321"
cooltime := "3000ms"
tr := TextRender().NoActivate().None()

tr.Draw(text, "a:top-right c:Random x:right y:85% width:20% t:" cooltime, "j:left n:true")
tr.Render(title, {c:"Random", a: "top-right", x: "right", y: tr.y - tr.h + 11, w: "20%", t: cooltime}, "j:left n:true")

Sleep(3000)
tr:="" ; Prevents error.
ExitApp
Last edited by iseahound on 02 Jun 2022, 09:56, edited 1 time in total.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 02 Jun 2022, 09:53

Maybe use Wait() instead of sleep. I get no errors like this

Code: Select all

title := "test"
text := "123456789987654321"
cooltime := "3000ms"

tr := TextRender().NoActivate().None()
tr.Draw(text, "a:top-right c:Random x:right y:85% width:20% t:" cooltime, "j:left n:true")
tr.Render(title, {c:"Random", a: "top-right", x: "right", y: tr.y - tr.h + 11, w: "20%", t: cooltime}, "j:left n:true")
tr.Wait()

ExitApp

Post Reply

Return to “Scripts and Functions (v1)”