From 245a1b1034cbee9513ad7db17ab8d35e18400b97 Mon Sep 17 00:00:00 2001 From: Tom Lint Date: Sat, 1 Jun 2013 16:04:30 +0200 Subject: [PATCH] Updated System::Nullable Replaced sourceRectangle parameter with Nullable --- include/Graphics/SpriteBatch.h | 11 ++++++----- include/System/Nullable.h | 16 ++++++++++++++++ src/libXFX/SpriteBatch.cpp | 24 ++++++++++++------------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/Graphics/SpriteBatch.h b/include/Graphics/SpriteBatch.h index f3ebc40..e86d7fa 100644 --- a/include/Graphics/SpriteBatch.h +++ b/include/Graphics/SpriteBatch.h @@ -17,6 +17,7 @@ #include "Sprite.h" #include "StateBlock.h" #include +#include #include #include @@ -73,12 +74,12 @@ namespace XFX void Begin(SpriteSortMode_t sortMode, const BlendState& blendState, const SamplerState& samplerState, const DepthStencilState& depthStencilState, const RasterizerState& rasterizerState, Effect* effect, Matrix transformMatrix); void Dispose(); void Draw(Texture2D * const texture, const Rectangle destinationRectangle, Color color); - void Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Rectangle sourceRectangle, Color color); + void Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Nullable sourceRectangle, Color color); void Draw(Texture2D * const texture, const Vector2 position, const Color color); - void Draw(Texture2D * const texture, const Vector2 position, const Rectangle sourceRectangle, const Color color); - void Draw(Texture2D * const texture, const Vector2 position, const Rectangle sourceRectangle, const Color color, const float rotation, const Vector2 origin, const float scale, const SpriteEffects_t effects, const float layerDepth); - void Draw(Texture2D * const texture, const Vector2 position, const Rectangle sourceRectangle, const Color color, const float rotation, const Vector2 origin, const Vector2 scale, const SpriteEffects_t effects, const float layerDepth); - void Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Rectangle sourceRectangle, const Color color, const float rotation, const Vector2 origin, const SpriteEffects_t effects, const float layerDepth); + void Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color); + void Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const float scale, const SpriteEffects_t effects, const float layerDepth); + void Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const Vector2 scale, const SpriteEffects_t effects, const float layerDepth); + void Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const SpriteEffects_t effects, const float layerDepth); void DrawString(SpriteFont * const spriteFont, String& text, const Vector2 position, const Color color); void DrawString(SpriteFont * const spriteFont, String& text, const Vector2 position, const Color color, const float rotation, const Vector2 origin, const Vector2 scale, const SpriteEffects_t effects, const float layerDepth); void DrawString(SpriteFont * const spriteFont, String& text, const Vector2 position, const Color color, const float rotation, const Vector2 origin, const float scale, const SpriteEffects_t effects, const float layerDepth); diff --git a/include/System/Nullable.h b/include/System/Nullable.h index f3634d3..5dcb91b 100644 --- a/include/System/Nullable.h +++ b/include/System/Nullable.h @@ -30,6 +30,22 @@ namespace System T getValue() const { return *data; } operator T() const { return *data; } + + Nullable& operator =(const T * newVal) + { + data = newVal; + return *this; + } + + Nullable& operator =(const Nullable& right) + { + if (right == *this) + goto end; + + *data = *right.data; + end: + return *this; + } }; template diff --git a/src/libXFX/SpriteBatch.cpp b/src/libXFX/SpriteBatch.cpp index 6d2e1af..c1191bd 100644 --- a/src/libXFX/SpriteBatch.cpp +++ b/src/libXFX/SpriteBatch.cpp @@ -125,21 +125,21 @@ namespace XFX Draw(texture, destination, Rectangle::Empty, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } - void SpriteBatch::Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Rectangle sourceRectangle, const Color color) + void SpriteBatch::Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Nullable sourceRectangle, const Color color) { Draw(texture, destinationRectangle, sourceRectangle, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } - void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Rectangle sourceRectangle, const Color color) + void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color) { Rectangle destination = Rectangle((int)position.X, (int)position.Y, texture->Width, texture->Height); Draw(texture, destination, sourceRectangle, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } - void SpriteBatch::Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Rectangle sourceRectangle, const Color color, const float rotation, const Vector2 origin, const SpriteEffects_t effects, const float layerDepth) + void SpriteBatch::Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const SpriteEffects_t effects, const float layerDepth) { Sprite sprite = Sprite(texture, - sourceRectangle != Rectangle::Empty ? sourceRectangle : Rectangle(0, 0, texture->Width, texture->Height), + sourceRectangle.HasValue() ? sourceRectangle : Rectangle(0, 0, texture->Width, texture->Height), destinationRectangle, color, rotation, @@ -153,14 +153,14 @@ namespace XFX Flush(); } - void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Rectangle sourceRectangle, const Color color, const float rotation, const Vector2 origin, const Vector2 scale, const SpriteEffects_t effects, const float layerDepth) + void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const Vector2 scale, const SpriteEffects_t effects, const float layerDepth) { int width; int height; - if (sourceRectangle != Rectangle::Empty) + if (sourceRectangle.HasValue()) { - width = (int)(sourceRectangle.Width * scale.X); - height = (int)(sourceRectangle.Height * scale.Y); + width = (int)(sourceRectangle.getValue().Width * scale.X); + height = (int)(sourceRectangle.getValue().Height * scale.Y); } else { @@ -171,14 +171,14 @@ namespace XFX Draw(texture, destination, sourceRectangle, color, rotation, origin, effects, layerDepth); } - void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Rectangle sourceRectangle, const Color color, const float rotation, const Vector2 origin, const float scale, const SpriteEffects_t effects, const float layerDepth) + void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const float scale, const SpriteEffects_t effects, const float layerDepth) { int width; int height; - if (sourceRectangle != Rectangle::Empty) + if (sourceRectangle.HasValue()) { - width = (int)(sourceRectangle.Width * scale); - height = (int)(sourceRectangle.Height * scale); + width = (int)(sourceRectangle.getValue().Width * scale); + height = (int)(sourceRectangle.getValue().Height * scale); } else {