Skip to content

Commit 89c0f88

Browse files
Address PR feedback: Position usage, signed offset, loop cleanup
1 parent 7e38250 commit 89c0f88

7 files changed

Lines changed: 162 additions & 192 deletions

File tree

CIO/CButton.cpp

Lines changed: 63 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,9 @@ void CButton::setMouseData(const SDL_MouseButtonEvent& button)
133133
bool CButton::render()
134134
{
135135
// position in the Surface 'Surf_Button'
136-
unsigned pos_x = 0;
137-
unsigned pos_y = 0;
136+
Position pos{0, 0};
138137
// width and height of the button color source picture
139-
unsigned pic_w = 0;
140-
unsigned pic_h = 0;
138+
Extent pic{0, 0};
141139
// foreground of the button --> marked or unmarked, NOT the picture
142140
int foreground;
143141

@@ -154,112 +152,107 @@ bool CButton::render()
154152

155153
// at first completly fill the background (not the fastest way, but simplier)
156154
if(size_.x <= global::bmpArray[pic_background].w)
157-
pic_w = size_.x;
155+
pic.x = size_.x;
158156
else
159-
pic_w = global::bmpArray[pic_background].w;
157+
pic.x = global::bmpArray[pic_background].w;
160158

161159
if(size_.y <= global::bmpArray[pic_background].h)
162-
pic_h = size_.y;
160+
pic.y = size_.y;
163161
else
164-
pic_h = global::bmpArray[pic_background].h;
162+
pic.y = global::bmpArray[pic_background].h;
165163

166-
while(pos_x + pic_w <= static_cast<unsigned>(Surf_Button->w))
164+
while(pos.x + pic.x <= static_cast<unsigned>(Surf_Button->w))
167165
{
168-
while(pos_y + pic_h <= static_cast<unsigned>(Surf_Button->h))
166+
while(pos.y + pic.y <= static_cast<unsigned>(Surf_Button->h))
169167
{
170-
CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface,
171-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
172-
Extent(pic_w, pic_h));
173-
pos_y += pic_h;
168+
CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos, Position(0, 0), pic);
169+
pos.y += pic.y;
174170
}
175171

176-
if(pos_y < static_cast<unsigned>(Surf_Button->h))
177-
CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface,
178-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
179-
Extent(pic_w, static_cast<unsigned>(Surf_Button->h - pos_y)));
172+
if(pos.y < Surf_Button->h)
173+
CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos, Position(0, 0),
174+
Extent(pic.x, static_cast<unsigned>(Surf_Button->h - pos.y)));
180175

181-
pos_y = 0;
182-
pos_x += pic_w;
176+
pos.y = 0;
177+
pos.x += pic.x;
183178
}
184179

185-
if(pos_x < static_cast<unsigned>(Surf_Button->w))
180+
if(pos.x < Surf_Button->w)
186181
{
187-
while(pos_y + pic_h <= static_cast<unsigned>(Surf_Button->h))
182+
while(pos.y + pic.y <= static_cast<unsigned>(Surf_Button->h))
188183
{
189-
CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface,
190-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
191-
Extent(static_cast<unsigned>(Surf_Button->w - pos_x), pic_h));
192-
pos_y += pic_h;
184+
CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos, Position(0, 0),
185+
Extent(static_cast<unsigned>(Surf_Button->w - pos.x), pic.y));
186+
pos.y += pic.y;
193187
}
194188

195-
if(pos_y < static_cast<unsigned>(Surf_Button->h))
189+
if(pos.y < Surf_Button->h)
196190
CSurface::Draw(
197-
Surf_Button, global::bmpArray[pic_background].surface,
198-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
199-
Extent(static_cast<unsigned>(Surf_Button->w - pos_x), static_cast<unsigned>(Surf_Button->h - pos_y)));
191+
Surf_Button, global::bmpArray[pic_background].surface, pos, Position(0, 0),
192+
Extent(static_cast<unsigned>(Surf_Button->w - pos.x), static_cast<unsigned>(Surf_Button->h - pos.y)));
200193
}
201194

