Old 12-09-2018, 07:33 PM   #1
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default How do you add an image to a GUI?

I have tried and searched and done things that I can't say in public to figure out how to add a simple .png as a logo to a Lokasenna generated script, and I just can't figure this stuff out. There's gfx, buffers, and dare I say, blitting (oh, my!) that I don't understand how they all work together in the GUI environment. I totally got lost looking through this thread.

What super powers must one possess in order to put a .png image at x=5, y=5, w=150, h=120 on a Lokasenna GUI? And where in the script must it be placed?
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-09-2018, 07:51 PM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Is it a script, that uses his Gui-Lib?

If yes, theres an image-class, that you can use.

More on his GUI-lib at:
https://forum.cockos.com/showthread.php?t=177772
__________________
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 12-09-2018, 08:00 PM   #3
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by mespotine View Post
Is it a script, that uses his Gui-Lib?

If yes, theres an image-class, that you can use.

More on his GUI-lib at:
https://forum.cockos.com/showthread.php?t=177772
I've gone over that page a few times too. Where's this image class?

And yes, it's using his GUI-Lib.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."

Last edited by tXShooter; 12-09-2018 at 08:05 PM.
tXShooter is offline   Reply With Quote
Old 12-09-2018, 08:26 PM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Hmm...for some reasons I can't find it. I know only an old version, so maybe it's not there anymore.

But you can try:

Code:
gfx.loadimg(100,"picturefilename.png") -- load imagefile into framebuffer 100
gfx.x=5 -- set x-position to 5
gfx.y=5 -- set y-position to 5
gfx.blit(100,1,0) -- blit at x and y position in original size and unrotated
gfx.update()
which should blit the image in the framebuffer 100(as set by the loadimg-function).
You can use the longer version of gfx.blit, with which you can also set, which part of the framebuffer 100 you want to blit(src-named-parameters), as well as the exact position, at which to blit the framebuffer 100(dst-named parameters).

I don't know, where to include it, probably after GUI.Init() and before GUI.update()-functions
(I hope, these functions still exist in the current version...)
__________________
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 12-09-2018, 08:56 PM   #5
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by mespotine View Post
Hmm...for some reasons I can't find it. I know only an old version, so maybe it's not there anymore.

But you can try:

Code:
gfx.loadimg(100,"picturefilename.png") -- load imagefile into framebuffer 100
gfx.x=5 -- set x-position to 5
gfx.y=5 -- set y-position to 5
gfx.blit(100,1,0) -- blit at x and y position in original size and unrotated
gfx.update()
which should blit the image in the framebuffer 100(as set by the loadimg-function).
You can use the longer version of gfx.blit, with which you can also set, which part of the framebuffer 100 you want to blit(src-named-parameters), as well as the exact position, at which to blit the framebuffer 100(dst-named parameters).

I don't know, where to include it, probably after GUI.Init() and before GUI.update()-functions
(I hope, these functions still exist in the current version...)
I had tried essentially just that, except that I tried it in buffers 0 and 1 instead of 100. I tried it in the Init(), in the Main(), and in the beginning, and in the end, and in the... hmm... I think that I even tried it with green eggs and ham.

I'm obviously missing something elemental.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-09-2018, 09:44 PM   #6
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Have you tried it in a new script? Just to see, whether it works in the first place..
__________________
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 12-10-2018, 06:59 AM   #7
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Oh...and my most common mistake: Have you checked the path to the filenam, whether it's valid? gfx.loadimg doesn't throw an error, when loading a file was successful, only in retval with a value of -1.

This is my most common error I do, when working with images and wonder, why nothing is displayed at all with blitting.
__________________
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 12-11-2018, 05:09 PM   #8
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by mespotine View Post
Oh...and my most common mistake: Have you checked the path to the filenam, whether it's valid? gfx.loadimg doesn't throw an error, when loading a file was successful, only in retval with a value of -1.
I've tinkered with this some more and still can't get it. I have tried different conventions on the paths (\ vs /), and have verified the path is correct. I'm just not getting it.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-19-2018, 07:12 PM   #9
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Still can't get it.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-20-2018, 01:17 AM   #10
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by tXShooter View Post
Still can't get it.
Can you post the code where you're doing it?
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 12-20-2018, 06:36 AM   #11
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by lb0 View Post
Can you post the code where you're doing it?
Code:
-- Script generated by Lokasenna's GUI Builder


