Question Making Valid Sketchpad object in Lua?

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,013
Reaction score
2,911
Points
138
Location
Massachusetts
I am trying to draw text and rectangles on the main camera view from the cockpit using Sketchpad objects. In the Help Lua documentation there is this statement:

In the following, skp is assumed to refer to a valid Sketchpad object.

But I have not seen how to make a "valid Sketchpad object" in Lua, so I am a little lost. It seems that skp is already defined if you are working with MFD scripts, but that does not appear to be the case for cockpit views from vessel scripts.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,763
Reaction score
2,017
Points
203
Location
between the planets
But I have not seen how to make a "valid Sketchpad object" in Lua, so I am a little lost.
I can imagine... You don't create a sketchpad. You get a sketchpad from a texture surface, as a sketchpad is specifically for drawing on textures.
You can't draw directly on the main camera view (it's not a texture). What you need is a cockpit 2D panel or a texture surface in a virtual cockpit to draw stuff on. Things get quickly more complicated from there...

The Doctor once put out a great tutorial for 2D panels, though obviously not for LUA:

What of all of this is exposed to LUA I don't know. Also, even if you get the whole API, this is a whole new can of worms you're about to open up...
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,013
Reaction score
2,911
Points
138
Location
Massachusetts
I can imagine... You don't create a sketchpad. You get a sketchpad from a texture surface, as a sketchpad is specifically for drawing on textures.
You can't draw directly on the main camera view (it's not a texture). What you need is a cockpit 2D panel or a texture surface in a virtual cockpit to draw stuff on. Things get quickly more complicated from there...
Maybe I should clarify as my terminology is lacking. I'm not really interesting in making a VC or a 2D panel. I am trying to replicate the DG landing gear status indicators like this using Lua:

Screenshot at 2023-11-16 12-56-43.png

I can put text onto this display using annotations like this:

Screenshot at 2023-11-16 12-59-40.png
But I am rather looking for a more HUD-like experience like the DG example above:
What of all of this is exposed to LUA I don't know. Also, even if you get the whole API, this is a whole new can of worms you're about to open up...
It's cans of worms all the way down. I'll get my can opener...
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,013
Reaction score
2,911
Points
138
Location
Massachusetts
I wonder if I can use the annotation class to set certain characters like this?:


Can I make a string using these characters that the annotation class will recognize? That would actually be pretty neat if so as there are lots of characters available.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,763
Reaction score
2,017
Points
203
Location
between the planets
Ah, you want to draw to the HUD, then. Yeah, "main camera view" is a rather inaccurate term for that.

Orbiter provides a callback function that hooks you right into the Huds drawing loop and hands you the sketchpad to draw with (at least for VESSEL3 derived classes, which I assume this is...).

The C++ signature of the method is:
Code:
virtual bool VESSEL3::clbkDrawHud(int, const HUDPAINTSPEC*, oapi::Sketchpad*)

You override it in your class, and orbiter calls it and hands you all the stuff you need. I assume there's a similar mechanism in LUA.

Can I make a string using these characters that the annotation class will recognize?
Hmmm... Sketchpad supports truetype fonts, but as far as I know only a selection of them. I'm not sure you can load in additional ones. The font you're using would have to support these, obviously.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,013
Reaction score
2,911
Points
138
Location
Massachusetts
Ah, you want to draw to the HUD, then. Yeah, "main camera view" is a rather inaccurate term for that.

Orbiter provides a callback function that hooks you right into the Huds drawing loop and hands you the sketchpad to draw with (at least for VESSEL3 derived classes, which I assume this is...).

The C++ signature of the method is:
Code:
virtual bool VESSEL3::clbkDrawHud(int, const HUDPAINTSPEC*, oapi::Sketchpad*)

You override it in your class, and orbiter calls it and hands you all the stuff you need. I assume there's a similar mechanism in LUA.
I wish the Lua documentation was a little more finished. It may well be, but I haven't seen reference to this particular callback.

Hmmm... Sketchpad supports truetype fonts, but as far as I know only a selection of them. I'm not sure you can load in additional ones. The font you're using would have to support these, obviously.
I was talking about the annotation class, which I don't think is the same thing as Sketchpad? If Sketchpad is how the HUD is rendered and if there is a clbkDrawHud analog in Lua that would get this done.
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,502
Reaction score
630
Points
128
I looked at the code and someone's been working on sketchpad implementation on LUA and likely encountered some problems since it's not finished. I didn't find the LUA analog of clbkDrawHud. I am totally unfamiliar with LUA and can't say much about it. Does LUA support callbacks from C++ code ? Might be good idea to talk to @kuddel and see if he got time to look into it.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,763
Reaction score
2,017
Points
203
Location
between the planets
Does LUA support callbacks from C++ code ?
I would guess it at least has to support the common lifecycle callbacks as well as preStep and postStep, otherwise I wouldn't see how it's possible to implement a vessel with it at all.
However, I'd assume that there's an actual VESSEL3 C++ implementation to which the LUA code binds, so if that doesn't have the callback implemented (which would be likely if sketchpad isn't), then there's nothing to bind to...
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,013
Reaction score
2,911
Points
138
Location
Massachusetts
I would guess it at least has to support the common lifecycle callbacks as well as preStep and postStep, otherwise I wouldn't see how it's possible to implement a vessel with it at all.
However, I'd assume that there's an actual VESSEL3 C++ implementation to which the LUA code binds, so if that doesn't have the callback implemented (which would be likely if sketchpad isn't), then there's nothing to bind to...
In the Help documentation only prestep, poststep, setclasscaps, and postcreation callbacks are indicated for Lua.

Screenshot at 2023-11-17 06-15-20.png
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,763
Reaction score
2,017
Points
203
Location
between the planets
Yeah, looks like you're out of luck with this one. Unless you get sketchpad to work in LUA...
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,013
Reaction score
2,911
Points
138
Location
Massachusetts
Yeah, looks like you're out of luck with this one. Unless you get sketchpad to work in LUA...
Sketchpad can be used to render shapes and text in Script MFDs using the update callback, but there doesn't seem to be anything analogous for the HUDs.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,763
Reaction score
2,017
Points
203
Location
between the planets
Sketchpad can be used to render shapes and text in Script MFDs using the update callback, but there doesn't seem to be anything analogous for the HUDs.
Ah, from Jarmoniks post above I got the impression that sketchpad doesn't work at all in LUA. But in this case, there is hope. You'd have to go into the source code of the lua-vessel module, override the callback, and add the appropriate bindings to wherever the LUA bindings are defined (I really don't know. I know the concept of how script languages and compiled languages interact in general, but nothing about LUA specifically). Or you'd have to get somebody to do it for you...
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,990
Reaction score
468
Points
83
Hi,
as I've heard my name ;) here's what I have found so far:
1. The Lua callback functions so far (prestep, poststep, setclasscaps) are implemented by the ScriptVessel class (see Orbitersdk/samples/ScriptVessel and Config/Vessels/ScriptPB.cfg).
2. Adding similar code to call clbkDrawHud might be doable, but I don't think this would be enough as the sketchpad (C++)-Object has no Lua interface.
So even if you could have a Lua clbk_drawhud callback, you can not do anything useful there.
3. Adding that functionality (the Lua interface) is nothing I would like to do as this is a field I am a complete noob at.
4. What is needed is one (or many) developer that knows Lua, knows how to interface C++ objects to be exposed to Lua AND likes to contribute :D

Unfortunately I am not one of those developers, sorry.
 
Top