202195
// draw partial black frame
203196
if(clicked)
204197
{
205198
// black frame is left and up
206199
// draw vertical line
207-
pos_x = 0;
200+
pos.x = 0;
208201
for(unsigned y = 0; y < size_.y; y++)
209-
CSurface::DrawPixel_RGB(Surf_Button, Position(pos_x, y), 0, 0, 0);
202+
CSurface::DrawPixel_RGB(Surf_Button, Position(pos.x, y), 0, 0, 0);
210203

211204
// draw vertical line
212-
pos_x = 1;
205+
pos.x = 1;
213206
for(unsigned y = 0; y < size_.y - 1; y++)
214-
CSurface::DrawPixel_RGB(Surf_Button, Position(pos_x, y), 0, 0, 0);
207+
CSurface::DrawPixel_RGB(Surf_Button, Position(pos.x, y), 0, 0, 0);
215208

216209
// draw horizontal line
217-
pos_y = 0;
210+
pos.y = 0;
218211
for(unsigned x = 0; x < size_.x; x++)
219-
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos_y), 0, 0, 0);
212+
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos.y), 0, 0, 0);
220213

221214
// draw horizontal line
222-
pos_y = 1;
215+
pos.y = 1;
223216
for(unsigned x = 0; x < size_.x - 1; x++)
224-
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos_y), 0, 0, 0);
217+
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos.y), 0, 0, 0);
225218
} else
226219
{
227220
// black frame is right and down
228221
// draw vertical line
229-
pos_x = size_.x - 1;
222+
pos.x = size_.x - 1;
230223
for(unsigned y = 0; y < size_.y; y++)
231-
CSurface::DrawPixel_RGB(Surf_Button, Position(pos_x, y), 0, 0, 0);
224+
CSurface::DrawPixel_RGB(Surf_Button, Position(pos.x, y), 0, 0, 0);
232225

233226
// draw vertical line
234-
pos_x = size_.x - 2;
227+
pos.x = size_.x - 2;
235228
for(unsigned y = 1; y < size_.y; y++)
236-
CSurface::DrawPixel_RGB(Surf_Button, Position(pos_x, y), 0, 0, 0);
229+
CSurface::DrawPixel_RGB(Surf_Button, Position(pos.x, y), 0, 0, 0);
237230

238231
// draw horizontal line
239-
pos_y = size_.y - 1;
232+
pos.y = size_.y - 1;
240233
for(unsigned x = 0; x < size_.x; x++)
241-
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos_y), 0, 0, 0);
234+
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos.y), 0, 0, 0);
242235

243236
// draw horizontal line
244-
pos_y = size_.y - 2;
237+
pos.y = size_.y - 2;
245238
for(unsigned x = 1; x < size_.x; x++)
246-
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos_y), 0, 0, 0);
239+
CSurface::DrawPixel_RGB(Surf_Button, Position(x, pos.y), 0, 0, 0);
247240
}
248241

249242
// draw the foreground --> at first the color (marked or unmarked) and then the picture or text
250243
if(size_.x <= global::bmpArray[pic_normal].w)
251-
pic_w = size_.x;
244+
pic.x = size_.x;
252245
else
253-
pic_w = global::bmpArray[pic_normal].w;
246+
pic.x = global::bmpArray[pic_normal].w;
254247

255248
if(size_.y <= global::bmpArray[pic_normal].h)
256-
pic_h = size_.y;
249+
pic.y = size_.y;
257250
else
258-
pic_h = global::bmpArray[pic_normal].h;
251+
pic.y = global::bmpArray[pic_normal].h;
259252

260253
// beware overdrawing the left and upper frame
261-
pos_x = 2;
262-
pos_y = 2;
254+
pos.x = 2;
255+
pos.y = 2;
263256

264257
// decide if button lights or not
265258
if(marked && !clicked)
@@ -268,40 +261,35 @@ bool CButton::render()
268261
foreground = pic_normal;
269262

270263
// '-2' follows a few times, this means: beware overdrawing the right and lower frame
271-
while(pos_x + pic_w <= static_cast<unsigned>(Surf_Button->w - 2))
264+
while(pos.x + pic.x <= static_cast<unsigned>(Surf_Button->w - 2))
272265
{
273-
while(pos_y + pic_h <= static_cast<unsigned>(Surf_Button->h - 2))
266+
while(pos.y + pic.y <= static_cast<unsigned>(Surf_Button->h - 2))
274267
{
275-
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface,
276-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
277-
Extent(pic_w, pic_h));
278-
pos_y += pic_h;
268+
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos, Position(0, 0), pic);
269+
pos.y += pic.y;
279270
}
280271

