Index: gui_act.c =================================================================== --- gui_act.c (revision 25579) +++ gui_act.c (revision 25580) @@ -1,15 +1,118 @@ #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."; -/* DOC: quit.html */ 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, design.hidlib.size_x, 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} + {"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) Index: main.c =================================================================== --- main.c (revision 25579) +++ main.c (revision 25580) @@ -3,8 +3,6 @@ /* hidlib headers */ #include "unit.h" -#include "global_typedefs.h" -#include "hidlib.h" #include "hid_init.h" #include "hid.h" #include "buildin.hidlib.h" @@ -11,6 +9,7 @@ /* local (app) headers */ #include "gui_act.h" +#include "main.h" const char *pcb_hidlib_default_embedded_menu = ""; const char *conf_internal = ""; @@ -64,11 +63,6 @@ } - -typedef struct { - pcb_hidlib_t hidlib; -} design_t; - design_t design; int main(int argc, char *argv[]) @@ -77,6 +71,7 @@ design.hidlib.size_x = PCB_MM_TO_COORD(100); design.hidlib.size_y = PCB_MM_TO_COORD(100); + design.hidlib.grid = PCB_MM_TO_COORD(1); pcb_hidlib_init1(conf_core_init); pcb_hidlib_init2(pup_buildins); Index: main.h =================================================================== --- main.h (nonexistent) +++ main.h (revision 25580) @@ -0,0 +1,8 @@ +#include "global_typedefs.h" +#include "hidlib.h" + +typedef struct { + pcb_hidlib_t hidlib; +} design_t; + +extern design_t design;