Beispiel #1
0
/* Test al_utf8_encode. */
static void t18(void)
{
   char buf[4];

   CHECK(al_utf8_encode(buf, 0) == 1);
   CHECK(0 == memcmp(buf, "\x00", 1));

   CHECK(al_utf8_encode(buf, 0x7f) == 1);
   CHECK(0 == memcmp(buf, "\x7f", 1));

   CHECK(al_utf8_encode(buf, 0x80) == 2);
   CHECK(0 == memcmp(buf, "\xC2\x80", 2));

   CHECK(al_utf8_encode(buf, 0x7ff) == 2);
   CHECK(0 == memcmp(buf, "\xDF\xBF", 2));

   CHECK(al_utf8_encode(buf, 0x000800) == 3);
   CHECK(0 == memcmp(buf, "\xE0\xA0\x80", 3));

   CHECK(al_utf8_encode(buf, 0x00ffff) == 3);
   CHECK(0 == memcmp(buf, "\xEF\xBF\xBF", 3));

   CHECK(al_utf8_encode(buf, 0x010000) == 4);
   CHECK(0 == memcmp(buf, "\xF0\x90\x80\x80", 4));

   CHECK(al_utf8_encode(buf, 0x10ffff) == 4);
   CHECK(0 == memcmp(buf, "\xF4\x8f\xBF\xBF", 4));

   /* These are illegal. */
   CHECK(al_utf8_encode(buf, 0x110000) == 0);
   CHECK(al_utf8_encode(buf, 0xffffff) == 0);
}
Beispiel #2
0
/* Function: al_ustr_rfind_chr
 */
int al_ustr_rfind_chr(const ALLEGRO_USTR *us, int end_pos, int32_t c)
{
   char encc[4];
   size_t sizec;
   struct _al_tagbstring enctb;
   int rc;

   /* Fast path for ASCII characters. */
   if (c < 128) {
      rc = _al_bstrrchrp(us, c, end_pos - 1);
      return (rc == _AL_BSTR_ERR) ? -1 : rc;
   }

   /* Non-ASCII.  We can simply encode the character into a string and search
    * for that.
    */

   sizec = al_utf8_encode(encc, c);
   if (!sizec) {
      al_set_errno(EINVAL);
      return -1; /* error */
   }

   _al_blk2tbstr(enctb, encc, sizec);
   rc = _al_binstrr(us, end_pos - sizec, &enctb);
   return (rc == _AL_BSTR_ERR) ? -1 : rc;
}
Beispiel #3
0
/* Function: al_ustr_set_chr
 */
size_t al_ustr_set_chr(ALLEGRO_USTR *us, int start_pos, int32_t c)
{
   int32_t oldc;
   size_t oldw;
   size_t neww;
   int rc;

   oldc = al_ustr_get(us, start_pos);
   if (oldc == -2)
      return 0;

   oldw = al_utf8_width(oldc);
   neww = al_utf8_width(c);
   if (neww == 0)
      return 0;

   if (oldw > neww)
      rc = _al_bdelete(us, start_pos, oldw - neww);
   else if (neww > oldw)
      rc = _al_binsertch(us, start_pos, neww - oldw, '\0');
   else
      rc = _AL_BSTR_OK;

   if (rc == _AL_BSTR_OK)
      return al_utf8_encode(_al_bdataofs(us, start_pos), c);
   else
      return 0;
}
Beispiel #4
0
static void log_key(char const *how, int keycode, int unichar, int modifiers)
{
   char multibyte[5] = {0, 0, 0, 0, 0};
   const char* key_name;

   al_utf8_encode(multibyte, unichar <= 32 ? ' ' : unichar);
   key_name = al_keycode_to_name(keycode);
   log_printf("%-8s  code=%03d, char='%s' (%4d), modifiers=%08x, [%s]\n",
      how, keycode, multibyte, unichar, modifiers, key_name);
}
Beispiel #5
0
/* Function: al_ustr_insert_chr
 */
