summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/DasherNode.h
blob: 705a9d46d5dc1f05b22b1eb2daee8d3c7cf4b70b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// DasherNode.h
//
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2002 David Ward
//
/////////////////////////////////////////////////////////////////////////////

#ifndef __DasherNode_h__
#define __DasherNode_h__

#include "NoClones.h"
#include "DasherTypes.h"
#include "LanguageModel.h"

namespace Dasher {class CDasherNode;}
class Dasher::CDasherNode : private NoClones
{
	// CDasherNode represents a rectangle and character 
	// nodes have children, siblings and parents
private:
	const unsigned int m_iLbnd,m_iHbnd;// the cumulative lower and upper bound prob relative to parent
	const unsigned int m_iGroup;       // group membership - e.g. 0=nothing 1=caps 2=punc
	unsigned int m_iChars, m_iAge;
	bool m_bAlive;                     // if true, then display node, else dont bother
	bool m_bControlNode;               // if true, node is a control node
	bool m_bControlChild;              // if true, node is offspring of a control node
	//bool m_Cscheme;                  // color scheme for the node - alternates through relatives
	Opts::ColorSchemes m_ColorScheme;
	int m_iPhase;                      // index for coloring
	int m_iColour;                     // for the advanced colour mode
	
	const symbol m_Symbol;             // the character to display
	CLanguageModel *m_languagemodel;   // pointer to the language model - in future, could be different for each node	
	CDasherNode **m_Children;          // pointer to array of children
	CDasherNode *m_parent;             // pointer to parent - only needed to grab parent context
	CLanguageModel::CNodeContext *m_context;
public:
	
	CDasherNode(CDasherNode *parent,symbol Symbol, unsigned int igroup, int iphase, Opts::ColorSchemes ColorScheme,int ilbnd,int ihbnd,CLanguageModel *lm, int Colour);
	~CDasherNode();
	bool m_bForce;                     // flag to force a node to be drawn - shouldn't be public
    
	// return private data members - read only 
	CDasherNode ** const Children() const {return m_Children;}
	unsigned int Lbnd() const {return m_iLbnd;}
	bool Alive() {return m_bAlive;}
	bool Control() {return m_bControlChild;}
	void Kill()  {m_bAlive=0;m_iAge=0;}
	unsigned int Hbnd() const {return m_iHbnd;}
	unsigned int Group() const {return m_iGroup;}
	unsigned int Age() const {return m_iAge;}
	symbol Symbol() const {return m_Symbol;}
	unsigned int Chars() const {return m_iChars;}
	int Phase() const {return m_iPhase;}
	Opts::ColorSchemes Cscheme() const {return m_ColorScheme;}
	int Colour() const {return m_iColour;}
	
	CDasherNode* const Get_node_under(int,myint y1,myint y2,myint smousex,myint smousey); // find node under given co-ords
	void Get_string_under(const int,const myint y1,const myint y2,const myint smousex,const myint smousey,std::vector<symbol>&) const; // get string under given co-ords
	void Generic_Push_Node(CLanguageModel::CNodeContext *context);
	void Push_Node();                                      // give birth to children
	void Push_Node(CLanguageModel::CNodeContext *context); // give birth to children with this context
	void Delete_children();
	void Dump_node() const;                                // diagnostic
};

/////////////////////////////////////////////////////////////////////////////
// Inline functions
/////////////////////////////////////////////////////////////////////////////

using namespace Dasher;
using namespace Opts;

/////////////////////////////////////////////////////////////////////////////

inline CDasherNode::CDasherNode(CDasherNode *parent,symbol Symbol, unsigned int igroup, int iphase, ColorSchemes ColorScheme,int ilbnd,int ihbnd,CLanguageModel *lm, int Colour=0)
	: m_parent(parent),m_Symbol(Symbol),m_iGroup(igroup),m_iLbnd(ilbnd),m_iHbnd(ihbnd),m_languagemodel(lm),m_iPhase(iphase),
  m_context(0), m_iAge(0), m_bAlive(1), m_Children(0), m_bForce(false), m_iChars(0), m_ColorScheme(ColorScheme), m_bControlChild(false), m_iColour(Colour)
{
	/*
	switch (ColorScheme) {
		case Nodes1:
			m_ColorScheme = Nodes2;
			break;
		case Nodes2:
			m_ColorScheme = Nodes1;
			break;
		case Special1:
			m_ColorScheme = Special2;
			break;
		case Special2:
			m_ColorScheme = Special1;
			break;
		case default:
			m_ColorScheme = ColorScheme;
			break;
	}
	*/
}

/////////////////////////////////////////////////////////////////////////////

inline void CDasherNode::Delete_children() 
{
	if (m_Children) {
		unsigned int i; 
		for (i=1;i<m_iChars;i++)
			delete m_Children[i];
		delete [] m_Children;
	}
	m_Children=0;
	
}

/////////////////////////////////////////////////////////////////////////////

inline CDasherNode::~CDasherNode() 
{
	Delete_children();
	if (m_context)
		m_languagemodel->ReleaseNodeContext(m_context);
}

/////////////////////////////////////////////////////////////////////////////

#endif /* #ifndef __DasherNode_h__ */