/* * Make a backup of the current buttons */ void button_backup_all(void) { button_backup *newbackup; newbackup = RNEW(button_backup); if (!newbackup) { return; } if (button_num == 0) { newbackup->buttons = NULL; newbackup->num = 0; newbackup->length = 0; } else { newbackup->buttons = C_RNEW(button_num, button_mouse); if (!(newbackup->buttons)) { FREE(newbackup); return; } /* Straight memory copy */ (void) C_COPY(newbackup->buttons, button_mse, button_num, button_mouse); newbackup->num = button_num; newbackup->length = button_length; } /* push the backup onto the stack */ newbackup->next = button_backups; button_backups = newbackup; /* Check we haven't already done this */ /*if (button_backup[0].key) return; */ /* Straight memory copy */ /*(void)C_COPY(button_backup, button_mse, MAX_MOUSE_BUTTONS, button_mouse); */ }
/* * Make a backup of the current buttons */ bool button_backup_all(bool kill_all) { button_backup *newbackup; newbackup = RNEW(button_backup); if(!newbackup) { return FALSE; } /* copy the 2d buttons */ if (kill_all) { newbackup->buttons = button_stack; newbackup->num = button_num; button_stack = NULL; button_num = 0; } else { /* copy the buttons to new memory */ button_mouse *dest, *src, *end; newbackup->buttons = NULL; newbackup->num = 0; end = NULL; src = button_stack; while (src) { dest = RNEW(button_mouse); if (!dest) { FREE(newbackup); return FALSE; } (void)C_COPY(dest, src, 1, button_mouse); if (src->label) { dest->label = (char*)string_make(src->label); } if (!(newbackup->buttons)) { newbackup->buttons = dest; } if (end) { end->next = dest; } end = dest; newbackup->num++; dest->next = NULL; src = src->next; } #if 0 int i; button_mouse *button; newbackup->buttons = C_RNEW(button_num, button_mouse); if (!(newbackup->buttons)) { FREE(newbackup); return FALSE; } button = button_stack; for (i=0; i<button_num; i++) { if (button) { /* Straight memory copy */ (void)C_COPY(&(newbackup->buttons[i]), button, 1, button_mouse); if (button->label) { newbackup->buttons[i].label = string_make(button->label); } button = button->next; } if (button) { newbackup->buttons[i].next = &(newbackup->buttons[i+1]); } } newbackup->num = button_num; #endif } /* copy the 1d buttons */ if (button_1d_num == 0) { newbackup->buttons_1d = NULL; newbackup->num_1d = 0; newbackup->length_1d = 0; } else { newbackup->buttons_1d = C_RNEW(button_1d_num, button_mouse_1d); if (!(newbackup->buttons_1d)) { /* free the 2d buttons TODO */ if (newbackup->buttons && !kill_all) { int i; for (i=0; i<newbackup->num; i++) { if (newbackup->buttons[i].label) { string_free(newbackup->buttons[i].label); } } FREE(newbackup->buttons); } FREE(newbackup); return FALSE; } /* Straight memory copy */ (void)C_COPY(newbackup->buttons_1d, button_1d_list, button_1d_num, button_mouse_1d); newbackup->num_1d = button_1d_num; newbackup->length_1d = button_1d_length; } /* push the backup onto the stack */ newbackup->next = button_backups; button_backups = newbackup; if (kill_all && (button_num || button_1d_num)) { button_kill_all(); } /* Redraw */ p_ptr->redraw |= (PR_BUTTONS); return TRUE; }
bool init_graphics_modes(const char *filename) { int i = 0; int line = 0; int previd; char *zz[16]; char buf[1024]; ang_file *fp; graphics_mode *mode = NULL,*next; /* Build the filename */ path_make(buf, ANGBAND_DIR_USER, filename); fp = file_open(buf, MODE_READ, FTYPE_TEXT); if (!fp) { /* Build the filename */ path_make(buf, ANGBAND_DIR_XTRA_GRAF, filename); fp = file_open(buf, MODE_READ, FTYPE_TEXT); } if (!fp) { return FALSE; } while (0 <= file_getl(fp, buf, 1024)) { /* Count lines */ line++; /* Skip "empty" lines */ if (!buf[0]) continue; /* Skip "blank" lines */ if (isspace(buf[0])) continue; /* Skip comments */ if (buf[0] == '#') continue; /* Require "?:*" format */ if (buf[1] != ':') return FALSE;/*(1);*/ /* process the line */ /* Process "N:<id>:<menuname>" -- start a new record */ if (buf[0] == 'N') { if (tokenize(buf + 2, 2, zz, TOKENIZE_CHECKQUOTE) == 2) { mode = ZNEW(graphics_mode); if (mode) { mode->grafID = strtol(zz[0], NULL, 0); strncpy(mode->menuname, zz[1], 32); mode->menuname[31] = 0; if (graphics_mode_high_id < mode->grafID) { graphics_mode_high_id = mode->grafID; } mode->pNext = graphics_modes; graphics_modes = mode; } else { return FALSE;/*(PARSE_ERROR_OUT_OF_MEMORY);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } /* Process "P:<prefname>:<preffile>" -- set the name used with pref files */ else if (buf[0] == 'P') { byte count = tokenize(buf + 2, 2, zz, TOKENIZE_CHECKQUOTE); if (count >= 1) { if (mode) { strncpy(mode->pref, zz[0], 32); if (count == 2) { /* overwrite the pref name with the pref filename */ strncpy(mode->pref, zz[1], 32); } mode->pref[31] = 0; } else { return FALSE;/*(PARSE_ERROR_MISSING_RECORD_HEADER);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } /* Process "I:<cell width>:<cell height>:<filename>" -- read the tileset info */ else if (buf[0] == 'I') { if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3) { if (mode) { mode->cell_width = strtol(zz[0], NULL, 0); mode->cell_height = strtol(zz[1], NULL, 0); strncpy(mode->file, zz[2], 32); mode->file[31] = 0; } else { return FALSE;/*(PARSE_ERROR_MISSING_RECORD_HEADER);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } /* Process "X:<alpha>:<overdraw_min>:<overdraw_max>" -- read some extra info */ else if (buf[0] == 'X') { if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3) { if (mode) { mode->alphablend = strtol(zz[0], NULL, 0); mode->overdrawRow = strtol(zz[1], NULL, 0); mode->overdrawMax = strtol(zz[2], NULL, 0); } else { return FALSE;/*(PARSE_ERROR_MISSING_RECORD_HEADER);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } else { /* Oops */ return FALSE;/*(PARSE_ERROR_UNDEFINED_DIRECTIVE);*/ } } /* close the file */ file_close(fp); mode = graphics_modes; graphics_modes = C_RNEW(graphics_mode_high_id+1,graphics_mode); /* set the default mode */ graphics_modes[0].grafID = 0; graphics_modes[0].alphablend = 0; graphics_modes[0].cell_height = 1; graphics_modes[0].cell_width = 1; graphics_modes[0].overdrawRow = 0; graphics_modes[0].overdrawMax = 0; strncpy(graphics_modes[0].menuname, "None", 32); strncpy(graphics_modes[0].pref, "font.prf", 32); strncpy(graphics_modes[0].file, "", 32); if (mode) { next = mode; while (next->pNext) next = next->pNext; graphics_modes[0].pNext = &(graphics_modes[next->grafID]); } else { graphics_modes[0].pNext = NULL; } previd = 0; while (mode) { next = mode->pNext; i = mode->grafID; graphics_modes[i].grafID = mode->grafID; graphics_modes[i].cell_height = mode->cell_height; graphics_modes[i].cell_width = mode->cell_width; graphics_modes[i].alphablend = mode->alphablend; graphics_modes[i].overdrawRow = mode->overdrawRow; graphics_modes[i].overdrawMax = mode->alphablend; strncpy(graphics_modes[i].menuname, mode->menuname, 32); strncpy(graphics_modes[i].pref, mode->pref, 32); strncpy(graphics_modes[i].file, mode->file, 32); if (previd) { graphics_modes[i].pNext = &(graphics_modes[previd]); } else { graphics_modes[i].pNext = NULL; } previd = i; FREE(mode); mode = next; } return TRUE; }