static ALLEGRO_USTR *create_filter_string(const ALLEGRO_USTR *patterns) { ALLEGRO_USTR *filter = al_ustr_new(""); bool filter_all = false; int start, end; if (0 == strcmp(al_cstr(patterns), "*.*")) { filter_all = true; } else { al_ustr_append_cstr(filter, "All Supported Files"); al_ustr_append_chr(filter, '\0'); start = al_ustr_size(filter); al_ustr_append(filter, patterns); /* Remove all instances of "*.*", which will be added separately. */ for (;;) { int pos = al_ustr_find_cstr(filter, start, "*.*;"); if (pos == -1) break; if (pos == start || al_ustr_get(filter, pos - 1) == ';') { filter_all = true; al_ustr_remove_range(filter, pos, pos + 4); start = pos; } else { start = pos + 4; } } while (al_ustr_has_suffix_cstr(filter, ";*.*")) { filter_all = true; end = al_ustr_size(filter); al_ustr_remove_range(filter, end - 4, end); } al_ustr_append_chr(filter, '\0'); } if (filter_all) { al_ustr_append_cstr(filter, "All Files"); al_ustr_append_chr(filter, '\0'); al_ustr_append_cstr(filter, "*.*"); al_ustr_append_chr(filter, '\0'); } al_ustr_append_chr(filter, '\0'); return filter; }
static void print_bitmap_flags(ALLEGRO_BITMAP *bitmap) { ALLEGRO_USTR *ustr = al_ustr_new(""); if (al_get_bitmap_flags(bitmap) & ALLEGRO_VIDEO_BITMAP) al_ustr_append_cstr(ustr, " VIDEO"); if (al_get_bitmap_flags(bitmap) & ALLEGRO_MEMORY_BITMAP) al_ustr_append_cstr(ustr, " MEMORY"); if (al_get_bitmap_flags(bitmap) & ALLEGRO_CONVERT_BITMAP) al_ustr_append_cstr(ustr, " CONVERT"); al_ustr_trim_ws(ustr); al_ustr_find_replace_cstr(ustr, 0, " ", " | "); log_printf("%s", al_cstr(ustr)); al_ustr_free(ustr); }
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; }
int _al_show_native_message_box(ALLEGRO_DISPLAY *display, ALLEGRO_NATIVE_DIALOG *fd) { UINT type = 0; int result; uint16_t *wide_text, *wide_title; size_t text_len, title_len; /* Note: the message box code cannot assume that Allegro is installed. */ if (fd->flags & ALLEGRO_MESSAGEBOX_QUESTION) type |= MB_ICONQUESTION; else if (fd->flags & ALLEGRO_MESSAGEBOX_WARN) type |= MB_ICONWARNING; else if (fd->flags & ALLEGRO_MESSAGEBOX_ERROR) type |= MB_ICONERROR; else type |= MB_ICONINFORMATION; if (fd->flags & ALLEGRO_MESSAGEBOX_YES_NO) type |= MB_YESNO; else if (fd->flags & ALLEGRO_MESSAGEBOX_OK_CANCEL) type |= MB_OKCANCEL; /* heading + text are combined together */ if (al_ustr_size(fd->mb_heading)) al_ustr_append_cstr(fd->mb_heading, "\n\n"); al_ustr_append(fd->mb_heading, fd->mb_text); text_len = al_ustr_size_utf16(fd->mb_heading); title_len = al_ustr_size_utf16(fd->title); wide_text = al_malloc(text_len + 1); if (!wide_text) return 0; wide_title = al_malloc(title_len + 1); if (!wide_title) { al_free(wide_text); return 0; } al_ustr_encode_utf16(fd->mb_heading, wide_text, text_len); al_ustr_encode_utf16(fd->title, wide_title, title_len); result = MessageBoxW(al_get_win_window_handle(display), (LPCWSTR) wide_text, (LPCWSTR) wide_title, type); al_free(wide_text); al_free(wide_title); if (result == IDYES || result == IDOK) return 1; else return 0; }
static ALLEGRO_USTR *apply_cwd(const char *path) { ALLEGRO_USTR *us; if (path_is_absolute(path)) { return al_ustr_new(path); } us = al_ustr_new(fs_apk_cwd); al_ustr_append_cstr(us, path); return us; }
/* 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); }
/* Function: al_set_path_extension */ bool al_set_path_extension(ALLEGRO_PATH *path, char const *extension) { int dot; ASSERT(path); if (al_ustr_size(path->filename) == 0) { return false; } dot = al_ustr_rfind_chr(path->filename, al_ustr_size(path->filename), '.'); if (dot >= 0) { al_ustr_truncate(path->filename, dot); } al_ustr_append_cstr(path->filename, extension); return true; }
static bool glsl_build_shader(ALLEGRO_SHADER *shader) { GLint status; ALLEGRO_SHADER_GLSL_S *gl_shader = (ALLEGRO_SHADER_GLSL_S *)shader; GLchar error_buf[4096]; if (gl_shader->vertex_shader == 0 && gl_shader->pixel_shader == 0) return false; if (gl_shader->program_object != 0) { glDeleteProgram(gl_shader->program_object); } gl_shader->program_object = glCreateProgram(); if (gl_shader->program_object == 0) return false; if (gl_shader->vertex_shader) glAttachShader(gl_shader->program_object, gl_shader->vertex_shader); if (gl_shader->pixel_shader) glAttachShader(gl_shader->program_object, gl_shader->pixel_shader); glLinkProgram(gl_shader->program_object); glGetProgramiv(gl_shader->program_object, GL_LINK_STATUS, &status); if (status == 0) { glGetProgramInfoLog(gl_shader->program_object, sizeof(error_buf), NULL, error_buf); if (shader->log) { al_ustr_truncate(shader->log, 0); al_ustr_append_cstr(shader->log, error_buf); } else { shader->log = al_ustr_new(error_buf); } ALLEGRO_ERROR("Link error: %s\n", error_buf); glDeleteProgram(gl_shader->program_object); return false; } /* Look up variable locations. */ lookup_varlocs(&gl_shader->varlocs, gl_shader->program_object); return true; }
static bool glsl_attach_shader_source(ALLEGRO_SHADER *shader, ALLEGRO_SHADER_TYPE type, const char *source) { GLint status; GLchar error_buf[4096]; ALLEGRO_SHADER_GLSL_S *gl_shader = (ALLEGRO_SHADER_GLSL_S *)shader; ALLEGRO_DISPLAY *display = al_get_current_display(); ASSERT(display); ASSERT(display->flags & ALLEGRO_OPENGL); if (source == NULL) { if (type == ALLEGRO_VERTEX_SHADER) { if (gl_shader->vertex_shader) { glDetachShader(gl_shader->program_object, gl_shader->vertex_shader); glDeleteShader(gl_shader->vertex_shader); gl_shader->vertex_shader = 0; } } else { if (gl_shader->pixel_shader) { glDetachShader(gl_shader->program_object, gl_shader->pixel_shader); glDeleteShader(gl_shader->pixel_shader); gl_shader->pixel_shader = 0; } } return true; } else { GLuint *handle; GLenum gl_type; if (type == ALLEGRO_VERTEX_SHADER) { handle = &(gl_shader->vertex_shader); gl_type = GL_VERTEX_SHADER; } else { handle = &(gl_shader->pixel_shader); gl_type = GL_FRAGMENT_SHADER; } *handle = glCreateShader(gl_type); if ((*handle) == 0) { return false; } glShaderSource(*handle, 1, &source, NULL); glCompileShader(*handle); glGetShaderiv(*handle, GL_COMPILE_STATUS, &status); if (status == 0) { glGetShaderInfoLog(*handle, sizeof(error_buf), NULL, error_buf); if (shader->log) { al_ustr_truncate(shader->log, 0); al_ustr_append_cstr(shader->log, error_buf); } else { shader->log = al_ustr_new(error_buf); } ALLEGRO_ERROR("Compile error: %s\n", error_buf); glDeleteShader(*handle); return false; } } return true; }