summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/DasherNode.cpp
Unidiff
Diffstat (limited to 'inputmethods/dasher/DasherNode.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/dasher/DasherNode.cpp167
1 files changed, 167 insertions, 0 deletions
diff --git a/inputmethods/dasher/DasherNode.cpp b/inputmethods/dasher/DasherNode.cpp
new file mode 100644
index 0000000..26af10f
--- a/dev/null
+++ b/inputmethods/dasher/DasherNode.cpp
@@ -0,0 +1,167 @@
1// DasherNode.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include "DasherNode.h"
10using namespace Dasher;
11using namespace Opts;
12using namespace std;
13
14/////////////////////////////////////////////////////////////////////////////
15
16void CDasherNode::Dump_node () const
17 {
18 /* TODO sort out
19 dchar out[256];
20 if (m_Symbol)
21 wsprintf(out,TEXT("%7x %3c %7x %5d %7x %5d %8x %8x \n"),this,m_Symbol,m_iGroup,m_context,m_Children,m_Cscheme,m_iLbnd,m_iHbnd);
22 else
23 wsprintf(out,TEXT("%7x %7x %5d %7x %5d %8x %8x \n"),this,m_iGroup,m_context,m_Children,m_Cscheme,m_iLbnd,m_iHbnd);
24
25 OutputDebugString(out);
26
27 if (m_Children) {
28 unsigned int i;
29 for (i=1;i<m_iChars;i++)
30 m_Children[i]->Dump_node();
31 }
32 */
33}
34
35void CDasherNode::Generic_Push_Node(CLanguageModel::CNodeContext *context) {
36
37 m_iAge=0;
38 m_bAlive=true;
39 if (m_Symbol && !m_iChars) // make sure it's a valid symbol and don't enter if already done
40 m_languagemodel->EnterNodeSymbol(m_context,m_Symbol);
41
42
43 vector<symbol> newchars; // place to put this list of characters
44 vector<unsigned int> cum,groups; // for the probability list
45 m_languagemodel->GetNodeProbs(m_context,newchars,groups,cum,0.003);
46 m_iChars=newchars.size();
47 // work out cumulative probs
48 unsigned int i;
49 for (i=1;i<m_iChars;i++)
50 cum[i]+=cum[i-1];
51
52 m_Children =new CDasherNode *[m_iChars];
53
54 // create the children
55 ColorSchemes NormalScheme, SpecialScheme;
56 if ((m_ColorScheme==Nodes1) || (m_ColorScheme==Special1)) {
57 NormalScheme = Nodes2;
58 SpecialScheme = Special2;
59 } else {
60 NormalScheme = Nodes1;
61 SpecialScheme = Special1;
62 }
63
64 ColorSchemes ChildScheme;
65 for (i=1;i<m_iChars;i++) {
66 if (newchars[i]==this->m_languagemodel->GetSpaceSymbol())
67 ChildScheme = SpecialScheme;
68 else
69 ChildScheme = NormalScheme;
70 m_Children[i]=new CDasherNode(this,newchars[i],groups[i],i,ChildScheme,cum[i-1],cum[i],m_languagemodel,m_languagemodel->GetColour(i));
71 }
72}
73
74/////////////////////////////////////////////////////////////////////////////
75
76void CDasherNode::Push_Node(CLanguageModel::CNodeContext *context)
77// push a node copying the specified context
78{
79
80 if (m_Children) {
81 // if there are children just give them a poke
82 unsigned int i;
83 for (i=1;i<m_iChars;i++) {
84 m_Children[i]->m_iAge=0;
85 m_Children[i]->m_bAlive=1;
86 }
87 return;
88 }
89
90 // if we haven't got a context then try to get a new one
91 m_context=m_languagemodel->CloneNodeContext(context);
92 // if it fails, be patient
93 if (!m_context)
94 return;
95 Generic_Push_Node(m_context);
96}
97
98/////////////////////////////////////////////////////////////////////////////
99
100void CDasherNode::Push_Node()
101{
102
103 if (m_Children) {
104 // if there are children just give them a poke
105 unsigned int i;
106 for (i=1;i<m_iChars;i++) {
107 m_Children[i]->m_iAge=0;
108 m_Children[i]->m_bAlive=1;
109 }
110 return;
111 }
112
113 // if we haven't got a context then try to get a new one
114 if (m_parent)
115 m_context=m_languagemodel->CloneNodeContext(m_parent->m_context);
116 else
117 m_context=m_languagemodel->GetRootNodeContext();
118
119 // if it fails, be patient
120 if (!m_context)
121 return;
122 Generic_Push_Node(m_context);
123}
124
125/////////////////////////////////////////////////////////////////////////////
126
127void CDasherNode::Get_string_under(const int iNormalization,const myint miY1,const myint miY2,const myint miMousex,const myint miMousey, vector<symbol> &vString) const
128{
129 // we are over (*this) node so add it to the string
130 vString.push_back(m_Symbol);
131
132 // look for children who might also be under the coords
133 if (m_Children) {
134 myint miRange=miY2-miY1;
135 unsigned int i;
136 for (i=1;i<m_iChars;i++) {
137 myint miNewy1=miY1+(miRange*m_Children[i]->m_iLbnd)/iNormalization;
138 myint miNewy2=miY1+(miRange*m_Children[i]->m_iHbnd)/iNormalization;
139 if (miMousey<miNewy2 && miMousey>miNewy1 && miMousex<miNewy2-miNewy1) {
140 m_Children[i]->Get_string_under(iNormalization,miNewy1,miNewy2,miMousex,miMousey,vString);
141 return;
142 }
143 }
144 }
145 return;
146}
147
148/////////////////////////////////////////////////////////////////////////////
149
150CDasherNode * const CDasherNode::Get_node_under(int iNormalization,myint miY1,myint miY2,myint miMousex,myint miMousey)
151{
152 if (m_Children) {
153 myint miRange=miY2-miY1;
154 m_iAge=0;
155 m_bAlive=true;
156 unsigned int i;
157 for (i=1;i<m_iChars;i++) {
158 myint miNewy1=miY1+(miRange*m_Children[i]->m_iLbnd)/iNormalization;
159 myint miNewy2=miY1+(miRange*m_Children[i]->m_iHbnd)/iNormalization;
160 if (miMousey<miNewy2 && miMousey>miNewy1 && miMousex<miNewy2-miNewy1)
161 return m_Children[i]->Get_node_under(iNormalization,miNewy1,miNewy2,miMousex,miMousey);
162 }
163 }
164 return this;
165}
166
167/////////////////////////////////////////////////////////////////////////////