1e929950b87d3f5a9ac2edcd62c62e552d3ce444
[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         for(int i=0; i<NUM_SHAPES; i++) {
49                 priv->shape[i] = new Mesh;
50         }
51
52         Mat4 xform;
53
54         gen_geosphere(priv->shape[SHAPE_SPHERE], 0.5, 0);
55         gen_box(priv->shape[SHAPE_BOX], 1, 1, 1);
56         gen_torus(priv->shape[SHAPE_TORUS], 0.4, 0.1, 12, 6);
57
58         gen_cone(priv->shape[SHAPE_CONE], 0.5, 1.0, 8, 2, 1);
59         xform.translation(0, -0.33, 0);
60         priv->shape[SHAPE_CONE]->apply_xform(xform, Mat4::identity);
61
62         return true;
63 }
64
65 void ShapesIcons::shutdown()
66 {
67         for(int i=0; i<NUM_SHAPES; i++) {
68                 delete priv->shape[i];
69         }
70 }
71
72 static int fstype_shape(FSNodeType type)
73 {
74         switch(type) {
75         case FSNODE_FILE:
76                 return SHAPE_SPHERE;
77         case FSNODE_DIR:
78                 return SHAPE_BOX;
79         case FSNODE_DEV:
80                 return SHAPE_TORUS;
81         default:
82                 break;
83         }
84         return SHAPE_CONE;
85 }
86
87 void ShapesIcons::draw(FSNode *node) const
88 {
89         int s = fstype_shape(node->type);
90         priv->shape[s]->draw_wire();
91 }