Beatmup
Beatmup::Scene Class Reference

An ordered set of layers representing a renderable content. More...

#include <scene.h>

Inheritance diagram for Beatmup::Scene:
Beatmup::LockableObject Beatmup::Object

Classes

class  BitmapLayer
 Layer having an image to render. More...
 
class  CustomMaskedBitmapLayer
 Layer containing a bitmap and a mask applied to the bitmap when rendering. More...
 
class  Layer
 Abstract scene layer having name, type, geometry and some content to display. More...
 
class  MaskedBitmapLayer
 Bitmap layer using another bitmap as a mask. More...
 
class  SceneIntegrityError
 
class  SceneLayer
 Layer containing an entire scene. More...
 
class  ShadedBitmapLayer
 Bitmap layer using a custom shader. More...
 
class  ShapedBitmapLayer
 Layer containing a bitmap and a parametric mask (shape) More...
 

Public Member Functions

 Scene ()
 
 ~Scene ()
 
BitmapLayernewBitmapLayer (const char *name)
 
BitmapLayernewBitmapLayer ()
 
MaskedBitmapLayernewMaskedBitmapLayer (const char *name)
 
MaskedBitmapLayernewMaskedBitmapLayer ()
 
ShapedBitmapLayernewShapedBitmapLayer (const char *name)
 
ShapedBitmapLayernewShapedBitmapLayer ()
 
ShadedBitmapLayernewShadedBitmapLayer (const char *name)
 
ShadedBitmapLayernewShadedBitmapLayer ()
 
SceneLayeraddScene (const Scene &scene)
 Adds a subscene to the current scene. More...
 
LayergetLayer (const char *name) const
 Retrieves a layer by its name or null if not found. More...
 
LayergetLayer (int index) const
 Retrieves a layer by its index. More...
 
LayergetLayer (float x, float y, unsigned int recursionDepth=0) const
 Retrieves a layer present at a specific point of the scene or null if not found. More...
 
int getLayerIndex (const Layer &layer) const
 Returns layer index in the scene or -1 if not found. More...
 
int getLayerCount () const
 Returns total number of layers in the scene. More...
 
bool resolveMapping (const Layer &layer, AffineMapping &mapping) const
 Computes absolute mapping of a given layer with respect to the scene mapping. More...
 
void attachLayer (Layer &layer)
 Attaches an existing layer to the scene. More...
 
LayerdetachLayer (int index)
 Detaches a layer from the scene. More...
 
- Public Member Functions inherited from Beatmup::LockableObject
void lock ()
 
void unlock ()
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Private Member Functions

template<class Type >
Type & newLayer (const char *name)
 

Private Attributes

std::vector< Layer * > layers
 scene layers More...
 

Detailed Description

An ordered set of layers representing a renderable content.

Definition at line 37 of file scene.h.

Constructor & Destructor Documentation

◆ Scene()

Scene::Scene ( )

Definition at line 106 of file scene.cpp.

106 {}

◆ ~Scene()

Scene::~Scene ( )

Definition at line 109 of file scene.cpp.

109  {
110  for (auto it : layers)
111  delete it;
112 }
std::vector< Layer * > layers
scene layers
Definition: scene.h:39

Member Function Documentation

◆ newLayer()

template<class Type >
Type& Beatmup::Scene::newLayer ( const char *  name)
inlineprivate

Definition at line 43 of file scene.h.

43  {
44  Type* l = new Type();
45  l->setName(name);
46  layers.push_back(l);
47  return *l;
48  }
return(jlong) new Beatmup jlong jstring name

◆ newBitmapLayer() [1/2]

Scene::BitmapLayer & Scene::newBitmapLayer ( const char *  name)

Definition at line 115 of file scene.cpp.

115  {
116  return newLayer<BitmapLayer>(name);
117 }

◆ newBitmapLayer() [2/2]

Scene::BitmapLayer & Scene::newBitmapLayer ( )

Definition at line 120 of file scene.cpp.

120  {
121  return newLayer<BitmapLayer>(generateUniqueLayerName(*this, "Bitmap layer").c_str());
122 }
std::string generateUniqueLayerName(const Scene &scene, const char *prefix="")
Definition: scene.cpp:97

◆ newMaskedBitmapLayer() [1/2]

Scene::MaskedBitmapLayer & Scene::newMaskedBitmapLayer ( const char *  name)

Definition at line 125 of file scene.cpp.

125  {
126  return newLayer<MaskedBitmapLayer>(name);
127 }

◆ newMaskedBitmapLayer() [2/2]

Scene::MaskedBitmapLayer & Scene::newMaskedBitmapLayer ( )

Definition at line 130 of file scene.cpp.

130  {
131  return newLayer<MaskedBitmapLayer>(generateUniqueLayerName(*this, "Masked bitmap layer").c_str());
132 }

◆ newShapedBitmapLayer() [1/2]

Scene::ShapedBitmapLayer & Scene::newShapedBitmapLayer ( const char *  name)

Definition at line 135 of file scene.cpp.

135  {
136  return newLayer<ShapedBitmapLayer>(name);
137 }

◆ newShapedBitmapLayer() [2/2]

Scene::ShapedBitmapLayer & Scene::newShapedBitmapLayer ( )

