------------------------------------------------------------------------------
| 2183 | |
| 2184 | //------------------------------------------------------------------------------ |
| 2185 | void vtkSVGContextDevice2D::DrawLineGradient(const vtkVector2f& p1, const vtkColor4ub& c1, |
| 2186 | const vtkVector2f& p2, const vtkColor4ub& c2, bool useAlpha) |
| 2187 | { |
| 2188 | const vtkColor4ub aveColor = { static_cast<unsigned char>(static_cast<int>(c1[0] + c2[0]) / 2), |
| 2189 | static_cast<unsigned char>(static_cast<int>(c1[1] + c2[1]) / 2), |
| 2190 | static_cast<unsigned char>(static_cast<int>(c1[2] + c2[2]) / 2), |
| 2191 | static_cast<unsigned char>(static_cast<int>(c1[3] + c2[3]) / 2) }; |
| 2192 | |
| 2193 | // If the colors are more or less the same, go ahead and draw this segment. |
| 2194 | // Same if the segment is small enough to fit on a single pixel. |
| 2195 | if (this->LengthLessThanTolerance(p1, p2) || this->ColorsAreClose(c1, c2, useAlpha)) |
| 2196 | { |
| 2197 | YConverter y(this->CanvasHeight); |
| 2198 | vtkNew<vtkXMLDataElement> line; |
| 2199 | this->ActiveNode->AddNestedElement(line); |
| 2200 | line->SetName("line"); |
| 2201 | line->SetFloatAttribute("x1", p1[0]); |
| 2202 | line->SetFloatAttribute("y1", y(p1[1])); |
| 2203 | line->SetFloatAttribute("x2", p2[0]); |
| 2204 | line->SetFloatAttribute("y2", y(p2[1])); |
| 2205 | this->ApplyPenWidthToNode(line); |
| 2206 | line->SetAttribute("stroke", ColorToString(aveColor.GetData()).c_str()); |
| 2207 | if (useAlpha && aveColor[3] != 255) |
| 2208 | { |
| 2209 | line->SetFloatAttribute("stroke-opacity", aveColor[3] / 255.f); |
| 2210 | } |
| 2211 | // FIXME: Disable gradient stipple for now, we'd need to account for offsets |
| 2212 | // this->ApplyPenStippleToNode(node); |
| 2213 | |
| 2214 | return; |
| 2215 | } |
| 2216 | |
| 2217 | // Otherwise, subdivide into two more line segments: |
| 2218 | const vtkVector2f avePos = (p1 + p2) * 0.5; |
| 2219 | |
| 2220 | this->DrawLineGradient(p1, c1, avePos, aveColor, useAlpha); |
| 2221 | this->DrawLineGradient(avePos, aveColor, p2, c2, useAlpha); |
| 2222 | } |
| 2223 | |
| 2224 | //------------------------------------------------------------------------------ |
| 2225 | void vtkSVGContextDevice2D::DrawTriangleGradient(const vtkVector2f& p1, const vtkColor4ub& c1, |
no test coverage detected