@@ -133,11 +133,9 @@ void CButton::setMouseData(const SDL_MouseButtonEvent& button)
133133bool 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
0 commit comments