Esempio n. 1
0
SDL_Surface* Font::text(const std::string& text, FontSize size, int r, int g, int b)
{
	if (text.empty())
		return NULL;

	SDL_Surface* returnSurface = NULL;

	SDL_Color color;
	color.r = r;
	color.g = g;
	color.b = b;

	switch (size)
	{
		case SMALL:
			returnSurface = TTF_RenderUTF8_Solid(smallFont, text.c_str(), color);
			break;
		case NORMAL:
			returnSurface = TTF_RenderUTF8_Solid(normalFont, text.c_str(), color);
			break;
		case LARGE:
			break;
	}

	return returnSurface;

}
Esempio n. 2
0
SDL_Surface* Font::textShaded(const std::string& text, FontSize size, int r, int g, int b)
{
	if (text.empty())
		return NULL;

	SDL_Surface* shadowSurface = NULL;
	SDL_Surface* textSurface = NULL;

	SDL_Color shadowColor = { 0, 0, 0 };
	SDL_Color textColor = { r, g, b };

	switch (size)
	{
		case SMALL:
			shadowSurface = TTF_RenderUTF8_Solid(smallFont, text.c_str(), shadowColor);
			break;
		case NORMAL:
			shadowSurface = TTF_RenderUTF8_Solid(normalFont, text.c_str(), shadowColor);
			break;
		case LARGE:
			break;
	}

	SDL_Surface* temp = Surface::createSurface(shadowSurface->w, shadowSurface->h, 128, 128, 128,
			255);

	Surface::setColorKey(temp, 128, 128, 128);

	Surface::draw(temp, shadowSurface, 0, 0);

	switch (size)
	{
		case SMALL:
			textSurface = TTF_RenderUTF8_Solid(smallFont, text.c_str(), textColor);
			break;
		case NORMAL:
			textSurface = TTF_RenderUTF8_Solid(normalFont, text.c_str(), textColor);
			break;
		case LARGE:
			break;
		}

	Surface::draw(temp, textSurface, -1, -1);

	SDL_FreeSurface(shadowSurface);
	SDL_FreeSurface(textSurface);

	return temp;
}
Esempio n. 3
0
JNIEXPORT jlong JNICALL Java_sdljava_x_swig_SWIG_1SDLTTFJNI_TTF_1RenderUTF8_1Solid(JNIEnv *jenv, jclass jcls, jlong jarg1, jstring jarg2, jlong jarg3) {
    jlong jresult = 0 ;
    TTF_Font *arg1 = (TTF_Font *) 0 ;
    char *arg2 ;
    SDL_Color arg3 ;
    SDL_Surface *result;
    SDL_Color *argp3 ;
    
    (void)jenv;
    (void)jcls;
    arg1 = *(TTF_Font **)&jarg1; 
    {
        arg2 = 0;
        if (jarg2) {
            arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0);
            if (!arg2) return 0;
        }
    }
    argp3 = *(SDL_Color **)&jarg3; 
    if (!argp3) {
        SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null SDL_Color");
        return 0;
    }
    arg3 = *argp3; 
    result = (SDL_Surface *)TTF_RenderUTF8_Solid(arg1,(char const *)arg2,arg3);
    
    *(SDL_Surface **)&jresult = result; 
    {
        if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, arg2); 
    }
    return jresult;
}
Esempio n. 4
0
ARC<TextureProtocol>
SDLRenderer::textureWithText(const std::string& text,
                             const std::string& font,
                             int size,
                             const Color& color,
                             bool antialiased) {
    
    std::string _txt = (text.length() > 0) ? text : " ";
    TTF_Font* ttf = loadFont(font, size);
    SDL_Surface* surf = nullptr;
    
    if(antialiased) {
        surf = TTF_RenderUTF8_Blended(ttf, _txt.c_str(), colorToSDL(color));
        
    }
    else {
        surf = TTF_RenderUTF8_Solid(ttf, _txt.c_str(), colorToSDL(color));
    }
    if(surf == nullptr) {
        throw std::runtime_error(std::string("Error rendering TrueType text: ") + TTF_GetError());
    }
    
    SDL_Texture* sdl = SDL_CreateTextureFromSurface(_renderer, surf);
    if(sdl == nullptr) {
        throw std::runtime_error(std::string("Error creating texture: ")+IMG_GetError());
    }
    SDL_FreeSurface(surf);
    
    SDL_SetTextureBlendMode(sdl, SDL_BLENDMODE_BLEND);
    return alloc<SDLTexture>(alloc<SDLTextureRef>(sdl));
}
Esempio n. 5
0
	SDL_Surface* TrueTypeFont::renderString(const std::string& text) {
		if( text.empty() ) {
			SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
				1,getHeight(),32,
				RMASK, GMASK, BMASK ,AMASK);
			SDL_FillRect(surface,0,0x00000000);
			return surface;
		}

		SDL_Surface* renderedText = 0;
		if (m_antiAlias) {
			renderedText = TTF_RenderUTF8_Blended(mFont, text.c_str(), mColor);
		} else {
			renderedText = TTF_RenderUTF8_Solid(mFont, text.c_str(), mColor);
		}
		// Workaround for a freetype bug, see here:
		// http://www.nabble.com/SDL_ttf-and-DPMSDisable-bug-is-back-or-still-there-to9578884.html
		if (renderedText == 0 && !m_antiAlias) {
			renderedText = TTF_RenderUTF8_Blended(mFont, text.c_str(), mColor);
		}
		// Still could not render? Something went horribly wrong!
		if (renderedText == 0) {
			throw FIFE::SDLException(TTF_GetError());
		}
		return renderedText;
	}
