Example #1
0
void create_font_symbols(Board *b){
    ALLEGRO_BITMAP *bmp = NULL, *currbuf = al_get_target_bitmap();
    ALLEGRO_FONT *newfont=NULL;
    int i, j;
    int texth = al_get_font_line_height(b->text_font);
    int bitmap_w, bitmap_h;
    int bw = al_get_bitmap_width(b->clue_unit_bmp[0][0]);
    int bh = al_get_bitmap_height(b->clue_unit_bmp[0][0]);
    int nbw, nbh;
    int range[2];
    al_set_target_bitmap(NULL);
    nbw = bw*(float)texth/bh;
    nbh = texth;
    
    bitmap_w = 4 + b->n*(2+nbw); // extra column for buttons, n>=4
    bitmap_h = 4 + (b->h+1)*(2+nbh);
    
    bmp = al_create_bitmap(bitmap_w, bitmap_h);
    al_set_target_bitmap(bmp);
    al_clear_to_color(NULL_COLOR);
    for(j=0; j<b->h; j++){
        for(i=0; i<b->n; i++){
        // the rectangle is to guarantee the right height for al_grab_font
            al_draw_scaled_bitmap(b->clue_unit_bmp[j][i], 0, 0, bw, bh, 2+i*(2+nbw), 2+ j*(2+nbh), nbw, nbh, 0);
            al_draw_rectangle( 2+i*(2+nbw)+0.5, 2+ j*(2+nbh) + 0.5,  2+i*(2+nbw) + nbw -0.5, 2+j*(2+nbh) + nbh- 0.5, al_map_rgba(1,1,1,1),1);
        }
    }
    
 //    draw the buttons. now j= b->h
    for(i=0;i<b->n;i++){
        bw=al_get_bitmap_width(b->button_bmp[i%4]);
        bh=al_get_bitmap_height(b->button_bmp[i%4]);
        al_draw_scaled_bitmap(b->button_bmp[i%4], 0, 0, bw, bh, 2+i*(2+nbw), 2+ j*(2+nbh), nbw, nbh, 0);
        al_draw_rectangle( 2+i*(2+nbw)+0.5, 2+ j*(2+nbh) + 0.5,  2+i*(2+nbw) + nbw -0.5, 2+j*(2+nbh) + nbh- 0.5, al_map_rgba(1,1,1,1),1);
    }
    
    
    range[0] = BF_CODEPOINT_START;
    range[1] = BF_CODEPOINT_START + b->n*b->h-1 + 4;
    newfont = al_grab_font_from_bitmap(bmp, 1, range);
    al_set_fallback_font(b->text_font, newfont);
    al_set_target_bitmap(currbuf);
    al_destroy_bitmap(bmp);
}
Example #2
0
int main(int argc, char **argv)
{
    ALLEGRO_DISPLAY *display;
    ALLEGRO_TIMER *timer;
    ALLEGRO_EVENT_QUEUE *queue;
    int redraw = 0;
    double t = 0;

    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
    }

    open_log_monospace();

    al_init_primitives_addon();
    al_install_mouse();
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_image_addon();
    init_platform_specific();

#ifdef ALLEGRO_IPHONE
    al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
#endif
    display = al_create_display(640, 480);
    if (!display) {
        abort_example("Could not create display.\n");
    }
    al_install_keyboard();

    if (argc >= 2) {
        font_file = argv[1];
    }

    ex.f1 = al_load_font(font_file, 48, 0);
    ex.f2 = al_load_font(font_file, 48, ALLEGRO_TTF_NO_KERNING);
    ex.f3 = al_load_font(font_file, 12, 0);
    /* Specifying negative values means we specify the glyph height
     * in pixels, not the usual font size.
     */
    ex.f4 = al_load_font(font_file, -140, 0);
    ex.f5 = al_load_font(font_file, 12, ALLEGRO_TTF_MONOCHROME);

    {
        int ranges[] = {0x1F40A, 0x1F40A};
        ALLEGRO_BITMAP *icon = al_load_bitmap("data/icon.png");
		if (!icon) {
			abort_example("Couldn't load data/icon.png.\n");
		}
        ALLEGRO_BITMAP *glyph = al_create_bitmap(50, 50);
        al_set_target_bitmap(glyph);
        al_clear_to_color(al_map_rgba_f(0, 0, 0, 0));
        al_draw_rectangle(0.5, 0.5, 49.5, 49.5, al_map_rgb_f(1, 1, 0),
         1);
        al_draw_bitmap(icon, 1, 1, 0);
        al_set_target_backbuffer(display);
        ex.f_alex = al_grab_font_from_bitmap(glyph, 1, ranges);
    }

    if (!ex.f1 || !ex.f2 || !ex.f3 || !ex.f4 || !ex.f_alex) {
        abort_example("Could not load font: %s\n", font_file);
    }

    al_set_fallback_font(ex.f3, ex.f_alex);

    ex.ranges_count = al_get_font_ranges(ex.f1, 0, NULL);
    print_ranges(ex.f1);

    ex.config = al_load_config_file("data/ex_ttf.ini");
    if (!ex.config) {
        abort_example("Could not data/ex_ttf.ini\n");
    }

    timer = al_create_timer(1.0 / 60);

    queue = al_create_event_queue();
    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    al_start_timer(timer);
    while (true) {
        ALLEGRO_EVENT event;
        al_wait_for_event(queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
            break;
        if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
                event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            break;
        }
        if (event.type == ALLEGRO_EVENT_TIMER)
            redraw++;

        while (redraw > 0 && al_is_event_queue_empty(queue)) {
            double dt;
            redraw--;

            dt = al_get_time();
            render();
            dt = al_get_time() - dt;

            t = 0.99 * t + 0.01 * dt;

            ex.fps = 1.0 / t;
            al_flip_display();
        }
    }

    al_destroy_font(ex.f1);
    al_destroy_font(ex.f2);
    al_destroy_font(ex.f3);
    al_destroy_font(ex.f4);
    al_destroy_font(ex.f5);
    al_destroy_config(ex.config);

    close_log(false);

    return 0;
}