MCPcopy Create free account
hub / github.com/NetHack/NetHack / check_cursor_visibility

Function check_cursor_visibility

win/X11/winmap.c:705–848  ·  view source on GitHub ↗

* Make sure the map's cursor is always visible. */

Source from the content-addressed store, hash-verified

703 * Make sure the map's cursor is always visible.
704 */
705void
706check_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)

Callers 3

input_eventFunction · 0.85
map_check_size_changeFunction · 0.85
display_map_windowFunction · 0.85

Calls 2

printfFunction · 0.85
display_cursorFunction · 0.85

Tested by

no test coverage detected