47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
/******
 | 
						|
  Contained are all functions, etc. for creating, loading, and freeing Font structs.
 | 
						|
******/
 | 
						|
#include "interface.h"
 | 
						|
#include "font.h"
 | 
						|
 | 
						|
struct Font *newFont() {
 | 
						|
  struct Font *font = malloc(sizeof(struct Font));
 | 
						|
  font->width = 0;
 | 
						|
  font->height = 0;
 | 
						|
  font->s_width = 0;
 | 
						|
  font->s_height = 0;
 | 
						|
  font->scale_x = 1.0f;
 | 
						|
  font->scale_y = 1.0f;
 | 
						|
  font->surface = NULL;
 | 
						|
  font->s_surface = NULL;
 | 
						|
  font->texture = 0;
 | 
						|
  return font;
 | 
						|
}
 | 
						|
 | 
						|
void loadFontFromMemory(struct Font *font, unsigned char *memory, unsigned int length, int width, int height) {
 | 
						|
  if (length <= 0)
 | 
						|
    return;
 | 
						|
  font->width = width;
 | 
						|
  font->height = height;
 | 
						|
  font->surface = IMG_Load_RW(SDL_RWFromMem(memory, length), 1);
 | 
						|
  setFontScale(font, 1.0f, 1.0f);
 | 
						|
}
 | 
						|
 | 
						|
void setFontScale(struct Font *font, float scale_x, float scale_y) {
 | 
						|
  font->scale_x = scale_x;
 | 
						|
  font->scale_y = scale_y;
 | 
						|
  font->s_width = font->width * scale_x;
 | 
						|
  font->s_height = font->height * scale_y;
 | 
						|
  if (font->s_surface != NULL)
 | 
						|
    SDL_FreeSurface(font->s_surface);
 | 
						|
  font->s_surface = SDL_ScaleSurface(font->surface, scale_x, scale_y);
 | 
						|
}
 | 
						|
 | 
						|
void freeFont(struct Font *font) {
 | 
						|
  if (font->surface != NULL)
 | 
						|
    SDL_FreeSurface(font->surface);
 | 
						|
  if (font->s_surface != NULL)
 | 
						|
    SDL_FreeSurface(font->s_surface);
 | 
						|
  free(font);
 | 
						|
}
 |