File: BaseSprite.h

package info (click to toggle)
jazz2-native 3.5.0-1
  • links: PTS, VCS
  • area: contrib
  • in suites:
  • size: 16,836 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (89 lines) | stat: -rw-r--r-- 2,464 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

#include "DrawableNode.h"
#include "../Primitives/Rect.h"

namespace nCine
{
	class Texture;
	class GLUniformBlockCache;

	/// Base class for sprites
	/*! \note Users cannot create instances of this class */
	class BaseSprite : public DrawableNode
	{
	public:
		BaseSprite(BaseSprite&&) = default;
		BaseSprite& operator=(BaseSprite&&) = default;

		BaseSprite& operator=(const BaseSprite&) = delete;

		/// Sets sprite size
		void setSize(float width, float height);
		/// Sets sprite size with a `Vector2f`
		inline void setSize(Vector2f size) {
			setSize(size.X, size.Y);
		}

		/// Gets the texture object
		inline const Texture* texture() const {
			return texture_;
		}
		/// Sets the texture object
		void setTexture(Texture* texture);
		/// Triggers a texture update without setting a new texture
		void resetTexture();

		/// Gets the texture source rectangle for blitting
		inline Recti texRect() const {
			return texRect_;
		}
		/// Sets the texture source rectangle for blitting
		void setTexRect(const Recti& rect);

		/// Returns `true` if the sprite texture is horizontally flipped
		inline bool isFlippedX() const {
			return flippedX_;
		}
		/// Flips the texture rect horizontally
		void setFlippedX(bool flippedX);
		/// Returns `true` if the sprite texture is vertically flipped
		inline bool isFlippedY() const {
			return flippedY_;
		}
		/// Flips the texture rect vertically
		void setFlippedY(bool flippedY);

	protected:
#ifndef DOXYGEN_GENERATING_OUTPUT
		/// The sprite texture
		Texture* texture_;
		/// The texture source rectangle
		Recti texRect_;

		/// A flag indicating if the sprite texture is horizontally flipped
		bool flippedX_;
		/// A flag indicating if the sprite texture is vertically flipped
		bool flippedY_;

		GLUniformBlockCache* instanceBlock_;
#endif

		/// Protected constructor accessible only by derived sprite classes
		BaseSprite(SceneNode* parent, Texture* texture, float xx, float yy);
		/// Protected constructor accessible only by derived sprite classes
		BaseSprite(SceneNode* parent, Texture* texture, Vector2f position);

		/// Protected copy constructor used to clone objects
		BaseSprite(const BaseSprite& other);

		/// Performs the required tasks upon a change to the shader
		void shaderHasChanged() override;

		/// Performs the required tasks upon a change to the texture
		virtual void textureHasChanged(Texture* newTexture) = 0;

		void updateRenderCommand() override;
	};

}