@@ -25,9 +25,6 @@ Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent&
2525Window::~Window ()
2626{
2727 RTTR_Assert (!isInMouseRelay);
28- // Steuerelemente aufräumen
29- for (Window* ctrl : childIdToWnd_ | boost::adaptors::map_values)
30- delete ctrl;
3128}
3229
3330void Window::Draw ()
@@ -79,9 +76,7 @@ bool Window::RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke)
7976 if (!IsMessageRelayAllowed ())
8077 return false ;
8178
82- // Alle Controls durchgehen
83- // Falls das Fenster dann plötzlich nich mehr aktiv ist (z.b. neues Fenster geöffnet, sofort abbrechen!)
84- for (Window* wnd : childIdToWnd_ | boost::adaptors::map_values)
79+ for (auto & wnd : childIdToWnd_ | boost::adaptors::map_values)
8580 {
8681 if (wnd->visible_ && wnd->active_ && CALL_MEMBER_FN (*wnd, msg)(ke))
8782 return true ;
@@ -100,7 +95,7 @@ bool Window::RelayMouseMessage(MouseMsgHandler msg, const MouseCoords& mc)
10095 isInMouseRelay = true ;
10196
10297 // Use reverse iterator because the topmost (=last elements) should receive the messages first!
103- for (Window* wnd : childIdToWnd_ | boost::adaptors::map_values | boost::adaptors::reversed)
98+ for (auto & wnd : childIdToWnd_ | boost::adaptors::map_values | boost::adaptors::reversed)
10499 {
105100 if (!lockedAreas_.empty () && IsInLockedRegion (mc.pos , wnd.get ()))
106101 continue ;
@@ -187,38 +182,32 @@ bool Window::IsMessageRelayAllowed() const
187182
188183void Window::DeleteCtrl (unsigned id)
189184{
190- auto it = childIdToWnd_.find (id);
191-
192- if (it == childIdToWnd_.end ())
193- return ;
194-
195- delete it->second ;
196-
197- childIdToWnd_.erase (it);
185+ childIdToWnd_.erase (id);
198186}
199187
200188ctrlBuildingIcon* Window::AddBuildingIcon (unsigned id, const DrawPoint& pos, BuildingType type, const Nation nation,
201189 unsigned short size, const std::string& tooltip)
202190{
203- return AddCtrl (new ctrlBuildingIcon (this , id, ScaleIf (pos), type, nation, ScaleIf (Extent (size, 0 )).x , tooltip));
191+ return AddCtrl (
192+ std::make_unique<ctrlBuildingIcon>(this , id, ScaleIf (pos), type, nation, ScaleIf (Extent (size, 0 )).x , tooltip));
204193}
205194
206195ctrlButton* Window::AddTextButton (unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
207196 const std::string& text, const glFont* font, const std::string& tooltip)
208197{
209- return AddCtrl (new ctrlTextButton (this , id, ScaleIf (pos), ScaleIf (size), tc, text, font, tooltip));
198+ return AddCtrl (std::make_unique< ctrlTextButton> (this , id, ScaleIf (pos), ScaleIf (size), tc, text, font, tooltip));
210199}
211200
212201ctrlButton* Window::AddColorButton (unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
213202 const unsigned fillColor, const std::string& tooltip)
214203{
215- return AddCtrl (new ctrlColorButton (this , id, ScaleIf (pos), ScaleIf (size), tc, fillColor, tooltip));
204+ return AddCtrl (std::make_unique< ctrlColorButton> (this , id, ScaleIf (pos), ScaleIf (size), tc, fillColor, tooltip));
216205}
217206
218207ctrlButton* Window::AddImageButton (unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
219208 ITexture* const image, const std::string& tooltip)
220209{
221- return AddCtrl (new ctrlImageButton (this , id, ScaleIf (pos), ScaleIf (size), tc, image, tooltip));
210+ return AddCtrl (std::make_unique< ctrlImageButton> (this , id, ScaleIf (pos), ScaleIf (size), tc, image, tooltip));
222211}
223212
224213ctrlButton* Window::AddImageButton (unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
@@ -230,37 +219,39 @@ ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Exte
230219ctrlChat* Window::AddChatCtrl (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
231220 const glFont* font)
232221{
233- return AddCtrl (new ctrlChat (this , id, ScaleIf (pos), ScaleIf (size), tc, font));
222+ return AddCtrl (std::make_unique< ctrlChat> (this , id, ScaleIf (pos), ScaleIf (size), tc, font));
234223}
235224
236225ctrlCheck* Window::AddCheckBox (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
237226 const std::string& text, const glFont* font, bool readonly)
238227{
239- return AddCtrl (new ctrlCheck (this , id, ScaleIf (pos), ScaleIf (size), tc, text, font, readonly));
228+ return AddCtrl (std::make_unique< ctrlCheck> (this , id, ScaleIf (pos), ScaleIf (size), tc, text, font, readonly));
240229}
241230
242231ctrlComboBox* Window::AddComboBox (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
243232 const glFont* font, unsigned short max_list_height, bool readonly)
244233{
245- return AddCtrl (new ctrlComboBox (this , id, ScaleIf (pos), ScaleIf (size), tc, font, max_list_height, readonly));
234+ return AddCtrl (
235+ std::make_unique<ctrlComboBox>(this , id, ScaleIf (pos), ScaleIf (size), tc, font, max_list_height, readonly));
246236}
247237
248238ctrlDeepening* Window::AddTextDeepening (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
249239 const std::string& text, const glFont* font, unsigned color, FontStyle style)
250240{
251- return AddCtrl (new ctrlTextDeepening (this , id, ScaleIf (pos), ScaleIf (size), tc, text, font, color, style));
241+ return AddCtrl (
242+ std::make_unique<ctrlTextDeepening>(this , id, ScaleIf (pos), ScaleIf (size), tc, text, font, color, style));
252243}
253244
254245ctrlDeepening* Window::AddColorDeepening (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
255246 unsigned fillColor)
256247{
257- return AddCtrl (new ctrlColorDeepening (this , id, ScaleIf (pos), ScaleIf (size), tc, fillColor));
248+ return AddCtrl (std::make_unique< ctrlColorDeepening> (this , id, ScaleIf (pos), ScaleIf (size), tc, fillColor));
258249}
259250
260251ctrlDeepening* Window::AddImageDeepening (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
261252 ITexture* image)
262253{
263- return AddCtrl (new ctrlImageDeepening (this , id, ScaleIf (pos), ScaleIf (size), tc, image));
254+ return AddCtrl (std::make_unique< ctrlImageDeepening> (this , id, ScaleIf (pos), ScaleIf (size), tc, image));
264255}
265256
266257ctrlDeepening* Window::AddImageDeepening (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
@@ -272,18 +263,18 @@ ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, cons
272263ctrlEdit* Window::AddEdit (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
273264 unsigned short maxlength, bool password, bool disabled, bool notify)
274265{
275- return AddCtrl (
276- new ctrlEdit ( this , id, ScaleIf (pos), ScaleIf (size), tc, font, maxlength, password, disabled, notify));
266+ return AddCtrl (std::make_unique<ctrlEdit>( this , id, ScaleIf (pos), ScaleIf (size), tc, font, maxlength, password,
267+ disabled, notify));
277268}
278269
279270ctrlGroup* Window::AddGroup (unsigned id)
280271{
281- return AddCtrl (new ctrlGroup (this , id));
272+ return AddCtrl (std::make_unique< ctrlGroup> (this , id));
282273}
283274
284275ctrlImage* Window::AddImage (unsigned id, const DrawPoint& pos, ITexture* image, const std::string& tooltip)
285276{
286- return AddCtrl (new ctrlImage (this , id, ScaleIf (pos), image, tooltip));
277+ return AddCtrl (std::make_unique< ctrlImage> (this , id, ScaleIf (pos), image, tooltip));
287278}
288279
289280ctrlImage* Window::AddImage (unsigned id, const DrawPoint& pos, glArchivItem_Bitmap* image, const std::string& tooltip)
@@ -293,110 +284,77 @@ ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitm
293284
294285ctrlList* Window::AddList (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font)
295286{
296- return AddCtrl (new ctrlList (this , id, ScaleIf (pos), ScaleIf (size), tc, font));
287+ return AddCtrl (std::make_unique< ctrlList> (this , id, ScaleIf (pos), ScaleIf (size), tc, font));
297288}
298289
299290ctrlMultiline* Window::AddMultiline (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
300291 const glFont* font, FontStyle format)
301292{
302- return AddCtrl (new ctrlMultiline (this , id, ScaleIf (pos), ScaleIf (size), tc, font, format));
293+ return AddCtrl (std::make_unique< ctrlMultiline> (this , id, ScaleIf (pos), ScaleIf (size), tc, font, format));
303294}
304295
305- /* *
306- * fügt ein OptionenGruppe hinzu.
307- *
308- * @param[in] id ID des Steuerelements
309- * @param[in] select_type Typ der Auswahl
310- *
311- * @return Instanz das Steuerelement.
312- */
313296ctrlOptionGroup* Window::AddOptionGroup (unsigned id, GroupSelectType select_type)
314297{
315- return AddCtrl (new ctrlOptionGroup (this , id, select_type));
298+ return AddCtrl (std::make_unique< ctrlOptionGroup> (this , id, select_type));
316299}
317300
318- /* *
319- * fügt ein MultiSelectGruppe hinzu.
320- *
321- * @param[in] id ID des Steuerelements
322- * @param[in] select_type Typ der Auswahl
323- *
324- * @return Instanz das Steuerelement.
325- */
326301ctrlMultiSelectGroup* Window::AddMultiSelectGroup (unsigned id, GroupSelectType select_type)
327302{
328- return AddCtrl (new ctrlMultiSelectGroup (this , id, select_type));
303+ return AddCtrl (std::make_unique< ctrlMultiSelectGroup> (this , id, select_type));
329304}
330305
331306ctrlPercent* Window::AddPercent (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
332307 unsigned text_color, const glFont* font, const unsigned short * percentage)
333308{
334- return AddCtrl (new ctrlPercent (this , id, ScaleIf (pos), ScaleIf (size), tc, text_color, font, percentage));
309+ return AddCtrl (
310+ std::make_unique<ctrlPercent>(this , id, ScaleIf (pos), ScaleIf (size), tc, text_color, font, percentage));
335311}
336312
337313ctrlProgress* Window::AddProgress (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
338314 unsigned short button_minus, unsigned short button_plus, unsigned short maximum,
339315 const std::string& tooltip, const Extent& padding, unsigned force_color,
340316 const std::string& button_minus_tooltip, const std::string& button_plus_tooltip)
341317{
342- return AddCtrl (new ctrlProgress (this , id, ScaleIf (pos), ScaleIf (size), tc, button_minus, button_plus, maximum,
343- padding, force_color, tooltip, button_minus_tooltip, button_plus_tooltip));
318+ return AddCtrl (std::make_unique<ctrlProgress>(this , id, ScaleIf (pos), ScaleIf (size), tc, button_minus, button_plus,
319+ maximum, padding, force_color, tooltip, button_minus_tooltip,
320+ button_plus_tooltip));
344321}
345322
346323ctrlScrollBar* Window::AddScrollBar (unsigned id, const DrawPoint& pos, const Extent& size, unsigned short button_height,
347324 TextureColor tc, unsigned short page_size)
348325{
349326 button_height = ScaleIf (Extent (0 , button_height)).y ;
350327
351- return AddCtrl (new ctrlScrollBar (this , id, ScaleIf (pos), ScaleIf (size), button_height, tc, page_size));
328+ return AddCtrl (
329+ std::make_unique<ctrlScrollBar>(this , id, ScaleIf (pos), ScaleIf (size), button_height, tc, page_size));
352330}
353331
354332ctrlTab* Window::AddTabCtrl (unsigned id, const DrawPoint& pos, unsigned short width)
355333{
356- return AddCtrl (new ctrlTab (this , id, ScaleIf (pos), ScaleIf (Extent (width, 0 )).x ));
334+ return AddCtrl (std::make_unique< ctrlTab> (this , id, ScaleIf (pos), ScaleIf (Extent (width, 0 )).x ));
357335}
358336
359- /* *
360- * fügt eine Tabelle hinzu.
361- * ... sollte eine Menge von const char*, int und SortType sein
362- */
363337ctrlTable* Window::AddTable (unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
364338 std::vector<TableColumn> columns)
365339{
366- return AddCtrl (new ctrlTable (this , id, ScaleIf (pos), ScaleIf (size), tc, font, std::move (columns)));
340+ return AddCtrl (std::make_unique< ctrlTable> (this , id, ScaleIf (pos), ScaleIf (size), tc, font, std::move (columns)));
367341}
368342
369343ctrlTimer* Window::AddTimer (unsigned id, std::chrono::milliseconds timeout)
370344{
371- return AddCtrl (new ctrlTimer (this , id, timeout));
345+ return AddCtrl (std::make_unique< ctrlTimer> (this , id, timeout));
372346}
373347
374- /* *
375- * fügt ein TextCtrl hinzu.
376- *
377- * @param[in] x X-Koordinate des Steuerelements
378- * @param[in] y Y-Koordinate des Steuerelements
379- * @param[in] text Text
380- * @param[in] color Textfarbe
381- * @param[in] format Formatierung des Textes
382- * @p FontStyle::LEFT - Text links ( standard )
383- * @p FontStyle::CENTER - Text mittig
384- * @p FontStyle::RIGHT - Text rechts
385- * @p FontStyle::TOP - Text oben ( standard )
386- * @p FontStyle::VCENTER - Text vertikal zentriert
387- * @p FontStyle::BOTTOM - Text unten
388- * @param[in] font Schriftart
389- */
390348ctrlText* Window::AddText (unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, FontStyle format,
391349 const glFont* font)
392350{
393- return AddCtrl (new ctrlText (this , id, ScaleIf (pos), text, color, format, font));
351+ return AddCtrl (std::make_unique< ctrlText> (this , id, ScaleIf (pos), text, color, format, font));
394352}
395353
396354ctrlMapSelection* Window::AddMapSelection (unsigned id, const DrawPoint& pos, const Extent& size,
397355 const SelectionMapInputData& inputData)
398356{
399- return AddCtrl (new ctrlMapSelection (this , id, ScaleIf (pos), ScaleIf (size), inputData));
357+ return AddCtrl (std::make_unique< ctrlMapSelection> (this , id, ScaleIf (pos), ScaleIf (size), inputData));
400358}
401359
402360TextFormatSetter Window::AddFormattedText (unsigned id, const DrawPoint& pos, const std::string& text, unsigned color,
@@ -412,49 +370,32 @@ ctrlVarDeepening* Window::AddVarDeepening(unsigned id, const DrawPoint& pos, con
412370 va_list liste;
413371 va_start (liste, parameters);
414372
415- auto * ctrl =
416- new ctrlVarDeepening ( this , id, ScaleIf (pos), ScaleIf (size), tc, formatstr, font, color, parameters, liste);
373+ auto ctrl = std::make_unique<ctrlVarDeepening>( this , id, ScaleIf (pos), ScaleIf (size), tc, formatstr, font, color,
374+ parameters, liste);
417375
418376 va_end (liste);
419377
420- return AddCtrl (ctrl);
378+ return AddCtrl (std::move ( ctrl) );
421379}
422380
423- /* *
424- * fügt ein variables TextCtrl hinzu.
425- *
426- * @param[in] x X-Koordinate des Steuerelements
427- * @param[in] y Y-Koordinate des Steuerelements
428- * @param[in] formatstr Der Formatstring des Steuerelements
429- * @param[in] color Textfarbe
430- * @param[in] format Formatierung des Textes
431- * @p FontStyle::LEFT - Text links ( standard )
432- * @p FontStyle::CENTER - Text mittig
433- * @p FontStyle::RIGHT - Text rechts
434- * @p FontStyle::TOP - Text oben ( standard )
435- * @p FontStyle::VCENTER - Text vertikal zentriert
436- * @p FontStyle::BOTTOM - Text unten
437- * @param[in] font Schriftart
438- * @param[in] parameters Anzahl der nachfolgenden Parameter
439- * @param[in] ... die variablen Parameter
440- */
441381ctrlVarText* Window::AddVarText (unsigned id, const DrawPoint& pos, const std::string& formatstr, unsigned color,
442382 FontStyle format, const glFont* font, unsigned parameters, ...)
443383{
444384 va_list liste;
445385 va_start (liste, parameters);
446386
447- auto * ctrl = new ctrlVarText (this , id, ScaleIf (pos), formatstr, color, format, font, parameters, liste);
387+ auto ctrl =
388+ std::make_unique<ctrlVarText>(this , id, ScaleIf (pos), formatstr, color, format, font, parameters, liste);
448389
449390 va_end (liste);
450391
451- return AddCtrl (ctrl);
392+ return AddCtrl (std::move ( ctrl) );
452393}
453394
454395ctrlPreviewMinimap* Window::AddPreviewMinimap (const unsigned id, const DrawPoint& pos, const Extent& size,
455396 libsiedler2::ArchivItem_Map* const map)
456397{
457- return AddCtrl (new ctrlPreviewMinimap (this , id, ScaleIf (pos), ScaleIf (size), map));
398+ return AddCtrl (std::make_unique< ctrlPreviewMinimap> (this , id, ScaleIf (pos), ScaleIf (size), map));
458399}
459400
460401void Window::Draw3D (const Rect& rect, TextureColor tc, bool elevated, bool highlighted, bool illuminated,
@@ -499,19 +440,19 @@ void Window::DrawLine(DrawPoint pt1, DrawPoint pt2, unsigned short width, unsign
499440void Window::Msg_PaintBefore ()
500441{
501442 animations_.update (VIDEODRIVER.GetTickCount ());
502- for (Window* control : childIdToWnd_ | boost::adaptors::map_values)
443+ for (auto & control : childIdToWnd_ | boost::adaptors::map_values)
503444 control->Msg_PaintBefore ();
504445}
505446
506447void Window::Msg_PaintAfter ()
507448{
508- for (Window* control : childIdToWnd_ | boost::adaptors::map_values)
449+ for (auto & control : childIdToWnd_ | boost::adaptors::map_values)
509450 control->Msg_PaintAfter ();
510451}
511452
512453void Window::Draw_ ()
513454{
514- for (Window* control : childIdToWnd_ | boost::adaptors::map_values)
455+ for (auto & control : childIdToWnd_ | boost::adaptors::map_values)
515456 control->Draw ();
516457}
517458
@@ -521,10 +462,8 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr)
521462 if (!scale_)
522463 return ;
523464 RescaleWindowProp rescale (sr.oldSize , sr.newSize );
524- for (Window* ctrl : childIdToWnd_ | boost::adaptors::map_values)
465+ for (auto & ctrl : childIdToWnd_ | boost::adaptors::map_values)
525466 {
526- if (!ctrl)
527- continue ;
528467 // Save new size (could otherwise be changed(?) in Msg_ScreenResize)
529468 Extent newSize = rescale (ctrl->GetSize ());
530469 ctrl->SetPos (rescale (ctrl->GetPos ()));
0 commit comments