#include "actions.h" #include "compat_misc.h" #include "main.h" #define NOGUI() \ do { \ if ((pcb_gui == NULL) || (!pcb_gui->gui)) { \ PCB_ACT_IRES(1); \ return 0; \ } \ PCB_ACT_IRES(0); \ } while(0) static const char pcb_acts_Quit[] = "Quit()"; static const char pcb_acth_Quit[] = "Quits the application."; static fgw_error_t pcb_act_Quit(fgw_arg_t *res, int argc, fgw_arg_t *argv) { exit(0); } const char pcb_acts_Pan[] = "Pan(Mode)"; const char pcb_acth_Pan[] = "Start or stop panning (Mode = 1 to start, 0 to stop)\n"; fgw_error_t pcb_act_Pan(fgw_arg_t *res, int argc, fgw_arg_t *argv) { int mode; pcb_coord_t x, y; NOGUI(); pcb_hid_get_coords("Click on a place to pan", &x, &y, 0); PCB_ACT_CONVARG(1, FGW_INT, Pan, mode = argv[1].val.nat_int); pcb_gui->pan_mode(x, y, mode); PCB_ACT_IRES(0); return 0; } const char pcb_acts_Zoom[] = "Zoom()\n" "Zoom([+|-|=]factor)\n" "Zoom(x1, y1, x2, y2)\n" "Zoom(?)\n" "Zoom(get)\n"; const char pcb_acth_Zoom[] = "GUI zoom"; fgw_error_t pcb_act_Zoom(fgw_arg_t *res, int argc, fgw_arg_t *argv) { const char *vp, *ovp; double v; pcb_coord_t x = 0, y = 0; NOGUI(); if (argc < 2) { pcb_gui->zoom_win(0, 0, hle_design.hidlib.size_x, hle_design.hidlib.size_y, 1); return 0; } if (argc == 5) { pcb_coord_t x1, y1, x2, y2; PCB_ACT_CONVARG(1, FGW_COORD, Zoom, x1 = fgw_coord(&argv[1])); PCB_ACT_CONVARG(2, FGW_COORD, Zoom, y1 = fgw_coord(&argv[2])); PCB_ACT_CONVARG(3, FGW_COORD, Zoom, x2 = fgw_coord(&argv[3])); PCB_ACT_CONVARG(4, FGW_COORD, Zoom, y2 = fgw_coord(&argv[4])); pcb_gui->zoom_win(x1, y1, x2, y2, 1); return 0; } if (argc > 2) PCB_ACT_FAIL(Zoom); PCB_ACT_CONVARG(1, FGW_STR, Zoom, ovp = vp = argv[1].val.str); if (*vp == '?') { pcb_message(PCB_MSG_INFO, "Current zoom level (coord-per-pix): %$mm\n", pcb_gui->coord_per_pix); return 0; } if (pcb_strcasecmp(argv[1].val.str, "get") == 0) { res->type = FGW_DOUBLE; res->val.nat_double = pcb_gui->coord_per_pix; return 0; } if (*vp == '+' || *vp == '-' || *vp == '=') vp++; v = strtod(vp, NULL); if (v <= 0) return FGW_ERR_ARG_CONV; pcb_hid_get_coords("Select zoom center", &x, &y, 0); switch (ovp[0]) { case '-': pcb_gui->zoom(x, y, 1 / v, 1); break; default: case '+': pcb_gui->zoom(x, y, v, 1); break; case '=': pcb_gui->zoom(x, y, v, 0); break; } PCB_ACT_IRES(0); return 0; } static pcb_action_t gui_action_list[] = { {"Quit", pcb_act_Quit, pcb_acth_Quit, pcb_acts_Quit}, {"Pan", pcb_act_Pan, pcb_acth_Pan, pcb_acts_Pan}, {"Zoom", pcb_act_Zoom, pcb_acth_Zoom, pcb_acts_Zoom} }; PCB_REGISTER_ACTIONS(gui_action_list, NULL) #include "dolists.h" void gui_act_init(void) { PCB_REGISTER_ACTIONS(gui_action_list, NULL) }