void DrawingContext::draw_surface(SurfacePtr surface, const Vector& position, float angle, const Color& color, const Blend& blend, int layer) { assert(surface != 0); DrawingRequest* request = new(obst) DrawingRequest(); request->target = target; request->type = SURFACE; request->pos = transform.apply(position); if(request->pos.x >= SCREEN_WIDTH || request->pos.y >= SCREEN_HEIGHT || request->pos.x + surface->get_width() < 0 || request->pos.y + surface->get_height() < 0) return; request->layer = layer; request->drawing_effect = transform.drawing_effect; request->alpha = transform.alpha; request->angle = angle; request->color = color; request->blend = blend; SurfaceRequest* surfacerequest = new(obst) SurfaceRequest(); surfacerequest->surface = surface.get(); request->request_data = surfacerequest; requests->push_back(request); }
void TtFontAsset::RenderText( SurfacePtr dest, int& x, int& y, const char* text, const pei::Color& color /*= pei::XColor(255,255,255)*/ ) { // assert ( pFont ); if (!m_TtFont || dest.get() == NULL ) { return; } #ifdef _HAS_SDL_TTF_ SDL_Surface *text_surface = NULL; // this is a hack! We swap r & g and correct the color format manually // SDL_ttf renders ARGB, but we need ABGR (or LE RGBA) to match RGBA texture format - performace reasons! SDL_Color c = { color.b, color.g, color.r, color.a }; if ( (text_surface = TTF_RenderText_Blended( (TTF_Font*)m_TtFont->GetFontHandle(), text, c )) != NULL ) { // swap r&g in the format description text_surface->format->Rmask = 0x000000ff; text_surface->format->Rshift = 0; text_surface->format->Bmask = 0x00ff0000; text_surface->format->Bshift = 16; pei::SurfacePtr txt( new pei::SDL::SurfaceWrapper(text_surface)); pei::Blitter blitter(pei::PixOpPtr(new PixOpAlphaBlitSrcAlpha(txt->GetFormat(),dest->GetFormat()) ) ); blitter.Blit( txt, dest, x, y, txt->GetWidth(), txt->GetHeight(), 0, 0 ); int tw, th; TTF_SizeText( (TTF_Font*)m_TtFont->GetFontHandle(), text, &tw, &th); Uint32 font_height = TTF_FontHeight((TTF_Font*)m_TtFont->GetFontHandle()); // - a - 2*d; y += font_height; x += tw; } #endif }
void DrawingContext::draw_surface_part(SurfacePtr surface, const Rectf& srcrect, const Rectf& dstrect, int layer) { assert(surface != 0); DrawingRequest* request = new(obst) DrawingRequest(); request->target = target; request->type = SURFACE_PART; request->pos = transform.apply(dstrect.p1); request->layer = layer; request->drawing_effect = transform.drawing_effect; request->alpha = transform.alpha; SurfacePartRequest* surfacepartrequest = new(obst) SurfacePartRequest(); surfacepartrequest->srcrect = srcrect; surfacepartrequest->dstsize = dstrect.get_size(); surfacepartrequest->surface = surface.get(); request->request_data = surfacepartrequest; requests->push_back(request); }