Boyu Fang
/
Ovation_Controller
TFT
Fork of Ovation_Controller_1 by
font_new.cpp@3:92845c139aca, 2014-08-28 (annotated)
- Committer:
- bf1891
- Date:
- Thu Aug 28 15:18:07 2014 +0000
- Revision:
- 3:92845c139aca
- Parent:
- 1:ecf8078bf531
publish;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewcrussell | 1:ecf8078bf531 | 1 | #include "mbed.h" |
andrewcrussell | 1:ecf8078bf531 | 2 | #include <stdio.h> |
andrewcrussell | 1:ecf8078bf531 | 3 | #include "font_new.h" |
andrewcrussell | 1:ecf8078bf531 | 4 | |
andrewcrussell | 1:ecf8078bf531 | 5 | void Write_Command(unsigned char command); |
andrewcrussell | 1:ecf8078bf531 | 6 | void SendData(unsigned long color); |
andrewcrussell | 1:ecf8078bf531 | 7 | void WindowSet(int s_x, int e_x,int s_y,int e_y); |
andrewcrussell | 1:ecf8078bf531 | 8 | |
andrewcrussell | 1:ecf8078bf531 | 9 | void put_pixcels( int xs, int width, int ys, int height, unsigned char *c, int f_color, int b_color ); |
andrewcrussell | 1:ecf8078bf531 | 10 | void put_pixcels_alpha( int xs, int width, int ys, int height, unsigned char *c, int color, int key ); |
andrewcrussell | 1:ecf8078bf531 | 11 | |
andrewcrussell | 1:ecf8078bf531 | 12 | int FontDrawSpace( int width, int height, int xpos, int ypos, int f_color, int b_color ); |
andrewcrussell | 1:ecf8078bf531 | 13 | |
andrewcrussell | 1:ecf8078bf531 | 14 | typedef struct _draw_font_parameters { |
andrewcrussell | 1:ecf8078bf531 | 15 | font *font_ptr; |
andrewcrussell | 1:ecf8078bf531 | 16 | int inter_char_space; |
andrewcrussell | 1:ecf8078bf531 | 17 | int alpha_mode; |
andrewcrussell | 1:ecf8078bf531 | 18 | int f_color; |
andrewcrussell | 1:ecf8078bf531 | 19 | int b_color; |
andrewcrussell | 1:ecf8078bf531 | 20 | } |
andrewcrussell | 1:ecf8078bf531 | 21 | draw_font_parameters; |
andrewcrussell | 1:ecf8078bf531 | 22 | draw_font_parameters dfp; |
andrewcrussell | 1:ecf8078bf531 | 23 | |
andrewcrussell | 1:ecf8078bf531 | 24 | font Calibri14; |
andrewcrussell | 1:ecf8078bf531 | 25 | font Calibri28; |
andrewcrussell | 1:ecf8078bf531 | 26 | font Calibri72; |
andrewcrussell | 1:ecf8078bf531 | 27 | font Calibri78_1; |
andrewcrussell | 1:ecf8078bf531 | 28 | |
andrewcrussell | 1:ecf8078bf531 | 29 | void FontDrawInit( void ) |
andrewcrussell | 1:ecf8078bf531 | 30 | { |
andrewcrussell | 1:ecf8078bf531 | 31 | Calibri14.height = 23; |
andrewcrussell | 1:ecf8078bf531 | 32 | Calibri14.max_width = 17; |
andrewcrussell | 1:ecf8078bf531 | 33 | Calibri14.space_width = 7; |
andrewcrussell | 1:ecf8078bf531 | 34 | Calibri14.data_table = c14_data_table; |
andrewcrussell | 1:ecf8078bf531 | 35 | Calibri14.offset_table = c14_offset_table; |
andrewcrussell | 1:ecf8078bf531 | 36 | Calibri14.index_table = c14_index_table; |
andrewcrussell | 1:ecf8078bf531 | 37 | Calibri14.width_table = c14_width_table; |
andrewcrussell | 1:ecf8078bf531 | 38 | |
andrewcrussell | 1:ecf8078bf531 | 39 | Calibri28.height = 45; |
andrewcrussell | 1:ecf8078bf531 | 40 | Calibri28.max_width = 34; |
andrewcrussell | 1:ecf8078bf531 | 41 | Calibri28.space_width = 10; |
andrewcrussell | 1:ecf8078bf531 | 42 | Calibri28.data_table = c28_data_table; |
andrewcrussell | 1:ecf8078bf531 | 43 | Calibri28.offset_table = c28_offset_table; |
andrewcrussell | 1:ecf8078bf531 | 44 | Calibri28.index_table = c28_index_table; |
andrewcrussell | 1:ecf8078bf531 | 45 | Calibri28.width_table = c28_width_table; |
andrewcrussell | 1:ecf8078bf531 | 46 | |
andrewcrussell | 1:ecf8078bf531 | 47 | Calibri72.height = 117; |
andrewcrussell | 1:ecf8078bf531 | 48 | Calibri72.max_width = 87; |
andrewcrussell | 1:ecf8078bf531 | 49 | Calibri72.space_width = 20; |
andrewcrussell | 1:ecf8078bf531 | 50 | Calibri72.data_table = c72_data_table; |
andrewcrussell | 1:ecf8078bf531 | 51 | Calibri72.offset_table = c72_offset_table; |
andrewcrussell | 1:ecf8078bf531 | 52 | Calibri72.index_table = c72_index_table; |
andrewcrussell | 1:ecf8078bf531 | 53 | Calibri72.width_table = c72_width_table; |
andrewcrussell | 1:ecf8078bf531 | 54 | |
andrewcrussell | 1:ecf8078bf531 | 55 | Calibri78_1.height = 117; |
andrewcrussell | 1:ecf8078bf531 | 56 | Calibri78_1.max_width = 49; |
andrewcrussell | 1:ecf8078bf531 | 57 | Calibri78_1.space_width = 20; |
andrewcrussell | 1:ecf8078bf531 | 58 | Calibri78_1.data_table = c78_1_data_table; |
andrewcrussell | 1:ecf8078bf531 | 59 | Calibri78_1.offset_table = c78_1_offset_table; |
andrewcrussell | 1:ecf8078bf531 | 60 | Calibri78_1.index_table = c78_1_index_table; |
andrewcrussell | 1:ecf8078bf531 | 61 | Calibri78_1.width_table = c78_1_width_table; |
andrewcrussell | 1:ecf8078bf531 | 62 | |
andrewcrussell | 1:ecf8078bf531 | 63 | dfp.font_ptr = &Calibri14; |
andrewcrussell | 1:ecf8078bf531 | 64 | dfp.inter_char_space = 0; |
andrewcrussell | 1:ecf8078bf531 | 65 | dfp.alpha_mode = 0; |
andrewcrussell | 1:ecf8078bf531 | 66 | dfp.f_color = 0x0000FF; |
andrewcrussell | 1:ecf8078bf531 | 67 | dfp.b_color = 0xFFFFFF; |
andrewcrussell | 1:ecf8078bf531 | 68 | |
andrewcrussell | 1:ecf8078bf531 | 69 | #if 0 |
andrewcrussell | 1:ecf8078bf531 | 70 | // printf( "c14_data_table : %p\r\n", c14_data_table ); |
andrewcrussell | 1:ecf8078bf531 | 71 | // printf( "c14_data_table : %p\r\n", Calibri14.data_table ); |
andrewcrussell | 1:ecf8078bf531 | 72 | // printf( "c14_offset_table : %p\r\n", Calibri14.offset_table ); |
andrewcrussell | 1:ecf8078bf531 | 73 | // printf( "c14_index_table : %p\r\n", Calibri14.index_table ); |
andrewcrussell | 1:ecf8078bf531 | 74 | // printf( "c14_width_table : %p\r\n", Calibri14.width_table ); |
andrewcrussell | 1:ecf8078bf531 | 75 | |
andrewcrussell | 1:ecf8078bf531 | 76 | // printf( "(dfp.font_ptr->)data_table : %p\r\n", dfp.font_ptr->data_table ); |
andrewcrussell | 1:ecf8078bf531 | 77 | #endif |
andrewcrussell | 1:ecf8078bf531 | 78 | } |
andrewcrussell | 1:ecf8078bf531 | 79 | |
andrewcrussell | 1:ecf8078bf531 | 80 | //#ifdef TEST |
andrewcrussell | 1:ecf8078bf531 | 81 | //extern unsigned char screen[ SC_WIDTH * SC_HEIGHT ]; |
andrewcrussell | 1:ecf8078bf531 | 82 | //#endif |
andrewcrussell | 1:ecf8078bf531 | 83 | |
andrewcrussell | 1:ecf8078bf531 | 84 | void put_pixcels( int xs, int width, int ys, int height, unsigned char *c, int f_color, int b_color ) |
andrewcrussell | 1:ecf8078bf531 | 85 | { |
andrewcrussell | 1:ecf8078bf531 | 86 | int i; |
andrewcrussell | 1:ecf8078bf531 | 87 | int j; |
andrewcrussell | 1:ecf8078bf531 | 88 | |
andrewcrussell | 1:ecf8078bf531 | 89 | #ifdef TEST |
andrewcrussell | 1:ecf8078bf531 | 90 | for ( j = 0; j < height; j++ ) |
andrewcrussell | 1:ecf8078bf531 | 91 | for ( i = 0; i < width; i++ ) |
andrewcrussell | 1:ecf8078bf531 | 92 | *(screen + ((((height - 1) - j) + ys) * SC_WIDTH) + i + xs) = (unsigned char)((*c++ == 'F') ? f_color : b_color); |
andrewcrussell | 1:ecf8078bf531 | 93 | #else |
andrewcrussell | 1:ecf8078bf531 | 94 | WindowSet( xs, (xs + width) - 1, ys, (ys + height) - 1 ); |
andrewcrussell | 1:ecf8078bf531 | 95 | |
andrewcrussell | 1:ecf8078bf531 | 96 | Write_Command( 0x2c ); |
andrewcrussell | 1:ecf8078bf531 | 97 | |
andrewcrussell | 1:ecf8078bf531 | 98 | for ( j = 0; j < height; j++ ) |
andrewcrussell | 1:ecf8078bf531 | 99 | for ( i = 0; i < width; i++ ) |
andrewcrussell | 1:ecf8078bf531 | 100 | SendData( (*c++ == 'F') ? f_color : b_color ); |
andrewcrussell | 1:ecf8078bf531 | 101 | #endif |
andrewcrussell | 1:ecf8078bf531 | 102 | } |
andrewcrussell | 1:ecf8078bf531 | 103 | |
andrewcrussell | 1:ecf8078bf531 | 104 | |
andrewcrussell | 1:ecf8078bf531 | 105 | void put_pixcels_alpha( int xs, int width, int ys, int height, unsigned char *c, int color, int key ) |
andrewcrussell | 1:ecf8078bf531 | 106 | { |
andrewcrussell | 1:ecf8078bf531 | 107 | int i; |
andrewcrussell | 1:ecf8078bf531 | 108 | int j; |
andrewcrussell | 1:ecf8078bf531 | 109 | |
andrewcrussell | 1:ecf8078bf531 | 110 | #ifdef TEST |
andrewcrussell | 1:ecf8078bf531 | 111 | |
andrewcrussell | 1:ecf8078bf531 | 112 | for ( j = 0; j < height; j++ ) |
andrewcrussell | 1:ecf8078bf531 | 113 | { |
andrewcrussell | 1:ecf8078bf531 | 114 | for ( i = 0; i < width; i++ ) |
andrewcrussell | 1:ecf8078bf531 | 115 | { |
andrewcrussell | 1:ecf8078bf531 | 116 | if ( *c == 'F' ) |
andrewcrussell | 1:ecf8078bf531 | 117 | *(screen + ((((height - 1) - j) + ys) * SC_WIDTH) + i + xs) = color; |
andrewcrussell | 1:ecf8078bf531 | 118 | c++; |
andrewcrussell | 1:ecf8078bf531 | 119 | } |
andrewcrussell | 1:ecf8078bf531 | 120 | } |
andrewcrussell | 1:ecf8078bf531 | 121 | |
andrewcrussell | 1:ecf8078bf531 | 122 | #else |
andrewcrussell | 1:ecf8078bf531 | 123 | |
andrewcrussell | 1:ecf8078bf531 | 124 | for ( j = 0; j < height; j++ ) |
andrewcrussell | 1:ecf8078bf531 | 125 | { |
andrewcrussell | 1:ecf8078bf531 | 126 | for ( i = 0; i < width; i++ ) |
andrewcrussell | 1:ecf8078bf531 | 127 | { |
andrewcrussell | 1:ecf8078bf531 | 128 | if ( *c != key ) |
andrewcrussell | 1:ecf8078bf531 | 129 | { |
andrewcrussell | 1:ecf8078bf531 | 130 | WindowSet( xs + i, xs + i, ys + j, ys + j ); |
andrewcrussell | 1:ecf8078bf531 | 131 | Write_Command( 0x2c ); |
andrewcrussell | 1:ecf8078bf531 | 132 | SendData( *c++ ); |
andrewcrussell | 1:ecf8078bf531 | 133 | } |
andrewcrussell | 1:ecf8078bf531 | 134 | } |
andrewcrussell | 1:ecf8078bf531 | 135 | } |
andrewcrussell | 1:ecf8078bf531 | 136 | |
andrewcrussell | 1:ecf8078bf531 | 137 | #endif |
andrewcrussell | 1:ecf8078bf531 | 138 | |
andrewcrussell | 1:ecf8078bf531 | 139 | } |
andrewcrussell | 1:ecf8078bf531 | 140 | |
andrewcrussell | 1:ecf8078bf531 | 141 | int FontDrawStringWidth( char *s, font *font_ptr ) |
andrewcrussell | 1:ecf8078bf531 | 142 | { |
andrewcrussell | 1:ecf8078bf531 | 143 | int str_width = 0; |
andrewcrussell | 1:ecf8078bf531 | 144 | char c; |
andrewcrussell | 1:ecf8078bf531 | 145 | |
andrewcrussell | 1:ecf8078bf531 | 146 | while ( c = *s++ ) |
andrewcrussell | 1:ecf8078bf531 | 147 | { |
andrewcrussell | 1:ecf8078bf531 | 148 | if ( ' ' == c ) |
andrewcrussell | 1:ecf8078bf531 | 149 | { |
andrewcrussell | 1:ecf8078bf531 | 150 | str_width += font_ptr->space_width; |
andrewcrussell | 1:ecf8078bf531 | 151 | } |
andrewcrussell | 1:ecf8078bf531 | 152 | else |
andrewcrussell | 1:ecf8078bf531 | 153 | { |
andrewcrussell | 1:ecf8078bf531 | 154 | str_width += font_ptr->width_table[ font_ptr->index_table[ c ] ]; |
andrewcrussell | 1:ecf8078bf531 | 155 | |
andrewcrussell | 1:ecf8078bf531 | 156 | if ( dfp.inter_char_space ) |
andrewcrussell | 1:ecf8078bf531 | 157 | str_width += dfp.inter_char_space; |
andrewcrussell | 1:ecf8078bf531 | 158 | } |
andrewcrussell | 1:ecf8078bf531 | 159 | } |
andrewcrussell | 1:ecf8078bf531 | 160 | |
andrewcrussell | 1:ecf8078bf531 | 161 | return ( str_width ); |
andrewcrussell | 1:ecf8078bf531 | 162 | } |
andrewcrussell | 1:ecf8078bf531 | 163 | |
andrewcrussell | 1:ecf8078bf531 | 164 | |
andrewcrussell | 1:ecf8078bf531 | 165 | unsigned char pad[ 90 * 120 ]; |
andrewcrussell | 1:ecf8078bf531 | 166 | |
andrewcrussell | 1:ecf8078bf531 | 167 | |
andrewcrussell | 1:ecf8078bf531 | 168 | int FontDrawChar( char c, int xpos, int ypos, int f_color, int b_color, font *font_ptr ) |
andrewcrussell | 1:ecf8078bf531 | 169 | { |
andrewcrussell | 1:ecf8078bf531 | 170 | unsigned char index; |
andrewcrussell | 1:ecf8078bf531 | 171 | unsigned int offset; |
andrewcrussell | 1:ecf8078bf531 | 172 | int width; |
andrewcrussell | 1:ecf8078bf531 | 173 | int height; |
andrewcrussell | 1:ecf8078bf531 | 174 | unsigned char *data; |
andrewcrussell | 1:ecf8078bf531 | 175 | int i; |
andrewcrussell | 1:ecf8078bf531 | 176 | int j; |
andrewcrussell | 1:ecf8078bf531 | 177 | |
andrewcrussell | 1:ecf8078bf531 | 178 | index = font_ptr->index_table[ c ]; |
andrewcrussell | 1:ecf8078bf531 | 179 | offset = font_ptr->offset_table[ index ]; |
andrewcrussell | 1:ecf8078bf531 | 180 | |
andrewcrussell | 1:ecf8078bf531 | 181 | height = font_ptr->height; |
andrewcrussell | 1:ecf8078bf531 | 182 | |
andrewcrussell | 1:ecf8078bf531 | 183 | if ( ' ' == c ) |
andrewcrussell | 1:ecf8078bf531 | 184 | return ( FontDrawSpace( font_ptr->space_width, height, xpos, ypos, f_color, b_color ) ); |
andrewcrussell | 1:ecf8078bf531 | 185 | |
andrewcrussell | 1:ecf8078bf531 | 186 | width = font_ptr->width_table[ index ]; |
andrewcrussell | 1:ecf8078bf531 | 187 | |
andrewcrussell | 1:ecf8078bf531 | 188 | //#if 0 |
andrewcrussell | 1:ecf8078bf531 | 189 | // printf( "char = '%c' on %d / %d - %d / %d - %p\r\n", c, xpos, ypos, f_color, b_color, font_ptr ); |
andrewcrussell | 1:ecf8078bf531 | 190 | // printf( "c14_data_table : %p\r\n", c14_data_table ); |
andrewcrussell | 1:ecf8078bf531 | 191 | // printf( "c14_offset_table : %p\r\n", c14_offset_table ); |
andrewcrussell | 1:ecf8078bf531 | 192 | // printf( "c14_index_table : %p\r\n", c14_index_table ); |
andrewcrussell | 1:ecf8078bf531 | 193 | // printf( "c14_width_table : %p\r\n", c14_width_table ); |
andrewcrussell | 1:ecf8078bf531 | 194 | // printf( "(dfp.font_ptr->)data_table : %p\r\n", dfp.font_ptr->data_table ); |
andrewcrussell | 1:ecf8078bf531 | 195 | // printf( "font_ptr->height : %p\r\n", font_ptr->height ); |
andrewcrussell | 1:ecf8078bf531 | 196 | // printf( "font_ptr->max_width : %p\r\n", font_ptr->max_width ); |
andrewcrussell | 1:ecf8078bf531 | 197 | // printf( "font_ptr->space_width : %p\r\n", font_ptr->space_width ); |
andrewcrussell | 1:ecf8078bf531 | 198 | // printf( "font_ptr->data_table : %p\r\n", font_ptr->data_table ); |
andrewcrussell | 1:ecf8078bf531 | 199 | // printf( "font_ptr->offset_table : %p (%p)\r\n", font_ptr->offset_table, font_ptr->offset_table - (unsigned int *)font_ptr->data_table ); |
andrewcrussell | 1:ecf8078bf531 | 200 | // printf( "font_ptr->index_table : %p (%p)\r\n", font_ptr->index_table, font_ptr->index_table - font_ptr->data_table ); |
andrewcrussell | 1:ecf8078bf531 | 201 | // printf( "font_ptr->width_table : %p (%p)\r\n", font_ptr->width_table, font_ptr->width_table - font_ptr->data_table ); |
andrewcrussell | 1:ecf8078bf531 | 202 | // printf( "index = %u\r\n", index ); |
andrewcrussell | 1:ecf8078bf531 | 203 | // printf( "offset = %u\r\n", offset ); |
andrewcrussell | 1:ecf8078bf531 | 204 | // printf( "width = %u\r\n", width ); |
andrewcrussell | 1:ecf8078bf531 | 205 | // printf( "height = %u\r\n", height ); |
andrewcrussell | 1:ecf8078bf531 | 206 | // printf( "\r\n" ); |
andrewcrussell | 1:ecf8078bf531 | 207 | //#endif |
andrewcrussell | 1:ecf8078bf531 | 208 | data = (unsigned char *)(&(font_ptr->data_table[ offset ])); |
andrewcrussell | 1:ecf8078bf531 | 209 | |
andrewcrussell | 1:ecf8078bf531 | 210 | //#define CHAR_FLIP_NORMAL_HORIZONTAL |
andrewcrussell | 1:ecf8078bf531 | 211 | |
andrewcrussell | 1:ecf8078bf531 | 212 | #define CHAR_FLIP_NORMAL_VERTICAL |
andrewcrussell | 1:ecf8078bf531 | 213 | |
andrewcrussell | 1:ecf8078bf531 | 214 | for ( i = 0; i < width; i++ ) |
andrewcrussell | 1:ecf8078bf531 | 215 | { |
andrewcrussell | 1:ecf8078bf531 | 216 | for ( j = 0; j < height; j++ ) |
andrewcrussell | 1:ecf8078bf531 | 217 | { |
andrewcrussell | 1:ecf8078bf531 | 218 | #if defined( CHAR_FLIP_NORMAL_HORIZONTAL ) && !defined( CHAR_FLIP_NORMAL_VERTICAL ) |
andrewcrussell | 1:ecf8078bf531 | 219 | *(pad + (j * width) + ((width - 1) - i)) = (*(data + (i * ((height + 7) / 8)) + (j / 8)) << (j % 8)) & 0x80 ? 'F' : 'B'; |
andrewcrussell | 1:ecf8078bf531 | 220 | #elif !defined( CHAR_FLIP_NORMAL_HORIZONTAL ) && defined( CHAR_FLIP_NORMAL_VERTICAL ) |
andrewcrussell | 1:ecf8078bf531 | 221 | *(pad + (((height - 1) - j) * width) + i) = (*(data + (i * ((height + 7) / 8)) + (j / 8)) << (j % 8)) & 0x80 ? 'F' : 'B'; |
andrewcrussell | 1:ecf8078bf531 | 222 | #elif defined( CHAR_FLIP_NORMAL_HORIZONTAL ) && defined( CHAR_FLIP_NORMAL_VERTICAL ) |
andrewcrussell | 1:ecf8078bf531 | 223 | *(pad + (((height - 1) - j) * width) + ((width - 1) - i)) = (*(data + (i * ((height + 7) / 8)) + (j / 8)) << (j % 8)) & 0x80 ? 'F' : 'B'; |
andrewcrussell | 1:ecf8078bf531 | 224 | #else |
andrewcrussell | 1:ecf8078bf531 | 225 | *(pad + (j * width) + i) = (*(data + (i * ((height + 7) / 8)) + (j / 8)) << (j % 8)) & 0x80 ? 'F' : 'B'; |
andrewcrussell | 1:ecf8078bf531 | 226 | #endif |
andrewcrussell | 1:ecf8078bf531 | 227 | |
andrewcrussell | 1:ecf8078bf531 | 228 | |
andrewcrussell | 1:ecf8078bf531 | 229 | |
andrewcrussell | 1:ecf8078bf531 | 230 | #if 0 |
andrewcrussell | 1:ecf8078bf531 | 231 | #if 0 |
andrewcrussell | 1:ecf8078bf531 | 232 | *(pad + (j * width) + i) = (*(data + (i * ((height + 7) / 8)) + (j / 8)) << (j % 8)) & 0x80 ? 'F' : 'B'; |
andrewcrussell | 1:ecf8078bf531 | 233 | #else |
andrewcrussell | 1:ecf8078bf531 | 234 | *(pad + (((height - 1) - j) * width) + i) = (*(data + (i * ((height + 7) / 8)) + (j / 8)) << (j % 8)) & 0x80 ? 'F' : 'B'; |
andrewcrussell | 1:ecf8078bf531 | 235 | #endif |
andrewcrussell | 1:ecf8078bf531 | 236 | #endif |
andrewcrussell | 1:ecf8078bf531 | 237 | } |
andrewcrussell | 1:ecf8078bf531 | 238 | } |
andrewcrussell | 1:ecf8078bf531 | 239 | |
andrewcrussell | 1:ecf8078bf531 | 240 | if ( dfp.alpha_mode ) |
andrewcrussell | 1:ecf8078bf531 | 241 | put_pixcels_alpha( xpos, width, ypos, height, pad, f_color, b_color ); |
andrewcrussell | 1:ecf8078bf531 | 242 | else |
andrewcrussell | 1:ecf8078bf531 | 243 | put_pixcels( xpos, width, ypos, height, pad, f_color, b_color ); |
andrewcrussell | 1:ecf8078bf531 | 244 | |
andrewcrussell | 1:ecf8078bf531 | 245 | if ( dfp.inter_char_space ) |
andrewcrussell | 1:ecf8078bf531 | 246 | width += FontDrawSpace( dfp.inter_char_space, height, xpos + width, ypos, f_color, b_color ); |
andrewcrussell | 1:ecf8078bf531 | 247 | |
andrewcrussell | 1:ecf8078bf531 | 248 | return ( width ); |
andrewcrussell | 1:ecf8078bf531 | 249 | } |
andrewcrussell | 1:ecf8078bf531 | 250 | |
andrewcrussell | 1:ecf8078bf531 | 251 | |
andrewcrussell | 1:ecf8078bf531 | 252 | int FontDrawSpace( int width, int height, int xpos, int ypos, int f_color, int b_color ) |
andrewcrussell | 1:ecf8078bf531 | 253 | { |
andrewcrussell | 1:ecf8078bf531 | 254 | int i; |
andrewcrussell | 1:ecf8078bf531 | 255 | unsigned char pad[ width * height ]; |
andrewcrussell | 1:ecf8078bf531 | 256 | |
andrewcrussell | 1:ecf8078bf531 | 257 | if ( dfp.alpha_mode ) |
andrewcrussell | 1:ecf8078bf531 | 258 | return ( width ); |
andrewcrussell | 1:ecf8078bf531 | 259 | |
andrewcrussell | 1:ecf8078bf531 | 260 | for ( i = 0; i < width * height; i++ ) |
andrewcrussell | 1:ecf8078bf531 | 261 | *(pad + i) = b_color; |
andrewcrussell | 1:ecf8078bf531 | 262 | |
andrewcrussell | 1:ecf8078bf531 | 263 | put_pixcels( xpos, width, ypos, height, pad, f_color, b_color ); |
andrewcrussell | 1:ecf8078bf531 | 264 | |
andrewcrussell | 1:ecf8078bf531 | 265 | return ( width ); |
andrewcrussell | 1:ecf8078bf531 | 266 | } |
andrewcrussell | 1:ecf8078bf531 | 267 | |
andrewcrussell | 1:ecf8078bf531 | 268 | |
andrewcrussell | 1:ecf8078bf531 | 269 | void FontDrawString( char *s, int xpos, int ypos, int f_color, int b_color, font *font_ptr ) |
andrewcrussell | 1:ecf8078bf531 | 270 | { |
andrewcrussell | 1:ecf8078bf531 | 271 | char c; |
andrewcrussell | 1:ecf8078bf531 | 272 | |
andrewcrussell | 1:ecf8078bf531 | 273 | while ( c = *s++ ) |
andrewcrussell | 1:ecf8078bf531 | 274 | xpos += FontDrawChar( c, xpos, ypos, f_color, b_color, font_ptr ); |
andrewcrussell | 1:ecf8078bf531 | 275 | } |
andrewcrussell | 1:ecf8078bf531 | 276 | |
andrewcrussell | 1:ecf8078bf531 | 277 | void FontDraw_SetInterCharSpace( int space ) |
andrewcrussell | 1:ecf8078bf531 | 278 | { |
andrewcrussell | 1:ecf8078bf531 | 279 | dfp.inter_char_space = space; |
andrewcrussell | 1:ecf8078bf531 | 280 | } |
andrewcrussell | 1:ecf8078bf531 | 281 | |
andrewcrussell | 1:ecf8078bf531 | 282 | |
andrewcrussell | 1:ecf8078bf531 | 283 | void FontDraw_SetAlphaMode( int mode ) |
andrewcrussell | 1:ecf8078bf531 | 284 | { |
andrewcrussell | 1:ecf8078bf531 | 285 | dfp.alpha_mode = mode; |
andrewcrussell | 1:ecf8078bf531 | 286 | } |
andrewcrussell | 1:ecf8078bf531 | 287 | |
andrewcrussell | 1:ecf8078bf531 | 288 | void FontDraw_SetFont( font f ) |
andrewcrussell | 1:ecf8078bf531 | 289 | { |
andrewcrussell | 1:ecf8078bf531 | 290 | dfp.font_ptr = &f; |
andrewcrussell | 1:ecf8078bf531 | 291 | } |
andrewcrussell | 1:ecf8078bf531 | 292 | |
andrewcrussell | 1:ecf8078bf531 | 293 | void FontDraw_SetForegroundColor( int v ) |
andrewcrussell | 1:ecf8078bf531 | 294 | { |
andrewcrussell | 1:ecf8078bf531 | 295 | dfp.f_color = v; |
andrewcrussell | 1:ecf8078bf531 | 296 | } |
andrewcrussell | 1:ecf8078bf531 | 297 | |
andrewcrussell | 1:ecf8078bf531 | 298 | void FontDraw_SetBackgroundColor( int v ) |
andrewcrussell | 1:ecf8078bf531 | 299 | { |
andrewcrussell | 1:ecf8078bf531 | 300 | dfp.b_color = v; |
andrewcrussell | 1:ecf8078bf531 | 301 | } |
andrewcrussell | 1:ecf8078bf531 | 302 | |
andrewcrussell | 1:ecf8078bf531 | 303 | void FontDraw_puts( int x, int y, char *s ) |
andrewcrussell | 1:ecf8078bf531 | 304 | { |
andrewcrussell | 1:ecf8078bf531 | 305 | FontDrawString( s, x, y, dfp.f_color, dfp.b_color, dfp.font_ptr ); |
andrewcrussell | 1:ecf8078bf531 | 306 | } |
andrewcrussell | 1:ecf8078bf531 | 307 | |
andrewcrussell | 1:ecf8078bf531 | 308 | |
andrewcrussell | 1:ecf8078bf531 | 309 | #include <stdarg.h> |
andrewcrussell | 1:ecf8078bf531 | 310 | |
andrewcrussell | 1:ecf8078bf531 | 311 | void FontDraw_printf( int x, int y, char *format, ... ) |
andrewcrussell | 1:ecf8078bf531 | 312 | { |
andrewcrussell | 1:ecf8078bf531 | 313 | char s[ 80 ]; |
andrewcrussell | 1:ecf8078bf531 | 314 | va_list args; |
andrewcrussell | 1:ecf8078bf531 | 315 | |
andrewcrussell | 1:ecf8078bf531 | 316 | va_start( args, format ); |
andrewcrussell | 1:ecf8078bf531 | 317 | vsnprintf( s, 32, format, args ); |
andrewcrussell | 1:ecf8078bf531 | 318 | va_end( args ); |
andrewcrussell | 1:ecf8078bf531 | 319 | |
andrewcrussell | 1:ecf8078bf531 | 320 | FontDraw_puts( x, y, s ); |
andrewcrussell | 1:ecf8078bf531 | 321 | } |