12 #include "gmath/gmath.h"
16 static IconRenderer *iconrend;
18 static std::map<std::string, FSNode*> node_cache;
19 static FSNode *cur_node;
20 static int start_child;
24 iconrend = new ShapesIcons;
25 if(!iconrend->init()) {
29 cur_node = get_fsnode(0);
36 std::map<std::string, FSNode*>::iterator it = node_cache.begin();
37 while(it != node_cache.end()) {
38 FSNode *node = it++->second;
45 static Vec3 icon_pos(int row, int col, int ncols, float row_spacing, float radius)
47 float angle = 2.0 * M_PI * (float)col / (float)ncols;
48 float x = sin(angle) * radius;
49 float z = -cos(angle) * radius;
50 float y = (float)row * row_spacing;
56 static const int ncols = 8;
57 static const float row_spacing = 2.0;
58 static const float radius = 5;
61 base_xform.rotate(time_sec, 0, 0);
62 base_xform.rotate(0, 0, time_sec * 0.5);
63 base_xform.translate(0, 2, 0);
66 glDisable(GL_TEXTURE_2D);
68 int first = start_child % ncols;
69 int nchildren = (int)cur_node->children.size();
72 for(int i=0; i<nchildren; i++) {
73 int idx = (i + first) % nchildren;
74 Vec3 pos = icon_pos(row, col, ncols, row_spacing, radius);
76 Mat4 xform = base_xform;
80 glMultMatrixf(xform[0]);
81 iconrend->draw(cur_node->children[idx]);
91 FSNode *get_fsnode(const char *path)
93 char *abspath = make_abs_path(path);
95 FSNode *node = node_cache[abspath];
101 if(stat(node->path, &st) == -1) {
102 fprintf(stderr, "failed to stat: %s\n", node->path.get_path());
106 node->size = st.st_size;
108 switch(st.st_mode & S_IFMT) {
110 node->type = FSTYPE_FILE;
114 node->type = FSTYPE_DIR;
119 node->type = FSTYPE_DEV;
123 node->type = FSTYPE_UNKNOWN;
125 node_cache[abspath] = node;
131 FSNode *get_fsnode(const char *dir, const char *name)
134 return get_fsnode(name);
136 if(!name || *name == '/') {
140 int len = strlen(dir) + 1 + strlen(name);
141 char *buf = new char[len + 1];
142 sprintf(buf, "%s/%s", dir, name);
143 FSNode *res = get_fsnode(buf);
148 // ---- FSNode implementation ----
151 type = FSTYPE_UNKNOWN;
156 bool FSNode::expand()
158 if(type != FSTYPE_DIR) {
162 DIR *dir = opendir(path);
164 fprintf(stderr, "failed to open dir: %s: %s\n", path.get_path(), strerror(errno));
169 while((dent = readdir(dir))) {
170 if(strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) {
174 FSNode *node = get_fsnode(path, dent->d_name);
177 children.push_back(node);
179 printf("expanded %d children\n", (int)children.size());
181 parent = get_fsnode(path.get_parent());