diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /editor/plugins/particles_2d_editor_plugin.cpp | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'editor/plugins/particles_2d_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/particles_2d_editor_plugin.cpp | 110 |
1 files changed, 50 insertions, 60 deletions
diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index 1efdbe9e68..94644cd410 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -35,9 +35,9 @@ void Particles2DEditorPlugin::edit(Object *p_object) { if (p_object) { - particles=p_object->cast_to<Particles2D>(); + particles = p_object->cast_to<Particles2D>(); } else { - particles=NULL; + particles = NULL; } } @@ -55,145 +55,135 @@ void Particles2DEditorPlugin::make_visible(bool p_visible) { toolbar->hide(); } - } -void Particles2DEditorPlugin::_file_selected(const String& p_file) { +void Particles2DEditorPlugin::_file_selected(const String &p_file) { - print_line("file: "+p_file); + print_line("file: " + p_file); - int epc=epoints->get_value(); + int epc = epoints->get_value(); Image img; - Error err = ImageLoader::load_image(p_file,&img); - ERR_EXPLAIN(TTR("Error loading image:")+" "+p_file); - ERR_FAIL_COND(err!=OK); + Error err = ImageLoader::load_image(p_file, &img); + ERR_EXPLAIN(TTR("Error loading image:") + " " + p_file); + ERR_FAIL_COND(err != OK); img.convert(Image::FORMAT_LA8); - ERR_FAIL_COND(img.get_format()!=Image::FORMAT_LA8); - Size2i s = Size2(img.get_width(),img.get_height()); - ERR_FAIL_COND(s.width==0 || s.height==0); + ERR_FAIL_COND(img.get_format() != Image::FORMAT_LA8); + Size2i s = Size2(img.get_width(), img.get_height()); + ERR_FAIL_COND(s.width == 0 || s.height == 0); PoolVector<uint8_t> data = img.get_data(); PoolVector<uint8_t>::Read r = data.read(); Vector<Point2i> valid_positions; - valid_positions.resize(s.width*s.height); - int vpc=0; - + valid_positions.resize(s.width * s.height); + int vpc = 0; - for(int i=0;i<s.width*s.height;i++) { + for (int i = 0; i < s.width * s.height; i++) { - uint8_t a = r[i*2+1]; - if (a>128) { - valid_positions[vpc++]=Point2i(i%s.width,i/s.width); + uint8_t a = r[i * 2 + 1]; + if (a > 128) { + valid_positions[vpc++] = Point2i(i % s.width, i / s.width); } } valid_positions.resize(vpc); ERR_EXPLAIN(TTR("No pixels with transparency > 128 in image..")); - ERR_FAIL_COND(valid_positions.size()==0); + ERR_FAIL_COND(valid_positions.size() == 0); PoolVector<Point2> epoints; epoints.resize(epc); PoolVector<Point2>::Write w = epoints.write(); - Size2 extents = Size2(img.get_width()*0.5,img.get_height()*0.5); + Size2 extents = Size2(img.get_width() * 0.5, img.get_height() * 0.5); - for(int i=0;i<epc;i++) { + for (int i = 0; i < epc; i++) { - Point2 p = valid_positions[Math::rand()%vpc]; - p-=s/2; - w[i]=p/extents; + Point2 p = valid_positions[Math::rand() % vpc]; + p -= s / 2; + w[i] = p / extents; } w = PoolVector<Point2>::Write(); undo_redo->create_action(TTR("Set Emission Mask")); - undo_redo->add_do_method(particles,"set_emission_points",epoints); - undo_redo->add_do_method(particles,"set_emission_half_extents",extents); - undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points()); - undo_redo->add_undo_method(particles,"set_emission_half_extents",particles->get_emission_half_extents()); + undo_redo->add_do_method(particles, "set_emission_points", epoints); + undo_redo->add_do_method(particles, "set_emission_half_extents", extents); + undo_redo->add_undo_method(particles, "set_emission_points", particles->get_emission_points()); + undo_redo->add_undo_method(particles, "set_emission_half_extents", particles->get_emission_half_extents()); undo_redo->commit_action(); - } void Particles2DEditorPlugin::_menu_callback(int p_idx) { - switch(p_idx) { + switch (p_idx) { case MENU_LOAD_EMISSION_MASK: { - file->popup_centered_ratio(); } break; case MENU_CLEAR_EMISSION_MASK: { undo_redo->create_action(TTR("Clear Emission Mask")); - undo_redo->add_do_method(particles,"set_emission_points",PoolVector<Vector2>()); - undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points()); + undo_redo->add_do_method(particles, "set_emission_points", PoolVector<Vector2>()); + undo_redo->add_undo_method(particles, "set_emission_points", particles->get_emission_points()); undo_redo->commit_action(); } break; } - } - void Particles2DEditorPlugin::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - menu->get_popup()->connect("id_pressed",this,"_menu_callback"); - menu->set_icon(menu->get_popup()->get_icon("Particles2D","EditorIcons")); - file->connect("file_selected",this,"_file_selected"); + menu->get_popup()->connect("id_pressed", this, "_menu_callback"); + menu->set_icon(menu->get_popup()->get_icon("Particles2D", "EditorIcons")); + file->connect("file_selected", this, "_file_selected"); } } void Particles2DEditorPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_callback"),&Particles2DEditorPlugin::_menu_callback); - ClassDB::bind_method(D_METHOD("_file_selected"),&Particles2DEditorPlugin::_file_selected); + ClassDB::bind_method(D_METHOD("_menu_callback"), &Particles2DEditorPlugin::_menu_callback); + ClassDB::bind_method(D_METHOD("_file_selected"), &Particles2DEditorPlugin::_file_selected); } - - Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) { - particles=NULL; - editor=p_node; - undo_redo=editor->get_undo_redo(); + particles = NULL; + editor = p_node; + undo_redo = editor->get_undo_redo(); - toolbar = memnew( HBoxContainer ); + toolbar = memnew(HBoxContainer); add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, toolbar); toolbar->hide(); - toolbar->add_child( memnew( VSeparator ) ); + toolbar->add_child(memnew(VSeparator)); - menu = memnew( MenuButton ); - menu->get_popup()->add_item(TTR("Load Emission Mask"),MENU_LOAD_EMISSION_MASK); - menu->get_popup()->add_item(TTR("Clear Emission Mask"),MENU_CLEAR_EMISSION_MASK); + menu = memnew(MenuButton); + menu->get_popup()->add_item(TTR("Load Emission Mask"), MENU_LOAD_EMISSION_MASK); + menu->get_popup()->add_item(TTR("Clear Emission Mask"), MENU_CLEAR_EMISSION_MASK); menu->set_text("Particles"); toolbar->add_child(menu); - file = memnew( EditorFileDialog ); + file = memnew(EditorFileDialog); List<String> ext; ImageLoader::get_recognized_extensions(&ext); - for(List<String>::Element *E=ext.front();E;E=E->next()) { - file->add_filter("*."+E->get()+"; "+E->get().to_upper()); + for (List<String>::Element *E = ext.front(); E; E = E->next()) { + file->add_filter("*." + E->get() + "; " + E->get().to_upper()); } file->set_mode(EditorFileDialog::MODE_OPEN_FILE); toolbar->add_child(file); - epoints = memnew( SpinBox ); + epoints = memnew(SpinBox); epoints->set_min(1); epoints->set_max(8192); epoints->set_step(1); epoints->set_value(512); - file->get_vbox()->add_margin_child(TTR("Generated Point Count:"),epoints); + file->get_vbox()->add_margin_child(TTR("Generated Point Count:"), epoints); } -Particles2DEditorPlugin::~Particles2DEditorPlugin() -{ +Particles2DEditorPlugin::~Particles2DEditorPlugin() { } - |