X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Ffs.cc;h=0da07e53a7cb77bc4782ddc4f408c4bef7206646;hp=b65db45ce096ea359281076c745087bc3a1c2786;hb=eca943b2fb891a01cb4e883c07aad2167a8ac94b;hpb=dfbd5842ef2f270e7d83507c4ba7bed005eea780 diff --git a/src/fs.cc b/src/fs.cc index b65db45..0da07e5 100644 --- a/src/fs.cc +++ b/src/fs.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,7 @@ #include "gmath/gmath.h" #include "opengl.h" #include "app.h" +#include "drawtext.h" static IconRenderer *iconrend; @@ -19,6 +21,10 @@ static std::map node_cache; static FSNode *cur_node; static int start_child; +static dtx_font *fat_font; +#define FAT_FONT_SZ 32 + + bool init_fs() { iconrend = new ShapesIcons; @@ -26,6 +32,11 @@ bool init_fs() return false; } + if(!(fat_font = dtx_open_font("data/fat.font", FAT_FONT_SZ))) { + fprintf(stderr, "failed to open font file data/fat.font\n"); + return false; + } + cur_node = get_fsnode(0); cur_node->expand(); return true; @@ -51,11 +62,22 @@ static Vec3 icon_pos(int row, int col, int ncols, float row_spacing, float radiu return Vec3(x, y, z); } +static float icon_angle(int col, int ncols, float max_angle = 0.0f) +{ + if(max_angle > 0) { + return max_angle * ((float)col / (float)(ncols - 1) - 0.5); + } + return 2.0 * M_PI * (float)col / (float)ncols; +} + void draw_fs() { - static const int ncols = 8; static const float row_spacing = 2.0; static const float radius = 5; + static const float umax = 0.42; + static const float max_icon_angle = M_PI * 2.0 * umax; + + int max_ncols = std::max(1, umax * 16); Mat4 base_xform; base_xform.rotate(time_sec, 0, 0); @@ -65,20 +87,40 @@ void draw_fs() glUseProgram(0); glDisable(GL_TEXTURE_2D); - int first = start_child % ncols; int nchildren = (int)cur_node->children.size(); + int ncols = std::min(cur_node->nfiles, max_ncols); + + int first = start_child % ncols; int col = 0, row = 0; for(int i=0; ichildren[idx]; + + if(node->type == FSTYPE_DIR) { + continue; + } + + float angle = icon_angle(col, ncols, max_icon_angle); Mat4 xform = base_xform; - xform.translate(pos); + xform.translate(0, row * row_spacing, -radius); + xform.rotate_y(angle); glPushMatrix(); glMultMatrixf(xform[0]); - iconrend->draw(cur_node->children[idx]); + iconrend->draw(node); + glPopMatrix(); + + glPushMatrix(); + xform = Mat4::identity; + xform.translate(-dtx_string_width(node->path.get_name()) / 2.0, 0, 0); + xform.scale(0.01); + xform.translate(0, 1 + row * row_spacing, -radius); + xform.rotate_y(angle); + glMultMatrixf(xform[0]); + + dtx_string(node->path.get_name()); glPopMatrix(); if(++col >= ncols) { @@ -151,6 +193,7 @@ FSNode::FSNode() type = FSTYPE_UNKNOWN; size = 0; parent = 0; + nfiles = ndirs = 0; } bool FSNode::expand() @@ -175,6 +218,15 @@ bool FSNode::expand() if(!node) continue; children.push_back(node); + switch(node->type) { + case FSTYPE_FILE: + ++nfiles; + break; + case FSTYPE_DIR: + ++ndirs; + default: + break; + } } printf("expanded %d children\n", (int)children.size());