/** * @brief Map custom widget mouse handling. * * @param wid Window sending events. * @param event Event window is sending. * @param mx Mouse X position. * @param my Mouse Y position. * @param w Width of the widget. * @param h Height of the widget. */ static void map_mouse( unsigned int wid, SDL_Event* event, double mx, double my, double w, double h ) { (void) wid; int i; double x,y, t; StarSystem *sys; t = 15.*15.; /* threshold */ mx -= w/2 - map_xpos; my -= h/2 - map_ypos; switch (event->type) { case SDL_MOUSEBUTTONDOWN: /* zooming */ if (event->button.button == SDL_BUTTON_WHEELUP) map_buttonZoom( 0, "btnZoomIn" ); else if (event->button.button == SDL_BUTTON_WHEELDOWN) map_buttonZoom( 0, "btnZoomOut" ); /* selecting star system */ else { for (i=0; i<systems_nstack; i++) { sys = system_getIndex( i ); /* must be reachable */ if (!space_sysReachable(sys)) continue; /* get position */ x = sys->pos.x * map_zoom; y = sys->pos.y * map_zoom; if ((pow2(mx-x)+pow2(my-y)) < t) { map_select( sys ); break; } } map_drag = 1; } break; case SDL_MOUSEBUTTONUP: if (map_drag) map_drag = 0; break; case SDL_MOUSEMOTION: if (map_drag) { /* axis is inverted */ map_xpos -= event->motion.xrel; map_ypos += event->motion.yrel; } break; } }
/** * @brief Map custom widget mouse handling. * * @param wid Window sending events. * @param event Event window is sending. * @param mx Mouse X position. * @param my Mouse Y position. * @param w Width of the widget. * @param h Height of the widget. */ static void map_mouse( unsigned int wid, SDL_Event* event, double mx, double my, double w, double h, void *data ) { (void) wid; (void) data; int i; double x,y, t; StarSystem *sys; t = 15.*15.; /* threshold */ switch (event->type) { case SDL_MOUSEBUTTONDOWN: /* Must be in bounds. */ if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h)) return; /* Zooming */ if (event->button.button == SDL_BUTTON_WHEELUP) map_buttonZoom( 0, "btnZoomIn" ); else if (event->button.button == SDL_BUTTON_WHEELDOWN) map_buttonZoom( 0, "btnZoomOut" ); /* selecting star system */ else { mx -= w/2 - map_xpos; my -= h/2 - map_ypos; for (i=0; i<systems_nstack; i++) { sys = system_getIndex( i ); /* must be reachable */ if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED) && !space_sysReachable(sys)) continue; /* get position */ x = sys->pos.x * map_zoom; y = sys->pos.y * map_zoom; if ((pow2(mx-x)+pow2(my-y)) < t) { map_select( sys, (SDL_GetModState() & KMOD_SHIFT) ); break; } } map_drag = 1; } break; case SDL_MOUSEBUTTONUP: if (map_drag) map_drag = 0; break; case SDL_MOUSEMOTION: if (map_drag) { /* axis is inverted */ map_xpos -= event->motion.xrel; map_ypos += event->motion.yrel; } break; } }