bool cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; if (zathura->document == NULL) { girara_notify(session, GIRARA_ERROR, _("No document opened.")); return false; } const unsigned int argc = girara_list_size(argument_list); if (argc != 1) { girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments given.")); return false; } const char* bookmark_name = girara_list_nth(argument_list, 0); zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, bookmark_name); if (bookmark == NULL) { girara_notify(session, GIRARA_ERROR, _("No such bookmark: %s"), bookmark_name); return false; } zathura_jumplist_add(zathura); page_set(zathura, bookmark->page - 1); if (bookmark->x != DBL_MIN && bookmark->y != DBL_MIN) { position_set(zathura, bookmark->x, bookmark->y); } zathura_jumplist_add(zathura); return true; }
void position_setDirect (Entity e, VECTOR3 pos, SUBHEX ground) { FUNCOPEN (); EntComponent pc = entity_getAs (e, "position"); POSITION pdata = component_getData (pc); SUBHEX oldGround; if (pdata == NULL) { fprintf (stderr, "%s (#%d, ...): entity without position component\n", __FUNCTION__, entity_GUID (e)); FUNCCLOSE (); return; } pdata->pos = pos; oldGround = pdata->position ? hexPos_platter (pdata->position, 1) : NULL; entity_speak (e, "positionUpdate", NULL); if (oldGround != ground) position_messageGroundChange (pc, oldGround, ground); int x = 0, y = 0; v2c (&pos, &x, &y); assert (hexMagnitude (x, y) <= MapRadius); position_set (e, map_at (subhexData (ground, x, y))); FUNCCLOSE (); }
void strat_autopos(int16_t x, int16_t y, int16_t a, int16_t epaisseurRobot) { robot.is_aligning = 1; // Pour se recaler, on met le robot en regulation angulaire, on reduit la vitesse et l'acceleration // On diminue la sensibilite on augmente la constante de temps de detection du bloquage bd_set_thresholds(&robot.distance_bd, 5000, 2); trajectory_set_speed(&robot.traj, 100, 100); robot.mode = BOARD_MODE_DISTANCE_ONLY; // On recule jusqu'a� qu'on ait touche un mur trajectory_d_rel(&robot.traj, (double) -2000); wait_traj_end(END_BLOCKING); trajectory_hardstop(&robot.traj); bd_reset(&robot.distance_bd); bd_reset(&robot.angle_bd); robot.mode = BOARD_MODE_ANGLE_DISTANCE; position_set(&robot.pos, epaisseurRobot, 0, COLOR_A(0.)); /* On se mets a la bonne position en x. */ trajectory_d_rel(&robot.traj, 80); wait_traj_end(END_TRAJ); /* On se tourne face a la paroi en Y. */ trajectory_only_a_abs(&robot.traj, COLOR_A(90)); wait_traj_end(END_TRAJ); /* On recule jusqu'a avoir touche le bord. */ trajectory_d_rel(&robot.traj, (double) -2000); wait_traj_end(END_BLOCKING); bd_reset(&robot.distance_bd); bd_reset(&robot.angle_bd); /* On reregle la position. */ robot.pos.pos_d.y = COLOR_Y(epaisseurRobot); robot.pos.pos_s16.y = COLOR_Y(epaisseurRobot); trajectory_d_rel(&robot.traj, 80); wait_traj_end(END_TRAJ); trajectory_goto_forward_xy_abs(&robot.traj, x, COLOR_Y(y)); wait_traj_end(END_TRAJ); /* Pour finir on s'occuppe de l'angle. */ trajectory_a_abs(&robot.traj, COLOR_A((double)a)); wait_traj_end(END_TRAJ); /* On remet le robot dans son etat initial. */ robot.mode = BOARD_MODE_ANGLE_DISTANCE; robot.is_aligning = 0; /* On se met en place a la position demandee. */ trajectory_set_speed(&robot.traj, speed_mm2imp(&robot.traj, 300), speed_rd2imp(&robot.traj, 2.5)); }
void position_copy (Entity target, const Entity source) { const POSITION sourcePosition = component_getData (entity_getAs (source, "position")); position_setOrientation (target, sourcePosition->orientation); position_setDirect (target, sourcePosition->pos, hexPos_platter (sourcePosition->position, 1)); if (!sourcePosition->position) return; position_set (target, map_copy (sourcePosition->position)); }
bool sc_search(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); g_return_val_if_fail(zathura->document != NULL, false); const unsigned int num_pages = zathura_document_get_number_of_pages(zathura->document); const unsigned int cur_page = zathura_document_get_current_page_number(zathura->document); GtkWidget *cur_page_widget = zathura_page_get_widget(zathura, zathura_document_get_page(zathura->document, cur_page)); bool nohlsearch, first_time_after_abort; gboolean draw; nohlsearch = first_time_after_abort = false; draw = FALSE; girara_setting_get(session, "nohlsearch", &nohlsearch); if (nohlsearch == false) { g_object_get(G_OBJECT(cur_page_widget), "draw-search-results", &draw, NULL); if (draw == false) { first_time_after_abort = true; } document_draw_search_results(zathura, true); } int diff = argument->n == FORWARD ? 1 : -1; if (zathura->global.search_direction == BACKWARD) diff = -diff; zathura_page_t* target_page = NULL; int target_idx = 0; for (unsigned int page_id = 0; page_id < num_pages; ++page_id) { int tmp = cur_page + diff * page_id; zathura_page_t* page = zathura_document_get_page(zathura->document, (tmp + num_pages) % num_pages); if (page == NULL) { continue; } GtkWidget* page_widget = zathura_page_get_widget(zathura, page); int num_search_results = 0, current = -1; g_object_get(G_OBJECT(page_widget), "search-current", ¤t, "search-length", &num_search_results, NULL); if (num_search_results == 0 || current == -1) { continue; } if (first_time_after_abort == true || (tmp + num_pages) % num_pages != cur_page) { target_page = page; target_idx = diff == 1 ? 0 : num_search_results - 1; break; } if (diff == 1 && current < num_search_results - 1) { /* the next result is on the same page */ target_page = page; target_idx = current + 1; } else if (diff == -1 && current > 0) { target_page = page; target_idx = current - 1; } else { /* the next result is on a different page */ g_object_set(G_OBJECT(page_widget), "search-current", -1, NULL); for (int npage_id = 1; page_id < num_pages; ++npage_id) { int ntmp = cur_page + diff * (page_id + npage_id); zathura_page_t* npage = zathura_document_get_page(zathura->document, (ntmp + 2*num_pages) % num_pages); GtkWidget* npage_page_widget = zathura_page_get_widget(zathura, npage); g_object_get(G_OBJECT(npage_page_widget), "search-length", &num_search_results, NULL); if (num_search_results != 0) { target_page = npage; target_idx = diff == 1 ? 0 : num_search_results - 1; break; } } } break; } if (target_page != NULL) { girara_list_t* results = NULL; GtkWidget* page_widget = zathura_page_get_widget(zathura, target_page); GObject* obj_page_widget = G_OBJECT(page_widget); g_object_set(obj_page_widget, "search-current", target_idx, NULL); g_object_get(obj_page_widget, "search-results", &results, NULL); /* Need to adjust rectangle to page scale and orientation */ zathura_rectangle_t* rect = girara_list_nth(results, target_idx); zathura_rectangle_t rectangle = recalc_rectangle(target_page, *rect); bool search_hadjust = true; girara_setting_get(session, "search-hadjust", &search_hadjust); /* compute the position of the center of the page */ double pos_x = 0; double pos_y = 0; page_number_to_position(zathura->document, zathura_page_get_index(target_page), 0.5, 0.5, &pos_x, &pos_y); /* correction to center the current result */ /* NOTE: rectangle is in viewport units, already scaled and rotated */ unsigned int cell_height = 0; unsigned int cell_width = 0; zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width); unsigned int doc_height = 0; unsigned int doc_width = 0; zathura_document_get_document_size(zathura->document, &doc_height, &doc_width); /* compute the center of the rectangle, which will be aligned to the center of the viewport */ double center_x = (rectangle.x1 + rectangle.x2) / 2; double center_y = (rectangle.y1 + rectangle.y2) / 2; pos_y += (center_y - (double)cell_height/2) / (double)doc_height; if (search_hadjust == true) { pos_x += (center_x - (double)cell_width/2) / (double)doc_width; } /* move to position */ zathura_jumplist_add(zathura); position_set(zathura, pos_x, pos_y); zathura_jumplist_add(zathura); } return false; }
bool sc_jumplist(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); g_return_val_if_fail(zathura->document != NULL, false); /* if no jumps in the jumplist */ if (zathura->jumplist.size == 0) { return true; } double x = zathura_document_get_position_x(zathura->document); double y = zathura_document_get_position_y(zathura->document); zathura_jump_t* jump = NULL; zathura_jump_t* prev_jump = zathura_jumplist_current(zathura); bool go_to_current = false; if (zathura_jumplist_has_next(zathura) == false || zathura_jumplist_has_previous(zathura) == false) { if (x == prev_jump->x && y == prev_jump->y) { go_to_current = false; } else { go_to_current = true; } } switch(argument->n) { case FORWARD: if (go_to_current == true && zathura_jumplist_has_previous(zathura) == false) { jump = zathura_jumplist_current(zathura); } else { zathura_jumplist_forward(zathura); jump = zathura_jumplist_current(zathura); } break; case BACKWARD: if (go_to_current == true && zathura_jumplist_has_next(zathura) == false) { jump = zathura_jumplist_current(zathura); } else { zathura_jumplist_backward(zathura); jump = zathura_jumplist_current(zathura); } break; } if (jump == prev_jump) { if ((zathura_jumplist_has_previous(zathura) == false && argument->n == BACKWARD) || (zathura_jumplist_has_next(zathura) == false && argument->n == FORWARD)) { jump = NULL; } } if (jump != NULL) { page_set(zathura, jump->page); position_set(zathura, jump->x, jump->y); } return false; }
bool sc_scroll(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); if (zathura->document == NULL) { return false; } /* if TOP or BOTTOM, go there and we are done */ if (argument->n == TOP) { position_set(zathura, -1, 0); return false; } else if (argument->n == BOTTOM) { position_set(zathura, -1, 1.0); return false; } /* Retrieve current page and position */ const unsigned int page_id = zathura_document_get_current_page_number(zathura->document); double pos_x = zathura_document_get_position_x(zathura->document); double pos_y = zathura_document_get_position_y(zathura->document); /* If PAGE_TOP or PAGE_BOTTOM, go there and we are done */ if (argument->n == PAGE_TOP) { double dontcare = 0.5; page_number_to_position(zathura->document, page_id, dontcare, 0.0, &dontcare, &pos_y); position_set(zathura, pos_x, pos_y); return false; } else if (argument->n == PAGE_BOTTOM) { double dontcare = 0.5; page_number_to_position(zathura->document, page_id, dontcare, 1.0, &dontcare, &pos_y); position_set(zathura, pos_x, pos_y); return false; } if (t == 0) { t = 1; } unsigned int view_width = 0; unsigned int view_height = 0; zathura_document_get_viewport_size(zathura->document, &view_height, &view_width); unsigned int doc_width = 0; unsigned int doc_height = 0; zathura_document_get_document_size(zathura->document, &doc_height, &doc_width); float scroll_step = 40; girara_setting_get(session, "scroll-step", &scroll_step); float scroll_hstep = -1; girara_setting_get(session, "scroll-hstep", &scroll_hstep); if (scroll_hstep < 0) { scroll_hstep = scroll_step; } float scroll_full_overlap = 0.0; girara_setting_get(session, "scroll-full-overlap", &scroll_full_overlap); bool scroll_page_aware = false; girara_setting_get(session, "scroll-page-aware", &scroll_page_aware); bool scroll_wrap = false; girara_setting_get(session, "scroll-wrap", &scroll_wrap); /* compute the direction of scrolling */ double direction = 1.0; if ((argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) || (argument->n == UP) || (argument->n == FULL_UP) || (argument->n == HALF_UP)) { direction = -1.0; } const double vstep = (double)view_height / (double)doc_height; const double hstep = (double)view_width / (double)doc_width; /* compute new position */ switch (argument->n) { case FULL_UP: case FULL_DOWN: pos_y += direction * (1.0 - scroll_full_overlap) * vstep; break; case FULL_LEFT: case FULL_RIGHT: pos_x += direction * (1.0 - scroll_full_overlap) * hstep; break; case HALF_UP: case HALF_DOWN: pos_y += direction * 0.5 * vstep; break; case HALF_LEFT: case HALF_RIGHT: pos_x += direction * 0.5 * hstep; break; case UP: case DOWN: pos_y += direction * t * scroll_step / (double)doc_height; break; case LEFT: case RIGHT: pos_x += direction * t * scroll_hstep / (double)doc_width; break; case BIDIRECTIONAL: { pos_x += event->x * t * scroll_hstep / (double)doc_width; pos_y += event->y * t * scroll_step / (double)doc_height; break; } } /* handle boundaries */ const double end_x = 0.5 * (double)view_width / (double)doc_width; const double end_y = 0.5 * (double)view_height / (double)doc_height; const double new_x = scroll_wrap ? 1.0 - end_x : end_x; const double new_y = scroll_wrap ? 1.0 - end_y : end_y; if (pos_x < end_x) { pos_x = new_x; } else if (pos_x > 1.0 - end_x) { pos_x = 1 - new_x; } if (pos_y < end_y) { pos_y = new_y; } else if (pos_y > 1.0 - end_y) { pos_y = 1 - new_y; } /* snap to the border if we change page */ const unsigned int new_page_id = position_to_page_number(zathura->document, pos_x, pos_y); if (scroll_page_aware == true && page_id != new_page_id) { double dummy = 0.0; switch(argument->n) { case FULL_LEFT: case HALF_LEFT: page_number_to_position(zathura->document, new_page_id, 1.0, 0.0, &pos_x, &dummy); break; case FULL_RIGHT: case HALF_RIGHT: page_number_to_position(zathura->document, new_page_id, 0.0, 0.0, &pos_x, &dummy); break; case FULL_UP: case HALF_UP: page_number_to_position(zathura->document, new_page_id, 0.0, 1.0, &dummy, &pos_y); break; case FULL_DOWN: case HALF_DOWN: page_number_to_position(zathura->document, new_page_id, 0.0, 0.0, &dummy, &pos_y); break; } } position_set(zathura, pos_x, pos_y); return false; }
void loop_xboard(void) { position_t* pos = position_new(); color_t engineColor = C_BLACK; IF.info_depth = info_depth; IF.info_pv = info_pv; IF.info_curmove = info_curmove; IF.search_done = search_done; log_set_mode(MODE_GUI); log_line("xboard mode"); threads_init(pos); while (1) { char* line = get_line(); char* token = arg_start(line); if (!strcmp(token, "new")) { position_reset(pos); TT_clear(); engineColor = C_BLACK; InGame = 1; } else if (!strcmp(token, "quit")) { InGame = 0; threads_search_stop(); break; } else if (!strcmp(token, "protover")) { char* v = arg_next(); if (v && atoi(v) == 2) { send_line("feature myname=\"Walce\""); send_line("feature setboard=1 usermove=1 sigint=0 sigterm=0"); send_line("feature playother=1 ping=1 time=1 colors=0 name=1"); send_line("feature ics=1 analyze=1"); send_line("feature option=\"Search Depth -spin %d 0 20\"", 0); send_line("feature option=\"Thinking Time -spin %d 0 600000\"", 0); send_line("feature done=1"); } } else if (!strcmp(token, "random") || !strcmp(token, "bk") || !strcmp(token, "ics") || !strcmp(token, "name") || !strcmp(token, "accepted") || !strcmp(token, "computer") ) { ; // IGNORE } else if (!strcmp(token, "variant") || !strcmp(token, "rejected") || !strcmp(token, "draw") || !strcmp(token, "hint") || !strcmp(token, "hard") || !strcmp(token, "easy") || !strcmp(token, "rating") || !strcmp(token, "pause") || !strcmp(token, "resume") || !strcmp(token, "memory") || !strcmp(token, "cores") || !strcmp(token, "egtpath") ) { send_line("Error (not implemented yet): %s", token); } else if (!strcmp(token, "?")) { threads_search_stop(); } else if (!strcmp(token, "st")) { token = arg_next(); if (token) TC.l_time = atoi(token) * 1000; } else if (!strcmp(token, "level")) { char* moves = arg_next(); char* min = arg_next(); char* inc = arg_next(); char* sec = min ? strchr(min, ':') : NULL; if (sec) *sec++ = 0; if (inc) { int t = atoi(min) * 60 + (sec ? atoi(sec) : 0); TC.togo = atoi(moves); TC.ctime[0] = TC.otime[0] = t * 1000; TC.ctime[1] = TC.otime[1] = atoi(inc) * 1000; } } else if (!strcmp(token, "time")) { token = arg_next(); if (token) TC.ctime[0] = atoi(token) * 10; } else if (!strcmp(token, "otim")) { token = arg_next(); if (token) TC.otime[0] = atoi(token) * 10; } else if (!strcmp(token, "analyze")) { ModeAnalyze = 1; TC.infinite = 1; engineColor = pos->to_move; threads_search(); } else if (ModeAnalyze && !strcmp(token, "exit")) { threads_search_stop(); ModeAnalyze = 0; TC.infinite = 0; } else if (ModeAnalyze && !strcmp(token, ".")) { //send_line("Error (not implemented yet): %s", token); } else if (!strncmp(line, "result", 6)) { InGame = 0; threads_search_stop(); } else if (!strncmp(line, "force", 5)) { engineColor = C_NONE; } else if (!strcmp(token, "go")) { engineColor = pos->to_move; threads_search(); } else if (!strcmp(token, "playother")) { engineColor = 1 ^ pos->to_move; } else if (!strcmp(token, "white")) { pos->to_move = C_WHITE; engineColor = C_BLACK; } else if (!strcmp(token, "black")) { pos->to_move = C_BLACK; engineColor = C_WHITE; } else if (!strcmp(token, "sd")) { char* d = arg_next(); if (d) TC.l_depth = atoi(d); } else if (!strcmp(token, "ping")) { char* a = arg_rest(); if (a) send_line("pong %s", a); else send_line("pong"); } else if (!strcmp(token, "edit")) { send_line("Error (command not implemented): %s", token); } else if (!strcmp(token, "undo")) { if (!position_unmove(pos)) send_line("Error (command not legal now): %s", token); } else if (!strcmp(token, "remove")) { if (!position_unmove(pos) || !position_unmove(pos)) send_line("Error (command not legal now): %s", token); } else if (!strcmp(token, "setboard")) { char* b = arg_rest(); if (!b) send_line("Error (missing argument): %s", token); else position_set(pos, b); } else if (!strcmp(token, "post")) { ModePost = 1; } else if (!strcmp(token, "nopost")) { ModePost = 1; } else if (!strcmp(token, "option")) { char* o = arg_next_sep('='); char* v = arg_next(); if (!o) log_line("missing option"); else if (!strcmp(o, "Thinking Time")) { if (v) TC.l_time = atoi(v); } else if (!strcmp(o, "Search Depth")) { if (v) TC.l_depth = atoi(v); } else log_line("unknown option: %s", o); } else { if (!strcmp(token, "usermove")) token = arg_next(); threads_search_stop(); move_t move = parse_move(pos, token); if (!move) { send_line("Illegal move: %s", token); } else { position_move(pos, move); position_print(pos, C_WHITE); if (ModeAnalyze || engineColor == pos->to_move) threads_search(); } } } threads_exit(); position_destroy(pos); }
void synctex_highlight_rects(zathura_t* zathura, unsigned int page, girara_list_t** rectangles) { const unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); for (unsigned int p = 0; p != number_of_pages; ++p) { GObject* widget = G_OBJECT(zathura->pages[p]); g_object_set(widget, "draw-links", FALSE, "search-results", rectangles[p], NULL); if (p == page) { g_object_set(widget, "search-current", 0, NULL); } } document_draw_search_results(zathura, true); girara_list_t* rect_list = rectangles[page]; if (rect_list == NULL || girara_list_size(rect_list) == 0) { girara_debug("No rectangles for the given page. Jumping to page %u.", page); page_set(zathura, page); return; } bool search_hadjust = true; girara_setting_get(zathura->ui.session, "search-hadjust", &search_hadjust); /* compute the position of the center of the page */ double pos_x = 0; double pos_y = 0; page_number_to_position(zathura->document, page, 0.5, 0.5, &pos_x, &pos_y); /* correction to center the current result */ /* NOTE: rectangle is in viewport units, already scaled and rotated */ unsigned int cell_height = 0; unsigned int cell_width = 0; zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width); unsigned int doc_height = 0; unsigned int doc_width = 0; zathura_document_get_document_size(zathura->document, &doc_height, &doc_width); /* Need to adjust rectangle to page scale and orientation */ zathura_page_t* doc_page = zathura_document_get_page(zathura->document, page); zathura_rectangle_t* rect = girara_list_nth(rect_list, 0); if (rect == NULL) { girara_debug("List of rectangles is broken. Jumping to page %u.", page); page_set(zathura, page); return; } zathura_rectangle_t rectangle = recalc_rectangle(doc_page, *rect); /* compute the center of the rectangle, which will be aligned to the center of the viewport */ double center_x = (rectangle.x1 + rectangle.x2) / 2; double center_y = (rectangle.y1 + rectangle.y2) / 2; pos_y += (center_y - (double)cell_height/2) / (double)doc_height; if (search_hadjust == true) { pos_x += (center_x - (double)cell_width/2) / (double)doc_width; } /* move to position */ girara_debug("Jumping to page %u position (%f, %f).", page, pos_x, pos_y); zathura_jumplist_add(zathura); position_set(zathura, pos_x, pos_y); zathura_jumplist_add(zathura); }