*
* @retval Result::Success When succeed.
* @retval Result::FailedAllocation An internal error with a memory allocation for an object to be dashed.
- * @retval Result::InvalidArguments In case a @c nullptr is passed as the @p dashPattern,
- * the given length of the array is less than two or any of the @p dashPattern values is zero or less.
+ * @retval Result::InvalidArguments In case that either @p dashPattern is @c nullptr or @p cnt is zero.
*
* @note If any of the dash pattern values is zero, this function has no effect.
+ * @note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt.
+ * @warning @p cnt must be greater than 1 if the dash pattern is valid.
*/
Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
{
- if (cnt < 2 || !dashPattern) return Result::InvalidArguments;
+ if ((cnt == 1) || (!dashPattern && cnt > 0) || (dashPattern && cnt == 0)) {
+ return Result::InvalidArguments;
+ }
for (uint32_t i = 0; i < cnt; i++)
if (dashPattern[i] < FLT_EPSILON) return Result::InvalidArguments;
bool strokeDash(const float* pattern, uint32_t cnt)
{
- if (!stroke) stroke = new ShapeStroke();
- if (!stroke) return false;
-
- if (stroke->dashCnt != cnt) {
- if (stroke->dashPattern) free(stroke->dashPattern);
+ //Reset dash
+ if (!pattern && cnt == 0) {
+ free(stroke->dashPattern);
stroke->dashPattern = nullptr;
+ } else {
+ if (!stroke) stroke = new ShapeStroke();
+ if (!stroke) return false;
+
+ if (stroke->dashCnt != cnt) {
+ free(stroke->dashPattern);
+ stroke->dashPattern = nullptr;
+ }
+ if (!stroke->dashPattern) {
+ stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
+ if (!stroke->dashPattern) return false;
+ }
+ for (uint32_t i = 0; i < cnt; ++i) {
+ stroke->dashPattern[i] = pattern[i];
+ }
}
-
- if (!stroke->dashPattern) {
- stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
- if (!stroke->dashPattern) return false;
- }
-
- for (uint32_t i = 0; i < cnt; ++i)
- stroke->dashPattern[i] = pattern[i];
-
stroke->dashCnt = cnt;
flag |= RenderUpdateFlag::Stroke;