3
// Copyright (C) 2001-present, the Celestia Development Team
4
// Original version by Chris Laurel <claurel@shatters.net>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
13
#include <celmath/geomutil.h>
14
#include <celutil/color.h>
18
#include "textlayout.h"
22
using namespace celestia::engine;
23
namespace math = celestia::math;
25
Overlay::Overlay(Renderer& r) :
26
layout(make_unique<TextLayout>(r.getScreenDpi())),
33
layout->setLayoutDirectionFollowTextAlignment(true);
34
layout->setScreenDpi(renderer.getScreenDpi());
36
projection = math::Ortho2D(0.0f, (float)windowWidth, 0.0f, (float)windowHeight);
37
// ModelView is Identity
39
Renderer::PipelineState ps;
41
ps.blendFunc = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA};
43
renderer.setPipelineState(ps);
51
void Overlay::setWindowSize(int w, int h)
57
void Overlay::setFont(const std::shared_ptr<TextureFont>& f)
62
void Overlay::setTextAlignment(TextLayout::HorizontalAlignment halign)
64
layout->setHorizontalAlignment(halign);
67
void Overlay::beginText()
70
layout->begin(projection);
73
void Overlay::endText()
79
void Overlay::print(std::string_view s)
84
void Overlay::drawRectangle(const celestia::Rect& r) const
86
renderer.drawRectangle(r, FisheyeOverrideMode::Disabled, projection);
89
void Overlay::setColor(float r, float g, float b, float a)
92
glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex, r, g, b, a);
95
void Overlay::setColor(const Color& c)
98
glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex,
99
c.red(), c.green(), c.blue(), c.alpha());
102
void Overlay::setColor(const Color& c, float a)
105
glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex,
106
c.red(), c.green(), c.blue(), a);
109
void Overlay::moveBy(float dx, float dy)
111
layout->moveRelative(dx, dy);
114
void Overlay::moveBy(int dx, int dy)
116
layout->moveRelative(static_cast<float>(dx), static_cast<float>(dy));
119
void Overlay::savePos()
121
posStack.push_back(layout->getCurrentPosition());
124
void Overlay::restorePos()
126
if (!posStack.empty())
128
auto [x, y] = posStack.back();
129
layout->moveAbsolute(x, y);