Esempio n. 6
0
void renderer::drawText(renderer::DrawContext c,TTF_Font* font,const char* text){
    register DrawContextPrivate* context = (DrawContextPrivate*)c;
    if(!font)
        font = g_defaultFont;

    if(text && font){
        SDL_Color color;
        SDL_GetRenderDrawColor(context->renderer,&color.r,&color.g,&color.b,&color.a);
        //Intento renderizar el texto
        SDL_Surface* textSurface = TTF_RenderUTF8_Solid(font,text,color);
        if(textSurface){
            SDL_Texture* textTexture = SDL_CreateTextureFromSurface(context->renderer,textSurface);

            SDL_Rect rect;
            rect.x = context->offset.x;
            rect.y = context->offset.y;
            rect.h = textSurface->h;
            rect.w = textSurface->w;
            SDL_RenderCopy(context->renderer,textTexture,NULL,&rect);

            SDL_DestroyTexture(textTexture);
            SDL_FreeSurface(textSurface);
        }else{
            printf("%s\n",TTF_GetError());
        }
    }
}
Esempio n. 7
0
void Screen::Display(const char *Text, int x, int y)
{
	if (x >= 0) this->OutputPosition.x = x;
	if (y >= 0) this->OutputPosition.y = y;
	for (int i = 0; i < (int)strlen(Text); i++)
	{
		if (Text[i] == 10)
		{
			NewLine();
		} else if (Text[i] == 9) {
			this->OutputPosition.x += this->FontWidth * 8;
			CheckPosition();
		} else {
			int len = SDL2Function::GetAllowCharNum(Text);
			char *t = (char*)malloc(len + 1);
			strncpy(t, Text + i, len);
			t[len] = '\0';
			i += len - 1;
			char *text = GB2312toUTF8(t);
			free(t);
			SDL_Surface *SDLText;
			SDL_Color FrontColor;
			Uint8 r, g, b;
			SDL_GetRGB(this->TextColor, this->ScreenSurface->format, &r, &g, &b);
			FrontColor.a = 255; FrontColor.r = r; FrontColor.g = g; FrontColor.b = b;
			SDLText = TTF_RenderUTF8_Solid((TTF_Font*)this->Font, text, FrontColor);
			Rect RefRect = ShowText(SDLText, this->OutputPosition.x, this->OutputPosition.y, 0, 0, this->ScreenSurface);
			this->Refresh(&RefRect);
		}
	}
}
Esempio n. 8
0
// @function gfx.TextSolid
// @format   surface = gfx.TextSolid( font , text , color )
// @describe Draw text from specified parameters
// @version  1.0
// @in       
// @out      
// @end
static int gfx_TextSolid(lua_State *L)
{
	
	TTF_Font *ttffont = lua_touserdata(L,1);
	const char *msg   = lua_tostring(L,2);
	SDL_Color *color  = lua_touserdata(L,3);
	
	if (!ttffont || !msg || !color)
	{
		// printf("gfx_Text : null\n");
		return 0;
	}
	
	SDL_Surface *ttfsurf = TTF_RenderUTF8_Solid ( ttffont , msg , *color );
	
	if (ttfsurf)
	{
		SDL_Surface **surf = (SDL_Surface **)lua_newuserdata(L,sizeof(SDL_Surface **));		
		*surf = ttfsurf;
		
		lua_newtable(L);
		lua_pushliteral(L,"__gc");
		lua_pushcfunction(L,gfx_FreeSurf);
		lua_rawset(L,-3);
		lua_setmetatable(L,-2);
	}
	else
		lua_pushnil(L);
	
	return 1;
}
Esempio n. 9
0
void TFont_ttf::surf_string_tr(SDL_Surface *surf,int x, int y, const char *s, int color,int w) {
    if (!s[0]) return;
  if (!ttf)
    return TFont::surf_string_tr(surf,x,y,s,color,w);
  if (!*s)
    return;
  SDL_Rect dest;
  SDL_Color sc;
  sc.b = (color >> 8) & 0xff;
  sc.g = (color >> 16) & 0xff;
  sc.r = (color >> 24) & 0xff;
  SDL_Surface *sf;
  if (is_utf)
      sf = TTF_RenderUTF8_Solid(ttf,s,sc );
  else
      sf = TTF_RenderText_Solid(ttf,s,sc );
  dest.x = x; dest.y = y;
  if (w && w < sf->w) {
      SDL_Rect src;
      src.w = w;
      src.h = sf->h;
      src.x = src.y = 0;
      SDL_BlitSurface(sf,&src,surf,&dest);
  } else
      SDL_BlitSurface(sf,NULL,surf,&dest);
  SDL_FreeSurface(sf);
}
Esempio n. 10
0
  SDL_Surface * TTF_RenderText_Solid_FAST(TTF_Font * font, const char* text, Uint8 r, Uint8 g, Uint8 b) {
    color.r = r;
    color.g = g;
    color.b = b;

    return TTF_RenderUTF8_Solid(font, text, color);
  }
