forked from CelestiaProject/Celestia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlayimage.cpp
More file actions
67 lines (56 loc) · 2.14 KB
/
overlayimage.cpp
File metadata and controls
67 lines (56 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <algorithm>
#include <iostream>
#include <celmath/mathlib.h>
#include "overlayimage.h"
#include "rectangle.h"
#include "render.h"
using namespace celmath;
OverlayImage::OverlayImage(fs::path f, Renderer *r) :
filename(std::move(f)),
renderer(r)
{
texture = std::unique_ptr<Texture>(LoadTextureFromFile(fs::path("images") / filename,
Texture::EdgeClamp,
Texture::NoMipMaps));
}
void OverlayImage::setColor(const Color& c)
{
colors.fill(c);
}
void OverlayImage::setColor(std::array<Color, 4>& c)
{
std::copy(c.begin(), c.end(), colors.begin());
}
void OverlayImage::render(float curr_time, int width, int height)
{
if (renderer == nullptr || texture == nullptr || (curr_time >= start + duration))
return;
float xSize = texture->getWidth();
float ySize = texture->getHeight();
// center overlay image horizontally if offsetX = 0
float left = (width * (1 + offsetX) - xSize)/2;
// center overlay image vertically if offsetY = 0
float bottom = (height * (1 + offsetY) - ySize)/2;
if (fitscreen)
{
float coeffx = xSize / width; // overlay pict width/view window width ratio
float coeffy = ySize / height; // overlay pict height/view window height ratio
xSize /= coeffx; // new overlay picture width size to fit viewport
ySize /= coeffy; // new overlay picture height to fit viewport
left = (width - xSize) / 2; // to be sure overlay pict is centered in viewport
bottom = 0; // overlay pict locked at bottom of screen
}
float alpha = 1.0f;
if (curr_time > start + fadeafter)
{
alpha = clamp(start + duration - curr_time);
}
celestia::Rect r(left, bottom, xSize, ySize);
r.tex = texture.get();
for (size_t i = 0; i < colors.size(); i++)
{
r.colors[i] = Color(colors[i], colors[i].alpha() * alpha);
}
r.nColors = 4;
renderer->drawRectangle(r, ShaderProperties::FisheyeOverrideModeDisabled, renderer->getOrthoProjectionMatrix());
}