[4597] | 1 | /* |
---|
[3655] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
[3766] | 12 | main-programmer: Benjamin Grauer |
---|
[3655] | 13 | co-programmer: ... |
---|
[3766] | 14 | |
---|
| 15 | for some fonts and licenses visit: =http://www.dafont.com/en/font.php= |
---|
| 16 | |
---|
| 17 | !! IMPORTANT !! When using ttf fonts clear the license issues prior to |
---|
[4597] | 18 | adding them to orxonox. This is really important, because we do not |
---|
[3767] | 19 | want to offend anyone. |
---|
[3655] | 20 | */ |
---|
| 21 | |
---|
[5357] | 22 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS |
---|
[3655] | 23 | |
---|
[3766] | 24 | #include "text_engine.h" |
---|
[5344] | 25 | #include "text.h" |
---|
| 26 | #include "font.h" |
---|
[3655] | 27 | |
---|
| 28 | |
---|
[9406] | 29 | |
---|
[3766] | 30 | #include <stdlib.h> |
---|
| 31 | #include <stdio.h> |
---|
| 32 | #include <string.h> |
---|
[3655] | 33 | |
---|
[3766] | 34 | #include "graphics_engine.h" |
---|
[7193] | 35 | #include "util/loading/resource_manager.h" |
---|
[3769] | 36 | |
---|
[3766] | 37 | #include "debug.h" |
---|
[3768] | 38 | /////////////////// |
---|
| 39 | /// TEXT-ENGINE /// |
---|
| 40 | /////////////////// |
---|
[9715] | 41 | ObjectListDefinition(TextEngine); |
---|
[3766] | 42 | /** |
---|
[4836] | 43 | * standard constructor |
---|
[3655] | 44 | */ |
---|
[4597] | 45 | TextEngine::TextEngine () |
---|
[3655] | 46 | { |
---|
[9685] | 47 | this->registerObject(this, TextEngine::_objectList); |
---|
| 48 | this->setName("TextEngine"); |
---|
| 49 | this->enableFonts(); |
---|
[3655] | 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
[4836] | 53 | * the singleton reference to this class |
---|
[3655] | 54 | */ |
---|
[3766] | 55 | TextEngine* TextEngine::singletonRef = NULL; |
---|
[3655] | 56 | |
---|
| 57 | /** |
---|
[4836] | 58 | * standard deconstructor |
---|
[3655] | 59 | |
---|
| 60 | */ |
---|
[4597] | 61 | TextEngine::~TextEngine () |
---|
[3655] | 62 | { |
---|
[5288] | 63 | // first remove all the remaining Texts (if any). |
---|
[9685] | 64 | while (!Text::objectList().empty()) |
---|
| 65 | delete Text::objectList().front(); |
---|
[5347] | 66 | // delete all remaining fonts (There should not be Anything to do here) |
---|
[9685] | 67 | |
---|
| 68 | //const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); |
---|
| 69 | //if (fontList != NULL) |
---|
[5287] | 70 | { |
---|
[5780] | 71 | ///FIXME |
---|
[9685] | 72 | // while (fontList->size() > 0) |
---|
[5287] | 73 | { |
---|
[9685] | 74 | // Font* font = dynamic_cast<Font*>(fontList->back()); |
---|
[8761] | 75 | //if (likely(font != Font::getDefaultFont())) |
---|
| 76 | // ResourceManager::getInstance()->unload(font, RP_GAME); |
---|
[5287] | 77 | } |
---|
| 78 | } |
---|
[3769] | 79 | this->disableFonts(); |
---|
[4597] | 80 | |
---|
[3766] | 81 | TextEngine::singletonRef = NULL; |
---|
[3655] | 82 | } |
---|
[3766] | 83 | |
---|
| 84 | /** |
---|
[4836] | 85 | * function to enable TTF_Fonts |
---|
[3766] | 86 | */ |
---|
[4746] | 87 | void TextEngine::enableFonts() |
---|
[3766] | 88 | { |
---|
| 89 | if (!TTF_WasInit()) |
---|
[9685] | 90 | { |
---|
| 91 | if(TTF_Init()==-1) |
---|
| 92 | PRINTF(1)("TTF_Init: %s\n", TTF_GetError()); |
---|
[3766] | 93 | |
---|
[9685] | 94 | TextEngine::checkVersion(); |
---|
| 95 | } |
---|
[3766] | 96 | else |
---|
| 97 | PRINTF(4)("Fonts already initialized\n"); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /** |
---|
[4836] | 101 | * function to disable TTF_fonts |
---|
[7428] | 102 | */ |
---|
[4746] | 103 | void TextEngine::disableFonts() |
---|
[3766] | 104 | { |
---|
| 105 | if (TTF_WasInit()) |
---|
[9685] | 106 | { |
---|
| 107 | // Font::removeDefaultFont(); |
---|
| 108 | TTF_Quit(); |
---|
| 109 | } |
---|
[3766] | 110 | else |
---|
| 111 | PRINTF(4)("Fonts were not initialized.\n"); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
[4836] | 115 | * outputs some nice Debug information |
---|
[5347] | 116 | * |
---|
| 117 | * @todo there should also be something outputted about Font |
---|
| 118 | */ |
---|
[4746] | 119 | void TextEngine::debug() const |
---|
[3774] | 120 | { |
---|
[9685] | 121 | PRINT(0)("+-------------------------------+\n"); |
---|
| 122 | PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); |
---|
| 123 | PRINT(0)("+-------------------------------+\n"); |
---|
| 124 | PRINT(0)("Reference: %p; Text Counts: %d\n", this, Text::objectList().size()); |
---|
| 125 | |
---|
[9715] | 126 | for (ObjectList<Text>::const_iterator it = Text::objectList().begin(); |
---|
[9685] | 127 | it != Text::objectList().end(); |
---|
| 128 | ++it) |
---|
[5287] | 129 | { |
---|
[9685] | 130 | (*it)->debug(); |
---|
[5287] | 131 | PRINT(0)("+---------------------------TE--+\n"); |
---|
| 132 | } |
---|
[3774] | 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | /** |
---|
[4836] | 137 | * checks if the compiled version and the local version of SDL_ttf match. |
---|
| 138 | * @returns true if match, false otherwise |
---|
[3766] | 139 | */ |
---|
[4746] | 140 | bool TextEngine::checkVersion() |
---|
[3766] | 141 | { |
---|
| 142 | SDL_version compile_version; |
---|
| 143 | SDL_version link_version; |
---|
| 144 | TTF_VERSION(&compile_version); |
---|
| 145 | link_version = *TTF_Linked_Version(); |
---|
| 146 | |
---|
| 147 | if (compile_version.major == link_version.major && |
---|
| 148 | compile_version.minor == link_version.minor && |
---|
| 149 | compile_version.patch == link_version.patch) |
---|
[9685] | 150 | { |
---|
| 151 | return true; |
---|
| 152 | } |
---|
[3766] | 153 | else |
---|
[9685] | 154 | { |
---|
| 155 | PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", |
---|
| 156 | compile_version.major, |
---|
| 157 | compile_version.minor, |
---|
| 158 | compile_version.patch); |
---|
[4597] | 159 | |
---|
[9685] | 160 | PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", |
---|
| 161 | link_version.major, |
---|
| 162 | link_version.minor, |
---|
| 163 | link_version.patch); |
---|
| 164 | return false; |
---|
| 165 | } |
---|
[3766] | 166 | } |
---|