Esempio n. 11
0
SDL_Surface* SimKit::TTFVFont::render_font(const std::string txt, const SDL_Color textcol, const SimKit::IVFont::TransparencyType bg) {
    switch (bg) {
        case SimKit::IVFont::COLORKEY:
            return TTF_RenderUTF8_Solid(this->rfont, txt.c_str(), textcol);
        case SimKit::IVFont::ALPHA:
            return TTF_RenderUTF8_Blended(this->rfont, txt.c_str(), textcol);
    }
};
Esempio n. 12
0
extern DECLSPEC SDL_Surface * SDLCALL
  TTF_RenderUTF8_Solid_p(
    TTF_Font *font,
    const char *text,
    SDL_Color *fg) {

  return TTF_RenderUTF8_Solid(font, text, *fg);
}
Esempio n. 13
0
void renderStringColor(const char *c, int x, int y, int r, int g, int b, SDL_Surface * surf)
{
	if( strcmp(c, "") == 0 )
		return;
	SDL_Color fColor = {r, g, b};
	SDL_Rect fontRect = {0, 0, 0, 0};
	SDL_Surface* fontSurface = TTF_RenderUTF8_Solid(sFont, c, fColor);
	fontRect.w = fontSurface->w;
	fontRect.h = fontSurface->h;
	fontRect.x = x - fontRect.w / 2;
	fontRect.y = y - fontRect.h / 2;
	SDL_BlitSurface(fontSurface, NULL, surf, &fontRect);
	SDL_FreeSurface(fontSurface);
}
Esempio n. 14
0
bool NXFont::InitChars(TTF_Font *font, uint32_t color)
{
SDL_Color fgcolor;
SDL_Surface *letter;

	fgcolor.r = (uint8_t)(color >> 16);
	fgcolor.g = (uint8_t)(color >> 8);
	fgcolor.b = (uint8_t)(color);

#ifdef _L10N_CP1251
    char utf8_str[2];
#endif
	
	char str[2];
	str[1] = 0;
	
	for(int i=1;i<NUM_LETTERS_RENDERED;i++)
	{
		str[0] = i;
#ifndef _L10N_CP1251
        letter = TTF_RenderUTF8_Solid(font, str, fgcolor);
#else
        win1251_to_utf8(str, utf8_str);
        letter = TTF_RenderUTF8_Solid(font, utf8_str, fgcolor);
#endif
		if (!letter)
		{
			staterr("InitChars: failed to render character %d: %s", i, TTF_GetError());
			return 1;
		}
		
		letters[i] = SDL_DisplayFormat(letter);
		SDL_FreeSurface(letter);
	}
	
	return 0;
}
Esempio n. 15
0
void scaledglprintf3(float sx, float sy, const char *fmt, ...)
{

    if (fmt==0) return;
    SDL_Color clrFg = {0,100,255,0};  // Blue ("Fg" is foreground)


    SDL_Surface *sText = TTF_RenderUTF8_Solid( fntCourier, "Hello" , clrFg );

    SDL_Rect rcDest = {200,300,0,0};
    SDL_BlitSurface( sText,NULL, screen_sfc,&rcDest );
    SDL_Flip( screen_sfc );
    SDL_FreeSurface( sText );

} /* scaledglprintf3 */
Esempio n. 16
0
void gui_scroll_text(int y, char *text)
{
	int i = strlen(text) * 12;

	if(scroll_count < -i) scroll_count = 800;

	message = TTF_RenderUTF8_Solid( font, text, WHITE );
	SDL_Surface *new_message = SDL_DisplayFormat( message );
	SDL_FreeSurface( message );

	apply_surface( scroll_count, y, new_message, myscreen );
	SDL_FreeSurface( new_message );

	scroll_count -= 1;
}
Esempio n. 17
0
void Text::updateText(const std::string& text, const SDL_Color& color, const SDL_Point& point) {
	_text = text;
	if (_texture != nullptr)
		SDL_DestroyTexture(_texture);
	SDL_Surface* surf = nullptr;
	if (type == TextType::Solid) {
		surf = TTF_RenderUTF8_Solid(_font->ttf_font, text.c_str(), color);
	} else if (type == TextType::Blended) {
		surf = TTF_RenderUTF8_Blended(_font->ttf_font, text.c_str(), color);
	}
	if (surf != nullptr) {
		_texture = SDL_CreateTextureFromSurface(game::Game::Renderer, surf);
		_srcRect = { 0, 0, surf->w, surf->h };
		_dstRect = { point.x, point.y, surf->w, surf->h };
		SDL_FreeSurface(surf);
	}
}
Esempio n. 18
0
void SDLTrueTypeFont::drawString(gcn::Graphics* graphics,
                                 const std::string& text,
                                 const int x, const int y) {
  if (text == "")
    return;

  // This is needed for drawing the Glyph in the middle if we have spacing
  int yoffset = getRowSpacing() / 2;

  gcn::Color col = graphics->getColor();
  std::string colstr;
  colstr += static_cast<char>(col.r);
  colstr += static_cast<char>(col.g);
  colstr += static_cast<char>(col.b);

  boost::shared_ptr<gcn::OpenGLImage> image =
    image_cache_.fetch(make_pair(text, colstr));
  if (!image) {
    SDL_Color sdlCol;
    sdlCol.b = col.b;
    sdlCol.r = col.r;
    sdlCol.g = col.g;

    SDL_Surface *textSurface;
    if (anti_alias_) {
      textSurface = TTF_RenderUTF8_Blended(font_, text.c_str(), sdlCol);
    } else {
      textSurface = TTF_RenderUTF8_Solid(font_, text.c_str(), sdlCol);
    }

    SDL_LockSurface(textSurface); {
      image.reset(new gcn::OpenGLImage((const unsigned int*)textSurface->pixels,
                                       textSurface->w, textSurface->h));
    }
    SDL_UnlockSurface(textSurface);
    SDL_FreeSurface(textSurface);

    image_cache_.insert(make_pair(text, colstr), image);
  }

  graphics->drawImage(image.get(),
                      0, 0,
                      x, y + yoffset,
                      image->getWidth(),
                      image->getHeight());
}
Esempio n. 19
0
int BEE::Font::draw_fast_internal(int x, int y, std::string text, RGBA color) {
	if (is_loaded) {
		if (text.size() > 0) {
			text = string_replace(text, "\t", "    ");

			if (is_sprite) {
				int i = 0;
				int w = sprite_font->get_subimage_width();
				int h = sprite_font->get_height();
				for (char& c : text) {
					sprite_font->draw_subimage(x+(i++), y, (int)c, w, h, 0.0, {color.r, color.g, color.b, color.a}, SDL_FLIP_NONE);
				}
			} else {
				SDL_Surface* tmp_surface;
				if (game->options->renderer_type != BEE_RENDERER_SDL) { // Fast font rendering is currently broken in OpenGL
					tmp_surface = TTF_RenderUTF8_Blended(font, text.c_str(), {color.r, color.g, color.b, color.a}); // Slow but pretty
				} else {
					tmp_surface = TTF_RenderUTF8_Solid(font, text.c_str(), {color.r, color.g, color.b, color.a}); // Fast but ugly
				}
				if (tmp_surface == nullptr) {
					game->messenger_send({"engine", "font"}, BEE_MESSAGE_WARNING, "Failed to draw with font \"" + name + "\": " + TTF_GetError());
					return 1;
				}

				Sprite* tmp_sprite = new Sprite();

				tmp_sprite->load_from_surface(tmp_surface);
				tmp_sprite->set_is_lightable(false);
				tmp_sprite->draw(x, y, 0, false);

				SDL_FreeSurface(tmp_surface);
				delete tmp_sprite;
			}

			return 0;
		}

		return 1;
	}

	if (!has_draw_failed) {
		game->messenger_send({"engine", "font"}, BEE_MESSAGE_WARNING, "Failed to draw text with \"" + name + "\" because it is not loaded");
		has_draw_failed = true;
	}
	return 1;
}
Esempio n. 20
0
/*!
 * @breif Draw text
 * drawText(surface, position, text, colorText, typeface, textSize)
 */
