Struggling with Lua Print

Started by garry23, December 03, 2016, 06:25:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

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

garry23

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

a1ex

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

@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

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

@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

@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

garry23

Daniel

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

Cheers

Garry

garry23

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

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

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

garry23

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

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

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

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


dfort

@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.

garry23

I'm getting too old  :)

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

Cheers

Garry

garry23

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

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

dfort

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.