* Make sure the map's cursor is always visible. */
| 703 | * Make sure the map's cursor is always visible. |
| 704 | */ |
| 705 | void |
| 706 | check_cursor_visibility(struct xwindow *wp) |
| 707 | { |
| 708 | Arg arg[2]; |
| 709 | Widget viewport, horiz_sb, vert_sb; |
| 710 | float top, shown, cursor_middle; |
| 711 | Boolean do_call, adjusted = False; |
| 712 | #ifdef VERBOSE |
| 713 | char *s; |
| 714 | #endif |
| 715 | |
| 716 | viewport = XtParent(wp->w); |
| 717 | horiz_sb = XtNameToWidget(viewport, "horizontal"); |
| 718 | vert_sb = XtNameToWidget(viewport, "vertical"); |
| 719 | |
| 720 | /* All values are relative to currently visible area */ |
| 721 | |
| 722 | #define V_BORDER 0.25 /* if this far from vert edge, shift */ |
| 723 | #define H_BORDER 0.25 /* if this far from horiz edge, shift */ |
| 724 | |
| 725 | #define H_DELTA 0.25 /* distance of horiz shift */ |
| 726 | #define V_DELTA 0.25 /* distance of vert shift */ |
| 727 | |
| 728 | if (horiz_sb) { |
| 729 | XtSetArg(arg[0], XtNshown, &shown); |
| 730 | XtSetArg(arg[1], nhStr(XtNtopOfThumb), &top); |
| 731 | XtGetValues(horiz_sb, arg, TWO); |
| 732 | |
| 733 | /* [ALI] Don't assume map widget is the same size as actual map */ |
| 734 | if (wp->map_information->is_tile) |
| 735 | cursor_middle = wp->map_information->tile_map.square_width; |
| 736 | else |
| 737 | cursor_middle = wp->map_information->text_map.square_width; |
| 738 | cursor_middle = (wp->cursx + 0.5) * cursor_middle / wp->pixel_width; |
| 739 | do_call = True; |
| 740 | |
| 741 | #ifdef VERBOSE |
| 742 | if (cursor_middle < top) { |
| 743 | s = " outside left"; |
| 744 | } else if (cursor_middle < top + shown * H_BORDER) { |
| 745 | s = " close to left"; |
| 746 | } else if (cursor_middle > (top + shown)) { |
| 747 | s = " outside right"; |
| 748 | } else if (cursor_middle > (top + shown - shown * H_BORDER)) { |
| 749 | s = " close to right"; |
| 750 | } else { |
| 751 | s = ""; |
| 752 | } |
| 753 | printf("Horiz: shown = %3.2f, top = %3.2f%s", shown, top, s); |
| 754 | #endif |
| 755 | |
| 756 | if (cursor_middle < top) { |
| 757 | top = cursor_middle - shown * H_DELTA; |
| 758 | if (top < 0.0) |
| 759 | top = 0.0; |
| 760 | } else if (cursor_middle < top + shown * H_BORDER) { |
| 761 | top -= shown * H_DELTA; |
| 762 | if (top < 0.0) |
no test coverage detected