Skip to content

Commit fcdd815

Browse files
Extent getBitmapSize
1 parent d39d1e9 commit fcdd815

4 files changed

Lines changed: 28 additions & 25 deletions

File tree

CIO/CWindow.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ void CWindow::setMouseData(SDL_MouseMotionEvent motion)
6363
{
6464
// cursor is on the title frame (+/-2 and +/-4 are only for a good optic)
6565
const Position titleFrameLT =
66-
pos_ + Position(global::getBitmapSize(ArchiveID::Resource, WINDOW_LEFT_UPPER_CORNER).x, 0) + Position(2, 4);
66+
pos_ + Position(static_cast<int>(global::getBitmapSize(ArchiveID::Resource, WINDOW_LEFT_UPPER_CORNER).x), 0)
67+
+ Position(2, 4);
6768
const Position titleFrameRB =
68-
pos_ + Position(static_cast<int>(size_.x), global::getBitmapSize(ArchiveID::Resource, WINDOW_UPPER_FRAME).y)
69-
- Position(global::getBitmapSize(ArchiveID::Resource, WINDOW_RIGHT_UPPER_CORNER).x + 2, 4);
69+
pos_
70+
+ Position(static_cast<int>(size_.x),
71+
static_cast<int>(global::getBitmapSize(ArchiveID::Resource, WINDOW_UPPER_FRAME).y))
72+
- Position(static_cast<int>(global::getBitmapSize(ArchiveID::Resource, WINDOW_RIGHT_UPPER_CORNER).x) + 2, 4);
7073
if(IsPointInRect(motion.x, motion.y, Rect(titleFrameLT, Extent(titleFrameRB - titleFrameLT))))
7174
{
7275
// left button was pressed while moving
@@ -91,28 +94,29 @@ void CWindow::setMouseData(SDL_MouseMotionEvent motion)
9194
{
9295
// cursor is on the button (+/-2 is only for the optic)
9396
const auto closeSize = global::getBitmapSize(ArchiveID::Resource, WINDOW_BUTTON_CLOSE);
94-
canClose_marked = IsPointInRect(Position(motion.x, motion.y),
95-
Rect(pos_ + Position(2, 2), Extent(closeSize - Extent(4, 4))));
97+
canClose_marked =
98+
IsPointInRect(Position(motion.x, motion.y), Rect(pos_ + Position(2, 2), closeSize - Extent(4, 4)));
9699
}
97100
// check whats happen to the minimize button
98101
if(canMinimize)
99102
{
100103
// cursor is on the button (+/-2 is only for the optic)
101104
const auto minSize = global::getBitmapSize(ArchiveID::Resource, WINDOW_BUTTON_MINIMIZE);
102-
canMinimize_marked = IsPointInRect(
103-
Position(motion.x, motion.y),
104-
Rect(pos_ + Position(static_cast<int>(size_.x) - minSize.x + 2, 2), Extent(minSize - Extent(4, 4))));
105+
canMinimize_marked =
106+
IsPointInRect(Position(motion.x, motion.y),
107+
Rect(pos_ + Position(static_cast<int>(size_.x) - static_cast<int>(minSize.x) + 2, 2),
108+
minSize - Extent(4, 4)));
105109
}
106110
// check whats happen to the resize button
107111
if(canResize)
108112
{
109113
// cursor is on the button (+/-2 is only for the optic)
110114
const auto resizeSize = global::getBitmapSize(ArchiveID::Resource, WINDOW_BUTTON_RESIZE);
111-
if(IsPointInRect(
112-
Position(motion.x, motion.y),
113-
Rect(pos_ + Position(static_cast<int>(size_.x) - resizeSize.x + 2,
114-
static_cast<int>(size_.y) - resizeSize.y + 2),
115-
Extent(resizeSize - Extent(4, 4)))))
115+
if(IsPointInRect(Position(motion.x, motion.y),
116+
Rect(pos_
117+
+ Position(static_cast<int>(size_.x) - static_cast<int>(resizeSize.x) + 2,
118+
static_cast<int>(size_.y) - static_cast<int>(resizeSize.y) + 2),
119+
resizeSize - Extent(4, 4))))
116120
{
117121
// left button was pressed while moving
118122
if(SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_LEFT))

CMap.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,24 +1161,24 @@ void CMap::render()
11611161
Texture::getTexture(ArchiveID::Resource, STATUE_UP_LEFT).Draw(Position(12, 12));
11621162
Texture::getTexture(ArchiveID::Resource, STATUE_UP_RIGHT)
11631163
.Draw(Position(static_cast<int>(displayRect.getSize().x)
1164-
- global::getBitmapSize(ArchiveID::Resource, STATUE_UP_RIGHT).x - 12,
1164+
- static_cast<int>(global::getBitmapSize(ArchiveID::Resource, STATUE_UP_RIGHT).x) - 12,
11651165
12));
11661166
Texture::getTexture(ArchiveID::Resource, STATUE_DOWN_LEFT)
11671167
.Draw(Position(12, static_cast<int>(displayRect.getSize().y)
1168-
- global::getBitmapSize(ArchiveID::Resource, STATUE_DOWN_LEFT).y - 12));
1168+
- static_cast<int>(global::getBitmapSize(ArchiveID::Resource, STATUE_DOWN_LEFT).y) - 12));
11691169
Texture::getTexture(ArchiveID::Resource, STATUE_DOWN_RIGHT)
11701170
.Draw(Position(static_cast<int>(displayRect.getSize().x)
1171-
- global::getBitmapSize(ArchiveID::Resource, STATUE_DOWN_RIGHT).x - 12,
1171+
- static_cast<int>(global::getBitmapSize(ArchiveID::Resource, STATUE_DOWN_RIGHT).x) - 12,
11721172
static_cast<int>(displayRect.getSize().y)
1173-
- global::getBitmapSize(ArchiveID::Resource, STATUE_DOWN_RIGHT).y - 12));
1173+
- static_cast<int>(global::getBitmapSize(ArchiveID::Resource, STATUE_DOWN_RIGHT).y) - 12));
11741174

