コード例 #1
0
void DrawingInterfaceAllegro5::draw_ustr_chr(int32_t ustr_char, float x, float y, float align_x, float align_y, ALLEGRO_COLOR color, std::string font_family, float font_size, ALLEGRO_FONT *font)
{
   if (!font) return;
   ALLEGRO_USTR *ustr = al_ustr_new("");
   al_ustr_set_chr(ustr, 0, ustr_char);
   al_draw_ustr(font, color, x, y - al_get_font_ascent(font), ALLEGRO_FLAGS_EMPTY, ustr);
   al_ustr_free(ustr);
}
コード例 #2
0
ファイル: ex_utf8.c プロジェクト: dradtke/battlechess
/* Test al_ustr_set_chr. */
static void t42(void)
{
   ALLEGRO_USTR *us = al_ustr_new("abcdef");

   /* Same size (ASCII). */
   CHECK(al_ustr_set_chr(us, 1, 'B') == 1);
   CHECK(0 == strcmp(al_cstr(us), "aBcdef"));
   CHECK(6 == al_ustr_size(us));

   /* Enlarge to 2-bytes. */
   CHECK(al_ustr_set_chr(us, 1, U_beta) == 2);
   CHECK(0 == strcmp(al_cstr(us), "aβcdef"));
   CHECK(7 == al_ustr_size(us));

   /* Enlarge to 3-bytes. */
   CHECK(al_ustr_set_chr(us, 5, U_1d08) == 3);
   CHECK(0 == strcmp(al_cstr(us), "aβcdᴈf"));
   CHECK(9 == al_ustr_size(us));

   /* Reduce to 2-bytes. */
   CHECK(al_ustr_set_chr(us, 5, U_schwa) == 2);
   CHECK(0 == strcmp(al_cstr(us), "aβcdəf"));
   CHECK(8 == al_ustr_size(us));

   /* Set at end of string. */
   CHECK(al_ustr_set_chr(us, al_ustr_size(us), U_1ff7) == 3);
   CHECK(0 == strcmp(al_cstr(us), "aβcdəfῷ"));
   CHECK(11 == al_ustr_size(us));

   /* Set past end of string. */
   CHECK(al_ustr_set_chr(us, al_ustr_size(us) + 2, U_2051) == 3);
   CHECK(0 == memcmp(al_cstr(us), "aβcdəfῷ\0\0⁑", 16));
   CHECK(16 == al_ustr_size(us));

   /* Set before start of string (not allowed). */
   CHECK(al_ustr_set_chr(us, -1, U_2051) == 0);
   CHECK(16 == al_ustr_size(us));

   al_ustr_free(us);
}
コード例 #3
0
ファイル: keybdnu.c プロジェクト: GREYFOXRGR/allegro5
int _al_parse_key_binding(const char *s, unsigned int *modifiers)
{
   ALLEGRO_USTR *us;
   unsigned start = 0;
   int keycode = 0;

   us = al_ustr_new(s);
   al_ustr_trim_ws(us);
   *modifiers = 0;

   while (start < al_ustr_size(us)) {
      /* XXX not all keys can be bound due to a conflict with the delimiter
       * characters
       */
      int end = al_ustr_find_set_cstr(us, start, "+-");
      unsigned int mod;

      /* Last component must be a key. */
      if (end == -1) {
         keycode = match_key_name(al_cstr(us) + start);
         break;
      }

      /* Otherwise must be a modifier. */
      al_ustr_set_chr(us, end, '\0');
      mod = match_modifier(al_cstr(us) + start);
      if (!mod) {
         break;
      }
      (*modifiers) |= mod;
      start = end + 1;
   }

   al_ustr_free(us);

   return keycode;
}
コード例 #4
0
ファイル: ex_logo.c プロジェクト: dradtke/battlechess
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_TIMER *timer;
   ALLEGRO_EVENT_QUEUE *queue;
   int redraw = 0, i;
   bool quit = false;

   if (!al_init()) {
      abort_example("Could not initialise Allegro\n");
      return 1;
   }
   al_init_primitives_addon();
   al_install_mouse();
   al_init_image_addon();
   al_init_font_addon();
   al_init_ttf_addon();
   srand(time(NULL));

   white = al_map_rgba_f(1, 1, 1, 1);

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Could not create display\n");
      return 1;
   }
   al_set_window_title(display, "Allegro Logo Generator");
   al_install_keyboard();

   /* Read logo parameters from logo.ini (if it exists). */
   config = al_load_config_file("logo.ini");
   if (!config)
      config = al_create_config();
   for (i = 0; param_names[i]; i++) {
      char const *value = al_get_config_value(config, "logo", param_names[i]);
      if (value)
         strncpy(param_values[i], value, sizeof(param_values[i]));
   }

   font = al_load_font("data/DejaVuSans.ttf", 12, 0);
   if (!font) {
      abort_example("Could not load font\n");
      return 1;
   }

   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_mouse_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 (!quit) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);
      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
         break;
      if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
         if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            quit = true;
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_ENTER) {
            if (editing) {
               regenerate = true;
               editing = false;
            }
            else {
               cursor = 0;
               editing = true;
            }
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_UP) {
            if (selection > 0) {
               selection--;
               cursor = 0;
               editing = false;
            }
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_DOWN) {
            if (param_names[selection + 1]) {
               selection++;
               cursor = 0;
               editing = false;
            }
         }
         else {
            int c = event.keyboard.unichar;
            if (editing) {
               if (c >= 32) {
                  ALLEGRO_USTR *u = al_ustr_new(param_values[selection]);
                  al_ustr_set_chr(u, cursor, c);
                  cursor++;
                  al_ustr_set_chr(u, cursor, 0);
                  strncpy(param_values[selection], al_cstr(u),
                     sizeof param_values[selection]);
                  al_ustr_free(u);
               }
            }
            else {
               if (c == 'r')
                  randomize();
               if (c == 's')
                  save();
            }
         }
      }
      if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
         if (event.mouse.button == 1) {
            mouse_click(event.mouse.x, event.mouse.y);
         }
      }
      if (event.type == ALLEGRO_EVENT_TIMER)
         redraw++;

      if (redraw && al_is_event_queue_empty(queue)) {
         redraw = 0;

         render();

         al_flip_display();
      }
   }

   /* Write modified parameters back to logo.ini. */
   for (i = 0; param_names[i]; i++) {
      al_set_config_value(config, "logo", param_names[i],
         param_values[i]);
   }
   al_save_config_file("logo.ini", config);
   al_destroy_config(config);

   return 0;
}
コード例 #5
0
static void ustr_replace_all(ALLEGRO_USTR *ustr, int32_t c1, int32_t c2)
{
	for (int i = al_ustr_find_chr(ustr, 0, c1); i >= 0; i = al_ustr_find_chr(ustr, i, c1)) {
		al_ustr_set_chr(ustr, i, c2);
	}
}