📄 iconedit_panel.c
字号:
return PANEL_NONE; default: if (ctrl_s_pending || ctrl_q_pending) { iced_panelmsg("",""); ctrl_s_pending = ctrl_q_pending = FALSE; } return panel_text_notify(item, event); }}/************************************************************************//* Load and Store *//************************************************************************/static struct pixrect *load_old_format(file_name, error_msg) char *file_name, *error_msg;{ int c, count; FILE *fd; icon_header_object header; struct pixrect *pr; fd = fopen(file_name, "r"); if (fd == NULL) { iced_panelmsg("","Can't open file."); return NULL_PR; } while ( (c= getc(fd)) != '{') { /* matching } */ if (c==EOF) { iced_panelmsg("Incorrect file format:","opening brace missing. "); fclose(fd); return NULL_PR; } } header.last_param_pos = ftell(fd); count = 0; while (1) { long junk; if (fscanf(fd, " 0x%X,", &junk) != 1) break; count++; }; fseek(fd, header.last_param_pos, 0); switch (count) { case 8: header.height = 16; header.valid_bits_per_item = 32; break; case 16: header.height = 16; header.valid_bits_per_item = 16; break; case 128: header.height = 64; header.valid_bits_per_item = 32; break; case 256: header.height = 64; header.valid_bits_per_item = 16; break; default: iced_panelmsg( "Incorrect file format:","wrong # of scan lines."); fclose(fd); return NULL_PR; } header.depth = 1; header.format_version = 1; header.width = header.height; pr = mem_create(header.width, header.height, header.depth); if (pr == NULL_PR) { strcpy(error_msg, "icon_load: pixrect create failed"); } else if (icon_read_pr(fd, &header, pr)) { strcpy(error_msg, "icon_load: icon read failed"); pr_destroy(pr); pr = NULL_PR; } fclose(fd); return pr;}static voidget_file_name(item)Panel_item item; { char full_file_name[1024]; expand_path((char *)panel_get_value(item), full_file_name); strcpy(iced_file_name, full_file_name);}/************************************************************************//* iced_load_proc *//************************************************************************//* ARGSUSED */voidiced_load_proc(item)Panel_item item;{ if (!iced_change_directory()) { iced_panelmsg("Unable to", "change to directory."); } else { if (special_characters()) iced_browse_proc(); else do_load(); }}staticspecial_characters(){ char *filename; filename = panel_get_value(iced_fname_item); return (index(filename, '*'));}/* ARGSUSED */staticdo_load(item) Panel_item item;{ int size; u_int op, mode, needs_clearing = FALSE; struct pixrect *new_pr; char error_msg[IL_ERRORMSG_SIZE]; get_file_name(iced_fname_item); if (!strlen(iced_file_name)) { iced_panelmsg("Please enter name of","file to load."); return; } new_pr = icon_load_mpr(iced_file_name, error_msg); if (!new_pr) { new_pr = load_old_format(iced_file_name, error_msg); if (!new_pr) return; } size = max(new_pr->pr_size.x, new_pr->pr_size.y); if (size <= 16) { iced_canvas_pr = &iced_new_cursor_pr; mode = CURSOR; if (new_pr->pr_size.x < 16 || new_pr->pr_size.y < 16) needs_clearing = TRUE; } else if (size <= 64) { iced_canvas_pr = &iced_icon_pr; mode = ICONIC; if (new_pr->pr_size.x < 64 || new_pr->pr_size.y < 64) needs_clearing = TRUE; } else iced_panelmsg("Unable to load image;","(side > 64 pixels)."); op = val_to_op((int)panel_get_value(iced_load_op_item)); backup(); iced_dirty_ul_cell.x = 0; iced_dirty_ul_cell.y = 0; iced_dirty_dr_cell.x = iced_cell_count-1; iced_dirty_dr_cell.y = iced_cell_count-1; if (op == PIX_SRC && needs_clearing) { pr_rop(iced_canvas_pr, 0, 0, iced_canvas_pr->pr_size.x, iced_canvas_pr->pr_size.y, PIX_CLR, 0, 0, 0); } pr_rop(iced_canvas_pr, 0, 0, new_pr->pr_size.x, new_pr->pr_size.y, op, new_pr, 0, 0); pr_destroy(new_pr); iced_icon_canvas_is_clear = FALSE; iced_state = -1; iced_set_state(mode); iced_panelmsg("","Image loaded.");}static char *read_save_stuff(file_name)char *file_name;{ extern char *calloc(); char *result; char error_msg[IL_ERRORMSG_SIZE]; long read; icon_header_object icon_header; register FILE *fd; result = NULL; fd = icon_open_header(file_name, error_msg, &icon_header); if (fd) { long stop_plus_one; stop_plus_one = ftell(fd); fseek(fd, icon_header.last_param_pos, 0); result = calloc(stop_plus_one-icon_header.last_param_pos+1, sizeof(*result)); read = fread(result, sizeof(*result), stop_plus_one-2-icon_header.last_param_pos, fd); if (read != (stop_plus_one-2-icon_header.last_param_pos)) abort(); fclose(fd); } return(result);}/************************************************************************//* store_proc *//************************************************************************/#define BITS_PER_BYTE 8#define ITEMS_PER_LINE 8#define MPR_D(pr) ((struct mpr_data *) (LINT_CAST((pr)->pr_data)))/* ARGSUSED */static voidstore_proc(item) Panel_item item;{ int x, y, w, h; int count, items, pad; register struct pixrect *pr; struct pixrect *tpr = 0; register short *data; register FILE *fd; register char *save_stuff = NULL; struct stat stat_buf; if (!iced_change_directory()) { iced_panelmsg("Unable to", "change to directory."); return; } if (iced_state == CURSOR) pr = &iced_new_cursor_pr; else pr = &iced_icon_pr; w = pr->pr_size.x; h = pr->pr_size.y; /* store trimmed */ if (!item) { if (!(tpr = mem_create(w, h, pr->pr_depth))) { iced_panelmsg("Error:", "out of memory"); return; } /* mush rows together */ for (y = 0; y < h; y++) pr_rop(tpr, 0, 0, w, 1, PIX_SRC | PIX_DST, pr, 0, y); /* find right pixel */ for (; w > 0; w--) if (pr_get(tpr, w - 1, 0)) break; /* mush columns together */ for (x = 0; x < w; x++) pr_rop(tpr, 0, 0, 1, h, PIX_SRC | PIX_DST, pr, x, 0); /* find bottom pixel */ for (; h > 0; h--) if (pr_get(tpr, 0, h - 1)) break; /* copy non-blank part */ pr_rop(tpr, 0, 0, pr->pr_width, pr->pr_height, PIX_CLR, (Pixrect *) 0, 0, 0); pr_rop(tpr, 0, 0, w, h, PIX_SRC, pr, 0, 0); pr = tpr; } get_file_name(iced_fname_item); if (!strlen(iced_file_name)) { iced_panelmsg("Please enter name of", "file to store."); goto Done; } if (stat(iced_file_name, &stat_buf) == -1) { ctrl_s_pending = TRUE; if (errno != ENOENT) { iced_panelmsg("Error:", sys_errlist[errno]); goto Done; } } else { /* stat succeeded; file exists */ if (store_invoked_from_keyboard) { if (!ctrl_s_pending) { iced_panelmsg("Confirm overwrite of", "existing file with ^S..."); goto Done; } } else { ctrl_s_pending = FALSE; iced_panelmsg("Confirm overwrite", "of existing file..."); confirm_mouse_proc(); if (!confirm()) { iced_panelmsg("", ""); canvas_mouse_proc(); goto Done; } canvas_mouse_proc(); } save_stuff = read_save_stuff(iced_file_name); } fd = fopen(iced_file_name, "w"); if (fd == NULL) { iced_panelmsg("", "Can't write to file."); goto Done; } fprintf(fd,"/* Format_version=1, Width=%d, Height=%d, Depth=%d, Valid_bits_per_item=%d\n", w, h, pr->pr_depth, BITS_PER_BYTE * sizeof (*data)); if (save_stuff) { extern cfree(); char *temp; int len; /* Massage save_stuff to make read-write idempotent. */ if (*(temp = save_stuff) == '\n') temp++; len = strlen(temp); if (temp[len - 1] == ' ') temp[len - 1] = '\0'; fprintf(fd, "%s", temp); cfree(save_stuff); } fprintf(fd, " */\n"); /* convert width to 16 bit chunks */ w = (w + 15) >> 4; count = h * w; items = 0; x = 0; data = MPR_D(pr)->md_image; pad = (MPR_D(pr)->md_linebytes >> 1) - w; while (--count >= 0) { fprintf(fd, items == 0 ? "\t" : ",");#ifdef i386 bitflip16(data);#endif fprintf(fd, "0x%04X", (unsigned short) *data++); if (++items == ITEMS_PER_LINE || count == 0) { items = 0; fprintf(fd, count ? ",\n" : "\n"); } if (++x == w) { x = 0; data += pad; } } fflush(fd); iced_panelmsg("", ferror(fd) ? "File write error." : "File written.");Done: if (fd != NULL) fclose(fd); if (tpr != NULL_PR) pr_destroy(tpr);}/**********************************************************************//* confirm */ /**********************************************************************/staticconfirm(){ struct fullscreen *fsh; int fd; struct inputevent event; int result; fd = (int)window_get(iced_base_frame, WIN_FD); fsh = fullscreen_init(fd); window_set(iced_base_frame, WIN_CONSUME_PICK_EVENTS, WIN_NO_EVENTS, WIN_MOUSE_BUTTONS, 0, WIN_CURSOR, &iconedit_confirm_cursor, 0); while (TRUE) { if (input_readevent(fd, &event) == -1) { perror("Cursor_confirm input failed"); abort(); } switch (event_action(&event)) { case MS_MIDDLE: case MS_RIGHT: result = FALSE; break; case MS_LEFT: result = TRUE; break; default: blink(fd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -