[dasher] Colours: move default scheme + phase-cycling into AlphMgr



commit 69b4501f738262e2adbb007c49e920548893206e
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Mon Feb 21 15:00:41 2011 +0000

    Colours: move default scheme + phase-cycling into AlphMgr
    
    AlphInfo::GetColour(sym) just gives number specified in XML, -1 if nothing was;
    AlphMgr uses symbol# in place of -1, and increments by 130 in two phases.

 Src/DasherCore/Alphabet/AlphInfo.cpp |   24 ------------------------
 Src/DasherCore/Alphabet/AlphInfo.h   |    7 ++++---
 Src/DasherCore/AlphabetManager.cpp   |   26 +++++++++++++++++++++++++-
 Src/DasherCore/AlphabetManager.h     |    8 +++++++-
 4 files changed, 36 insertions(+), 29 deletions(-)
---
diff --git a/Src/DasherCore/Alphabet/AlphInfo.cpp b/Src/DasherCore/Alphabet/AlphInfo.cpp
index 74fd688..08f5342 100644
--- a/Src/DasherCore/Alphabet/AlphInfo.cpp
+++ b/Src/DasherCore/Alphabet/AlphInfo.cpp
@@ -46,30 +46,6 @@ int CAlphInfo::GetTextColour(symbol Symbol) const {
   }
 }
 
-int 
-CAlphInfo::GetColour(symbol i, int iPhase) const {
-  int iColour = m_vCharacters[i-1].Colour;
-  
-  // This is for backwards compatibility with old alphabet files -
-  // ideally make this log a warning (unrelated TODO: automate
-  // validation of alphabet files, plus maintenance of repository
-  // etc.)
-  if(iColour == -1) {
-    if(i == iSpaceCharacter) {
-      iColour = 9;
-    }
-    else {
-      iColour = (i % 3) + 10;
-    }
-  }
-  
-  // Loop on low colours for nodes (TODO: go back to colour namespaces?)
-  if(iPhase == 1 && iColour < 130)
-    iColour += 130;
-  
-  return iColour;
-}
-
 CAlphabetMap *CAlphInfo::MakeMap() const {
   CAlphabetMap *map = new CAlphabetMap();
   if (iParagraphCharacter!=0) map->AddParagraphSymbol(iParagraphCharacter);
diff --git a/Src/DasherCore/Alphabet/AlphInfo.h b/Src/DasherCore/Alphabet/AlphInfo.h
index 585e197..6cce20e 100644
--- a/Src/DasherCore/Alphabet/AlphInfo.h
+++ b/Src/DasherCore/Alphabet/AlphInfo.h
@@ -95,9 +95,10 @@ public:
   /// return text for edit box for i'th symbol
   const std::string & GetText(symbol i) const {return m_vCharacters[i-1].Text;} 
   
-  // return string for i'th symbol
-  
-  int GetColour(symbol i, int iPhase) const;
+  // return colour specified for i'th symbol, or -1 if nothing in the XML  
+  int GetColour(symbol i) const {
+    return m_vCharacters[i-1].Colour;
+  };
   
   /// Text foreground colour for i'th symbol; default 4 if unspecified
   int GetTextColour(symbol i) const;
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index 21372f5..fe99e73 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -92,12 +92,36 @@ CAlphabetManager::~CAlphabetManager() {
   delete m_pLanguageModel;
 }
 
+int CAlphabetManager::GetColour(symbol sym, int iOffset) const {
+  int iColour = m_pAlphabet->GetColour(sym);
+  
+  // This is for backwards compatibility with old alphabet files -
+  // ideally make this log a warning (unrelated TODO: automate
+  // validation of alphabet files, plus maintenance of repository
+  // etc.)
+  if(iColour == -1) {
+    if(sym == m_pAlphabet->GetSpaceSymbol()) {
+      iColour = 9;
+    }
+    else {
+      iColour = (sym % 3) + 10;
+    }
+  }
+  
+  // Loop on low colours for nodes (TODO: go back to colour namespaces?)
+  if((iOffset&1) == 0 && iColour < 130)
+    iColour += 130;
+  
+  return iColour;
+}
+
+
 CAlphabetManager::CAlphNode::CAlphNode(CDasherNode *pParent, int iOffset, unsigned int iLbnd, unsigned int iHbnd, int iColour, const string &strDisplayText, CAlphabetManager *pMgr)
 : CDasherNode(pParent, iOffset, iLbnd, iHbnd, iColour, strDisplayText), m_pProbInfo(NULL), m_pMgr(pMgr) {
 }
 
 CAlphabetManager::CSymbolNode::CSymbolNode(CDasherNode *pParent, int iOffset, unsigned int iLbnd, unsigned int iHbnd, CAlphabetManager *pMgr, symbol _iSymbol)
-: CAlphNode(pParent, iOffset, iLbnd, iHbnd, pMgr->m_pAlphabet->GetColour(_iSymbol, (iOffset&1)^1), pMgr->m_pAlphabet->GetDisplayText(_iSymbol), pMgr), iSymbol(_iSymbol) {
+: CAlphNode(pParent, iOffset, iLbnd, iHbnd, pMgr->GetColour(_iSymbol, iOffset), pMgr->m_pAlphabet->GetDisplayText(_iSymbol), pMgr), iSymbol(_iSymbol) {
 }
 
 CAlphabetManager::CSymbolNode::CSymbolNode(CDasherNode *pParent, int iOffset, unsigned int iLbnd, unsigned int iHbnd, int iColour, const string &strDisplayText, CAlphabetManager *pMgr, symbol _iSymbol)
diff --git a/Src/DasherCore/AlphabetManager.h b/Src/DasherCore/AlphabetManager.h
index 850f465..7abd62e 100644
--- a/Src/DasherCore/AlphabetManager.h
+++ b/Src/DasherCore/AlphabetManager.h
@@ -81,7 +81,7 @@ namespace Dasher {
     };
     class CSymbolNode : public CAlphNode {
     public:
-      ///Standard constructor, gets colour+label by looking up symbol in current alphabet (& computing phase from offset)
+      ///Standard constructor, gets colour from GetColour(symbol,offset) and label from current alphabet
       CSymbolNode(CDasherNode *pParent, int iOffset, unsigned int iLbnd, unsigned int iHbnd, CAlphabetManager *pMgr, symbol iSymbol);
 
       ///
@@ -156,6 +156,12 @@ namespace Dasher {
     /// Default is just to add the control node, if appropriate.
     virtual void AddExtras(CAlphNode *pParent, std::vector<unsigned int> *pCProb);
 
+    ///Called to compute colour for a symbol at a specified offset.
+    /// Wraps CAlphabet::GetColour(sym), but (a) implements a default
+    ///  scheme for symbols not specifying a colour, and (b) implements
+    /// colour-cycling by phase (two cycles, using the LSBit of offset)
+    virtual int GetColour(symbol sym, int iOffset) const;
+    
     CLanguageModel *m_pLanguageModel;
     CLanguageModel::Context m_iLearnContext;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]