Author Topic: Struggling with Lua Print  (Read 4027 times)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Struggling with Lua Print
« on: December 03, 2016, 06:25:59 PM »
David (anyone ;-))

I hope you can put me out of my misery.

I've spent hours trying to work out how to update/change a message using the display.print call.

For example:

Code: [Select]
display.print(previous_message, 100,100,FONT.LARGE,COLOR.TRANSPARENT, COLOR.TRANSPARENT)
display.print(current_message, 100,100,FONT.LARGE,COLOR.WHITE, COLOR.BLACK)

But I can't get it to 'erase' the old message.

The current message writes over the top of the previous one, ie the transparent erase doesn't work.

Where am I going wrong :-(

Cheers

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #1 on: December 04, 2016, 10:48:14 AM »
OK, I'm convinced there is something going wrong in the Lua module.

Here is my test code:

Code: [Select]
display.print("Test Text 1", 100,100,FONT.LARGE,COLOR.RED,COLOR.WHITE)
display.print("Test Text 2", 100,200,FONT.LARGE,COLOR.TRANSPERANT, COLOR.TRANSPERANT)

The first line prints as expected, ie red text on a white background.

The second test text prints white text on a black background.

I even tried this:

Code: [Select]
display.print("Test Text 2", 100,200,FONT.LARGE,0,0)
But I still get white text on a black background.

Hope one of the developers can throw some light on this, ie COLOR.TRANSPARENT not appearing to work with the display.print.

Cheers

Garry

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12207
  • Maintenance mode
Re: Struggling with Lua Print
« Reply #2 on: December 04, 2016, 11:20:32 AM »
COLOR.TRANSPARENT is defined as 0. For historical reasons, a (fg,bg) defined as (0,0) defaults to white on black. Should be easy to fix.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #3 on: December 04, 2016, 11:37:14 AM »
@A1ex

Thanks for confirming it was not my stupidity  ;)

I would be really grateful if this could be 'fixed' in the next available uplift, ie COLOR.TRANSPARENT does just that, ie make the print or drawing pixels transparent.

Cheers

Garry

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12207
  • Maintenance mode
Re: Struggling with Lua Print
« Reply #4 on: December 04, 2016, 11:57:35 AM »
Pushed a fix, but unfortunately I don't have the patience to play with it. Only noticed that some existing code relies on old behavior, so I've added a workaround, but other than that, it's pretty much untested.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #5 on: December 04, 2016, 01:01:07 PM »
@A1ex

Thanks. As soon as it gets accessible to me, I'll provide feedback.

Once again: thanks for the quick fix - fingers crossed  ;)

Cheers

Garry

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3685
Re: Struggling with Lua Print
« Reply #6 on: December 04, 2016, 06:00:44 PM »
@garry23

The fixes were made on the lua_fix branch so you'll need special builds. Hope I got compiled the right platforms for you:

https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-lua_fix.2016Dec04.zip
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #7 on: December 04, 2016, 08:07:06 PM »
Daniel

Thanks, I'll take look and experiment. BTW I have a 5D3  :)

Cheers

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #8 on: December 04, 2016, 08:31:59 PM »
Daniel/A1ex

Looks good  :)

I'll continue experimenting and feedback any 'strangeness'.

Once again, thanks to both of you for providing such a quick turn around.

As usual, I'll publish my script on the ML Lua page.

Cheers

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #9 on: December 04, 2016, 08:36:28 PM »
A1ex/Daniel

One strangeness is that the display.print erases the ML background grid.

Is there a way to force ML to redraw its 'background'?

Cheers

Garry

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3685
Re: Struggling with Lua Print
« Reply #10 on: December 05, 2016, 06:02:23 AM »
Looks like the grid is part of the foreground:

https://bitbucket.org/hudson/magic-lantern/commits/3781fb5997a82c230ff9faef5d9b014cc09910e8
Code: [Select]
/* to be used instead of background color, to draw only the foreground pixels */
/* currently implemented only for bfnt_draw_char (FONT_CANON and ICON_ML_*)   */
#define NO_BG_ERASE 0xFF


