Old 12-06-2018, 08:37 AM   #1
Dsharpmaj
Human being with feelings
 
Join Date: Oct 2018
Posts: 9
Default What exactly does gfx.update do?

And do I really need to call it?
Dsharpmaj is offline   Reply With Quote
Old 12-06-2018, 09:13 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

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.
Xenakios is offline   Reply With Quote
Old 12-07-2018, 07:33 AM   #3
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

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.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 01-03-2020, 03:16 AM   #4
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
Default

Quote:
Originally Posted by mespotine View Post
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...
Fabian is offline   Reply With Quote
Old 01-03-2020, 09:05 AM   #5
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

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.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-03-2020, 09:07 AM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by Fabian View Post

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.
Xenakios is offline   Reply With Quote
Old 01-03-2020, 09:10 AM   #7
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,619
Default

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.
tack is offline   Reply With Quote
Old 01-03-2020, 09:14 AM   #8
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

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()
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-03-2020, 09:15 AM   #9
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

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?
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-03-2020, 09:17 AM   #10
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,619
Default

Quote:
Originally Posted by Lokasenna View Post
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.
tack is offline   Reply With Quote
Old 01-03-2020, 10:19 AM   #11
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

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.
dsyrock is offline   Reply With Quote
Old 01-03-2020, 10:27 AM   #12
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,619
Default

Quote:
Originally Posted by dsyrock View Post
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.
tack is offline   Reply With Quote
Old 01-03-2020, 11:12 AM   #13
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by tack View Post
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().
spk77 is offline   Reply With Quote
Old 01-04-2020, 06:41 AM   #14
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

Quote:
Originally Posted by Fabian View Post
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 View Post
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 View Post
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.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:01 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.