static int32_t
luaSDL_drawText(
	lua_State *L
)
{
	SDL_Surface *surface, *textSurface;
	gp_point_t pos;
	char *text;
	gp_color_t color;
	char *typeface = NULL;
	int32_t size;
	TTF_Font *font;
	SDL_Rect dstrect;
	SDL_Color forecol;

	surface = (SDL_Surface *) lua_touserdata(L, 1);
	pos = luaSdl_toPoint(L, 2);
	text = (char*)luaL_checkstring(L, 3);
	color = luaSdl_toColor(L, 4);
	typeface = (char *)luaL_checkstring(L, 5);
	size = luaL_checkinteger(L, 6);

	font = fntMgrOpenFont(typeface, size);
	if ( font == NULL ) {
		fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",
				size, typeface, SDL_GetError());
		return 0;
	}

	/* draw font */
	forecol.r = color.red;
	forecol.g = color.green;
	forecol.b = color.blue;
	textSurface = TTF_RenderUTF8_Solid(font, text, forecol);
	if ( textSurface != NULL ) {
		dstrect.x = pos.x;
		dstrect.y = pos.y;
		SDL_BlitSurface(textSurface, NULL, surface, &dstrect);
		SDL_FreeSurface(textSurface);
	}

	/* close font */
	fntMgrCloseFont(typeface, size);
	return 0;
}
Esempio n. 21
0
void UILabel::setFont(TtfFont *font) {
    this->font = font;
    SDL_Surface* textSurface = TTF_RenderUTF8_Solid( font->getFont(), text.c_str(), textColor );
    if( textSurface == NULL ) {
        printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
    }
    else {
        image = SDL_CreateTextureFromSurface( renderer, textSurface );
        if( image == NULL ) {
            printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
        } else {
            this->w = textSurface->w;
            this->h = textSurface->h;
        }
        SDL_FreeSurface( textSurface );
    }

}
Esempio n. 22
0
static mrb_value
mrb_sdl2_ttf_font_render_UTF8(mrb_state *mrb, mrb_value self)
{
  mrb_value text; 
  mrb_int r, g, b, a;
  SDL_Surface * c;
  SDL_Color color;
  mrb_get_args(mrb, "Siiii", &text, &r, &g, &b, &a);
  color.r = r;
  color.g = g;
  color.b = b;
  color.a = a;
  c = TTF_RenderUTF8_Solid(mrb_sdl2_font_get_ptr(mrb, self), RSTRING_PTR(text), color);
  if (c == NULL) {
    mruby_sdl2_raise_error(mrb);
    return mrb_false_value();
  }
  return mrb_sdl2_video_surface(mrb, c, 0);
}
Esempio n. 23
0
void RenderEngine::renderText(Image* image, const std::string& text, Color _color) {
    if (!font || !image) return;

    image->filename = "";

    if (image->texture) {
        SDL_DestroyTexture(image->texture);
        image->texture = NULL;
    }

    SDL_Color color = _color;
    SDL_Surface* surface = TTF_RenderUTF8_Solid(font, text.c_str(), color);
    if (surface) {
        image->texture = SDL_CreateTextureFromSurface(renderer, surface);
        SDL_FreeSurface(surface);
    }

    image->init(this);
}
Esempio n. 24
0
void UITextBox::GenerateTexture()
{
    ValidateText();

    SDL_Surface* textSurface = TTF_RenderUTF8_Solid( m_font, m_label.c_str(), m_textColor );
    m_sprite.SetTexture ( SDL_CreateTextureFromSurface( kuko::Application::GetRenderer(), textSurface ) );
    SDL_FreeSurface( textSurface );

    m_sprite.position = m_position;

    // Set w/h to fit the ratio
    int fullWidth, fullHeight;
    SDL_QueryTexture( m_sprite.texture, NULL, NULL, &fullWidth, &fullHeight );

    float fontRatio = float(fullWidth) / float(fullHeight);

    m_sprite.position.w = m_sprite.position.h * fontRatio;
    m_sprite.position.x += 2;
}
Esempio n. 25
0
File: sdl.c Progetto: IGLOU-EU/yirl
static int sdlPrintLine(SDLWid *wid,
			const char *str,
			unsigned int caract_per_line,
			SDL_Color color,
			int x, int y, int line)
{
  unsigned int   len = strlen(str);
  int text_width , text_height;
  SDL_Renderer *renderer = sg.renderer;

  y += wid->rect.y;
  x += wid->rect.x;
  for (unsigned int i = 0; i < len; i += caract_per_line)
    {
      static char  buff[125];  
      SDL_Surface *textSurface;
      SDL_Texture* text;

      if ((len - i) > caract_per_line) {
	strncpy(buff, str + i, caract_per_line);
	buff[caract_per_line] = 0;
      } else {
	strncpy(buff, str + i, len - i);
	buff[len - i] = 0;
      }

      textSurface = TTF_RenderUTF8_Solid(sgDefaultFont(),
					 buff, color);
      text = SDL_CreateTextureFromSurface(renderer, textSurface);
      text_width = textSurface->w;
      text_height = textSurface->h;
      if (i == 0)
	y += textSurface->h * line;	

      SDL_FreeSurface(textSurface);
      SDL_Rect renderQuad = { x, y, text_width, text_height };
      SDL_RenderCopy(renderer, text, NULL, &renderQuad);
      SDL_DestroyTexture(text);
      y += text_height;
    }
  return 0;
}
Esempio n. 26
0
Surface Font::CreateSurface(const std::string & txt,
                            const Color & color)
{
#ifdef HAVE_HANDHELD // would be HAVE_HANDHELD if ANDROID didn't misteriously crash because of it
  SDL_Surface *surf = TTF_RenderUTF8_Solid(m_font, txt.c_str(), color.GetSDLColor());
#else
  SDL_Surface *surf = TTF_RenderUTF8_Blended(m_font, txt.c_str(), color.GetSDLColor());
#endif

  if (!surf) {
    // SDL_ttf or freetype might be missing some feature, report it
    Error(Format("Unable to render text: %s", TTF_GetError()));
  }
  
#ifdef HAVE_HANDHELD
  return Surface(surf).DisplayFormat();
#else
  return Surface(surf).DisplayFormatAlpha();
#endif
}
Esempio n. 27
0
/**
 * \brief Redraws the text surface in the case of a normal font.
 *
 * This function is called when there is a change.
 */
