示例#1
0
文件: font.c 项目: catompiler/avrlibs
void font_puts(font_t* font, graphics_t* graphics, graphics_pos_t x, graphics_pos_t y, const char* s)
{
    if(x >= (graphics_pos_t)graphics_width(graphics) ||
            y >= (graphics_pos_t)graphics_height(graphics)) return;
    
    uint8_t tabs_count = 0;
    graphics_pos_t orig_x = x;
    while(*s){
        switch(*s){
            case '\r':
                x = orig_x;
                s ++;
                break;
            case '\n':
                x = orig_x;
                y += font->symbol_height + font->vspace;
                s ++;
                break;
            case '\t':
                font_putc(font, graphics, x, y, 0x20);
                x += font->symbol_width + font->hspace;
                if(++ tabs_count == FONT_TAB_SIZE){
                    tabs_count = 0;
                    s ++;
                }
                break;
            default:
                font_putc(font, graphics, x, y, *s);
                x += font->symbol_width + font->hspace;
                s ++;
                break;
        }
        if(y >= (graphics_pos_t)graphics_width(graphics)) break;
    }
}
示例#2
0
文件: window.c 项目: NunyaOS/Nunya
static inline void window_set_bounds(struct window *win, int x, int y, int w, int h) {
    // check if bounds_x_1 ... y_2 are -1.
    // if so, do calculation. otherwise, do nothing
    win->bounds_x_1 = x < 0 ? 0 : x;
    win->bounds_x_2 = x + w >= graphics_width() ? graphics_width() - 1 : x + w;
    win->bounds_y_1 = y < 0 ? 0 : y;
    win->bounds_y_2 = y + h >= graphics_height() ? graphics_height() - 1 : y + h;
}
示例#3
0
void console_init()
{
	xsize = graphics_width()/8;
	ysize = graphics_height()/8;
	console_reset();
	console_putstring("\nconsole: initialized\n");
}
示例#4
0
bool font_bitmap_get_char_position(const font_t* font, const font_bitmap_t* font_bitmap, font_char_t c, rect_t* rect, point_t* offset)
{
    if(font_bitmap == NULL) return false;
    if(c < font_bitmap_first_char(font_bitmap) || c > font_bitmap_last_char(font_bitmap)) return false;
    if(rect == NULL && offset == NULL) return false;
    
    size_t char_index = c - font_bitmap_first_char(font_bitmap);
    
    if(font_bitmap->char_descrs){
        const font_char_descr_t* descr = &font_bitmap->char_descrs[char_index];
        if(rect) rect_init_position(rect, descr->x, descr->y, descr->x + descr->width - 1, descr->y + descr->height - 1);
        if(offset) point_init_position(offset, descr->offset_x, descr->offset_y);
    }else{
        size_t char_pos = (char_index) * font_char_width(font);

        graphics_pos_t x = char_pos % graphics_width(font_bitmap_graphics(font_bitmap));
        graphics_pos_t y = char_pos / graphics_width(font_bitmap_graphics(font_bitmap));

        if(rect) rect_init_position(rect, x, y, x + font_char_width(font) - 1, y + font_char_height(font) - 1);
        if(offset) point_init_position(offset, 0, 0);
    }

    return true;
}