Celestia

Форк
0
/
overlay.cpp 
132 строки · 2.8 Кб
1
// overlay.cpp
2
//
3
// Copyright (C) 2001-present, the Celestia Development Team
4
// Original version by Chris Laurel <claurel@shatters.net>
5
//
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.
10

11
#include <cstring>
12
#include <Eigen/Core>
13
#include <celmath/geomutil.h>
14
#include <celutil/color.h>
15
#include "overlay.h"
16
#include "rectangle.h"
17
#include "render.h"
18
#include "textlayout.h"
19

20
using namespace std;
21
using namespace Eigen;
22
using namespace celestia::engine;
23
namespace math = celestia::math;
24

25
Overlay::Overlay(Renderer& r) :
26
    layout(make_unique<TextLayout>(r.getScreenDpi())),
27
    renderer(r)
28
{
29
}
30

31
void Overlay::begin()
32
{
33
    layout->setLayoutDirectionFollowTextAlignment(true);
34
    layout->setScreenDpi(renderer.getScreenDpi());
35

36
    projection = math::Ortho2D(0.0f, (float)windowWidth, 0.0f, (float)windowHeight);
37
    // ModelView is Identity
38

39
    Renderer::PipelineState ps;
40
    ps.blending = true;
41
    ps.blendFunc = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA};
42
    ps.depthMask = true;
43
    renderer.setPipelineState(ps);
44
}
45

46
void Overlay::end()
47
{
48
}
49

50

51
void Overlay::setWindowSize(int w, int h)
52
{
53
    windowWidth = w;
54
    windowHeight = h;
55
}
56

57
void Overlay::setFont(const std::shared_ptr<TextureFont>& f)
58
{
59
    layout->setFont(f);
60
}
61

62
void Overlay::setTextAlignment(TextLayout::HorizontalAlignment halign)
63
{
64
    layout->setHorizontalAlignment(halign);
65
}
66

67
void Overlay::beginText()
68
{
69
    savePos();
70
    layout->begin(projection);
71
}
72

73
void Overlay::endText()
74
{
75
    layout->end();
76
    restorePos();
77
}
78

79
void Overlay::print(std::string_view s)
80
{
81
    layout->render(s);
82
}
83

84
void Overlay::drawRectangle(const celestia::Rect& r) const
85
{
86
    renderer.drawRectangle(r, FisheyeOverrideMode::Disabled, projection);
87
}
88

89
void Overlay::setColor(float r, float g, float b, float a)
90
{
91
    layout->flush();
92
    glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex, r, g, b, a);
93
}
94

95
void Overlay::setColor(const Color& c)
96
{
97
    layout->flush();
98
    glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex,
99
                     c.red(), c.green(), c.blue(), c.alpha());
100
}
101

102
void Overlay::setColor(const Color& c, float a)
103
{
104
    layout->flush();
105
    glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex,
106
                     c.red(), c.green(), c.blue(), a);
107
}
108

109
void Overlay::moveBy(float dx, float dy)
110
{
111
    layout->moveRelative(dx, dy);
112
}
113

114
void Overlay::moveBy(int dx, int dy)
115
{
116
    layout->moveRelative(static_cast<float>(dx), static_cast<float>(dy));
117
}
118

119
void Overlay::savePos()
120
{
121
    posStack.push_back(layout->getCurrentPosition());
122
}
123

124
void Overlay::restorePos()
125
{
126
    if (!posStack.empty())
127
    {
128
        auto [x, y] = posStack.back();
129
        layout->moveAbsolute(x, y);
130
        posStack.pop_back();
131
    }
132
}
133

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.