CUGL 1.3
Cornell University Game Library
CUScaleAction.h
1 //
2 // CUScaleAction.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for the scaling actions. Scaling can specified
6 // as either the final magnification or multiplicative factor.
7 //
8 // These classes use our standard shared-pointer architecture.
9 //
10 // 1. The constructor does not perform any initialization; it just sets all
11 // attributes to their defaults.
12 //
13 // 2. All initialization takes place via init methods, which can fail if an
14 // object is initialized more than once.
15 //
16 // 3. All allocation takes place via static constructors which return a shared
17 // pointer.
18 //
19 // CUGL MIT License:
20 // This software is provided 'as-is', without any express or implied
21 // warranty. In no event will the authors be held liable for any damages
22 // arising from the use of this software.
23 //
24 // Permission is granted to anyone to use this software for any purpose,
25 // including commercial applications, and to alter it and redistribute it
26 // freely, subject to the following restrictions:
27 //
28 // 1. The origin of this software must not be misrepresented; you must not
29 // claim that you wrote the original software. If you use this software
30 // in a product, an acknowledgment in the product documentation would be
31 // appreciated but is not required.
32 //
33 // 2. Altered source versions must be plainly marked as such, and must not
34 // be misrepresented as being the original software.
35 //
36 // 3. This notice may not be removed or altered from any source distribution.
37 //
38 // Author: Sophie Huang and Walker White
39 // Version: 3/12/17
40 //
41 #ifndef __CU_SCALE_ACTION_H__
42 #define __CU_SCALE_ACTION_H__
43 
44 #include "CUAction.h"
45 
46 namespace cugl {
47 
48 #pragma mark -
49 #pragma mark ScaleBy
50 
65 class ScaleBy : public Action {
66 protected:
69 
70 public:
71 #pragma mark Constructors
72 
79 
83  ~ScaleBy() { dispose(); }
84 
90  void dispose() { _delta = Vec2::ONE; }
91 
99  bool init() {
100  return init(Vec2(1.0, 1.0), 0.0f);
101  }
102 
113  bool init(const Vec2& factor) {
114  return init(factor,0.0f);
115  }
116 
129  bool init(const Vec2& factor, float time);
130 
131 #pragma mark Static Constructors
132 
139  static std::shared_ptr<ScaleBy> alloc() {
140  std::shared_ptr<ScaleBy> result = std::make_shared<ScaleBy>();
141  return (result->init() ? result : nullptr);
142  }
143 
154  static std::shared_ptr<ScaleBy> alloc(const Vec2& factor) {
155  std::shared_ptr<ScaleBy> result = std::make_shared<ScaleBy>();
156  return (result->init(factor) ? result : nullptr);
157  }
158 
171  static std::shared_ptr<ScaleBy> alloc(const Vec2& factor, float time) {
172  std::shared_ptr<ScaleBy> result = std::make_shared<ScaleBy>();
173  return (result->init(factor,time) ? result : nullptr);
174  }
175 
176 #pragma mark Attributes
177 
185  const Vec2& getFactor() const { return _delta; }
186 
195  void setFactor(const Vec2& factor) { _delta = factor; }
196 
197 
198 #pragma mark Animation Methods
199 
204  virtual std::shared_ptr<Action> clone() override;
205 
215  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
216 
227  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
228 
229 #pragma mark Debugging Methods
230 
240  virtual std::string toString(bool verbose = false) const override;
241 };
242 
243 
244 #pragma mark -
245 
259 class ScaleTo : public Action {
260 protected:
263 
264 public:
265 #pragma mark Constructors
266 
273 
277  ~ScaleTo() { dispose(); }
278 
284  void dispose() { _scale = Vec2::ONE; }
285 
293  bool init() {
294  return init(Vec2(1.0, 1.0), 0.0f);
295  }
296 
306  bool init(const Vec2& scale) {
307  return init(scale,0.0f);
308  }
309 
320  bool init(const Vec2& scale, float time);
321 
322 #pragma mark Static Constructors
323 
330  static std::shared_ptr<ScaleTo> alloc() {
331  std::shared_ptr<ScaleTo> result = std::make_shared<ScaleTo>();
332  return (result->init() ? result : nullptr);
333  }
334 
344  static std::shared_ptr<ScaleTo> alloc(const Vec2& scale) {
345  std::shared_ptr<ScaleTo> result = std::make_shared<ScaleTo>();
346  return (result->init(scale) ? result : nullptr);
347  }
348 
359  static std::shared_ptr<ScaleTo> alloc(const Vec2& scale, float time) {
360  std::shared_ptr<ScaleTo> result = std::make_shared<ScaleTo>();
361  return (result->init(scale, time) ? result : nullptr);
362  }
363 
364 #pragma mark Attributes
365 
373  const Vec2& getScale() const { return _scale; }
374 
383  void setScale(const Vec2& scale) { _scale = scale; }
384 
385 #pragma mark Animation Methods
386 
391  virtual std::shared_ptr<Action> clone() override;
392 
402  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
403 
414  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
415 
416 #pragma mark Debugging Methods
417 
427  virtual std::string toString(bool verbose = false) const override;
428 };
429 
430 }
431 #endif /* __CU_SCALE_ACTION_H__ */
cugl::ScaleBy::dispose
void dispose()
Definition: CUScaleAction.h:90
cugl::ScaleTo::alloc
static std::shared_ptr< ScaleTo > alloc(const Vec2 &scale, float time)
Definition: CUScaleAction.h:359
cugl::Action
Definition: CUAction.h:70
cugl::ScaleBy::init
bool init()
Definition: CUScaleAction.h:99
cugl::ScaleBy::init
bool init(const Vec2 &factor)
Definition: CUScaleAction.h:113
cugl::ScaleTo::_scale
Vec2 _scale
Definition: CUScaleAction.h:262
cugl::ScaleBy::~ScaleBy
~ScaleBy()
Definition: CUScaleAction.h:83
cugl::ScaleTo::~ScaleTo
~ScaleTo()
Definition: CUScaleAction.h:277
cugl::ScaleBy::_delta
Vec2 _delta
Definition: CUScaleAction.h:68
cugl::Vec2::ONE
static const Vec2 ONE
Definition: CUVec2.h:73
cugl::ScaleTo::ScaleTo
ScaleTo()
Definition: CUScaleAction.h:272
cugl::ScaleBy::getFactor
const Vec2 & getFactor() const
Definition: CUScaleAction.h:185
cugl::ScaleTo::setScale
void setScale(const Vec2 &scale)
Definition: CUScaleAction.h:383
cugl::ScaleTo::init
bool init()
Definition: CUScaleAction.h:293
cugl::ScaleTo::load
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
cugl::ScaleBy::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::ScaleBy::ScaleBy
ScaleBy()
Definition: CUScaleAction.h:78
cugl::ScaleTo::alloc
static std::shared_ptr< ScaleTo > alloc()
Definition: CUScaleAction.h:330
cugl::ScaleBy::load
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
cugl::ScaleBy::alloc
static std::shared_ptr< ScaleBy > alloc(const Vec2 &factor)
Definition: CUScaleAction.h:154
cugl::Vec2
Definition: CUVec2.h:61
cugl::ScaleBy::alloc
static std::shared_ptr< ScaleBy > alloc(const Vec2 &factor, float time)
Definition: CUScaleAction.h:171
cugl::ScaleTo::toString
virtual std::string toString(bool verbose=false) const override
cugl::ScaleBy::toString
virtual std::string toString(bool verbose=false) const override
cugl::ScaleTo::clone
virtual std::shared_ptr< Action > clone() override
cugl::ScaleBy::alloc
static std::shared_ptr< ScaleBy > alloc()
Definition: CUScaleAction.h:139
cugl::ScaleBy
Definition: CUScaleAction.h:65
cugl::ScaleBy::clone
virtual std::shared_ptr< Action > clone() override
cugl::ScaleTo::getScale
const Vec2 & getScale() const
Definition: CUScaleAction.h:373
cugl::ScaleTo::alloc
static std::shared_ptr< ScaleTo > alloc(const Vec2 &scale)
Definition: CUScaleAction.h:344
cugl::ScaleTo::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::ScaleTo
Definition: CUScaleAction.h:259
cugl::ScaleTo::init
bool init(const Vec2 &scale)
Definition: CUScaleAction.h:306
cugl::ScaleTo::dispose
void dispose()
Definition: CUScaleAction.h:284
cugl::ScaleBy::setFactor
void setFactor(const Vec2 &factor)
Definition: CUScaleAction.h:195