Diffstat (limited to 'noncore/games/sfcave-sdl/bfont.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/bfont.cpp | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/noncore/games/sfcave-sdl/bfont.cpp b/noncore/games/sfcave-sdl/bfont.cpp index 0f29104..7dec8f5 100644 --- a/noncore/games/sfcave-sdl/bfont.cpp +++ b/noncore/games/sfcave-sdl/bfont.cpp | |||
@@ -52,107 +52,102 @@ void BFont::LoadFont (const char *filename) | |||
52 | { | 52 | { |
53 | SDL_Surface *surface(NULL); | 53 | SDL_Surface *surface(NULL); |
54 | int x; | 54 | int x; |
55 | // tutta roba inutile in C++.... :-) | 55 | // tutta roba inutile in C++.... :-) |
56 | /* BFont_Info *Font=NULL; | 56 | /* BFont_Info *Font=NULL; |
57 | Font = (BFont_Info *) malloc(sizeof(BFont_Info));*/ | 57 | Font = (BFont_Info *) malloc(sizeof(BFont_Info));*/ |
58 | 58 | ||
59 | if ((filename != NULL ) && (this != NULL)) | 59 | if ((filename != NULL ) && (this != NULL)) |
60 | { | 60 | { |
61 | surface = IMG_Load( filename ); | 61 | surface = IMG_Load( filename ); |
62 | 62 | ||
63 | if (surface != NULL) | 63 | if (surface != NULL) |
64 | { | 64 | { |
65 | Surface = surface; | 65 | Surface = surface; |
66 | for (x=0; x<256; x++) | 66 | for (x=0; x<256; x++) |
67 | { | 67 | { |
68 | Chars[x].x = 0; | 68 | Chars[x].x = 0; |
69 | Chars[x].y = 0; | 69 | Chars[x].y = 0; |
70 | Chars[x].h = 0; | 70 | Chars[x].h = 0; |
71 | Chars[x].w = 0; | 71 | Chars[x].w = 0; |
72 | } | 72 | } |
73 | InitFont(); // Init the font | 73 | InitFont(); // Init the font |
74 | } | 74 | } |
75 | } | 75 | } |
76 | else | ||
77 | { | ||
78 | cerr << "Error! The font has not been loaded!" << endl; | ||
79 | } | ||
80 | } | 76 | } |
81 | 77 | ||
82 | BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) | 78 | BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) |
83 | { | 79 | { |
84 | int x,y; | 80 | int x,y; |
85 | 81 | ||
86 | BFont *newfont; | 82 | BFont *newfont; |
87 | SDL_Surface *surface = NULL; | 83 | SDL_Surface *surface = NULL; |
88 | 84 | ||
89 | Uint32 pixel; | 85 | Uint32 pixel; |
90 | Uint8 old_r, old_g, old_b; | 86 | Uint8 old_r, old_g, old_b; |
91 | Uint8 new_r, new_g, new_b; | 87 | Uint8 new_r, new_g, new_b; |
92 | Uint32 color_key; | 88 | Uint32 color_key; |
93 | 89 | ||
94 | newfont = new BFont(NULL); | 90 | newfont = new BFont(NULL); |
95 | 91 | ||
96 | if (newfont != NULL) { | 92 | if (newfont != NULL) { |
97 | 93 | ||
98 | newfont->h = h; | 94 | newfont->h = h; |
99 | 95 | ||
100 | for (x=0; x<256; x++) { | 96 | for (x=0; x<256; x++) { |
101 | newfont->Chars[x].x = Chars[x].x; | 97 | newfont->Chars[x].x = Chars[x].x; |
102 | newfont->Chars[x].y = Chars[x].y; | 98 | newfont->Chars[x].y = Chars[x].y; |
103 | newfont->Chars[x].h = Chars[x].h; | 99 | newfont->Chars[x].h = Chars[x].h; |
104 | newfont->Chars[x].w = Chars[x].w; | 100 | newfont->Chars[x].w = Chars[x].w; |
105 | } | 101 | } |
106 | 102 | ||
107 | surface = SDL_CreateRGBSurface(SDL_SWSURFACE, Surface->w, Surface->h, 32, | 103 | surface = SDL_CreateRGBSurface(SDL_SWSURFACE, Surface->w, Surface->h, 32, |
108 | 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000); | 104 | 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000); |
109 | if (surface != NULL) { | 105 | if (surface != NULL) { |
110 | 106 | ||
111 | if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); | 107 | if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); |
112 | if (SDL_MUSTLOCK(Surface)) SDL_LockSurface(Surface); | 108 | if (SDL_MUSTLOCK(Surface)) SDL_LockSurface(Surface); |
113 | 109 | ||
114 | color_key = xGetPixel(Surface, 0, Surface->h-1); | 110 | color_key = xGetPixel(Surface, 0, Surface->h-1); |
115 | 111 | ||
116 | printf("looking...\n"); | ||
117 | for( x=0; x < Surface->w; x++) { | 112 | for( x=0; x < Surface->w; x++) { |
118 | for( y=0; y < Surface->h; y++) { | 113 | for( y=0; y < Surface->h; y++) { |
119 | old_r = old_g = old_b = 0; | 114 | old_r = old_g = old_b = 0; |
120 | pixel = xGetPixel(Surface,x,y); | 115 | pixel = xGetPixel(Surface,x,y); |
121 | 116 | ||
122 | if (pixel != color_key) { | 117 | if (pixel != color_key) { |
123 | SDL_GetRGB(pixel, Surface->format, &old_r,&old_g,&old_b); | 118 | SDL_GetRGB(pixel, Surface->format, &old_r,&old_g,&old_b); |
124 | 119 | ||
125 | new_r = (Uint8) ((old_r * r) / 255); | 120 | new_r = (Uint8) ((old_r * r) / 255); |
126 | new_g = (Uint8) ((old_g * g) / 255); | 121 | new_g = (Uint8) ((old_g * g) / 255); |
127 | new_b = (Uint8) ((old_b * b) / 255); | 122 | new_b = (Uint8) ((old_b * b) / 255); |
128 | 123 | ||
129 | pixel = SDL_MapRGB(surface->format,new_r,new_g,new_b); | 124 | pixel = SDL_MapRGB(surface->format,new_r,new_g,new_b); |
130 | } | 125 | } |
131 | PutPixel(surface,x,y,pixel); | 126 | PutPixel(surface,x,y,pixel); |
132 | } | 127 | } |
133 | } | 128 | } |
134 | printf("unlooking...\n"); | 129 | |
135 | if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); | 130 | if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); |
136 | if (SDL_MUSTLOCK(Surface)) SDL_UnlockSurface(Surface); | 131 | if (SDL_MUSTLOCK(Surface)) SDL_UnlockSurface(Surface); |
137 | 132 | ||
138 | SDL_SetColorKey(surface, SDL_SRCCOLORKEY, color_key); | 133 | SDL_SetColorKey(surface, SDL_SRCCOLORKEY, color_key); |
139 | } | 134 | } |
140 | 135 | ||
141 | newfont->Surface = surface; | 136 | newfont->Surface = surface; |
142 | } | 137 | } |
143 | return newfont; | 138 | return newfont; |
144 | } | 139 | } |
145 | 140 | ||
146 | 141 | ||
147 | /* Puts a single char on the surface with the specified font */ | 142 | /* Puts a single char on the surface with the specified font */ |
148 | int BFont::PutChar(SDL_Surface *screen, int x, int y, char c) | 143 | int BFont::PutChar(SDL_Surface *screen, int x, int y, char c) |
149 | { | 144 | { |
150 | int r=0; | 145 | int r=0; |
151 | SDL_Rect dest; | 146 | SDL_Rect dest; |
152 | 147 | ||
153 | dest.w = CharWidth(' '); | 148 | dest.w = CharWidth(' '); |
154 | dest.h = FontHeight(); | 149 | dest.h = FontHeight(); |
155 | dest.x = x; | 150 | dest.x = x; |
156 | dest.y = y; | 151 | dest.y = y; |
157 | 152 | ||
158 | if (c != ' ') | 153 | if (c != ' ') |