Definition at line 140 of file scene.cpp.

140  {
141  return newLayer<ShapedBitmapLayer>(generateUniqueLayerName(*this, "Shaped bitmap layer").c_str());
142 }

◆ newShadedBitmapLayer() [1/2]

Scene::ShadedBitmapLayer & Scene::newShadedBitmapLayer ( const char *  name)

Definition at line 145 of file scene.cpp.

145  {
146  return newLayer<ShadedBitmapLayer>(name);
147 }

◆ newShadedBitmapLayer() [2/2]

Scene::ShadedBitmapLayer & Scene::newShadedBitmapLayer ( )

Definition at line 150 of file scene.cpp.

150  {
151  return newLayer<ShadedBitmapLayer>(generateUniqueLayerName(*this, "Shaped bitmap layer").c_str());
152 }

◆ addScene()

Scene::SceneLayer & Scene::addScene ( const Scene scene)

Adds a subscene to the current scene.

Definition at line 155 of file scene.cpp.

155  {
156  SceneLayer* l = new SceneLayer(scene);
157  l->setName(generateUniqueLayerName(*this, "Scene layer").c_str());
158  layers.push_back(l);
159  return *l;
160 }
return $pool getJavaReference & scene(index)

◆ getLayer() [1/3]

Scene::Layer * Scene::getLayer ( const char *  name) const

Retrieves a layer by its name or null if not found.

Definition at line 163 of file scene.cpp.

163  {
164  for (auto l : layers)
165  if (l->getName() == name)
166  return l;
167  return nullptr;
168 }

◆ getLayer() [2/3]

Scene::Layer & Scene::getLayer ( int  index) const

Retrieves a layer by its index.

Definition at line 171 of file scene.cpp.

171  {
172  return *layers[index];
173 }
jlong jint index

◆ getLayer() [3/3]

Scene::Layer * Scene::getLayer ( float  x,
float  y,
unsigned int  recursionDepth = 0 
) const

Retrieves a layer present at a specific point of the scene or null if not found.

Definition at line 175 of file scene.cpp.

175  {
176  for (auto it = layers.crbegin(); it != layers.crend(); it++)
177  if (!(*it)->isPhantom()) {
178  if ((*it)->getType() == Scene::Layer::Type::SceneLayer) {
179  Layer *result = (*it)->getChild(x, y, recursionDepth + 1);
180  if (result)
181  return result;
182  } else {
183  if ((*it)->testPoint(x, y))
184  return *it;
185  }
186  }
187  return nullptr;
188 }
@ SceneLayer
layer containing a scene
jobject jlong jint jint y
Beatmup::IntPoint result
jobject jlong jint x

◆ getLayerIndex()

int Scene::getLayerIndex ( const Layer layer) const

Returns layer index in the scene or -1 if not found.

Definition at line 191 of file scene.cpp.

191  {
192  for (size_t i = 0; i < layers.size(); ++i)
193  if (layers[i] == &layer)
194  return (int)i;
195  return -1;
196 }
Beatmup::Scene::Layer * layer

◆ getLayerCount()

int Scene::getLayerCount ( ) const

Returns total number of layers in the scene.

Definition at line 199 of file scene.cpp.

199  {
200  return (int)layers.size();
201 }

◆ resolveMapping()

bool Scene::resolveMapping ( const Layer layer,
AffineMapping mapping 
) const

Computes absolute mapping of a given layer with respect to the scene mapping.

Returns
true if the given layer is reached, false otherwise (mapping is not changed in this case)

Definition at line 204 of file scene.cpp.

204  {
205  for (auto it = layers.crbegin(); it != layers.crend(); it++) {
206  if (&layer == *it) {
208  return true;
209  }
210 
211  // scene containers are checked recursively
212  if ((*it)->getType() == Scene::Layer::Type::SceneLayer) {
213  const SceneLayer& container = (*it)->castTo<SceneLayer>();
214  if (container.getScene().resolveMapping(layer, mapping)) {
215  mapping = container.getMapping() * mapping;
216  return true;
217  }
218  }
219  }
220  return false;
221 }
AffineMapping & getMapping()
Definition: scene.h:97
Beatmup::AffineMapping & mapping

◆ attachLayer()

void Scene::attachLayer ( Layer layer)

Attaches an existing layer to the scene.

Definition at line 224 of file scene.cpp.

224  {
225  if (getLayerIndex(layer) >= 0)
226  throw SceneIntegrityError(std::string("Layer ") + layer.getName() + " is already in the scene", *this);
227  layers.push_back(&layer);
228 }
const std::string & getName() const
Definition: scene.h:94
int getLayerIndex(const Layer &layer) const
Returns layer index in the scene or -1 if not found.
Definition: scene.cpp:191

◆ detachLayer()

Scene::Layer * Scene::detachLayer ( int  index)

Detaches a layer from the scene.

Definition at line 231 of file scene.cpp.

231  {
232  Layer* l = layers[index];
233  layers.erase(layers.begin() + index);
234  return l;
235 }

Member Data Documentation

◆ layers

std::vector<Layer*> Beatmup::Scene::layers
private

scene layers

Definition at line 41 of file scene.h.


The documentation for this class was generated from the following files: