| 1 | // $Id: dfont.cpp,v 1.3 2003/04/14 05:51:03 mbridak Exp $cxx . . $ `<file>/src/dfont.cpp`/ |
| 2 | #include "dfont.h"cxx . . $ `<file>/src/dfont.h`/ |
| 3 | #include "files.h"cxx . . $ `<file>/src/files.h`/ |
| 4 | |
| 5 | DFontcxx . . $ DFont#::DFontcxx . . $ DFont#DFont(d0489a02ea06dfc6). (char * IFile, char * DFile) |
| 6 | { |
| 7 | loadImagecxx . . $ DFont#loadImage(fda57c8427c60377).(IFile); |
| 8 | |
| 9 | ifstreamcxx . . $ ifstream# inCreditcxx . . $ std/basic_ifstream#basic_ifstream(b8cd37071ce335df).(DFile, ioscxx . . $ std/basic_ios#::incxx . . $ std/ios_base#in.); |
| 10 | if(!cxx . . $ std/basic_ios#`operator!`(50ce9a9e25b4a850).inCredit) |
| 11 | // if (!fstream(DFile, ios::in)) //does the file exist? |
| 12 | initMapcxx . . $ DFont#initMap(fda57c8427c60377).(DFile); //if the font file doesn't exist then create one |
| 13 | else |
| 14 | loadMapcxx . . $ DFont#loadMap(fda57c8427c60377).(DFile); |
| 15 | |
| 16 | loadMapcxx . . $ DFont#loadMap(fda57c8427c60377).(DFile); |
| 17 | gapcxx . . $ DFont#gap. = fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(da459db78e6e18a3).'!'].w; |
| 18 | } |
| 19 | |
| 20 | DFontcxx . . $ DFont#::~cxx . . $ DFont#`~DFont`(ced63f7c635d850d).DFontcxx . . $ DFont# () |
| 21 | { |
| 22 | SDL_FreeSurface(fontSurfacecxx . . $ DFont#fontSurface.); |
| 23 | } |
| 24 | |
| 25 | void DFontcxx . . $ DFont#::loadImagecxx . . $ DFont#loadImage(fda57c8427c60377). (char *name) |
| 26 | { |
| 27 | SDL_Surface *temp; |
| 28 | temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).(name); |
| 29 | fontSurfacecxx . . $ DFont#fontSurface. = SDL_DisplayFormat(temp); |
| 30 | SDL_FreeSurface(temp); |
| 31 | if (fontSurfacecxx . . $ DFont#fontSurface. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 32 | cerrcxx . . $ cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error loading font!\n"; |
| 33 | abortcxx . . $ abort(15d318a79ddce9e0).(); |
| 34 | } |
| 35 | // SDL_SetColorKey(fontSurface, SDL_SRCCOLORKEY, |
| 36 | // GetPixel(fontSurface, 0, 1)); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | Uint32cxx . . $ Uint32# DFontcxx . . $ DFont#::GetPixelcxx . . $ DFont#GetPixel(60d64c952162f67c). (SDL_Surface *screen, Sint32cxx . . $ Sint32# x, Sint32cxx . . $ Sint32# y) |
| 41 | { |
| 42 | switch (screen->format->BytesPerPixel) { |
| 43 | case 1: { /* Assuming 8-bpp */ |
| 44 | return *((Uint8cxx . . $ Uint8# *)screen->pixels + y*screen->pitch + x); |
| 45 | } |
| 46 | break; |
| 47 | |
| 48 | case 2: { /* Probably 15-bpp or 16-bpp */ |
| 49 | return *((Uint16cxx . . $ Uint16# *)screen->pixels + y*screen->pitch/2 + x); |
| 50 | } |
| 51 | break; |
| 52 | |
| 53 | case 3: { /* Slow 24-bpp mode, usually not used */ |
| 54 | //Fixme |
| 55 | return 0; |
| 56 | } |
| 57 | break; |
| 58 | |
| 59 | case 4: { /* Probably 32-bpp */ |
| 60 | return *((Uint32cxx . . $ Uint32# *)screen->pixels + y*screen->pitch/4 + x); |
| 61 | } |
| 62 | break; |
| 63 | } |
| 64 | return 0xffffffff; |
| 65 | } |
| 66 | |
| 67 | void DFontcxx . . $ DFont#::loadMapcxx . . $ DFont#loadMap(fda57c8427c60377). (char * name) |
| 68 | { |
| 69 | ifstreamcxx . . $ ifstream# filecxx . . $ std/basic_ifstream#basic_ifstream(b8cd37071ce335df). (name); |
| 70 | char c='!'; //all fonts must start with ! and then increment through the |
| 71 | //ASCII table!! |
| 72 | while (file >>cxx . . $ `operator>>`(406811df2e9f9d93). fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(da459db78e6e18a3).c++]) ; |
| 73 | } |
| 74 | |
| 75 | void DFontcxx . . $ DFont#::PutStringcxx . . $ DFont#PutString(dae77c54ebf0dad5). (SDL_Surface * screen, Sint16cxx . . $ Sint16# x, Sint16cxx . . $ Sint16# y, char * |
| 76 | str) |
| 77 | { |
| 78 | SDL_Rect dest; |
| 79 | for (; *str != '\0'; ++str) |
| 80 | { |
| 81 | if (*str == ' ') |
| 82 | x+=gapcxx . . $ DFont#gap.; |
| 83 | else |
| 84 | { |
| 85 | dest.w = fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).*str].w; |
| 86 | dest.h = fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).*str].h; |
| 87 | dest.x = x; |
| 88 | dest.y = y; |
| 89 | SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`! (fontSurfacecxx . . $ DFont#fontSurface., &fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).*str], screen, &dest); |
| 90 | SDL_UpdateRects(screen, 1, &dest); |
| 91 | x+=dest.w; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void DFontcxx . . $ DFont#::PutCharcxx . . $ DFont#PutChar(a83924c70b029325). (SDL_Surface * screen, Sint16cxx . . $ Sint16# x, Sint16cxx . . $ Sint16# y, char c) |
| 97 | { |
| 98 | SDL_Rect dest; |
| 99 | dest.w = fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).c].w; |
| 100 | dest.h = fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).c].h; |
| 101 | dest.x = x; |
| 102 | dest.y = y; |
| 103 | SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`! (fontSurfacecxx . . $ DFont#fontSurface., &fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).c], screen, &dest); |
| 104 | SDL_UpdateRects(screen, 1, &dest); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /* |
| 109 | This function used to save our newly created fonts to a file. |
| 110 | This is a bad idea as we do not know where the file is being |
| 111 | created. It usually ends up in ./data/ and that is not |
| 112 | nice behaviour. Commenting out the file creation and |
| 113 | writes to the file to avoid this. We ship with the proper |
| 114 | font files in the tarball, that should be enough. |
| 115 | -- Jesse |
| 116 | */ |
| 117 | void DFontcxx . . $ DFont#::initMapcxx . . $ DFont#initMap(fda57c8427c60377). (char * name) |
| 118 | { |
| 119 | // ofstream file(name); |
| 120 | //Sentry value |
| 121 | Uint32cxx . . $ Uint32# sentry = SDL_MapRGB(fontSurfacecxx . . $ DFont#fontSurface.->format, 255, 0, 255); |
| 122 | char index = '!'; //Start of the fonts in ASCII |
| 123 | //Uint16 w; |
| 124 | Sint16cxx . . $ Sint16# x(0); |
| 125 | //Read the file from left to right detecting the font break markers along the way |
| 126 | while ( x < fontSurfacecxx . . $ DFont#fontSurface.->w ) |
| 127 | { |
| 128 | if (GetPixelcxx . . $ DFont#GetPixel(60d64c952162f67c).(fontSurfacecxx . . $ DFont#fontSurface., x, 0) != sentry) { |
| 129 | fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).index].x = x; |
| 130 | fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).index].y = 1; |
| 131 | fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).index].h = fontSurfacecxx . . $ DFont#fontSurface.->h; |
| 132 | for (; GetPixelcxx . . $ DFont#GetPixel(60d64c952162f67c).(fontSurfacecxx . . $ DFont#fontSurface., x, 0) != sentry && x < fontSurfacecxx . . $ DFont#fontSurface.->w; ++x) |
| 133 | ; |
| 134 | fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).index].w = (x - fontscxx . . $ DFont#fonts.[cxx . . $ std/map#`operator[]`(bbd415b616967878).index].x); |
| 135 | // file << fonts[index]; |
| 136 | ++index; |
| 137 | } |
| 138 | else |
| 139 | ++x; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
| 144 | //Good Ol operator overloading Ahhhhh |
| 145 | ostreamcxx . . $ ostream#& operatorcxx . . $ `operator<<`(5e4960ddb1f9971). << (ostreamcxx . . $ ostream# & os, SDL_Rect const & r) |
| 146 | { |
| 147 | return os <<cxx . . $ std/basic_ostream#`operator<<`(27f8b99acd982269). r.x <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(27f8b99acd982269). r.y <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '<<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). r.w <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). r.h <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 148 | } |
| 149 | |
| 150 | istreamcxx . . $ istream#& operatorcxx . . $ `operator>>`(406811df2e9f9d93). >> (istreamcxx . . $ istream# & is, SDL_Rect & r) |
| 151 | { |
| 152 | return is >>cxx . . $ std/basic_istream#`operator>>`(5fbda91f42b71a89). r.x >>cxx . . $ std/basic_istream#`operator>>`(5fbda91f42b71a89). r.y >>cxx . . $ std/basic_istream#`operator>>`(3e1669bc71e9720a). r.w >>cxx . . $ std/basic_istream#`operator>>`(3e1669bc71e9720a). r.h; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | |
| 157 |