Example #1
0
//loads a bitmap from a file
static ALLEGRO_BITMAP *_load_bitmap(ALGUI_SKIN *skin, const char *filename) {
    ALLEGRO_USTR *filepath;
    ALLEGRO_BITMAP *bmp;
    
    //if the filename is null
    if (!filename) return NULL;
    
    //get the resource's filepath
    filepath = _get_resource_filepath(skin->filename, filename);
    
    //empty filepath
    if (!filepath) return NULL;
    
    //load the bitmap
    bmp = al_load_bitmap(al_cstr(filepath));
    
    //bitmap cannot be loaded
    if (!bmp) {
        al_ustr_free(filepath);
        return NULL;
    }        
    
    //install a resource
    if (!algui_install_resource(bmp, al_cstr(filepath), algui_bitmap_resource_destructor)) {
        al_destroy_bitmap(bmp);
        al_ustr_free(filepath);
        return NULL;
    }
    
    //success
    return bmp;
}
Example #2
0
//loads a font from a file
static ALLEGRO_FONT *_load_font(ALGUI_SKIN *skin, const char *filename, unsigned int size, unsigned int flags) {
    ALLEGRO_USTR *filepath;
    ALLEGRO_FONT *font;
    
    //if the filename is null
    if (!filename) return NULL;
    
    //get the resource's filepath
    filepath = _get_resource_filepath(skin->filename, filename);
    
    //empty filepath
    if (!filepath) return NULL;
    
    //load the font
    font = al_load_font(al_cstr(filepath), size, flags);
    
    //the font cannot be loaded
    if (!font) {
        al_ustr_free(filepath);
        return NULL;
    }        
    
    //install a resource
    if (!algui_install_resource(font, al_cstr(filepath), algui_font_resource_destructor)) {
        al_destroy_font(font);
        al_ustr_free(filepath);
        return NULL;
    }
    
    //success
    return font;
}
Example #3
0
/* Test whitespace trim functions (edge cases). */
static void t16(void)
{
   ALLEGRO_USTR *us1;

   /* Check return value when passed empty strings. */
   us1 = al_ustr_new("");
   CHECK(al_ustr_ltrim_ws(us1));
   CHECK(al_ustr_rtrim_ws(us1));
   CHECK(al_ustr_trim_ws(us1));
   al_ustr_free(us1);

   /* Check nothing bad happens if the whole string is whitespace. */
   us1 = al_ustr_new(" \f\n\r\t\v");
   CHECK(al_ustr_ltrim_ws(us1));
   CHECK(al_ustr_size(us1) == 0);
   al_ustr_free(us1);

   us1 = al_ustr_new(" \f\n\r\t\v");
   CHECK(al_ustr_rtrim_ws(us1));
   CHECK(al_ustr_size(us1) == 0);
   al_ustr_free(us1);

   us1 = al_ustr_new(" \f\n\r\t\v");
   CHECK(al_ustr_trim_ws(us1));
   CHECK(al_ustr_size(us1) == 0);
   al_ustr_free(us1);
}
/* Function: al_show_native_message_box
 */
int al_show_native_message_box(ALLEGRO_DISPLAY *display,
   char const *title, char const *heading, char const *text,
   char const *buttons, int flags)
{
   ALLEGRO_NATIVE_DIALOG *fc;
   int r;

   ASSERT(title);
   ASSERT(heading);
   ASSERT(text);

   /* Note: the message box code cannot assume that Allegro is installed.
    * al_malloc and ustr functions are okay (with the assumption that the
    * user doesn't change the memory management functions in another thread
    * while this message box is open).
    */

   fc = al_calloc(1, sizeof *fc);

   fc->title = al_ustr_new(title);
   fc->mb_heading = al_ustr_new(heading);
   fc->mb_text = al_ustr_new(text);
   fc->mb_buttons = al_ustr_new(buttons);
   fc->flags = flags;

   r = _al_show_native_message_box(display, fc);

   al_ustr_free(fc->title);
   al_ustr_free(fc->mb_heading);
   al_ustr_free(fc->mb_text);
   al_ustr_free(fc->mb_buttons);
   al_free(fc);

   return r;
}
Example #5
0
/** loads a font from a skin.
    The font is managed via the resource manager.
    @param skin skin.
    @param wgt widget name (UTF-8 string).
    @param res resource name (UTF-8 string).
    @param def default resource.
    @param def_size def size of font, in case the size of the font is not found.
    @param def_flags def size of font, in case the flags of the font are not found.
    @return the loaded resource or the default resource if the resource is not found.
 */