size_t al_ustr_insert_chr(ALLEGRO_USTR *us, int pos, int32_t c)
{
   uint32_t uc = c;
   size_t sz;

   if (uc < 128) {
      return (_al_binsertch(us, pos, 1, uc) == _AL_BSTR_OK) ? 1 : 0;
   }

   sz = al_utf8_width(c);
   if (_al_binsertch(us, pos, sz, '\0') == _AL_BSTR_OK) {
      return al_utf8_encode(_al_bdataofs(us, pos), c);
   }

   return 0;
}
Beispiel #6
0
int init_bitmaps(Board *b){
    // will load bitmaps from folders named 0, 1,..., 7
    // inside the folder "icons", each containing 8 square bitmaps
    int i,j, k=0;
    char pathname[1000];
    ALLEGRO_PATH *path;
    ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
    al_set_target_bitmap(NULL); // this is a workaround for android -- try removing later
    
#ifdef ALLEGRO_ANDROID
    al_android_set_apk_file_interface();
#endif

    al_set_target_bitmap(dispbuf);

    for(i=0;i<b->h+1;i++){
        for(j=0;j<b->n; j++){
            al_utf8_encode(symbol_char[i][j], BF_CODEPOINT_START+ j + i*b->n);
            symbol_char[i][j][al_utf8_width(BF_CODEPOINT_START+ j + i*b->n)] = '\0';
        }
    }
    
    // create buttons
    // xxx todo: improve these
    
    default_font = al_load_font(DEFAULT_FONT_FILE, 16, 0);
    if(!default_font) errlog("Error loading default font");
    
    b->info_text_bmp = NULL;
    b->info_panel.bmp = NULL;
    
    // if this fails, buttons will be created anyway at update_bitmaps
    b->button_bmp[0] = al_load_bitmap("buttons/light-bulb.png");
    b->button_bmp[1] = al_load_bitmap("buttons/question.png");
    b->button_bmp[2] = al_load_bitmap("buttons/gear.png");
    b->button_bmp[3] = al_load_bitmap("buttons/undo.png");
    
    if(b->type_of_tiles == 2)
        return init_bitmaps_classic(b);
    
    if(b->type_of_tiles == 1){ // use bitmaps
#ifndef ALLEGRO_ANDROID
        path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
        al_path_cstr(path, '/');
#else
        path = al_create_path("");
#endif
        for(j=0; j<b->h; j++){
            for(k=0; k<b->n; k++){
                snprintf(pathname, 999, "%sicons/%d/%d.png", al_path_cstr(path, '/'), j, k);
                basic_bmp[j][k] = al_load_bitmap(pathname);
                if(!basic_bmp[j][k]){
                    errlog("Error loading %s.", pathname);
                    unload_basic_bmps(b, j,k-1);
                    al_destroy_path(path);
                    return -1;
                }
            }
        }
        al_destroy_path(path);
    }
    
    // create symbols (alternatively we could load these from files!))
    symbol_bmp[SYM_FORBIDDEN] = al_create_bitmap(256, 256);
    symbol_bmp[SYM_SWAPPABLE] = al_create_bitmap(3*256 + 2*b->clue_unit_space, 256);
    symbol_bmp[SYM_ONE_SIDE] = al_create_bitmap(256, 256);
    symbol_bmp[SYM_ONLY_ONE] = al_create_bitmap(256, 3*256);

    if( (!symbol_bmp[SYM_FORBIDDEN]) || (!symbol_bmp[SYM_SWAPPABLE]) || (!symbol_bmp[SYM_ONE_SIDE]) || !symbol_bmp[SYM_ONLY_ONE]){
        fprintf(stderr, "Error creating bitmap.\n");
        return -1;
    }
    al_set_target_bitmap(symbol_bmp[SYM_FORBIDDEN]);
    al_clear_to_color(NULL_COLOR);
    al_draw_line(1, 1, 254, 254, al_map_rgba_f(1,0,0,0.5),4);
    al_draw_line(1, 254, 254, 1, al_map_rgba_f(1,0,0,0.5),4);
    
    al_set_target_bitmap(symbol_bmp[SYM_SWAPPABLE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_line(256*0.7,256*0.9, 256*(3-0.7),256*0.9, al_map_rgba_f(1,0,0,0.5), 2);
    al_draw_filled_triangle(256*0.5,256*0.9, 256*0.7,256, 256*0.7, 256*0.8, al_map_rgba_f(1,0,0,0.35));
    
    
    al_set_target_bitmap(symbol_bmp[SYM_ONE_SIDE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_filled_circle(256/2, 256/2, 0.03*256, WHITE_COLOR);
    al_draw_filled_circle(256/2 - 0.2*256, 256/2, 0.03*256, WHITE_COLOR);
    al_draw_filled_circle(256/2 + 0.2*256, 256/2, 0.03*256, WHITE_COLOR);

    al_set_target_bitmap(symbol_bmp[SYM_ONLY_ONE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_filled_triangle(256*0.3, 256, 256*0.7, 256, 256*0.5, 256*0.7, al_map_rgba_f(1,0,0,0.5));
    al_draw_filled_triangle(256*0.3, 256, 256*0.7, 256, 256*0.5, 256*1.3, al_map_rgba_f(1,0,0,0.5));
    al_draw_line(256*0.5, 256*0.8, 256*0.5, 256*1.2, WHITE_COLOR, 3);

    al_set_target_bitmap(dispbuf);
    return 0;
}