Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Welcome to the Rockbox Technical Forums!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  LUA -- Moving images on the screen
« previous next »
  • Print
Pages: [1]

Author Topic: LUA -- Moving images on the screen  (Read 1702 times)

Offline ipodclassic

  • Member
  • *
  • Posts: 15
LUA -- Moving images on the screen
« 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
« Last Edit: December 15, 2017, 01:13:08 PM by Bilgus »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 537
Re: LUA -- Moving images on the screen
« Reply #1 on: December 15, 2017, 01:18:25 PM »
Code: [Select]
--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

Code: [Select]
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
« Last Edit: December 15, 2017, 01:28:33 PM by Bilgus »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 537
Re: LUA -- Moving images on the screen
« Reply #2 on: December 15, 2017, 01:24:44 PM »
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
Logged

Offline ipodclassic

  • Member
  • *
  • Posts: 15
Re: LUA -- Moving images on the screen
« Reply #3 on: December 19, 2017, 10:52:55 AM »
Thank you so much for your reply. I really appreciate your help. I will try this code and get back to you.
Logged

Offline ipodclassic

  • Member
  • *
  • Posts: 15
Re: LUA -- Moving images on the screen
« Reply #4 on: December 19, 2017, 10:59:21 AM »
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.
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 537
Re: LUA -- Moving images on the screen
« Reply #5 on: December 19, 2017, 09:13:34 PM »
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
Logged

Offline ipodclassic

  • Member
  • *
  • Posts: 15
Re: LUA -- Moving images on the screen
« Reply #6 on: December 20, 2017, 11:07:43 AM »
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
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  LUA -- Moving images on the screen
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.071 seconds with 15 queries.