void TextSurface::rebuild_ttf() {

    // create the text surface

    SDL_Surface *internal_surface = NULL;
    switch (rendering_mode) {

    case TEXT_SOLID:
        internal_surface = TTF_RenderUTF8_Solid(fonts[font_id].internal_font, text.c_str(), *text_color.get_internal_color());
        break;

    case TEXT_ANTIALIASING:
        internal_surface = TTF_RenderUTF8_Blended(fonts[font_id].internal_font, text.c_str(), *text_color.get_internal_color());
        break;
    }

    Debug::check_assertion(internal_surface != NULL, StringConcat()
                           << "Cannot create the text surface for string '" << text << "': " << SDL_GetError());
    surface = new Surface(internal_surface);
}
Esempio n. 28
0
//	*A SDL_Rect is created at this point because the texture information is defined in the SDL_Surface but
//	 is lost when it becomes a SDL_Texture
TTF_TEXT* Resource::loadText( std::string fontName, std::string text, int fontSize, SDL_Color color, int textX, int textY ){
	TTF_TEXT* retText = NULL;
	
	retText = new TTF_TEXT();
	TTF_Font* font = TTF_OpenFont(fontName.c_str(), fontSize);
	SDL_Surface* textSurface = TTF_RenderUTF8_Solid(font, text.c_str(), color);
	retText->text = SDL_CreateTextureFromSurface(renderer, textSurface);
	SDL_Rect* textRect = new SDL_Rect();
	textRect->x = textX;			textRect->y = textY;
	textRect->w = textSurface->w;	textRect->h = textSurface->h;
	retText->rect = textRect;

	SDL_FreeSurface(textSurface);
	TTF_CloseFont(font);

	

	return retText;
	
}
Image * SDLHardwareRenderDevice::renderTextToImage(FontStyle* font_style, const std::string& text, Color color, bool blended) {
	SDLHardwareImage *image = new SDLHardwareImage(this, renderer);

	SDL_Surface *cleanup;

	if (blended) {
		cleanup = TTF_RenderUTF8_Blended(static_cast<SDLFontStyle *>(font_style)->ttfont, text.c_str(), color);
	}
	else {
		cleanup = TTF_RenderUTF8_Solid(static_cast<SDLFontStyle *>(font_style)->ttfont, text.c_str(), color);
	}

	if (cleanup) {
		image->surface = SDL_CreateTextureFromSurface(renderer, cleanup);
		SDL_FreeSurface(cleanup);
		return image;
	}

	delete image;
	return NULL;
}
Esempio n. 30
0
void TextureOpenGL::create_from_font(const char *str, const char *font_name, u32 font_size)
{
#if 0
    destroy();

    // フォントのビットマップ化
    Bitmap bitmap;
    bitmap.create_from_font(str, font_name, font_size);

    GLuint tex    = create_from_bitmap(&bitmap);
    m_tex_name    = tex;
    m_desc.width  = bitmap.get_width();
    m_desc.height = bitmap.get_height();
    m_desc.info   = str;

    TTF_Init();
    TTF_Font *p_font = TTF_OpenFont("/System/Library/Fonts/AquaKana.ttc", 20);
    if ( !p_font ) {
        printf("failed open font\n");
    }
    
    SDL_Color color;
    color.r =255;
    color.g = 255;
    color.b = 255;
    
    SDL_Surface *surface = TTF_RenderUTF8_Solid(p_font, str, color);
    
    
    TTF_CloseFont(p_font);
    TTF_Quit();
    
    GLuint tex    = __create_from_surface(surface);
    m_tex_name    = tex;
    m_desc.width  = surface->w;
    m_desc.height = surface->h;
    m_desc.info   = str;
    
#endif
}