Пример #1
0
void TCOD_sys_console_to_bitmap(void *vbitmap, int console_width, int console_height, char_t *console_buffer, char_t *prev_console_buffer) {
	int x,y;
	sfImage *bitmap=(sfImage *)vbitmap;
	TCOD_color_t fading_color = TCOD_console_get_fading_color();
	static int oldFade=-1;
	uint8 fade = TCOD_console_get_fade();
	static sfShape *rectShape=NULL;

	if ( ! rectShape ) {
		rectShape=sfShape_CreateRectangle(0.5f, 0.5f, 0.5f + fontWidth, 0.5f + fontHeight, sfBlack, 0.0f, sfBlack);
		sfShape_EnableOutline(rectShape, sfFalse);
	}
	for (y=0;y<console_height;y++) {
		for (x=0; x<console_width; x++) {
			char_t *c=&console_buffer[x+y*console_width];
			bool changed=true;
			if ( changed ) {
				sfColor b={c->back.r,c->back.g,c->back.b,255};
				// background
				b.r = ((int)b.r) * fade / 255 + ((int)fading_color.r) * (255-fade)/255;
				b.g = ((int)b.g) * fade / 255  + ((int)fading_color.g) * (255-fade)/255;
				b.b = ((int)b.b) * fade / 255 + ((int)fading_color.b) * (255-fade)/255;
				int destx=x*fontWidth;
				int desty=y*fontHeight;
				if ( (void *)bitmap == (void *)renderWindow && fullscreen_on ) {
					destx+=fullscreen_offsetx;
					desty+=fullscreen_offsety;
				}
				sfShape_SetPosition(rectShape,destx+0.5f,desty+0.5f);
				sfShape_SetColor(rectShape,sfWhite);
				sfRenderWindow_DrawShape (renderWindow, rectShape);
				nbBlit++;
				int srcx,srcy;
				if ( c->c != ' ') {
					// foreground
					int ascii=(int)c->c;
					sfColor f={c->fore.r,c->fore.g,c->fore.b,255};
					f.r = ((int)f.r) * fade / 255 + ((int)fading_color.r) * (255-fade)/255;
					f.g = ((int)f.g) * fade / 255 + ((int)fading_color.g) * (255-fade)/255;
					f.b = ((int)f.b) * fade / 255 + ((int)fading_color.b) * (255-fade)/255;
					if (fontInRow) {
						srcx = (ascii%fontNbCharHoriz)*fontWidth;
						srcy = (ascii/fontNbCharHoriz)*fontHeight;
					} else {
						srcx = (ascii/fontNbCharVertic)*fontWidth;
						srcy = (ascii%fontNbCharVertic)*fontHeight;
					}
					sfIntRect rect={srcx,srcy,srcx+fontWidth-1,srcy+fontHeight-1};
					sfSprite_SetSubRect(charmapSprite,&rect);
					sfSprite_SetX(charmapSprite,destx);
					sfSprite_SetY(charmapSprite,desty);
					sfSprite_SetColor(charmapSprite,f);
					sfRenderWindow_DrawSprite(renderWindow,charmapSprite);
				}
			}
		}
	}

}
Пример #2
0
// render when no font is loaded (happens when using some TCODImage stuff without root console)
void TCOD_sys_console_to_bitmap_nocharmap(void *vbitmap, TCOD_console_data_t *con, bool new_font) {
	int x,y;
	SDL_Surface *bitmap=(SDL_Surface *)vbitmap;
	Uint32 sdl_back=0;
	TCOD_color_t fading_color = TCOD_console_get_fading_color();
	int fade = (int)TCOD_console_get_fade();
	bool track_changes=(TCOD_old_fade == fade && con->oldbuf);
	for (y=0;y<con->h;y++) {
		for (x=0; x<con->w; x++) {
			SDL_Rect dstRect;
			bool changed=true;
			char_t *c=&con->buf[x+y*con->w];
			TCOD_bitmap_char_t *bitmap_char=&TCOD_font_chars[c->c];
			TCOD_color_t b=TCOD_image_get_pixel(con->backbuf,x,y);
			if ( c->cf == -1 ) c->cf = bitmap_char->ascii_to_tcod;
			if ( track_changes ) {
				TCOD_color_t oldb=TCOD_image_get_pixel(con->oldbackbuf,x,y);
				changed=false;
				if ( bitmap_char->updated || b.r != oldb.r || b.g != oldb.g
					|| b.b != oldb.b ) {
					changed=true;
				}
			}
			if ( changed ) {
				dstRect.x=x*TCOD_font_width;
				dstRect.y=y*TCOD_font_height;
				dstRect.w=TCOD_font_width;
				dstRect.h=TCOD_font_height;
				// draw background
				if ( fade != 255 ) {
					b.r = ((int)b.r) * fade / 255 + ((int)fading_color.r) * (255-fade)/255;
					b.g = ((int)b.g) * fade / 255  + ((int)fading_color.g) * (255-fade)/255;
					b.b = ((int)b.b) * fade / 255 + ((int)fading_color.b) * (255-fade)/255;
				}
				sdl_back=SDL_MapRGB(bitmap->format,b.r,b.g,b.b);
				if ( bitmap == TCOD_screen && TCOD_fullscreen_on ) {
					dstRect.x+=TCOD_fullscreen_offsetx;
					dstRect.y+=TCOD_fullscreen_offsety;
				}
				SDL_FillRect(bitmap,&dstRect,sdl_back);
			}
		}
	}
	TCOD_old_fade=fade;
}
Пример #3
0
colornum_t
TCOD_console_get_fading_color_wrapper ()
{
  return color_to_int(TCOD_console_get_fading_color());
}
Пример #4
0
void TCOD_sys_console_to_bitmap(void *vbitmap, int console_width, int console_height, char_t *console_buffer, char_t *prev_console_buffer) {
	int x,y;
	SDL_Surface *bitmap=(SDL_Surface *)vbitmap;
	Uint32 sdl_back=0,sdl_fore=0;
	TCOD_color_t fading_color = TCOD_console_get_fading_color();
	int fade = (int)TCOD_console_get_fade();
	bool track_changes=(oldFade == fade && prev_console_buffer);
#ifdef USE_SDL_LOCKS
	if ( SDL_MUSTLOCK( bitmap ) && SDL_LockSurface( bitmap ) < 0 ) return;
#endif
	for (y=0;y<console_height;y++) {
		for (x=0; x<console_width; x++) {
			SDL_Rect srcRect,dstRect;
			bool changed=true;
			char_t *c=&console_buffer[x+y*console_width];
			if ( c->cf == -1 ) c->cf = ascii_to_tcod[c->c];
			if ( track_changes ) {
				char_t *oc=&prev_console_buffer[x+y*console_width];
				changed=false;
				if ( c->dirt || ascii_updated[ c->c ] || c->back.r != oc->back.r || c->back.g != oc->back.g
					|| c->back.b != oc->back.b || c->fore.r != oc->fore.r
					|| c->fore.g != oc->fore.g || c->fore.b != oc->fore.b
					|| c->c != oc->c || c->cf != oc->cf) {
					changed=true;
				}
			}
			c->dirt=0;
			if ( changed ) {
				TCOD_color_t b=c->back;
				dstRect.x=x*fontWidth;
				dstRect.y=y*fontHeight;
				dstRect.w=fontWidth;
				dstRect.h=fontHeight;
				// draw background
				b.r = ((int)b.r) * fade / 255 + ((int)fading_color.r) * (255-fade)/255;
				b.g = ((int)b.g) * fade / 255  + ((int)fading_color.g) * (255-fade)/255;
				b.b = ((int)b.b) * fade / 255 + ((int)fading_color.b) * (255-fade)/255;
				sdl_back=SDL_MapRGB(bitmap->format,b.r,b.g,b.b);
				if ( bitmap == screen && fullscreen_on ) {
					dstRect.x+=fullscreen_offsetx;
					dstRect.y+=fullscreen_offsety;
				}
				SDL_FillRect(bitmap,&dstRect,sdl_back);
				if ( c->c != ' ' ) {
					// draw foreground
					//int ascii=fontTcodLayout ? (int)(ascii_to_tcod[c->c]): c->c;
					int ascii=c->cf;
					TCOD_color_t *curtext = &charcols[ascii];
					bool first = first_draw[ascii];
					TCOD_color_t f=c->fore;

					f.r = ((int)f.r) * fade / 255 + ((int)fading_color.r) * (255-fade)/255;
					f.g = ((int)f.g) * fade / 255 + ((int)fading_color.g) * (255-fade)/255;
					f.b = ((int)f.b) * fade / 255 + ((int)fading_color.b) * (255-fade)/255;
					// only draw character if foreground color != background color
					if ( ascii_updated[c->c] || f.r != b.r || f.g != b.g || f.b != b.b ) {
						if ( charmap && charmap->format->Amask == 0
							&& f.r == fontKeyCol.r && f.g == fontKeyCol.g && f.b == fontKeyCol.b ) {
							// cannot draw with the key color...
							if ( f.r < 255 ) f.r++; else f.r--;
						}
						if (fontInRow) {
							srcRect.x = (ascii%fontNbCharHoriz)*fontWidth;
							srcRect.y = (ascii/fontNbCharHoriz)*fontHeight;
						} else {
							srcRect.x = (ascii/fontNbCharVertic)*fontWidth;
							srcRect.y = (ascii%fontNbCharVertic)*fontHeight;
						}
						srcRect.w=fontWidth;
						srcRect.h=fontHeight;

						if ( charmap && (first || curtext->r != f.r || curtext->g != f.g || curtext->b!=f.b) ) {
							// change the character color in the font
					    	Uint8 bpp = charmap->format->BytesPerPixel;
					    	first_draw[ascii]=false;
							sdl_fore=SDL_MapRGB(charmap->format,f.r,f.g,f.b) & rgb_mask;
							*curtext=f;
#ifdef USE_SDL_LOCKS
							if ( SDL_MUSTLOCK(charmap) ) {
								if ( SDL_LockSurface(charmap) < 0 ) return;
							}
#endif
							if ( bpp == 4 ) {
								// 32 bits font : fill the whole character with color
								Uint32 *pix = (Uint32 *)(((Uint8 *)charmap->pixels)+srcRect.x*bpp + srcRect.y*charmap->pitch);
								int hdelta=(charmap->pitch - fontWidth*bpp)/4;
								int h=fontHeight;
								while (h> 0) {
									int w=fontWidth;
									while ( w > 0 ) {
										(*pix) &= nrgb_mask;
										(*pix) |= sdl_fore;
										w--;
										pix++;
									}
									h--;
									pix += hdelta;
								}
							} else	{
								// 24 bits font : fill only non key color pixels
								Uint32 *pix = (Uint32 *)(((Uint8 *)charmap->pixels)+srcRect.x*bpp + srcRect.y*charmap->pitch);
								int h=fontHeight;
								int hdelta=(charmap->pitch - fontWidth*bpp);
								while (h> 0) {
									int w=fontWidth;
									while ( w > 0 ) {
										if (((*pix) & rgb_mask) != sdl_key ) {
											(*pix) &= nrgb_mask;
											(*pix) |= sdl_fore;
										}
										w--;
										pix = (Uint32 *) (((Uint8 *)pix)+3);
									}
									h--;
									pix = (Uint32 *) (((Uint8 *)pix)+hdelta);
								}
							}
#ifdef USE_SDL_LOCKS
							if ( SDL_MUSTLOCK(charmap) ) {
								SDL_UnlockSurface(charmap);
							}
#endif
						}
						SDL_BlitSurface(charmap,&srcRect,bitmap,&dstRect);
					}
				}
			}
		}
	}
#ifdef USE_SDL_LOCKS
	if ( SDL_MUSTLOCK( bitmap ) ) SDL_UnlockSurface( bitmap );
#endif
	oldFade=fade;
	if ( any_ascii_updated ) {
		memset(ascii_updated,0,sizeof(bool)*TCOD_max_font_chars);
		any_ascii_updated=false;
	}
}
Пример #5
0
TCODColor TCODConsole::getFadingColor() {
	return TCOD_console_get_fading_color();
}