Magic Lantern Forum

Developing Magic Lantern => Scripting Corner => Scripting Q&A => Topic started by: garry23 on December 03, 2016, 06:25:59 PM

Title: Struggling with Lua Print
Post by: garry23 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:

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
Title: Re: Struggling with Lua Print
Post by: garry23 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:

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:


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
Title: Re: Struggling with Lua Print
Post by: a1ex 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.
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print
Post by: a1ex 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.
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print
Post by: dfort 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
Title: Re: Struggling with Lua Print
Post by: garry23 on December 04, 2016, 08:07:06 PM
Daniel

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

Cheers

Garry
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print
Post by: dfort 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
/* 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
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print
Post by: dmilligan 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.
Title: Re: Struggling with Lua Print
Post by: a1ex 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.
Title: Re: Struggling with Lua Print
Post by: garry23 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.

:-(
Title: Re: Struggling with Lua Print
Post by: dfort on December 09, 2016, 12:07:22 AM
@garry23

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

Try this newer build (https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-manual_lens_info.2016Dec05.5D3113.zip), it has dual_iso and that manual lens script (http://www.magiclantern.fm/forum/index.php?topic=18083.msg176038#msg176038). 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.
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print
Post by: garry23 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
Title: Re: Struggling with Lua Print: SOLVED
Post by: garry23 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:

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:

        camera.shoot(64, false)

The lens moves!!!

Cheers

Garry
Title: Re: Struggling with Lua Print
Post by: dfort on December 16, 2016, 09:57:27 PM
Quote from: garry23 on December 16, 2016, 09:18:43 AM
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.