local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not lib_path or lib_path == "" then
    reaper.MB("Couldn't load the Lokasenna_GUI library. Please run 'Set Lokasenna_GUI v2 library path.lua' in the Lokasenna_GUI folder.", "Whoops!", 0)
    return
end
loadfile(lib_path .. "Core.lua")()

GUI.req("Classes/Class - Textbox.lua")()
GUI.req("Classes/Class - Button.lua")()
GUI.req("Classes/Class - Label.lua")()
GUI.req("Classes/Class - Options.lua")()
-- If any of the requested libraries weren't found, abort the script.
if missing_lib then return 0 end


GUI.name = "Reaper DAW Interface"
GUI.x, GUI.y, GUI.w, GUI.h = 245, 420, 1100, 250
GUI.anchor, GUI.corner = "mouse", "C"


local function Init()
	reaper.Main_OnCommand(40262) -- Enable Auto-View-Scroll while Recording
	reaper.Main_OnCommand(41172) -- Dock/undock currently focused window
	local f=io.open("C:/ProgramData/Reaper/RDI.rdi","r")
	if f~=nil then
		io.close(f)
		os.remove("C:/ProgramData/Reaper/RDI.rdi")
	end
	local f=io.open("C:/ProgramData/Reaper/GSN.rdi","r")
	if f~=nil then
		io.close(f)
		os.remove("C:/ProgramData/Reaper/GSN.rdi")
	end
	local f=io.open("c:/ProgramData/Reaper/RDIParseToDatabase.rdi","r")
	if f ~= nil then
		feDB:close(f)
		os.remove("c:/ProgramData/Reaper/RDIParseToDatabase.rdi")
	end
	gfx.loadimg(100,"C:/OneDriveTemp/OneDrive/Media Ministry/Logo.png") -- load imagefile into framebuffer 100
	gfx.x=5 -- set x-position to 5
	gfx.y=5 -- set y-position to 5
	gfx.blit(100,1,0) -- blit at x and y position in original size and unrotated
	gfx.update()
end

GUI.Init()
GUI.func = Main
GUI.freq = 0
GUI.Main()
That's some of it. I didn't include the declarations, elements, or functions.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-20-2018, 08:48 AM   #12
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Code:
 gfx.init(100,100,100)
 buffer_id = 0 -- top layer
 gfx.setimgdim(buffer_id,gfx.w, gfx.h)
  gfx.loadimg(buffer_id,[[C:\\OneDriveTemp\\OneDrive\\Media Ministry\\Logo.png]] ) -- load imagefile into framebuffer 100
gfx.blit(buffer_id,1,0)
  gfx.update()
I can't even get that simple script (attached) to run in the ReaScript Development Editor. I got some of that code from here. I am definitely missing some information.

(Which, btw, HOW THE HECK DO YOU CHANGE THE BACKGROUND IN THE EDITOR TO ANYTHING OTHER THAN BLACK?? That hurts my eyes!)
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."

Last edited by tXShooter; 12-25-2018 at 06:39 PM.
tXShooter is offline   Reply With Quote
Old 12-20-2018, 08:53 AM   #13
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

You can set the IDE-colors in the Theme Editor. There's a section for the IDE, at the bottom AFAIK.


gfx.loadimg also returns a value, that is either the BufferID(0 in your case) or -1(in case of an error). You should check that, because maybe that loading fails already.
And you don't need to do gfx.setimgdim of a buffer, in which you want to put an image, as it will be resized automatically to the size of the loaded image-file.

Oh, how big is the Logo.png in pixels? Framebuffers in the gfx-window support only sizes up to 2048x2048 pixels. Maybe its too big? Don't know, if Reaper would crop the image accordingly...

And you should set the variables gfx.x and gfx.y to the position at which you want to blit the picture.
Alternatively, you can use the longer gfx.blit-version, in which you can include the x and y-position as well, but it's harder to use.


And somehow, I stumble over [[C:\\OneDriveTemp\\OneDrive\\Media Ministry\\Logo.png]]. Maybe it's just me, but I would only write "C:\\OneDriveTemp\\OneDrive\\Media Ministry\\Logo.png", though the former should work as well...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...

