File indexing completed on 2025-02-02 04:11:07
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "rect.hpp" 0008 0009 GLAXNIMATE_OBJECT_IMPL(glaxnimate::model::Rect) 0010 0011 glaxnimate::math::bezier::Bezier glaxnimate::model::Rect::to_bezier(model::FrameTime t) const 0012 { 0013 math::bezier::Bezier bezier; 0014 QRectF bb = local_bounding_rect(t); 0015 float rounded = this->rounded.get_at(t); 0016 float max_r = std::min(bb.width()/2, bb.height()/2); 0017 if ( rounded > max_r ) 0018 rounded = max_r; 0019 0020 if ( rounded == 0 && !this->rounded.animated() ) 0021 { 0022 bezier.add_point(bb.topRight()); 0023 bezier.add_point(bb.bottomRight()); 0024 bezier.add_point(bb.bottomLeft()); 0025 bezier.add_point(bb.topLeft()); 0026 } 0027 else 0028 { 0029 QPointF hh(rounded/2, 0); 0030 QPointF vh(0, rounded/2); 0031 QPointF hd(rounded, 0); 0032 QPointF vd(0, rounded); 0033 bezier.add_point(bb.topRight()+vd, -vh); 0034 bezier.add_point(bb.bottomRight()-vd, {0,0}, vh); 0035 bezier.add_point(bb.bottomRight()-hd, hh); 0036 bezier.add_point(bb.bottomLeft()+hd, {0,0}, -hh); 0037 bezier.add_point(bb.bottomLeft()-vd, vh); 0038 bezier.add_point(bb.topLeft()+vd, {0,0}, -vh); 0039 bezier.add_point(bb.topLeft()+hd, -hh); 0040 bezier.add_point(bb.topRight()-hd, {0,0}, hh); 0041 } 0042 0043 bezier.close(); 0044 0045 if ( reversed.get() ) 0046 bezier.reverse(); 0047 0048 return bezier; 0049 }