Skip to content

Commit

Permalink
change exposure adjusting
Browse files Browse the repository at this point in the history
  • Loading branch information
375gnu committed Jan 26, 2025
1 parent 6843fe6 commit a0b4044
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 43 deletions.
35 changes: 19 additions & 16 deletions src/celestia/celestiacore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ float ComputeRotationCoarseness(const Simulation& sim)
return coarseness;
}

void
AdjustExposure(Simulation *sim, CelestiaCore *core, const std::locale &loc, float sign)
{
float exposure = sim->getExposure();
float delta = sign < 0.0f
? exposure < 1.0001f ? 0.1f : 1.0f
: exposure > 0.9999f ? 1.0f : 0.1f;
exposure += sign * delta;

if (std::abs(exposure - 1.0f) < 0.0001f)
exposure = 1.0f;
exposure = std::clamp(exposure, 0.1f, 15.0f);
sim->setExposure(exposure);
auto buf = fmt::format(loc, _("Exposure time: {:.2f}"), exposure);
core->flash(buf);
}

} // anonymous namespace

CelestiaCore::CelestiaCore() :
Expand Down Expand Up @@ -1467,19 +1484,11 @@ void CelestiaCore::charEntered(const char *c_p, int modifiers)
break;

case '[':
{
setExposure(sim->getExposure() * 0.5);
auto buf = fmt::format(loc, _("Exposure time: {:.2f}"), sim->getExposure());
flash(buf);
}
AdjustExposure(sim, this, loc, -1.0f);
break;

case ']':
{
setExposure(sim->getExposure() * 2.0);
auto buf = fmt::format(loc, _("Exposure time: {:.2f}"), sim->getExposure());
flash(buf);
}
AdjustExposure(sim, this, loc, +1.0f);
break;

case '\\':
Expand Down Expand Up @@ -2562,12 +2571,6 @@ bool CelestiaCore::initRenderer([[maybe_unused]] bool useMesaPackInvert)
return true;
}

/// Set the exposure; adjust the renderer's brightness parameters appropriately.
void CelestiaCore::setExposure(float _exposure)
{
sim->setExposure(_exposure);
}

void CelestiaCore::fatalError(const string& msg, bool visual)
{
if (alerter == nullptr)
Expand Down
2 changes: 0 additions & 2 deletions src/celestia/celestiacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ class CelestiaCore // : public Watchable<CelestiaCore>
void addWatcher(CelestiaWatcher*);
void removeWatcher(CelestiaWatcher*);

void setExposure(float);

std::vector<Observer*> getObservers() const;
celestia::View* getViewByObserver(const Observer*) const;
void splitView(celestia::View::Type type, celestia::View* av = nullptr, float splitPos = 0.5f);
Expand Down
26 changes: 2 additions & 24 deletions src/celestia/qt/qtcelestiaactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,30 +366,8 @@ CelestiaActions::slotSetTextureResolution()
void
CelestiaActions::slotAdjustExposure()
{
QAction* act = qobject_cast<QAction*>(sender());
if (act != nullptr)
{
// HACK!HACK!HACK!
// Consider removal relevant entries from menus.
// If search console is open then pass keys to it.
if (appCore->getTextEnterMode() != celestia::Hud::TextEnterMode::Normal)
{
appCore->charEntered(act->shortcut().toString().toUtf8().data());
return;
}

Renderer* renderer = appCore->getRenderer();
float change = (float) act->data().toDouble();

QString notification;

float newExposure = qBound(0.0f, appCore->getSimulation()->getExposure() * change, 1000.0f);
appCore->setExposure(newExposure);

notification = QString(_("Exposure time: %L1")).arg(newExposure, 0, 'f', 2);

appCore->flash(notification.toUtf8().data());
}
if (auto* act = qobject_cast<QAction*>(sender()); act != nullptr)
appCore->charEntered(act->shortcut().toString().toUtf8().data());
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/celscript/lua/celx_celestia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ static int celestia_setexposure(lua_State* l)

CelestiaCore* appCore = this_celestia(l);
float exposure = (float)Celx_SafeGetNumber(l, 2, AllErrors, "Argument to celestia:setexposure() must be a number");
appCore->setExposure(exposure);
appCore->getSimulation()->setExposure(exposure);

return 0;
}
Expand Down

0 comments on commit a0b4044

Please sign in to comment.