| 8 | } |
| 9 | |
| 10 | void xg::shape::Rect::CreatePath(canvas::CanvasContext &context) const { |
| 11 | context.BeginPath(); |
| 12 | if(radius_ <= XG_EPS) { |
| 13 | if(this->HasRounding()) { |
| 14 | float height = static_cast<float>(size_.height);//height < 0 柱朝上 |
| 15 | float width = static_cast<float>(size_.width); |
| 16 | float x = static_cast<float>(point_.x); |
| 17 | float y = static_cast<float>(point_.y); |
| 18 | if (width >= 0) { |
| 19 | context.MoveTo(x + roundings[2], y); |
| 20 | context.LineTo(x + width - roundings[3], y); |
| 21 | } else { |
| 22 | context.MoveTo(x - roundings[2], y); |
| 23 | context.LineTo(x + width + roundings[3], y); |
| 24 | } |
| 25 | if (height < 0) { |
| 26 | context.QuadraticCurveTo(x + width, y, x + width, y - roundings[3]); |
| 27 | context.LineTo(x + width, y + height + roundings[1]); |
| 28 | }else { |
| 29 | context.QuadraticCurveTo(x + width, y, x + width, y + roundings[3]); |
| 30 | context.LineTo(x + width, y + height - roundings[1]); |
| 31 | } |
| 32 | if (width >= 0) { |
| 33 | context.QuadraticCurveTo(x + width, y + height, x + width - roundings[1], y + height); |
| 34 | context.LineTo(x + roundings[0], y + height); |
| 35 | } else { |
| 36 | context.QuadraticCurveTo(x + width, y + height, x + width + roundings[1], y + height); |
| 37 | context.LineTo(x - roundings[0], y + height); |
| 38 | } |
| 39 | if (height < 0) { |
| 40 | context.QuadraticCurveTo(x, y + height, x, y + height + roundings[0]); |
| 41 | context.LineTo(x, y - roundings[2]); |
| 42 | } else { |
| 43 | context.QuadraticCurveTo(x, y + height, x, y + height - roundings[0]); |
| 44 | context.LineTo(x, y + roundings[2]); |
| 45 | } |
| 46 | if (width >= 0) { |
| 47 | context.QuadraticCurveTo(x, y, x + roundings[2], y); |
| 48 | } else { |
| 49 | context.QuadraticCurveTo(x, y, x - roundings[2], y); |
| 50 | } |
| 51 | } else { |
| 52 | context.Rect(point_.x, point_.y, size_.width, size_.height); |
| 53 | } |
| 54 | context.ClosePath(); |
| 55 | } else { |
| 56 | double unitX = std::cos(startAngle_); |
| 57 | double unitY = std::sin(startAngle_); |
| 58 | context.SetLineDash(this->dash_); |
| 59 | context.MoveTo(unitX * radius0_ + point_.x, unitY * radius0_ + point_.y); |
| 60 | context.LineTo(unitX * radius_ + point_.x, unitY * radius_ + point_.y); |
| 61 | if(fabs(endAngle_ - startAngle_) > 0.0001 || (fabs(startAngle_) <= XG_EPS && fabs(endAngle_) <= XG_EPS)) { |
| 62 | context.Arc(point_.x, point_.y, radius_, startAngle_, endAngle_, false); |
| 63 | context.LineTo(std::cos(endAngle_) * radius0_ + point_.x, std::sin(endAngle_) * radius0_ + point_.y); |
| 64 | if(radius0_ >= XG_EPS) { |
| 65 | context.Arc(point_.x, point_.y, radius0_, endAngle_, startAngle_, true); |
| 66 | } |
| 67 | } |
no test coverage detected