supplierdeeply

On-screen drawing from lua - now possible.

  • 32 Replies
  • 5287 Views
On-screen drawing from lua - now possible.
« on: 13 / November / 2011, 18:27:04 »
Advertisements
Reading source code made me wonder if it's possible to add some on-screen drawings for lua. I've also found this request: http://chdk.setepontos.com/index.php?topic=5502.0

I gave it a try and here it is! Patch below this post contains diff from luascript.c file from changeset 1415. If this function will find acceptance it could be added to the trunk. In my opinion simple drawings might be usefull.

Ok, and now, what this patch gives us. New functions:

Code: [Select]
draw_pixel(x,y,color)
draw_line(x1,y1,x2,y2,color)
draw_rect(x1,y1,x2,y2,color,[thickness])
draw_circle(x,y,r,color)
draw_ellipse(x,y,a,b,color)

draw_clear()

get_screen_width()
get_screen_height()

Most of these functions explain themselves but some additional info:

- when you draw a rect you can specify a thickness - if no thickness is set the value of 1 will be used; if <=0 value is set the rect will be filled with specified color

- thickness (and fill) of circle and ellipse is not supported (yet?)

- get_screen_width() and ...height() don't work as I expect, it would be nice if somebody look into a code and told me why it returns strange value instead of number (is it hex value? value of what?!). These two function could be usefull not only for drawings.

- draw_clear() removes all drawings from the screen

All colors are numbers in decimal.

As in cited topic reyalp said - every time the screen is updated the whole drawing wipes away. But I've observed ot occurs only while I rotate a camera or in situations like this. But then the script console also dissappears so it's the same problem.

I've been trying to use the other way that reyalp suggested in cited thread - to make some possibility to add 'widgets' to OSD from lua. But being not familiar with C I felt lost somewhere between mallocs...:D

I like to see your comments, if you like it or not.

Regards!
« Last Edit: 13 / November / 2011, 18:28:36 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: On-screen drawing from lua - now possible.
« Reply #1 on: 13 / November / 2011, 18:40:40 »
All you need now is a draw_text(x,y,font,string) to make this really useful.
Ported : A1200  SD940  G10  Powershot N  G16*

Re: On-screen drawing from lua - now possible.
« Reply #2 on: 13 / November / 2011, 18:48:30 »
I missed it! In a few days it will be completed, I guess;) And we can go from DOS-like scripts to Win3.1-like:)
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: On-screen drawing from lua - now possible.
« Reply #3 on: 13 / November / 2011, 18:50:27 »
Even better - it only works in Lua.
Ported : A1200  SD940  G10  Powershot N  G16*


Re: On-screen drawing from lua - now possible.
« Reply #4 on: 13 / November / 2011, 18:54:10 »
True, but uBasic is less powerfull, I'm not using it and even didn't look in its interpreter source code;) If anyone find it usefull to add these things to uBasic - it would be nice.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: On-screen drawing from lua - now possible.
« Reply #5 on: 13 / November / 2011, 19:01:19 »
As in cited topic reyalp said - every time the screen is updated the whole drawing wipes away. But I've observed ot occurs only while I rotate a camera or in situations like this. But then the script console also dissappears so it's the same problem.
This is fixable using the same technique philmoz used to stop the menus from dissappearing.  It was discussed and implemented here but never added to the autobuild as far as I remember.



Ported : A1200  SD940  G10  Powershot N  G16*

Re: On-screen drawing from lua - now possible.
« Reply #6 on: 13 / November / 2011, 19:09:07 »
The problem might be that these from-script drawings are not redrawed by gui_draw_osd() (that's why I asked about how the drawing work). I tried to add there a new function with mallocated array which could contain all drawings.

This function would be run every time gui_draw_osd() is run.

This way the drawings would be present on the screen even after exiting the script (why not?) and might be added or removed whenever you want. But playing with malloc was beyond my possibilities.

Other solution might bu script-based - we can make script-writer responsible to redraw the osd each from time to time (or maybe on key press or something). The guard pixel could be added and peek-ed for example each second. But that's not an elegant in script.
« Last Edit: 13 / November / 2011, 19:12:10 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: On-screen drawing from lua - now possible.
« Reply #7 on: 13 / November / 2011, 19:13:43 »
About your patch - maybe post it on [REQ] thread? I would like to see it in trunk! Very nice:D
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick


Re: On-screen drawing from lua - now possible.
« Reply #8 on: 13 / November / 2011, 19:14:44 »
About your patch - maybe post it on [REQ] thread? I would like to see it in trunk! Very nice:D
There was a reason that philmoz did not want to include it at the time.  Something about it not working in all modes if I recall correctly.

I used to add it to my builds each time I update my cameras with a new trunk build.


Ported : A1200  SD940  G10  Powershot N  G16*

Re: On-screen drawing from lua - now possible.
« Reply #9 on: 13 / November / 2011, 19:18:43 »
I'll try to use it, thanks. And add this draw_text() function. But now it's around 1:16 am here and I need to sleep... Oh! I need it! Have to malloc more time in my day-time adressess...
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics