示例#1
0
static void render(void)
{
    ALLEGRO_COLOR white = al_map_rgba_f(1, 1, 1, 1);
    ALLEGRO_COLOR black = al_map_rgba_f(0, 0, 0, 1);
    ALLEGRO_COLOR red = al_map_rgba_f(1, 0, 0, 1);
    ALLEGRO_COLOR green = al_map_rgba_f(0, 0.5, 0, 1);
    ALLEGRO_COLOR blue = al_map_rgba_f(0.1, 0.2, 1, 1);
    ALLEGRO_COLOR purple = al_map_rgba_f(0.3, 0.1, 0.2, 1);
    int x, y, w, h, as, de, xpos, ypos;
    unsigned int index;
    int target_w, target_h;
    ALLEGRO_USTR_INFO info, sub_info;
    const ALLEGRO_USTR *u;
    ALLEGRO_USTR *tulip = al_ustr_new("Tulip");
    ALLEGRO_USTR *dimension_text = al_ustr_new("Tulip");
    ALLEGRO_USTR *vertical_text  = al_ustr_new("Rose.");

    al_clear_to_color(white);

    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f1, black, 50,  20, 0, "Tulip (kerning)");
    al_draw_textf(ex.f2, black, 50,  80, 0, "Tulip (no kerning)");

    x = 50;
    y = 140;
    for (index = 0; index < al_ustr_length(dimension_text); index ++) {
       int cp  = ustr_at(dimension_text, index);
       int bbx, bby, bbw, bbh;
       al_get_glyph_dimensions(ex.f2, cp, &bbx, &bby, &bbw, &bbh);
       al_draw_rectangle(x + bbx + 0.5, y + bby + 0.5, x + bbx + bbw - 0.5, y + bby + bbh - 0.5, blue, 1);
       al_draw_rectangle(x + 0.5, y + 0.5, x + bbx + bbw - 0.5, y + bby + bbh - 0.5, green, 1);
       al_draw_glyph(ex.f2, purple, x, y, cp);
       x += al_get_glyph_advance(ex.f2, cp, ALLEGRO_NO_KERNING);
    }
    al_draw_line(50.5, y+0.5, x+0.5, y+0.5, red, 1);
    al_draw_textf(ex.f2, black, x + 10, y, 0, "(dimensions)");

    al_draw_textf(ex.f3, black, 50, 200, 0, "This font has a size of 12 pixels, "
        "the one above has 48 pixels.");

    al_hold_bitmap_drawing(false);
    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f3, red, 50, 220, 0, "The color can simply be changed.🐊← fallback glyph");

    al_hold_bitmap_drawing(false);
    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f3, green, 50, 240, 0, "Some unicode symbols:");
    al_draw_textf(ex.f3, green, 50, 260, 0, "%s", get_string("symbols1"));
    al_draw_textf(ex.f3, green, 50, 280, 0, "%s", get_string("symbols2"));
    al_draw_textf(ex.f3, green, 50, 300, 0, "%s", get_string("symbols3"));

   #define OFF(x) al_ustr_offset(u, x)
   #define SUB(x, y) al_ref_ustr(&sub_info, u, OFF(x), OFF(y))
    u = al_ref_cstr(&info, get_string("substr1"));
    al_draw_ustr(ex.f3, green, 50, 320, 0, SUB(0, 6));
    u = al_ref_cstr(&info, get_string("substr2"));
    al_draw_ustr(ex.f3, green, 50, 340, 0, SUB(7, 11));
    u = al_ref_cstr(&info, get_string("substr3"));
    al_draw_ustr(ex.f3, green, 50, 360, 0, SUB(4, 11));
    u = al_ref_cstr(&info, get_string("substr4"));
    al_draw_ustr(ex.f3, green, 50, 380, 0, SUB(0, 11));

    al_draw_textf(ex.f5, black, 50, 395, 0, "forced monochrome");

    /* Glyph rendering tests. */
    al_draw_textf(ex.f3, red, 50, 410, 0, "Glyph adv Tu: %d, draw: ",
                        al_get_glyph_advance(ex.f3, 'T', 'u'));
    x = 50;
    y = 425;
    for (index = 0; index < al_ustr_length(tulip); index ++) {
       int cp  = ustr_at(tulip, index);
       /* Use al_get_glyph_advance for the stride, with no kerning. */
       al_draw_glyph(ex.f3, red, x, y, cp);
       x += al_get_glyph_advance(ex.f3, cp, ALLEGRO_NO_KERNING);
    }

    x = 50;
    y = 440;
    /* First draw a red string using al_draw_text, that should be hidden
     * completely by the same text drawing in green per glyph
     * using al_draw_glyph and al_get_glyph_advance below. */
    al_draw_ustr(ex.f3, red, x, y, 0, tulip);
    for (index = 0; index < al_ustr_length(tulip); index ++) {
      int cp  = ustr_at(tulip, index);
      int ncp = (index < (al_ustr_length(tulip) - 1)) ?
         ustr_at(tulip, index + 1) : ALLEGRO_NO_KERNING;
      /* Use al_get_glyph_advance for the stride and apply kerning. */
      al_draw_glyph(ex.f3, green, x, y, cp);
      x += al_get_glyph_advance(ex.f3, cp, ncp);
    }

    x = 50;
    y = 466;
    al_draw_ustr(ex.f3, red, x, y, 0, tulip);
    for (index = 0; index < al_ustr_length(tulip); index ++) {
      int cp  = ustr_at(tulip, index);
      int bbx, bby, bbw, bbh;
      al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh);
      al_draw_glyph(ex.f3, blue, x, y, cp);
      x += bbx + bbw;
    }


    x = 10;
    y = 30;
    for (index = 0; index < al_ustr_length(vertical_text); index ++) {
      int bbx, bby, bbw, bbh;
      int cp  = ustr_at(vertical_text, index);
      /* Use al_get_glyph_dimensions for the height to apply. */
      al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh);
      al_draw_glyph(ex.f3, green, x, y, cp);
      y += bby;
      y += bbh;
    }


    x = 30;
    y = 30;
    for (index = 0; index < al_ustr_length(vertical_text); index ++) {
      int bbx, bby, bbw, bbh;
      int cp  = ustr_at(vertical_text, index);
      /* Use al_get_glyph_dimensions for the height to apply, here bby is
       * omited for the wrong result. */
      al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh);
      al_draw_glyph(ex.f3, red, x, y, cp);
      y += bbh;
    }


    al_hold_bitmap_drawing(false);

    target_w = al_get_bitmap_width(al_get_target_bitmap());
    target_h = al_get_bitmap_height(al_get_target_bitmap());

    xpos = target_w - 10;
    ypos = target_h - 10;
    al_get_text_dimensions(ex.f4, "Allegro", &x, &y, &w, &h);
    as = al_get_font_ascent(ex.f4);
    de = al_get_font_descent(ex.f4);
    xpos -= w;
    ypos -= h;
    x += xpos;
    y += ypos;

    al_draw_rectangle(x, y, x + w - 0.5, y + h - 0.5, black, 0);
    al_draw_line(x+0.5, y + as + 0.5, x + w - 0.5, y + as + 0.5, black, 0);
    al_draw_line(x + 0.5, y + as + de + 0.5, x + w - 0.5, y + as + de + 0.5, black, 0);

    al_hold_bitmap_drawing(true);
    al_draw_textf(ex.f4, blue, xpos, ypos, 0, "Allegro");
    al_hold_bitmap_drawing(false);

    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f3, black, target_w, 0, ALLEGRO_ALIGN_RIGHT,
       "%.1f FPS", ex.fps);

    al_draw_textf(ex.f3, black, 0, 0, 0, "%s: %d unicode ranges", font_file,
       ex.ranges_count);

    al_hold_bitmap_drawing(false);
}
示例#2
0
int update_font_bitmaps(Game *g, Board *b){
    int i, j, s;
    float FONT_FACTOR=1;
    ALLEGRO_FONT *tile_font1, *tile_font2, *tile_font3;
    ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
    int bbx, bby, bbw, bbh;
    
    al_set_target_bitmap(NULL);
    
    s=min(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h);
    tile_font1 = load_font_mem(tile_font_mem, TILE_FONT_FILE, -s*FONT_FACTOR);
    tile_font2 = load_font_mem(tile_font_mem, TILE_FONT_FILE, -b->panel_tile_size*FONT_FACTOR);
    tile_font3 = load_font_mem(tile_font_mem, TILE_FONT_FILE, -b->clue_unit_size*FONT_FACTOR);

    if(!tile_font1 || !tile_font2 || !tile_font3) {
        fprintf(stderr, "Error loading tile font file %s.\n", TILE_FONT_FILE);
        return -1;
    }
    
    for(i=0;i<b->h;i++){
        for(j=0;j<b->n;j++){
            b->guess_bmp[i][j] = al_create_bitmap(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h);
            b->panel_tile_bmp[i][j] = al_create_bitmap(b->panel_tile_size,b->panel_tile_size);
            b->clue_unit_bmp[i][j] = al_create_bitmap(b->clue_unit_size, b->clue_unit_size);
            if(!b->guess_bmp[i][j] || !b->panel_tile_bmp[i][j] || !b->clue_unit_bmp[i][j]){
                fprintf(stderr, "Error creating bitmap.\n");
                return -1;
            }
            
            // guessed bitmaps
            al_set_target_bitmap(b->guess_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR[i]));
            al_get_glyph_dimensions(tile_font1, CLUE_CODE[i][j][0], &bbx, &bby, &bbw, &bbh);
            if(GLYPH_SHADOWS){
                al_draw_glyph(tile_font1, DARK_GREY_COLOR, (b->panel.b[0]->b[0]->w-bbw)/2 -bbx +1,(b->panel.b[0]->b[0]->h-bbh)/2-bby+1, CLUE_CODE[i][j][0]);
            }
            al_draw_glyph(tile_font1, al_color_html(CLUE_FG_COLOR[i]), (b->panel.b[0]->b[0]->w-bbw)/2 -bbx,(b->panel.b[0]->b[0]->h-bbh)/2-bby, CLUE_CODE[i][j][0]);
            // this draws a border for all tiles, independent of the "bd" setting in b
            if(TILE_SHADOWS)
                draw_shadow(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h,2);
            else
                al_draw_rectangle(.5,.5,b->panel.b[0]->b[0]->w-.5, b->panel.b[0]->b[0]->h-.5, TILE_GENERAL_BD_COLOR,1);
            
            // panel bitmaps
    
            al_set_target_bitmap(b->panel_tile_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR[i]));
            al_get_glyph_dimensions(tile_font2, CLUE_CODE[i][j][0], &bbx, &bby, &bbw, &bbh);
            if(GLYPH_SHADOWS){
                al_draw_glyph(tile_font2, DARK_GREY_COLOR,(b->panel_tile_size -bbw)/2-bbx+1, (b->panel_tile_size - bbh)/2-bby+1, CLUE_CODE[i][j][0]);
            }
            al_draw_glyph(tile_font2, al_color_html(CLUE_FG_COLOR[i]),(b->panel_tile_size -bbw)/2-bbx, (b->panel_tile_size - bbh)/2-bby, CLUE_CODE[i][j][0]);
            if(TILE_SHADOWS)
                draw_shadow(b->panel_tile_size, b->panel_tile_size,2);
            else
                al_draw_rectangle(.5,.5,b->panel_tile_size-.5,b->panel_tile_size-.5, TILE_GENERAL_BD_COLOR,1);
            
            // clue unit tile bitmaps
            al_set_target_bitmap(b->clue_unit_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR[i]));
            al_get_glyph_dimensions(tile_font3, CLUE_CODE[i][j][0], &bbx, &bby, &bbw, &bbh);
            if(GLYPH_SHADOWS){
                al_draw_glyph(tile_font3, DARK_GREY_COLOR, (b->clue_unit_size-bbw)/2 -bbx +1,(b->clue_unit_size-bbh)/2-bby+1, CLUE_CODE[i][j][0]);
            }
            al_draw_glyph(tile_font3, al_color_html(CLUE_FG_COLOR[i]), (b->clue_unit_size-bbw)/2 -bbx,(b->clue_unit_size-bbh)/2-bby, CLUE_CODE[i][j][0]);
            if(TILE_SHADOWS)
                draw_shadow(b->clue_unit_size,b->clue_unit_size,2);
            else
                al_draw_rectangle(.5,.5,b->clue_unit_size-.5, b->clue_unit_size-.5, TILE_GENERAL_BD_COLOR,1);
        }
    }

    if(draw_symbols(g, b)) return -1;
    
    al_destroy_font(tile_font1);
    al_destroy_font(tile_font2);
    al_destroy_font(tile_font3);
    
    al_set_target_backbuffer(al_get_current_display());
    // create clue tile bmps
    al_set_target_bitmap(dispbuf);
    return make_clue_bitmaps(g, b);
    
}