Last edited by Meo-Ada Mespotine; 12-20-2018 at 09:03 AM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 12-20-2018, 01:55 PM   #14
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by mespotine View Post
You can set the IDE-colors in the Theme Editor. There's a section for the IDE, at the bottom AFAIK.
THANK YOU!! OMG, that was so harsh on these old eyes.

Quote:
Originally Posted by mespotine View Post
gfx.loadimg also returns a value, that is either the BufferID(0 in your case) or -1(in case of an error). You should check that, because maybe that loading fails already.
I tested this with a 'showmessagebox' in the IDE and it's returning a 0.

Quote:
Originally Posted by mespotine View Post
And you don't need to do gfx.setimgdim of a buffer, in which you want to put an image, as it will be resized automatically to the size of the loaded image-file.
Good to know. Thank you.

Quote:
Originally Posted by mespotine View Post
Oh, how big is the Logo.png in pixels? Framebuffers in the gfx-window support only sizes up to 2048x2048 pixels. Maybe its too big? Don't know, if Reaper would crop the image accordingly...

And you should set the variables gfx.x and gfx.y to the position at which you want to blit the picture.
Alternatively, you can use the longer gfx.blit-version, in which you can include the x and y-position as well, but it's harder to use.
This clued me into the problem as far as the testing in the IDE... the image was far larger than the gfx.x / gfx.y of the window. I resized the image with GIMP and reset the window size appropriately... now it shows fine for the IDE test.


Quote:
Originally Posted by mespotine View Post
And somehow, I stumble over [[C:\\OneDriveTemp\\OneDrive\\Media Ministry\\Logo.png]]. Maybe it's just me, but I would only write "C:\\OneDriveTemp\\OneDrive\\Media Ministry\\Logo.png", though the former should work as well...
I think that I read elsewhere in this forum that the double-bracket system is for verbatim, to include quotes... not 100% sure though. However, I just followed the example that MPL left in that other thread. (For testing purposes, my image still shows if I use a set of quotes with double-forward slashes, as well as quotes with single-reverse slashes.)

Code:
 gfx.init("Logo Image Test",192,93)
 buffer_id = 0 -- top layer
 -- gfx.setimgdim(buffer_id,gfx.w, gfx.h)
  gfx.loadimg(buffer_id,"C:/OneDriveTemp/OneDrive/Media Ministry/Logo 192x93.png" )
gfx.blit(buffer_id,1,0)
  gfx.update()
-- reaper.ShowMessageBox(buffer_id,"Logo Image Test",0)
All of the above work still hasn't gotten me any further in my original script... no image displayed.

I think the hangup is in the way that Lokesenna's GUI handles images. Like you, I think there was at one point in time an image class, but has since been dropped. I dunno. There's several things about this GUI interface that have me stumped, and without any support I'm just about to a point of dumping the entire project and going some other direction... a complete reboot for the 6th time. I can't even contemplate what it is going to take to incorporate an autocomplete textbox from an Excel database into this GUI interface, let alone 18x autocomplete textboxes.

I'm rather frustrated. If you can think of anything else to try, please don't hesitate to pass on the wisdom. I do thank you for your input.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-20-2018, 11:33 PM   #15
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Hmm...I think there are two more options. One, you add such an image-class yourself. Afaik, lokasenna did the class-concept for that purpose to make enhancing easier. But I never looked into it, so I can't help you with that(lokasenna, where ar thou?)

The other option is one, I use for the winterly snowflakes-function in my API, replacing the gfx.update()-function.

1. Copy gfx.update into a variable, like oldgfxupd=gfx.update
2. Write a new one, that blits the image and run oldgfxupd()
3. Before blitting, store the old values of gfx.x and gfx.y and restore them after blitting the image.

The function declaration is, as you are used to:
function gfx.update()

...Your blitting code here...

oldgfxupd()

end


