Path: blob/master/editor/scene/gui/margin_container_editor_plugin.cpp
12222 views
/**************************************************************************/1/* margin_container_editor_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "margin_container_editor_plugin.h"3132#include "editor/scene/canvas_item_editor_plugin.h"33#include "editor/themes/editor_scale.h"3435void MarginContainerEditorPlugin::edit(Object *p_object) {36if (margin_container) {37margin_container->disconnect(SNAME("draw"), callable_mp(CanvasItemEditor::get_singleton(), &CanvasItemEditor::update_viewport));38}3940margin_container = Object::cast_to<MarginContainer>(p_object);4142if (margin_container) {43margin_container->connect(SNAME("draw"), callable_mp(CanvasItemEditor::get_singleton(), &CanvasItemEditor::update_viewport));44}45CanvasItemEditor::get_singleton()->update_viewport();46}4748bool MarginContainerEditorPlugin::handles(Object *p_object) const {49return Object::cast_to<MarginContainer>(p_object) != nullptr;50}5152void MarginContainerEditorPlugin::forward_canvas_draw_over_viewport(Control *p_viewport_control) {53if (!margin_container) {54return;55}5657Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * margin_container->get_screen_transform();5859// NOTE: This color is copied from Camera2DEditor::forward_canvas_draw_over_viewport.60// We may want to unify them somehow in the future.61Color border_color = Color(1, 1, 0.25, 0.63);6263int border_width = Math::round(1 * EDSCALE);6465Rect2 rect = margin_container->_edit_get_rect();6667int margin_left = margin_container->get_margin_size(SIDE_LEFT);68int margin_top = margin_container->get_margin_size(SIDE_TOP);69int margin_right = margin_container->get_margin_size(SIDE_RIGHT);70int margin_bottom = margin_container->get_margin_size(SIDE_BOTTOM);7172Vector2 p1, p2;7374// Calculate left margin line.75p1 = xform.xform(rect.position + Vector2(margin_left, margin_top));76p2 = xform.xform(rect.position + Vector2(margin_left, rect.size.y - margin_bottom));77p_viewport_control->draw_line(p1, p2, border_color, border_width);7879// Calculate top margin line.80p1 = xform.xform(rect.position + Vector2(margin_left, margin_top));81p2 = xform.xform(rect.position + Vector2(rect.size.x - margin_right, margin_top));82p_viewport_control->draw_line(p1, p2, border_color, border_width);8384// Calculate right margin line.85p1 = xform.xform(rect.position + Vector2(rect.size.x - margin_right, margin_top));86p2 = xform.xform(rect.position + Vector2(rect.size.x - margin_right, rect.size.y - margin_bottom));87p_viewport_control->draw_line(p1, p2, border_color, border_width);8889// Calculate bottom margin line.90p1 = xform.xform(rect.position + Vector2(margin_left, rect.size.y - margin_bottom));91p2 = xform.xform(rect.position + Vector2(rect.size.x - margin_right, rect.size.y - margin_bottom));92p_viewport_control->draw_line(p1, p2, border_color, border_width);93}949596