X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCGraphics.cpp;h=0beb6ca3ad4dd5f27cb5deb2e1142be72a6abe94;hb=e7b735a148e426e8d4dc4c0e5a000ceff6575263;hp=f6e2292351dbc6d17a5e6ab62f8b1988a5235cac;hpb=aa83777c567f9f98aa1cb3cc2708f696001b551f;p=quix0rs-blobwars.git diff --git a/src/CGraphics.cpp b/src/CGraphics.cpp index f6e2292..0beb6ca 100644 --- a/src/CGraphics.cpp +++ b/src/CGraphics.cpp @@ -1,5 +1,6 @@ /* Copyright (C) 2004-2011 Parallel Realities +Copyright (C) 2011-2015 Perpendicular Dimensions This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -538,17 +539,9 @@ void Graphics::loadMapTiles(const char *baseDir) } } -/* -Note : We need to search for the right >>> PIXEL SIZE <<< and NOT point size!! -If a user has a resolution other than approximately 72dpi then -they will get a small or larger font and this won't work. This might look -weird since we'll load and delete multiple fonts, but it works... -*/ -void Graphics::loadFont(int i, const char *filename, int pixelSize) +void Graphics::loadFont(int i, const char *filename, int pointSize) { - int minx, maxx, miny, maxy, advance; - - debug(("Attempting to load a font with pixel size of %d...\n", pixelSize)); + debug(("Attempting to load font %s with point size of %d...\n", filename, pointSize)); if (font[i]) { @@ -556,65 +549,21 @@ void Graphics::loadFont(int i, const char *filename, int pixelSize) TTF_CloseFont(font[i]); } - char tempPath[PATH_MAX]; - - snprintf(tempPath, sizeof tempPath, "%sfont.ttf", engine->userHomeDirectory); + #if USEPAK + (void)filename; + char tempPath[PATH_MAX]; + snprintf(tempPath, sizeof tempPath, "%sfont.ttf", engine->userHomeDirectory); + font[i] = TTF_OpenFont(tempPath, pointSize); + #else + font[i] = TTF_OpenFont(filename, pointSize); + #endif - bool found = false; - int size = 0; - - while (!found) + if (!font[i]) { - if (font[i]) - { - TTF_CloseFont(font[i]); - } - - #if USEPAK - font[i] = TTF_OpenFont(tempPath, ++size); - #else - font[i] = TTF_OpenFont("data/vera.ttf", ++size); - #endif - - if (!font[i]) - { - engine->reportFontFailure(); - } - - TTF_GlyphMetrics(font[i], '8', &minx, &maxx, &miny, &maxy, &advance); - - // great! we have an exact match - if (maxx == pixelSize) - { - break; - } - - // we've overshot, so we'll use the previous size! - if (maxx > pixelSize) - { - TTF_CloseFont(font[i]); - - #if USEPAK - font[i] = TTF_OpenFont(tempPath, size - 1); - #else - font[i] = TTF_OpenFont("data/vera.ttf", size - 1); - #endif - - TTF_GlyphMetrics(font[i], '8', &minx, &maxx, &miny, &maxy, &advance); - - break; - } - - if (size >= 100) - { - debug(("Pixel size has exceeded 99 pixels! I'm giving up!\n")); - engine->reportFontFailure(); - } + engine->reportFontFailure(); } TTF_SetFontStyle(font[i], TTF_STYLE_NORMAL); - - debug(("Got a match for font size %d - Nearest = %d\n", pixelSize, maxx)); } Sprite *Graphics::addSprite(const char *name) @@ -884,6 +833,12 @@ SDL_Surface *Graphics::getString(const char *in, bool transparent) text = TTF_RenderUTF8_Shaded(font[fontSize], "FONT_ERROR", fontForeground, fontBackground); } + if (!text) + { + fprintf(stderr, "Unable to render text: %s\n", SDL_GetError()); + abort(); + } + if (transparent) setTransparent(text); @@ -1133,8 +1088,9 @@ void Graphics::showLoading(int amount, int max) drawRect(120, 420, 400, 10, black, white, screen); drawRect(121, 421, currentLoading, 8, red, screen); - - SDL_UpdateRect(screen, 120, 420, 400, 10); + #else + (void)amount; + (void)max; #endif }