static int resol_gui(void) { int id, jd; if ((id = gui_vstack(0))) { if ((jd = gui_harray(id))) { gui_label(jd, _("Resolution"), GUI_SML, 0, 0); gui_space(jd); gui_start(jd, _("Back"), GUI_SML, RESOL_BACK, 0); } gui_space(id); if (modes) { int i; for (i = 0; fill_row(gui_harray(id), modes, i, 4); i += 4); } gui_layout(id, 0, 0); } return id; }
static int fill_row(int id, SDL_Rect **modes, int i, int n) { int complete; if (n == 0) return 1; if (modes[i]) { char label[20]; int btn; sprintf(label, "%d x %d", modes[i]->w, modes[i]->h); complete = fill_row(id, modes, i + 1, n - 1); btn = gui_state(id, label, GUI_SML, RESOL_SELECT, i); gui_set_hilite(btn, (config_get_d(CONFIG_WIDTH) == modes[i]->w && config_get_d(CONFIG_HEIGHT) == modes[i]->h)); } else { for (; n; gui_space(id), n--); complete = 0; } return complete; }
/* Display the whole tree (single/split/full view) */ static void display_tree(struct menu *menu) { struct symbol *sym; struct property *prop; struct menu *child; enum prop_type ptype; if (menu == &rootmenu) { indent = 1; current = &rootmenu; } for (child = menu->list; child; child = child->next) { prop = child->prompt; sym = child->sym; ptype = prop ? prop->type : P_UNKNOWN; if (sym) sym->flags &= ~SYMBOL_CHANGED; if ((view_mode == SPLIT_VIEW) && !(child->flags & MENU_ROOT) && (tree == tree1)) continue; if ((view_mode == SPLIT_VIEW) && (child->flags & MENU_ROOT) && (tree == tree2)) continue; if (menu_is_visible(child) || show_all) place_node(child, fill_row(child)); #ifdef DEBUG printf("%*c%s: ", indent, ' ', menu_get_prompt(child)); printf("%s", child->flags & MENU_ROOT ? "rootmenu | " : ""); dbg_print_ptype(ptype); printf(" | "); if (sym) { dbg_print_stype(sym->type); printf(" | "); dbg_print_flags(sym->flags); printf("\n"); } else printf("\n"); #endif if ((view_mode != FULL_VIEW) && (ptype == P_MENU) && (tree == tree2)) continue; /* if (((menu != &rootmenu) && !(menu->flags & MENU_ROOT)) || (view_mode == FULL_VIEW) || (view_mode == SPLIT_VIEW))*/ if (((view_mode == SINGLE_VIEW) && (menu->flags & MENU_ROOT)) || (view_mode == FULL_VIEW) || (view_mode == SPLIT_VIEW)) { indent++; display_tree(child); indent--; } } }
/* * Update the tree by adding/removing entries * Does not change other nodes */ static void update_tree(struct menu *src, GtkTreeIter * dst) { struct menu *child1; GtkTreeIter iter, tmp; GtkTreeIter *child2 = &iter; gboolean valid; GtkTreeIter *sibling; struct symbol *sym; struct property *prop; struct menu *menu1, *menu2; if (src == &rootmenu) indent = 1; valid = gtk_tree_model_iter_children(model2, child2, dst); for (child1 = src->list; child1; child1 = child1->next) { prop = child1->prompt; sym = child1->sym; reparse: menu1 = child1; if (valid) gtk_tree_model_get(model2, child2, COL_MENU, &menu2, -1); else menu2 = NULL; // force adding of a first child #ifdef DEBUG printf("%*c%s | %s\n", indent, ' ', menu1 ? menu_get_prompt(menu1) : "nil", menu2 ? menu_get_prompt(menu2) : "nil"); #endif if (!menu_is_visible(child1) && !show_all) { // remove node if (gtktree_iter_find_node(dst, menu1) != NULL) { memcpy(&tmp, child2, sizeof(GtkTreeIter)); valid = gtk_tree_model_iter_next(model2, child2); gtk_tree_store_remove(tree2, &tmp); if (!valid) return; // next parent else goto reparse; // next child } else continue; } if (menu1 != menu2) { if (gtktree_iter_find_node(dst, menu1) == NULL) { // add node if (!valid && !menu2) sibling = NULL; else sibling = child2; gtk_tree_store_insert_before(tree2, child2, dst, sibling); set_node(child2, menu1, fill_row(menu1)); if (menu2 == NULL) valid = TRUE; } else { // remove node memcpy(&tmp, child2, sizeof(GtkTreeIter)); valid = gtk_tree_model_iter_next(model2, child2); gtk_tree_store_remove(tree2, &tmp); if (!valid) return; // next parent else goto reparse; // next child } } else if (sym && (sym->flags & SYMBOL_CHANGED)) { set_node(child2, menu1, fill_row(menu1)); } indent++; update_tree(child1, child2); indent--; valid = gtk_tree_model_iter_next(model2, child2); } }
static void inline draw_paddle(uint8_t pos) { fill_row(0, c000000); rgb_screen[0+pos][0] = (pixel_t) (uint8_t) c005500; rgb_screen[1+pos][0] = (pixel_t) (uint8_t) c005500; rgb_screen[2+pos][0] = (pixel_t) (uint8_t) c005500; }
/* Display the whole tree (single/split/full view) */ static void display_tree(struct menu *menu) { struct symbol *sym; struct property *prop; struct menu *child; enum prop_type ptype; if (menu == &rootmenu) { indent = 1; current = &rootmenu; } for (child = menu->list; child; child = child->next) { prop = child->prompt; sym = child->sym; ptype = prop ? prop->type : P_UNKNOWN; if (sym) sym->flags &= ~SYMBOL_CHANGED; if ((view_mode == SPLIT_VIEW) && !(child->flags & MENU_ROOT) && (tree == tree1)) continue; if ((view_mode == SPLIT_VIEW) && (child->flags & MENU_ROOT) && (tree == tree2)) continue; if ((opt_mode == OPT_NORMAL && menu_is_visible(child)) || (opt_mode == OPT_PROMPT && menu_has_prompt(child)) || (opt_mode == OPT_ALL && menu_get_prompt(child))) place_node(child, fill_row(child)); #ifdef DEBUG printf("%*c%s: ", indent, ' ', menu_get_prompt(child)); printf("%s", child->flags & MENU_ROOT ? "rootmenu | " : ""); printf("%s", prop_get_type_name(ptype)); printf(" | "); if (sym) { printf("%s", sym_type_name(sym->type)); printf(" | "); printf("%s", dbg_sym_flags(sym->flags)); printf("\n"); } else printf("\n"); #endif if ((view_mode != FULL_VIEW) && (ptype == P_MENU) && (tree == tree2)) continue; /* if (((menu != &rootmenu) && !(menu->flags & MENU_ROOT)) || (view_mode == FULL_VIEW) || (view_mode == SPLIT_VIEW))*/ /* Change paned position if the view is not in 'split mode' */ if (view_mode == SINGLE_VIEW || view_mode == FULL_VIEW) { gtk_paned_set_position(GTK_PANED(hpaned), 0); } if (((view_mode == SINGLE_VIEW) && (menu->flags & MENU_ROOT)) || (view_mode == FULL_VIEW) || (view_mode == SPLIT_VIEW)) { indent++; display_tree(child); indent--; } } }
int main(int argc, char *argv[]) { int width = DEFAULT_WIDTH; int generations = DEFAULT_HEIGHT; unsigned long ruleset = DEFAULT_RULES; FILE *output_fh = stdout; char start_row[CA_MAX_WIDTH]; char start_str[CA_MAX_WIDTH]; CA *ca_ptr; gdImagePtr image; int idx; int opt; int init_cntr = 0; int blk_r = 0, blk_g = 0, blk_b = 0; int wht_r = 255, wht_g = 255, wht_b = 255; char *filename = NULL; long hexval; int dimension; int percentage=0; while( (opt = getopt(argc, argv, "s:p:x:y:b:w:o:r:123")) != -1 ) { switch(opt) { case 's': strncpy(start_str, optarg,CA_MAX_WIDTH); break; case 'p': sscanf(optarg, "%d", &percentage); if ( (percentage > 100) || (percentage < 0) ) { percentage = 50; } break; case 'x': sscanf(optarg, "%d", &dimension); if (dimension <= 0) { fprintf(stderr, "Width too small! Using default.\n"); width = DEFAULT_WIDTH; } else if( dimension > CA_MAX_WIDTH) { fprintf(stderr, "Width too big! Using default.\n"); width = DEFAULT_WIDTH; } else { width = dimension; } break; case 'y': sscanf(optarg, "%d", &dimension); if (dimension <= 0) { fprintf(stderr, "Height too small! Using default.\n"); generations = DEFAULT_HEIGHT; break; } else { generations = dimension; } break; case 'b': sscanf(optarg,"%lx", &hexval); blk_r = hexval & 0xff0000; blk_r = blk_r >> 16; blk_g = hexval & 0x00ff00; blk_g = blk_g >> 8; blk_b = hexval & 0x0000ff; break; case 'w': sscanf(optarg,"%lx", &hexval); wht_r = hexval & 0xff0000; wht_r = wht_r >> 16; wht_g = hexval & 0x00ff00; wht_g = wht_g >> 8; wht_b = hexval & 0x0000ff; break; case 'o': filename = optarg; break; case 'r': sscanf(optarg, "%lu", &ruleset); if (ruleset < 0 || ruleset > (unsigned long)(~0)) { fprintf(stderr, "Bad rule [%lu] specified!\n", ruleset); exit(1); } break; case '1': init_cntr = 1; break; case '2': init_cntr = 2; break; case '3': init_cntr = 3; break; case ':': fprintf(stderr,"Option '%c' requires a value.\n", optopt); exit(1); case '?': fprintf(stderr,"Unknown option '%c'.\n", optopt); exit(1); } } /* End of command line processing. */ srand(0); for (idx = 0; idx < width; idx++) { start_row[idx] = rand() % 2; } if( ! init_cntr) { fill_row_random(start_row, percentage, 0, width, 0); } else if ( init_cntr == 1) { fill_row_center(start_row, start_str, 0, width); } else if (init_cntr == 2) { fill_row_center(start_row, start_str, 1, width); } else if (init_cntr == 3) { fill_row_repeat(start_row, start_str, width); } else { fill_row(start_row, 0, width); } ca_ptr = new_ca(width,ruleset,start_row); image = ca_make_gif(ca_ptr, generations, blk_r,blk_g,blk_b, wht_r,wht_g,wht_b); if (filename) { output_fh = fopen(filename, "w"); if (! output_fh) { fprintf(stderr,"Unable to open %s for writing: %s\n", filename, strerror(errno)); exit(errno); } } gdImagePng(image, output_fh); gdImageDestroy(image); free_ca(ca_ptr); exit(0); }