11751175
// lower menubar
11761176
const Position menubarPos =
11771177
Position(static_cast<int>(displayRect.getSize().x) / 2, static_cast<int>(displayRect.getSize().y));
11781178
// draw lower menubar
11791179
Texture::getTexture(ArchiveID::Resource, MENUBAR)
1180-
.Draw(Position(menubarPos.x - global::getBitmapSize(ArchiveID::Resource, MENUBAR).x / 2,
1181-
menubarPos.y - global::getBitmapSize(ArchiveID::Resource, MENUBAR).y));
1180+
.Draw(Position(menubarPos.x - static_cast<int>(global::getBitmapSize(ArchiveID::Resource, MENUBAR).x) / 2,
1181+
menubarPos.y - static_cast<int>(global::getBitmapSize(ArchiveID::Resource, MENUBAR).y)));
11821182

11831183
// draw pictures to lower menubar
11841184
// backgrounds (use button background texture for each slot)

globals.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ bool global::loadPalette(const boost::filesystem::path& filepath)
9292
return true;
9393
}
9494

95-
Position global::getBitmapSize(ArchiveID archive, unsigned index)
95+
Extent global::getBitmapSize(ArchiveID archive, unsigned index)
9696
{
9797
auto& archiv = typedArchives[archive];
9898
if(index >= archiv.size())
99-
return {0, 0};
99+
return {0u, 0u};
100100
auto* bmp = dynamic_cast<const libsiedler2::baseArchivItem_Bitmap*>(archiv.get(index));
101101
if(!bmp)
102-
return {0, 0};
102+
return {0u, 0u};
103103
return {bmp->getWidth(), bmp->getHeight()};
104104
}
105105

globals.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ extern std::map<ArchiveID, libsiedler2::Archiv> typedArchives;
3535
bool loadArchive(ArchiveID archive, const boost::filesystem::path& filepath,
3636
const libsiedler2::ArchivItem_Palette* palette = nullptr);
3737

38-
/// Get the size of a bitmap from a typed archive. Archiv stores uint16_t
39-
/// which naturally promotes to int — returns Position for signed use.
40-
Position getBitmapSize(ArchiveID archive, unsigned index);
38+
/// Get the size of a bitmap from a typed archive.
39+
Extent getBitmapSize(ArchiveID archive, unsigned index);
4140

4241
/// Load a palette BBM file into currentPalette. Returns true on success.
4342
bool loadPalette(const boost::filesystem::path& filepath);

0 commit comments

Comments
 (0)