Rockbox Technical Forums
Support and General Use => Plugins/Viewers => Topic started by: ipodclassic on December 14, 2017, 12:04:43 AM
-
I need a small help with LUA script. Can you please tell me how can I move bitmap image loaded on screen (ipod screen in this case). Do I get a handle? I am using following function from sample:
function draw_image(img, x, y)
local x, y = (rb.LCD_WIDTH - img:width()) / 2, (rb.LCD_HEIGHT - img:height()) / 2
local func = rb.lcd_bitmap_transparent_part
or rb.lcd_bitmap_part -- Fallback version for grayscale targets
or rb.lcd_mono_bitmap_part -- Fallback version for mono targets
func(img, 0, 0, img:width(), x, y, img:width(), img:height())
rb.lcd_update()
end
Thanks in advance
-
--draws a passed image to coords (x, y)
function draw_image(img, x, y)
if not img then --make sure an image was passed, otherwise bail
rb.splash(rb.HZ, "No Image!")
return nil
end
--User supplied
--local x, y = (rb.LCD_WIDTH - img:width()) / 2, (rb.LCD_HEIGHT - img:height()) / 2
local imgx = 0
local imgy = 0
local func = rb.lcd_bitmap_transparent_part
or rb.lcd_bitmap_part -- Fallback version for grayscale targets
or rb.lcd_mono_bitmap_part -- Fallback version for mono targets
rb.lcd_clear_display()
func(img, imgx, imgy, img:width(), x, y, img:width(), img:height())
end
local src_bmp = backdrop
if (src_bmp) then
local sx = 0
-- local sy = 0
local last_sx = 0
local last_sy = 0
for sy = (rb.LCD_HEIGHT / 10), rb.LCD_HEIGHT do
--NOTE 'sy' is local to only this for loop
if (sy > 10) then
sx = sx + (rb.LCD_WIDTH / rb.LCD_HEIGHT + rb.LCD_HEIGHT / rb.LCD_WIDTH)
if (sx > rb.LCD_WIDTH - src_bmp:width()) then sx = rb.LCD_WIDTH - src_bmp:width() end
end
draw_image(src_bmp, sx, sy)
if(rb.lcd_update_rect) then
rb.lcd_update_rect(last_sx, last_sy, sx + src_bmp:width(), sy + src_bmp:height())
last_sx = sx
last_sy = sy
else
rb.lcd_update()
end
end
--and back...
sx = rb.LCD_WIDTH
for sy=rb.LCD_HEIGHT, 0, -1 do
--NOTE 'sy' is local to only this for loop
if (sy > 10) then
sx = sx - (rb.LCD_WIDTH / rb.LCD_HEIGHT + rb.LCD_HEIGHT / rb.LCD_WIDTH)
if (sx < 0) then sx = 0 end
end
draw_image(src_bmp, sx, sy)
if(rb.lcd_update_rect) then
rb.lcd_update_rect(last_sx, last_sy, sx + src_bmp:width(), sy + src_bmp:height())
last_sx = sx
last_sy = sy
else
rb.lcd_update()
end
end
end
-
This should get you started. I was attempting to show you how to grab the framebuffer and move images on the screen as well but the functions (or lack thereof) exposed to ROCKlua makes it a nightmare
-
Thank you so much for your reply. I really appreciate your help. I will try this code and get back to you.
-
Sorry... one more question.... is there any way to load fix background image and move only foreground images?
The only way I could figure was to keep rebuilding the background as we move the foreground images.
-
You would still need to copy the background image back. Your best bet would probably be to copy a portion of the background image (similar to how the image gets copied in this example) to restore the part that was destroyed by the foreground image and update only that part..
I'm working on an update to the RBlua image library that should make this stuff a bit easier but It still wouldn't do sprites like you are wanting nor will I be done with it for a few weeks
-
Thanks Bilgus for all the help!
Please keep me posted with the status of RBLua image library. Let me know if I can be of any help
Thanks again