11// SPDX-License-Identifier: Apache-2.0
22
33#include < scratchcpp/costume.h>
4+ #include < scratchcpp/scratchconfiguration.h>
45
56#include " costume_p.h"
67
@@ -11,6 +12,9 @@ Costume::Costume(const std::string &name, const std::string &id, const std::stri
1112 Asset(name, id, format),
1213 impl(spimpl::make_unique_impl<CostumePrivate>())
1314{
15+ // NOTE: image is always initialized, so there's no need for null checks
16+ impl->image = ScratchConfiguration::createImageFormat (format);
17+ impl->updateImage ();
1418}
1519
1620/* ! Returns the reciprocal of the costume scaling factor for bitmap costumes. */
@@ -49,6 +53,56 @@ void Costume::setRotationCenterY(int newRotationCenterY)
4953 impl->rotationCenterY = newRotationCenterY;
5054}
5155
56+ /* ! Returns the costume width. */
57+ unsigned int Costume::width () const
58+ {
59+ return impl->image ->width () * impl->scale ;
60+ }
61+
62+ /* ! Returns the costume height. */
63+ unsigned int Costume::height () const
64+ {
65+ return impl->image ->height () * impl->scale ;
66+ }
67+
68+ /* ! Returns the image scale. */
69+ double Costume::scale () const
70+ {
71+ return impl->scale ;
72+ }
73+
74+ /* ! Sets the image scale (this is automatically set by the sprite). */
75+ void Costume::setScale (double scale)
76+ {
77+ if (impl->scale == scale)
78+ return ;
79+
80+ impl->scale = scale;
81+ impl->updateImage ();
82+ }
83+
84+ /* ! Returns true if the costume image is mirrored horizontally. */
85+ bool Costume::mirrorHorizontally () const
86+ {
87+ return impl->mirrorHorizontally ;
88+ }
89+
90+ /* ! Sets whether the costume image is mirrored horizontally (this is automatically set by the sprite). */
91+ void Costume::setMirrorHorizontally (bool mirror)
92+ {
93+ if (impl->mirrorHorizontally == mirror)
94+ return ;
95+
96+ impl->mirrorHorizontally = mirror;
97+ impl->updateImage ();
98+ }
99+
100+ /* ! Returns the bitmap of the costume (an array of pixel rows). */
101+ Rgb **Costume::bitmap () const
102+ {
103+ return impl->bitmap ;
104+ }
105+
52106/* !
53107 * Returns the Broadcast linked with this costume.
54108 * \note This is used by the "switch backdrop to and wait" block.
@@ -57,3 +111,10 @@ Broadcast *Costume::broadcast()
57111{
58112 return &impl->broadcast ;
59113}
114+
115+ void Costume::processData (const char *data)
116+ {
117+ impl->image ->setData (data);
118+ impl->freeImage ();
119+ impl->updateImage ();
120+ }
0 commit comments