EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
watchface_editable_highlight_create(&hi_, WATCHFACE_EDITABLE_SHAPE_TYPE_CIRCLE);
watchface_editable_highlight_set_geometry(hi_, 50, 50, 100, 100);
+ watchface_editable_highlight_set_normalized_geometry(hi_, 0.5, 0.5, 0.3, 0.3);
+
+ double norm_x, norm_y, norm_w, norm_h;
+ watchface_editable_highlight_get_normalized_geometry(
+ hi_, &norm_x, &norm_y, &norm_w, &norm_h);
+ EXPECT_DOUBLE_EQ(norm_x, 0.5);
+ EXPECT_DOUBLE_EQ(norm_y, 0.5);
+ EXPECT_DOUBLE_EQ(norm_w, 0.3);
+ EXPECT_DOUBLE_EQ(norm_h, 0.3);
+
ret = watchface_editable_add_complication(handle, comp_id, comp_, hi_);
EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
ret = watchface_editable_candidates_list_create(&candidates_list_);
watchface_editable_highlight_destroy(hi_);
watchface_editable_highlight_create(&hi_, WATCHFACE_EDITABLE_SHAPE_TYPE_CIRCLE);
watchface_editable_highlight_set_geometry(hi_, 100, 50, 100, 100);
+ watchface_editable_highlight_set_normalized_geometry(hi_, 0.7, 0.7, 0.3, 0.3);
watchface_editable_highlight_set_shape_type(hi_, WATCHFACE_EDITABLE_SHAPE_TYPE_RECT);
bundle* design_element = bundle_create();
bundle_add_str(design_element, "TEST_COLOR", "Blue");
class Geometry {
public:
- Geometry() {
- x_ = 0;
- y_ = 0;
- w_ = 0;
- h_ = 0;
+ Geometry()
+ : x_(0), y_(0), w_(0), h_(0) {
}
Geometry(int x, int y, int w, int h) : x_(x), y_(y), w_(w), h_(h) {
int h_;
};
+ class NormalizedGeometry {
+ public:
+ NormalizedGeometry()
+ : norm_x_(0), norm_y_(0), norm_w_(0), norm_h_(0) {
+ }
+
+ NormalizedGeometry(double norm_x, double norm_y, double norm_w, double norm_h)
+ : norm_x_(norm_x), norm_y_(norm_y), norm_w_(norm_w), norm_h_(norm_h) {
+ }
+
+ NormalizedGeometry(NormalizedGeometry&& info)
+ : norm_x_(info.norm_x_), norm_y_(info.norm_y_),
+ norm_w_(info.norm_w_), norm_h_(info.norm_h_) {
+ }
+
+ NormalizedGeometry(const NormalizedGeometry& info)
+ : norm_x_(info.norm_x_), norm_y_(info.norm_y_),
+ norm_w_(info.norm_w_), norm_h_(info.norm_h_) {
+ }
+
+ NormalizedGeometry& operator = (const NormalizedGeometry& info) {
+ if (this != &info) {
+ norm_x_ = info.GetNormalizedX();
+ norm_y_ = info.GetNormalizedY();
+ norm_w_ = info.GetNormalizedW();
+ norm_h_ = info.GetNormalizedH();
+ }
+ return *this;
+ }
+
+ NormalizedGeometry& operator = (NormalizedGeometry&& info) noexcept {
+ if (this != &info) {
+ norm_x_ = info.GetNormalizedX();
+ norm_y_ = info.GetNormalizedY();
+ norm_w_ = info.GetNormalizedW();
+ norm_h_ = info.GetNormalizedH();
+ }
+ return *this;
+ }
+
+ const double GetNormalizedX() const {
+ return norm_x_;
+ }
+
+ const double GetNormalizedY() const {
+ return norm_y_;
+ }
+
+ const double GetNormalizedW() const {
+ return norm_w_;
+ }
+
+ const double GetNormalizedH() const {
+ return norm_h_;
+ }
+
+ void SetNormalizedX(double x) {
+ norm_x_ = x;
+ }
+
+ void SetNormalizedY(double y) {
+ norm_y_ = y;
+ }
+
+ void SetNormalizedW(double w) {
+ norm_w_ = w;
+ }
+
+ void SetNormalizedH(double h) {
+ norm_h_ = h;
+ }
+
+ private:
+ double norm_x_;
+ double norm_y_;
+ double norm_w_;
+ double norm_h_;
+ };
+
class Highlight {
public:
Highlight() {}
+ Highlight(EditableShapeType shape_type)
+ : geo_(std::move(std::unique_ptr<Geometry>(new Geometry(0, 0, 0, 0)))),
+ norm_geo_(std::move(std::unique_ptr<NormalizedGeometry>(new NormalizedGeometry(0, 0, 0, 0)))),
+ shape_type_(shape_type) {
+ }
+
Highlight(std::unique_ptr<Geometry> geo, EditableShapeType shape_type)
- : geo_(std::move(geo)), shape_type_(shape_type) {
+ : geo_(std::move(geo)),
+ norm_geo_(std::move(std::unique_ptr<NormalizedGeometry>(new NormalizedGeometry(0, 0, 0, 0)))),
+ shape_type_(shape_type) {
}
Highlight(tizen_base::Bundle encoded) {
Highlight(const Highlight& hi) {
geo_ = std::unique_ptr<Geometry>(new Geometry(*hi.geo_));
+ norm_geo_ = std::unique_ptr<NormalizedGeometry>(
+ new NormalizedGeometry(*hi.norm_geo_));
shape_type_ = hi.shape_type_;
}
geo_.get()->SetH(geo.GetH());
}
+ void SetNormalizedGeometry(std::unique_ptr<NormalizedGeometry> geo) {
+ norm_geo_ = std::move(geo);
+ }
+
+ const NormalizedGeometry* GetNormalizedGeometry() const {
+ return norm_geo_.get();
+ }
+
+
void Encode(tizen_base::Bundle* encoded) {
encoded->Add("SHAPE_TYPE", std::to_string(shape_type_));
- if (geo_ == nullptr)
- return;
+ if (geo_ != nullptr) {
+ encoded->Add("GEO_X", std::to_string(geo_->GetX()));
+ encoded->Add("GEO_Y", std::to_string(geo_->GetY()));
+ encoded->Add("GEO_W", std::to_string(geo_->GetW()));
+ encoded->Add("GEO_H", std::to_string(geo_->GetH()));
+ }
- encoded->Add("GEO_X", std::to_string(geo_->GetX()));
- encoded->Add("GEO_Y", std::to_string(geo_->GetY()));
- encoded->Add("GEO_W", std::to_string(geo_->GetW()));
- encoded->Add("GEO_H", std::to_string(geo_->GetH()));
+ if (norm_geo_ != nullptr) {
+ encoded->Add("GEO_NORMALIZED_X",
+ std::to_string(norm_geo_->GetNormalizedX()));
+ encoded->Add("GEO_NORMALIZED_Y",
+ std::to_string(norm_geo_->GetNormalizedY()));
+ encoded->Add("GEO_NORMALIZED_W",
+ std::to_string(norm_geo_->GetNormalizedW()));
+ encoded->Add("GEO_NORMALIZED_H",
+ std::to_string(norm_geo_->GetNormalizedH()));
+ }
}
void Decode(tizen_base::Bundle encoded) {
shape_type_ = (EditableShapeType)stoi(shape_str);
std::string x_str = encoded.GetString("GEO_X");
- if (x_str.empty())
- return;
-
- std::string y_str = encoded.GetString("GEO_Y");
- std::string w_str = encoded.GetString("GEO_W");
- std::string h_str = encoded.GetString("GEO_H");
-
- geo_ = std::unique_ptr<Geometry>(new Geometry(
+ if (!x_str.empty()) {
+ std::string y_str = encoded.GetString("GEO_Y");
+ std::string w_str = encoded.GetString("GEO_W");
+ std::string h_str = encoded.GetString("GEO_H");
+ geo_ = std::unique_ptr<Geometry>(new Geometry(
stoi(x_str), stoi(y_str), stoi(w_str), stoi(h_str)));
+ }
+
+ std::string norm_x_str = encoded.GetString("GEO_NORMALIZED_X");
+ if (!norm_x_str.empty()) {
+ std::string norm_y_str = encoded.GetString("GEO_NORMALIZED_Y");
+ std::string norm_w_str = encoded.GetString("GEO_NORMALIZED_W");
+ std::string norm_h_str = encoded.GetString("GEO_NORMALIZED_H");
+ norm_geo_ = std::unique_ptr<NormalizedGeometry>(new NormalizedGeometry(
+ stof(norm_x_str), stof(norm_y_str), stof(norm_w_str), stof(norm_h_str)));
+ }
}
const EditableShapeType GetShapeType() const {
private:
std::unique_ptr<Geometry> geo_;
+ std::unique_ptr<NormalizedGeometry> norm_geo_;
EditableShapeType shape_type_ = Circle;
};
virtual ~IEditable() = default;
}
h = (watchface_editable_highlight_h)SharedHandle<IEditable::Highlight>::Make(
- make_shared<IEditable::Highlight>(
- unique_ptr<IEditable::Geometry>(new IEditable::Geometry(-1, -1, -1, -1)),
- (IEditable::EditableShapeType)shape)
+ make_shared<IEditable::Highlight>((IEditable::EditableShapeType)shape)
);
*handle = h;
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
+extern "C" EXPORT_API int watchface_editable_highlight_set_normalized_geometry(
+ watchface_editable_highlight_h handle, double x, double y, double w, double h) {
+
+ if (!watchface_complication::util::CheckWatchFeatureEnabled())
+ return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+ if (handle == nullptr || x < 0.0 || y < 0.0 || w < 0.0 || h < 0.0 ||
+ x > 1.0 || y > 1.0 || w > 1.0 || h > 1.0) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ shared_ptr<IEditable::Highlight> ptr =
+ ((SharedHandle<IEditable::Highlight>*)handle)->GetPtr();
+ ptr->SetNormalizedGeometry(
+ unique_ptr<IEditable::NormalizedGeometry>(
+ new IEditable::NormalizedGeometry(x, y, w, h)));
+
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_editable_highlight_get_normalized_geometry(
+ watchface_editable_highlight_h handle, double *x, double *y, double *w, double *h) {
+ if (!watchface_complication::util::CheckWatchFeatureEnabled())
+ return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+ if (handle == nullptr || x == nullptr || y == nullptr || w == nullptr || h == nullptr) {
+ LOGE("Invalid param");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ shared_ptr<IEditable::Highlight> ptr =
+ ((SharedHandle<IEditable::Highlight>*)handle)->GetPtr();
+ *x = ptr->GetNormalizedGeometry()->GetNormalizedX();
+ *y = ptr->GetNormalizedGeometry()->GetNormalizedY();
+ *w = ptr->GetNormalizedGeometry()->GetNormalizedW();
+ *h = ptr->GetNormalizedGeometry()->GetNormalizedH();
+
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
extern "C" EXPORT_API int watchface_editable_highlight_set_geometry(
watchface_editable_highlight_h handle, int x, int y, int w, int h) {
if (!watchface_complication::util::CheckWatchFeatureEnabled())