[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" |
---|
[3769] | 35 | |
---|
[3766] | 36 | #include "debug.h" |
---|
[3768] | 37 | /////////////////// |
---|
| 38 | /// TEXT-ENGINE /// |
---|
| 39 | /////////////////// |
---|
[9869] | 40 | ObjectListDefinition(TextEngine); |
---|
[3766] | 41 | /** |
---|
[4836] | 42 | * standard constructor |
---|
[3655] | 43 | */ |
---|
[4597] | 44 | TextEngine::TextEngine () |
---|
[3655] | 45 | { |
---|
[9869] | 46 | this->registerObject(this, TextEngine::_objectList); |
---|
| 47 | this->setName("TextEngine"); |
---|
| 48 | this->enableFonts(); |
---|
[3655] | 49 | } |
---|
| 50 | |
---|
| 51 | /** |
---|
[4836] | 52 | * the singleton reference to this class |
---|
[3655] | 53 | */ |
---|
[3766] | 54 | TextEngine* TextEngine::singletonRef = NULL; |
---|
[3655] | 55 | |
---|
| 56 | /** |
---|
[4836] | 57 | * standard deconstructor |
---|
[3655] | 58 | |
---|
| 59 | */ |
---|
[4597] | 60 | TextEngine::~TextEngine () |
---|
[3655] | 61 | { |
---|
[5288] | 62 | // first remove all the remaining Texts (if any). |
---|
[9869] | 63 | while (!Text::objectList().empty()) |
---|
| 64 | delete Text::objectList().front(); |
---|
[5347] | 65 | // delete all remaining fonts (There should not be Anything to do here) |
---|
[9869] | 66 | |
---|
| 67 | //const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); |
---|
| 68 | //if (fontList != NULL) |
---|
[5287] | 69 | { |
---|
[5780] | 70 | ///FIXME |
---|
[9869] | 71 | // while (fontList->size() > 0) |
---|
[5287] | 72 | { |
---|
[9869] | 73 | // Font* font = dynamic_cast<Font*>(fontList->back()); |
---|
[8761] | 74 | //if (likely(font != Font::getDefaultFont())) |
---|
| 75 | // ResourceManager::getInstance()->unload(font, RP_GAME); |
---|
[5287] | 76 | } |
---|
| 77 | } |
---|
[3769] | 78 | this->disableFonts(); |
---|
[4597] | 79 | |
---|
[3766] | 80 | TextEngine::singletonRef = NULL; |
---|
[3655] | 81 | } |
---|
[3766] | 82 | |
---|
| 83 | /** |
---|
[4836] | 84 | * function to enable TTF_Fonts |
---|
[3766] | 85 | */ |
---|
[4746] | 86 | void TextEngine::enableFonts() |
---|
[3766] | 87 | { |
---|
| 88 | if (!TTF_WasInit()) |
---|
[9869] | 89 | { |
---|
| 90 | if(TTF_Init()==-1) |
---|
| 91 | PRINTF(1)("TTF_Init: %s\n", TTF_GetError()); |
---|
[3766] | 92 | |
---|
[9869] | 93 | TextEngine::checkVersion(); |
---|
| 94 | } |
---|
[3766] | 95 | else |
---|
| 96 | PRINTF(4)("Fonts already initialized\n"); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
[4836] | 100 | * function to disable TTF_fonts |
---|
[7428] | 101 | */ |
---|
[4746] | 102 | void TextEngine::disableFonts() |
---|
[3766] | 103 | { |
---|
| 104 | if (TTF_WasInit()) |
---|
[9869] | 105 | { |
---|
| 106 | // Font::removeDefaultFont(); |
---|
| 107 | TTF_Quit(); |
---|
| 108 | } |
---|
[3766] | 109 | else |
---|
| 110 | PRINTF(4)("Fonts were not initialized.\n"); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
[4836] | 114 | * outputs some nice Debug information |
---|
[5347] | 115 | * |
---|
| 116 | * @todo there should also be something outputted about Font |
---|
| 117 | */ |
---|
[4746] | 118 | void TextEngine::debug() const |
---|
[3774] | 119 | { |
---|
[9869] | 120 | PRINT(0)("+-------------------------------+\n"); |
---|
| 121 | PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); |
---|
| 122 | PRINT(0)("+-------------------------------+\n"); |
---|
| 123 | PRINT(0)("Reference: %p; Text Counts: %d\n", this, Text::objectList().size()); |
---|
| 124 | |
---|
| 125 | for (ObjectList<Text>::const_iterator it = Text::objectList().begin(); |
---|
| 126 | it != Text::objectList().end(); |
---|
| 127 | ++it) |
---|
[5287] | 128 | { |
---|
[9869] | 129 | (*it)->debug(); |
---|
[5287] | 130 | PRINT(0)("+---------------------------TE--+\n"); |
---|
| 131 | } |
---|
[3774] | 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | /** |
---|
[4836] | 136 | * checks if the compiled version and the local version of SDL_ttf match. |
---|
| 137 | * @returns true if match, false otherwise |
---|
[3766] | 138 | */ |
---|
[4746] | 139 | bool TextEngine::checkVersion() |
---|
[3766] | 140 | { |
---|
| 141 | SDL_version compile_version; |
---|
| 142 | SDL_version link_version; |
---|
| 143 | TTF_VERSION(&compile_version); |
---|
| 144 | link_version = *TTF_Linked_Version(); |
---|
| 145 | |
---|
| 146 | if (compile_version.major == link_version.major && |
---|
| 147 | compile_version.minor == link_version.minor && |
---|
| 148 | compile_version.patch == link_version.patch) |
---|
[9869] | 149 | { |
---|
| 150 | return true; |
---|
| 151 | } |
---|
[3766] | 152 | else |
---|
[9869] | 153 | { |
---|
| 154 | PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", |
---|
| 155 | compile_version.major, |
---|
| 156 | compile_version.minor, |
---|
| 157 | compile_version.patch); |
---|
[4597] | 158 | |
---|
[9869] | 159 | PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", |
---|
| 160 | link_version.major, |
---|
| 161 | link_version.minor, |
---|
| 162 | link_version.patch); |
---|
| 163 | return false; |
---|
| 164 | } |
---|
[3766] | 165 | } |
---|