1 /* 2 * Copyright 2006, 2023, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 * Zardshard 8 */ 9 10 #include "PathSourceShape.h" 11 12 #include <new> 13 14 #include <agg_bounding_rect.h> 15 #include <Message.h> 16 17 #ifdef ICON_O_MATIC 18 # include "CommonPropertyIDs.h" 19 # include "Property.h" 20 # include "PropertyObject.h" 21 #endif // ICON_O_MATIC 22 #include "Style.h" 23 24 using std::nothrow; 25 26 27 PathSourceShape::PathSourceShape(::Style* style) 28 : Shape(style), 29 30 fMinVisibilityScale(0.0), 31 fMaxVisibilityScale(4.0) 32 { 33 } 34 35 36 PathSourceShape::PathSourceShape(const PathSourceShape& other) 37 : Shape(other), 38 39 fMinVisibilityScale(other.fMinVisibilityScale), 40 fMaxVisibilityScale(other.fMaxVisibilityScale) 41 { 42 } 43 44 45 PathSourceShape::~PathSourceShape() 46 { 47 } 48 49 50 // #pragma mark - 51 52 53 status_t 54 PathSourceShape::Unarchive(BMessage* archive) 55 { 56 Shape::Unarchive(archive); 57 58 // min visibility scale 59 if (archive->FindFloat("min visibility scale", &fMinVisibilityScale) < B_OK) 60 fMinVisibilityScale = 0.0; 61 62 // max visibility scale 63 if (archive->FindFloat("max visibility scale", &fMaxVisibilityScale) < B_OK) 64 fMaxVisibilityScale = 4.0; 65 66 if (fMinVisibilityScale < 0.0) 67 fMinVisibilityScale = 0.0; 68 if (fMinVisibilityScale > 4.0) 69 fMinVisibilityScale = 4.0; 70 if (fMaxVisibilityScale < 0.0) 71 fMaxVisibilityScale = 0.0; 72 if (fMaxVisibilityScale > 4.0) 73 fMaxVisibilityScale = 4.0; 74 75 return B_OK; 76 } 77 78 79 #ifdef ICON_O_MATIC 80 status_t 81 PathSourceShape::Archive(BMessage* into, bool deep) const 82 { 83 status_t ret = Shape::Archive(into, deep); 84 85 // min visibility scale 86 if (ret == B_OK) 87 ret = into->AddFloat("min visibility scale", fMinVisibilityScale); 88 89 // max visibility scale 90 if (ret == B_OK) 91 ret = into->AddFloat("max visibility scale", fMaxVisibilityScale); 92 93 return ret; 94 } 95 96 97 PropertyObject* 98 PathSourceShape::MakePropertyObject() const 99 { 100 PropertyObject* object = Shape::MakePropertyObject(); 101 if (object == NULL) 102 return NULL; 103 104 // object->AddProperty(new BoolProperty(PROPERTY_HINTING, fHinting)); 105 106 object->AddProperty(new FloatProperty(PROPERTY_MIN_VISIBILITY_SCALE, 107 fMinVisibilityScale, 0, 4)); 108 109 object->AddProperty(new FloatProperty(PROPERTY_MAX_VISIBILITY_SCALE, 110 fMaxVisibilityScale, 0, 4)); 111 112 return object; 113 } 114 115 116 bool 117 PathSourceShape::SetToPropertyObject(const PropertyObject* object) 118 { 119 AutoNotificationSuspender _(this); 120 Shape::SetToPropertyObject(object); 121 122 // hinting 123 // SetHinting(object->Value(PROPERTY_HINTING, fHinting)); 124 125 // min visibility scale 126 SetMinVisibilityScale(object->Value(PROPERTY_MIN_VISIBILITY_SCALE, fMinVisibilityScale)); 127 128 // max visibility scale 129 SetMaxVisibilityScale(object->Value(PROPERTY_MAX_VISIBILITY_SCALE, fMaxVisibilityScale)); 130 131 return HasPendingNotifications(); 132 } 133 #endif // ICON_O_MATIC 134 135 136 // #pragma mark - 137 138 139 status_t 140 PathSourceShape::InitCheck() const 141 { 142 return Shape::InitCheck(); 143 } 144 145 146 // #pragma mark - 147 148 149 void 150 PathSourceShape::SetMinVisibilityScale(float scale) 151 { 152 if (fMinVisibilityScale == scale) 153 return; 154 155 fMinVisibilityScale = scale; 156 Notify(); 157 } 158 159 160 void 161 PathSourceShape::SetMaxVisibilityScale(float scale) 162 { 163 if (fMaxVisibilityScale == scale) 164 return; 165 166 fMaxVisibilityScale = scale; 167 Notify(); 168 } 169 170 171 bool 172 PathSourceShape::Visible(float scale) const 173 { 174 return scale >= MinVisibilityScale() 175 && (scale <= MaxVisibilityScale() || MaxVisibilityScale() >= 4.0f); 176 } 177 178