fixed scale in VR
[vrfileman] / src / icon.cc
1 #include <string.h>
2 #include "icon.h"
3 #include "fs.h"
4 #include "meshgen.h"
5 #include "mesh.h"
6
7 IconRenderer::~IconRenderer()
8 {
9 }
10
11 bool IconRenderer::init()
12 {
13         return true;
14 }
15
16 void IconRenderer::shutdown()
17 {
18 }
19
20
21 // Shapes icon renderer
22 enum {
23         SHAPE_SPHERE,
24         SHAPE_BOX,
25         SHAPE_TORUS,
26         SHAPE_CONE,
27         NUM_SHAPES
28 };
29
30 struct ShapesIconsPriv {
31         Mesh *shape[NUM_SHAPES];
32 };
33
34 ShapesIcons::ShapesIcons()
35 {
36         priv = new ShapesIconsPriv;
37         memset(priv, 0, sizeof *priv);
38 }
39
40 ShapesIcons::~ShapesIcons()
41 {
42         shutdown();
43         delete priv;
44 }
45
46 bool ShapesIcons::init()
47 {
48         const float s = 0.12;
49
50         for(int i=0; i<NUM_SHAPES; i++) {
51                 priv->shape[i] = new Mesh;
52         }
53
54         Mat4 xform;
55
56         gen_geosphere(priv->shape[SHAPE_SPHERE], 0.5 * s, 0);
57         gen_box(priv->shape[SHAPE_BOX], 0.7 * s, 0.7 * s, 0.7 * s);
58         gen_torus(priv->shape[SHAPE_TORUS], 0.4 * s, 0.1 * s, 12, 6);
59
60         gen_cone(priv->shape[SHAPE_CONE], 0.5 * s, 1.0 * s, 8, 2, 1);
61         xform.translation(0, -0.33 * s, 0);
62         priv->shape[SHAPE_CONE]->apply_xform(xform, Mat4::identity);
63
64         return true;
65 }
66
67 void ShapesIcons::shutdown()
68 {
69         for(int i=0; i<NUM_SHAPES; i++) {
70                 delete priv->shape[i];
71         }
72 }
73
74 static int fstype_shape(FSNodeType type)
75 {
76         switch(type) {
77         case FSTYPE_FILE:
78                 return SHAPE_SPHERE;
79         case FSTYPE_DIR:
80                 return SHAPE_BOX;
81         case FSTYPE_DEV:
82                 return SHAPE_TORUS;
83         default:
84                 break;
85         }
86         return SHAPE_CONE;
87 }
88
89 void ShapesIcons::draw(FSNode *node) const
90 {
91         int s = fstype_shape(node->type);
92         priv->shape[s]->draw_wire();
93 }