• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 15260061968

26 May 2025 06:29PM UTC coverage: 50.444% (+0.2%) from 50.286%
15260061968

Pull #1536

github

web-flow
Merge d009f07d9 into 0d2a837ba
Pull Request #1536: Add support for image cropping inside ctrlImageButton

55 of 64 new or added lines in 6 files covered. (85.94%)

4 existing lines in 4 files now uncovered.

22448 of 44501 relevant lines covered (50.44%)

34892.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/s25main/ogl/glArchivItem_Bitmap_Player.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "glArchivItem_Bitmap_Player.h"
6
#include "Loader.h"
7
#include "Point.h"
8
#include "drivers/VideoDriverWrapper.h"
9
#include "libsiedler2/PixelBufferBGRA.h"
10
#include <glad/glad.h>
11

12
namespace {
13
struct GL_RGBAColor
14
{
15
    GLbyte r, g, b, a;
16
};
17
} // namespace
18

19
Extent glArchivItem_Bitmap_Player::CalcTextureSize() const
×
20
{
21
    // We have the texture 2 times: one with non-player colors and one with them
22
    return VIDEODRIVER.calcPreferredTextureSize(Extent(GetSize().x * 2, GetSize().y));
×
23
}
24

25
void glArchivItem_Bitmap_Player::DrawFull(const Rect& destArea, unsigned color, unsigned player_color)
×
26
{
27
    Draw(destArea, Rect(Position::all(0), GetSize()), color, player_color);
×
28
}
×
29

30
void glArchivItem_Bitmap_Player::DrawFull(const DrawPoint& dst, unsigned color, unsigned player_color)
×
31
{
32
    DrawFull(Rect(dst, GetSize()), color, player_color);
×
33
}
×
34

35
void glArchivItem_Bitmap_Player::DrawFull(const Position& dstPos, unsigned color)
×
36
{
37
    DrawFull(dstPos, color, COLOR_WHITE);
×
38
}
×
39

40
void glArchivItem_Bitmap_Player::drawForPlayer(const DrawPoint& dst, unsigned playerColor)
×
41
{
42
    DrawFull(dst, COLOR_WHITE, playerColor);
×
43
}
×
44

NEW
45
void glArchivItem_Bitmap_Player::Draw(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/)
×
46
{
NEW
47
    Draw(dstArea, srcArea, color, COLOR_WHITE);
×
NEW
48
}
×
49

UNCOV
50
void glArchivItem_Bitmap_Player::Draw(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/,
×
51
                                      unsigned player_color /*= COLOR_WHITE*/)
52
{
53
    if(GetTexture() == 0)
×
54
        return;
×
55

56
    RTTR_Assert(dstArea.getSize().x > 0 && dstArea.getSize().y > 0);
×
57
    RTTR_Assert(srcArea.getSize().x > 0 && srcArea.getSize().y > 0);
×
58
    // Compatibility only!
59
    Extent srcSize = srcArea.getSize();
×
60
    if(srcSize.x == 0)
×
61
        srcSize.x = getWidth();
×
62
    if(srcSize.y == 0)
×
63
        srcSize.y = getHeight();
×
64
    srcArea.setSize(srcSize);
×
65
    Extent dstSize = dstArea.getSize();
×
66
    if(dstSize.x == 0)
×
67
        dstSize.x = srcSize.x;
×
68
    if(dstSize.y == 0)
×
69
        dstSize.y = srcSize.y;
×
70
    dstArea.setSize(dstSize);
×
71

72
    std::array<Point<GLfloat>, 8> texCoords, vertices;
×
73

74
    dstArea.move(-GetOrigin());
×
75

76
    vertices[0].x = vertices[1].x = GLfloat(dstArea.left);
×
77
    vertices[2].x = vertices[3].x = GLfloat(dstArea.right);
×
78
    vertices[0].y = vertices[3].y = GLfloat(dstArea.top);
×
79
    vertices[1].y = vertices[2].y = GLfloat(dstArea.bottom);
×
80

81
    Point<GLfloat> srcOrig = Point<GLfloat>(srcArea.getOrigin()) / GetTexSize();
×
82
    Point<GLfloat> srcEndPt = Point<GLfloat>(srcArea.getEndPt()) / GetTexSize();
×
83
    texCoords[0].x = texCoords[1].x = srcOrig.x;
×
84
    texCoords[2].x = texCoords[3].x = srcEndPt.x;
×
85
    texCoords[0].y = texCoords[3].y = srcOrig.y;
×
86
    texCoords[1].y = texCoords[2].y = srcEndPt.y;
×
87

88
    std::copy(vertices.begin(), vertices.begin() + 4, vertices.begin() + 4);
×
89
    std::copy(texCoords.begin(), texCoords.begin() + 4, texCoords.begin() + 4);
×
90

91
    texCoords[4].x += 0.5f;
×
92
    texCoords[5].x += 0.5f;
×
93
    texCoords[6].x += 0.5f;
×
94
    texCoords[7].x += 0.5f;
×
95

96
    std::array<GL_RGBAColor, 8> colors;
97
    colors[0].r = GetRed(color);
×
98
    colors[0].g = GetGreen(color);
×
99
    colors[0].b = GetBlue(color);
×
100
    colors[0].a = GetAlpha(color);
×
101
    colors[3] = colors[2] = colors[1] = colors[0];
×
102

103
    colors[4].r = GetRed(player_color);
×
104
    colors[4].g = GetGreen(player_color);
×
105
    colors[4].b = GetBlue(player_color);
×
106
    colors[4].a = GetAlpha(player_color);
×
107
    colors[7] = colors[6] = colors[5] = colors[4];
×
108

109
    glEnableClientState(GL_COLOR_ARRAY);
×
110
    glVertexPointer(2, GL_FLOAT, 0, vertices.data());
×
111
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords.data());
×
112
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors.data());
×
113
    VIDEODRIVER.BindTexture(GetTexture());
×
114
    glDrawArrays(GL_QUADS, 0, 8);
×
115
    glDisableClientState(GL_COLOR_ARRAY);
×
116
}
117

118
void glArchivItem_Bitmap_Player::FillTexture()
×
119
{
120
    // Spezialpalette (blaue Spielerfarben sind Grau) verwenden,
121
    // damit man per OpenGL einfärben kann!
122
    const libsiedler2::ArchivItem_Palette* palette = LOADER.GetPaletteN("colors");
×
123

124
    int iformat = GetInternalFormat(), dformat = GL_BGRA; // GL_BGRA_EXT;
×
125

126
    Extent texSize = GetTexSize();
×
127
    libsiedler2::PixelBufferBGRA buffer(texSize.x, texSize.y);
×
128

129
    print(buffer, palette, 128, 0, 0, 0, 0, 0, 0, false);
×
130
    print(buffer, palette, 128, texSize.x / 2u, 0, 0, 0, 0, 0, true);
×
131
    glTexImage2D(GL_TEXTURE_2D, 0, iformat, texSize.x, texSize.y, 0, dformat, GL_UNSIGNED_BYTE, buffer.getPixelPtr());
×
132
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc