Skip to content

Commit a6b220d

Browse files
committed
Add property setters for OfxRect and OfxPoint
Signed-off-by: Gary Oberbrunner <[email protected]>
1 parent bb265d4 commit a6b220d

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

openfx-cpp/include/openfx/ofxPropsAccess.h

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <math.h>
7+
#include <ofxCore.h>
78

89
#include <array>
910
#include <cassert>
@@ -13,7 +14,6 @@
1314
#include <type_traits>
1415
#include <vector>
1516

16-
#include <ofxCore.h>
1717
#include "ofxExceptions.h"
1818
#include "ofxLog.h"
1919
#include "ofxPropsMetadata.h"
@@ -506,6 +506,62 @@ class PropertyAccessor {
506506
return *this;
507507
}
508508

509+
// For 2-d (PointD) single-type properties
510+
template <PropId id,
511+
std::enable_if_t<properties::PropTraits<id>::def.dimension == 2 &&
512+
!properties::PropTraits<id>::is_multitype &&
513+
std::is_same_v<typename properties::PropTraits<id>::type, double>,
514+
int> = 0>
515+
PropertyAccessor &set(OfxPointD values, bool error_if_missing = true) {
516+
assert(propset_ != nullptr);
517+
this->template set<id>(values.x, 0, error_if_missing);
518+
this->template set<id>(values.y, 1, error_if_missing);
519+
return *this;
520+
}
521+
522+
// For 2-d (PointI) single-type properties
523+
template <PropId id,
524+
std::enable_if_t<properties::PropTraits<id>::def.dimension == 2 &&
525+
!properties::PropTraits<id>::is_multitype &&
526+
std::is_same_v<typename properties::PropTraits<id>::type, double>,
527+
int> = 0>
528+
PropertyAccessor &set(OfxPointI values, bool error_if_missing = true) {
529+
assert(propset_ != nullptr);
530+
this->template set<id>(values.x, 0, error_if_missing);
531+
this->template set<id>(values.y, 1, error_if_missing);
532+
return *this;
533+
}
534+
535+
// For 4-d (RectD) single-type properties
536+
template <PropId id,
537+
std::enable_if_t<properties::PropTraits<id>::def.dimension == 4 &&
538+
!properties::PropTraits<id>::is_multitype &&
539+
std::is_same_v<typename properties::PropTraits<id>::type, double>,
540+
int> = 0>
541+
PropertyAccessor &set(OfxRectD values, bool error_if_missing = true) {
542+
assert(propset_ != nullptr);
543+
this->template set<id>(values.x1, 0, error_if_missing);
544+
this->template set<id>(values.y1, 1, error_if_missing);
545+
this->template set<id>(values.x2, 2, error_if_missing);
546+
this->template set<id>(values.y2, 3, error_if_missing);
547+
return *this;
548+
}
549+
550+
// For 4-d (RectI) single-type properties
551+
template <PropId id,
552+
std::enable_if_t<properties::PropTraits<id>::def.dimension == 4 &&
553+
!properties::PropTraits<id>::is_multitype &&
554+
std::is_same_v<typename properties::PropTraits<id>::type, double>,
555+
int> = 0>
556+
PropertyAccessor &set(OfxRectI values, bool error_if_missing = true) {
557+
assert(propset_ != nullptr);
558+
this->template set<id>(values.x1, 0, error_if_missing);
559+
this->template set<id>(values.y1, 1, error_if_missing);
560+
this->template set<id>(values.x2, 2, error_if_missing);
561+
this->template set<id>(values.y2, 3, error_if_missing);
562+
return *this;
563+
}
564+
509565
// For multi-type properties - require explicit ElementType
510566
template <PropId id, typename ElementType>
511567
PropertyAccessor &setAllTyped(const std::initializer_list<ElementType> &values,

0 commit comments

Comments
 (0)