diff --git a/src/celengine/cmdparser.cpp b/src/celengine/cmdparser.cpp index 640e6f78f..e2daf31d9 100644 --- a/src/celengine/cmdparser.cpp +++ b/src/celengine/cmdparser.cpp @@ -764,6 +764,13 @@ Command* CommandParser::parseCommand() Color color((float) colorv.x, (float) colorv.y, (float) colorv.z); cmd = new CommandSetLabelColor(item, color); } + else if (commandName == "settextcolor") + { + Vec3d colorv(1.0f, 1.0f, 1.0f); + paramList->getVector("color", colorv); + Color color((float) colorv.x, (float) colorv.y, (float) colorv.z); + cmd = new CommandSetTextColor(color); + } else { error("Unknown command name '" + commandName + "'"); diff --git a/src/celengine/command.cpp b/src/celengine/command.cpp index 1e386af92..fbac6f0f4 100644 --- a/src/celengine/command.cpp +++ b/src/celengine/command.cpp @@ -923,6 +923,20 @@ void CommandSetLabelColor::process(ExecutionEnvironment& /* env */) } +//////////////// +// SetTextColor command + +CommandSetTextColor::CommandSetTextColor(Color _color) : + color(_color) +{ +} + +void CommandSetTextColor::process(ExecutionEnvironment& env) +{ + env.getCelestiaCore()->setTextColor(color); +} + + /////////////// // Repeat command diff --git a/src/celengine/command.h b/src/celengine/command.h index 55bda1cf8..523a929b2 100644 --- a/src/celengine/command.h +++ b/src/celengine/command.h @@ -658,6 +658,17 @@ class CommandSetLabelColor : public InstantaneousCommand }; +class CommandSetTextColor : public InstantaneousCommand +{ + public: + CommandSetTextColor(Color); + void process(ExecutionEnvironment&); + + private: + Color color; +}; + + class Execution; class RepeatCommand : public Command diff --git a/src/celestia/celestiacore.cpp b/src/celestia/celestiacore.cpp index b8e9aa8dc..68df7cb27 100644 --- a/src/celestia/celestiacore.cpp +++ b/src/celestia/celestiacore.cpp @@ -309,6 +309,7 @@ CelestiaCore::CelestiaCore() : messageVOffset(0), messageStart(0.0), messageDuration(0.0), + textColor(Color(1.0f, 1.0f, 1.0f)), typedText(""), typedTextCompletionIdx(-1), textEnterMode(KbNormal), @@ -3886,7 +3887,7 @@ void CelestiaCore::renderOverlay() float alpha = 1.0f; if (currentTime > messageStart + messageDuration - 0.5) alpha = (float) ((messageStart + messageDuration - currentTime) / 0.5); - glColor4f(1.0f, 1.0f, 1.0f, alpha); + glColor4f(textColor.red(), textColor.green(), textColor.blue(), alpha); glTranslatef((float) x, (float) y, 0.0f); overlay->beginText(); *overlay << _(messageText.c_str()); @@ -4677,6 +4678,18 @@ void CelestiaCore::setHudDetail(int newHudDetail) notifyWatchers(VerbosityLevelChanged); } + +Color CelestiaCore::getTextColor() +{ + return textColor; +} + +void CelestiaCore::setTextColor(Color newTextColor) +{ + textColor = newTextColor; +} + + astro::Date::Format CelestiaCore::getDateFormat() const { return dateFormat; diff --git a/src/celestia/celestiacore.h b/src/celestia/celestiacore.h index 865246960..122cbc5fd 100644 --- a/src/celestia/celestiacore.h +++ b/src/celestia/celestiacore.h @@ -280,6 +280,8 @@ class CelestiaCore // : public Watchable int getHudDetail(); void setHudDetail(int); + Color getTextColor(); + void setTextColor(Color); astro::Date::Format getDateFormat() const; void setDateFormat(astro::Date::Format format); int getOverlayElements() const; @@ -375,6 +377,7 @@ class CelestiaCore // : public Watchable int messageVOffset; double messageStart; double messageDuration; + Color textColor; std::string typedText; std::vector typedTextCompletion; int typedTextCompletionIdx; diff --git a/src/celestia/celx.cpp b/src/celestia/celx.cpp index 1c796ba63..93b46358a 100644 --- a/src/celestia/celx.cpp +++ b/src/celestia/celx.cpp @@ -2118,6 +2118,40 @@ static int celestia_getoverlayelements(lua_State* l) return 1; } + +static int celestia_settextcolor(lua_State* l) +{ + Celx_CheckArgs(l, 4, 4, "Three arguments expected for celestia:settextcolor()"); + CelestiaCore* appCore = this_celestia(l); + + Color color; + double red = Celx_SafeGetNumber(l, 2, WrongType, "settextcolor: color values must be numbers", 1.0); + double green = Celx_SafeGetNumber(l, 3, WrongType, "settextcolor: color values must be numbers", 1.0); + double blue = Celx_SafeGetNumber(l, 4, WrongType, "settextcolor: color values must be numbers", 1.0); + + // opacity currently not settable + double opacity = 1.0; + + color = Color((float) red, (float) green, (float) blue, (float) opacity); + appCore->setTextColor(color); + + return 0; +} + +static int celestia_gettextcolor(lua_State* l) +{ + Celx_CheckArgs(l, 1, 1, "No arguments expected for celestia:getgalaxylightgain()"); + CelestiaCore* appCore = this_celestia(l); + + Color color = appCore->getTextColor(); + lua_pushnumber(l, color.red()); + lua_pushnumber(l, color.green()); + lua_pushnumber(l, color.blue()); + + return 3; +} + + static int celestia_setlabelcolor(lua_State* l) { Celx_CheckArgs(l, 5, 5, "Four arguments expected for celestia:setlabelcolor()"); @@ -3392,6 +3426,8 @@ static void CreateCelestiaMetaTable(lua_State* l) Celx_RegisterMethod(l, "getlabelcolor", celestia_getlabelcolor); Celx_RegisterMethod(l, "setlinecolor", celestia_setlinecolor); Celx_RegisterMethod(l, "getlinecolor", celestia_getlinecolor); + Celx_RegisterMethod(l, "settextcolor", celestia_settextcolor); + Celx_RegisterMethod(l, "gettextcolor", celestia_gettextcolor); Celx_RegisterMethod(l, "getoverlayelements", celestia_getoverlayelements); Celx_RegisterMethod(l, "setoverlayelements", celestia_setoverlayelements); Celx_RegisterMethod(l, "getfaintestvisible", celestia_getfaintestvisible);