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

Return-To-The-Roots / s25client / 15361818345

31 May 2025 08:14AM UTC coverage: 50.464% (+0.2%) from 50.286%
15361818345

Pull #1536

github

web-flow
Merge 6c29935b6 into 5dd0526f9
Pull Request #1536: Add support for image cropping inside ctrlImageButton

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

25 existing lines in 9 files now uncovered.

22455 of 44497 relevant lines covered (50.46%)

35525.47 hits per line

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

85.71
/libs/s25main/controls/ctrlBaseImage.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 "ctrlBaseImage.h"
6
#include "ogl/ITexture.h"
7
#include "s25util/colors.h"
8

9
ctrlBaseImage::ctrlBaseImage(ITexture* img /*= nullptr*/) : img_(img), modulationColor_(COLOR_WHITE) {}
390✔
10

11
void ctrlBaseImage::SwapImage(ctrlBaseImage& other)
×
12
{
13
    std::swap(img_, other.img_);
×
14
}
×
15

16
Rect ctrlBaseImage::GetImageRect() const
2✔
17
{
18
    if(!img_)
2✔
19
        return Rect();
×
20
    return Rect(-img_->GetOrigin(), img_->GetSize());
2✔
21
}
22

23
void ctrlBaseImage::DrawImage(const Rect& dstArea) const
37✔
24
{
25
    DrawImage(dstArea, modulationColor_);
37✔
26
}
37✔
27

28
void ctrlBaseImage::DrawImage(const Rect& dstArea, unsigned color) const
37✔
29
{
30
    if(img_ == nullptr)
37✔
NEW
31
        return;
×
32

33
    auto dst = dstArea;
37✔
34
    auto imageSize = img_->GetSize();
37✔
35
    auto dstSize = dstArea.getSize();
37✔
36
    Rect srcArea = Rect(DrawPoint::all(0), imageSize);
37✔
37

38
    if(imageSize.x > dstSize.x)
37✔
39
    {
40
        auto halfDelta = (imageSize.x - dstSize.x) / 2;
2✔
41
        srcArea.left += halfDelta;
2✔
42
        srcArea.right -= halfDelta;
2✔
43
    } else if(imageSize.x < dstSize.x)
35✔
44
    {
45
        auto halfDelta = (dstSize.x - imageSize.x) / 2;
34✔
46
        dst.left += halfDelta;
34✔
47
        dst.right -= halfDelta;
34✔
48
    }
49

50
    if(imageSize.y > dstSize.y)
37✔
51
    {
52
        auto halfDelta = (imageSize.y - dstSize.y) / 2;
2✔
53
        srcArea.top += halfDelta;
2✔
54
        srcArea.bottom -= halfDelta;
2✔
55
    } else if(imageSize.y < dstSize.y)
35✔
56
    {
57
        auto halfDelta = (dstSize.y - imageSize.y) / 2;
34✔
58
        dst.top += halfDelta;
34✔
59
        dst.bottom -= halfDelta;
34✔
60
    }
61

62
    img_->Draw(dst, srcArea, color);
37✔
63
}
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