ALLEGRO_FONT *algui_get_skin_font(ALGUI_SKIN *skin, const char *wgt, const char *res, ALLEGRO_FONT *def, unsigned int def_size, unsigned int def_flags) {
    const char *valstr;
    unsigned int size, flags;
    ALLEGRO_USTR *filename;
    ALLEGRO_FONT *font;
    
    assert(skin);
    assert(skin->config);
    
    //get the config value
    valstr = al_get_config_value(skin->config, wgt, res);
    
    //the filename string
    filename = al_ustr_new("");
    
    //convert the string to font; if the conversion fails, return the default
    if (!_string_to_font(valstr, def_size, def_flags, filename, &size, &flags)) {
        al_ustr_free(filename);
        return def;
    }        
    
    //load the font
    font = _load_font(skin, al_cstr(filename), size, flags);
    
    //free the filename string
    al_ustr_free(filename);
    
    //if the font was loaded successfuly, return it, otherwise return the default
    return font ? font : def;
}
Example #6
0
/* Test al_ustr_insert. */
static void t11(void)
{
   ALLEGRO_USTR *us1;
   ALLEGRO_USTR *us2;
   size_t sz;

   /* Insert in middle. */
   us1 = al_ustr_new("aábdðeéfghiíjkprstuúvxyýþæö");
   us2 = al_ustr_new("lmnoó");
   al_ustr_insert(us1, 18, us2);
   CHECK(0 == strcmp(al_cstr(us1), "aábdðeéfghiíjklmnoóprstuúvxyýþæö"));

   /* Insert into itself. */
   al_ustr_insert(us2, 3, us2);
   CHECK(0 == strcmp(al_cstr(us2), "lmnlmnoóoó"));

   /* Insert before start (not allowed). */
   CHECK(!al_ustr_insert(us2, -1, us2));

   /* Insert past end (will be padded with NULs). */
   sz = al_ustr_size(us2);
   al_ustr_insert(us2, sz + 3, us2);
   CHECK(al_ustr_size(us2) == sz + sz + 3);
   CHECK(0 == memcmp(al_cstr(us2), "lmnlmnoóoó\0\0\0lmnlmnoóoó", sz + sz + 3));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #7
0
/* Test al_ustr_dup_substr. */
static void t7(void)
{
   ALLEGRO_USTR *us1;
   ALLEGRO_USTR *us2;

   us1 = al_ustr_new("aábdðeéfghiíjklmnoóprstuúvxyýþæö");

   /* Cut out part of a string.  Check for NUL terminator. */
   us2 = al_ustr_dup_substr(us1, 36, 36 + 4);
   CHECK(al_ustr_size(us2) == 4);
   CHECK(0 == strcmp(al_cstr(us2), "þæ"));
   al_ustr_free(us2);

   /* Under and overflow */
   us2 = al_ustr_dup_substr(us1, INT_MIN, INT_MAX);
   CHECK(al_ustr_size(us2) == al_ustr_size(us1));
   CHECK(0 == strcmp(al_cstr(us2), al_cstr(us1)));
   al_ustr_free(us2);

   /* Start > end */
   us2 = al_ustr_dup_substr(us1, INT_MAX, INT_MIN);
   CHECK(0 == al_ustr_size(us2));
   al_ustr_free(us2);

   al_ustr_free(us1);
}
Example #8
0
/* Function: al_destroy_path
 */
void al_destroy_path(ALLEGRO_PATH *path)
{
   unsigned i;

   if (!path) {
      return;
   }

   if (path->drive) {
      al_ustr_free(path->drive);
      path->drive = NULL;
   }

   if (path->filename) {
      al_ustr_free(path->filename);
      path->filename = NULL;
   }

   for (i = 0; i < _al_vector_size(&path->segments); i++) {
      al_ustr_free(get_segment(path, i));
   }
   _al_vector_free(&path->segments);

   if (path->basename) {
      al_ustr_free(path->basename);
      path->basename = NULL;
   }

   if (path->full_string) {
      al_ustr_free(path->full_string);
      path->full_string = NULL;
   }

   _AL_FREE(path);
}
Example #9
0
/* Test al_ustr_dup. */
static void t6(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("aábdðeéfghiíjklmnoóprstuúvxyýþæö");
   ALLEGRO_USTR *us2 = al_ustr_dup(us1);

   CHECK(al_ustr_size(us1) == al_ustr_size(us2));
   CHECK(0 == memcmp(al_cstr(us1), al_cstr(us2), al_ustr_size(us1)));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #10
0
/* Test that we can create and destroy strings and get their data and size. */
static void t1(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("");
   ALLEGRO_USTR *us2 = al_ustr_new("áƵ");

   CHECK(0 == strcmp(al_cstr(us1), ""));
   CHECK(0 == strcmp(al_cstr(us2), "áƵ"));
   CHECK(4 == al_ustr_size(us2));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #11
0
/* Test al_ustr_assign, al_ustr_assign_cstr. */
static void t40(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("我隻氣墊船裝滿晒鱔");
   ALLEGRO_USTR *us2 = al_ustr_new("Τὸ χόβερκράφτ μου εἶναι γεμᾶτο χέλια");

   CHECK(al_ustr_assign(us1, us2));
   CHECK(0 == strcmp(al_cstr(us1), "Τὸ χόβερκράφτ μου εἶναι γεμᾶτο χέλια"));

   CHECK(al_ustr_assign_cstr(us1, "私のホバークラフトは鰻でいっぱいです"));
   CHECK(54 == al_ustr_size(us1));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #12
0
/* Test al_ustr_append, al_ustr_append_cstr. */
static void t8(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("aábdðeéfghiíjklm");
   ALLEGRO_USTR *us2 = al_ustr_new("noóprstuú");

   CHECK(al_ustr_append(us1, us2));
   CHECK(0 == strcmp(al_cstr(us1), "aábdðeéfghiíjklmnoóprstuú"));

   CHECK(al_ustr_append_cstr(us1, "vxyýþæö"));
   CHECK(0 == strcmp(al_cstr(us1), "aábdðeéfghiíjklmnoóprstuúvxyýþæö"));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #13
0
/* Test al_ustr_find_replace, al_ustr_find_replace_cstr. */
static void t49(void)
{
   ALLEGRO_USTR *us;
   ALLEGRO_USTR_INFO findi;
   ALLEGRO_USTR_INFO repli;
   const ALLEGRO_USTR *find;
   const ALLEGRO_USTR *repl;

   us = al_ustr_new("aábdðeéfghiíaábdðeéfghií");
   find = al_ref_cstr(&findi, "ðeéf");
   repl = al_ref_cstr(&repli, "deef");

   CHECK(al_ustr_find_replace(us, 0, find, repl));
   CHECK(0 == strcmp(al_cstr(us), "aábddeefghiíaábddeefghií"));

   find = al_ref_cstr(&findi, "aá");
   repl = al_ref_cstr(&repli, "AÁ");

   CHECK(al_ustr_find_replace(us, 14, find, repl));
   CHECK(0 == strcmp(al_cstr(us), "aábddeefghiíAÁbddeefghií"));

   CHECK(al_ustr_find_replace_cstr(us, 0, "dd", "đ"));
   CHECK(0 == strcmp(al_cstr(us), "aábđeefghiíAÁbđeefghií"));

   /* Not allowed */
   find = al_ustr_empty_string();
   CHECK(! al_ustr_find_replace(us, 0, find, repl));
   CHECK(0 == strcmp(al_cstr(us), "aábđeefghiíAÁbđeefghií"));

   al_ustr_free(us);
}
Example #14
0
/* Test that we can make strings which reference (parts of) other strings. */
static void t5(void)
{
   ALLEGRO_USTR *us1;
   const ALLEGRO_USTR *us2;
   ALLEGRO_USTR_INFO us2_info;

   us1 = al_ustr_new("aábdðeéfghiíjklmnoóprstuúvxyýþæö");

   us2 = al_ref_ustr(&us2_info, us1, 36, 36 + 4);
   CHECK(0 == memcmp(al_cstr(us2), "þæ", al_ustr_size(us2)));

   /* Start pos underflow */
   us2 = al_ref_ustr(&us2_info, us1, -10, 7);
   CHECK(0 == memcmp(al_cstr(us2), "aábdð", al_ustr_size(us2)));

   /* End pos overflow */
   us2 = al_ref_ustr(&us2_info, us1, 36, INT_MAX);
   CHECK(0 == memcmp(al_cstr(us2), "þæö", al_ustr_size(us2)));

   /* Start > end */
   us2 = al_ref_ustr(&us2_info, us1, 36 + 4, 36);
   CHECK(0 == al_ustr_size(us2));

   al_ustr_free(us1);
}
Example #15
0
/* Test al_ustr_insert_cstr. */
static void t12(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("aábeéf");
   CHECK(al_ustr_insert_cstr(us1, 4, "dð"));
   CHECK(0 == strcmp(al_cstr(us1), "aábdðeéf"));
   al_ustr_free(us1);
}
Example #16
0
/* Test al_ustr_replace_range. */
static void t44(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("Šis kungs par visu samaksās");
   ALLEGRO_USTR *us2 = al_ustr_new("ī kundze");

   CHECK(al_ustr_replace_range(us1, 2, 10, us2));
   CHECK(0 == strcmp(al_cstr(us1), "Šī kundze par visu samaksās"));

   /* Insert into itself. */
   CHECK(al_ustr_replace_range(us1, 5, 11, us1));
   CHECK(0 == strcmp(al_cstr(us1),
         "Šī Šī kundze par visu samaksās par visu samaksās"));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #17
0
static ALLEGRO_FS_ENTRY *fs_apk_read_directory(ALLEGRO_FS_ENTRY *fse)
{
   ALLEGRO_FS_ENTRY_APK *e = (ALLEGRO_FS_ENTRY_APK *)fse;
   ALLEGRO_FS_ENTRY *next;
   ALLEGRO_USTR *tmp;

   if (!e->file_list_pos)
      return NULL;
   if (!*e->file_list_pos)
      return NULL;

   tmp = al_ustr_new(e->path_cstr);
   ensure_trailing_slash(tmp);
   char *name = e->file_list_pos;
   char *semi = strchr(name, ';');
   if (semi) {
      *semi = 0;
      e->file_list_pos = semi + 1;
   }
   else {
      e->file_list_pos = name + strlen(name);
   }
   al_ustr_append_cstr(tmp, name);
   next = fs_apk_create_entry(al_cstr(tmp));
   al_ustr_free(tmp);

   return next;
}
Example #18
0
/** cleans up a skin structure.
    Destroys the allegro config.
    @param skin skin structure to cleanup.
 */
void algui_cleanup_skin(ALGUI_SKIN *skin) {
    assert(skin);
    al_ustr_free(skin->filename);
    al_destroy_config(skin->config);
    skin->filename = NULL;
    skin->config = NULL;
}
Example #19
0
/* Function: al_create_path
 */
ALLEGRO_PATH *al_create_path(const char *str)
{
   ALLEGRO_PATH *path;

   path = _AL_MALLOC(sizeof(ALLEGRO_PATH));
   if (!path)
      return NULL;

   path->drive = al_ustr_new("");
   path->filename = al_ustr_new("");
   _al_vector_init(&path->segments, sizeof(ALLEGRO_USTR *));
   path->basename = al_ustr_new("");
   path->full_string = al_ustr_new("");

   if (str != NULL) {
      ALLEGRO_USTR *copy = al_ustr_new(str);
      replace_backslashes(copy);

      if (!parse_path_string(copy, path)) {
         al_destroy_path(path);
         path = NULL;
      }

      al_ustr_free(copy);
   }

   return path;
}
			void framerate::renderFPS() { //Renders the FPS
				al_draw_filled_rectangle(0,0,32,16,al_map_rgba_f(0,0,0,0.5));
				al_draw_rectangle(1,1,31,15,al_map_rgba_f(1,1,1,0.7),1);
				al_draw_ustr(FPSRenderFont,al_map_rgb(255,255,255),6,2,0,FPSText);
				ALLEGRO_USTR* nS = al_ustr_newf("%i",networking::gameServer::getLatency());
				al_draw_ustr(FPSRenderFont,al_map_rgb(255,255,255),6,16,0,nS);
				al_ustr_free(nS);
			}
Example #21
0
/* Test whitespace trim functions. */
static void t15(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new(" \f\n\r\t\vhello \f\n\r\t\v");
   ALLEGRO_USTR *us2 = al_ustr_new(" \f\n\r\t\vhello \f\n\r\t\v");

   CHECK(al_ustr_ltrim_ws(us1));
   CHECK(0 == strcmp(al_cstr(us1), "hello \f\n\r\t\v"));

   CHECK(al_ustr_rtrim_ws(us1));
   CHECK(0 == strcmp(al_cstr(us1), "hello"));

   CHECK(al_ustr_trim_ws(us2));
   CHECK(0 == strcmp(al_cstr(us2), "hello"));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #22
0
/*
Title: Text Box

Section: Internal

Function: wz_textbox_proc

See also:
<wz_widget_proc>
*/
int wz_textbox_proc(WZ_WIDGET* wgt, ALLEGRO_EVENT* event)
{
	int ret = 1;
	WZ_TEXTBOX* box = (WZ_TEXTBOX*)wgt;
	switch (event->type)
	{
		case WZ_DRAW:
		{
			if (wgt->flags & WZ_STATE_HIDDEN)
			{
				ret = 0;
			}
			else
			{
				int flags = (wgt->flags & WZ_STATE_DISABLED) ? WZ_STYLE_DISABLED : 0;
				wgt->theme->draw_textbox(wgt->theme, wgt->local_x, wgt->local_y, wgt->w, wgt->h, box->h_align, box->v_align, box->text, flags);
			}
			break;
		}
		case WZ_DESTROY:
		{
			if(box->own)
				al_ustr_free(box->text);
			ret = 0;
			break;
		}
		case WZ_SET_TEXT:
		{
			if(box->own)
			{
				al_ustr_free(box->text);
				box->text = al_ustr_dup((ALLEGRO_USTR*)event->user.data3);
			}
			else
			{
				box->text = (ALLEGRO_USTR*)event->user.data3;
			}
			break;
		}
		default:
			ret = 0;
	}
	if (ret == 0)
		ret = wz_widget_proc(wgt, event);
	return ret;
}
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);
}
Example #24
0
/* Test al_ustr_length. */
static void t27(void)
{
   ALLEGRO_USTR *us = al_ustr_new("aþ€\xf4\x8f\xbf\xbf");

   CHECK(0 == al_ustr_length(al_ustr_empty_string()));
   CHECK(4 == al_ustr_length(us));

   al_ustr_free(us);
}
Example #25
0
void destroy_translation(void)
{
	std::vector<ALLEGRO_USTR *> &v = post_translated_strings;

	for (int i = 0; i < (int)v.size(); i++) {
		al_ustr_free(v[i]);
	}
	v.clear();
}
/* Function: al_destroy_native_file_dialog
 */
void al_destroy_native_file_dialog(ALLEGRO_FILECHOOSER *dialog)
{
   ALLEGRO_NATIVE_DIALOG *fd = (ALLEGRO_NATIVE_DIALOG *)dialog;
   size_t i;

   if (!fd)
      return;

   _al_unregister_destructor(_al_dtor_list, fd);

   al_ustr_free(fd->title);
   al_destroy_path(fd->fc_initial_path);
   for (i = 0; i < fd->fc_path_count; i++) {
      al_destroy_path(fd->fc_paths[i]);
   }
   al_free(fd->fc_paths);
   al_ustr_free(fd->fc_patterns);
   al_free(fd);
}
Example #27
0
/* Test al_ustr_append with aliased strings. */
static void t9(void)
{
   ALLEGRO_USTR *us1;
   ALLEGRO_USTR_INFO us2_info;
   const ALLEGRO_USTR *us2;

   /* Append a string to itself. */
   us1 = al_ustr_new("aábdðeéfghiíjklm");
   CHECK(al_ustr_append(us1, us1));
   CHECK(0 == strcmp(al_cstr(us1), "aábdðeéfghiíjklmaábdðeéfghiíjklm"));
   al_ustr_free(us1);

   /* Append a substring of a string to itself. */
   us1 = al_ustr_new("aábdðeéfghiíjklm");
   us2 = al_ref_ustr(&us2_info, us1, 5, 5 + 11); /* ð...í */
   CHECK(al_ustr_append(us1, us2));
   CHECK(0 == strcmp(al_cstr(us1), "aábdðeéfghiíjklmðeéfghií"));
   al_ustr_free(us1);
}
Example #28
0
/* Test al_ustr_assign_cstr. */
static void t41(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("Моја лебдилица је пуна јегуља");
   ALLEGRO_USTR *us2 = al_ustr_new("");

   CHECK(al_ustr_assign_substr(us2, us1, 9, 27));
   CHECK(0 == strcmp(al_cstr(us2), "лебдилица"));

   /* Start > End */
   CHECK(al_ustr_assign_substr(us2, us1, 9, 0));
   CHECK(0 == strcmp(al_cstr(us2), ""));

   /* Start, end out of bounds */
   CHECK(al_ustr_assign_substr(us2, us1, -INT_MAX, INT_MAX));
   CHECK(0 == strcmp(al_cstr(us2), "Моја лебдилица је пуна јегуља"));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #29
0
/* Test al_ustr_replace_range (part 2). */
static void t45(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("abcdef");
   ALLEGRO_USTR *us2 = al_ustr_new("ABCDEF");

   /* Start1 < 0 [not allowed] */
   CHECK(! al_ustr_replace_range(us1, -1, 1, us2));

   /* Start1 > end(us1) [padded] */
   CHECK(al_ustr_replace_range(us1, 8, 100, us2));
   CHECK(0 == memcmp(al_cstr(us1), "abcdef\0\0ABCDEF", 15));

   /* Start1 > end1 [not allowed] */
   CHECK(! al_ustr_replace_range(us1, 8, 1, us2));
   CHECK(0 == memcmp(al_cstr(us1), "abcdef\0\0ABCDEF", 15));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #30
0
//destroys a resource
static void _destroy_resource(_RESOURCE *res, int invoke_dtor) {
    //invoke the destructor
    if (invoke_dtor) res->destructor(res->data);
    
    //destroy the name string
    al_ustr_free(res->name);
    
    //free the memory occupied by the resource
    al_free(res);
}