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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include "tile.h"
/********************************************************
Simple operations to apply to every visible tile in a list.
********************************************************/
Bool
list_oksizes(Tile*list) {
Tile*t;
FOR_EACH_VISIBLE(list->down,0){
assert(TILESIZE(t) >= t->base);
}
return true;
}
void
list_unhide(Tile*list) {
Tile*t;
FOR_EACH_TILE(list->down,0) {
t->ishidden = false;
if ( TILESIZE(t) < t->base)
t->max = t->min + t->base;
}
}
/* Slide the visible children of 't' along so that they abut one another */
void
list_slide(Tile *t) {
int prev = t->cmin;
FOR_EACH_VISIBLE(t->down, 0) {
moveto(t, prev);
prev = t->max;
}
}
/* Return the biggest visible child in the (half-open) range */
Tile*
biggest_visible(Tile*start, Tile*end) {
Tile *t, *big = 0;
FOR_EACH_VISIBLE(start, end) {
if (!big || TILESIZE(t) > TILESIZE(big))
big =t;
}
return big;
}
/* Return the last child with a visible body in the (half-open) range */
Tile*
last_visible_body(Tile*start, Tile*end) {
Tile *t, *last=0;
FOR_EACH_VISIBLE(start, end) {
if(TILESIZE(t) > t->base)
last =t;
}
return last;
}
/* Return the last visible child in the (half-open) range */
Tile*
last_visible(Tile*start, Tile*end) {
Tile *t, *last=0;
FOR_EACH_VISIBLE(start, end) {
last = t;
}
return last;
}
/* The total size of the visible tiles in the (half-open) range. */
int
list_size(Tile *start, Tile *end) {
int size=0;
Tile *t;
FOR_EACH_VISIBLE(start, end) {
size += TILESIZE(t);
}
return size;
}
/* Sum the base sizes of the tiles in the (half-open) range. */
int
list_basesize(Tile*start, Tile*end) {
int size=0;
Tile *t;
FOR_EACH_VISIBLE(start, end) {
size += t->base;
}
return size;
}
/* Find the child of 'parent' which contains position 'n' */
Tile*
list_find(Tile*parent, int n) {
Tile *t;
FOR_EACH_VISIBLE(parent->down, 0) {
if (n < t->max && n >= t->min)
break;
}
return t;
}
/* Return the next visible tile after 't' */
Tile*
next_visible(Tile*t) {
FOR_EACH_VISIBLE(t->right, 0) {
break;
}
return t;
}
/* Return the next visible tile after 't' */
Bool
list_contains(Tile*start, Tile*end, Tile *want) {
Tile*t;
FOR_EACH_VISIBLE(start,end) {
if(t==want)
return true;
}
return false;
}
|