Scripting: Print colored text

The place to discuss creating, porting and modifying Celestia's source code.
Avatar
Topic author
Marco Klunder
Posts: 180
Joined: 20.02.2008
Age: 58
With us: 12 years 9 months
Location: The Netherlands

Scripting: Print colored text

Post #1by Marco Klunder » 28.10.2009, 19:14

Is it possible to develop a color parameter in the scripting celestia:print() and/or :flash() method, so it will be possible to give the printed text on the screen a specific colour?

Normally, white will be OK, when seen against the darkness of space.
There are situations however, especially when zoomed in on brigth stars or planets like Mercury, that white text cannot be read at all.
I think it will be an improvement when a script writer can give his/her text a colour at such moments.

Marco

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 15 years 10 months
Location: Nancy, France

Re: Scripting: Print colored text

Post #2by Vincent » 29.10.2009, 09:12

Marco,

This is not possible, yet.
A request to print scripting text in color has been already added to the Sourceforge tracker.
I'll take care of this ASAP.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 15 years 10 months
Location: Nancy, France

Re: Scripting: Print colored text

Post #3by Vincent » 29.10.2009, 13:38

I've been thinking about the best way to set the text color from a script...

The first option would be to add the color as the seventh argument of the celestia:print method.
This option has a disadvantage, though: script writers would have to specify all the seven arguments,
i.e., the following code would return an error: celestia:print(text, color)
One should write, instead: celestia:print(text, duration, horig, vorig, hoffset, voffset, color),
which would be both confusing and inconvenient.

A second option would be to add a new celestia:settextcolor method,
so that one could write: settextcolor(red, green, blue)
This option is both simplier and handier: the color set during a script will remain even after the
script is terminated, which gives the possibility to customize the color of the Celestia messages.
Also, it is more relevant with the syntax of the setlinecolor and setlabelcolor methods.

I should have a patch ready quite soon which uses the latter.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
Cham M
Posts: 4325
Joined: 14.01.2004
Age: 56
With us: 16 years 10 months
Location: Montreal

Re: Scripting: Print colored text

Post #4by Cham » 29.10.2009, 13:44

Vincent,

would it be possible to use different colors in the same message ? This is important to highlight some words in the same sentence.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 15 years 10 months
Location: Nancy, France

Re: Scripting: Print colored text

Post #5by Vincent » 29.10.2009, 14:16

Cham wrote:would it be possible to use different colors in the same message ? This is important to highlight some words in the same sentence.
Unfortunately, this won't be possible.
For this, you'll need to use the Lua Tools.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 15 years 10 months
Location: Nancy, France

Re: Scripting: Print colored text

Post #6by Vincent » 29.10.2009, 14:25

Here's a patch built against the SVN ver1_6_1 branch version:
http://vincent.giangiulio.perso.sfr.fr/ ... olor.patch

Here's a pre-compiled Windows .exe file:
http://vincent.giangiulio.perso.sfr.fr/ ... a_test.zip

And here's a little celx script for testing:

Code: Select all

for n = 0, 100 do
    r = math.random()
    g = math.random()
    b = math.random()
    celestia:settextcolor(r, g, b)
    celestia:print(" Welcome to Celestia!")
    wait(0.05)
end

celestia:settextcolor(1.0, 1.0, 1.0)
celestia:print(" Welcome to Celestia!")
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
Topic author
Marco Klunder
Posts: 180
Joined: 20.02.2008
Age: 58
With us: 12 years 9 months
Location: The Netherlands

Re: Scripting: Print colored text

Post #7by Marco Klunder » 30.10.2009, 16:04

He Vincent,

This was really quick and the solution works fine, as far as I look at it, GREAT work.

During testing, it became directly clear to me, that we absolutely also need a celestia:gettextcolor() method.
(probably you already programmed it ...).
During testing, I pressed the [Esc] key and after that all my text was printed in Blue...

So using the celestia:gettextcolor() and celestia:settextcolor(r,g,b) in the celestia_cleanup_callback() definitions must be possible to reset the color to white again.

Marco
Marco Klunder
email: marco.klunder@hccnet.nl
Windows7 Ultimate, PD 3.0 GHz, 2 GB of RAM, Nvidia GeForce 6700 XL
Celestia161 / SVN + Lua Edu Tools v1.2 Beta9 and Celestia160-ED

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 15 years 10 months
Location: Nancy, France

Re: Scripting: Print colored text

Post #8by Vincent » 30.10.2009, 16:38

Marco Klunder wrote:He Vincent,

This was really quick and the solution works fine, as far as I look at it, GREAT work.

During testing, it became directly clear to me, that we absolutely also need a celestia:gettextcolor() method.
(probably you already programmed it ...).
During testing, I pressed the [Esc] key and after that all my text was printed in Blue...

So using the celestia:gettextcolor() and celestia:settextcolor(r,g,b) in the celestia_cleanup_callback() definitions must be possible to reset the color to white again.

Marco
Marco,

Indeed, I've added the celestia:gettextcolor() method as well, so you can already use it. :)
This function returns a triple which corresponds to the red, green, blue components of the text color:

Code: Select all

r, g, b = celestia:gettextcolor()
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 15 years 10 months
Location: Nancy, France

Re: Scripting: Print colored text

Post #9by Vincent » 01.11.2009, 18:06

I've committed the patch to both the trunk and 1.6.1 branch.

This change adds the celestia:settextcolor and celestia:gettextcolor commands to CELX scripting.
I've updated the Celx scripting Wiki page accordingly

The patch also adds the settextcolor command to CEL scripting.
I would be a good thing to update the CEL documentation as well with all these new commands...
Example:

Code: Select all

{
# Set text color to green
settextcolor { color [0.0 1.0 0.0] }
print { origin "topleft"  row 27  column 1  duration 2 text "Welcome to Celestia!" }
wait { duration 2 }

# Set text color back to white
settextcolor { color [1.0 1.0 1.0] }
print { origin "topleft"  row 27  column 1  duration 2 text "Welcome to Celestia!" }
wait { duration 2 }
}



Here's a Windows executable for testing:
http://vincent.giangiulio.perso.sfr.fr/ ... 61_SVN.zip
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3


Return to “Development”

Who is online