Skip to content

Commit

Permalink
Texture: Notify observers of a DimensionsChange
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 21, 2013
1 parent dd6cf00 commit 449f5a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 18 additions & 3 deletions doomsday/client/include/resource/texture.h
Expand Up @@ -54,6 +54,7 @@ class Texture

public:
DENG2_DEFINE_AUDIENCE(Deletion, void textureBeingDeleted(Texture const &texture))
DENG2_DEFINE_AUDIENCE(DimensionsChange, void textureDimensionsChanged(Texture const &texture))

/**
* Classification/processing flags.
Expand Down Expand Up @@ -263,13 +264,27 @@ class Texture
*/
String description() const;

/// Returns the dimensions of the texture in map coordinate space units.
/**
* Returns the world dimensions of the texture, in map coordinate space
* units. The DimensionsChange audience is notified whenever dimensions
* are changed.
*/
Vector2i const &dimensions() const;

/// Returns the world width of the texture in map coordinate space units.
/**
* Convenient accessor method for returning the X axis size (width) of
* the world dimensions for the texture, in map coordinate space units.
*
* @see dimensions()
*/
inline int width() const { return dimensions().x; }

/// Returns the world height of the texture in map coordinate space units.
/**
* Convenient accessor method for returning the X axis size (height) of
* the world dimensions for the texture, in map coordinate space units.
*
* @see dimensions()
*/
inline int height() const { return dimensions().y; }

/**
Expand Down
9 changes: 9 additions & 0 deletions doomsday/client/src/resource/texture.cpp
Expand Up @@ -72,6 +72,12 @@ DENG2_PIMPL(Texture)
self.clearVariants();
#endif
}

/// Notify iterested parties of a change in world dimensions.
void notifyDimensionsChanged()
{
DENG2_FOR_PUBLIC_AUDIENCE(DimensionsChange, i) i->textureDimensionsChanged(self);
}
};

Texture::Texture(TextureManifest &manifest) : d(new Instance(this, manifest))
Expand Down Expand Up @@ -131,6 +137,7 @@ void Texture::setDimensions(Vector2i const &_newDimensions)
if(d->dimensions != newDimensions)
{
d->dimensions = newDimensions;
d->notifyDimensionsChanged();
}
}

Expand All @@ -139,6 +146,7 @@ void Texture::setWidth(int newWidth)
if(d->dimensions.x != newWidth)
{
d->dimensions.x = newWidth;
d->notifyDimensionsChanged();
}
}

Expand All @@ -147,6 +155,7 @@ void Texture::setHeight(int newHeight)
if(d->dimensions.y != newHeight)
{
d->dimensions.y = newHeight;
d->notifyDimensionsChanged();
}
}

Expand Down

0 comments on commit 449f5a4

Please sign in to comment.