Skip to content

Commit

Permalink
Fix namespacing + formatting for sdlfontmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtCoDFish committed Apr 20, 2018
1 parent ec0ac12 commit b3a5299
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 163 deletions.
31 changes: 3 additions & 28 deletions include/APG/APGGraphics.hpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
/*
* Copyright (c) 2015 See AUTHORS file.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef INCLUDE_APG_APGGRAPHICS_HPP_
#define INCLUDE_APG_APGGRAPHICS_HPP_

// Include all APG graphics files
#include "APG/graphics/AnimatedSprite.hpp"
#include "APG/graphics/Buffer.hpp"
#include "APG/graphics/Camera.hpp"
#include "APG/graphics/GLError.hpp"
#include "APG/graphics/IndexBufferObject.hpp"
#include "APG/graphics/Mesh.hpp"
#include "APG/graphics/PackedTexture.hpp"
#include "APG/graphics/ShaderProgram.hpp"
#include "APG/graphics/Sprite.hpp"
#include "APG/graphics/SpriteBase.hpp"
Expand All @@ -46,4 +21,4 @@
#include "APG/graphics/VertexBufferObject.hpp"


#endif /* INCLUDE_APG_APGGRAPHICS_HPP_ */
#endif
31 changes: 3 additions & 28 deletions include/APG/APGTiled.hpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
/*
* Copyright (c) 2015 See AUTHORS file.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef INCLUDE_APG_APGTILED_HPP_
#define INCLUDE_APG_APGTILED_HPP_

// Include all APG tiled files.
#include "APG/tiled/TmxRenderer.hpp"
#include "APG/tiled/GLTmxRenderer.hpp"
#include "APG/tiled/PackedTmxRenderer.hpp"
#include "APG/tiled/GLTmxRenderer.hpp"
#include "APG/tiled/SDLTmxRenderer.hpp"


#endif /* INCLUDE_APG_APGTILED_HPP_ */
#endif
65 changes: 23 additions & 42 deletions include/APG/font/SDLFontManager.hpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
/*
* Copyright (c) 2015 See AUTHORS file.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef INCLUDE_APG_FONT_SDLFONTMANAGER_HPP_
#define INCLUDE_APG_FONT_SDLFONTMANAGER_HPP_

Expand All @@ -40,6 +13,7 @@
#include "APG/SXXDL.hpp"
#include "APG/graphics/Texture.hpp"
#include "APG/graphics/Sprite.hpp"
#include "APG/graphics/PackedTexture.hpp"
#include "APG/font/FontManager.hpp"

namespace APG {
Expand All @@ -48,26 +22,29 @@ class SpriteBase;
class SDLFontManager : public FontManager {
public:
explicit SDLFontManager();
virtual ~SDLFontManager() = default;

virtual font_handle loadFontFile(const std::string &filename, int pointSize) override;
virtual void freeFont(font_handle &handle) override;
~SDLFontManager() override = default;

font_handle loadFontFile(const std::string &filename, int pointSize) override;

void freeFont(font_handle &handle) override;

virtual void setFontColor(const font_handle &handle, const glm::vec4 &color) override;
void setFontColor(const font_handle &handle, const glm::vec4 &color) override;

virtual glm::ivec2 estimateSizeOf(const font_handle &fontHandle, const std::string &text) override;
virtual SpriteBase *renderText(const font_handle &fontHandle, const std::string &text, bool ignoreWhitespace = true,
const FontRenderMethod method = FontRenderMethod::FAST) override;
glm::ivec2 estimateSizeOf(const font_handle &fontHandle, const std::string &text) override;

SpriteBase *renderText(const font_handle &fontHandle, const std::string &text, bool ignoreWhitespace = true,
FontRenderMethod method = FontRenderMethod::FAST) override;

private:
static constexpr int MAX_OWNED_TEXTURES = 5;
static constexpr int MAX_OWNED_SPRITES = 3;

struct StoredFont {
StoredFont(const font_handle &handle, SXXDL::ttf::font_ptr &&ptr) :
handle { handle },
ptr { std::move(ptr) },
color { 0, 0, 0, 255 } {
handle{handle},
ptr{std::move(ptr)},
color{0, 0, 0, 255} {
}

font_handle handle;
Expand All @@ -76,9 +53,9 @@ class SDLFontManager : public FontManager {
};

struct StoredSDLText {
StoredSDLText(const std::string &text, const int spriteID) :
text { text },
spriteID { spriteID } {
StoredSDLText(std::string text, int spriteID) :
text{std::move(text)},
spriteID{spriteID} {
}

const std::string text;
Expand All @@ -90,12 +67,16 @@ class SDLFontManager : public FontManager {
std::array<std::unique_ptr<Sprite>, MAX_OWNED_SPRITES> ownedSprites;

int findAvailableOwnedTexture(SDL_Surface *surface) const;

int findAvailableSpriteSlot() const;

SDL_Color glmToSDLColor(const glm::vec4 &glmColor);

SpriteBase * renderTextIgnoreWhitespace(const StoredFont &font, const std::string &text, const FontRenderMethod method, el::Logger * const logger);
SpriteBase * renderTextWithWhitespace(const StoredFont &font, const std::string &text, const FontRenderMethod method, el::Logger * const logger);
SpriteBase *renderTextIgnoreWhitespace(const StoredFont &font, const std::string &text, FontRenderMethod method,
el::Logger *logger);

SpriteBase *renderTextWithWhitespace(const StoredFont &font, const std::string &text, FontRenderMethod method,
el::Logger *logger);
};

}
Expand Down
Loading

0 comments on commit b3a5299

Please sign in to comment.