TextRender v1.7 - Draw text on screen

Post your working scripts, libraries and tools for AHK v1.1 and older
viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: TextRender v1.7 - Draw text on screen

Post by viv » 02 Jun 2022, 10:54

@iseahound

Display different styles in one instance
My initial goal was this
It should be that I didn't read the document too carefully

Thank you for your help

But the error is not caused by sleep
I used sleep at first to locate the wrong location

As long as you create a second instance, you will get an error

Code: Select all

tr := TextRender()
tr := TextRender()

Now my needs are solved
it doesn't require two instances

I have a small question, can this support more layers?
Let's say I need four different styles
If can't, you have to create multiple instance to implement it.
I'll take a closer look at the documentation, if I can it's not a problem

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 02 Jun 2022, 11:44

As long as you delete TextRender before exit, there should be no error.

Code: Select all

tr1 := TextRender()
tr2 := TextRender()
tr1:=0
tr2:=0
ExitApp ; Is v2 limitation. 
You can call Draw() as many times as you need.

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

Re: TextRender v1.7 - Draw text on screen

Post by viv » 02 Jun 2022, 12:20

@iseahound

Although I don't understand why this is the case
But I might understand why there is no error in the function

https://lexikos.github.io/v2/docs/Functions.htm#Local
All local variables which are not static are automatically freed (made empty) when the function returns, with the exception of variables which are bound to a closure or VarRef (such variables are freed at the same time as the closure or VarRef).
This is equivalent to automatically clearing tr when the function returns

If there is a static inside the function, there will also be an error when ExitApp()

Code: Select all

fn()


fn()
{
     tr1 := TextRender()
     tr2 := TextRender()
    ;  static tr3 := TextRender() ;will error
}

ExitApp()

But that's not a problem
It can be implemented in one instance and there is no need to create multiple instances


Thank you for your work
Finally have a great life!

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 02 Jun 2022, 13:08

It is because the order of destruction is... alphabetical.

If you rename your variable tr to a or b you will not get the error.
Order of destruction
a
b ; I found TextRender
TextRender
tr1 ; Where is TextRender?
tr2
Feel free to ask Lexikos about this

User avatar
MomoArts
Posts: 5
Joined: 10 Jun 2022, 16:09

Re: TextRender v1.7 - Draw text on screen

Post by MomoArts » 11 Jun 2022, 01:14

Hello I've fallen In love with your script it's the most beautiful one for creating text, and its so well documented, but I've been struggling trying to get it to render images so I can have a cute graphic above the text while I move it.

I tried this and notice that I was getting rectangles of random colors with the dimensions of the images in path so I knew it was kind of working and went back to troubleshooting the issue.

Code: Select all

path := "img.png"
ir := ImageRender()
ir.Render(path, "c:Random")
After a few hours of messing around I got it to work with the same code after closing all my open apps and scripts and it worked!
Seemed like the issue was the fact had the image opened in MS paint which gave the window the title of "img.png - Paint". half of my images work after adding "SetTitleMatchMode 3" to the top of the script.

Sadly the other half still didn't work so I went back to troubleshooting, the 2nd issue seems to be related to the dimensions of the images, only the ones with either a width or height larger than my screen size seemed to work, I'm assuming something in script checks then updates the canvas if its larger than the screen size?

I don't think I'm smart enough to fix the 2nd issue but ill try my best to help >.<
Gonna follow the suggestion you gave brentor on how to instance/merge the ImageRender with TextRender if this gets figured out, thank you again for this script its so Good! :dance:

Edit: I found a work around for now by changing the follow and scaling the image by 1

Code: Select all

         ; Draw image using GDI.
         ; if (q = 0 || w == width && h == height) 
         if (q = 0 || w != width && h != height) 
AutoHotkey U64 1.1.34.03 WIN10

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 12 Jun 2022, 09:04

Ah well ImageRender is neglected at the moment. Could you help me by offering your opinion on this post over here?

viewtopic.php?p=463471#p463471

I have no idea how ImageRender is being used, as such, I am at a loss to decide whether to incorporate the two classes, or to keep them separate.

User avatar
MomoArts
Posts: 5
Joined: 10 Jun 2022, 16:09

Re: TextRender v1.7 - Draw text on screen

Post by MomoArts » 12 Jun 2022, 19:14

I feel like the best choice would be whats best for CPU performance and FPS, not sure what method that would be.
The main cases I can see ImageRender being used is for GUIs that have a have an image that doesn't need to be on the same canvas as the text to follow it, and the other case would be where it does need to follow.
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.
I like this choice the most it would cover both scenarios, the best

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 12 Jun 2022, 23:36

Appreciate the input. For CPU performance is 30 frames per second at 1920x1080 okay? I can try to squeeze some more, but I also assume most images will be smaller, so will easily surpass 60+ FPS. It'll take some time to get everything up to my level of satisfaction

User avatar
MomoArts
Posts: 5
Joined: 10 Jun 2022, 16:09

Re: TextRender v1.7 - Draw text on screen

Post by MomoArts » 13 Jun 2022, 00:36

30 frames per second at 1920x1080 should be okay, I don't have any performance issues personally it works great!

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 13 Jun 2022, 15:38

v1.8 - Includes a speed test demonstration script. I get 1000 fps

https://github.com/iseahound/TextRender/releases

