vrfileman

changeset 6:b041bc1c38ad tip

layout
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 03 Feb 2015 15:42:03 +0200
parents d487181ee1d9
children
files src/fs.cc src/fs.h src/layout.cc src/layout.h
diffstat 4 files changed, 127 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/src/fs.cc	Tue Feb 03 03:35:14 2015 +0200
     1.2 +++ b/src/fs.cc	Tue Feb 03 15:42:03 2015 +0200
     1.3 @@ -32,7 +32,6 @@
     1.4  	sorted = true;
     1.5  	uid = gid = mode = 0;
     1.6  	type = UNKNOWN;
     1.7 -	data = 0;
     1.8  }
     1.9  
    1.10  void FSNode::destroy()
    1.11 @@ -228,16 +227,6 @@
    1.12  	return expanded;
    1.13  }
    1.14  
    1.15 -void FSNode::set_ext_data(void *data)
    1.16 -{
    1.17 -	this->data = data;
    1.18 -}
    1.19 -
    1.20 -void *FSNode::get_ext_data() const
    1.21 -{
    1.22 -	return data;
    1.23 -}
    1.24 -
    1.25  
    1.26  // ---- FSDir ----
    1.27  FSDir::FSDir()
     2.1 --- a/src/fs.h	Tue Feb 03 03:35:14 2015 +0200
     2.2 +++ b/src/fs.h	Tue Feb 03 15:42:03 2015 +0200
     2.3 @@ -17,8 +17,6 @@
     2.4  	Type type;
     2.5  	unsigned int uid, gid, mode;
     2.6  
     2.7 -	void *data;
     2.8 -
     2.9  private:
    2.10  	FSNode(const FSNode&);
    2.11  	FSNode &operator =(const FSNode&);
    2.12 @@ -59,9 +57,6 @@
    2.13  
    2.14  	virtual bool expand();
    2.15  	virtual bool is_expanded() const;
    2.16 -
    2.17 -	virtual void set_ext_data(void *data);
    2.18 -	virtual void *get_ext_data() const;
    2.19  };
    2.20  
    2.21  class FSDir : public FSNode {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/layout.cc	Tue Feb 03 15:42:03 2015 +0200
     3.3 @@ -0,0 +1,81 @@
     3.4 +#include "layout.h"
     3.5 +
     3.6 +Layout::Layout()
     3.7 +{
     3.8 +	init();
     3.9 +}
    3.10 +
    3.11 +Layout::~Layout()
    3.12 +{
    3.13 +	destroy();
    3.14 +}
    3.15 +
    3.16 +bool Layout::init()
    3.17 +{
    3.18 +	tree = 0;
    3.19 +	return true;
    3.20 +}
    3.21 +
    3.22 +void Layout::destroy()
    3.23 +{
    3.24 +	std::map<FSNode*, LayoutData*>::iterator it = node_data.begin();
    3.25 +	while(it != node_data.end()) {
    3.26 +		delete it->second;
    3.27 +		++it;
    3.28 +	}
    3.29 +	node_data.clear();
    3.30 +}
    3.31 +
    3.32 +void Layout::clear()
    3.33 +{
    3.34 +	destroy();
    3.35 +	init();
    3.36 +}
    3.37 +
    3.38 +void Layout::set_root(FSNode *root)
    3.39 +{
    3.40 +	clear();
    3.41 +	tree = root;
    3.42 +}
    3.43 +
    3.44 +Vector3 Layout::get_local_pos(const FSNode *node) const
    3.45 +{
    3.46 +	return Vector3();
    3.47 +}
    3.48 +
    3.49 +Vector3 Layout::get_world_pos(const FSNode *node) const
    3.50 +{
    3.51 +	Vector3 pos;
    3.52 +
    3.53 +	while(node) {
    3.54 +		pos += get_local_pos(node);
    3.55 +		node = node->get_parent();
    3.56 +	}
    3.57 +	return pos;
    3.58 +}
    3.59 +
    3.60 +
    3.61 +// ---- PlanarLayout ----
    3.62 +
    3.63 +void PlanarLayout::layout()
    3.64 +{
    3.65 +	clear();
    3.66 +
    3.67 +	if(!tree) return;
    3.68 +
    3.69 +	PlanarLayoutData *root_data = new PlanarLayoutData;
    3.70 +	root_data->width = root_data->height = 0;
    3.71 +	root_data->sub_width = root_data->sub_width = 0;
    3.72 +	node_data[tree] = root_data;
    3.73 +
    3.74 +	layout_tree(tree);
    3.75 +}
    3.76 +
    3.77 +void PlanarLayout::layout_tree(FSNode *tree)
    3.78 +{
    3.79 +
    3.80 +}
    3.81 +
    3.82 +Vector3 PlanarLayout::get_local_pos(const FSNode *node) const
    3.83 +{
    3.84 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/layout.h	Tue Feb 03 15:42:03 2015 +0200
     4.3 @@ -0,0 +1,46 @@
     4.4 +#ifndef LAYOUT_H_
     4.5 +#define LAYOUT_H_
     4.6 +
     4.7 +#include <map>
     4.8 +#include <vmath/vmath.h>
     4.9 +#include "fs.h"
    4.10 +
    4.11 +struct LayoutData {};
    4.12 +
    4.13 +class Layout {
    4.14 +protected:
    4.15 +	FSNode *tree;
    4.16 +	std::map<FSNode*, LayoutData*> node_data;
    4.17 +
    4.18 +public:
    4.19 +	Layout();
    4.20 +	virtual ~Layout();
    4.21 +
    4.22 +	virtual bool init();
    4.23 +	virtual void destroy();
    4.24 +	virtual void clear();
    4.25 +
    4.26 +	virtual void set_root(FSNode *root);
    4.27 +
    4.28 +	virtual void layout() = 0;
    4.29 +
    4.30 +	virtual Vector3 get_local_pos(const FSNode *node) const;
    4.31 +	virtual Vector3 get_world_pos(const FSNode *node) const;
    4.32 +};
    4.33 +
    4.34 +struct PlanarLayoutData {
    4.35 +	Vector2 pos; /* local pos, relative to parent */
    4.36 +	float width, height;
    4.37 +	float sub_width, sub_height;
    4.38 +};
    4.39 +
    4.40 +class PlanarLayout : public Layout {
    4.41 +private:
    4.42 +	void layout_tree(FSNode *tree);
    4.43 +
    4.44 +public:
    4.45 +	void layout();
    4.46 +};
    4.47 +
    4.48 +
    4.49 +#endif	// LAYOUT_H_