summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2014-08-26 14:33:57 -0400
committerQuentin Carbonneaux2014-08-26 14:38:06 -0400
commitc0db2c17bca4d0349edfd21504b0ad7c8b9f7fc4 (patch)
tree6c250cf115a00c9f21ce9efcbbc68b726670eb71
parent79356dbfaad1e47e05326f9cf569abeda0c79f2a (diff)
change api for gui control box
-rw-r--r--gui.h2
-rw-r--r--main.c50
-rw-r--r--x11.c14
3 files changed, 29 insertions, 37 deletions
diff --git a/gui.h b/gui.h
index 4b73104..c4d01bf 100644
--- a/gui.h
+++ b/gui.h
@@ -106,13 +106,13 @@ struct gui {
void (*drawtext)(GRect *clip, Rune *str, int len,
int x, int y, GColor color);
void (*drawrect)(GRect *clip, int x, int y, int w, int h, GColor c);
- int (*ptincontrol)(GRect *clip, int x, int y);
void (*setpointer)(GPointer pt);
int (*textwidth)(Rune *str, int len);
int (*nextevent)(GEvent *eret);
int hmargin;
int vmargin;
int border;
+ GRect actionr;
};
/* Available gui modules */
diff --git a/main.c b/main.c
index a137d17..a63fc96 100644
--- a/main.c
+++ b/main.c
@@ -28,7 +28,7 @@ static int
gev(int fd, int flag, void *unused)
{
static unsigned selbeg;
- static W *mwin;
+ static W *mousewin;
static int resizing;
unsigned pos;
W *win;
@@ -53,31 +53,29 @@ gev(int fd, int flag, void *unused)
scrolling = 0;
break;
case GMouseDown:
+ mousewin = win_locus(e.mouse.x, e.mouse.y, &pos);
+ if (!mousewin)
+ break;
if (e.mouse.button == GBLeft) {
- mwin = win_locus(e.mouse.x, e.mouse.y, &pos);
- if (!mwin)
- break;
- if (g->ptincontrol(&mwin->gr, e.mouse.x, e.mouse.y)) {
+ if (e.mouse.x - mousewin->gr.x < g->actionr.w)
+ if (e.mouse.y - mousewin->gr.y < g->actionr.h) {
g->setpointer(GPResize);
resizing = 1;
break;
}
- if (mwin == curwin) {
- selbeg = pos;
- goto Select;
- }
- curwin = mwin;
- mwin = 0;
+ curwin = mousewin;
+ selbeg = pos;
+ goto Setcursor;
} else if (e.mouse.button == GBWheelUp) {
- win_scroll(curwin, -4);
+ win_scroll(mousewin, -4);
} else if (e.mouse.button == GBWheelDown) {
- win_scroll(curwin, +4);
+ win_scroll(mousewin, +4);
}
break;
case GMouseUp:
if (resizing) {
resizing = 0;
- win_move(mwin, e.mouse.x, e.mouse.y);
+ win_move(mousewin, e.mouse.x, e.mouse.y);
g->setpointer(GPNormal);
}
break;
@@ -85,7 +83,7 @@ gev(int fd, int flag, void *unused)
if (resizing)
break;
win = win_locus(e.mouse.x, e.mouse.y, &pos);
- if (win && mwin == win) {
+ if (win && mousewin == win) {
assert(selbeg != -1u);
if (pos != selbeg) {
eb_setmark(curwin->eb, SelBeg, selbeg);
@@ -93,21 +91,19 @@ gev(int fd, int flag, void *unused)
}
} else
pos = curwin->cu;
- goto Select;
+ goto Setcursor;
default:
break;
}
- if (0) {
- Select:
- curwin->cu = pos;
- curwin->rev = 0;
- } else {
- selbeg = -1u;
- if (curwin->cu >= curwin->l[curwin->nl])
- curwin->cu = curwin->l[curwin->nl-1];
- if (curwin->cu < curwin->l[0])
- curwin->cu = curwin->l[0];
- }
+ selbeg = -1u;
+ if (curwin->cu >= curwin->l[curwin->nl])
+ curwin->cu = curwin->l[curwin->nl-1];
+ if (curwin->cu < curwin->l[0])
+ curwin->cu = curwin->l[0];
+ continue;
+ Setcursor:
+ curwin->cu = pos;
+ curwin->rev = 0;
}
win_redraw_frame();
diff --git a/x11.c b/x11.c
index 9ed4762..e6db2f1 100644
--- a/x11.c
+++ b/x11.c
@@ -83,6 +83,10 @@ init()
pbuf = XCreatePixmap(d, win, Width, Height, depth);
xft = XftDrawCreate(d, pbuf, visual, cmap);
+ /* set the action rectangle */
+ gui_x11.actionr.w = HMargin - 3;
+ gui_x11.actionr.h = VMargin + font->height;
+
return XConnectionNumber(d);
}
@@ -169,14 +173,6 @@ decorate(GRect *clip, int dirty, GColor c)
drawrect(clip, 2, 2, HMargin-7, boxh-4, c);
}
-static int
-ptincontrol(GRect *clip, int x, int y)
-{
- return
- (x -= clip->x) >= 0 && x < HMargin-3 &&
- (y -= clip->y) >= 0 && y < VMargin + font->height;
-}
-
static void
setpointer(GPointer pt)
{
@@ -350,10 +346,10 @@ struct gui gui_x11 = {
.drawtext = drawtext,
.getfont = getfont,
.nextevent = nextevent,
- .ptincontrol = ptincontrol,
.setpointer = setpointer,
.textwidth = textwidth,
.hmargin = HMargin,
.vmargin = VMargin,
.border = Border,
+ .actionr = {0, 0, 0, 0},
};