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

Return-To-The-Roots / s25client / 24625571893

19 Apr 2026 09:10AM UTC coverage: 50.212% (-0.2%) from 50.371%
24625571893

Pull #1890

github

web-flow
Merge 8ad0e7354 into 7b5704a17
Pull Request #1890: Add support for borderless Windows

167 of 637 new or added lines in 44 files covered. (26.22%)

26 existing lines in 9 files now uncovered.

23082 of 45969 relevant lines covered (50.21%)

42862.09 hits per line

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

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

5
#include "dskTextureTest.h"
6
#include "Loader.h"
7
#include "RttrConfig.h"
8
#include "WindowManager.h"
9
#include "controls/ctrlComboBox.h"
10
#include "drivers/VideoDriverWrapper.h"
11
#include "dskMainMenu.h"
12
#include "files.h"
13
#include "ingameWindows/iwMsgbox.h"
14
#include "lua/GameDataLoader.h"
15
#include "ogl/FontStyle.h"
16
#include "ogl/glArchivItem_Bitmap.h"
17
#include <glad/glad.h>
18
#include <boost/filesystem/path.hpp>
19
#include <array>
20

21
namespace {
22
enum
23
{
24
    ID_txtTitle = dskMenuBase::ID_FIRST_FREE,
25
    ID_btBack,
26
    ID_cbTexture
27
};
28
}
29

30
dskTextureTest::dskTextureTest()
×
31
{
32
    AddText(ID_txtTitle, DrawPoint(300, 20), "Test screen for textures", COLOR_ORANGE, FontStyle::CENTER, LargeFont);
×
33
    AddComboBox(ID_cbTexture, DrawPoint(630, 50), Extent(100, 22), TextureColor::Green2, NormalFont, 100);
×
34
    Load();
×
35
    AddTextButton(ID_btBack, DrawPoint(630, 565), Extent(150, 22), TextureColor::Red1, _("Back"), NormalFont);
×
36
}
×
37

38
dskTextureTest::~dskTextureTest() = default;
×
39

40
void dskTextureTest::Load()
×
41
{
42
    WorldDescription newDesc;
×
43
    GameDataLoader gdLoader(newDesc);
×
44
    if(!gdLoader.Load())
×
45
    {
46
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMsgbox>(_("Error"), "Failed to load game data!", nullptr,
×
47
                                                                 MsgboxButton::Ok, MsgboxIcon::ExclamationRed));
×
48
        return;
×
49
    }
50
    desc = newDesc;
×
51

52
    auto* cb = GetCtrl<ctrlComboBox>(ID_cbTexture);
×
53
    const unsigned selection = cb->GetSelection().value_or(0);
×
54
    cb->DeleteAllItems();
×
55
    for(const auto& t : desc.terrain)
×
NEW
56
        cb->AddItem(t.name);
×
57
    cb->SetSelection(selection);
×
58
    Msg_ComboSelectItem(ID_cbTexture, selection);
×
59
}
60

61
void dskTextureTest::Msg_ComboSelectItem(const unsigned ctrl_id, const unsigned selection)
×
62
{
63
    curTerrainIdx = desc.terrain.getIndex(GetCtrl<ctrlComboBox>(ctrl_id)->GetText(selection));
×
64
    if(!curTerrainIdx)
×
65
        return;
×
66
    const TerrainDesc& cur = desc.get(curTerrainIdx);
×
67
    LOADER.Load(RTTRCONFIG.ExpandPath(cur.texturePath));
×
68
    const auto textureName = ResourceId::make(bfs::path(cur.texturePath));
×
69
    glArchivItem_Bitmap* texBmp = LOADER.GetImageN(textureName, 0);
×
70
    curTexture = LOADER.ExtractTexture(*texBmp, cur.posInTexture);
×
71
}
72

73
void dskTextureTest::Msg_ButtonClick(const unsigned /*ctrl_id*/)
×
74
{
75
    WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>());
×
76
}
×
77

78
using PointF = Point<GLfloat>;
79
using Triangle = std::array<PointF, 3>;
80

81
void dskTextureTest::Msg_PaintAfter()
×
82
{
83
    dskMenuBase::Msg_PaintAfter();
×
84
    if(!curTexture)
×
85
        return;
×
86
    DrawRectangle(Rect(0, 50, 800, 550), COLOR_BLACK);
×
87
    VIDEODRIVER.BindTexture(curTexture->GetTexture());
×
88
    const TerrainDesc& cur = desc.get(curTerrainIdx);
×
89
    Position texOrigin = cur.posInTexture.getOrigin();
×
90
    PointF texSize(curTexture->GetTexSize());
×
91

92
    TerrainDesc::Triangle trianglePos = cur.GetRSUTriangle();
×
93
    std::array<Triangle, 2> texCoords;
×
94

95
    Triangle& rsuCoord = texCoords[0];
×
96
    rsuCoord[0] = PointF(trianglePos.tip - texOrigin);
×
97
    rsuCoord[1] = PointF(trianglePos.left - texOrigin);
×
98
    rsuCoord[2] = PointF(trianglePos.right - texOrigin);
×
99
    // Normalize to texture size
100
    for(unsigned i = 0; i < 3; i++)
×
101
        rsuCoord[i] /= texSize;
×
102

103
    Triangle& usdCoord = texCoords[1];
×
104
    trianglePos = cur.GetUSDTriangle();
×
105
    usdCoord[0] = PointF(trianglePos.left - texOrigin);
×
106
    usdCoord[1] = PointF(trianglePos.tip - texOrigin);
×
107
    usdCoord[2] = PointF(trianglePos.right - texOrigin);
×
108
    // Normalize to texture size
109
    for(unsigned i = 0; i < 3; i++)
×
110
        usdCoord[i] /= texSize;
×
111

112
    std::array<Triangle, 2> vertexCoords;
×
113
    PointF triangleSize(448, 224);
×
114
    vertexCoords[0][0] = PointF(triangleSize.x / 2 + 10, 60);
×
115
    vertexCoords[0][1] = vertexCoords[0][0] + PointF(-triangleSize.x / 2, triangleSize.y);
×
116
    vertexCoords[0][2] = vertexCoords[0][0] + PointF(triangleSize.x / 2, triangleSize.y);
×
117

118
    vertexCoords[1][0] = PointF(10, triangleSize.y + 80);
×
119
    vertexCoords[1][1] = vertexCoords[1][0] + PointF(triangleSize.x / 2, triangleSize.y);
×
120
    vertexCoords[1][2] = vertexCoords[1][0] + PointF(triangleSize.x, 0);
×
121

122
    glVertexPointer(2, GL_FLOAT, 0, &vertexCoords.front());
×
123
    glTexCoordPointer(2, GL_FLOAT, 0, &texCoords.front());
×
124
    glColor3ub(0xFF, 0xFF, 0xFF);
×
125

126
    glDrawArrays(GL_TRIANGLES, 0, 2 * 3);
×
127
}
128

129
bool dskTextureTest::Msg_KeyDown(const KeyEvent& ke)
×
130
{
131
    if(ke.kt == KeyType::F5)
×
132
    {
133
        Load();
×
134
        return true;
×
135
    }
136
    return dskMenuBase::Msg_KeyDown(ke);
×
137
}
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