diff options
| author | Quentin Carbonneaux | 2014-08-26 16:17:23 -0400 |
|---|---|---|
| committer | Quentin Carbonneaux | 2014-08-26 16:19:05 -0400 |
| commit | 12ac8baeecda34d67b343cd5880ccd4c01ddb36d (patch) | |
| tree | 36eac99cd0d2b78ac801f9f58cee2c55ccaea81b | |
| parent | d6ad5497539563429c2230ec14dfe40e1b7dbdba (diff) | |
split win_locus in two functions
| -rw-r--r-- | main.c | 19 | ||||
| -rw-r--r-- | win.c | 45 | ||||
| -rw-r--r-- | win.h | 3 |
3 files changed, 35 insertions, 32 deletions
@@ -31,7 +31,6 @@ gev(int fd, int flag, void *unused) static W *mousewin; static int resizing; unsigned pos; - W *win; GEvent e; (void) fd; @@ -53,7 +52,7 @@ gev(int fd, int flag, void *unused) scrolling = 0; break; case GMouseDown: - mousewin = win_locus(e.mouse.x, e.mouse.y, &pos); + mousewin = win_which(e.mouse.x, e.mouse.y); if (!mousewin) break; if (e.mouse.button == GBLeft) { @@ -64,6 +63,7 @@ gev(int fd, int flag, void *unused) break; } curwin = mousewin; + pos = win_at(mousewin, e.mouse.x, e.mouse.y); selbeg = pos; goto Setcursor; } else if (e.mouse.button == GBWheelUp) { @@ -82,15 +82,12 @@ gev(int fd, int flag, void *unused) case GMouseSelect: if (resizing) break; - win = win_locus(e.mouse.x, e.mouse.y, &pos); - if (win && mousewin == win) { - assert(selbeg != -1u); - if (pos != selbeg) { - eb_setmark(curwin->eb, SelBeg, selbeg); - eb_setmark(curwin->eb, SelEnd, pos); - } - } else - pos = curwin->cu; + assert(selbeg != -1u); + pos = win_at(mousewin, e.mouse.x, e.mouse.y); + if (pos != selbeg) { + eb_setmark(curwin->eb, SelBeg, selbeg); + eb_setmark(curwin->eb, SelEnd, pos); + } goto Setcursor; default: break; @@ -111,30 +111,18 @@ win_delete(W *w) // also, do not delete if only one window is left } -/* win_locus - Find a window on the screen at position [x1], - * [y1]. If the argument pointer is non null, it is used to - * store the position of the pointed rune. +/* win_at - Return the buffer offset at the specified location, + * if no offset is found the cursor position is returned. */ -W * -win_locus(int x1, int y1, unsigned *pos) +unsigned +win_at(W *w, int x1, int y1) { - W *w; - int i, x; + int x; unsigned p; - for (i=0; (w = screen[i]); i++) - if (x1 < w->gr.x + w->gr.w) - break; - if (tag.visible && tag.owner == w) - if (y1 >= tag.win.gr.y) - w = &tag.win; - if (!pos || !w) - return w; y1 = (y1 - g->vmargin - w->gr.y) / font.height; - if (y1 < 0 || y1 >= w->nl) { - *pos = -1u; - return w; - } + if (y1 < 0 || y1 >= w->nl) + return w->cu; p = w->l[y1]; x = 0; for (; p < w ->l[y1+1] - 1; p++) { @@ -142,7 +130,24 @@ win_locus(int x1, int y1, unsigned *pos) if (x + w->gr.x + g->hmargin >= x1) break; } - *pos = p; + return p; +} + +/* win_which - Find the window at the specified position, null + * is returned if no window is found. + */ +W * +win_which(int x1, int y1) +{ + W *w; + int i; + + for (i=0; (w = screen[i]); i++) + if (x1 < w->gr.x + w->gr.w) + break; + if (tag.visible && tag.owner == w) + if (y1 >= tag.win.gr.y) + return &tag.win; return w; } @@ -35,7 +35,8 @@ enum CursorLoc { CTop, CMid, CBot }; void win_init(struct gui *g); W *win_new(EBuf *eb); void win_delete(W *); -W *win_locus(int, int, unsigned *); +unsigned win_at(W *w, int x, int y); +W *win_which(int x, int y); void win_move(W *, int x, int y); void win_resize_frame(int w, int h); void win_redraw_frame(void); |
