Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __text_c
- #define __text_c
- #include "sdl_text.h"
- const u64 thin_font[] = {
- 0b000000000100000000000100000100001110001110000100ULL,
- 0b000000000000000000000000000000001010001010001010ULL,
- 0b000000001010001010011111001010011111001010001010ULL,
- 0b000000000110001111010000001110000001011110000100ULL,
- 0b000000011001010010000010000100001001010011000000ULL,
- 0b000000010110001001001001010101000100001010000100ULL,
- 0b000000000000000000000000000000001000000100000100ULL,
- 0b000000000100000010000001000001000001000010000100ULL,
- 0b000000000010000100001000001000001000000100000010ULL,
- 0b000000000000001010000100011111000100001010000000ULL,
- 0b000000000000001000001000111110001000001000000000ULL,
- 0b000010000100000100000000000000000000000000000000ULL,
- 0b000000000000000000000000011110000000000000000000ULL,
- 0b000000000100000100000000000000000000000000000000ULL,
- 0b000000000001000010000100001000010000100000000000ULL,
- 0b000000001110010011010011010101011001010001001110ULL,
- 0b000000011111000100000100000100000101000110000100ULL,
- 0b000000011111010001000110001100010000010001001110ULL,
- 0b000000001110010001010000001100010000010001001110ULL,
- 0b000000011100001000011111001001001010001100001000ULL,
- 0b000000001110010001010000001111000001000001011111ULL,
- 0b000000001110010001010001001111000001000010001100ULL,
- 0b000000000010000010000010000100001000010001011111ULL,
- 0b000000001110010001010001001110010001010001001110ULL,
- 0b000000001110010000010000011110010001010001001110ULL,
- 0b000000000100000100000000000000000100000100000000ULL,
- 0b000010000100000100000000000000000100000100000000ULL,
- 0b000000001000000100000010000001000010000100001000ULL,
- 0b000000000000011111000000000000011111000000000000ULL,
- 0b000000000010000100001000010000001000000100000010ULL,
- 0b000000000100000000000100001000010000010001001110ULL,
- 0b000000001110000001011101010101011101010001001110ULL,
- 0b000000010001010001011111010001010001001010000100ULL,
- 0b000000001111010010010010001110010010010010001111ULL,
- 0b000000001100010010000001000001000001010010001100ULL,
- 0b000000001111010010010010010010010010010010001111ULL,
- 0b000000011111010010000010001110000010010010011111ULL,
- 0b000000000111000010000010001110000010010010011111ULL,
- 0b000000011100010010011001000001000001010010001100ULL,
- 0b000000010001010001010001011111010001010001010001ULL,
- 0b000000001110000100000100000100000100000100001110ULL,
- 0b000000000110001001001001001000001000001000011100ULL,
- 0b000000110011001010001010000110001010001010010011ULL,
- 0b000000011111010010000010000010000010000010000111ULL,
- 0b000000010001010001010001010101010101011011010001ULL,
- 0b000000010001010001010001011001010101010011010001ULL,
- 0b000000001110010001010001010001010001010001001110ULL,
- 0b000000000111000010000010001110010010010010001111ULL,
- 0b110000001110010101010001010001010001010001001110ULL,
- 0b000000010011001010000110001110010010010010001111ULL,
- 0b000000001110010001010000001110000001010001001110ULL,
- 0b000000001110000100000100000100000100010101011111ULL,
- 0b000000001110010001010001010001010001010001010001ULL,
- 0b000000000100001010010001010001010001010001010001ULL,
- 0b000000001010010101010101010101010001010001010001ULL,
- 0b000000010001001010001010000100001010001010010001ULL,
- 0b000000001110000100000100000100001010010001010001ULL,
- 0b000000011111010001000010000100001000010001011111ULL,
- 0b000000000111000001000001000001000001000001000111ULL,
- 0b000000100000010000001000000100000010000001000001ULL,
- 0b000000000111000100000100000100000100000100000111ULL,
- 0b000000000000000000000000010001010001001010000100ULL,
- 0b111111000000000000000000000000000000000000000000ULL,
- 0b000000000000000000000000000000001000000100000100ULL,
- 0b000000111110010001011110010000001110000000000000ULL,
- 0b000000001101010010010110001010000010000010000011ULL,
- 0b000000001110010001000001010001001110000000000000ULL,
- 0b000000110110011001011001010110010000010000011000ULL,
- 0b000000001110000001011111010001001110000000000000ULL,
- 0b000000000111000010000010000111000010010010001100ULL,
- 0b001111010000011110010001010001010110000000000000ULL,
- 0b000000010011010010010010010110001010000010000011ULL,
- 0b000000001110000100000100000100000110000000000100ULL,
- 0b001110010001010001010000010000011000000000010000ULL,
- 0b000000010010001010000110001010010010000010000011ULL,
- 0b000000001110000100000100000100000100000100000110ULL,
- 0b000000010101010101010101010101001011000000000000ULL,
- 0b000000010001010001010001010011001101000000000000ULL,
- 0b000000001110010001010001010001001110000000000000ULL,
- 0b000111000010001110010010010010001111000000000000ULL,
- 0b011100001000001110001001001001010110000000000000ULL,
- 0b000000000111000010000010010110011011000000000000ULL,
- 0b000000001111010000001110000001011110000000000000ULL,
- 0b000000001100010010000010000010001111000010000010ULL,
- 0b000000010110011001010001010001010001000000000000ULL,
- 0b000000000100001010010001010001010001000000000000ULL,
- 0b000000001010010101010101010101010001000000000000ULL,
- 0b000000010001001010000100001010010001000000000000ULL,
- 0b001111010000011110010001010001010001000000000000ULL,
- 0b000000011111000010000100001000011111000000000000ULL,
- 0b000000011000000100000100000011000100000100011000ULL,
- 0b000000000100000100000100000000000100000100000100ULL,
- 0b000000000011000100000100011000000100000100000011ULL,
- 0b000000000000000000000000000000000000001101010010ULL,
- 0b000000011111010001010001010001001010000100000000ULL
- };
- #define thin_font_len (sizeof(thin_font) / sizeof(thin_font[0]))
- void text_print_char( int x, int y, int c, color_t color, SDL_Surface* t ) {
- register u64 letter;
- register int dx, dy;
- if( !t ) return;
- if( c == ' ' ) return;
- if( c < '!' || c > '~' ) c = '?';
- c -= '!';
- letter = thin_font[ c ];
- for( dy = 0; dy < 8; ++dy ) {
- for( dx = 0; dx < 6; ++dx ) {
- if( letter & 1 ) {
- SDL_PutPixel( t, x+dx, y+dy, color );
- }
- letter >>= 1;
- }
- }
- }
- void text_print_str( int x, int y, char* str, color_t color, SDL_Surface* t ) {
- int cx, cy;
- if( !str || !t ) return;
- cx = x; cy = y;
- while( *str ) {
- if( *str == '\n' ) {
- cx = x;
- cy += 8;
- } else if( *str == '\r' ) {
- cx = x;
- } else if( *str == '\t' ) {
- cx += (6*4);
- } else if( *str == ' ' ) {
- cx += 6;
- } else {
- text_print_char( cx, cy, *str, color, t );
- cx += 6;
- }
- ++str;
- }
- }
- void text_print_int( int x, int y, int n, color_t color, SDL_Surface* t ) {
- char letters[ 16 ];
- memset( letters, 0, sizeof(char)*16 );
- snprintf( letters, 15, "%i", n );
- text_print_str( x, y, letters, color, t );
- }
- int text_len_get( char* str, int* w, int* h ) {
- int cx, cy;
- if( !str ) return -1;
- if( !w && !h ) return -2;
- cx = 0;
- cy = 8;
- if( w ) *w = 0;
- if( h ) *h = 8;
- while( *str ) {
- if( *str == '\n' ) {
- cx = 0;
- cy += 8;
- if( h ) if( cy > *h ) *h = cy;
- } else if( *str == '\r' ) {
- cx = 0;
- } else if( *str == '\t' ) {
- cx += (6*4);
- if( w ) if( cx > *w ) *w = cx;
- } else { // space or anything else
- cx += 6;
- if( w ) if( cx > *w ) *w = cx;
- }
- ++str;
- }
- return 0;
- }
- void text_print_int_with_info( int x, int y, int n, char* prefix, color_t color, SDL_Surface* t ) {
- int w, h;
- if( !t ) return;
- if( prefix == NULL ) {
- text_print_int( x, y, n, color, t );
- return;
- }
- text_len_get( prefix, &w, &h );
- text_print_str( x, y, prefix, color, t );
- text_print_int( x + w, y, n, color, t );
- }
- void text_print_two_items_float( int x, int y, char* p1, float n1, char* p2, float n2, color_t color, SDL_Surface* t ) {
- char temp_buf[ 4096 ];
- memset( temp_buf, 0, 4096 );
- snprintf( temp_buf, 4095, "%s: %f, %s: %f", p1, n1, p2, n2 );
- text_print_str( x, y, temp_buf, color, t );
- }
- void text_print_str_double( int x, int y, char* s1, char* s2, color_t color, SDL_Surface* t ) {
- int w, h;
- if( !t ) return;
- if( !s1 || !s2 ) return;
- text_len_get( s1, &w, &h );
- text_print_str( x, y, s1, color, t );
- text_print_str( x+w, y, s2, color, t );
- }
- void text_print__str_float_float( int x, int y, char* str, float f1, float f2, color_t color, SDL_Surface* t ) {
- char temp_buf[ 128 ];
- memset( temp_buf, 0, 128 );
- snprintf( temp_buf, 127, "%s %.4f %.4f", str, f1, f2 );
- text_print_str( x, y, temp_buf, color, t );
- }
- void text_print__str_u32_u32( int x, int y, char* str, u32 n1, u32 n2, color_t color, SDL_Surface* t ) {
- char temp_buf[ 128 ];
- memset( temp_buf, 0, 128 );
- snprintf( temp_buf, 127, "%s %08X %08X", str, n1, n2 );
- text_print_str( x, y, temp_buf, color, t );
- }
- void text_print__str_int_str_int( int x, int y, char* s1, int i1, char* s2, int i2, color_t color, SDL_Surface* t ) {
- char temp_buf[ 256 ];
- memset( temp_buf, 0, 256 );
- snprintf( temp_buf, 255, "%s %i %s %i", s1, i1, s2, i2 );
- text_print_str( x, y, temp_buf, color, t );
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement