Пример #1
0
int vita2d_pgf_draw_text(vita2d_pgf *font, int x, int y, unsigned int color, float scale, const char *text)
{
	int pen_x = x;

	while (*text) {
		unsigned int character = *text++;

		if (!texture_atlas_exists(font->tex_atlas, character)) {
			if (!atlas_add_glyph_pgf(font, character)) {
				continue;
			}
		}

		bp2d_rectangle rect;
		int bitmap_left, bitmap_top;
		int advance_x, advance_y;

		if (!texture_atlas_get(font->tex_atlas, character,
			&rect, &bitmap_left, &bitmap_top,
			&advance_x, &advance_y, NULL))
				continue;

		vita2d_draw_texture_tint_part_scale(font->tex_atlas->tex,
			pen_x + bitmap_left * scale,
			y - bitmap_top * scale,
			rect.x, rect.y, rect.w, rect.h,
			scale,
			scale,
			color);

		pen_x += (advance_x >> 6) * scale;
	}

	return pen_x - x;
}
Пример #2
0
void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) {
	if (icon >= GUI_ICON_MAX) {
		return;
	}
	struct GUIIconMetric metric = defaultIconMetrics[icon];
	switch (align & GUI_ALIGN_HCENTER) {
	case GUI_ALIGN_HCENTER:
		x -= metric.width;
		break;
	case GUI_ALIGN_RIGHT:
		x -= metric.width * 2;
		break;
	}
	switch (align & GUI_ALIGN_VCENTER) {
	case GUI_ALIGN_VCENTER:
		y -= metric.height;
		break;
	case GUI_ALIGN_BOTTOM:
		y -= metric.height * 2;
		break;
	}

	switch (orient) {
	case GUI_ORIENT_HMIRROR:
		vita2d_draw_texture_tint_part_scale(font->icons, x + metric.width * 2, y,
		                                    metric.x * 2, metric.y * 2,
		                                    metric.width * 2, metric.height * 2,
		                                    -1, 1, color);
		return;
	case GUI_ORIENT_VMIRROR:
		vita2d_draw_texture_tint_part_scale(font->icons, x, y + metric.height * 2,
		                                    metric.x * 2, metric.y * 2,
		                                    metric.width * 2, metric.height * 2,
		                                    1, -1, color);
		return;
	case GUI_ORIENT_0:
	default:
		// TOOD: Rotate
		vita2d_draw_texture_tint_part(font->icons, x, y,
		                                    metric.x * 2, metric.y * 2,
		                                    metric.width * 2, metric.height * 2,
		                                    color);
		break;
	}
}
Пример #3
0
void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) {
	if (icon >= GUI_ICON_MAX) {
		return;
	}
	struct GUIIconMetric metric = defaultIconMetrics[icon];
	vita2d_draw_texture_tint_part_scale(font->icons, x, y,
	                                    metric.x * 2, metric.y * 2,
	                                    metric.width * 2, metric.height * 2,
	                                    w / (float) metric.width, h / (float) metric.height, color);
}
Пример #4
0
int generic_pgf_draw_text(vita2d_pgf *font, int draw, int *height,
			  int x, int y, unsigned int color, float scale,
			  const char *text)
{
	unsigned int character;
	bp2d_rectangle rect;
	texture_atlas_entry_data data;
	vita2d_texture *tex = font->atlas->texture;
	int start_x = x;
	int max_x = 0;
	int pen_x = x;
	int pen_y = y;

	while (*text) {
		character = utf8_character(&text);

		if (character == '\n') {
			if (pen_x > max_x)
				max_x = pen_x;
			pen_x = start_x;
			pen_y += font->vsize * scale;
			continue;
		}

		if (!texture_atlas_get(font->atlas, character, &rect, &data)) {
			if (!atlas_add_glyph(font, character)) {
				continue;
			}

			if (!texture_atlas_get(font->atlas, character,
					       &rect, &data))
					continue;
		}

		if (draw) {
			vita2d_draw_texture_tint_part_scale(tex,
				pen_x + data.bitmap_left * scale,
				pen_y - data.bitmap_top * scale,
				rect.x, rect.y, rect.w, rect.h,
				scale,
				scale,
				color);
		}

		pen_x += (data.advance_x >> 6) * scale;
	}

	if (pen_x > max_x)
		max_x = pen_x;

	if (height)
		*height = pen_y + font->vsize * scale - y;

	return max_x - x;
}
Пример #5
0
static void vita2d_render_overlay(void *data)
{
   vita_video_t *vita = (vita_video_t*)data;
   for (unsigned i = 0; i < vita->overlays; i++)
   {
    vita2d_draw_texture_tint_part_scale(vita->overlay[i].tex, 
                                              vita->overlay[i].x, 
                                              vita->overlay[i].y, 
                                              vita->overlay[i].tex_x, 
                                              vita->overlay[i].tex_y, 
                                              vita->overlay[i].tex_w, 
                                              vita->overlay[i].tex_h, 
                                              vita->overlay[i].w, 
                                              vita->overlay[i].h,
                                              RGBA8(0xFF,0xFF,0xFF,(uint8_t)(vita->overlay[i].alpha_mod * 255.0f)));
                                              //RGBA8(0x00, 0x00, 0x00, (uint8_t)(vita->overlay[i].alpha_mod * 255.0f)));
   }
}
Пример #6
0
void vita2d_font_draw_text(vita2d_font *font, int x, int y, unsigned int color, unsigned int size, const char *text)
{
	FTC_FaceID face_id = (FTC_FaceID)font;
	FT_Face face;
	FTC_Manager_LookupFace(font->ftcmanager, face_id, &face);

	FT_Int charmap_index;
	charmap_index = FT_Get_Charmap_Index(face->charmap);

	FT_Glyph glyph;
	FT_Bool use_kerning = FT_HAS_KERNING(face);
	FT_UInt glyph_index, previous = 0;
	int pen_x = x;
	int pen_y = y + size;

	FTC_ScalerRec scaler;
	scaler.face_id = face_id;
	scaler.width = size;
	scaler.height = size;
	scaler.pixel = 1;

	FT_ULong flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL;

	while (*text) {
		glyph_index = FTC_CMapCache_Lookup(font->cmapcache, (FTC_FaceID)font, charmap_index, *text);

		if (use_kerning && previous && glyph_index) {
			FT_Vector delta;
			FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
			pen_x += delta.x >> 6;
		}

		if (!texture_atlas_exists(font->tex_atlas, glyph_index)) {
			FTC_ImageCache_LookupScaler(font->imagecache, &scaler, flags, glyph_index, &glyph, NULL);

			if (!atlas_add_glyph(font->tex_atlas, glyph_index, (FT_BitmapGlyph)glyph, size)) {
				continue;
			}
		}

		bp2d_rectangle rect;
		int bitmap_left, bitmap_top;
		int advance_x, advance_y;
		int glyph_size;

		texture_atlas_get(font->tex_atlas, glyph_index,
			&rect, &bitmap_left, &bitmap_top,
			&advance_x, &advance_y, &glyph_size);

		const float draw_scale = size/(float)glyph_size;

		vita2d_draw_texture_tint_part_scale(font->tex_atlas->tex,
			pen_x + bitmap_left * draw_scale,
			pen_y - bitmap_top * draw_scale,
			rect.x, rect.y, rect.w, rect.h,
			draw_scale,
			draw_scale,
			color);

		pen_x += (advance_x >> 16) * draw_scale;
		pen_y += (advance_y >> 16) * draw_scale;

		previous = glyph_index;
		text++;
	}
Пример #7
0
static void vita2d_font_render_line(
      vita_font_t *font, const char *msg, unsigned msg_len,
      float scale, const unsigned int color, float pos_x,
      float pos_y, unsigned text_align)
{
   int x, y, delta_x, delta_y;
	 unsigned width, height;
   unsigned i;

	 video_driver_get_size(&width, &height);

   x       = roundf(pos_x * width);
   y       = roundf((1.0f - pos_y) * height);
   delta_x = 0;
   delta_y = 0;


   switch (text_align)
   {
      case TEXT_ALIGN_RIGHT:
         x -= vita2d_font_get_message_width(font, msg, msg_len, scale);
         break;
      case TEXT_ALIGN_CENTER:
         x -= vita2d_font_get_message_width(font, msg, msg_len, scale) / 2;
         break;
   }

   for (i = 0; i < msg_len; i++)
   {
      int off_x, off_y, tex_x, tex_y, width, height;
      const char *msg_tmp            = &msg[i];
      unsigned code                  = utf8_walk(&msg_tmp);
      unsigned skip                  = msg_tmp - &msg[i];

      if (skip > 1)
         i += skip - 1;
         
      const struct font_glyph *glyph =
         font->font_driver->get_glyph(font->font_data, code);

      if (!glyph) /* Do something smarter here ... */
         glyph = font->font_driver->get_glyph(font->font_data, '?');
      if (!glyph)
         continue;

      off_x  = glyph->draw_offset_x;
      off_y  = glyph->draw_offset_y;
      tex_x  = glyph->atlas_offset_x;
      tex_y  = glyph->atlas_offset_y;
      width  = glyph->width;
      height = glyph->height;

			vita2d_draw_texture_tint_part_scale(font->texture,
				x + off_x + delta_x * scale,
				y + off_y + delta_y * scale,
				tex_x, tex_y, width, height,
				scale,
				scale,
				color);

      delta_x += glyph->advance_x;
      delta_y += glyph->advance_y;
   }
}