struct widget * widget_new_text(struct widget * parent, int x, int y, char const * const text) { struct widget * obj; int w, h; if(text != NULL) { w = 2 + font_width(text) + 2; h = 1 + font_height() + 1; } else { w = 4; h = 4; } obj = widget_new_child(parent, x, y, w, h); assert(obj != NULL); if(obj != NULL) { widget_set_on_draw(obj, widget_draw); widget_set_ulong(obj, "type", WT_TEXT); widget_set_flags(obj, 0); if(text != NULL) widget_set_string(obj, "text", "%s", text); } return obj; }
struct widget * widget_new_grid(struct widget * parent, int x, int y) { struct widget * grid; grid = NULL; if(parent == NULL) parent = widget_root(); assert(parent != NULL); if(parent != NULL) { grid = widget_new_child(parent, x, y, 0, 0); widget_set_ulong(grid, "type", WT_GRID); } return grid; }
struct widget * widget_new_title_credits(struct widget * parent, int x, int y, int width) { struct widget * obj; obj = widget_new_child(parent, x, y, width, 10); /* The height is in error here, but it should not matter. */ assert(obj != NULL); if(obj != NULL) { widget_set_on_draw(obj, draw); widget_set_ulong(obj, "type", WT_TITLE_CREDITS); widget_set_flags(obj, 0); widget_set_ulong(obj, "help_screen", 0); widget_set_ulong(obj, "credits_index", 0); widget_set_pointer(obj, "credits", 'P', read_credits(filenames[0])); widget_set_on_unload(obj, on_unload); #ifdef WITH_OPENGL if(globals.opengl) { struct gfxbuf * buf; buf = gfxbuf_new(GFXBUF_STATIC_2D, GL_QUADS, GFXBUF_COLOUR | GFXBUF_BLENDING); assert(buf != NULL); gfxbuf_resize(buf, 4 * 2); int vpos, cpos; vpos = cpos = 0; buf->vbuf[vpos++] = 0; buf->vbuf[vpos++] = font_height(); buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0xff; buf->vbuf[vpos++] = 0; buf->vbuf[vpos++] = 0; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0xff; buf->vbuf[vpos++] = 12; buf->vbuf[vpos++] = 0; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->vbuf[vpos++] = 12; buf->vbuf[vpos++] = font_height(); buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->vbuf[vpos++] = width - 12; buf->vbuf[vpos++] = font_height(); buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->vbuf[vpos++] = width - 12; buf->vbuf[vpos++] = 0; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->vbuf[vpos++] = width; buf->vbuf[vpos++] = 0; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0xff; buf->vbuf[vpos++] = width; buf->vbuf[vpos++] = font_height(); buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0x00; buf->cbuf[cpos++] = 0xff; gfxbuf_update(buf, 0, vpos / 2); widget_set_pointer(obj, "gfxbuf", 'P', buf); } #endif } return obj; }
static GuiWidget *create_widget_list(GuiWidget *parent_widget, xmlNodePtr root) { GuiWidget *widget = NULL, *first_widget = NULL; xmlNodePtr cur = XML_GET_CHILD(root); while(cur != NULL) { if ( xmlStrcmp(cur->name, WIDGET_STR) == 0 ) { xmlChar *widget_name = xmlGetProp(cur, NAME_STR ); xmlChar *classid = xmlGetProp(cur, CLASS_STR); xmlChar *widget_style = xmlGetProp(cur, STYLE_STR); // printf("XmlParser: widget_name=%s\n",(char *)widget_name); widget = widget_new_child(parent_widget, (char *)widget_name, (char *)classid, (char *)widget_style); if (widget_name) xmlFree(widget_name); if (classid) xmlFree(classid); if (widget_style) xmlFree(widget_style); if (widget == NULL) goto next; if (first_widget == NULL) first_widget = widget; xmlNodePtr node = XML_GET_CHILD(cur); while (node != NULL) { if ( xmlStrcmp(node->name, PROPERTY_STR) == 0 ) { xmlChar *key = xmlGetProp(node, NAME_STR); xmlChar *value = xmlGetProp(node, VALUE_STR);//xmlNodeGetContent(node); if (xmlStrcmp(key, (xmlChar*)"tabstop") == 0) widget->tabstop= atoidef((char *)value, 1); else widget_set_property(widget, (char *)key, (char *)value); if (key) xmlFree(key); if (value) xmlFree(value); } else if (xmlStrcmp(node->name, SIGNAL_STR) == 0 ) { xmlChar *name = xmlGetProp(node, NAME_STR); xmlChar *handler = xmlGetProp(node, HANDLER_STR); signal_new(widget, (char *)name, (char *)handler); if (name) xmlFree(name); if (handler) xmlFree(handler); } else if (xmlStrcmp(node->name, CHILDREN_STR) == 0 ) create_widget_list(widget, node); node = node->next; } } else if ( xmlStrcmp(cur->name, FILES_STR) == 0 ) { int i=0; gui->search_num = 0; xmlNodePtr node = XML_GET_CHILD(cur); while (node != NULL) { if (xmlStrcmp(node->name, SEARCH_STR) == 0) gui->search_num++; node = node->next; } gui->search_path = (char **)malloc(sizeof(char*) *gui->search_num + 1); node = XML_GET_CHILD(cur); while (node != NULL) { if (xmlStrcmp(node->name, SEARCH_STR) == 0) gui->search_path[i++] = strdup( (char *)xmlGetProp(node, PATH_STR) ); node = node->next; } gui->search_path[i] = NULL; node = XML_GET_CHILD(cur); while (node != NULL) { if (xmlStrcmp(node->name, FONT_STR) == 0) { xmlChar *font_name = xmlGetProp(node, NAME_STR); xmlChar *file_name = xmlGetProp(node, FILE_STR); if (file_name && font_name) create_fontdesc((char *)font_name, (char *)file_name); if (file_name) xmlFree(file_name); if (font_name) xmlFree(font_name); } else if (xmlStrcmp(node->name, IMAGE_STR) == 0) { xmlChar *image_name = xmlGetProp(node, NAME_STR); xmlChar* file_name = xmlGetProp(node, FILE_STR); if (file_name && image_name) create_imagedesc((char *)image_name, (char *)file_name); if (file_name) xmlFree(file_name); if (image_name) xmlFree(image_name); } node = node->next; } } else if ( xmlStrcmp(cur->name, I18N_STR) == 0 ) { xmlNodePtr node = XML_GET_CHILD(cur); while (node != NULL) { GuiI18n *i18n; if (xmlStrcmp(node->name, LANGUAGE_STR) == 0) { xmlChar *language = xmlGetProp(node, NAME_STR); if (language) { i18n = i18n_add_language((char *)language); xmlFree(language); if (i18n) { xmlNodePtr text_node = XML_GET_CHILD(node); while (text_node != NULL) { if (xmlStrcmp(text_node->name, TRAN_STR) == 0) { xmlChar *key = xmlGetProp(text_node, ID_STR); xmlChar *value = xmlNodeGetContent(text_node); i18n_add_tran(i18n, (char *)key, (char *)value); if (key) xmlFree(key); if (value) xmlFree(value); } text_node = text_node->next; } } } } node = node->next; } } else if ( xmlStrcmp(cur->name, THEMES_STR) == 0) { xmlNodePtr node = XML_GET_CHILD(cur); while (node != NULL) { if (xmlStrcmp(node->name, THEME_STR) == 0) { Theme *theme = (Theme *)malloc(sizeof(Theme)); if (theme == NULL) { printf("memory out\n"); node = node->next; continue; } char *filename = (char *)xmlGetProp(node, FILE_STR); if (file_exists(filename) == -1) { char *oldfile = filename; filename = gui_search_file(filename); free(oldfile); } if (filename) { xmlChar *theme_name = xmlGetProp(node, NAME_STR); if (theme_load(theme, filename) == 0) { if (gui->current_theme == NULL) gui->current_theme = theme; hash_add(gui->theme_hash, (char *)theme_name, theme); } xmlFree(theme_name); free(filename); } } node = node->next; } } next: cur = cur->next; } return first_widget; }
struct widget * widget_new_list(struct widget * parent, int x, int y, int width, int height, struct stack * items) { struct widget * rv; int scrollbar_width; int visible_items; { struct widget * tmp; tmp = widget_new_button(widget_root(), 0, 0, "x"); visible_items = (height - 2) / widget_height(tmp); widget_delete(tmp); int item_count; item_count = 0; for(unsigned int i = 0; i < items->size; i++) if(items->data[i] != NULL) item_count++; if(item_count <= visible_items) scrollbar_width = 0; else scrollbar_width = 20; } rv = widget_new_child(parent, x, y, width, height); widget_set_ulong(rv, "type", WT_LIST); struct stack * itemobjs; itemobjs = stack_new(); widget_set_pointer(rv, "items", 'P', itemobjs); struct widget * container, * frame; container = widget_new_child(rv, 0, 0, width - scrollbar_width, height); widget_add_flags(container, WF_CLIPPING); frame = widget_new_frame(container, 0, 0, width - scrollbar_width, height); frame->z_ = rv->z_; widget_delete_flags(frame, WF_CAST_SHADOW | WF_DRAW_BORDERS | WF_BACKGROUND); struct widget * prev; y = 0; prev = NULL; for(unsigned int i = 0; i < items->size; i++) if(items->data[i] != NULL) { struct widget * obj; obj = widget_new_button(frame, 0, y, items->data[i]); stack_push(itemobjs, obj); widget_delete_flags(obj, WF_DRAW_BORDERS | WF_ALIGN_CENTER); widget_set_ulong(obj, "alpha", 0x80); widget_set_width(obj, widget_width(frame)); widget_set_ulong(obj, "value", i); widget_set_widget_pointer(obj, "list_object", rv); widget_set_on_release(obj, on_item_release); widget_set_on_focus(obj, on_item_focus); y += widget_height(obj); if(prev != NULL) widget_set_navigation_updown(prev, obj); prev = obj; } widget_set_height(frame, y); widget_set_widget_pointer(rv, "focus_down_object", prev); if(scrollbar_width > 0) { struct widget * scrollbar, * scrollbar_button; int bheight; scrollbar = widget_new_frame(rv, width - scrollbar_width, 0, scrollbar_width, height); scrollbar->z_ = rv->z_; widget_delete_flags(scrollbar, WF_CAST_SHADOW); widget_set_on_activate_at(scrollbar, on_scrollbar_clicked); widget_set_enabled(scrollbar, true); widget_add_flags(scrollbar, WF_FOCUSABLE); scrollbar_button = widget_new_button(scrollbar, 1, 1, NULL); widget_set_width(scrollbar_button, scrollbar_width - 2); bheight = 0; if(items->size > 0) bheight += (height - 2) * visible_items / items->size; if(bheight > height - 2) bheight = height - 2; widget_set_height(scrollbar_button, bheight); widget_set_on_activate_at(scrollbar_button, on_scrollbar_button_clicked); widget_set_widget_pointer(scrollbar_button, "frame", frame); widget_set_widget_pointer(scrollbar, "scrollbar_button", scrollbar_button); widget_set_widget_pointer(rv, "scrollbar_button", scrollbar_button); } return rv; }