/* ------------------------------------------------------------------------- */ TextureGlyph * texture_font_get_glyph( TextureFont *self, wchar_t charcode ) { size_t i; static wchar_t *buffer = 0; TextureGlyph *glyph; assert( self ); assert( self->filename ); assert( self->atlas ); /* Check if charcode has been already loaded */ for( i=0; i<self->glyphs->size; ++i ) { glyph = (TextureGlyph *) vector_get( self->glyphs, i ); if( glyph->charcode == charcode ) { return glyph; } } /* If not, load it */ if( !buffer) { buffer = (wchar_t *) calloc( 2, sizeof(wchar_t) ); } buffer[0] = charcode; if( texture_font_cache_glyphs( self, buffer ) == 0 ) { return (TextureGlyph *) vector_back( self->glyphs ); } return NULL; }
/** * Access stack top data. */ void* stack_top(const cstl_stack_t* cpsk_stack) { assert(cpsk_stack != NULL); #if defined (CSTL_STACK_VECTOR_SEQUENCE) return vector_back(&cpsk_stack->_t_sequence); #elif defined (CSTL_STACK_LIST_SEQUENCE) return list_back(&cpsk_stack->_t_sequence); #else return deque_back(&cpsk_stack->_t_sequence); #endif }
void test_front_and_back() { vector* v = create_test_vector(); int* first_element = (int*)vector_front(v); int* last_element = (int*)vector_back(v); printf("First element = %i\n", *first_element); printf("Last element = %i\n", *last_element); vector_free(v, NULL); }
void verr_reraise() { if (try_stack->size > 0) { TryFrame* frame = vector_back(try_stack); longjmp(frame->env, current_error); } fprintf(stderr, "unhandled exception: %s", verr_msg(current_error)); if (current_msg) { fprintf(stderr, " - %s\n", current_msg); } else { fprintf(stderr, "\n"); } #ifdef DEBUG verr_print_stacktrace(); #endif abort(); }
void test_vector() { size_t arr[10], arr2[10]; size_t i, j; vector vec; j = 200; vector_init(&vec, &malloc, &free); for (i = 0; i < 10; ++i) { arr[i] = i; vector_push_back(&vec, &arr[i]); } for (i = 0; i < 10; ++i) { arr2[i] = i + 10; vector_push_back(&vec, &arr2[i]); } vector_insert(&vec, &j, vec.size); vector_remove(&vec, 0); printf("-----\nVector testing\n-----\nSize: %d\nMax size: %d\nContents: ", vector_size(&vec), vector_max_size(&vec)); for (i = 0; i < 20; ++i) printf("%d ", *(size_t*)vector_pop_back(&vec)); vector_push_back(&vec, &j); printf("\nFront: %d\nBack: %d\n", *(size_t*)vector_front(&vec), *(size_t*)vector_back(&vec)); vector_clear(&vec); printf("Vector cleared\nSize: %d\n", vec.size); vector_free(&vec); printf("\n"); }
// ------------------------------------------------- texture_font_get_glyph --- texture_glyph_t * texture_font_get_glyph( texture_font_t * self, wchar_t charcode ) { assert( self ); size_t i; static wchar_t *buffer = 0; texture_glyph_t *glyph; assert( self ); assert( self->filename ); assert( self->atlas ); /* Check if charcode has been already loaded */ for( i=0; i<self->glyphs->size; ++i ) { glyph = *(texture_glyph_t **) vector_get( self->glyphs, i ); if( (glyph->charcode == charcode) && (glyph->outline_type == self->outline_type) && (glyph->outline_thickness == self->outline_thickness) ) { return glyph; } } /* charcode -1 is special : it is used for line drawing (overline, * underline, strikethrough) and background. */ if( charcode == (wchar_t)(-1) ) { size_t width = self->atlas->width; size_t height = self->atlas->height; ivec4 region = texture_atlas_get_region( self->atlas, 5, 5 ); texture_glyph_t * glyph = texture_glyph_new( ); static unsigned char data[4*4*3] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; if ( region.x < 0 ) { // fprintf( stderr, "Texture atlas is full (line %d)\n", __LINE__ ); return NULL; } #ifndef RENDERSTRING texture_atlas_set_region( self->atlas, region.x, region.y, 4, 4, data, 0 ); #else data[0]=0; #endif glyph->charcode = (wchar_t)(-1); glyph->s0 = (region.x+2)/(float)width; glyph->t0 = (region.y+2)/(float)height; glyph->s1 = (region.x+3)/(float)width; glyph->t1 = (region.y+3)/(float)height; vector_push_back( self->glyphs, &glyph ); return glyph; //*(texture_glyph_t **) vector_back( self->glyphs ); } /* Glyph has not been already loaded */ if( !buffer) { buffer = (wchar_t *) calloc( 2, sizeof(wchar_t) ); } buffer[0] = charcode; if( texture_font_load_glyphs( self, buffer ) == 0 ) { return *(texture_glyph_t **) vector_back( self->glyphs ); } return NULL; }
/* 总是将孩子节点加在子节点链的最右边 如果 parent 在对象树中 那么完成添加工作后一定要更新 root->parent 的 lchild 成员和 rchild 成员 这是为了保证遍历的正确 */ si_t application_add_window(struct window * parent, struct window * window) { struct object node, * tree; /* 添加顶层窗口 */ if(parent == NULL) { /* node 的父节点是 window */ node.parent = OBJECT_POINTER(window); node.lchild = object_tree_l_most_node(OBJECT_POINTER(window)); node.rchild = object_tree_r_most_node(OBJECT_POINTER(window)); node.name = NULL; node.id = 0; /* 将窗口添加到向量 */ vector_push_back(&(global_application.window_vector), &node, sizeof(struct object)); tree = vector_back(&(global_application.window_vector)); /* window 的父节点是 node */ window->parent = tree; } /* 添加非顶层窗口 */ else { object_insert_child(OBJECT_POINTER(parent), OBJECT_POINTER(window)); } /** * if already running in app_exec **/ if(global_application.exec_flag) { union message msg; msg.base.type = MESSAGE_TYPE_WIDGET_REPAINT; msg.widget_repaint.area = window->area; if(global_application.focus != NULL) { struct window* w = WINDOW_POINTER(global_application.focus); struct object* tree, *node, *tree_real_parent; w->is_activated = 0; msg.widget_repaint.area = w->area; if(w->callback != NULL) { w->callback(w, &msg); } node = OBJECT_POINTER(w); tree = node->parent; tree_real_parent = tree->parent; tree->parent = node; node = object_tree_l_most_node(tree); while(node != NULL) { union message msg; msg.base.type = MESSAGE_TYPE_WIDGET_REPAINT; msg.widget_repaint.area = WIDGET_POINTER(node)->area; if(WIDGET_POINTER(node)->callback != NULL) WIDGET_POINTER(node)->callback(node, &msg); node = object_tree_iterator_increment(tree, node); } tree->parent = tree_real_parent; } window->descriptor = register_window((parent == NULL ? 0 : parent->descriptor), window->title, window->area.x, window->area.y, window->area.width, window->area.height, window->minimize_enable, window->maximize_enable, window->modal); if(window->descriptor == 0) { EGUI_PRINT_ERROR("failed to register window"); application_exit(); return -1; } /** * find icon for the application **/ if((window->icon_path = (char*)malloc(256)) == NULL) { EGUI_PRINT_SYS_ERROR("failed to malloc for icon path. malloc"); application_exit(); return -1; } else { /** * in C89 standard, snprintf() is NOT included in <stdio.h> * so you have to use sprintf, which may be dangerous. be careful **/ sprintf(window->icon_path, "%s/icons/%s.bmp", global_application.icon_root_path, global_application.name); if(access(window->icon_path, R_OK) == -1) { sprintf(window->icon_path, "%s/icons/default.bmp", global_application.icon_root_path); } } msg.widget_repaint.area = window->area; global_application.focus = window; window->is_activated = 1; if(window->callback != NULL) { window->callback(window, &msg); } } return 0; }
int stack_top(Stack* stack) { return vector_back(stack->elems); }
void *stack_top(stack *s) { return vector_back(&s->storage); }