1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #ifndef PROPERTY_H 10 #define PROPERTY_H 11 12 #include <limits.h> 13 14 #include <Archivable.h> 15 #include <String.h> 16 #include <TypeConstants.h> 17 18 class PropertyAnimator; 19 20 // Property 21 class Property : public BArchivable { 22 // TODO: actually use BArchivable! 23 public: 24 Property(uint32 identifier); 25 Property(const Property& other); 26 Property(BMessage* archive); 27 virtual ~Property(); 28 29 virtual Property* Clone() const = 0; 30 31 virtual type_code Type() const = 0; 32 33 virtual bool SetValue(const char* value) = 0; 34 virtual bool SetValue(const Property* other) = 0; 35 virtual void GetValue(BString& string) = 0; 36 37 // animation 38 virtual bool InterpolateTo(const Property* other, 39 float scale); 40 41 inline uint32 Identifier() const 42 { return fIdentifier; } 43 44 void SetEditable(bool editable); 45 inline bool IsEditable() const 46 { return fEditable; } 47 48 private: 49 uint32 fIdentifier; 50 bool fEditable; 51 }; 52 53 // IntProperty 54 class IntProperty : public Property { 55 public: 56 IntProperty(uint32 identifier, 57 int32 value = 0, 58 int32 min = LONG_MIN, 59 int32 max = LONG_MAX); 60 IntProperty(const IntProperty& other); 61 virtual ~IntProperty(); 62 63 virtual Property* Clone() const; 64 65 virtual type_code Type() const 66 { return B_INT32_TYPE; } 67 68 virtual bool SetValue(const char* value); 69 virtual bool SetValue(const Property* other); 70 virtual void GetValue(BString& string); 71 72 virtual bool InterpolateTo(const Property* other, 73 float scale); 74 75 // IntProperty 76 bool SetValue(int32 value); 77 78 inline int32 Value() const 79 { return fValue; } 80 inline int32 Min() const 81 { return fMin; } 82 inline int32 Max() const 83 { return fMax; } 84 85 private: 86 int32 fValue; 87 int32 fMin; 88 int32 fMax; 89 }; 90 91 // FloatProperty 92 class FloatProperty : public Property { 93 public: 94 FloatProperty(uint32 identifier, 95 float value = 0.0, 96 float min = -1000000.0, 97 float max = 1000000.0); 98 FloatProperty(const FloatProperty& other); 99 virtual ~FloatProperty(); 100 101 virtual Property* Clone() const; 102 103 virtual type_code Type() const 104 { return B_FLOAT_TYPE; } 105 106 virtual bool SetValue(const char* value); 107 virtual bool SetValue(const Property* other); 108 virtual void GetValue(BString& string); 109 110 virtual bool InterpolateTo(const Property* other, 111 float scale); 112 113 // FloatProperty 114 bool SetValue(float value); 115 116 inline float Value() const 117 { return fValue; } 118 inline float Min() const 119 { return fMin; } 120 inline float Max() const 121 { return fMax; } 122 123 private: 124 float fValue; 125 float fMin; 126 float fMax; 127 }; 128 129 // UInt8Property 130 class UInt8Property : public Property { 131 public: 132 UInt8Property(uint32 identifier, 133 uint8 value = 255); 134 UInt8Property(const UInt8Property& other); 135 virtual ~UInt8Property(); 136 137 virtual Property* Clone() const; 138 139 virtual type_code Type() const 140 { return B_INT8_TYPE; } 141 142 virtual bool SetValue(const char* value); 143 virtual bool SetValue(const Property* other); 144 virtual void GetValue(BString& string); 145 146 virtual bool InterpolateTo(const Property* other, 147 float scale); 148 149 // UInt8Property 150 bool SetValue(uint8 value); 151 152 inline uint8 Value() const 153 { return fValue; } 154 155 private: 156 uint8 fValue; 157 }; 158 159 // BoolProperty 160 class BoolProperty : public Property { 161 public: 162 BoolProperty(uint32 identifier, 163 bool value = false); 164 BoolProperty(const BoolProperty& other); 165 virtual ~BoolProperty(); 166 167 virtual Property* Clone() const; 168 169 virtual type_code Type() const 170 { return B_BOOL_TYPE; } 171 172 virtual bool SetValue(const char* value); 173 virtual bool SetValue(const Property* other); 174 virtual void GetValue(BString& string); 175 176 virtual bool InterpolateTo(const Property* other, 177 float scale); 178 179 // BoolProperty 180 bool SetValue(bool value); 181 182 inline bool Value() const 183 { return fValue; } 184 185 private: 186 bool fValue; 187 }; 188 189 // StringProperty 190 class StringProperty : public Property { 191 public: 192 StringProperty(uint32 identifier, 193 const char* string); 194 StringProperty(const StringProperty& other); 195 virtual ~StringProperty(); 196 197 virtual Property* Clone() const; 198 199 virtual type_code Type() const 200 { return B_STRING_TYPE; } 201 202 virtual bool SetValue(const char* value); 203 virtual bool SetValue(const Property* other); 204 virtual void GetValue(BString& string); 205 206 // StringProperty 207 inline const char* Value() const 208 { return fValue.String(); } 209 210 private: 211 BString fValue; 212 }; 213 214 #endif // PROPERTY_H 215