281-
if(pos_y + 2 < static_cast<unsigned>(Surf_Button->h))
282-
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface,
283-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
284-
Extent(pic_w, static_cast<unsigned>(Surf_Button->h - pos_y)));
272+
if(pos.y + 2 < Surf_Button->h)
273+
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos, Position(0, 0),
274+
Extent(pic.x, static_cast<unsigned>(Surf_Button->h - pos.y)));
285275

286-
pos_y = 2;
287-
pos_x += pic_w;
276+
pos.y = 2;
277+
pos.x += pic.x;
288278
}
289279

290-
if(pos_x + 2 < static_cast<unsigned>(Surf_Button->w))
280+
if(pos.x + 2 < Surf_Button->w)
291281
{
292-
while(pos_y + pic_h <= static_cast<unsigned>(Surf_Button->h - 2))
282+
while(pos.y + pic.y <= static_cast<unsigned>(Surf_Button->h - 2))
293283
{
294-
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface,
295-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
296-
Extent(static_cast<unsigned>(Surf_Button->w - 2 - pos_x), pic_h));
297-
pos_y += pic_h;
284+
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos, Position(0, 0),
285+
Extent(static_cast<unsigned>(Surf_Button->w - 2 - pos.x), pic.y));
286+
pos.y += pic.y;
298287
}
299288

300-
if(pos_y + 2 < static_cast<unsigned>(Surf_Button->h))
301-
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface,
302-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
303-
Extent(static_cast<unsigned>(Surf_Button->w - 2 - pos_x),
304-
static_cast<unsigned>(Surf_Button->h - 2 - pos_y)));
289+
if(pos.y + 2 < Surf_Button->h)
290+
CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos, Position(0, 0),
291+
Extent(static_cast<unsigned>(Surf_Button->w - 2 - pos.x),
292+
static_cast<unsigned>(Surf_Button->h - 2 - pos.y)));
305293
}
306294

307295
// positioning the picture or write text

CIO/CFile.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,8 @@ bool CFile::read_bob02(FILE* fp)
10061006
starts = new Uint16[bmpArray->h];
10071007

10081008
// read start addresses
1009-
for(Position pos{0, 0}; pos.y < bmpArray->h; pos.y++)
1010-
CHECK_READ(libendian::le_read_us(&starts[pos.y], fp));
1009+
for(int y = 0; y < bmpArray->h; y++)
1010+
CHECK_READ(libendian::le_read_us(&starts[y], fp));
10111011

10121012
// now we are ready to read the picture lines and fill the surface, so lets create one
10131013
if((bmpArray->surface = makePalSurface(bmpArray->w, bmpArray->h, palActual->colors)) == nullptr)
@@ -1166,8 +1166,8 @@ bool CFile::read_bob04(FILE* fp, int player_color)
11661166
starts = new Uint16[bmpArray->h];
11671167

11681168
// read start addresses
1169-
for(Position pos{0, 0}; pos.y < bmpArray->h; pos.y++)
1170-
CHECK_READ(libendian::le_read_us(&starts[pos.y], fp));
1169+
for(int y = 0; y < bmpArray->h; y++)
1170+
CHECK_READ(libendian::le_read_us(&starts[y], fp));
11711171

11721172
// now we are ready to read the picture lines and fill the surface, so lets create one
11731173
if((bmpArray->surface = makePalSurface(bmpArray->w, bmpArray->h, palActual->colors)) == nullptr)
@@ -1306,8 +1306,8 @@ bool CFile::read_bob07(FILE* fp)
13061306
starts = new Uint16[shadowArray->h];
13071307

13081308
// read start addresses
1309-
for(Position pos{0, 0}; pos.y < shadowArray->h; pos.y++)
1310-
CHECK_READ(libendian::le_read_us(&starts[pos.y], fp));
1309+
for(int y = 0; y < shadowArray->h; y++)
1310+
CHECK_READ(libendian::le_read_us(&starts[y], fp));
13111311

13121312
// now we are ready to read the picture lines and fill the surface, so lets create one
13131313
if((shadowArray->surface = makePalSurface(shadowArray->w, shadowArray->h, palActual->colors)) == nullptr)

CIO/CPicture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#pragma once
77

8+
#include "Point.h"
89
#include "SdlSurface.h"
9-
#include "defines.h"
1010

