Example #1
0
void HUD_Lua_Class::draw_text(FontSpecifier *font, const char *text,
															float x, float y,
															float r, float g, float b, float a,
															float scale)
{
	if (!m_drawing)
		return;
	
	if (!text || !strlen(text))
		return;
	
	apply_clip();
#ifdef HAVE_OPENGL
	if (m_opengl)
	{
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glTranslatef(x, y + (font->Height * scale), 0);
        glScalef(scale, scale, 1.0);
		glColor4f(r, g, b, a);
		font->OGL_Render(text);
		glColor4f(1, 1, 1, 1);
		glPopMatrix();
	}
	else
#endif
	if (m_surface)
	{
		SDL_Rect rect;
		rect.x = static_cast<Sint16>(x) + m_wr.x;
		rect.y = static_cast<Sint16>(y) + m_wr.y;
		rect.w = font->TextWidth(text);
		rect.h = font->LineSpacing;
        
        // FIXME: draw_text doesn't support full RGBA transfer for proper scaling,
        // so draw blended but unscaled text instead
#if 0
        if (scale < 0.99 || scale > 1.01)
        {
            SDL_Surface *s2 = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, m_surface->format->BitsPerPixel, m_surface->format->Rmask, m_surface->format->Gmask, m_surface->format->Bmask, m_surface->format->Amask);
            SDL_SetAlpha(s2, SDL_SRCALPHA, 0);
            
            font->Info->draw_text(s2, text, strlen(text),
                                  0, font->Height,
                                  SDL_MapRGBA(m_surface->format,
                                              static_cast<unsigned char>(r * 255),
                                              static_cast<unsigned char>(g * 255),
                                              static_cast<unsigned char>(b * 255),
                                              static_cast<unsigned char>(a * 255)),
                                  font->Style);
            
            SDL_Rect srcrect;
            srcrect.x = 0;
            srcrect.y = 0;
            srcrect.w = ceilf(rect.w * scale);
            srcrect.h = ceilf(rect.h * scale);
            SDL_Surface *s3 = rescale_surface(s2, srcrect.w, srcrect.h);
            SDL_FreeSurface(s2);
            
            rect.w = srcrect.w;
            rect.h = srcrect.h;
            SDL_BlitSurface(s3, &srcrect, SDL_GetVideoSurface(), &rect);
            SDL_FreeSurface(s3);
        }
        else
#endif
        {
            SDL_BlitSurface(SDL_GetVideoSurface(), &rect, m_surface, &rect);
            font->Info->draw_text(m_surface, text, strlen(text),
                                  rect.x, rect.y + font->Height,
                                  SDL_MapRGBA(m_surface->format,
                                              static_cast<unsigned char>(r * 255),
                                              static_cast<unsigned char>(g * 255),
                                              static_cast<unsigned char>(b * 255),
                                              static_cast<unsigned char>(a * 255)),
                                  font->Style);
            SDL_BlitSurface(m_surface, &rect, SDL_GetVideoSurface(), &rect);
        }
	}
}
void Shape_Blitter::SDL_Draw(SDL_Surface *dst_surface, const Image_Rect& dst)
{
    if (!dst_surface)
		return;
	
    // load shape into surface if necessary
    if (!m_surface)
    {
        byte *pixelsOut = NULL;
        SDL_Surface *tmp = get_shape_surface(m_frame, m_coll, &pixelsOut, (m_type == Shape_Texture_Interface) ? -1.0 : 1.0);
        if (!tmp)
            return;
        
        if (pixelsOut)
        {
			m_surface = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_BGRA8888, 0);
            SDL_FreeSurface(tmp);
            free(pixelsOut);
            pixelsOut = NULL;
        }
        else if (m_coll == 0 && m_frame >= 12 && m_frame <= 29)
        {
            // fix transparency on motion sensor blips
            SDL_SetColorKey(tmp, SDL_TRUE, 0);
			m_surface = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_BGRA8888, 0);
            SDL_FreeSurface(tmp);
        }
        else
            m_surface = tmp;
    }
    if (!m_surface)
        return;
    
    if (!m_scaled_surface ||
        m_scaled_surface->w != m_scaled_src.w ||
        m_scaled_surface->h != m_scaled_src.h)
    {
        if (m_scaled_surface && (m_scaled_surface != m_surface))
            SDL_FreeSurface(m_scaled_surface);
        
        if (m_scaled_src.w != m_src.w || m_scaled_src.h != m_src.h)
            m_scaled_surface = rescale_surface(m_surface, m_scaled_src.w, m_scaled_src.h);
        else
            m_scaled_surface = m_surface;
        
        if (m_type == Shape_Texture_Wall)
        {
            // rotate wall textures
            SDL_Surface *tmp = rotate_surface(m_scaled_surface, m_scaled_surface->w, m_scaled_surface->h);
            if (m_scaled_surface != m_surface)
                SDL_FreeSurface(m_scaled_surface);
            m_scaled_surface = tmp;
        }
        else if (m_type == Shape_Texture_Landscape)
        {
            // flip landscapes vertically
            SDL_Surface *tmp = flip_surface(m_scaled_surface, m_scaled_surface->w, m_scaled_surface->h);
            if (m_scaled_surface != m_surface)
                SDL_FreeSurface(m_scaled_surface);
            m_scaled_surface = tmp;
        }
    }
    
    if (!m_scaled_surface)
        return;
    
    SDL_Rect r = { crop_rect.x, crop_rect.y, crop_rect.w, crop_rect.h };
    SDL_Rect sdst = { dst.x, dst.y, dst.w, dst.h };
	SDL_BlitSurface(m_scaled_surface, &r, dst_surface, &sdst);
}
Example #3
0
void Shape_Blitter::SDL_Draw(SDL_Surface *dst_surface, SDL_Rect& dst)
{
  if (!dst_surface) {
    return;
  }

  // load shape into surface if necessary
  if (!m_surface) {
    byte *pixelsOut = NULL;
    SDL_Surface *tmp =
      get_shape_surface(m_desc, NONE, &pixelsOut,
                        (m_type == Shape_Texture_Interface) ? -1.0 : 1.0);
    if (!tmp) {
      return;
    }

    if (pixelsOut) {
      m_surface = SDL_DisplayFormatAlpha(tmp);
      SDL_FreeSurface(tmp);
      free(pixelsOut);
      pixelsOut = NULL;
    }
    else{
      m_surface = tmp;
    }
  }
  if (!m_surface) {
    return;
  }

  if (!m_scaled_surface ||
      m_scaled_surface->w != m_scaled_src.w ||
      m_scaled_surface->h != m_scaled_src.h) {
    if (m_scaled_surface && (m_scaled_surface != m_surface)) {
      SDL_FreeSurface(m_scaled_surface);
    }

    if (m_scaled_src.w != m_src.w || m_scaled_src.h != m_src.h) {
      m_scaled_surface = rescale_surface(m_surface, m_scaled_src.w,
                                         m_scaled_src.h);
    }
    else{
      m_scaled_surface = m_surface;
    }

    if (m_type == Shape_Texture_Wall) {
      // rotate wall textures
      SDL_Surface *tmp = rotate_surface(m_scaled_surface, m_scaled_surface->w,
                                        m_scaled_surface->h);
      if (m_scaled_surface != m_surface) {
        SDL_FreeSurface(m_scaled_surface);
      }
      m_scaled_surface = tmp;
    }
    else if (m_type == Shape_Texture_Landscape) {
      // flip landscapes vertically
      SDL_Surface *tmp = flip_surface(m_scaled_surface, m_scaled_surface->w,
                                      m_scaled_surface->h);
      if (m_scaled_surface != m_surface) {
        SDL_FreeSurface(m_scaled_surface);
      }
      m_scaled_surface = tmp;
    }
  }

  if (!m_scaled_surface) {
    return;
  }

  SDL_Rect r = crop_rect;
  SDL_BlitSurface(m_scaled_surface, &r, dst_surface, &dst);
}