|
|
|
12-06-2018, 08:37 AM
|
#1
|
Human being with feelings
Join Date: Oct 2018
Posts: 9
|
What exactly does gfx.update do?
And do I really need to call it?
|
|
|
12-06-2018, 09:13 AM
|
#2
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
It redraws the GUI window your script may have opened.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
12-07-2018, 07:33 AM
|
#3
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
When you open a window with gfx.init and you draw into it, you need to call gfx.update or otherwise, your drawn-stuff will not be shown.
Especially with defer-scripts, this is important.
It has the great benefit, that you can draw your stuff first, before actually showing it.
Otherwise, when seeing every element drawn at the time of calling of the drawing-function, this would cause flickering graphics.
|
|
|
01-03-2020, 03:16 AM
|
#4
|
Human being with feelings
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
|
Quote:
Originally Posted by mespotine
When you open a window with gfx.init and you draw into it, you need to call gfx.update or otherwise, your drawn-stuff will not be shown.
Especially with defer-scripts, this is important.
It has the great benefit, that you can draw your stuff first, before actually showing it.
Otherwise, when seeing every element drawn at the time of calling of the drawing-function, this would cause flickering graphics.
|
Is this really the case? That we "need to call gfx.update or otherwise, [the] drawn-stuff will not be shown".
I am experimenting with Lua scripts, and everything seems to work fine whether I call gfx.update() on each defer or not. In fact, your own demo code here https://forum.cockos.com/showpost.ph...12&postcount=7 does not have any gfx.update() in sight, yet it works flawlessly.
There is probably something that I'm missing, but I cannot see what...
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
|
|
|
01-03-2020, 09:05 AM
|
#5
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
It may depend on how you're handling the UI. My GUI blits the entire window when it updates itself, so removing gfx.update doesn't appear to affect anything.
|
|
|
01-03-2020, 09:07 AM
|
#6
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by Fabian
There is probably something that I'm missing, but I cannot see what...
|
What operating system are you on? (Mac Os might be doing automatic window updates.) Are you using gfx.blit?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
01-03-2020, 09:10 AM
|
#7
|
Human being with feelings
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,619
|
My understanding is that gfx.update() doesn't actually draw anything, but refreshes the various gfx variables based on current window position, mouse position, dock state, etc.
I think these get updated implicitly anyway, but update() forces it to be current at the time of invocation. I agree this isn't very clear from the documentation.
|
|
|
01-03-2020, 09:14 AM
|
#8
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
For what it's worth, on Linux this code erases the previous content correctly:
Code:
gfx.init()
local str = "Hello!"
local str_w, str_h = gfx.measurestr(str)
local function Main()
local char = gfx.getchar()
if char == -1 or char == 27 then
gfx.quit()
return
end
gfx.x = math.random() * (gfx.w - str_w)
gfx.y = math.random() * (gfx.h - str_h)
gfx.drawstr(str)
reaper.defer(Main)
end
Main()
|
|
|
01-03-2020, 09:15 AM
|
#9
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Quote:
I think these get updated implicitly anyway, but update() forces it to be current at the time of invocation. I agree this isn't very clear from the documentation.
|
How would they ever not be up to date if Reaper is updating them implicitly?
|
|
|
01-03-2020, 09:17 AM
|
#10
|
Human being with feelings
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,619
|
Quote:
Originally Posted by Lokasenna
How would they ever not be up to date if Reaper is updating them implicitly?
|
For example if you call some API that moves the window, gfx.{x,y} would be stale until gfx.update() is called (or until the next defer cycle).
That's my hypothesis anyway.
|
|
|
01-03-2020, 10:19 AM
|
#11
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Recently I'm writing a script with. And I found that when there is gfx.update() in my code, the function gfx.getdropfile doesn't work anymore. And it works again after deleting gfx.update(). That is weird.
|
|
|
01-03-2020, 10:27 AM
|
#12
|
Human being with feelings
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,619
|
Quote:
Originally Posted by dsyrock
Recently I'm writing a script with. And I found that when there is gfx.update() in my code, the function gfx.getdropfile doesn't work anymore. And it works again after deleting gfx.update(). That is weird.
|
gfx.update() does seem to clear the dropfile list. So you need to call gfx.getdropfile() before gfx.update() in your defer handler.
|
|
|
01-03-2020, 11:12 AM
|
#13
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by tack
My understanding is that gfx.update() doesn't actually draw anything, but refreshes the various gfx variables based on current window position, mouse position, dock state, etc.
I think these get updated implicitly anyway, but update() forces it to be current at the time of invocation. I agree this isn't very clear from the documentation.
|
I'm quite sure that a few months (years?) ago, gfx.mouse_x and gfx.mouse_y didn't update without calling gfx.update().
|
|
|
01-04-2020, 06:41 AM
|
#14
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
Quote:
Originally Posted by Fabian
Is this really the case? That we "need to call gfx.update or otherwise, [the] drawn-stuff will not be shown".
I am experimenting with Lua scripts, and everything seems to work fine whether I call gfx.update() on each defer or not. In fact, your own demo code here https://forum.cockos.com/showpost.ph...12&postcount=7 does not have any gfx.update() in sight, yet it works flawlessly.
There is probably something that I'm missing, but I cannot see what...
|
The behavior has changed in the meantime, though I don't know how much. I think it also has something to do with the massive overhaul in gui/retina/graphics-stuff so my claim may not be 100% accurate anymore.
I personally would say, use it. As long as the devs don't deprecate the function, there are probably things where it's actually needed.
Quote:
Originally Posted by spk77
I'm quite sure that a few months (years?) ago, gfx.mouse_x and gfx.mouse_y didn't update without calling gfx.update().
|
Yes, this was changed in the meantime too, afair somewhere in the last year.
gfx.mousecap too IIRC.
Quote:
Originally Posted by tack
gfx.update() does seem to clear the dropfile list. So you need to call gfx.getdropfile() before gfx.update() in your defer handler.
|
Good to know, I will add that into my ReaScript-docs as useful information.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 10:01 PM.
|