1111
class CPicture
1212
{

CIO/CSelectBox.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,10 @@ void CSelectBox::setMouseData(SDL_MouseButtonEvent button)
205205

206206
bool CSelectBox::render()
207207
{
208-
// position in the Surface 'Surf_Button'
209-
unsigned pos_x = 0;
210-
unsigned pos_y = 0;
208+
// position in the Surface 'Surf_SelectBox'
209+
Position pos{0, 0};
211210
// width and height of the button color source picture
212-
unsigned pic_w = 0;
213-
unsigned pic_h = 0;
211+
Extent pic{0, 0};
214212

215213
// if we don't need to render, all is up to date, return true
216214
if(!needRender)
@@ -231,46 +229,44 @@ bool CSelectBox::render()
231229

232230
// at first completly fill the background (not the fastest way, but simplier)
233231
if(size_.x <= global::bmpArray[pic].w)
234-
pic_w = size_.x;
232+
pic.x = size_.x;
235233
else
236-
pic_w = global::bmpArray[pic].w;
234+
pic.x = global::bmpArray[pic].w;
237235

238236
if(size_.y <= global::bmpArray[pic].h)
239-
pic_h = size_.y;
237+
pic.y = size_.y;
240238
else
241-
pic_h = global::bmpArray[pic].h;
239+
pic.y = global::bmpArray[pic].h;
242240

243-
while(pos_x + pic_w <= static_cast<unsigned>(Surf_SelectBox->w))
241+
while(pos.x + pic.x <= static_cast<unsigned>(Surf_SelectBox->w))
244242
{
245-
while(pos_y + pic_h <= static_cast<unsigned>(Surf_SelectBox->h))
243+
while(pos.y + pic.y <= static_cast<unsigned>(Surf_SelectBox->h))
246244
{
247-
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface,
248-
Position(static_cast<int>(pos_x), static_cast<int>(pos_y)), Extent(0, 0),
249-
Extent(pic_w, pic_h));
250-
pos_y += pic_h;
245+
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos, Position(0, 0), pic);
246+
pos.y += pic.y;
251247
}
252248

253-
if(pos_y < static_cast<unsigned>(Surf_SelectBox->h))
254-
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, static_cast<int>(pos_x),
255-
static_cast<int>(pos_y), 0, 0, pic_w, static_cast<unsigned>(Surf_SelectBox->h - pos_y));
249+
if(pos.y < Surf_SelectBox->h)
250+
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos.x, pos.y, 0, 0, pic.x,
251+
static_cast<unsigned>(Surf_SelectBox->h - pos.y));
256252

257-
pos_y = 0;
258-
pos_x += pic_w;
253+
pos.y = 0;
254+
pos.x += pic.x;
259255
}
260256

261-
if(pos_x < static_cast<unsigned>(Surf_SelectBox->w))
257+
if(pos.x < Surf_SelectBox->w)
262258
{
263-
while(pos_y + pic_h <= static_cast<unsigned>(Surf_SelectBox->h))
259+
while(pos.y + pic.y <= static_cast<unsigned>(Surf_SelectBox->h))
264260
{
265-
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, static_cast<int>(pos_x),
266-
static_cast<int>(pos_y), 0, 0, static_cast<unsigned>(Surf_SelectBox->w - pos_x), pic_h);
267-
pos_y += pic_h;
261+
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos.x, pos.y, 0, 0,
262+
static_cast<unsigned>(Surf_SelectBox->w - pos.x), pic.y);
263+
pos.y += pic.y;
268264
}
269265

270-
if(pos_y < static_cast<unsigned>(Surf_SelectBox->h))
271-
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, static_cast<int>(pos_x),
272-
static_cast<int>(pos_y), 0, 0, static_cast<unsigned>(Surf_SelectBox->w - pos_x),
273-
static_cast<unsigned>(Surf_SelectBox->h - pos_y));
266+
if(pos.y < Surf_SelectBox->h)
267+
CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos.x, pos.y, 0, 0,
268+
static_cast<unsigned>(Surf_SelectBox->w - pos.x),
269+
static_cast<unsigned>(Surf_SelectBox->h - pos.y));
274270
}
275271
} else
276272
SDL_FillRect(Surf_SelectBox.get(), nullptr, SDL_MapRGB(Surf_SelectBox->format, 0, 0, 0));

0 commit comments

Comments
 (0)