File: point.c

package info (click to toggle)
wily 0.13.33-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,500 kB
  • ctags: 1,720
  • sloc: ansic: 12,830; sh: 245; makefile: 188
file content (68 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "tile.h"
#include "view.h"

/* Set 'cmin' and 'cmax' for any child of 'list'  */
void
setcminmax(Tile *list, int*cmin, int*cmax) {
	if(list) {
		*cmin = (list->ori == V)? list->tag->r.max.y + tagheight:list->min;
		*cmax = list->max;
	} else {
		*cmin = 0;
		*cmax = screen.r.max.x;
	}
}

/* Return the Rectangle to enclose 't' */
Rectangle
rectangle(Tile*t) {
	if(t->ori==H) {
		return Rect(t->min, t->up->tag->r.max.y, 
				t->max, t->up->max);
	} else if (t->up) {
		return Rect(t->up->min, t->min, t->up->max, t->max);
	} else {
		return Rect(0, t->min, t->cmax, t->max);
	}
}

/* Return a point somewhere in the middle of 'tile's button */
Point
buttonpos(Tile*tile) {
	return add(tile->tag->r.min, Pt(SCROLLWIDTH/2, SCROLLWIDTH/2));
}

/* Return the tile containing p (or 0) */
Tile*
point2tile(Tile *tile, Point p) {
	int	pos;
	Tile	*t;

	assert(tile);
	if(tile->body || ptinrect(p, tile->tag->r))
		return tile;
	pos = tile->ori==V ? p.x : p.y ;
	for (t =tile ->down; t; t=t->right) {
		if (!tile_hidden(t) && pos < t->max && pos >= t->min)
			break;
	}
	if (t && !tile_hidden(t) && pos > t->min)
		return point2tile(t,p);
	return tile;
}

/* Return the view containing p (or 0) */
View *
point2view(Point p) {
	Tile	*t;
	View	*v;

	t = point2tile(wily, p);
	if (ptinrect(p, t->tag->r))
		v=  t->tag;
	else
		v = t->body;
	assert(IMPLIES(v, ptinrect(p, v->r)));
	return v;
}