The latter approach is more a hack that should work, but it may break with a future version of the gui-lib(though it's not likely to break).
__________________
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 12-21-2018, 02:58 AM   #16
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

It's very hard to see from your code exactly what's happening as there are bits missing - and I know nothing about Lokasenna's gui lib.

So these suggestions are probably not going to help - but anyway -

Could it be something simple like not specifying the target buffer for the blit call?

Nowhere I can see a gfx.dest = -1 which would set the target to the main gui window buffer. If any other functions set the gfx.dest to anything else - and do not return it to -1 - then you would be blitting to whatever was last set for gfx.dest.

If Lokasenna's library utilizes any separate gfx backbuffer - then you may need to be blitting to this instead of the main -1 buffer.

Also - you're not expressely setting the alpha value - gfx.a = 1 will ensure what you're blitting is opaque (although there are rarely reasons to set it to 0 - which would be the only case to make the image completely invisible).
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 12-21-2018, 07:19 AM   #17
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default No Joy with Images in LS GUI lib

I've gone back over and over and over this and have added the code below to my script before Main(). Still no background image. I just don't understand enough here to figure out what's going wrong.

Code:
GUI.images = {
	bg = "C:\\OneDriveTemp\\OneDrive\\Media Ministry\\bg.jpg",
	logo = "C:\\OneDriveTemp\\OneDrive\\Media Ministry\\Logo 192x93.png",
}
-- Load all our images into buffers
local function load_images()
	local info = debug.getinfo(1,'S')
	script_path = info.source:match[[^@?(.*[\/])[^\/]-$]]
	local idx = 0
	for key, file in pairs(GUI.images) do
		retval = gfx.loadimg(idx, script_path..file)
		GUI.images[key] = idx
		idx = idx + 1
	end
end
GUI.load_images = load_images

-- Draw the specified frame from a given image buffer
local function img(x, y, w, h, step, buffer)
	gfx.mode = 0
	local img_y = h * GUI.round(step)
	gfx.blit(buffer, 1, 0, 0, img_y, w, h, x, y, w, h)
end
GUI.img = img

GUI.img(0, 0, GUI.w, GUI.h, 0, GUI.images.bg)
-- GUI.img(5, 5, 192, 93, 0, GUI.images.logo)

local function Main()
I'm trying to use the image below as the background (bg).

__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-21-2018, 08:27 AM   #18
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by lb0 View Post
gfx.dest = -1 which would set the target to the main gui window buffer.

If Lokasenna's library utilizes any separate gfx backbuffer - then you may need to be blitting to this instead of the main -1 buffer.

Also - you're not expressely setting the alpha value - gfx.a = 1 will ensure what you're blitting is opaque (although there are rarely reasons to set it to 0 - which would be the only case to make the image completely invisible).
I tried this, but still no image...

Code:
	gfx.init("Logo Image Test",1600,400)
	buffer_id = 12 -- top layer
	gfx.x = 5
	gfx.y = 5
	gfx.w = 1600
	gfx.h = 400
	gfx.dest = -1
	-- gfx.setimgdim(buffer_id,gfx.w, gfx.h)
	gfx.loadimg(buffer_id,"C:/OneDriveTemp/OneDrive/Media Ministry/bg.jpg" ) -- load imagefile into framebuffer 100

	gfx.blit(buffer_id,1,0)
	gfx.update()
	MsgBox(buffer_id)
I did find out that while the Console Message Box is displayed (that's the MsgBox), the image DOES show, but after clicking 'OK' it is quickly covered by the gray of the script. Now I know it is working. I guess the next thing to do is to find out what 'layer' the background gray is on, and make the image one step above that.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-25-2018, 01:39 PM   #19
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

I've toyed around with it yesterday, but couldn't solve this without wasting tons of computing-ressources or changing the gui-lib too much.

I guess, the easiest way would be a Feature Request to lokasenna to implement background-images, which should be possible without problems.
__________________
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 12-25-2018, 02:07 PM   #20
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by mespotine View Post
I've toyed around with it yesterday, but couldn't solve this without wasting tons of computing-resources or changing the gui-lib too much.

I guess, the easiest way would be a Feature Request to lokasenna to implement background-images, which should be possible without problems.
So it's not just me then. Whew! Thanks for looking into it. I guess Lokasenna has gone into hibernation?

If I had a better understanding about how the GUI-Lib worked I would modify it myself, but I'm barely scratching the surface with Lua and what Reaper allows... there seems to be a large amount of limitations between the two. The bulk of my script deals with Textboxes and Buttons with a few Labels tossed in for clarity. I only wanted to add a logo for fun and color.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-25-2018, 02:14 PM   #21
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by tXShooter View Post
So it's not just me then. Whew! Thanks for looking into it. I guess Lokasenna has gone into hibernation?

If I had a better understanding about how the GUI-Lib worked I would modify it myself, but I'm barely scratching the surface with Lua and what Reaper allows... there seems to be a large amount of limitations between the two. The bulk of my script deals with Textboxes and Buttons with a few Labels tossed in for clarity. I only wanted to add a logo for fun and color.
Basically its easy to include background-images in Reaper, even with the GUI-Lib.
But at some point, the GUI-Lib is painting the grey over it, as you also saw. I have no idea why and where, couldn't even deactivate it.
__________________
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 05-06-2019, 09:03 PM   #22
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

tXShooter just pointed this thread out to me - sorry for not catching it the first time around.

My GUI library doesn't currently have any image-related functionality (the upcoming v3 will, hopefully), but images are straightforward enough that it's not too hard to add them.

The example given above has links to a version of the library (a VERY old version - like, not even worth using for anything other than that tutorial) that I had rewritten to use the provided images rather than drawing the elements.

As it happens, I reimplemented a portion of that code the other day for a script I'm working on. I've added a bunch of comments, hopefully it gets the idea across:

Code:
-- We'll be reusing a couple of methods from this
GUI.req("Classes/Class - Button.lua")()

-- We'll keep the loaded images here so we don't keep loading existing files
local images = {}

-- Loads the specified image from script_path/images/[image].png
-- If successful, returns a buffer number for retrieving it
local function loadImage(image)
  -- If we've already got this file...
  if images[image] then return images[image] end

  -- Have the GUI assign a buffer for our image to live in
  local buffer = GUI.GetBuffer()

  -- Attempt to load the given image from our ./images
  local ret = gfx.loadimg(buffer, GUI.script_path.."/images/"..image..".png")

  -- If we're good, store the buffer number and return it
  if ret > -1 then
    images[image] = buffer
    return buffer
  -- If not, release the buffer
  else
    GUI.FreeBuffer(buffer)
  end
end

-- Create a new element class
local IButton = GUI.Element:new()
GUI.IButton = IButton
IButton.__index = IButton

-- Required properties: z, w, h, image, func, params
-- w and h must be the size of one "frame" of the image
function IButton:new(name, props)
  local button = props

  button.name = name
  button.type = "IButton"

  if not button.image then error("IButton: Missing 'image' property") end

  button.state = 0

  GUI.redraw_z[button.z] = true

  return setmetatable(button, self)
end

-- Make sure we have the image specified for this button
function IButton:init()
  self.imageBuffer = loadImage(self.image)
  if not self.imageBuffer then error("IButton: The specified image was not found") end
end

-- Draw from our buffer to the current layer
-- This setup expects three button states, laid out left to right: Normal, Hover, Down
function IButton:draw()
  gfx.mode = 0
  gfx.blit(self.imageBuffer, 1, 0, self.state * self.w, 0, self.w, self.h, self.x, self.y, self.w, self.h)
end

-- Check to see if the mouse has left the button and update accordingly
function IButton:onupdate()
  if self.state > 0 and not GUI.IsInside(self, GUI.mouse.x, GUI.mouse.y) then
    self.state = 0
    self:redraw()
  end

end

-- Hover
function IButton:onmouseover()
  self.state = 1
  self:redraw()
end

-- Mouse down
function IButton:onmousedown()
  self.state = 2
  self:redraw()
end

-- These two functions aren't any different, so we can just borrow them
IButton.onmouseup = GUI.Button.onmouseup
IButton.ondoubleclick = GUI.Button.ondoubleclick
__________________
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 05-14-2019, 09:35 PM   #23
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Wow, that is incredibly helpful code!!!!

Now I am starting to feel like 'I can get there from here'....

thanks!
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 05-15-2019, 08:23 PM   #24
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Okay, I took this code and moved it to library/classes/Class - IButton.lua

And then tried calling it by editing the simple template:

Code:
-- NoIndex: true

--[[
	Lokasenna_GUI example

	- Getting user input before running an action; i.e. replacing GetUserInputs

]]--

-- The Core library must be loaded prior to anything else

local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not lib_path or lib_path == "" then
    reaper.MB("Couldn't load the Lokasenna_GUI library. Please run 'Script: Set Lokasenna_GUI v2 library path.lua' in your Action List.", "Whoops!", 0)
    return
end
loadfile(lib_path .. "Core.lua")()

GUI.req("Classes/Class - IButton.lua")()

-- If any of the requested libraries weren't found, abort the script nicely.
if missing_lib then return 0 end




------------------------------------
-------- Functions  ----------------
------------------------------------


local function btn_click()
	
	reaper.ShowMessageBox(
		"This is where we pretend to perform some sort of fancy operation with the user's settings.\n\n"
		.."Glue the processed items together afterward: "
		, "Yay!", 0)

	-- Exit the script on the next update
	--GUI.quit = true
	
end




------------------------------------
-------- Window settings -----------
------------------------------------


GUI.name = "Example - Typical script options"
GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, 400, 200
GUI.anchor, GUI.corner = "mouse", "C"




------------------------------------
-------- GUI Elements --------------
------------------------------------
-- Required properties: z, w, h, image, func, params
iProps = {
		type = "IButton",
		z = 1,
		x = 0,
		y = 0,
		w = 48,
		h = 40,
		image = "C:\\Users\\emoon\\Documents\\_REAPER\\Scripts\\LBX\\LBXCS_resources\\controls\\switchesMed.png",
		func = btn_click
		--params????
}
GUI.New("img_btn",iProps)


GUI.Init()
GUI.Main()
I get "Core.lua:747: attempt to call a nil value (method 'new')"

What am I doing wrong here?
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 05-16-2019, 06:33 AM   #25
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

When you moved the code, did you change all of the function/method names to GUI.IButton? If you left them as is, the GUI won't be able to find it.
__________________
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 05-16-2019, 07:18 AM   #26
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Hmm. Did that, but I'm still getting the same error....
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 05-16-2019, 08:13 AM   #27
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Without seeing all of the code it's hard to say, but if the GUI is giving you that error at that point it's most likely a problem loading the class file.

Feel free to PM it to me, I can have a look.
__________________
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 05-16-2019, 07:44 PM   #28
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

I'm on to a new problem... I think the constructor was choking because IButton was local. But now it's choking 2 lines later:

-- Create a new element class
GUI.IButton = GUI.Element:new()
GUI.IButton = IButton
IButton.__index = IButton --attempt to index a nil value

I really have no clue how the constructor works, so I have no idea what might be wrong here...

PS sorry about so many pm's. I really thought they weren't sending.
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 05-17-2019, 09:06 AM   #29
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Hah! I just modified Button with these methods, and it is working!!!!

I am so stoked, thanks Lokasenna!!!!
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 05-17-2019, 09:15 AM   #30
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Ironically, this brings me back to the original post....

How would I put a background image behind my controls?

Edit: Ideally, I'd like some sort of container that holds a number of controls, and itself has a background image. My controls have partially transparent images, so the background can show through. I guess the draw method of a control would need to grab the portion of the background image that is behind the control, and redraw it as well, any time the control itself is redrawn....

Can you layer two images via gfx?
__________________
eric moon
Very Stable Genius
https://gogolab.com/

Last edited by woodslanding; 05-17-2019 at 09:34 AM.
woodslanding is offline   Reply With Quote
Old 05-17-2019, 09:22 AM   #31
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

- Create another class just for displaying static images. Should be just a matter of copy + paste + rename from the IButton class I sent you.

- Remove the input methods since you don't care about them.

- Remove the state property and the multiplication in the call to gfx.blit, since you only have one image frame to show.

- Add your image element on a layer behind all of the script's elements (higher Z).
__________________
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

Last edited by Lokasenna; 05-17-2019 at 11:39 AM.
Lokasenna is offline   Reply With Quote
Old 05-17-2019, 10:28 AM   #32
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Oh yes, I forgot you had all this great built-in support for z-layering.


Cool!!
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 07-26-2022, 11:31 AM   #33
Raskal
Human being with feelings
 
Join Date: Jul 2022
Posts: 7
Default

Hi @woodslanding

I'm trying to add a logo to a gui script (Lokasenna).
I tried to follow the steps here but i wasn't able to make it work. I always end up with an error :

Core.lua:749: attempt to call a nil value (method 'new')

Would you share an exemple of how you made it work please ?

Many thanks in advance

Raskak
Raskal 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 01:11 AM.


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