Maybe you can load and redraw the grid in lua?

http://davidmilligan.github.io/ml-lua/modules/display.html
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #11 on: December 05, 2016, 07:16:53 AM »
Daniel

As far as I'm concerned it's not worth it, i.e I'll live with a 'hole' in the grid.

But it is maybe something the developers wish to think about, i.e how to handle the interaction of Lua display 'layer' with other ML drawn objects that should persist after the Lua drawing is done.

Cheers

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #12 on: December 05, 2016, 08:53:57 AM »
Daniel

Just realized, that the drawing 'conflict' is with the Canon grid.

I guess there is not much we can do there, eg refresh the Canon grid, after a Lua draw update.

Cheers

Garry

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: Struggling with Lua Print
« Reply #13 on: December 05, 2016, 03:26:50 PM »
The way to think about what display drawing functions do is like everything drawing to a single simple bmp image file. There are lots of different things drawing to this single file, ML core, Lua, Canon firmware. There is no concept of "layers". So the way to restore the background would be to make a copy of the "file" before you start drawing and then restore it when you are done (not currently possible to do this in Lua). You are perhaps accustomed to modern desktop OSes that do provide complex window management and layered drawing functionality. We do not have such luxury available in ML unless we implement it ourselves, which would probably be overkill.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12207
  • Maintenance mode
Re: Struggling with Lua Print
« Reply #14 on: December 05, 2016, 03:35:12 PM »
Canon firmware has a pretty complex window system, so reverse engineering that one and refactoring all ML graphics code to use it could be useful in the long run.

Until then, there's the good old redraw (which probably should be exposed to Lua as well). Not very elegant, the screen will flicker on redraw, there may be conflicts with Canon GUI code (e.g. if ML redraws in the wrong moment, Canon code might record whatever ML has drawn and consider that a part of their GUI, to be restored on future redraws) and so on. That's why you still see GUI artifacts every now and then.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #15 on: December 08, 2016, 11:37:27 PM »
Daniel

Just noticed your complied version here: https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-lua_fix.2016Dec04.zip don't work with Dual-ISO and Bulb-ND.

:-(

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3685
Re: Struggling with Lua Print
« Reply #16 on: December 09, 2016, 12:07:22 AM »
@garry23

That is so like day old bread, just deleted it.

Try this newer build, it has dual_iso and that manual lens script. I haven't tried the Bulb ND Filter Module but it should work. It doesn't build and install by default but I can compile it if you want.
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #17 on: December 09, 2016, 12:31:54 AM »
I'm getting too old  :)

I simply can't keep up with all the good stuff  ;)

Cheers

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print
« Reply #18 on: December 09, 2016, 08:04:19 AM »
Daniel

Confirmed Dual loaded ok with that build.

As you imply, no Bulb-ND.

I hope your build, plus Bulb-ND and Lua fixes etc, turns up in the Nightlies soon  ;)

Thanks for sharing your build. My two 'go-to' scripts, Auto Landscape Bracketing and the Auto HFD, are my constant companions :-)

Cheers

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1719
Re: Struggling with Lua Print: SOLVED
« Reply #19 on: December 16, 2016, 09:18:43 AM »
UPDATE

OK worked it out by looking at the code, ie the delay has been removed, ie all you need now is:

Code: [Select]
camera.shoot(false)
 :)


Daniel or David

In this version https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-manual_lens_info.2016Dec05.5D3113.zip has the camera.shoot changed, as I've noticed strange behaviors with my scripts using:

Code: [Select]
        camera.shoot(64, false)
The lens moves!!!

Cheers

Garry

dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3685
Re: Struggling with Lua Print
« Reply #20 on: December 16, 2016, 09:57:27 PM »
In this version https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-manual_lens_info.2016Dec05.5D3113.zip has the camera.shoot changed, as I've noticed strange behaviors with my scripts using:

I think dmilligan incorporated the next round of lua_fix in that version. I only played around with the lens.lua script.
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102