예제 #1
0
void JE_outTextAndDarken( SDL_Surface * screen, int x, int y, const char *s, uint32_t colorbank, uint32_t brightness, uint32_t font )
{
	int bright = 0;

	for (int i = 0; s[i] != '\0'; ++i)
	{
		int sprite_id = font_ascii[(uint8_t)s[i]];

		switch (s[i])
		{
		case ' ':
			x += 6;
			break;

		case '~':
			bright = (bright == 0) ? 4 : 0;
			break;

		default:
			if (sprite_id != -1 && sprite_exists(TINY_FONT, sprite_id))
			{
				blit_sprite_dark(screen, x + 1, y + 1, font, sprite_id, false);
				blit_sprite_hv_unsafe(screen, x, y, font, sprite_id, colorbank, brightness + bright);

				x += sprite(font, sprite_id)->width + 1;
			}
			break;
		}
	}
}
예제 #2
0
// does not clip on left or right edges of surface
// unsafe because it doesn't check that value won't overflow into hue
// we can replace it when we know that we don't rely on that 'feature'
void blit_sprite_hv_unsafe( SDL_Surface *surface, int x, int y, unsigned int table, unsigned int index, Uint8 hue, Sint8 value )
{
	if (index >= sprite_table[table].count || !sprite_exists(table, index))
	{
		assert(false);
		return;
	}
	
	hue <<= 4;
	
	const Sprite * const cur_sprite = sprite(table, index);
	
	const Uint8 *data = cur_sprite->data;
	const Uint8 * const data_ul = data + cur_sprite->size;
	
	const unsigned int width = cur_sprite->width;
	unsigned int x_offset = 0;
	
	assert(surface->format->BitsPerPixel == 8);
	Uint8 *             pixels =    (Uint8 *)surface->pixels + (y * surface->pitch) + x;
	const Uint8 * const pixels_ll = (Uint8 *)surface->pixels,  // lower limit
	            * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch);  // upper limit
	
	for (; data < data_ul; ++data)
	{
		switch (*data)
		{
		case 255:  // transparent pixels
			data++;  // next byte tells how many
			pixels += *data;
			x_offset += *data;
			break;
			
		case 254:  // next pixel row
			pixels += width - x_offset;
			x_offset = width;
			break;
			
		case 253:  // 1 transparent pixel
			pixels++;
			x_offset++;
			break;
			
		default:  // set a pixel
			if (pixels >= pixels_ul)
				return;
			if (pixels >= pixels_ll)
				*pixels = hue | ((*data & 0x0f) + value);
			
			pixels++;
			x_offset++;
			break;
		}
		if (x_offset >= width)
		{
			pixels += surface->pitch - x_offset;
			x_offset = 0;
		}
	}
}
예제 #3
0
void JE_outTextAdjust( SDL_Surface * screen, int x, int y, const char *s, uint32_t filter, int brightness, uint32_t font, bool shadow )
{
	int bright = 0;

	for (int i = 0; s[i] != '\0'; ++i)
	{
		int sprite_id = font_ascii[(uint8_t)s[i]];

		switch (s[i])
		{
		case ' ':
			x += 6;
			break;

		case '~':
			bright = (bright == 0) ? 4 : 0;
			break;

		default:
			if (sprite_id != -1 && sprite_exists(TINY_FONT, sprite_id))
			{
				if (shadow)
					blit_sprite_dark(screen, x + 2, y + 2, font, sprite_id, false);
				blit_sprite_hv(screen, x, y, font, sprite_id, filter, brightness + bright);

				x += sprite(font, sprite_id)->width + 1;
			}
			break;
		}
	}
}
예제 #4
0
파일: font.c 프로젝트: idispatch/opentyrian
/**
 * \brief Draws text in a color specified by hue and value.
 * 
 * A '~' in the text is not drawn but instead toggles highlighting which
 * increases \c value by 4.
 * 
 * \li like JE_outText() with (brightness >= 0)
 * \li like JE_outTextAdjust() without shadow
 * 
 * @param surface destination surface
 * @param x initial x-position in pixels; which direction(s) the text is drawn
 *        from this position depends on the alignment
 * @param y initial upper y-position in pixels
 * @param text text to be drawn
 * @param font style/size of text
 * @param alignment left_aligned, centered, or right_aligned
 * @param hue hue component of text color
 * @param value value component of text color
 */
void draw_font_hv( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, Uint8 hue, Sint8 value )
{
	switch (alignment)
	{
	case left_aligned:
		break;
	case centered:
		x -= JE_textWidth(text, font) / 2;
		break;
	case right_aligned:
		x -= JE_textWidth(text, font);
		break;
	}
	
	bool highlight = false;
	
	for (; *text != '\0'; ++text)
	{
		int sprite_id = font_ascii[(unsigned char)*text];
		
		switch (*text)
		{
		case ' ':
			x += 6;
			break;
			
		case '~':
			highlight = !highlight;
			if (highlight)
				value += 4;
			else
				value -= 4;
			break;
			
		default:
			if (sprite_id != -1 && sprite_exists(font, sprite_id))
			{
				blit_sprite_hv(surface, x, y, font, sprite_id, hue, value);
				
				x += sprite(font, sprite_id)->width + 1;
			}
			break;
		}
	}
}
예제 #5
0
파일: font.c 프로젝트: idispatch/opentyrian
/**
 * \brief Draws darkened text.
 * 
 * Corresponds to blit_sprite_dark()
 * 
 * \li like JE_outText() with (brightness < 0)  if (black == true)
 * 
 * @param surface destination surface
 * @param x initial x-position in pixels; which direction(s) the text is drawn
 *        from this position depends on the alignment
 * @param y initial upper y-position in pixels
 * @param text text to be drawn
 * @param font style/size of text
 * @param alignment left_aligned, centered, or right_aligned
 * @param black if true text is drawn as solid black, if false text is drawn by
 *        darkening the pixels of the destination surface
 */
void draw_font_dark( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, bool black )
{
	switch (alignment)
	{
	case left_aligned:
		break;
	case centered:
		x -= JE_textWidth(text, font) / 2;
		break;
	case right_aligned:
		x -= JE_textWidth(text, font);
		break;
	}
	
	for (; *text != '\0'; ++text)
	{
		int sprite_id = font_ascii[(unsigned char)*text];
		
		switch (*text)
		{
		case ' ':
			x += 6;
			break;
			
		case '~':
			break;
			
		default:
			if (sprite_id != -1 && sprite_exists(font, sprite_id))
			{
				blit_sprite_dark(surface, x, y, font, sprite_id, black);
				
				x += sprite(font, sprite_id)->width + 1;
			}
			break;
		}
	}
}