Diffstat (limited to 'inputmethods/dasher/DasherInterface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/dasher/DasherInterface.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/inputmethods/dasher/DasherInterface.cpp b/inputmethods/dasher/DasherInterface.cpp index bb5b85e..4699687 100644 --- a/inputmethods/dasher/DasherInterface.cpp +++ b/inputmethods/dasher/DasherInterface.cpp @@ -1,224 +1,241 @@ // DasherInterface.cpp // ///////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2002 Iain Murray // ///////////////////////////////////////////////////////////////////////////// #include "DasherInterface.h" //#include "EnglishAlphabet.h" #include "CustomAlphabet.h" #include "DasherViewSquare.h" #include "PPMLanguageModel.h" #include <iostream> namespace { #include "stdio.h" } using namespace Dasher; using namespace std; const string CDasherInterface::EmptyString = ""; CDasherInterface::CDasherInterface() - : m_DashEditbox(0), m_DasherScreen(0), m_LanguageModel(0), TrainContext(0), m_Alphabet(0), - m_DasherModel(0), m_DasherView(0), AlphabetID(""), LanguageModelID(-1), ViewID(-1), - m_MaxBitRate(-1), m_Orientation(Opts::LeftToRight), m_SettingsStore(0), m_SettingsUI(0), - m_UserLocation("usr_"), m_SystemLocation("sys_"), m_AlphIO(0), m_TrainFile(""), - m_DasherFont(""), m_EditFont(""), m_EditFontSize(0), m_DrawKeyboard(false) + : m_Alphabet(0), + m_LanguageModel(0), + m_DasherModel(0), + m_DashEditbox(0), + m_DasherScreen(0), + m_DasherView(0), + m_SettingsStore(0), + m_SettingsUI(0), + m_AlphIO(0), + TrainContext(0), + AlphabetID(""), + LanguageModelID(-1), + ViewID(-1), + m_MaxBitRate(-1), + m_DrawKeyboard(false), + m_Orientation(Opts::LeftToRight), + m_UserLocation("usr_"), + m_SystemLocation("sys_"), + m_TrainFile(""), + m_DasherFont(""), + m_EditFont(""), + m_EditFontSize(0) { } CDasherInterface::~CDasherInterface() { if (m_LanguageModel) m_LanguageModel->ReleaseNodeContext(TrainContext); delete m_DasherModel; // The order of some of these deletions matters delete m_LanguageModel; // eg DasherModel has a pointer to LanguageModel. delete m_Alphabet; // DM baulks if LM is deleted before it is. delete m_DasherView; // Do NOT delete Edit box or Screen. This class did not create them. } void CDasherInterface::SetSettingsStore(CSettingsStore* SettingsStore) { delete m_SettingsStore; m_SettingsStore = SettingsStore; this->SettingsDefaults(m_SettingsStore); } void CDasherInterface::SetSettingsUI(CDasherSettingsInterface* SettingsUI) { delete m_SettingsUI; m_SettingsUI = SettingsUI; //this->SettingsDefaults(m_SettingsStore); m_SettingsUI->SettingsDefaults(m_SettingsStore); } void CDasherInterface::SetUserLocation(std::string UserLocation) { // Nothing clever updates. (At the moment) it is assumed that // this is set before anything much happens and that it does // not require changing. m_UserLocation = UserLocation; if (m_Alphabet!=0) m_TrainFile = m_UserLocation + m_Alphabet->GetTrainingFile(); } void CDasherInterface::SetSystemLocation(std::string SystemLocation) { // Nothing clever updates. (At the moment) it is assumed that // this is set before anything much happens and that it does // not require changing. m_SystemLocation = SystemLocation; } void CDasherInterface::CreateDasherModel() { if (m_DashEditbox!=0 && m_LanguageModel!=0) { delete m_DasherModel; m_DasherModel = new CDasherModel(m_DashEditbox, m_LanguageModel, m_Dimensions); if (m_MaxBitRate>=0) m_DasherModel->SetMaxBitrate(m_MaxBitRate); if (ViewID!=-1) ChangeView(ViewID); } } void CDasherInterface::Start() { if (m_DasherModel!=0) m_DasherModel->Start(); } void CDasherInterface::PauseAt(int MouseX, int MouseY) { if (m_DasherView!=0) m_DasherView->FlushAt(MouseX, MouseY); if (m_DashEditbox!=0) { m_DashEditbox->write_to_file(); if (m_CopyAllOnStop) m_DashEditbox->CopyAll(); } } void CDasherInterface::Unpause(unsigned long Time) { if (m_DashEditbox!=0) m_DashEditbox->unflush(); if (m_DasherModel!=0) m_DasherModel->Reset_framerate(Time); } void CDasherInterface::Redraw() { if (m_DasherView!=0) { m_DasherView->Render(); m_DasherView->Display(); } } void CDasherInterface::TapOn(int MouseX, int MouseY, unsigned long Time) { if (m_DasherView!=0) { m_DasherView->TapOnDisplay(MouseX, MouseY, Time); m_DasherView->Render(); if (m_DrawMouse==true) { m_DasherView->DrawMouse(MouseX, MouseY); } if (m_DrawKeyboard==true) { m_DasherView->DrawKeyboard(); } m_DasherView->Display(); } if (m_DasherModel!=0) m_DasherModel->NewFrame(Time); } void CDasherInterface::ChangeAlphabet(const std::string& NewAlphabetID) { if (m_SettingsUI!=0) m_SettingsUI->ChangeAlphabet(NewAlphabetID); if (m_SettingsStore!=0) m_SettingsStore->SetStringOption(Keys::ALPHABET_ID, NewAlphabetID); AlphabetID = NewAlphabetID; if (!m_AlphIO) m_AlphIO = new CAlphIO(m_SystemLocation, m_UserLocation); CAlphIO::AlphInfo Info = m_AlphIO->GetInfo(NewAlphabetID); CAlphabet* old = m_Alphabet; m_Alphabet = new CCustomAlphabet(Info); // Apply options from alphabet m_TrainFile = m_UserLocation + m_Alphabet->GetTrainingFile(); // Recreate widgets and language model if (m_DashEditbox!=0) m_DashEditbox->SetInterface(this); if (m_DasherScreen!=0) m_DasherScreen->SetInterface(this); if (LanguageModelID!=-1 || m_LanguageModel) ChangeLanguageModel(LanguageModelID); delete old; // only delete old alphabet after telling all other objects not to use it Start(); // We can only change the orientation after we have called // Start, as this will prompt a redraw, which will fail if the // model hasn't been updated for the new alphabet if (m_Orientation==Opts::Alphabet) ChangeOrientation(Opts::Alphabet); Redraw(); } void CDasherInterface::ChangeMaxBitRate(double NewMaxBitRate) { m_MaxBitRate = NewMaxBitRate; if (m_DasherModel!=0) m_DasherModel->SetMaxBitrate(m_MaxBitRate); if (m_SettingsUI!=0) m_SettingsUI->ChangeMaxBitRate(m_MaxBitRate); if (m_SettingsStore!=0) m_SettingsStore->SetLongOption(Keys::MAX_BITRATE_TIMES100, long(m_MaxBitRate*100) ); if (m_DrawKeyboard==true && m_DasherView!=NULL) { m_DasherView->DrawKeyboard(); } } void CDasherInterface::ChangeLanguageModel(unsigned int NewLanguageModelID) { LanguageModelID = NewLanguageModelID; if (m_Alphabet!=0) { if (m_LanguageModel) m_LanguageModel->ReleaseNodeContext(TrainContext); TrainContext = 0; |