Page 1 of 1
Scripting: Print colored text
Posted: 28.10.2009, 19:14
by Marco Klunder
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
Re: Scripting: Print colored text
Posted: 29.10.2009, 09:12
by Vincent
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.
Re: Scripting: Print colored text
Posted: 29.10.2009, 13:38
by Vincent
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.
Re: Scripting: Print colored text
Posted: 29.10.2009, 13:44
by Cham
Vincent,
would it be possible to use different colors in the same message ? This is important to highlight some words in the same sentence.
Re: Scripting: Print colored text
Posted: 29.10.2009, 14:16
by Vincent
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.
Re: Scripting: Print colored text
Posted: 29.10.2009, 14:25
by Vincent
Here's a patch built against the SVN ver1_6_1 branch version:
http://vincent.giangiulio.perso.sfr.fr/ ... olor.patchHere's a pre-compiled Windows .exe file:
http://vincent.giangiulio.perso.sfr.fr/ ... a_test.zipAnd 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!")
Re: Scripting: Print colored text
Posted: 30.10.2009, 16:04
by Marco Klunder
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
Re: Scripting: Print colored text
Posted: 30.10.2009, 16:38
by Vincent
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.
![Smile :)](./images/smilies/icon_smile.gif)
This function returns a triple which corresponds to the red, green, blue components of the text color:
Re: Scripting: Print colored text
Posted: 01.11.2009, 18:06
by Vincent
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