38 |
38 |
39 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } |
39 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } |
40 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } |
40 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } |
41 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
41 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
43 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) LDOBJ_DEFAULTCOLOR (maincolor()) |
43 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) LDOBJ_DEFAULTCOLOR (MainColor()) |
44 #define LDOBJ_DEFAULTCOLOR(V) public: virtual LDColor defaultColor() const override { return (V); } |
44 #define LDOBJ_DEFAULTCOLOR(V) public: virtual LDColor defaultColor() const override { return (V); } |
45 |
45 |
46 #define LDOBJ_CUSTOM_SCEMANTIC public: virtual bool isScemantic() const override |
46 #define LDOBJ_CUSTOM_SCEMANTIC public: virtual bool isScemantic() const override |
47 #define LDOBJ_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return true; } |
47 #define LDOBJ_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return true; } |
48 #define LDOBJ_NON_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return false; } |
48 #define LDOBJ_NON_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return false; } |
216 // |
216 // |
217 // Makes a new LDObject. This makes the shared pointer always use the custom |
217 // Makes a new LDObject. This makes the shared pointer always use the custom |
218 // deleter so that all deletions go through finalDelete(); |
218 // deleter so that all deletions go through finalDelete(); |
219 // |
219 // |
220 template<typename T, typename... Args> |
220 template<typename T, typename... Args> |
221 inline QSharedPointer<T> spawn (Args... args) |
221 inline QSharedPointer<T> LDSpawn (Args... args) |
222 { |
222 { |
223 static_assert (std::is_base_of<LDObject, T>::value, "spawn may only be used with LDObject-derivatives"); |
223 static_assert (std::is_base_of<LDObject, T>::value, |
|
224 "spawn may only be used with LDObject-derivatives"); |
224 LDObjectPtr ptr; |
225 LDObjectPtr ptr; |
225 new T (&ptr, args...); |
226 new T (&ptr, args...); |
226 |
227 |
227 // Set default color. This cannot be done in the c-tor. |
228 // Set default color. Relying on virtual functions, this cannot be done in the c-tor. |
228 if (ptr->isColored()) |
229 if (ptr->isColored()) |
229 ptr->setColor (ptr->defaultColor()); |
230 ptr->setColor (ptr->defaultColor()); |
230 |
231 |
231 return ptr.staticCast<T>(); |
232 return ptr.staticCast<T>(); |
232 } |
233 } |
257 Vertex m_position; |
258 Vertex m_position; |
258 |
259 |
259 public: |
260 public: |
260 LDMatrixObject (LDObjectPtr* selfptr) : |
261 LDMatrixObject (LDObjectPtr* selfptr) : |
261 LDObject (selfptr), |
262 LDObject (selfptr), |
262 m_position (g_origin) {} |
263 m_position (Origin) {} |
263 |
264 |
264 LDMatrixObject (LDObjectPtr* selfptr, const Matrix& transform, const Vertex& pos) : |
265 LDMatrixObject (LDObjectPtr* selfptr, const Matrix& transform, const Vertex& pos) : |
265 LDObject (selfptr), |
266 LDObject (selfptr), |
266 m_transform (transform), |
267 m_transform (transform), |
267 m_position (pos) {} |
268 m_position (pos) {} |
581 PROPERTY (public, int, camera, setCamera, STOCK_WRITE) |
582 PROPERTY (public, int, camera, setCamera, STOCK_WRITE) |
582 PROPERTY (public, int, x, setX, STOCK_WRITE) |
583 PROPERTY (public, int, x, setX, STOCK_WRITE) |
583 PROPERTY (public, int, y, setY, STOCK_WRITE) |
584 PROPERTY (public, int, y, setY, STOCK_WRITE) |
584 PROPERTY (public, int, width, setWidth, STOCK_WRITE) |
585 PROPERTY (public, int, width, setWidth, STOCK_WRITE) |
585 PROPERTY (public, int, height, setHeight, STOCK_WRITE) |
586 PROPERTY (public, int, height, setHeight, STOCK_WRITE) |
586 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE) |
587 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE) |
587 }; |
588 }; |
588 |
589 |
589 using LDOverlayPtr = QSharedPointer<LDOverlay>; |
590 using LDOverlayPtr = QSharedPointer<LDOverlay>; |
590 using LDOverlayWeakPtr = QWeakPointer<LDOverlay>; |
591 using LDOverlayWeakPtr = QWeakPointer<LDOverlay>; |
591 |
592 |
592 // Other common LDraw stuff |
593 // Other common LDraw stuff |
593 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " |
594 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " |
594 "see CAreadme.txt"); |
595 "see CAreadme.txt"); |
595 static const int LowResolution = 16; |
596 |
596 static const int HighResolution = 48; |
597 enum |
|
598 { |
|
599 LowResolution = 16, |
|
600 HighResolution = 48 |
|
601 }; |
597 |
602 |
598 QString PreferredLicenseText(); |
603 QString PreferredLicenseText(); |
599 |
604 |
600 template<typename T> |
605 template<typename T> |
601 inline void DynamicExecute (LDObjectPtr obj, std::function<void (QSharedPointer<T> const&)> func) |
606 inline void DynamicExecute (LDObjectPtr obj, std::function<void (QSharedPointer<T> const&)> func) |