Repository: godotengine/godot
File: editor/plugins/camera_2d_editor_plugin.cpp (C++)

Code before:
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "camera_2d_editor_plugin.h"

#include "canvas_item_editor_plugin.h"
#include "core/config/project_settings.h"
#include "editor/editor_node.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/label.h"
#include "scene/gui/menu_button.h"

void Camera2DEditor::edit(Camera2D *p_camera) {
	if (p_camera == selected_camera) {
		return;
	}
	selected_camera = p_camera;
}

void Camera2DEditor::_menu_option(int p_option) {
	switch (p_option) {
		case MENU_SNAP_LIMITS_TO_VIEWPORT: {
			if (selected_camera == nullptr) {
				break;
			}
			selected_camera->set_limit(SIDE_LEFT, 0);
			selected_camera->set_limit(SIDE_TOP, 0);
			selected_camera->set_limit(SIDE_RIGHT, GLOBAL_GET("display/window/size/viewport_width"));
			selected_camera->set_limit(SIDE_BOTTOM, GLOBAL_GET("display/window/size/viewport_height"));
			break;
		}
		default:
			break;
	}
}

void Camera2DEditor::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED: {
			options->set_button_icon(get_editor_theme_icon(SNAME("Camera2D")));
			options->get_popup()->set_item_icon(MENU_SNAP_LIMITS_TO_VIEWPORT, get_editor_theme_icon(SNAME("Camera2D")));
		} break;
	}

Review comment (suggestion):
```suggestion
```
Not needed if all the method does is assign a single variable.

Code after:
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "camera_2d_editor_plugin.h"

#include "canvas_item_editor_plugin.h"
#include "core/config/project_settings.h"
#include "editor/editor_node.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/themes/editor_scale.h"
#include "scene/2d/camera_2d.h"
#include "scene/gui/label.h"
#include "scene/gui/menu_button.h"

void Camera2DEditor::edit(Camera2D *p_camera) {
	if (p_camera == selected_camera) {
		return;
	}
	selected_camera = p_camera;
}

void Camera2DEditor::_menu_option(int p_option) {
	switch (p_option) {
		case MENU_SNAP_LIMITS_TO_VIEWPORT: {
			EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
			Rect2 prev_rect = selected_camera->get_limit_rect();
			ur->create_action(TTR("Snap the Limits to the Viewport"), UndoRedo::MERGE_DISABLE, selected_camera);
			ur->add_do_method(this, "_snap_limits_to_viewport");
			ur->add_do_reference(selected_camera);
			ur->add_undo_method(this, "_undo_snap_limits_to_viewport", prev_rect);
			ur->commit_action();
		} break;
	}
}

void Camera2DEditor::_snap_limits_to_viewport() {
	selected_camera->set_limit(SIDE_LEFT, 0);
	selected_camera->set_limit(SIDE_TOP, 0);
	selected_camera->set_limit(SIDE_RIGHT, GLOBAL_GET("display/window/size/viewport_width"));
	selected_camera->set_limit(SIDE_BOTTOM, GLOBAL_GET("display/window/size/viewport_height"));
}

void Camera2DEditor::_undo_snap_limits_to_viewport(const Rect2 &p_prev_rect) {