User avatar
MomoArts
Posts: 5
Joined: 10 Jun 2022, 16:09

Re: TextRender v1.7 - Draw text on screen

Post by MomoArts » 18 Jun 2022, 12:38

I notice a flicker when drag and dropping text or images, is there anything I can do to avoid that?

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 18 Jun 2022, 16:53

There hasn't been any flicker in my testing, could you post the code / steps to reproduce?

User avatar
MomoArts
Posts: 5
Joined: 10 Jun 2022, 16:09

Re: TextRender v1.7 - Draw text on screen

Post by MomoArts » 18 Jun 2022, 23:31

My bad the issue was on my end and is now fixed

User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: TextRender v1.7 - Draw text on screen

Post by gwarble » 08 Sep 2022, 19:41

awesome, thanks for sharing (switching from <Graphics> was painless too).

starting with:
RenderTime := TextRender("", "x:0vw w:100vw y:67vh q:4 c:00000000 justify:right", "q:4 justify:right s:18vh f:(Segoe UI Light)")

i'd like to support multiple monitors:

Code: Select all

 SysGet, MonitorCount, MonitorCount
 Loop, % MonitorCount
  RenderTime%A_Index% := TextRender("", "x:0vw w:100vw y:67vh q:4 c:00000000 justify:right", "q:4 justify:right s:18vh f:(Segoe UI Light)")
is there a trick to use the relative positioning x:0vw w:100vw y:67vh justify:right for a secondary/specific monitor? of course I can do the math and give absolute positions instead, but if the library supports it, even better

thanks,
gwarble
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 09 Sep 2022, 11:35

Not at the moment. It should default to the primary monitor, but your text can be manually positioned to a different monitor.

TextRender is used by very few people, so perhaps if it gets more popular :)

User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: TextRender v1.7 - Draw text on screen

Post by gwarble » 10 Sep 2022, 15:33

thanks for the quick reply... not a problem to handle script side by just doing the math:

Code: Select all

 Loop, % MonitorCount
  SysGet, Monitor%A_Index%, Monitor, % A_Index

 Loop, % MonitorCount
  RenderTime%A_Index% := TextRender("", "x:" Monitor%A_Index%Left " w:" Monitor%A_Index%Right - Monitor%A_Index%Left " y:" Monitor%A_Index%Top + (Monitor%A_Index%Bottom-Monitor%A_Index%Top)*.67 " q:4 c:00000000 justify:right", "q:4 justify:right s:18vh f:(Segoe UI Light)")

I mainly wanted to make sure I wasn't missing an option since you handle everything so well
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: TextRender v1.7 - Draw text on screen

Post by gwarble » 28 Sep 2022, 18:31

Hello again,

Scratching my head and I can't find anything wrong with the math so I hesitate to suggest there might be a bug in the Y position on a second monitor that is in the negative X range, ie dual monitors with the primary the one on the right is the only place I see this problem... when the primary is on the left (ie all X values are 0 positive) everything works right, but when the second monitor is in the -x range, the y values aren't right (or I'm an idiot)

Anyone able to test or notice what I'm doing wrong? I would expect both screenshots to have both messages at the bottom of the screen.

Code: Select all

#Persistent
#Include <TextRender>
 Sysget, MonitorCount, 80
 Loop, % MonitorCount {
  SysGet, Mon%A_Index%, Monitor, % A_Index
  Mon%A_Index%W := Round(Mon%A_Index%Right - Mon%A_Index%Left)
  Mon%A_Index%H := Round(Mon%A_Index%Bottom - Mon%A_Index%Top)
  RenderTime%A_Index% := TextRender("Message", "x:" Mon%A_Index%Left " w:" Mon%A_Index%W " y:" Round(Mon%A_Index%Top + Mon%A_Index%H*.67) " c:FF666666", "m:0 s:" Mon%A_Index%H*.18)
 }
Attachments
-20220928161057.png
-20220928161057.png (59.1 KiB) Viewed 1671 times
-20220928161029.png
-20220928161029.png (50.23 KiB) Viewed 1671 times
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 28 Sep 2022, 19:15

Could you try updating to the latest version on the Github?
v1: https://github.com/iseahound/TextRender/blob/main/TextRender%20(for%20v1).ahk
v2: https://github.com/iseahound/TextRender/blob/main/TextRender.ahk

This sounds very similar to the following bug which was fixed last month.
https://github.com/iseahound/TextRender/issues/11

User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: TextRender v1.7 - Draw text on screen

Post by gwarble » 28 Sep 2022, 19:42

sure does, and updating fixed it (even though ver was still 1.8 6/2022)

any obvious reason that TextRenderWallpaper would still have similar issues with -X?
Edit: I think its a different issue wherein the wallpaper coordinates start 0,0 at the top left even if its negative on the desktop... will test more but probably not a bug in this case

and thanks for the quick response and awesome function
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

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

Re: TextRender v1.7 - Draw text on screen

Post by iseahound » 28 Sep 2022, 20:00

TextRenderWallpaper needs work! It depends on undocumented functionality, so some tinkering will be involved.

Dates change when the release number changes.

Also, I am looking for feedback on the documentation and included examples. Feel free to suggest any changes. Are the docs too wordy, or is there not enough?

https://github.com/iseahound/TextRender/wiki

Post Reply

Return to “Scripts and Functions (v1)”