Cursor.cpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #include "nomlib/gui/Cursor.hpp"
30 
31 namespace nom {
32  namespace ui {
33 
34 Cursor::Cursor ( void ): locked_ ( false )
35 {
36 NOM_LOG_TRACE ( NOM );
37 }
38 
39 Cursor::Cursor ( const SpriteSheet& sheet ): AnimatedSprite ( sheet ),
40  locked_ ( false )
41 {
42 NOM_LOG_TRACE ( NOM );
43 }
44 
45 Cursor::Cursor ( const std::string& filename ): AnimatedSprite ( filename ),
46  locked_ ( false )
47 {
48 NOM_LOG_TRACE ( NOM );
49 }
50 
52 {
53 NOM_LOG_TRACE ( NOM );
54 }
55 
57 {
58  this->sprite = other.sprite;
59  this->coords = other.coords;
60  this->offsets = other.offsets;
61  this->state = other.state;
62  this->sprite_sheet = other.sprite_sheet;
63  this->sheet_id = other.sheet_id;
64  this->scale_factor = other.scale_factor;
65 
66  this->max_frames = other.max_frames;
67  this->current_frame = other.current_frame;
68  this->frame_increment = other.frame_increment;
69  this->animation_style = other.animation_style;
70  this->animation_status = other.animation_status;
71  this->fps = other.fps;
72 
73  return *this;
74 }
75 
76 int32 Cursor::x ( void ) const
77 {
78  return this->getPosition().x;
79 }
80 
81 int32 Cursor::y ( void ) const
82 {
83  return this->getPosition().y;
84 }
85 
86 bool Cursor::locked ( void ) const
87 {
88  return this->locked_;
89 }
90 
91 void Cursor::toggle_lock ( bool toggle )
92 {
93  this->locked_ = toggle;
94 }
95 
96 int32 Cursor::move_up ( void )
97 {
98  return -1; // Do nothing virtual implementation
99 }
100 
101 int32 Cursor::move_down ( void )
102 {
103  return -1; // Do nothing virtual implementation
104 }
105 
106 int32 Cursor::move_left ( void )
107 {
108  return -1; // Do nothing virtual implementation
109 }
110 
111 int32 Cursor::move_right ( void )
112 {
113  return -1; // Do nothing virtual implementation
114 }
115 
116 
117  } // namespace ui
118 } // namespace nom
Helper class for loading, positioning and keeping track of a cursor controlled by an user-defined inp...
Definition: Cursor.hpp:44
int32 max_frames
Total number of animation frames.
Coords offsets
Source (input) coordinates – used for sprite sheet positioning.
Definition: SpriteBatch.hpp:82
bool locked(void) const
Getter for obtaining locked status.
Definition: Cursor.cpp:86
virtual int32 move_right(void)
Definition: Cursor.cpp:111
int32 scale_factor
Scale factor applied if the resize method is called.
Definition: Sprite.hpp:102
int32 y(void) const
Definition: Cursor.cpp:81
void toggle_lock(bool toggle)
Toggle the lock variable.
Definition: Cursor.cpp:91
Texture sprite
Object that holds our sprite image.
Definition: Sprite.hpp:96
int32 sheet_id
The sheet&#39;s frame ID presently in use.
Definition: SpriteBatch.hpp:88
int32 current_frame
Current animation frame.
uint32 state
Convenience instance variable (user-defined)
Definition: Sprite.hpp:99
enum AnimatedSprite::AnimationStatus animation_status
Status info.
AnimationTimer fps
Keeps record of our current tick and frame rate (think: frame delay)
Cursor(void)
Definition: Cursor.cpp:34
Specialized class container for the creation of sprite sheets via RFC 4627 JSON-compliant file input...
Definition: SpriteSheet.hpp:62
Cursor & operator=(const Cursor &other)
Copy assignment operator.
Definition: Cursor.cpp:56
enum AnimatedSprite::AnimationStyle animation_style
Animation playback logic.
int32 x(void) const
Definition: Cursor.cpp:76
SpriteSheet sprite_sheet
Our attached sprite sheet object.
Definition: SpriteBatch.hpp:85
virtual int32 move_down(void)
Definition: Cursor.cpp:101
virtual int32 move_up(void)
Definition: Cursor.cpp:96
virtual ~Cursor(void)
Destructor.
Definition: Cursor.cpp:51
int32 frame_increment
Value that we increment the current_frame by.
virtual int32 move_left(void)
Definition: Cursor.cpp:106