[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] [pingus] push by address@hidden - Added create<>() to Group
From: |
pingus |
Subject: |
[Pingus-CVS] [pingus] push by address@hidden - Added create<>() to GroupComponent() to get rid of manual "new" calls on 2011-10-11 15:42 GMT |
Date: |
Tue, 11 Oct 2011 15:43:04 +0000 |
Revision: 1a188fc7ca01
Author: Ingo Ruhnke <address@hidden>
Date: Tue Oct 11 08:42:27 2011
Log: Added create<>() to GroupComponent() to get rid of manual "new"
calls
http://code.google.com/p/pingus/source/detail?r=1a188fc7ca01
Modified:
/src/editor/action_properties.cpp
/src/editor/editor_screen.cpp
/src/editor/file_dialog.cpp
/src/editor/generic_level_obj.cpp
/src/editor/group_level_obj.cpp
/src/editor/level_obj_factory.cpp
/src/editor/level_properties.cpp
/src/editor/message_box.cpp
/src/editor/object_properties.cpp
/src/editor/object_selector.cpp
/src/editor/object_selector_list_objects.hpp
/src/editor/panel.cpp
/src/engine/gui/group_component.hpp
=======================================
--- /src/editor/action_properties.cpp Mon Aug 29 14:30:22 2011
+++ /src/editor/action_properties.cpp Tue Oct 11 08:42:27 2011
@@ -69,15 +69,12 @@
ActionProperties::add_action(ActionName::Enum id)
{
ActionComponent comp;
- comp.checkbox = new Checkbox(Rect(Vector2i(10,10 + y_pos), Size(80,20)),
ActionName::to_screenname(id));
- comp.inputbox = new Inputbox(Rect(Vector2i(100,10 + y_pos),
Size(40,20)));
+ comp.checkbox = create<Checkbox>(Rect(Vector2i(10,10 + y_pos),
Size(80,20)), ActionName::to_screenname(id));
+ comp.inputbox = create<Inputbox>(Rect(Vector2i(100,10 + y_pos),
Size(40,20)));
comp.checkbox->set_checked(true);
comp.inputbox->set_text("20");
-
- add(comp.checkbox);
- add(comp.inputbox);
-
+
action_comps[id] = comp;
comp.checkbox->on_change.connect(std::bind(&ActionProperties::on_checkbox_change,
this, std::placeholders::_1, id));
=======================================
--- /src/editor/editor_screen.cpp Tue Oct 11 07:00:51 2011
+++ /src/editor/editor_screen.cpp Tue Oct 11 08:42:27 2011
@@ -67,50 +67,42 @@
minimap = new Minimap(this, Rect());
gui_manager->add(minimap);
- object_properties = new ObjectProperties(this, Rect(Vector2i(),
Size(200, 150)));
- gui_manager->add(object_properties);
-
- action_properties = new ActionProperties(this, Rect());
+ object_properties = gui_manager->create<ObjectProperties>(this,
Rect(Vector2i(), Size(200, 150)));
+
+ action_properties = gui_manager->create<ActionProperties>(this, Rect());
action_properties->hide();
- gui_manager->add(action_properties);
-
- level_properties = new LevelProperties(this, Rect());
+
+ level_properties = gui_manager->create<LevelProperties>(this, Rect());
level_properties->hide();
level_properties->set_level(plf.get());
action_properties->set_level(plf.get());
- gui_manager->add(level_properties);
-
- object_selector = new ObjectSelector(this, Rect());
- gui_manager->add(object_selector);
-
- file_load_dialog = new FileDialog(this, Rect(Vector2i(50, 50),
- Size(size.width - 100,
- size.height - 100)),
- FileDialog::LOAD);
+
+ object_selector = gui_manager->create<ObjectSelector>(this, Rect());
+
+ file_load_dialog = gui_manager->create<FileDialog>(this,
Rect(Vector2i(50, 50),
+
Size(size.width - 100,
+
size.height - 100)),
+ FileDialog::LOAD);
file_load_dialog->set_directory(".");
file_load_dialog->hide();
- gui_manager->add(file_load_dialog);
-
- file_save_dialog = new FileDialog(this, Rect(Vector2i(50, 50),
- Size(Display::get_width() -
100,
- Display::get_height()
- 100)),
- FileDialog::SAVE);
+
+ file_save_dialog = gui_manager->create<FileDialog>(this,
Rect(Vector2i(50, 50),
+
Size(Display::get_width() - 100,
+
Display::get_height() - 100)),
+ FileDialog::SAVE);
file_save_dialog->set_directory(".");
file_save_dialog->hide();
- gui_manager->add(file_save_dialog);
{
Size msg_size(600, 160);
- std::unique_ptr<MessageBox> msgbox(new
MessageBox(Rect(Vector2i((Display::get_width() - msg_size.width)/2,
-
(Display::get_height()
- msg_size.height)/2),
-
msg_size)));
-
- msgbox->set_title("Create new level");
- msgbox->set_text("Replace current level with an empty new one?");
- msgbox->set_ok_text("Replace");
-
msgbox->on_ok.connect(std::bind(&EditorScreen::level_new_without_confirm,
this));
-
- gui_manager->add(m_level_new_msgbox = msgbox.release());
+
+ m_level_new_msgbox =
gui_manager->create<MessageBox>(Rect(Vector2i((Display::get_width() -
msg_size.width)/2,
+
(Display::get_height() - msg_size.height)/2),
+ msg_size));
+ m_level_new_msgbox->set_title("Create new level");
+ m_level_new_msgbox->set_text("Replace current level with an empty new
one?");
+ m_level_new_msgbox->set_ok_text("Replace");
+
m_level_new_msgbox->on_ok.connect(std::bind(&EditorScreen::level_new_without_confirm,
this));
m_level_new_msgbox->hide();
}
=======================================
--- /src/editor/file_dialog.cpp Tue Sep 27 05:52:55 2011
+++ /src/editor/file_dialog.cpp Tue Oct 11 08:42:27 2011
@@ -41,30 +41,29 @@
pathname_inputbox(),
filename_inputbox()
{
- file_list = new FileList(Rect(4, 30 + 30 + 30,
- rect.get_width()-4 - 30, rect.get_height()
- 4 - 35));
- add(file_list);
+ file_list = create<FileList>(Rect(4, 30 + 30 + 30,
+ rect.get_width()-4 - 30,
rect.get_height() - 4 - 35));
file_list->on_click.connect(std::bind(&FileDialog::load_file, this,
std::placeholders::_1));
Rect file_rect = file_list->get_rect();
- up_button = new Button(Rect(file_rect.right + 2, file_rect.top,
+ up_button = create<Button>(Rect(file_rect.right + 2, file_rect.top,
rect.get_width()-4, file_rect.top +
file_rect.get_height()/2 - 1),
"/\\\n|");
- down_button = new Button(Rect(file_rect.right + 2, file_rect.top +
file_rect.get_height()/2 + 1,
+ down_button = create<Button>(Rect(file_rect.right + 2, file_rect.top +
file_rect.get_height()/2 + 1,
rect.get_width()-4, file_rect.bottom),
"|\n\\/");
- datadir_button = new Button(Rect(Vector2i(4, rect.get_height() - 4 - 30),
- Size(100, 30)), _("Datadir"));
- userdir_button = new Button(Rect(Vector2i(4 + 110, rect.get_height() - 4
- 30),
- Size(100, 30)), _("Userdir"));
-
- open_button = new Button(Rect(Vector2i(rect.get_width() - 104,
rect.get_height() - 4 - 30),
- Size(100, 30)), mode == LOAD ? _("Open") :
_("Save"));
-
- cancel_button = new Button(Rect(Vector2i(rect.get_width() - 104 - 104,
rect.get_height() - 4 - 30),
- Size(100, 30)), _("Cancel"));
+ datadir_button = create<Button>(Rect(Vector2i(4, rect.get_height() - 4 -
30),
+ Size(100, 30)), _("Datadir"));
+ userdir_button = create<Button>(Rect(Vector2i(4 + 110, rect.get_height()
- 4 - 30),
+ Size(100, 30)), _("Userdir"));
+
+ open_button = create<Button>(Rect(Vector2i(rect.get_width() - 104,
rect.get_height() - 4 - 30),
+ Size(100, 30)), mode == LOAD ?
_("Open") : _("Save"));
+
+ cancel_button = create<Button>(Rect(Vector2i(rect.get_width() - 104 -
104, rect.get_height() - 4 - 30),
+ Size(100, 30)), _("Cancel"));
up_button->on_click.connect(std::bind(&FileDialog::on_up, this));
down_button->on_click.connect(std::bind(&FileDialog::on_down, this));
@@ -75,23 +74,14 @@
open_button->on_click.connect(std::bind(&FileDialog::on_open, this));
cancel_button->on_click.connect(std::bind(&FileDialog::on_cancel, this));
- add(filename_label = new Label(Rect(6, 4+30, 4 + 60, 26+30),
_("Filename:")));
- add(pathname_label = new Label(Rect(6, 4+60, 4 + 60, 26+60),
_("Pathname:")));
-
- add(filename_inputbox = new Inputbox(Rect(4 + 60, 4+30,
rect.get_width()-4, 26+30)));
- add(pathname_inputbox = new Inputbox(Rect(4 + 60, 4+60,
rect.get_width()-4, 26+60)));
+ filename_label = create<Label>(Rect(6, 4+30, 4 + 60, 26+30),
_("Filename:"));
+ pathname_label = create<Label>(Rect(6, 4+60, 4 + 60, 26+60),
_("Pathname:"));
+
+ filename_inputbox = create<Inputbox>(Rect(4 + 60, 4+30,
rect.get_width()-4, 26+30));
+ pathname_inputbox = create<Inputbox>(Rect(4 + 60, 4+60,
rect.get_width()-4, 26+60));
filename_inputbox->on_enter.connect(std::bind(&FileDialog::on_filename_enter,
this));
pathname_inputbox->on_change.connect(std::bind(&FileDialog::on_pathname_change,
this));
-
- add(up_button);
- add(down_button);
-
- add(datadir_button);
- add(userdir_button);
-
- add(open_button);
- add(cancel_button);
}
FileDialog::~FileDialog()
=======================================
--- /src/editor/generic_level_obj.cpp Tue Sep 27 17:24:41 2011
+++ /src/editor/generic_level_obj.cpp Tue Oct 11 08:42:27 2011
@@ -502,7 +502,7 @@
LevelObjPtr
GenericLevelObj::duplicate(const Vector2i& offset) const
{
- std::shared_ptr<GenericLevelObj> obj(new GenericLevelObj(*this));
+ std::shared_ptr<GenericLevelObj> obj =
std::make_shared<GenericLevelObj>(*this);
obj->pos.x += static_cast<float>(offset.x);
obj->pos.y += static_cast<float>(offset.y);
return obj;
=======================================
--- /src/editor/group_level_obj.cpp Tue Sep 27 06:07:52 2011
+++ /src/editor/group_level_obj.cpp Tue Oct 11 08:42:27 2011
@@ -30,7 +30,7 @@
{
PrefabFile prefab = PrefabFile::from_resource(name);
- std::shared_ptr<GroupLevelObj> group(new GroupLevelObj);
+ std::shared_ptr<GroupLevelObj> group =
std::make_shared<GroupLevelObj>();
group->m_name = name;
for(auto it = prefab.get_objects().begin(); it !=
prefab.get_objects().end(); ++it)
@@ -264,7 +264,7 @@
LevelObjPtr
GroupLevelObj::duplicate(const Vector2i& offset) const
{
- std::shared_ptr<GroupLevelObj> group(new GroupLevelObj);
+ std::shared_ptr<GroupLevelObj> group = std::make_shared<GroupLevelObj>();
group->m_name = m_name;
group->m_pos = m_pos + offset;
=======================================
--- /src/editor/level_obj_factory.cpp Sat Sep 17 04:24:43 2011
+++ /src/editor/level_obj_factory.cpp Tue Oct 11 08:42:27 2011
@@ -27,7 +27,7 @@
{
if (reader.get_name() == "group")
{
- std::shared_ptr<GroupLevelObj> group(new GroupLevelObj);
+ std::shared_ptr<GroupLevelObj> group =
std::make_shared<GroupLevelObj>();
FileReader objects = reader.read_section("objects");
std::vector<FileReader> sections = objects.get_sections();
@@ -78,7 +78,7 @@
bool tmp_bool;
// Create new object
- LevelObjPtr obj(new GenericLevelObj(reader.get_name()));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>(reader.get_name());
attribs = obj->get_attribs();
// All objects have a position - get that.
=======================================
--- /src/editor/level_properties.cpp Wed Sep 7 12:26:39 2011
+++ /src/editor/level_properties.cpp Tue Oct 11 08:42:27 2011
@@ -49,33 +49,33 @@
height(),
music()
{
- add(new Label (Rect(Vector2i( 10, 10), Size( 80, 20)), "Author:"));
- add(author = new Inputbox);
-
- add(new Label (Rect(Vector2i( 10, 32), Size( 80, 20)), "Levelname:"));
- add(levelname = new Inputbox);
-
- add(new Label (Rect(Vector2i( 10, 54), Size( 80,
20)), "Description:"));
- add(description = new Inputbox);
+ create<Label>(Rect(Vector2i( 10, 10), Size( 80, 20)), "Author:");
+ author = create<Inputbox>();
+
+ create<Label>(Rect(Vector2i( 10, 32), Size( 80, 20)), "Levelname:");
+ levelname = create<Inputbox>();
+
+ create<Label>(Rect(Vector2i( 10, 54), Size( 80, 20)), "Description:");
+ description = create<Inputbox>();
int y = 116;
- add(new Label (Rect(Vector2i( 10, y), Size( 80, 20)), "Pingus
Count:"));
- add(number_of_pingus = new Inputbox);
-
- add(new Label (Rect(Vector2i( 10, y+22), Size( 80, 20)), "Pingus to
Save:"));
- add(number_to_save = new Inputbox);
-
- add(new Label (Rect(Vector2i( 10, y+44), Size( 80, 20)), "Time:"));
- add(time = new Inputbox);
-
- add(new Label (Rect(Vector2i( 10, y+66), Size( 80, 20)), "Width:"));
- add(width = new Inputbox);
-
- add(new Label (Rect(Vector2i( 10, y+88), Size( 80, 20)), "Height:"));
- add(height = new Inputbox);
-
- add(new Label (Rect(Vector2i( 10, y+110), Size( 80, 20)), "Music:"));
- add(music = new Inputbox);
+ create<Label>(Rect(Vector2i( 10, y), Size( 80, 20)), "Pingus Count:");
+ number_of_pingus = create<Inputbox>();
+
+ create<Label>(Rect(Vector2i( 10, y+22), Size( 80, 20)), "Pingus to
Save:");
+ number_to_save = create<Inputbox>();
+
+ create<Label>(Rect(Vector2i( 10, y+44), Size( 80, 20)), "Time:");
+ time = create<Inputbox>();
+
+ create<Label>(Rect(Vector2i( 10, y+66), Size( 80, 20)), "Width:");
+ width = create<Inputbox>();
+
+ create<Label>(Rect(Vector2i( 10, y+88), Size( 80, 20)), "Height:");
+ height = create<Inputbox>();
+
+ create<Label>(Rect(Vector2i( 10, y+110), Size( 80, 20)), "Music:");
+ music = create<Inputbox>();
author->on_change.connect(std::bind(&LevelProperties::on_author_change,
this, std::placeholders::_1));
levelname->on_change.connect(std::bind(&LevelProperties::on_levelname_change,
this, std::placeholders::_1));
=======================================
--- /src/editor/message_box.cpp Tue Sep 27 06:07:52 2011
+++ /src/editor/message_box.cpp Tue Oct 11 08:42:27 2011
@@ -31,13 +31,10 @@
m_text(),
on_ok()
{
- m_cancel_button = new Button(Rect(Vector2i(rect.get_width() - 4 - 210,
rect.get_height() - 4 - 30),
- Size(100, 30)), _("Cancel"));
- m_ok_button = new Button(Rect(Vector2i(rect.get_width() - 4 - 100,
rect.get_height() - 4 - 30),
- Size(100, 30)), _("Replace"));
-
- add(m_ok_button);
- add(m_cancel_button);
+ m_cancel_button = create<Button>(Rect(Vector2i(rect.get_width() - 4 -
210, rect.get_height() - 4 - 30),
+ Size(100, 30)), _("Cancel"));
+ m_ok_button = create<Button>(Rect(Vector2i(rect.get_width() - 4 - 100,
rect.get_height() - 4 - 30),
+ Size(100, 30)), _("Replace"));
m_ok_button->on_click.connect(std::bind(&MessageBox::on_ok_button,
this));
m_cancel_button->on_click.connect(std::bind(&MessageBox::on_cancel_button,
this));
=======================================
--- /src/editor/object_properties.cpp Mon Sep 12 13:41:30 2011
+++ /src/editor/object_properties.cpp Tue Oct 11 08:42:27 2011
@@ -84,15 +84,15 @@
height_inputbox(),
y_pos()
{
- add(type_label = new Label(Rect(Vector2i(4, 4), Size(120, 20)),
_("Object:")));
- add(mesg_label = new Label(Rect(Vector2i(10, 0), Size(180, 20)),
_("Nothing selected")));
+ type_label = create<Label>(Rect(Vector2i(4, 4), Size(120, 20)),
_("Object:"));
+ mesg_label = create<Label>(Rect(Vector2i(10, 0), Size(180, 20)),
_("Nothing selected"));
Rect label_rect(10,0, 80, 20);
Rect box_rect(80,0, 190, 20);
// Groundpiece Type
- add(gptype_label = new Label(label_rect, "GPType:"));
- add(gptype_type = new Combobox(box_rect));
+ gptype_label = create<Label>(label_rect, "GPType:");
+ gptype_type = create<Combobox>(box_rect);
gptype_type->add(Groundtype::GP_TRANSPARENT, _("Transparent"));
gptype_type->add(Groundtype::GP_SOLID, _("Solid"));
@@ -105,8 +105,8 @@
gptype_type->on_select.connect(std::bind(&ObjectProperties::on_gptype_change,
this, std::placeholders::_1));
- add(entrance_direction_label = new Label(label_rect, _("Direction:")));
- add(entrance_direction = new Combobox(box_rect));
+ entrance_direction_label = create<Label>(label_rect, _("Direction:"));
+ entrance_direction = create<Combobox>(box_rect);
entrance_direction->add(0, _("Left"));
entrance_direction->add(1, _("Misc"));
entrance_direction->add(2, _("Right"));
@@ -114,63 +114,63 @@
entrance_direction->on_select.connect(std::bind(&ObjectProperties::on_entrance_direction_change,
this, std::placeholders::_1));
- add(release_rate_label = new Label(label_rect, _("ReleaseRate:")));
- add(release_rate_inputbox = new Inputbox(box_rect));
+ release_rate_label = create<Label>(label_rect, _("ReleaseRate:"));
+ release_rate_inputbox = create<Inputbox>(box_rect);
release_rate_inputbox->on_change.connect(std::bind(&ObjectProperties::on_release_rate_change,
this, std::placeholders::_1));
// Background Stretch
- add(stretch_label = new Label(label_rect, "Stretch:"));
- add(stretch_x_checkbox = new Checkbox(Rect(Vector2i(box_rect.left,
box_rect.top),
+ stretch_label = create<Label>(label_rect, "Stretch:");
+ stretch_x_checkbox = create<Checkbox>(Rect(Vector2i(box_rect.left,
box_rect.top),
Size(box_rect.get_width()/2,
box_rect.get_height())),
- "X"));
- add(stretch_y_checkbox = new
Checkbox(Rect(Vector2i(box_rect.left+box_rect.get_width()/2, box_rect.top),
+ "X");
+ stretch_y_checkbox =
create<Checkbox>(Rect(Vector2i(box_rect.left+box_rect.get_width()/2,
box_rect.top),
Size(box_rect.get_width()/2,
box_rect.get_height())),
- "Y"));
+ "Y");
stretch_x_checkbox->on_change.connect(std::bind(&ObjectProperties::on_stretch_x_change,
this, std::placeholders::_1));
stretch_y_checkbox->on_change.connect(std::bind(&ObjectProperties::on_stretch_y_change,
this, std::placeholders::_1));
- add(keep_aspect_label = new Label(label_rect, "Aspect:"));
- add(keep_aspect_checkbox = new Checkbox(Rect(Vector2i(box_rect.left,
box_rect.top),
+ keep_aspect_label = create<Label>(label_rect, "Aspect:");
+ keep_aspect_checkbox = create<Checkbox>(Rect(Vector2i(box_rect.left,
box_rect.top),
Size(box_rect.get_width(),
box_rect.get_height())),
- "keep"));
+ "keep");
keep_aspect_checkbox->on_change.connect(std::bind(&ObjectProperties::on_keep_aspect_change,
this, std::placeholders::_1));
- add(para_x_label = new Label(label_rect, _("Para-X:")));
- add(para_y_label = new Label(label_rect, _("Para-Y:")));
-
- add(para_x_inputbox = new Inputbox(box_rect));
- add(para_y_inputbox = new Inputbox(box_rect));
+ para_x_label = create<Label>(label_rect, _("Para-X:"));
+ para_y_label = create<Label>(label_rect, _("Para-Y:"));
+
+ para_x_inputbox = create<Inputbox>(box_rect);
+ para_y_inputbox = create<Inputbox>(box_rect);
para_x_inputbox->on_change.connect(std::bind(&ObjectProperties::on_para_x_change,
this, std::placeholders::_1));
para_y_inputbox->on_change.connect(std::bind(&ObjectProperties::on_para_y_change,
this, std::placeholders::_1));
- add(scroll_x_label = new Label(label_rect, _("Scroll-X:")));
- add(scroll_y_label = new Label(label_rect, _("Scroll-Y:")));
-
- add(scroll_x_inputbox = new Inputbox(box_rect));
- add(scroll_y_inputbox = new Inputbox(box_rect));
+ scroll_x_label = create<Label>(label_rect, _("Scroll-X:"));
+ scroll_y_label = create<Label>(label_rect, _("Scroll-Y:"));
+
+ scroll_x_inputbox = create<Inputbox>(box_rect);
+ scroll_y_inputbox = create<Inputbox>(box_rect);
scroll_x_inputbox->on_change.connect(std::bind(&ObjectProperties::on_scroll_x_change,
this, std::placeholders::_1));
scroll_y_inputbox->on_change.connect(std::bind(&ObjectProperties::on_scroll_y_change,
this, std::placeholders::_1));
- add(owner_label = new Label(label_rect, _("Owner Id:")));
- add(owner_inputbox = new Inputbox(box_rect));
+ owner_label = create<Label>(label_rect, _("Owner Id:"));
+ owner_inputbox = create<Inputbox>(box_rect);
owner_inputbox->on_change.connect(std::bind(&ObjectProperties::on_owner_change,
this, std::placeholders::_1));
- add(pos_z_label = new Label(label_rect, _("Z-Pos:")));
- add(pos_z_inputbox = new Inputbox(box_rect));
+ pos_z_label = create<Label>(label_rect, _("Z-Pos:"));
+ pos_z_inputbox = create<Inputbox>(box_rect);
pos_z_inputbox->on_change.connect(std::bind(&ObjectProperties::on_pos_z_change,
this, std::placeholders::_1));
// ___________________________________________________________________
//
Size color_s(box_rect.get_width()/4, box_rect.get_height());
- add(color_label = new Label(label_rect, _("Color:")));
- add(color_r_inputbox = new Inputbox(Rect(Vector2i(box_rect.left +
0*color_s.width, box_rect.top), color_s)));
- add(color_g_inputbox = new Inputbox(Rect(Vector2i(box_rect.left +
1*color_s.width, box_rect.top), color_s)));
- add(color_b_inputbox = new Inputbox(Rect(Vector2i(box_rect.left +
2*color_s.width, box_rect.top), color_s)));
- add(color_a_inputbox = new Inputbox(Rect(Vector2i(box_rect.left +
3*color_s.width, box_rect.top), color_s)));
+ color_label = create<Label>(label_rect, _("Color:"));
+ color_r_inputbox = create<Inputbox>(Rect(Vector2i(box_rect.left +
0*color_s.width, box_rect.top), color_s));
+ color_g_inputbox = create<Inputbox>(Rect(Vector2i(box_rect.left +
1*color_s.width, box_rect.top), color_s));
+ color_b_inputbox = create<Inputbox>(Rect(Vector2i(box_rect.left +
2*color_s.width, box_rect.top), color_s));
+ color_a_inputbox = create<Inputbox>(Rect(Vector2i(box_rect.left +
3*color_s.width, box_rect.top), color_s));
color_r_inputbox->on_change.connect(std::bind(&ObjectProperties::on_color_r_change,
this, std::placeholders::_1));
color_g_inputbox->on_change.connect(std::bind(&ObjectProperties::on_color_g_change,
this, std::placeholders::_1));
@@ -178,29 +178,29 @@
color_a_inputbox->on_change.connect(std::bind(&ObjectProperties::on_color_a_change,
this, std::placeholders::_1));
// ___________________________________________________________________
//
- add(small_stars_label = new Label(label_rect, _("Small Stars:")));
- add(small_stars_inputbox = new Inputbox(box_rect));
-
- add(middle_stars_label = new Label(label_rect, _("Middle Stars:")));
- add(middle_stars_inputbox = new Inputbox(box_rect));
-
- add(large_stars_label = new Label(label_rect, _("Large Stars:")));
- add(large_stars_inputbox = new Inputbox(box_rect));
+ small_stars_label = create<Label>(label_rect, _("Small Stars:"));
+ small_stars_inputbox = create<Inputbox>(box_rect);
+
+ middle_stars_label = create<Label>(label_rect, _("Middle Stars:"));
+ middle_stars_inputbox = create<Inputbox>(box_rect);
+
+ large_stars_label = create<Label>(label_rect, _("Large Stars:"));
+ large_stars_inputbox = create<Inputbox>(box_rect);
small_stars_inputbox->on_change.connect(std::bind(&ObjectProperties::on_small_stars_change,
this, std::placeholders::_1));
middle_stars_inputbox->on_change.connect(std::bind(&ObjectProperties::on_middle_stars_change,
this, std::placeholders::_1));
large_stars_inputbox->on_change.connect(std::bind(&ObjectProperties::on_large_stars_change,
this, std::placeholders::_1));
// ___________________________________________________________________
//
- add(repeat_label = new Label(label_rect, _("Repeat:")));
- add(repeat_inputbox = new Inputbox(box_rect));
+ repeat_label = create<Label>(label_rect, _("Repeat:"));
+ repeat_inputbox = create<Inputbox>(box_rect);
repeat_inputbox->on_change.connect(std::bind(&ObjectProperties::on_repeat_change,
this, std::placeholders::_1));
// ___________________________________________________________________
//
- add(flip_horizontal_button = new Button(Rect(Vector2i(15+40*0-3, 0),
Size(34, 34)), "|"));
- add(flip_vertical_button = new Button(Rect(Vector2i(15+40*1-3, 0),
Size(34, 34)), "--"));
- add(rotate_270_button = new Button(Rect(Vector2i(15+40*2-3 + 20,
0), Size(34, 34)), "<-."));
- add(rotate_90_button = new Button(Rect(Vector2i(15+40*3-3 + 20,
0), Size(34, 34)), ".->"));
+ flip_horizontal_button = create<Button>(Rect(Vector2i(15+40*0-3, 0),
Size(34, 34)), "|");
+ flip_vertical_button = create<Button>(Rect(Vector2i(15+40*1-3, 0),
Size(34, 34)), "--");
+ rotate_270_button = create<Button>(Rect(Vector2i(15+40*2-3 + 20,
0), Size(34, 34)), "<-.");
+ rotate_90_button = create<Button>(Rect(Vector2i(15+40*3-3 + 20,
0), Size(34, 34)), ".->");
flip_vertical_button->on_click.connect(std::bind(&ObjectProperties::on_flip_vertical,
this));
flip_horizontal_button->on_click.connect(std::bind(&ObjectProperties::on_flip_horizontal,
this));
@@ -208,17 +208,17 @@
rotate_270_button->on_click.connect(std::bind(&ObjectProperties::on_rotate_270,
this));
// ___________________________________________________________________
//
- add(id_label = new Label(label_rect, _("Id:")));
- add(id_inputbox = new Inputbox(box_rect));
+ id_label = create<Label>(label_rect, _("Id:"));
+ id_inputbox = create<Inputbox>(box_rect);
id_inputbox->on_change.connect(std::bind(&ObjectProperties::on_id_change,
this, std::placeholders::_1));
- add(target_id_label = new Label(label_rect, _("Target Id:")));
- add(target_id_inputbox = new Inputbox(box_rect));
+ target_id_label = create<Label>(label_rect, _("Target Id:"));
+ target_id_inputbox = create<Inputbox>(box_rect);
target_id_inputbox->on_change.connect(std::bind(&ObjectProperties::on_target_id_change,
this, std::placeholders::_1));
// ___________________________________________________________________
//
- add(height_label = new Label(label_rect, _("Height:")));
- add(height_inputbox = new Inputbox(box_rect));
+ height_label = create<Label>(label_rect, _("Height:"));
+ height_inputbox = create<Inputbox>(box_rect);
height_inputbox->on_change.connect(std::bind(&ObjectProperties::on_height_change,
this, std::placeholders::_1));
// ___________________________________________________________________
//
=======================================
--- /src/editor/object_selector.cpp Wed Sep 28 09:41:01 2011
+++ /src/editor/object_selector.cpp Tue Oct 11 08:42:27 2011
@@ -144,8 +144,8 @@
worldobj_set(),
prefab_set()
{
- add(object_list = new ObjectSelectorList(editor, this,
- Rect(2, 2 + 60 + 2,
rect.get_width() - 2, rect.get_height() - 2)));
+ object_list = create<ObjectSelectorList>(editor, this,
+ Rect(2, 2 + 60 + 2,
rect.get_width() - 2, rect.get_height() - 2));
gp_ground_set = create_gp_ground();
gp_solid_set = create_gp_solid();
@@ -194,10 +194,10 @@
ObjectSelectorSet* set)
{
ObjectSelectorButton* button;
- add(button = new ObjectSelectorButton(object_list,
+ button = create<ObjectSelectorButton>(object_list,
Vector2i(2 + button_pos.x * 30,
2 + button_pos.y * 30),
- image, tooltip));
+ image, tooltip);
button->on_click.connect(std::bind(&ObjectSelectorList::set_objects,
object_list, set));
button_pos.x += 1;
=======================================
--- /src/editor/object_selector_list_objects.hpp Mon Sep 19 06:02:23 2011
+++ /src/editor/object_selector_list_objects.hpp Tue Oct 11 08:42:27 2011
@@ -36,7 +36,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("groundpiece"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("groundpiece");
obj->set_pos(pos);
obj->set_res_desc(desc);
obj->set_ground_type(type);
@@ -52,7 +52,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("entrance"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("entrance");
obj->set_type("generic");
obj->set_pos(pos);
obj->set_pos_z(110);
@@ -74,7 +74,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("exit"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("exit");
obj->set_pos(pos);
obj->set_res_desc(desc);
// obj->set_para();
@@ -95,7 +95,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("hotspot"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("hotspot");
obj->set_pos(pos);
obj->set_pos_z(static_cast<float>(z_pos));
obj->set_res_desc(desc);
@@ -115,7 +115,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("surface-background"));
+ LevelObjPtr obj =
std::make_shared<GenericLevelObj>("surface-background");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y), -1000.0f)); // FIXME: Hack, z-pos handling is
messed up
obj->set_para_x(0.5f);
obj->set_para_y(0.5f);
@@ -136,7 +136,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("solidcolor-background"));
+ LevelObjPtr obj =
std::make_shared<GenericLevelObj>("solidcolor-background");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y), -1000.0f)); // FIXME: Hack, z-pos handling is
messed up
obj->set_color(Color(255, 0, 255));
return obj;
@@ -151,7 +151,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("starfield-background"));
+ LevelObjPtr obj =
std::make_shared<GenericLevelObj>("starfield-background");
// FIXME: Hack, z-pos handling is messed up
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y), -1000.0f));
obj->set_small_stars(500);
@@ -172,7 +172,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("liquid"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("liquid");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
obj->set_res_desc(desc);
obj->set_repeat(1);
@@ -188,7 +188,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("guillotine"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("guillotine");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -202,7 +202,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("spike"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("spike");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -216,7 +216,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("fake_exit"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("fake_exit");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -230,7 +230,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("laser_exit"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("laser_exit");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -244,7 +244,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("smasher"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("smasher");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -258,7 +258,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("hammer"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("hammer");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -272,7 +272,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("snow-generator"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("snow-generator");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -286,7 +286,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("rain-generator"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("rain-generator");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
return obj;
}
@@ -300,7 +300,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("teleporter"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("teleporter");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
obj->set_target_id("");
return obj;
@@ -315,7 +315,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("teleporter-target"));
+ LevelObjPtr obj =
std::make_shared<GenericLevelObj>("teleporter-target");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
obj->set_id("id" + StringUtil::to_string(rand()));
return obj;
@@ -330,7 +330,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("iceblock"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("iceblock");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
obj->set_repeat(1);
return obj;
@@ -345,7 +345,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("conveyorbelt"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("conveyorbelt");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
obj->set_repeat(1);
return obj;
@@ -360,7 +360,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("switchdoor-switch"));
+ LevelObjPtr obj =
std::make_shared<GenericLevelObj>("switchdoor-switch");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
obj->set_height(15);
obj->set_target_id("");
@@ -376,7 +376,7 @@
{}
LevelObjPtr create(const Vector2i& pos) {
- LevelObjPtr obj(new GenericLevelObj("switchdoor-door"));
+ LevelObjPtr obj = std::make_shared<GenericLevelObj>("switchdoor-door");
obj->set_pos(Vector3f(static_cast<float>(pos.x),
static_cast<float>(pos.y)));
obj->set_repeat(1);
obj->set_id("id" + StringUtil::to_string(rand()));
=======================================
--- /src/editor/panel.cpp Mon Sep 26 08:16:43 2011
+++ /src/editor/panel.cpp Tue Oct 11 08:42:27 2011
@@ -252,25 +252,22 @@
void
Panel::add_button(const std::string& image, const std::string& tooltip,
Callback callback_)
{
- PanelButton* comp = new PanelButton(editor, pos, image, tooltip,
callback_);
+ PanelButton* comp =
editor->get_gui_manager()->create<PanelButton>(editor, pos, image, tooltip,
callback_);
pos.x += comp->get_width();
- editor->get_gui_manager()->add(comp);
}
void
Panel::add_toggle_button(const std::string& image)
{
- PanelButton* comp = new PanelButton(editor, pos, image, "");
+ PanelButton* comp =
editor->get_gui_manager()->create<PanelButton>(editor, pos, image, "");
pos.x += comp->get_width();
- editor->get_gui_manager()->add(comp);
}
void
Panel::add_separator()
{
- PanelSeparator* comp = new PanelSeparator(pos);
+ PanelSeparator* comp =
editor->get_gui_manager()->create<PanelSeparator>(pos);
pos.x += comp->get_width();
- editor->get_gui_manager()->add(comp);
}
} // namespace Editor
=======================================
--- /src/engine/gui/group_component.hpp Wed Sep 7 04:00:46 2011
+++ /src/engine/gui/group_component.hpp Tue Oct 11 08:42:27 2011
@@ -69,6 +69,14 @@
/** \a comp will be deleted by GroupComponent */
void add(Component* comp);
+
+ template<typename C, typename ...Args>
+ C* create(Args&&... args)
+ {
+ C* c = new C(std::forward<Args>(args)...);
+ add(c);
+ return c;
+ }
void update_layout();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] [pingus] push by address@hidden - Added create<>() to GroupComponent() to get rid of manual "new" calls on 2011-10-11 15:42 GMT,
pingus <=