diff --git a/configure.py b/configure.py index eee1ef3c..499e5d27 100644 --- a/configure.py +++ b/configure.py @@ -911,7 +911,7 @@ config.libs = [ IPLSection("keyboard", [ Object(Matching, "keyboard/tiPcKeyboard.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiCellPhone.cpp", extra_cflags=["-O4,p"]), - Object(NonMatching, "keyboard/tiInputForm.cpp", extra_cflags=["-O4,p"]), + Object(Matching, "keyboard/tiInputForm.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiCandidateBox.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiToolBar.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiPredictLang.cpp", extra_cflags=["-O4,p"]), diff --git a/include/keyboard/tiInputForm.h b/include/keyboard/tiInputForm.h index 3daa84fb..368a54b4 100644 --- a/include/keyboard/tiInputForm.h +++ b/include/keyboard/tiInputForm.h @@ -178,8 +178,14 @@ namespace textinput { void inputCharZi_(wchar_t character, u32 modifiers); void inputCharDefault_(wchar_t character, u32 modifiers); void inputInputting_(wchar_t character); - inline bool hasZiPredictions() const; - inline bool usesZiPrediction() const; + bool hasZiPredictions() const; + bool usesZiPrediction() const; +#ifdef TIINPUTFORM_IMPLEMENTATION + void checkUnfixConverting_(); + void setAtokMode_(bool fixMode, bool kanaMode); + void trimString_(u32 length); + void startConverting_(); +#endif inline void resetPredictionContext(); inline void resetInputRelation(); #endif diff --git a/include/keyboard/tiString.h b/include/keyboard/tiString.h index ef8e2ba8..d4614b07 100644 --- a/include/keyboard/tiString.h +++ b/include/keyboard/tiString.h @@ -85,10 +85,30 @@ namespace textinput { #endif #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION) +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual ~Decolated() {} +#else virtual ~Decolated(); +#endif enum TranslateMode { TM_Direct, TM_Kana, TM_Roman, TM_Hangul }; +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual void clear() { + StringBase::clear(); + mCursorStart = 0; + mCursorEnd = 0; + mbSustain = false; + initKanaConverter(); + } + virtual void set(const wchar_t* string) { + StringBase::set(string); + u32 length = getLength(); + mCursorStart = length; + mCursorEnd = length; + } +#else virtual void clear(); virtual void set(const wchar_t* string); +#endif virtual void setLength(u16 length); void setTranslateMode(TranslateMode mode); TranslateMode getTranslateMode() const { return static_cast(mTranslateMode); } @@ -194,6 +214,9 @@ namespace textinput { public: WithAtok(u16 maxLength) : Decolated(maxLength) {} virtual ~WithAtok(); + virtual bool isFix(); + virtual void setFix(bool fix); + virtual void initConverting(); virtual void pushBack(wchar_t ch); virtual void popBack(); virtual void inputChar(wchar_t ch); @@ -209,9 +232,6 @@ namespace textinput { u32 selectedStart; u32 selectedEnd; }; - virtual bool isFix(); - virtual void setFix(bool fix); - virtual void initConverting(); virtual bool isConverting(); virtual wchar_t* getConfirmedWCString() const; virtual int getCurrentNumPredicted(); diff --git a/include/keyboard/tiTextInputBase.h b/include/keyboard/tiTextInputBase.h index c18227cb..df64cdc8 100644 --- a/include/keyboard/tiTextInputBase.h +++ b/include/keyboard/tiTextInputBase.h @@ -47,8 +47,13 @@ namespace textinput { public : virtual ~Base() {} +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual void create(MEMAllocator* allocator) {} + virtual void init() {} +#else virtual void create(MEMAllocator* allocator); virtual void init(); +#endif }; class CommandSender; @@ -59,8 +64,12 @@ namespace textinput { #endif #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) CommandReceiver() { clearSender(); } +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual ~CommandReceiver() {} +#else virtual ~CommandReceiver(); #endif +#endif #if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) struct Scroll { bool absY; diff --git a/src/keyboard/tiInputForm.cpp b/src/keyboard/tiInputForm.cpp index aaa4418a..2e0f3334 100644 --- a/src/keyboard/tiInputForm.cpp +++ b/src/keyboard/tiInputForm.cpp @@ -1,4 +1,6 @@ #define TIINPUTFORM_IMPLEMENTATION +#include "keyboard/tiUtil.h" +#include "keyboard/tiGUIManager.h" #include "keyboard/tiInputForm.h" #include "keyboard/tiManager.h" #include "keyboard/tiDebug.h" @@ -53,10 +55,13 @@ private: class AnmPane : public nw4rmanager::AnmPane { public: AnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : nw4rmanager::AnmPane(pane, observer), meState(ANM_Normal) {} - virtual void init(); - virtual void changeAnimation(u32 id); - virtual KeyType getKeyType() const; - virtual Animation getState(); + virtual void init() { meState = ANM_Normal; } + virtual void changeAnimation(u32 id) { + meState = static_cast(id); + nw4rmanager::AnmPane::changeAnimation(id); + } + virtual KeyType getKeyType() const { return meKeyType; } + virtual Animation getState() { return meState; } protected: Animation meState; @@ -66,11 +71,16 @@ protected: class NormalButtonAnmPane : public AnmPane { public: NormalButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { meKeyType = KT_NormalButton; } - virtual ~NormalButtonAnmPane(); + virtual ~NormalButtonAnmPane() {} virtual void onAnmEvent(AnmPaneEvent event); }; - +class Sample : public LayoutByNW4R { +public: + Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName) + : LayoutByNW4R(manager, accessor, layoutName, observer, NULL) {} + virtual ~Sample() {} +}; nw4r::ut::Color csUnInputedWCharColor(200, 50, 50, 255); nw4r::ut::Color csCharColor(20, 20, 20, 255); @@ -80,63 +90,9 @@ nw4r::ut::Color csZiStringColorRight(50, 100, 50, 255); nw4r::ut::Color csUnderlateColor(100, 200, 200, 255); nw4r::ut::Color csUnInputedWCharColorSpace(255, 20, 20, 255); -extern "C" asm void GetCursorY__Q34nw4r2ut10CharWriterCFv(); -extern "C" asm void GetCursorX__Q34nw4r2ut10CharWriterCFv(); -extern "C" asm void SetCursor__Q34nw4r2ut10CharWriterFff(); -extern "C" asm void SetCursorY__Q34nw4r2ut10CharWriterFf(); -extern "C" asm void SetCursorX__Q34nw4r2ut10CharWriterFf(); -extern "C" asm void SetTextColor__Q34nw4r2ut10CharWriterFQ34nw4r2ut5Color(); -extern "C" asm void GetFontHeight__Q34nw4r2ut10CharWriterCFv(); -extern "C" asm void GetFont__Q34nw4r2ut10CharWriterCFv(); -extern "C" asm void SetFixedWidth__Q34nw4r2ut10CharWriterFf(); -extern "C" asm void EnableFixedWidth__Q34nw4r2ut10CharWriterFb(); extern "C" void KPRInitQueue(KPRQueue* queue); extern "C" void KPRSetMode(KPRQueue* queue, KPRMode mode); -extern "C" asm void create__Q39textinput10textdrawer4BaseFP12MEMAllocator(); -extern "C" asm void init__Q49textinput9inputform4Base14RowInfoManagerFv(); -extern "C" asm void MEMAllocFromAllocator(); -extern "C" asm void MEMFreeToAllocator(); -extern "C" asm void __dt__Q34nw4r2ut10CharWriterFv(); -extern "C" asm void __dl__FPv(); -extern "C" asm void SinFIdx__Q24nw4r4mathFf(); -extern "C" asm void drawLine___Q29textinput5debugFfffffUcR8_GXColor(); -extern "C" asm void setDrawString__Q39textinput10textdrawer4BaseFPCwUlUl(); -extern "C" asm void draw__Q39textinput10textdrawer4BaseFPQ49textinput10textdrawer4Base9CursorPos(); -extern "C" asm void drawBox___Q29textinput5debugFffffffR8_GXColor(); -extern "C" asm void clearCandidates__Q39textinput8tistring6WithZiFv(); -extern "C" asm void getCurrentInput__Q39textinput8tistring6WithZiFPwUl(); -extern "C" asm void hermiteInterporation__Q29textinput4utilFfffffff(); -extern "C" asm void getCurrentString__Q39textinput9inputform4BaseFb(); -extern "C" asm void onCommand__Q29textinput15CommandReceiverFQ39textinput15CommandReceiver13INPUT_COMMANDPv(); -extern "C" asm void resetCandidate__Q39textinput12candidatebox18CandidateBoxCallerFv(); -extern "C" asm void addCandidate__Q39textinput12candidatebox18CandidateBoxCallerFPCw(); -extern "C" asm void updateCandidate__Q39textinput12candidatebox18CandidateBoxCallerFv(); -extern "C" asm void setCurrentWord__Q39textinput8tistring6WithZiFPCw(); -extern "C" asm void update__Q39textinput8tistring6WithZiFv(); extern "C" int wcsnicmp(const wchar_t* left, const wchar_t* right, u32 length); -extern "C" asm void List_Append__Q24nw4r2utFPQ34nw4r2ut4ListPv(); -extern "C" asm void List_GetNext__Q24nw4r2utFPCQ34nw4r2ut4ListPCv(); -extern "C" asm void List_Remove__Q24nw4r2utFPQ34nw4r2ut4ListPv(); -extern "C" asm void IsScrolling__Q39textinput12candidatebox10UITextAreaFv(); -extern "C" asm void destroy__Q39textinput11nw4rmanager7AnmPaneFP12MEMAllocator(); -extern "C" asm void __dt__Q34nw4r2ut7ResFontFv(); -extern "C" asm void __dt__Q39textinput11nw4rmanager6LayoutFv(); -extern "C" asm void __dt__Q34nw4r2ut10CharWriterFv(); -extern "C" asm void __ct__Q39textinput11nw4rmanager6LayoutFPQ34nw4r3lyt24MultiArcResourceAccessorPCcPQ29textinput13EventObserver(); -extern "C" asm void __ct__Q34nw4r2ut7ResFontFv(); -extern "C" asm void __dt__Q39textinput8tistring10StringBaseFv(); -extern "C" asm void set__Q39textinput8tistring10StringBaseFPCw(); -extern "C" asm void clear__Q39textinput8tistring10StringBaseFv(); -extern "C" asm void updateRepeatInput__Q39textinput9inputform12LayoutByNW4RFUlUl(); -extern "C" asm void ChangeSelectedText__Q39textinput12candidatebox10UITextAreaFl(); -extern "C" asm void confirmInput___Q39textinput9inputform4BaseFv(); -extern "C" asm void isAlphabet__Q29textinput4utilFw(); -extern "C" asm void reverseLetterCaseW__Q29textinput4utilFw(); -extern "C" asm void confirmInputting___Q39textinput9inputform4BaseFwbUsbPv(); -extern "C" asm void calc__Q39textinput9inputform4BaseFv(); -extern "C" asm void calc__Q39textinput11nw4rmanager6LayoutFv(); -extern "C" asm void draw__Q39textinput11nw4rmanager6LayoutFv(); -extern "C" asm void searchPaneComponent__Q39textinput3gui11PaneManagerFPCc(); extern "C" char scP_txtScrll_UP[]; extern "C" char scP_txtScrll_DOWN[]; extern "C" char scN_JPNUSAEUR[]; @@ -149,165 +105,6 @@ extern "C" char scT_title_textKOR[]; extern "C" char scN_separateBarCHN[]; extern "C" char scT_2l_TextBoxCHN[]; extern "C" char scT_title_textCHN[]; -extern "C" const char scN_KOR[]; -extern "C" const char scN_CHN[]; -extern "C" const f32 scInputFormZeroF; -extern "C" void _savegpr_20(); -extern "C" void _restgpr_20(); -extern "C" void _savegpr_27(); -extern "C" void _restgpr_27(); -extern "C" asm void __ct__Q34nw4r2ut10CharWriterFv(); - - - - -extern "C" asm void __vt__Q29textinput15CommandReceiver(); -extern "C" asm void __vt__Q39textinput10textdrawer4Base(); -extern "C" asm void __vt__Q39textinput9inputform4Base(); -extern "C" asm void __vt__Q39textinput9inputform12LayoutByNW4R(); -extern "C" asm void __vt__Q39textinput4util9Animation(); -extern "C" asm void __vt__Q39textinput9inputform10EditBuffer(); -extern "C" asm void __vt__Q39textinput8tistring9Decolated(); -extern "C" asm void __vt__Q39textinput8tistring8WithAtok(); -extern "C" asm void __vt__Q39textinput8tistring6WithZi(); -void Base::moveCandidateToIdx(s32 index) { - if (mbPredictOn) { - if (mpManager->getCandidateBox()->isInScroll()) return; - if (mePredictMode == PM_Atok) { - if (mpUnfixString->getFixedPredictionNum() && !mpUnfixString->isConverting()) { - mpUnfixString->confirm(NULL); - wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); - mpString->getCursorPos(); - mpString->confirm(confirmed); - mpString->getCursorPos(); - mpUnfixString->enableConfirmedString(false); - } - mpUnfixString->setSelectedCandidate(index); - } else { - mpZiString->setSelectedCandidate(index); - } - mpManager->getCandidateBox()->getTextArea().ChangeSelectedText(index); - } else { - meScrollFlag = SF_ScrollOn; - } -} -void Base::confirmInput_() { - if (!mbPredictOn) { - if (!mpString->isKanaFix()) { - mpString->getCursorPos(); - mpString->confirmKana(); - mpString->getCursorPos(); - } - } else if (mePredictMode == PM_Atok) { - if (mpUnfixString->isCandidateSelected()) { - s32 selected = mpUnfixString->getSelectedCandidate(); - onCommand(static_cast(21), &selected); - } else { - mpUnfixString->confirm(NULL); - wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); - mpString->getCursorPos(); - mpString->confirm(confirmed); - mpString->getCursorPos(); - mpUnfixString->enableConfirmedString(false); - } - } else { - const wchar_t* selected = mpZiString->getCurrentSelected(); - if (mpZiString->getInputStringLength()) { - mpString->getCursorPos(); - mpString->inputString(selected); - mpString->getCursorPos(); - if (meLanguage == CN) mpZiString->setCurrentWord(selected); - } - mpZiString->clearCandidates(); - mbZuSelected = false; - if (meLanguage == CN) mpZiString->update(); - } -} -void Base::inputInputting_(wchar_t character) { - tistring::Decolated* current = getCurrentString(false); - if (static_cast(character + 0xcf65) <= 1) { - onCommand(static_cast(27), NULL); - } else if (mbPredictOn && mePredictMode == PM_Atok) { - if (mpUnfixString->isCandidateSelected()) onCommand(static_cast(6), NULL); - mpUnfixString->setInputting(character); - } else { - if (mbPredictOn && getPredictMode() == PM_11 && !mpManager->getCandidateBox()->isInvalid()) { - if (util::isAlphabet(character) || (character >= L'1' && character <= L'5')) { - mpZiString->setInputting(character); - } else { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions && mpZiString->getInputStringLength() != 0 && (meLanguage != CN || !mpZiString->hasCandidate())) confirmInput_(); - mpZiString->setInputting(character); - mpZiString->setSelectedCandidate(-1); - return; - } - } else { - current->setCandidate(character); - } - } - if (character != 0) onSE(sound::SE_CHAR_INPUT); - meScrollFlag = SF_ScrollOn; -} -void Base::inputCharDefault_(wchar_t character, u32 modifiers) { - tistring::WithAtok* unfix; - tistring::Decolated* current = getCurrentString(true); - unfix = mpUnfixString; - if (getCurrentString(false) == unfix && !unfix->isConverting() && mpUnfixString->getSelectedCandidate() >= 0) { - confirmInput_(); - } - if (meLanguage == KR && mpManager->getPCKeyboard()->getTranslateMode() != keyboard::pctype::Base::TM_00) { - if (util::isAlphabet(character) && (modifiers & 2)) character = util::reverseLetterCaseW(character); - } - if (mpString == current) { - mpString->getCursorPos(); - mpString->inputChar(character); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predicted; - if (!mbPredictOn) predicted = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predicted = true; - else predicted = false; - if (predicted) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } else current->inputChar(character); - if (character == L' ') onSE(sound::SE_CHAR_DECIDE); - else if (character != L'\n') onSE(sound::SE_CHAR_INPUT); - meScrollFlag = SF_ScrollOn; -} - -void LayoutByNW4R::draw() { - nw4rmanager::Layout::draw(); - muGlobalAlpha = getLayout()->GetRootPane()->GetAlpha(); - nw4r::lyt::Pane* textBox = mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true); - AdjustPaneMtx(mMtx.m, mDrawInfo, textBox->GetGlobalMtx()); - Base::draw(); -} -void Base::calcCursorTimer() { - muCursorTimer += 8; -} -bool Base::isAtokActive() const { - u32 enabled = mbPredictOn; - if (enabled == 0) return false; - return mePredictMode == PM_Atok; -} -void Base::dirtyCacheAll() { - dirtyCursorCache(); - dirtyDrawCache(); -} -void Base::initZiString() { - mpZiString->clearCandidates(); - mbZuSelected = false; -} -void Base::resetContextPredict_() { - getCurrentString(false); - resetPredictionContext(); -} static GXColor kanaBackground = {128, 255, 128, 255}; static GXColor candidateBackground = {255, 210, 12, 255}; @@ -377,36 +174,8 @@ extern "C" const LanguagePaneData csLanguageDependencyDataCHN__Q29textinput9inpu extern "C" const wchar_t pppURLCheck[2][10] = {L"http://", L"https://"}; - -extern "C" const f32 scInputFormZeroF = 0.0f; -extern "C" const f32 scInputForm640F = 640.0f; -extern "C" const f64 scInputFormF32ConvertMagic = 4503601774854144.0; -extern "C" const f32 scInputFormOneF = 1.0f; -extern "C" const f32 scInputFormHalfF = 0.5f; -extern "C" const f32 scInputFormDegToFIdxF = 0.7111111f; -extern "C" const f32 scInputForm150F = 150.0f; -extern "C" const f32 scInputForm30F = 30.0f; -extern "C" const f32 scInputForm50F = 50.0f; -extern "C" const f32 scInputForm10F = 10.0f; -extern "C" const f32 scInputForm52F = 52.0f; -extern "C" const f32 scInputFormTwoF = 2.0f; -extern "C" const f32 scInputForm140F = 140.0f; -extern "C" const f32 scInputForm90F = 90.0f; -extern "C" const f32 scInputForm253F = 253.0f; -extern "C" const f32 scInputForm20F = 20.0f; -extern "C" const u8 scInputFormColorRU8 = 0xff; -extern "C" const u8 scInputFormColorGU8 = 0x32; -extern "C" const u8 scInputFormColorBU8 = 0x32; -extern "C" const u8 scInputFormColorAU8 = 0; -extern "C" const f32 scInputForm255F = 255.0f; -extern "C" const f32 scInputForm127F = 127.0f; -extern "C" const f32 scInputForm14592F = 14592.0f; -extern "C" const f64 scInputFormF64ConvertMagic = 4503599627370496.0; -extern "C" const f32 scInputForm15F = 15.0f; f32 sfColorPhase; -bool mbHyphen = true; - extern "C" char scP_txtScrll_UP[] = "P_txtScrll_UP"; extern "C" char scP_txtScrll_DOWN[] = "P_txtScrll_DOWN"; struct ButtonAnimations { @@ -440,6 +209,7 @@ extern "C" char scN_separateBarCHN[] = "N_separateBarCHN"; extern "C" char scT_2l_TextBoxCHN[] = "T_2l_TextBoxCHN"; extern "C" char scT_title_textCHN[] = "T_title_textCHN"; bool DeadKeyStream::sbCompatibleFilterEnabled = true; +bool mbHyphen = true; #pragma push #pragma section const_type ".data" @@ -464,6 +234,404 @@ inline wchar_t DeadKeyStream::getChar() { return character; } +struct CharacterInput { + wchar_t character; + u32 modifiers; + bool keyboardMode; + bool deadKey; + u32 data; +}; + +struct ConfirmInput { + wchar_t character; + u16 letterMode; + bool direct; + bool held; + bool confirmOnly; + bool silent; + void* holdingKey; +}; + +struct PredictionState { + Base::PredictMode mode; + bool enabled; +}; + +struct ControlInput { + HVKCode code; + u32 modifiers; +}; + +inline void Base::resetPredictionContext() { + if (mpZiString && meLanguage == CN) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + updateCandidateState_(); + } +} + +inline void Base::resetInputRelation() { + resetRelation(); + updateCandidateState_(); +} + +static inline const char* selectInputTextName(const nw4rmanager::Layout& layout, const void* const& languageData) { + if (layout.getPane(static_cast(languageData)->textBox)) { + return static_cast(languageData)->textBox; + } + return "T_2l_TextBox"; +} + +inline nw4r::lyt::TextBox* LayoutByNW4R::getTextBox() const { + nw4r::lyt::TextBox* textBox = static_cast(mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true)); + return textBox; +} + +inline const nw4r::lyt::Pane* LayoutByNW4R::getLanguageTextPane() const { + return getPane(static_cast(mpLanguageData)->textBox); +} + +inline void DeadKeyStream::init() { + KPRInitQueue(&mKPRQueue); + KPRSetMode(&mKPRQueue, KPR_MODE_DEADKEY); +} + +inline u16 initializeRowLinks(Base::Info_* const& rows, const u16& capacity) { + for (u16 index = 0; index < capacity; ++index) { + Base::Info_* row = &rows[index]; + row->Back = index - 1; + row->Next = index + 1; + row->StrCount = 0; + row->DispRowCount = 0; + } + return capacity; +} +inline f32 nextColorPhase(f32 phase) { phase += 2.0f; return phase; } +inline f32 colorSine(f32 phase) { return nw4r::math::SinFIdx(phase * 0.7111111f); } + +static inline f32 scaledExtent(f32 scale, f32 start, f32 end) { + f32 extent = end - start; + return scale * extent; +} + +static inline f32 glyphBottom(f32 origin, const Base::DrawInfo& glyph, const nw4r::math::VEC2& scale) { + f32 extent = glyph.rect.GetHeight(); + return origin + scale.y * extent; +} + +} // namespace inputform + +namespace tistring { + +inline u32 Decolated::getCursorPos() const { return mCursorStart; } +inline bool Decolated::isOnSustain() { return mbSustain; } +inline wchar_t* Decolated::getKanaBuffer() { + return mKanaStream.mOutput; +} + +inline bool Decolated::isKanaFix() const { + if (static_cast(mTranslateMode) == TM_Hangul) return true; + return KPRLookAhead(const_cast(&mKanaStream.mQueue), NULL, NULL) == 0; +} + +inline void Decolated::EnableKSXFilter(bool enable) {} +inline void Decolated::deleteChar() {} + +inline WithAtok::~WithAtok() {} +inline void WithAtok::backSpace() {} +inline void WithAtok::changeKanaMode(bool kana) {} +inline void WithAtok::closeDictionary() {} +inline void WithAtok::commitPredicted(int index) {} +inline void WithAtok::confirm(const wchar_t* string) {} +inline void WithAtok::enableConfirmedString(bool enable) {} +inline void WithAtok::getCursorPos(u32* start, u32* end) {} +inline void WithAtok::getDrawString(DrawInfo& info) {} +inline void WithAtok::getPredicted(int index, wchar_t* string) {} +inline void WithAtok::initConverting() {} +inline void WithAtok::init() {} +inline void WithAtok::inputChar(wchar_t ch) {} +inline void WithAtok::openDictionary(void* atok, int atokSize, void* apot, int apotSize, void* nintendo, int nintendoSize) {} +inline void WithAtok::popBack() {} +inline void WithAtok::pushBack(wchar_t ch) {} +inline void WithAtok::resetRelation() {} +inline void WithAtok::setDefaultPrediction(int count, const char** predictions) {} +inline void WithAtok::setFixMode(bool fixed) {} +inline void WithAtok::setFixPrediction(int count, const char** predictions) {} +inline void WithAtok::setFix(bool fix) {} +inline void WithAtok::setInputting(wchar_t ch) {} +inline void WithAtok::setSelectedCandidate(s32 index) {} +inline void WithAtok::startConverting() {} +inline bool WithAtok::isFix() { return true; } +inline bool WithAtok::isConverting() { return false; } +inline s16 WithAtok::getSelectedConverting() { return 0; } +inline bool WithAtok::isDictionaryOpened() { return false; } +inline wchar_t* WithAtok::getConfirmedWCString() const { return NULL; } +inline bool WithAtok::hasConfirmedString() { return false; } +inline int WithAtok::getCurrentNumPredicted() { return 0; } +inline bool WithAtok::isCandidateSelected() { return false; } +inline s32 WithAtok::getSelectedCandidate() { return 0; } +inline s32 WithAtok::getFixedPredictionNum() { return 0; } +inline wchar_t WithAtok::getInputStringLength() { return 0; } +inline bool WithAtok::moveCursorLeft() { return false; } +inline bool WithAtok::moveCursorRight() { return false; } + +inline void WithZi::setSelectedCandidate(s32 index) { mSelectedCandidate = index; } +inline void WithZi::setPredictLaunguage(PredictLanguage language) { mPredictLanguage = language; } +inline int WithZi::getCurrentNumPredicted() { return mCandidateCount; } +inline u16 WithZi::getInputStringLength() { return mInputLength; } +inline void WithZi::changeLetterMode(LetterMode mode) { mLetterMode = mode; } +inline void WithZi::setCellPhoneHoldingkey(void* key) { mpHoldingKey = key; } + +inline bool StringBase::hasCandidate() const { + return mwcCandidate != 0; +} + +} // namespace tistring + +namespace textdrawer { + +inline int Base::getLine() { + return muLine + 1; +} + +inline void Base::setVIWidth(f32 width) { + mfVIWidth = width; +} + +inline bool Base::isEnableCursorCache() const { + return mbCursorCache; +} + +inline u32 Base::getStartPos() const { + return muDrawStartPos; +} + +inline u32 Base::getEndPos() const { return muDrawEndPos; } +inline u32 Base::getDrawModifyStartLine() const { return muDrawModifyStartLine; } +inline u32 Base::getDrawModifyEndLine() const { return muDrawModifyEndLine; } +inline void Base::dirtyDrawCache() { mbDrawCache = false; } +inline void Base::dirtyCursorCache() { mbCursorCache = false; } +inline u32 Base::getDrawCacheStartPos() const { + if (mbDrawCache) return muCachedStartPos; + return 0x7fffffff; +} + +} // namespace textdrawer + +namespace util { + +inline void Animation::startAnm(f32 start, f32 end, f32 duration, AnimObserver* observer, void* data) { + mfStartPoint = start; + mfEndPoint = end; + mfAnimationTime = duration; + mfCurrentFrame = 0.0f; + mbInAnimation = true; + mpAnimObserver = observer; + mpData = data; + mbSE = false; + if (observer) observer->onAnmEvent(AnimObserver::AE_0, data); +} + +inline void Animation::calc() { + if (mbInAnimation) { + if (mfCurrentFrame < mfAnimationTime) { + mfCurrentFrame = 1.0f + mfCurrentFrame; + } else { + if (mbInAnimation && mpAnimObserver) { + mpAnimObserver->onAnmEvent(AnimObserver::AE_1, mpData); + } + mbInAnimation = false; + } + } +} + +inline f32 Animation::getValue() { + return hermiteInterporation(mfCurrentFrame, 0.0f, mfStartPoint, 0.0f, mfAnimationTime, mfEndPoint, 0.0f); +} + +inline bool Animation::isActive() { + return mbInAnimation; +} + +inline void Animation::setSEFlag(bool flag) { + mbSE = flag; +} + +inline bool Animation::isSEFlag() { + return mbSE; +} + +inline void Animation::stop() { + mbInAnimation = false; +} + +} // namespace util + +namespace candidatebox { + +inline bool Base::isInvalid() const { return mbInvalid; } + +inline bool LayoutByNW4R::isInScroll() { + return mTextArea.IsScrolling(); +} + +} // namespace candidatebox + +inline void CommandReceiver::addSender(CommandSender* sender) { + nw4r::ut::List_Append(&mSenderList, sender); +} + +inline void gui::GUIComponent::init() { + if (mbInitialize) return; + for (int point = 0; point < GUI_POINTS_MAX; ++point) { + mbPointed[point] = false; + mDraggingPos[point].x = 0.0f; + mDraggingPos[point].y = 0.0f; + mDraggingPos[point].z = 0.0f; + mbDragging[point] = false; + mFlightDuration[point] = 0; + } +} + +namespace inputform { + +inline Base::RowInfoManager::~RowInfoManager() { + MEMFreeToAllocator(mpAllocator, mpInfo); +} + +inline void Base::enableSpaceByRight(bool rightWithSpace) { + mbRightWithSpace = rightWithSpace; +} + +inline nw4r::math::VEC2 Base::getScale() const { + return nw4r::math::VEC2(1.0f, 1.0f); +} + +inline void Base::onSE(sound::SE) {} + +inline bool Base::isInScroll() { + return mScrollAnm.isActive(); +} + +inline void Base::create(MEMAllocator*) {} + +inline void Base::doAfterDrawProcess(const wchar_t*, u32, const DrawInfo&) {} + +inline void Base::finishDraw(u32) {} + +inline bool Base::isAtokDictionaryOpened() { + return mpUnfixString->isDictionaryOpened(); +} + +inline void Base::setLineDrawInfo(bool lineDraw, u32 lineCount) { + mbLineDraw = lineDraw; + muSpecifyLineDrawCount = lineCount; +} + +inline void Base::doWordWrap(bool wordWrap) { + mbDoWordWrap = wordWrap; +} + +inline void Base::limitStringLength(u32 limitStringLength) { + muLimitStringLength = limitStringLength; +} + +inline void Base::limitRowNum(u32 limitRowNum) { + muLimitRowNum = limitRowNum; + if (limitRowNum == 1) { + doWordWrap(false); + } +} + +inline wchar_t Base::getCandidate() const { + return mpString->getCandidate(); +} + +inline void* Base::getAtokString() { + return mpUnfixString; +} + +inline wchar_t* Base::getWCString() const { + return mpString->getWCString(); +} + +inline bool LayoutByNW4R::isAbleToUp() { + return mbUpVisible; +} + +inline bool LayoutByNW4R::isAbleToDown() { + return mbDownVisible; +} + +inline void LayoutByNW4R::visibleSeparator(bool flag) { + mbRepeat = flag; +} + +EditBuffer::~EditBuffer() { + if (mpString) { + static_cast(mpString)->~Decolated(); + MEMFreeToAllocator(mpAllocator, mpString); + } + if (mpUnfixString) { + static_cast(mpUnfixString)->~WithAtok(); + MEMFreeToAllocator(mpAllocator, mpUnfixString); + } + if (mpZiString) { + static_cast(mpZiString)->~WithZi(); + MEMFreeToAllocator(mpAllocator, mpZiString); + } + mpString = NULL; + mpUnfixString = NULL; + mpZiString = NULL; +} + +void EditBuffer::create(MEMAllocator* allocator) { + mpAllocator = allocator; + void* memory = MEMAllocFromAllocator(allocator, sizeof(tistring::Decolated)); + tistring::Decolated* fixed = static_cast(memory); + fixed = new (memory) tistring::Decolated(1024); + mpString = fixed; + fixed->create(allocator); + memory = MEMAllocFromAllocator(allocator, sizeof(tistring::WithAtok)); + tistring::WithAtok* atok = static_cast(memory); + atok = new (memory) tistring::WithAtok(1024); + mpUnfixString = atok; + atok->create(allocator); + memory = MEMAllocFromAllocator(allocator, sizeof(tistring::WithZi)); + tistring::WithZi* zi = static_cast(memory); + zi = new (memory) tistring::WithZi(1024); + mpZiString = zi; + zi->create(allocator); +} + +wchar_t DeadKeyStream::ToCombineClass(Language language, wchar_t code) { + switch (language) { + case DE: + if (code == 0xb4) return 0x301; + if (code == 0x60) return 0x300; + break; + case FR: + if (code == 0x5e) return 0x302; + if (code == 0xa8) return 0x308; + break; + case SP: + if (code == 0x60) return 0x300; + if (code == 0xb4) return 0x301; + if (code == 0x5e) return 0x302; + if (code == 0x7e) return 0x303; + if (code == 0xa8) return 0x308; + break; + case NL: + if (code == 0x60) return 0x300; + if (code == 0x5e) return 0x302; + if (code == 0x7e) return 0x303; + if (code == 0x27) return 0x30d; + if (code == 0x22) return 0x30e; + break; + } + return code; +} + wchar_t DeadKeyStream::ToIndependentClass(wchar_t code) { if (code < 0x300 || code > 0x330) { return code; @@ -490,6 +658,95 @@ wchar_t DeadKeyStream::ToIndependentClass(wchar_t code) { } } +void Base::RowInfoManager::init() { + u16 capacity = initializeRowLinks(mpInfo, mMaxLength); + Info_* freeHead = &mpInfo[mMaxLength]; + u16 last = capacity - 1; + freeHead->Back = last; + freeHead->Next = 0; + Info_* rows = mpInfo; + rows[last].Next = mMaxLength; + rows[0].Back = mMaxLength; + u16 activeIndex = mMaxLength + 1; + Info_* activeHead = &mpInfo[activeIndex]; + activeHead->Back = activeIndex; + activeHead->Next = mMaxLength + 1; +} + +void Base::setCursorPos(tistring::Decolated* string, u32 pos) { + string->setCursorPos(pos); +} + +Base::Base(Manager* manager) : CommandReceiver(), textdrawer::Base(), candidatebox::CandidateBoxCaller(), + mpString(NULL), mpUnfixString(NULL), mpZiString(NULL), meInputMode(IM_Direct), mePredictMode(PM_USEn), + mbPredictOn(false), mbDoWordWrap(true), mbRightWithSpace(true), mfCursorX(0.0f), mfCursorY(0.0f), + mfScrollX(0.0f), mfScrollY(0.0f), mScrollAnm(), mfSustainTimer(0.0f), meScrollFlag(SF_NoScroll), + muWordWrapCounter(0), muLimitStringLength(1024), muLimitRowNum(9999), mfCursorTimer(0.0f), muGlobalAlpha(255), + mCharColor(0xffffffff), mpAllocator(NULL), mpManager(manager), mDKStream(), meLanguage(USA), + mbZuSelected(false), mbCursorSelected(false), mriManager(muLimitStringLength), mpCursorLine(NULL), + mCursorLinePos(0), mbLineDraw(true), muSpecifyLineDrawCount(0), muCursorTimer(0) { +} + +Base::~Base() {} + +void Base::init() { + CommandReceiver::init(); + meInputMode = IM_Direct; + mfCursorX = 0.0f; + mfCursorY = 0.0f; + mfScrollX = 0.0f; + mfScrollY = 0.0f; + mfSustainTimer = 0.0f; + mfCursorTimer = 0.0f; + muGlobalAlpha = 255; + mDKStream.init(); + SetFixedWidth(GetFont()->GetWidth()); + EnableFixedWidth(false); + enableSpaceByRight(true); + resetRelation(); + updateCandidateState_(); + dirtyDrawCache(); + dirtyCursorCache(); + mfDrawScrollY = mfScrollY; +} + +bool Base::isEditMode() { + switch (mePredictMode) { + case PM_Off: + case PM_Atok: + break; + default: + if (!mpZiString->isFix()) return false; + break; + } + return true; +} + +bool Base::checkHeadOfSentence(bool checkSpace) { + bool externallyHandled; + onCommand(static_cast(32), &externallyHandled); + if (externallyHandled) return false; + bool moved = false; + if (mpString->getCursorPos() < 1) return true; + if (checkSpace) { + switch (mpString->getWCharAtCursor()) { + case L' ': + case L'\n': + break; + default: + return false; + } + moved = mpString->moveCursorLeft(); + } + bool beginning = mpString->atTheBeginningOfASentence(); + if (moved) mpString->moveCursorRight(); + return beginning; +} + +void Base::setDestination(Destination destination) { + meDestination = destination; +} + void Base::setLanguage(Language language) { meLanguage = language; switch (language) { @@ -536,59 +793,44 @@ void Base::setLanguage(Language language) { } } -struct CharacterInput { - wchar_t character; - u32 modifiers; - bool keyboardMode; - bool deadKey; - u32 data; -}; - -struct ConfirmInput { - wchar_t character; - u16 letterMode; - bool direct; - bool held; - bool confirmOnly; - bool silent; - void* holdingKey; -}; - -struct PredictionState { - Base::PredictMode mode; - bool enabled; -}; - -struct ControlInput { - HVKCode code; - u32 modifiers; -}; - -inline bool Base::hasZiPredictions() const { - if (!mbPredictOn) return false; - if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) return true; - return false; -} - -inline bool Base::usesZiPrediction() const { - if (!mbPredictOn) return false; - if (mePredictMode == PM_Atok) return false; - if (meLanguage == CN && static_cast(mpManager)->getCandidateBox()->isInvalid()) return false; - return true; -} - -inline void Base::resetPredictionContext() { - if (mpZiString && meLanguage == CN) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - updateCandidateState_(); +void Base::setPredictMode(PredictMode predictMode) { + switch (meDestination) { + case DST_EU: + if (predictMode == PM_En || predictMode == PM_De || predictMode == PM_Fr || predictMode == PM_Sp || predictMode == PM_It || predictMode == PM_Nl) { + break; + } + return; + case DST_JP: + if (predictMode == PM_Atok) { + break; + } + return; + case DST_US: + if (predictMode == PM_USEn || predictMode == PM_USFr || predictMode == PM_USSp) { + break; + } + return; + case DST_CN: + if (predictMode == PM_11) { + break; + } + return; + case DST_KR: + if (predictMode != PM_12) { + return; + } + break; } + PredictMode mode; + onCommand(static_cast(31), &mode); + mode = predictMode; + onCommand(static_cast(29), &mode); } -inline void Base::resetInputRelation() { - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); - updateCandidateState_(); +Base::PredictMode Base::getPredictMode() { + Base::PredictMode mode; + onCommand(static_cast(31), &mode); + return mode; } void Base::onCommand(INPUT_COMMAND command, void* data) { @@ -609,10 +851,7 @@ void Base::onCommand(INPUT_COMMAND command, void* data) { if (mDKStream.lookAhead()) mDKStream.putChar(0xffff); else mDKStream.putChar(L' '); if (mDKStream.isEmpty()) onSE(sound::SE_CHAR_INPUT); - { - tistring::WithAtok* unfix = mpUnfixString; - if (getCurrentString(false) == unfix) unfix->isConverting(); - } + checkUnfixConverting_(); for (;;) { wchar_t character = mDKStream.getChar(); if (!character) break; @@ -651,18 +890,14 @@ void Base::onCommand(INPUT_COMMAND command, void* data) { if (useAtok) { savedState.direct = false; savedState.kana = false; - mpUnfixString->setFixMode(keyboardState.direct); - mpUnfixString->changeKanaMode(keyboardState.kana); + setAtokMode_(keyboardState.direct, keyboardState.kana); } } if (input->deadKey) character = DeadKeyStream::ToCombineClass(meLanguage, character); if (character == L' ' && mDKStream.lookAhead()) mDKStream.putChar(0xffff); else mDKStream.putChar(character); if (mDKStream.isEmpty()) onSE(sound::SE_CHAR_INPUT); - { - tistring::WithAtok* unfix = mpUnfixString; - if (getCurrentString(false) == unfix) unfix->isConverting(); - } + checkUnfixConverting_(); for (;;) { wchar_t queued = mDKStream.getChar(); if (!queued) break; @@ -682,10 +917,7 @@ void Base::onCommand(INPUT_COMMAND command, void* data) { mpString->getCursorPos(); } else active->setTranslateMode(savedState.mode); bool useAtok = isAtokActive(); - if (useAtok) { - mpUnfixString->setFixMode(savedState.direct); - mpUnfixString->changeKanaMode(savedState.kana); - } + if (useAtok) setAtokMode_(savedState.direct, savedState.kana); } if (checkHeadOfSentence(true)) onCommand(static_cast(33), NULL); break; @@ -782,7 +1014,8 @@ void Base::onCommand(INPUT_COMMAND command, void* data) { } else { onSE(sound::SE_CHAR_DECIDE); if (mpUnfixString->isConverting()) { - mpUnfixString->commitPredicted(mpUnfixString->getSelectedConverting()); + int selected = mpUnfixString->getSelectedConverting(); + mpUnfixString->commitPredicted(selected); updateCandidateState_(); } else confirmInput_(); } @@ -1008,9 +1241,7 @@ void Base::onCommand(INPUT_COMMAND command, void* data) { case 39: mDKStream.clear(); return; case 47: return; case 36: { - u32 length = *static_cast(data); - if (fixed->getLength() > length) mpString->getLength(); - mpString->setLength(static_cast(length)); + trimString_(*static_cast(data)); return; } case 46: @@ -1024,105 +1255,51 @@ void Base::onCommand(INPUT_COMMAND command, void* data) { updateCandidateState_(); } -void Base::onHKBCtrlCode(HVKCode code, u32 modifiers) { - tistring::Decolated* current = getCurrentString(false); - switch (code) { - case 2: - if (mePredictMode == PM_Atok) toggleAtokMode_(0); - break; - case 17: - if (mePredictMode == PM_Atok) { - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Kana) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Roman); - } else if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Roman) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); - } - toggleAtokMode_(1); - } else if (meLanguage == KR && !mpManager->getPCKeyboard()->isQwertyOnly() && mpManager->getPCKeyboard()->isLanguageKeyActive()) { - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); - } else { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); - } +void Base::checkUnfixConverting_() { + tistring::WithAtok* unfix = mpUnfixString; + if (getCurrentString(false) == unfix) unfix->isConverting(); +} + +void Base::setAtokMode_(bool fixMode, bool kanaMode) { + mpUnfixString->setFixMode(fixMode); + mpUnfixString->changeKanaMode(kanaMode); +} + +void Base::updateCandidateState_() { + if (!mbPredictOn) return; + wchar_t prediction[64]; + if (mePredictMode == PM_Atok) { + if (mpUnfixString->hasConfirmedString()) { + const wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); + mpString->getCursorPos(); + mpString->confirm(confirmed); + mpString->getCursorPos(); + mpUnfixString->enableConfirmedString(false); + onSE(sound::SE_CHAR_DECIDE); } - break; - case 18: - if (mePredictMode == PM_Atok) { - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00 && !mbPredictOn) { - if (!mpManager->getPCKeyboard()->isQwertyOnly()) onSE(sound::SE_CHAR_CURSOR_FIX); - } else toggleAtokMode_(2); - } - break; - case 36: - if (mePredictMode == PM_Atok) toggleAtokMode_(0); - else if (static_cast(meLanguage) - CN <= 1) { - if (!mpManager->getPCKeyboard()->isQwertyOnly() && mpManager->getPCKeyboard()->isLanguageKeyActive()) { - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); - } else { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); - } + bool suppress = false; + CommandReceiver::onCommand(static_cast(35), &suppress); + candidatebox::CandidateBoxCaller::resetCandidate(); + if (!suppress) { + int count = mpUnfixString->getCurrentNumPredicted(); + for (int index = 0; index < count; ++index) { + mpUnfixString->getPredicted(index, prediction); + candidatebox::CandidateBoxCaller::addCandidate(prediction); } - } else if (mePredictMode != PM_Off && mpManager->getCandidateBox()->isActive()) { - mpManager->startPredictTurnOn(!mbPredictOn); + candidatebox::CandidateBoxCaller::updateCandidate(); } - break; - case 1: - if (current == mpUnfixString) updateCandidateState_(); - break; - case 9: - onCommand(static_cast(7), NULL); - onCommand(static_cast(39), NULL); - break; - case 8: - onSpaceKeyHWKB(modifiers); - break; - case 29: - onCommand(static_cast(44), NULL); - break; - case 30: - onCommand(static_cast(45), NULL); - break; - case 31: - onCommand(static_cast(42), NULL); - break; - case 32: - onCommand(static_cast(43), NULL); - break; - case 16: - if (mePredictMode == PM_Atok) { - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Kana) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Roman); - } else if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Roman) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); - } else if (!mpManager->getPCKeyboard()->isQwertyOnly()) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); - } + } else { + candidatebox::CandidateBoxCaller::resetCandidate(); + int count = mpZiString->getCurrentNumPredicted(); + for (int index = 0; index < count; ++index) { + mpZiString->getPredicted(index, prediction); + candidatebox::CandidateBoxCaller::addCandidate(prediction); } - break; + candidatebox::CandidateBoxCaller::updateCandidate(); } } -LayoutByNW4R::LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, const char* layout, EventObserver* observer, const char* fontName) - : Base(manager), nw4rmanager::Layout(accessor, layout, observer), mpLayoutData("T_2l_TextBox"), - mpLanguageData(&csLanguageDependencyDataUEJ__Q29textinput9inputform), mpFontName(fontName), - mbUpVisible(false), mbDownVisible(false), mbRepeat(false), mpInputEventHandler(NULL) {} - -static inline const char* selectInputTextName(const nw4rmanager::Layout& layout, const void* const& languageData) { - if (layout.getPane(static_cast(languageData)->textBox)) { - return static_cast(languageData)->textBox; - } - return "T_2l_TextBox"; -} - -inline nw4r::lyt::TextBox* LayoutByNW4R::getTextBox() const { - nw4r::lyt::TextBox* textBox = static_cast(mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true)); - return textBox; -} - -void LayoutByNW4R::create(MEMAllocator* allocator, EditBuffer* editBuffer) { - nw4r::lyt::Pane* pane; - void* handlerMemory; +void Base::create(MEMAllocator* allocator, EditBuffer* editBuffer) { mpAllocator = allocator; textdrawer::Base::create(allocator); mpString = static_cast(editBuffer->mpString); @@ -1160,298 +1337,113 @@ void LayoutByNW4R::create(MEMAllocator* allocator, EditBuffer* editBuffer) { row->StrCount = 0; row->DispRowCount = 1; mpCursorLine = row; - handlerMemory = MEMAllocFromAllocator(allocator, sizeof(EventHandler)); - mpInputEventHandler = new (handlerMemory) EventHandler(this); - nw4rmanager::Layout::createWithEventHandler(allocator, mpInputEventHandler); - if (!mpFontName) { - mpFontName = "RevoIpl_RodinNTLGProM_32_I4.brfnt"; - mFont.SetResource(mpMultiArcResourceAccessor->GetResource(0, mpFontName, NULL)); - mFont.SetAlternateChar(0xe06b); - setFont(mFont); - } else { - mpMultiArcResourceAccessor->GetFont(mpFontName)->SetAlternateChar(0xe06b); - setFont(*mpMultiArcResourceAccessor->GetFont(mpFontName)); +} + +void Base::draw() { + SetCursor(getScale().x, mfScrollY); + nw4r::math::VEC2 scale = getScale(); + nw4r::ut::Rect clip(0.0f, 0.0f, 0.0f, 0.0f); + nw4r::math::VEC2 origin = getGlobalLeftTopPos(); + clip.left = origin.x; + clip.bottom = origin.y; + clip.right = origin.x + scale.x * (mRect.right - mRect.left); + clip.top = origin.y + scale.y * (mRect.top - mRect.bottom); + u32 position = mpString->getCursorPos(); + beginDraw(clip); + drawFixString(position); + endDraw(); +} + +void Base::makeUpCursorPos(CursorPos* cursorPos, u32 pos, s32 startLine, s32 endLine) { + u32 wordWrapCounter = muWordWrapCounter; + muWordWrapCounter = pos; + textdrawer::Base::makeUpCursorPos(cursorPos, pos, startLine, endLine); + muWordWrapCounter = wordWrapCounter; +} + +// The original file had an uncalled function here that the linker stripped, so its body +// is lost. It called getDrawModifyEndLine and getEndPos and was the first user of 0.5f, +// which places those inline copies and the constant; this stand-in keeps that order. +f32 strippedFunctionStandIn(Base* base) { + base->getDrawModifyEndLine(); + base->getEndPos(); + return 0.5f; +} + +void Base::drawFixString(u32 position) { + CursorPos cursor; + cursor.fCursorX = 0.0f; + cursor.fCursorY = 0.0f; + cursor.uCursorPos = position; + mCharColor.a = muGlobalAlpha; + SetTextColor(mCharColor); + u32 length = mpString->getLength(); + textdrawer::Base::setDrawString(mpString->getWCString(), 0, length); + textdrawer::Base::draw(&cursor); + drawCursor(cursor.fCursorX, cursor.fCursorY); +} + +void Base::trimString_(u32 length) { + if (mpString->getLength() > length) mpString->getLength(); + mpString->setLength(static_cast(length)); +} + +void Base::calc() { + if (mScrollAnm.isActive()) { + f32 scroll = mScrollAnm.getValue(); + mfScrollY = scroll; + mfDrawScrollY = mfScrollY; } - nw4r::lyt::TextBox* textBox = getTextBox(); - textBox->SetString(L"", 0); - mfCharacterSpacing = textBox->GetCharSpace(); - mfLineSpacing = textBox->GetLineSpace(); - mfFontWidth = textBox->GetFontSize().width; - mfFontHeight = textBox->GetFontSize().height; - mRect = textBox->GetPaneRect(mDrawInfo); - AdjustPaneMtx(mMtx.m, mDrawInfo, textBox->GetGlobalMtx()); - csCharColor = textBox->GetTextColor(nw4r::lyt::TEXTCOLOR_TOP); - setVisible("N_2line", true); - mpPaneManager->setAllComponentTriggerTarget(false); - mpPaneManager->setAllBoundingBoxComponentTriggerTarget(true); - pane = mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLanguageData)->textBox, true); - if (!pane) pane = mpLayout->GetRootPane()->FindPaneByName(selectInputTextName(*this, mpLanguageData), true); - mpPaneManager->getPaneComponentByPane(pane)->setTriggerTarget(true); - for (u16 buttonIndex = 0; buttonIndex < 2; buttonIndex++) { - const ButtonAnimations& button = csButtonAnimations[buttonIndex]; - nw4rmanager::AnmPane* animationPane = NULL; - switch (button.type) { - case KT_NormalButton: { - void* memory = MEMAllocFromAllocator(allocator, sizeof(NormalButtonAnmPane)); - animationPane = new (memory) NormalButtonAnmPane(getPane(button.paneName), NULL); - break; - } - } - nw4r::ut::List_Append(&mAnmPanes, animationPane); - for (u16 animationIndex = 0; animationIndex < button.count; animationIndex++) { - void* resource = mpMultiArcResourceAccessor->GetResource(0, button.files[animationIndex]->fileName); - AnimTransformPane* transform = static_cast(getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor)); - if (button.bindingName == NULL) { - animationPane->addAnimation(allocator, button.files[animationIndex]->id, transform, false, true); - } else { - animationPane->forceAddAnimation(allocator, button.files[animationIndex]->id, transform, button.bindingName, false, true); - } - } + if (!mScrollAnm.isActive()) autoScroll(); + if (!mpString->isOnSustain()) mfSustainTimer = 1.0f + mfSustainTimer; + mScrollAnm.calc(); + f32 wave = colorSine(sfColorPhase); + mSelectedColor.r = 2; + mSelectedColor.g = 90; + mSelectedColor.b = 253; + mSelectedColor.a = static_cast(150.0f + 30.0f * wave); + if (mpString->isOnSustain()) { + mSelectedColor.r = 52; + mSelectedColor.g = 140; + mSelectedColor.b = 253; + mSelectedColor.a = static_cast(50.0f + 10.0f * wave); + } else if (mfSustainTimer <= 50.0f) { + mSelectedColor.r = static_cast(util::hermiteInterporation(mfSustainTimer, 0.0f, 52.0f, 0.0f, 50.0f, 2.0f, 0.0f)); + mSelectedColor.g = static_cast(util::hermiteInterporation(mfSustainTimer, 0.0f, 140.0f, 0.0f, 50.0f, 90.0f, 0.0f)); + u8 blue = static_cast(util::hermiteInterporation(mfSustainTimer, 0.0f, 253.0f, 0.0f, 50.0f, 253.0f, 0.0f)); + f32 phase = sfColorPhase; + f32 angle = phase * 0.7111111f; + mSelectedColor.b = blue; + wave = nw4r::math::SinFIdx(angle); + f32 alpha = util::hermiteInterporation(mfSustainTimer, 0.0f, 50.0f, 0.0f, 50.0f, 150.0f, 0.0f); + mSelectedColor.a = static_cast(alpha + 20.0f * wave); } + u32 cursorTimer = muCursorTimer + 8; + f32 phase = sfColorPhase; + muCursorTimer = cursorTimer; + sfColorPhase = nextColorPhase(phase); +} + +void Base::calcCursorTimer() { + muCursorTimer += 8; +} + +void Base::setFont(const nw4r::ut::Font& font) { + textdrawer::Base::setFont(font); +} + +void Base::setString(const wchar_t* string) { + mpString->set(string); +} + +void Base::clear() { init(); -} -inline const nw4r::lyt::Pane* LayoutByNW4R::getLanguageTextPane() const { - return getPane(static_cast(mpLanguageData)->textBox); + mpString->clear(); } -void LayoutByNW4R::init() { - Base::init(); - searchAnmPane("P_txtScrll_UP")->changeAnimation(ANM_Off); - searchAnmPane("P_txtScrll_DOWN")->changeAnimation(ANM_Off); - mbUpVisible = false; - mbDownVisible = false; - mUpRepeat = 0; - mDownRepeat = 0; - mLeftRepeat = 0; - mRightRepeat = 0; - mRepeatButtons = 0; - mCharColor = csCharColor; - visibleSeparator(false); - nw4r::lyt::TextBox* textBox = getTextBox(); - textBox->SetString(L"", 0); - mfCharacterSpacing = textBox->GetCharSpace(); - mfLineSpacing = textBox->GetLineSpace(); - mfFontWidth = textBox->GetFontSize().width; - mfFontHeight = textBox->GetFontSize().height; - mRect = textBox->GetPaneRect(mDrawInfo); - AdjustPaneMtx(mMtx.m, mDrawInfo, textBox->GetGlobalMtx()); - mpLayout->Animate(0); - mpLayout->CalculateMtx(mDrawInfo); - const VisiblePanes* visibility = static_cast(mpLanguageData)->visibility; - for (u16 index = 0; index < visibility->visibleCount; ++index) setVisible(visibility->visibleNames[index], true); - for (u16 index = 0; index < visibility->hiddenCount; ++index) setVisible(visibility->hiddenNames[index], false); -} -void LayoutByNW4R::calc() { - Base::calc(); - nw4rmanager::Layout::calc(); - bool up = false; - bool down = false; - const char* separator = static_cast(mpLanguageData)->separator; - if (getPane(separator)) setVisible(static_cast(mpLanguageData)->separator, mbRepeat); - else setVisible("N_separateBarAll", mbRepeat); - if (!mScrollAnm.isActive()) { - if (0.0f > mfScrollY) up = true; - if (mfMinScrollY < mfScrollY) down = true; - if (mbUpVisible != up) { - mbUpVisible = up; - if (up) { - searchAnmPane("P_txtScrll_UP")->onAnmEvent(nw4rmanager::AnmPane::PE_6); - mpPaneManager->searchPaneComponent("P_txtScrll_UP")->init(); - } else searchAnmPane("P_txtScrll_UP")->onAnmEvent(nw4rmanager::AnmPane::PE_7); - } - if (mbDownVisible != down) { - mbDownVisible = down; - if (down) { - searchAnmPane("P_txtScrll_DOWN")->onAnmEvent(nw4rmanager::AnmPane::PE_6); - mpPaneManager->searchPaneComponent("P_txtScrll_DOWN")->init(); - } else searchAnmPane("P_txtScrll_DOWN")->onAnmEvent(nw4rmanager::AnmPane::PE_7); - } - } -} - -void LayoutByNW4R::setLanguage(Language language) { - Base::setLanguage(language); - if (language == CN) mpLanguageData = &csLanguageDependencyDataCHN__Q29textinput9inputform; - else if (language == KR) mpLanguageData = &csLanguageDependencyDataKOR__Q29textinput9inputform; - else mpLanguageData = &csLanguageDependencyDataUEJ__Q29textinput9inputform; - const char* textName; - if (!getLanguageTextPane()) textName = "T_2l_TextBox"; - else textName = static_cast(mpLanguageData)->textBox; - mpLayoutData = textName; - if (::strcmp(static_cast(mpLayoutData), "T_2l_TextBox") != 0) setVisible("T_2l_TextBox", false); - nw4r::lyt::Pane* pane = mpLayout->GetRootPane()->FindPaneByName(selectInputTextName(*this, mpLanguageData), true); - static_cast(pane)->SetString(L"", 0); - const VisiblePanes* visibility = static_cast(mpLanguageData)->visibility; - for (u16 index = 0; index < visibility->visibleCount; ++index) setVisible(visibility->visibleNames[index], true); - for (u16 index = 0; index < visibility->hiddenCount; ++index) setVisible(visibility->hiddenNames[index], false); - pane = mpLayout->GetRootPane()->FindPaneByName(selectInputTextName(*this, mpLanguageData), true); - mpPaneManager->getPaneComponentByPane(pane)->setTriggerTarget(true); - if (getPane("T_title_text")) { - nw4r::lyt::TextBox* title = nw4r::ut::DynamicCast(getPane("T_title_text")); - const char* titleName = static_cast(mpLanguageData)->title; - if (getPane(titleName)) { - nw4r::lyt::TextBox* languageTitle = nw4r::ut::DynamicCast(getPane(static_cast(mpLanguageData)->title)); - title->SetCharSpace(languageTitle->GetCharSpace()); - title->SetLineSpace(languageTitle->GetLineSpace()); - title->SetFontSize(languageTitle->GetFontSize()); - title->SetTranslate(languageTitle->GetTranslate()); - title->SetSize(languageTitle->GetSize()); - } - } -} - -void LayoutByNW4R::onCommand(INPUT_COMMAND command, void* data) { - mpEventObserver->onInput(command, data); - mpEventObserver->onCommand(command, data); - Base::onCommand(command, data); - if (command == 31) return; - u32 limit = muLimitStringLength; - if (meLanguage == KR) { - u32 start, end; - mpString->getCursorPos(&start, &end); - if (start >= limit && !mpString->isKanaFix()) { - mpString->clearKana(); - onSE(sound::SE_CHAR_DELETE_ERROR); - } - if (!mpString->isKanaFix()) limit = muLimitStringLength - 1; - } - if (limit < mpString->getLength()) { - u32 start, end; - mpString->getCursorPos(&start, &end); - if (start > limit || end > limit) { - onSE(sound::SE_CHAR_DELETE_ERROR); - Base::onCommand(static_cast(36), &limit); - } - } - switch (command) { - case 32: - case 33: - case 35: - break; - default: { - u32 trimLimit = limit; - if (trimLimit < mpString->getLength()) { - if (mpString->getLength() > trimLimit) mpString->getLength(); - mpString->setLength(static_cast(trimLimit)); - mpEventObserver->onOutOfLength(); - if (command == 6 || command == 5 || command == 0 || command == 38 || command == 21 || command == 7) { - onSE(sound::SE_CHAR_DELETE_ERROR); - } - } - break; - } - } - u32 excessPos = isOverRowLimit(muLimitRowNum, mpString->getWCString()); - u32 rowLimit = excessPos; - if (excessPos) { - if (mpString->getLength() > excessPos) mpString->getLength(); - mpString->setLength(static_cast(excessPos)); - mpEventObserver->onOutOfLength(); - onSE(sound::SE_CHAR_DELETE_ERROR); - Base::onCommand(static_cast(36), &rowLimit); - if (meLanguage == KR && !mpString->isKanaFix()) { - rowLimit = isOverRowLimit(muLimitRowNum, mpString->getWCString()); - if (rowLimit) mpString->clearKana(); - } - } -} - - - -void EventHandler::onTiEvent(gui::PaneComponent* component, u32 event, Input* input) { - char animationName[17]; - const char* name = component->getPane()->GetName(); - nw4r::math::VEC2 cursor; - cursor.x = input->x; - cursor.y = -input->y; - if (name[0] == 'B') { - util::replaceChar(animationName, 17, name, 0, 'P'); - if (event == gui::EventHandler::ON_TRIG && (input->trigger & WPAD_BUTTON_A) && !mpInputForm->isInScroll()) { - if (mpInputForm->isAbleToUp() && util::strcmp("P_txtScrll_UP", animationName)) { - textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; - movement.fCursorY = mpInputForm->getLineHeight(); - mpInputForm->onCommand(static_cast(24), &movement); - mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); - } else if (mpInputForm->isAbleToDown() && util::strcmp("P_txtScrll_DOWN", animationName)) { - textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; - movement.fCursorY = -mpInputForm->getLineHeight(); - mpInputForm->onCommand(static_cast(24), &movement); - mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); - } - } - if (event == gui::EventHandler::ON_MOVE && (input->hold & WPAD_BUTTON_A) && !(input->trigger & WPAD_BUTTON_A)) { - if (mpInputForm->isAbleToUp() && util::strcmp("P_txtScrll_UP", animationName)) { - if (component->isDragging(input->controller)) { - u32 duration = mpInputForm->getFlightDuration(input->controller, name); - if (duration >= 60 && duration % 20 == 0) { - textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; - movement.fCursorY = mpInputForm->getLineHeight(); - mpInputForm->onCommand(static_cast(24), &movement); - mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); - } - } - } else if (mpInputForm->isAbleToDown() && util::strcmp("P_txtScrll_DOWN", animationName)) { - if (component->isDragging(input->controller)) { - u32 duration = mpInputForm->getFlightDuration(input->controller, name); - if (duration >= 60 && duration % 20 == 0) { - textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; - movement.fCursorY = -mpInputForm->getLineHeight(); - mpInputForm->onCommand(static_cast(24), &movement); - mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); - } - } - } - } - AnmPane* animation = static_cast(mpInputForm->searchAnmPane(animationName)); - if (animation) { - switch (event) { - case gui::EventHandler::ON_LEFT: animation->onAnmEvent(nw4rmanager::AnmPane::PE_2); break; - case gui::EventHandler::ON_POINT: - if (animation->getState() != ANM_Off) { - mpEventObserver->onSE(sound::SE_SELECT); - animation->onAnmEvent(nw4rmanager::AnmPane::PE_1); - } - break; - } - } - } else if (name[0] == 'P') { - AnmPane* animation = static_cast(mpInputForm->searchAnmPane(name)); - if (animation) { - switch (event) { - case gui::EventHandler::ON_POINT: - if (animation->getState() != ANM_Off) { - mpEventObserver->onSE(sound::SE_SELECT); - animation->onAnmEvent(nw4rmanager::AnmPane::PE_1); - } - break; - case gui::EventHandler::ON_LEFT: - if (animation->getState() != ANM_Off) { - mpEventObserver->onSE(sound::SE_SELECT); - animation->onAnmEvent(nw4rmanager::AnmPane::PE_2); - } - break; - } - } - } else { - const char* textPane; - LayoutByNW4R* form = mpInputForm; - const nw4rmanager::Layout& layout = *form; - if (layout.getPane(static_cast(form->mpLanguageData)->textBox)) textPane = static_cast(form->mpLanguageData)->textBox; - else textPane = "T_2l_TextBox"; - if (util::strcmp(name, textPane)) { - if (event == gui::EventHandler::ON_TRIG && (input->trigger & WPAD_BUTTON_A)) mpInputForm->onCommand(static_cast(14), &cursor); - if (event == gui::EventHandler::ON_RELEASE && (input->release & WPAD_BUTTON_A)) mpInputForm->onCommand(static_cast(15), &cursor); - if (event == gui::EventHandler::ON_MOVE && (input->hold & WPAD_BUTTON_A)) mpInputForm->onCommand(static_cast(16), &cursor); - } - } -} - -void Base::enableSpaceByRight(bool rightWithSpace) { - mbRightWithSpace = rightWithSpace; -} - -void Base::setDestination(Destination destination) { - meDestination = destination; +void Base::preDraw(u32 pos) { + muWordWrapCounter = pos; + mbHyphen = false; } bool Base::findURL(u32* start, u32* end, const wchar_t* string, u32 from, u32 to) { @@ -1534,1463 +1526,144 @@ bool Base::findURL(u32* start, u32* end, const wchar_t* string, u32 from, u32 to return found; } -void Base::autoScroll() { - if (mScrollAnm.isActive()) return; - if (u32(meScrollFlag - SF_ScrollOn) > 1) return; - f32 cursorY = mfCursorY + getLineHeight() / 2.0f; - if (cursorY < 0.0f) { - s32 lines = s32(cursorY / getLineHeight() - 1.0f); - mScrollAnm.startAnm(mfScrollY, mfScrollY - lines * getLineHeight(), 15.0f, NULL, NULL); - onSE(sound::SE_LINE_SCROLL); +bool Base::doWordWrap(const wchar_t* string, u32 pos, f32 width) { + struct WordWrapDrawInfo { + f32 left; + f32 top; + f32 right; + f32 bottom; + u16 character; + }; + + if (!mbDoWordWrap) { + return false; } - if (cursorY >= (mRect.top - mRect.bottom) * getScale().y) { - s32 lines = s32((cursorY - (mRect.top - mRect.bottom) * getScale().y) / getLineHeight()) + 1; - mScrollAnm.startAnm(mfScrollY, mfScrollY - lines * getLineHeight(), 15.0f, NULL, NULL); - onSE(sound::SE_LINE_SCROLL); - } - meScrollFlag = SF_NoScroll; -} -} - -void textinput::util::Animation::startAnm(f32 start, f32 end, f32 duration, AnimObserver* observer, void* data) { - mfStartPoint = start; - mfEndPoint = end; - mfAnimationTime = duration; - mfCurrentFrame = 0.0f; - mbInAnimation = true; - mpAnimObserver = observer; - mpData = data; - mbSE = false; - if (observer) observer->onAnmEvent(AnimObserver::AE_0, data); -} - -namespace inputform { - -void Base::deselectCandidate() { - if (!mbPredictOn) return; - if (mePredictMode != PM_Atok) return; - mpUnfixString->setSelectedCandidate(-1); -} - -void Base::resetRelation() { - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); -} - -inline void DeadKeyStream::init() { - KPRInitQueue(&mKPRQueue); - KPRSetMode(&mKPRQueue, KPR_MODE_DEADKEY); -} - -void Base::init() { - meInputMode = IM_Direct; - mfCursorX = 0.0f; - mfCursorY = 0.0f; - mfScrollX = 0.0f; - mfScrollY = 0.0f; - mfSustainTimer = 0.0f; - mfCursorTimer = 0.0f; - muGlobalAlpha = 255; - mDKStream.init(); - SetFixedWidth(GetFont()->GetWidth()); - EnableFixedWidth(false); - enableSpaceByRight(true); - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); - updateCandidateState_(); - dirtyDrawCache(); - dirtyCursorCache(); - mfDrawScrollY = mfScrollY; -} - -void Base::create(MEMAllocator* allocator, EditBuffer* editBuffer) { - mpAllocator = allocator; - textdrawer::Base::create(allocator); - mpString = static_cast(editBuffer->mpString); - mpUnfixString = static_cast(editBuffer->mpUnfixString); - mpZiString = static_cast(editBuffer->mpZiString); - mriManager.mpAllocator = allocator; - mriManager.mpInfo = static_cast(MEMAllocFromAllocator(allocator, (mriManager.mMaxLength + 2) * sizeof(Info_))); - mriManager.init(); - Info_* rows; - Info_* row; - u16 next; - u16 previous; - u16 selectedIndex; - Info_* listEnd; - Info_* info; - rows = mriManager.mpInfo; - row = &rows[mriManager.mMaxLength]; - row = &rows[row->Next]; - next = row->Next; - previous = row->Back; - selectedIndex = rows[next].Back; - rows[next].Back = previous; - rows[previous].Next = next; - row->Back = selectedIndex; - row->Next = selectedIndex; - info = mriManager.mpInfo; - listEnd = &info[info[static_cast(mriManager.mMaxLength + 1)].Back]; - if (row->Back == row->Next) { - u16 head = listEnd->Next; - row->Back = info[head].Back; - row->Next = head; - listEnd->Next = selectedIndex; - info[head].Back = selectedIndex; - } - row->StrCount = 0; - row->DispRowCount = 1; - mpCursorLine = row; -} - -tistring::Decolated* Base::getCurrentString(bool inputting) { - if (!mbPredictOn) return mpString; - if (meLanguage == KR) { - if (mpManager->getToolBar()->isQwerty()) { - if (mpManager->getPCKeyboard()->getTranslateMode() == 0) return mpString; - } else { - if (mpManager->getCellPhoneKeyboard()->getInputMode() != 0) return mpString; - } - } - if (meLanguage == CN) { - if (mpManager->getCandidateBox()->isInvalid() || !mpManager->getCandidateBox()->isActive()) return mpString; - } - switch (mePredictMode) { - case PM_Atok: - if (!mpUnfixString->isFix() || inputting) return mpUnfixString; - break; - default: - if (!mpZiString->isFix() || inputting) return mpZiString; - break; - } - return mpString; -} - -bool Base::isVacancy() const { - if (mpString->getLength() != 0 || !mpString->isKanaFix()) return false; - if (mePredictMode == PM_Atok) { - if (!mpUnfixString->isFix()) return false; - if (mpString->getLength() != 0) return false; - if (mpUnfixString->isCandidateSelected()) return false; - } else { - if (mePredictMode == PM_12) return true; - if (mePredictMode != PM_Off) { - if (mpZiString->getLength() != 0) return false; - wchar_t input[16]; - if (mpZiString->getCurrentInput(input, 16) > 0) return false; - if (mbCursorSelected | mbZuSelected) { - const wchar_t* selected = mpZiString->getCurrentSelected(); - if (selected && *selected != 0xfffe) return false; - } - } - } - return true; -} - -void Base::notifyChangeMode() { - if (mePredictMode == PM_Atok) { - if (mpManager->getToolBar()->isQwerty()) { - if (mpManager->getPCKeyboard()->isABC()) { - if (!mpManager->getPCKeyboard()->getTranslateMode()) goto checkInput; - } - } - if (!mpManager->getToolBar()->isQwerty()) mpManager->getCellPhoneKeyboard()->getInputMode(); -checkInput: - if (mpUnfixString->getInputStringLength() == 0) updateCandidateState_(); - } else if (mePredictMode == PM_12) { - tistring::WithZi::PredictLanguage language; - if (mpManager->getToolBar()->isQwerty()) language = static_cast(10); - else language = static_cast(11); - mpZiString->setPredictLaunguage(language); - } else if (mePredictMode == PM_11) { - if (mbPredictOn) mpZiString->setCurrentWord(NULL); - } -} - -void Base::updateCandidateState_() { - if (!mbPredictOn) return; - wchar_t prediction[64]; - if (mePredictMode == PM_Atok) { - if (mpUnfixString->hasConfirmedString()) { - const wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); - mpString->getCursorPos(); - mpString->confirm(confirmed); - mpString->getCursorPos(); - mpUnfixString->enableConfirmedString(false); - onSE(sound::SE_CHAR_DECIDE); - } - bool suppress = false; - CommandReceiver::onCommand(static_cast(35), &suppress); - candidatebox::CandidateBoxCaller::resetCandidate(); - if (!suppress) { - int count = mpUnfixString->getCurrentNumPredicted(); - for (int index = 0; index < count; ++index) { - mpUnfixString->getPredicted(index, prediction); - candidatebox::CandidateBoxCaller::addCandidate(prediction); - } - candidatebox::CandidateBoxCaller::updateCandidate(); - } - } else { - candidatebox::CandidateBoxCaller::resetCandidate(); - int count = mpZiString->getCurrentNumPredicted(); - for (int index = 0; index < count; ++index) { - mpZiString->getPredicted(index, prediction); - candidatebox::CandidateBoxCaller::addCandidate(prediction); - } - candidatebox::CandidateBoxCaller::updateCandidate(); - } -} - -void Base::moveCursorUp() { - f32 y = mfCursorY; - if (-(mfCursorY - mfScrollY) >= 0.0f) { - u32 start, end; - mpString->getCursorPos(&start, &end); - if (start == 0 && end == 0) onSE(sound::SE_CHAR_CURSOR_FIX); - else onSE(sound::SE_CHAR_CURSOR); - mpString->setCursorPos(0); - } else { - y = mfCursorY >= 0.0f ? mfCursorY : 0.0f; - f32 lineHeight = getLineHeight(); - f32 targetY = 1.0f + (y - lineHeight); - u32 position = calcCursorPos(mfCursorX, targetY); - mpString->setCursorPos(position); - onSE(sound::SE_CHAR_CURSOR); - } - meScrollFlag = SF_ScrollOn; -} - -void Base::moveCursorDown() { - if (-(mfCursorY - mfScrollY) < mfMinScrollY) { - u32 start, end; - mpString->getCursorPos(&start, &end); - if (start == mpString->getLength() && end == mpString->getLength()) onSE(sound::SE_CHAR_CURSOR_FIX); - else onSE(sound::SE_CHAR_CURSOR); - mpString->setCursorPos(mpString->getLength()); - } else { - f32 lineHeight = getLineHeight(); - f32 y = mfCursorY + lineHeight; - mpString->setCursorPos(calcCursorPos(mfCursorX, 1.0f + y)); - onSE(sound::SE_CHAR_CURSOR); - } - meScrollFlag = SF_ScrollOn; -} - -void Base::confirmInputting_(wchar_t character, bool direct, u16 letterMode, bool confirmOnly, void* holdingKey) { - tistring::Decolated* current = getCurrentString(true); - if (!character) return; - if (mbPredictOn && getPredictMode() == PM_11) { - if (!mpManager->getCandidateBox()->isInvalid() && !util::isAlphabet(character) && (character < L'1' || character > L'5')) { - mpString->getCursorPos(); - mpString->inputChar(character); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - if (meLanguage == CN) { - mpZiString->clearCandidates(); - mbZuSelected = false; - mpZiString->update(); - } else confirmInput_(); - return; - } - } - if (direct) { - mpString->getCursorPos(); - mpString->inputChar(character); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } else { - if (current == mpZiString) { - if (!mpZiString->getInputStringLength()) { - mpZiString->changeLetterMode(static_cast(letterMode)); - mpZiString->setCellPhoneHoldingkey(holdingKey); - } - if (mpZiString->getInputStringLength() >= 32) { - onCommand(static_cast(6), NULL); - mpZiString->changeLetterMode(static_cast(letterMode)); - mpZiString->inputChar(character); - onSE(sound::SE_CHAR_DECIDE); - updateCandidateState_(); - return; - } - } else if (current == mpUnfixString) { - if (confirmOnly && !mpUnfixString->hasCandidate()) return; - } else if (mbPredictOn && mePredictMode == PM_Atok && current != mpUnfixString && character == L' ') { - character = 0x3000; - mpUnfixString->setCandidate(0); - } - if (current == mpString) { - mpString->getCursorPos(); - mpString->inputChar(character); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } else { - current->inputChar(character); - if (meLanguage == KR && mpManager->getToolBar()->isQwerty()) { - wchar_t predicted[64]; - mpZiString->getPredicted(0, predicted); - if (wcslen(predicted) >= 2) { - predicted[1] = 0; - mpString->getCursorPos(); - mpString->inputString(predicted); - mpString->getCursorPos(); - mpZiString->partialConfirmForKR(); - } - } - } - onSE(sound::SE_CHAR_INPUT); - } -} - -void Base::inputCharZi_(wchar_t character, u32 modifiers) { - if (meLanguage != KR && (modifiers & 3)) character = util::toWLower(character); - bool direct = false; - if (character == L' ') direct = true; - if (meLanguage == CN) { - if (!util::isAlphabet(character) && (character < L'1' || character > L'5' || !mpZiString->getInputStringLength())) direct = true; - } else if (meLanguage == KR) { - if (util::isAlphabet(character)) { - if (getCurrentString(true) == mpZiString && (modifiers & 2)) character = util::reverseLetterCaseW(character); - } else direct = true; - } - if (direct) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) confirmInput_(); - mpString->getCursorPos(); - mpString->inputChar(character); - mpString->getCursorPos(); - if (meLanguage == CN) { - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - onSE(sound::SE_CHAR_DECIDE); - } else { - u16 letterMode; - switch (modifiers & 3) { - case 1: letterMode = 0; break; - case 2: letterMode = 2; break; - default: letterMode = 1; break; - } - confirmInputting_(character, false, letterMode, false, NULL); - } - meScrollFlag = SF_ScrollOn; -} - -void Base::toggleAtokMode_(u8 operation) { - bool allowed; - if (!mpManager->getToolBar()->isEnableKeytopChange() && !mpManager->getToolBar()->isQwerty()) { - allowed = false; - } else allowed = !mpManager->getPCKeyboard()->isQwertyOnly(); - if (!allowed) return; - bool enabled; - if (mpManager->getCandidateBox()->isActive()) { - if (mpManager->isPredictTurning()) return; - enabled = !mbPredictOn; - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) enabled = true; - } else { - enabled = mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00; - } - if (enabled && operation == 2) enabled = false; - else if (!enabled && operation == 1) enabled = true; - if (enabled) { - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); - } - } else { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); - } - if (mpManager->getCandidateBox()->isActive() && mbPredictOn != enabled) { - mpManager->startPredictTurnOn(!mbPredictOn); - } -} - -void Base::onSpaceKeyHWKB(u32 modifiers) { - tistring::Decolated* current = getCurrentString(false); - if (modifiers & 8) { - if (static_cast(meLanguage) - CN <= 1 && !mpManager->getPCKeyboard()->isQwertyOnly() && mpManager->getPCKeyboard()->isLanguageKeyActive()) { - if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { - mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); - } else mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); - } - return; - } - bool useZi; - if (!mbPredictOn) useZi = false; - else if (mePredictMode == PM_Atok) useZi = false; - else if (meLanguage == CN && static_cast(mpManager)->getCandidateBox()->isInvalid()) useZi = false; - else useZi = true; - if (useZi) { - bool predicted; - if (!mbPredictOn) predicted = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predicted = true; - else predicted = false; - if (predicted) { - if (!(mbCursorSelected | mbZuSelected) && mpManager->getToolBar()->isQwerty()) { - if (meLanguage != CN && meLanguage != KR && mbPredictOn && mePredictMode != PM_Atok) { - wchar_t input[64]; - mpZiString->getCurrentInput(input, 64); - mpString->getCursorPos(); - mpString->inputString(input); - mpString->getCursorPos(); - mpZiString->clearCandidates(); - mbZuSelected = false; - getCurrentString(false); - if (mpZiString && meLanguage == CN) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - updateCandidateState_(); - } - } - } else confirmInput_(); - updateCandidateState_(); - } - } else { - bool useAtok; - u32 enabled = mbPredictOn; - if (enabled == 0) useAtok = false; - else useAtok = mePredictMode == PM_Atok; - if (useAtok && current == mpUnfixString) { - if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); - if (mpUnfixString->isConverting()) { - if (!mpManager->getCandidateBox()->isInScroll()) { - if (modifiers & 2) { - tistring::Decolated* active = getCurrentString(false); - if (active == mpUnfixString) { - s32 selected = static_cast(mpUnfixString->getSelectedConverting() - 1); - if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; - else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - } - } else { - tistring::Decolated* active = getCurrentString(false); - if (active == mpUnfixString) { - s32 selected = static_cast(mpUnfixString->getSelectedConverting() + 1); - if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; - else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - } - } - onSE(sound::SE_CHAR_CURSOR_FIX); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - } - } else { - if (mpUnfixString->getInputStringLength()) { - mpUnfixString->startConverting(); - updateCandidateState_(); - moveCandidateToIdx(0); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onCommand(static_cast(47), NULL); - } - } - return; - } - } - if (mDKStream.lookAhead()) mDKStream.putChar(0xffff); - else mDKStream.putChar(L' '); - if (!mbPredictOn) useZi = false; - else if (mePredictMode == PM_Atok) useZi = false; - else if (meLanguage == CN && static_cast(mpManager)->getCandidateBox()->isInvalid()) useZi = false; - else useZi = true; - if (useZi) { - wchar_t character; - for (;;) { - character = mDKStream.getChar(); - if (!character) break; - inputCharZi_(character, modifiers); - } - } else { - wchar_t character; - for (;;) { - character = mDKStream.getChar(); - if (!character) break; - inputCharDefault_(character, modifiers); - } - } - updateCandidateState_(); -} - - -void Base::onPressUp() { - tistring::Decolated* current = getCurrentString(false); - if (mpZiString == current) return; - if (mpUnfixString == current) { - if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); - if (mpUnfixString->isConverting()) { - if (!mpManager->getCandidateBox()->isInScroll()) { - tistring::Decolated* active = getCurrentString(false); - if (active == mpUnfixString) { - s32 selected = static_cast(mpUnfixString->getSelectedConverting() - 1); - if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; - else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - } - onSE(sound::SE_CHAR_CURSOR_FIX); - } - } else if (mpUnfixString->getInputStringLength()) { - mpUnfixString->startConverting(); - updateCandidateState_(); - moveCandidateToIdx(0); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onCommand(static_cast(47), NULL); - } - } else if (current == mpString) { - if (meLanguage == KR && !getCurrentString(false)->isKanaFix()) { - mpString->getCursorPos(); - mpString->inputChar(L'\n'); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } - if (current->hasCandidate() || !current->isKanaFix()) return; - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); - updateCandidateState_(); - if (mpUnfixString->getCandidate() != L' ') { - moveCursorUp(); - onCommand(static_cast(47), NULL); - } - } -} - -void Base::onPressDown() { - tistring::Decolated* current = getCurrentString(false); - if (mpZiString == current) return; - if (mpUnfixString == current) { - if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); - if (mpUnfixString->isConverting()) { - if (!mpManager->getCandidateBox()->isInScroll()) { - tistring::Decolated* active = getCurrentString(false); - if (active == mpUnfixString) { - s32 selected = static_cast(mpUnfixString->getSelectedConverting() + 1); - if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; - else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - } - onSE(sound::SE_CHAR_CURSOR_FIX); - } - } else if (mpUnfixString->getInputStringLength()) { - mpUnfixString->startConverting(); - updateCandidateState_(); - moveCandidateToIdx(0); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onCommand(static_cast(47), NULL); - } - } else if (current == mpString) { - if (meLanguage == KR && !getCurrentString(false)->isKanaFix()) { - mpString->getCursorPos(); - mpString->inputChar(L'\n'); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } - if (current->hasCandidate() || !current->isKanaFix()) return; - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); - updateCandidateState_(); - if (mpUnfixString->getCandidate() != L' ') { - moveCursorDown(); - onCommand(static_cast(47), NULL); - } - } -} - -void Base::onPressDownHWKB() { - s32 selected; - tistring::Decolated* current = getCurrentString(false); - u32 modifiers = input::HKBManager::getInstance().GetModifierState(); - if (current == mpString) { - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); - updateCandidateState_(); - if (meLanguage == KR && !getCurrentString(false)->isKanaFix()) { - mpString->getCursorPos(); - mpString->inputChar(L'\n'); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } - if (current->hasCandidate() || !current->isKanaFix()) return; - if (mpUnfixString->getCandidate() == L' ') return; - moveCursorDown(); - onCommand(static_cast(47), NULL); - - } else if (mpUnfixString == current) { - if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); - if (mpUnfixString->isConverting()) { - if (modifiers & 2) { - mpUnfixString->commitPredicted(mpUnfixString->getSelectedConverting()); - updateCandidateState_(); - } else { - if (!mpManager->getCandidateBox()->isInScroll()) { - tistring::Decolated* active = getCurrentString(false); - if (active == mpUnfixString) { - selected = static_cast(mpUnfixString->getSelectedConverting() + 1); - if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; - else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - } - onSE(sound::SE_CHAR_CURSOR_FIX); - } - } - } else { - if (mpUnfixString->getInputStringLength()) { - mpUnfixString->startConverting(); - updateCandidateState_(); - moveCandidateToIdx(0); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onCommand(static_cast(47), NULL); - } - } - } - else if (mpZiString == current) { - return; - } -} - -void Base::onPressLeftHWKB() { - tistring::Decolated* current = getCurrentString(false); - input::HKBManager::getInstance().GetModifierState(); - current->getCursorPos(); - if (current == mpString) { - if (meLanguage == KR) { - if (!getCurrentString(false)->isKanaFix()) { - mpString->getCursorPos(); - mpString->inputChar(L'\n'); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } - current->getCursorPos(); - } - if (current->hasCandidate() || !current->isKanaFix()) return; - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); - updateCandidateState_(); - if (current->moveCursorLeft()) onSE(sound::SE_CHAR_CURSOR); - else onSE(sound::SE_CHAR_CURSOR_FIX); - } else if (current == mpUnfixString) { - if (mpManager->getCandidateBox()->isInScroll()) return; - if (mpUnfixString->getCurrentNumPredicted() <= 0) return; - if (mpUnfixString->isConverting()) { - onPressLeft(); - return; - } - s32 selected = static_cast(mpUnfixString->getSelectedCandidate() - 1); - if (selected < -1) selected = 0; - else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onSE(sound::SE_CHAR_CURSOR_FIX); - } else if (current == mpZiString) { - if (mpManager->getCandidateBox()->isInScroll()) return; - bool selectedAlready = mbZuSelected; - mbZuSelected = true; - if (mpZiString->getCurrentNumPredicted() < 0) return; - s32 selected = mpZiString->getSelectedCandidateIndex(); - if (selectedAlready) --selected; - if (selected < 0) selected = mpZiString->getCurrentNumPredicted() - 1; - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onSE(sound::SE_CHAR_CURSOR_FIX); - } - meScrollFlag = SF_ScrollOn; -} - -void Base::onPressRightHWKB() { - tistring::Decolated* current = getCurrentString(false); - input::HKBManager::getInstance().GetModifierState(); - current->getCursorPos(); - if (current == mpString) { - if (meLanguage == KR) { - if (!getCurrentString(false)->isKanaFix()) { - mpString->getCursorPos(); - mpString->inputChar(L'\n'); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } - current->getCursorPos(); - } - if (current->hasCandidate() || !current->isKanaFix()) return; - mpManager->getHWKeyboard()->resetQuoteState(); - mpUnfixString->resetRelation(); - updateCandidateState_(); - if (current->moveCursorRight()) onSE(sound::SE_CHAR_CURSOR_FIX); - else onSE(sound::SE_CHAR_CURSOR); - } else if (current == mpUnfixString) { - if (mpManager->getCandidateBox()->isInScroll()) return; - if (mpUnfixString->getCurrentNumPredicted() <= 0) return; - if (mpUnfixString->isConverting()) { - current->moveCursorRight(); - onSE(sound::SE_CHAR_CURSOR_FIX); - updateCandidateState_(); - } else { - s32 selected = static_cast(mpUnfixString->getSelectedCandidate() + 1); - if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onSE(sound::SE_CHAR_CURSOR_FIX); - } - } else if (current == mpZiString) { - if (mpManager->getCandidateBox()->isInScroll()) return; - bool selectedAlready = mbZuSelected; - mbZuSelected = true; - if (mpZiString->getCurrentNumPredicted() < 0) return; - s32 selected = mpZiString->getSelectedCandidateIndex(); - if (selectedAlready) ++selected; - if (selected >= mpZiString->getCurrentNumPredicted()) selected = 0; - if (selected < 0) selected = 0; - moveCandidateToIdx(selected); - mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); - onSE(sound::SE_CHAR_CURSOR_FIX); - } - meScrollFlag = SF_ScrollOn; -} - -void Base::onPressLeft() { - tistring::Decolated* current = getCurrentString(false); - current->getCursorPos(); - if (current == mpString) { - if (meLanguage == KR) { - if (!getCurrentString(false)->isKanaFix()) { - mpString->getCursorPos(); - mpString->inputChar(L'\n'); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } - current->getCursorPos(); - } - if (current->hasCandidate() || !current->isKanaFix()) return; - resetInputRelation(); - if (mpUnfixString->getCandidate() == L' ') return; - } - if (current->moveCursorLeft()) onSE(sound::SE_CHAR_CURSOR); - else onSE(sound::SE_CHAR_CURSOR_FIX); - if (current == mpUnfixString) updateCandidateState_(); - meScrollFlag = SF_ScrollOn; -} - -void Base::onPressRight() { - tistring::Decolated* current = getCurrentString(false); - current->getCursorPos(); - if (current == mpString) { - if (meLanguage == KR) { - if (!getCurrentString(false)->isKanaFix()) { - mpString->getCursorPos(); - mpString->inputChar(L'\n'); - mpString->getCursorPos(); - if (meLanguage == CN) { - bool predictions; - if (!mbPredictOn) predictions = false; - else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; - else predictions = false; - if (predictions) { - mpZiString->setCurrentWord(NULL); - mpZiString->update(); - } - } - } - current->getCursorPos(); - } - if (current->hasCandidate() || !current->isKanaFix()) return; - resetInputRelation(); - if (mpUnfixString->getCandidate() == L' ') return; - } - if (current->moveCursorRight() && mbRightWithSpace) { - CharacterInput space = {L' ', 0, false, false, 0}; - onCommand(static_cast(0), &space); - onSE(sound::SE_CHAR_CURSOR); - } - if (current == mpZiString || current == mpUnfixString) onSE(sound::SE_CHAR_CURSOR_FIX); - else onSE(sound::SE_CHAR_CURSOR); - if (current == mpUnfixString) updateCandidateState_(); - meScrollFlag = SF_ScrollOn; -} - -inline f32 nextColorPhase(f32 phase) { phase += 2.0f; return phase; } -inline f32 colorSine(f32 phase) { return nw4r::math::SinFIdx(phase * 0.7111111f); } -void Base::calc() { - if (mScrollAnm.isActive()) { - f32 scroll = mScrollAnm.getValue(); - mfScrollY = scroll; - mfDrawScrollY = mfScrollY; - } - if (!mScrollAnm.isActive()) autoScroll(); - if (!mpString->isOnSustain()) mfSustainTimer = 1.0f + mfSustainTimer; - mScrollAnm.calc(); - f32 wave = colorSine(sfColorPhase); - mSelectedColor.r = 2; - mSelectedColor.g = 90; - mSelectedColor.b = 253; - mSelectedColor.a = static_cast(150.0f + 30.0f * wave); - if (mpString->isOnSustain()) { - mSelectedColor.r = 52; - mSelectedColor.g = 140; - mSelectedColor.b = 253; - mSelectedColor.a = static_cast(50.0f + 10.0f * wave); - } else if (mfSustainTimer <= 50.0f) { - mSelectedColor.r = static_cast(util::hermiteInterporation(mfSustainTimer, 0.0f, 52.0f, 0.0f, 50.0f, 2.0f, 0.0f)); - mSelectedColor.g = static_cast(util::hermiteInterporation(mfSustainTimer, 0.0f, 140.0f, 0.0f, 50.0f, 90.0f, 0.0f)); - u8 blue = static_cast(util::hermiteInterporation(mfSustainTimer, 0.0f, 253.0f, 0.0f, 50.0f, 253.0f, 0.0f)); - f32 phase = sfColorPhase; - f32 angle = phase * 0.7111111f; - mSelectedColor.b = blue; - wave = nw4r::math::SinFIdx(angle); - f32 alpha = util::hermiteInterporation(mfSustainTimer, 0.0f, 50.0f, 0.0f, 50.0f, 150.0f, 0.0f); - mSelectedColor.a = static_cast(alpha + 20.0f * wave); - } - u32 cursorTimer = muCursorTimer + 8; - f32 phase = sfColorPhase; - muCursorTimer = cursorTimer; - sfColorPhase = nextColorPhase(phase); -} - -Base::RowInfoManager::~RowInfoManager() { - MEMFreeToAllocator(mpAllocator, mpInfo); -} - -Base::~Base() {} - -Base::Base(Manager* manager) : CommandReceiver(), textdrawer::Base(), candidatebox::CandidateBoxCaller(), - mpString(NULL), mpUnfixString(NULL), mpZiString(NULL), meInputMode(IM_Direct), mePredictMode(PM_USEn), - mbPredictOn(false), mbDoWordWrap(true), mbRightWithSpace(true), mfCursorX(0.0f), mfCursorY(0.0f), - mfScrollX(0.0f), mfScrollY(0.0f), mScrollAnm(), mfSustainTimer(0.0f), meScrollFlag(SF_NoScroll), - muWordWrapCounter(0), muLimitStringLength(1024), muLimitRowNum(9999), mfCursorTimer(0.0f), muGlobalAlpha(255), - mCharColor(0xffffffff), mpAllocator(NULL), mpManager(manager), mDKStream(), meLanguage(USA), - mbZuSelected(false), mbCursorSelected(false), mriManager(muLimitStringLength), mpCursorLine(NULL), - mCursorLinePos(0), mbLineDraw(true), muSpecifyLineDrawCount(0), muCursorTimer(0) { -} - - - - - - - - - - - - - -} - -void Base::init() {} - -namespace inputform { - - - - - - - - - - - - - - - - - - - -} - -int textdrawer::Base::getLine() { - return muLine + 1; -} - -namespace inputform { - - - - - - - - - - - - -} - -bool textinput::util::Animation::isActive() { - return mbInAnimation; -} - -namespace inputform { -} - -wchar_t* tistring::Decolated::getKanaBuffer() { - return mKanaStream.mOutput; -} - -namespace inputform { - - - - - -} - -bool tistring::StringBase::hasCandidate() const { - return mwcCandidate != 0; -} - -namespace inputform { - - - - - - - - -void Base::create(MEMAllocator*) {} - -} - -void textdrawer::Base::setVIWidth(f32 width) { - mfVIWidth = width; -} - -namespace inputform { - - - -} - -void textinput::util::Animation::stop() { - mbInAnimation = false; -} - -namespace inputform { -} - -bool textinput::util::Animation::isSEFlag() { - return mbSE; -} - -namespace inputform { -} - -void textinput::util::Animation::setSEFlag(bool flag) { - mbSE = flag; -} - -namespace inputform { -} - -f32 textinput::util::Animation::getValue() { - return hermiteInterporation(mfCurrentFrame, 0.0f, mfStartPoint, 0.0f, mfAnimationTime, mfEndPoint, 0.0f); -} - -namespace inputform { - -void LayoutByNW4R::onSE(sound::SE seId) { - mpEventObserver->onSE(seId); -} -} - -void CommandReceiver::addSender(CommandSender* sender) { - nw4r::ut::List_Append(&mSenderList, sender); -} - -namespace inputform { -} - -bool candidatebox::LayoutByNW4R::isInScroll() { - return mTextArea.IsScrolling(); -} - -namespace inputform { -} - -tistring::Decolated::~Decolated() {} - -namespace inputform { -} - -tistring::WithAtok::~WithAtok() {} - -namespace inputform { -} - -CommandReceiver::~CommandReceiver() {} - -namespace inputform { -} - -bool tistring::Decolated::isKanaFix() const { - if (static_cast(mTranslateMode) == TM_Hangul) return true; - return KPRLookAhead(const_cast(&mKanaStream.mQueue), NULL, NULL) == 0; -} - -namespace inputform { -} - -void textinput::util::Animation::calc() { - if (mbInAnimation) { - if (mfCurrentFrame < mfAnimationTime) { - mfCurrentFrame = 1.0f + mfCurrentFrame; - } else { - if (mbInAnimation && mpAnimObserver) { - mpAnimObserver->onAnmEvent(AnimObserver::AE_1, mpData); - } - mbInAnimation = false; - } - } -} - -bool textdrawer::Base::isEnableCursorCache() const { - return mbCursorCache; -} - -u32 textdrawer::Base::getStartPos() const { - return muDrawStartPos; -} - -namespace inputform { -} - -void tistring::Decolated::set(const wchar_t* string) { - StringBase::set(string); - u32 length = getLength(); - mCursorStart = length; - mCursorEnd = length; -} - -namespace inputform { -} - -void tistring::Decolated::clear() { - StringBase::clear(); - mCursorStart = 0; - mCursorEnd = 0; - mbSustain = false; - initKanaConverter(); -} - -namespace inputform { -inline u16 initializeRowLinks(Base::Info_* const& rows, const u16& capacity) { - for (u16 index = 0; index < capacity; ++index) { - Base::Info_* row = &rows[index]; - row->Back = index - 1; - row->Next = index + 1; - row->StrCount = 0; - row->DispRowCount = 0; - } - return capacity; -} -void Base::RowInfoManager::init() { - u16 capacity = initializeRowLinks(mpInfo, mMaxLength); - Info_* freeHead = &mpInfo[mMaxLength]; - u16 last = capacity - 1; - freeHead->Back = last; - freeHead->Next = 0; - Info_* rows = mpInfo; - rows[last].Next = mMaxLength; - rows[0].Back = mMaxLength; - u16 activeIndex = mMaxLength + 1; - Info_* activeHead = &mpInfo[activeIndex]; - activeHead->Back = activeIndex; - activeHead->Next = mMaxLength + 1; -} -nw4r::math::VEC2 LayoutByNW4R::getScale() const { - return mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true)->GetScale(); -} -LayoutByNW4R::~LayoutByNW4R() { - if (mpInputEventHandler) { - mpInputEventHandler->~TiEventHandler(); - MEMFreeToAllocator(mpAllocator, mpInputEventHandler); - } - nw4rmanager::AnmPane* pane = static_cast(nw4r::ut::List_GetNext(&mAnmPanes, NULL)); - while (pane) { - nw4r::ut::List_Remove(&mAnmPanes, pane); - pane->destroy(mpAllocator); - pane = static_cast(nw4r::ut::List_GetNext(&mAnmPanes, NULL)); - } -} - -void EditBuffer::create(MEMAllocator* allocator) { - mpAllocator = allocator; - void* memory = MEMAllocFromAllocator(allocator, sizeof(tistring::Decolated)); - tistring::Decolated* fixed = static_cast(memory); - fixed = new (memory) tistring::Decolated(1024); - mpString = fixed; - fixed->create(allocator); - memory = MEMAllocFromAllocator(allocator, sizeof(tistring::WithAtok)); - tistring::WithAtok* atok = static_cast(memory); - atok = new (memory) tistring::WithAtok(1024); - mpUnfixString = atok; - atok->create(allocator); - memory = MEMAllocFromAllocator(allocator, sizeof(tistring::WithZi)); - tistring::WithZi* zi = static_cast(memory); - zi = new (memory) tistring::WithZi(1024); - mpZiString = zi; - zi->create(allocator); -} -EditBuffer::~EditBuffer() { - if (mpString) { - static_cast(mpString)->~Decolated(); - MEMFreeToAllocator(mpAllocator, mpString); - } - if (mpUnfixString) { - static_cast(mpUnfixString)->~WithAtok(); - MEMFreeToAllocator(mpAllocator, mpUnfixString); - } - if (mpZiString) { - static_cast(mpZiString)->~WithZi(); - MEMFreeToAllocator(mpAllocator, mpZiString); - } - mpString = NULL; - mpUnfixString = NULL; - mpZiString = NULL; -} -void LayoutByNW4R::updateInputCommon(int chan, u32 trig, u32 hold, u32 release, void* data) { - updateRepeatInput(trig, hold); - if (mRepeatButtons & WPAD_BUTTON_MINUS) onCommand(static_cast(1), NULL); -} -void LayoutByNW4R::updateRepeatInput(u32 trig, u32 hold) { - mRepeatButtons = trig; - if (hold & WPAD_BUTTON_LEFT) { - if (--mLeftRepeat == 0) { - mRepeatButtons |= WPAD_BUTTON_LEFT; - mLeftRepeat = 9; - } - } else mLeftRepeat = 30; - if (hold & WPAD_BUTTON_RIGHT) { - if (--mRightRepeat == 0) { - trig = mRepeatButtons; - mRightRepeat = 9; - mRepeatButtons = trig | WPAD_BUTTON_RIGHT; - } - } else mRightRepeat = 30; - if (hold & WPAD_BUTTON_UP) { - if (--mUpRepeat == 0) { - trig = mRepeatButtons; - mUpRepeat = 9; - mRepeatButtons = trig | WPAD_BUTTON_UP; - } - } else mUpRepeat = 30; - if (hold & WPAD_BUTTON_DOWN) { - if (--mDownRepeat == 0) { - trig = mRepeatButtons; - mDownRepeat = 9; - mRepeatButtons = trig | WPAD_BUTTON_DOWN; - } - } else mDownRepeat = 30; - if (hold & WPAD_BUTTON_MINUS) { - if (--mDeleteRepeat == 0) { - trig = mRepeatButtons; - mDeleteRepeat = 9; - mRepeatButtons = trig | WPAD_BUTTON_MINUS; - } - } else mDeleteRepeat = 30; -} -wchar_t DeadKeyStream::ToCombineClass(Language language, wchar_t code) { - switch (language) { - case DE: - if (code == 0xb4) return 0x301; - if (code == 0x60) return 0x300; - break; - case FR: - if (code == 0x5e) return 0x302; - if (code == 0xa8) return 0x308; - break; - case SP: - if (code == 0x60) return 0x300; - if (code == 0xb4) return 0x301; - if (code == 0x5e) return 0x302; - if (code == 0x7e) return 0x303; - if (code == 0xa8) return 0x308; - break; - case NL: - if (code == 0x60) return 0x300; - if (code == 0x5e) return 0x302; - if (code == 0x7e) return 0x303; - if (code == 0x27) return 0x30d; - if (code == 0x22) return 0x30e; - break; - } - return code; -} -} -void gui::GUIComponent::init() { - if (mbInitialize) return; - for (int point = 0; point < GUI_POINTS_MAX; ++point) { - mbPointed[point] = false; - mDraggingPos[point].x = 0.0f; - mDraggingPos[point].y = 0.0f; - mDraggingPos[point].z = 0.0f; - mbDragging[point] = false; - mFlightDuration[point] = 0; - } -} -namespace inputform { - -bool Base::isEditMode() { - switch (mePredictMode) { - case PM_Off: - case PM_Atok: - break; - default: - if (!mpZiString->isFix()) return false; - break; - } - return true; -} - -bool Base::checkHeadOfSentence(bool checkSpace) { - bool externallyHandled; - onCommand(static_cast(32), &externallyHandled); - if (externallyHandled) return false; - bool moved = false; - if (mpString->getCursorPos() < 1) return true; - if (checkSpace) { - switch (mpString->getWCharAtCursor()) { - case L' ': - case L'\n': - break; - default: - return false; - } - moved = mpString->moveCursorLeft(); - } - bool beginning = mpString->atTheBeginningOfASentence(); - if (moved) mpString->moveCursorRight(); - return beginning; -} - -void Base::setLineDrawInfo(bool lineDraw, u32 lineCount) { - mbLineDraw = lineDraw; - muSpecifyLineDrawCount = lineCount; -} - -void Base::doWordWrap(bool wordWrap) { - mbDoWordWrap = wordWrap; -} - -void Base::limitStringLength(u32 limitStringLength) { - muLimitStringLength = limitStringLength; -} - -void Base::setAtokDictionary(void* atok, int atokSize, void* apot, int apotSize, void* nintendo, int nintendoSize) { - mpUnfixString->openDictionary(atok, atokSize, apot, apotSize, nintendo, nintendoSize); -} - -void Base::setCursorPos(tistring::Decolated* string, u32 pos) { - string->setCursorPos(pos); -} - -void Base::closeAtokDictionary() { - mpUnfixString->closeDictionary(); -} - -bool Base::isAtokDictionaryOpened() { - return mpUnfixString->isDictionaryOpened(); -} - -void Base::limitRowNum(u32 limitRowNum) { - muLimitRowNum = limitRowNum; - if (limitRowNum == 1) { - doWordWrap(false); - } -} - -void Base::makeUpCursorPos(CursorPos* cursorPos, u32 pos, s32 startLine, s32 endLine) { + bool characterWrap; + const wchar_t* stringPtr = string; + u32 current; u32 wordWrapCounter = muWordWrapCounter; - muWordWrapCounter = pos; - textdrawer::Base::makeUpCursorPos(cursorPos, pos, startLine, endLine); - muWordWrapCounter = wordWrapCounter; -} - -void Base::setFont(const nw4r::ut::Font& font) { - textdrawer::Base::setFont(font); -} - -void Base::clear() { - init(); - mpString->clear(); -} - -u32 Base::isOverRowLimit(u32 limit, const wchar_t* string) { - const wchar_t* current; - u32 rows; - bool kanaHandled; - bool kana; - const wchar_t* character; - u32 pos; - f32 cursorX; - u32 cursorStart; - u32 cursorEnd; - current = string; - if (!*string) return 0; - cursorX = getScale().x; - nw4r::math::VEC2 scale = getScale(); - pos = 0; - rows = 0; - muWordWrapCounter = 0; - kanaHandled = false; - mbHyphen = false; - mpString->getCursorPos(&cursorStart, &cursorEnd); - for (;;) { - DrawInfo info; - info.rect.left = 0.0f; - info.rect.top = 0.0f; - info.rect.right = 0.0f; - info.rect.bottom = 0.0f; - kana = false; - if (meLanguage == KR && !kanaHandled && cursorStart == pos) { - kanaHandled = true; - character = mpString->getKanaBuffer(); - if (*character) kana = true; - } - if (!kana) { - if (!*current) break; - character = current; - } - info.character = *character; - calcRect(info); - f32 right = cursorX + scale.x * info.rect.GetWidth(); - if (kana) { - if (right >= scale.x * mRect.GetWidth()) { - cursorX = getScale().x; - ++rows; - if (rows >= limit) return pos; - } else { - cursorX = right; - } - continue; - } - if (doWordWrap(string, pos, cursorX)) { - ++rows; - if (rows >= limit) { - while (pos < muWordWrapCounter) { - f32 advance; - f32 nextCursorX; - advance = scale.x * info.rect.GetWidth(); - nextCursorX = cursorX + advance; - if (nextCursorX >= scale.x * mRect.GetWidth()) return pos; - ++current; - cursorX += advance; - info.character = *current; - calcRect(info); - ++pos; - } - return muWordWrapCounter - 1; - } - cursorX = getScale().x; - } else if (right >= scale.x * mRect.GetWidth()) { - cursorX = getScale().x; - ++rows; - if (rows >= limit) return pos; - } - if (*current == L'\n') { - cursorX = getScale().x; - ++rows; - if (rows >= limit) return pos; - if (!current[1]) return 0; - } else { - cursorX += scale.x * info.rect.GetWidth(); - } - ++pos; - ++current; + if (pos < wordWrapCounter) { + return false; } - return 0; + + s32 hyphenType = 0; + if (wordWrapCounter != 0 && getDrawCacheStartPos() != wordWrapCounter) { + wchar_t previous = stringPtr[wordWrapCounter - 1]; + if (previous == L'-') { + hyphenType = 1; + } else if (previous != L' ') { + hyphenType = 2; + } + } + + f32 stringWidth = 0.0f; + f32 zero = stringWidth; + u32 index; + u32 hyphenPos; + bool wrap; + hyphenPos = 0; + current = muWordWrapCounter; + wrap = false; + index = current; + stringPtr = string + current; + do { + if (*stringPtr == L' ' || *stringPtr == L'\n') { + break; + } + WordWrapDrawInfo drawInfo; + drawInfo.left = 0.0f; + drawInfo.top = 0.0f; + drawInfo.right = 0.0f; + drawInfo.bottom = 0.0f; + drawInfo.character = *stringPtr; + calcRect(reinterpret_cast(drawInfo)); + characterWrap = false; + stringWidth += drawInfo.right - drawInfo.left; + + if (width != getScale().x) { + if (width + stringWidth * getScale().x >= getWordWrapRectWidth() * getScale().x) { + characterWrap = true; + } + } + if (characterWrap) { + wrap = true; + } + + if (index != current && *stringPtr == L'-') { + hyphenPos = index; + mbHyphen = true; + } + + ++stringPtr; + ++index; + } while (*stringPtr != L'\0'); + + if (index == current) { + mbHyphen = false; + } + + if (stringWidth * getScale().x >= getWordWrapRectWidth() * getScale().x) { + wrap = false; + if (mbHyphen) { + wrap = true; + } + if (hyphenType == 1) { + wrap = true; + } + } + + if (wrap) { + if (!findURL(0, 0, string, current, index)) { + if (hyphenPos == 0) { + mbHyphen = false; + ++index; + muWordWrapCounter = index; + return true; + } + + index = hyphenPos; + } + } else { + mbHyphen = false; + } + + ++index; + muWordWrapCounter = index; + return false; +} + +bool Base::isOverLine(const DrawInfo& drawInfo) { + return GetCursorX() + drawInfo.rect.GetWidth() * getScale().x >= mRect.GetWidth() * getScale().x; +} + +void Base::doBeforeDrawProcess(const wchar_t* string, u32 position, const DrawInfo& info) { + f32 cursorX = GetCursorX(); + if (doWordWrap(string, position, cursorX)) doLineFeed(); + if (isOverLine(info)) { + ++muLine; + f32 height = getLineHeight(); + f32 cursorY = GetCursorY(); + SetCursorY(cursorY + height); + SetCursorX(getScale().x); + } + u32 start, end; + mpString->getSelected(start, end); + if (position >= start && position < end) { + f32 left = info.rect.left + GetCursorX(); + f32 top = info.rect.top + GetCursorY(); + f32 right = info.rect.right + GetCursorX(); + f32 bottom = info.rect.bottom + GetCursorY(); + debug::drawBox_(left, top, right, bottom, 0.0f, 1.0f, mSelectedColor); + } +} + +void Base::doLineFeed() { + ++muLine; + f32 height = getLineHeight(); + f32 cursorY = GetCursorY(); + SetCursorY(cursorY + height); + SetCursorX(getScale().x); } bool Base::onCursor(CursorPos* cursor) { @@ -3135,14 +1808,22 @@ bool Base::onCursor(CursorPos* cursor) { return positioned; } -static inline f32 scaledExtent(f32 scale, f32 start, f32 end) { - f32 extent = end - start; - return scale * extent; +u32 Base::getCursorPos() { + u32 fixedStart, unfixedStart, end; + mpString->getCursorPos(&fixedStart, &end); + mpUnfixString->getCursorPos(&unfixedStart, &end); + return fixedStart + unfixedStart; } -static inline f32 glyphBottom(f32 origin, const Base::DrawInfo& glyph, const nw4r::math::VEC2& scale) { - f32 extent = glyph.rect.GetHeight(); - return origin + scale.y * extent; +void Base::drawCursor(f32 x, f32 y) { + f32 opacity = static_cast(muGlobalAlpha) / 255.0f; + mfCursorX = x; + mfCursorY = y; + GXColor color = {255, 50, 50, 0}; + f32 pulse = nw4r::math::SinFIdx(0.7111111f * muCursorTimer); + color.a = static_cast(opacity * (127.0f + 127.0f * pulse)); + f32 width = mfViewWidth - mfViewX; + debug::drawLine_(mfCursorX, 2.0f + mfCursorY, mfCursorX, (mfCursorY + GetFontHeight()) - 2.0f, 0.0f, static_cast(14592.0f / width), color); } u32 Base::calcCursorPos(f32 x, f32 y) { @@ -3221,171 +1902,6 @@ nw4r::math::VEC2 Base::getGlobalLeftTopPos() const { return nw4r::math::VEC2(position.x, -position.y); } -void Base::doAfterDrawProcess(const wchar_t*, u32, const DrawInfo&) {} - -void Base::preDraw(u32 pos) { - muWordWrapCounter = pos; - mbHyphen = false; -} - -bool Base::doWordWrap(const wchar_t* string, u32 pos, f32 width) { - struct WordWrapDrawInfo { - f32 left; - f32 top; - f32 right; - f32 bottom; - u16 character; - }; - - if (!mbDoWordWrap) { - return false; - } - - bool characterWrap; - const wchar_t* stringPtr = string; - u32 current; - u32 wordWrapCounter = muWordWrapCounter; - if (pos < wordWrapCounter) { - return false; - } - - s32 hyphenType = 0; - if (wordWrapCounter != 0 && getDrawCacheStartPos() != wordWrapCounter) { - wchar_t previous = stringPtr[wordWrapCounter - 1]; - if (previous == L'-') { - hyphenType = 1; - } else if (previous != L' ') { - hyphenType = 2; - } - } - - f32 stringWidth = 0.0f; - f32 zero = stringWidth; - u32 index; - u32 hyphenPos; - bool wrap; - hyphenPos = 0; - current = muWordWrapCounter; - wrap = false; - index = current; - stringPtr = string + current; - do { - if (*stringPtr == L' ' || *stringPtr == L'\n') { - break; - } - WordWrapDrawInfo drawInfo; - drawInfo.left = 0.0f; - drawInfo.top = 0.0f; - drawInfo.right = 0.0f; - drawInfo.bottom = 0.0f; - drawInfo.character = *stringPtr; - calcRect(reinterpret_cast(drawInfo)); - characterWrap = false; - stringWidth += drawInfo.right - drawInfo.left; - - if (width != getScale().x) { - if (width + stringWidth * getScale().x >= getWordWrapRectWidth() * getScale().x) { - characterWrap = true; - } - } - if (characterWrap) { - wrap = true; - } - - if (index != current && *stringPtr == L'-') { - hyphenPos = index; - mbHyphen = true; - } - - ++stringPtr; - ++index; - } while (*stringPtr != L'\0'); - - if (index == current) { - mbHyphen = false; - } - - if (stringWidth * getScale().x >= getWordWrapRectWidth() * getScale().x) { - wrap = false; - if (mbHyphen) { - wrap = true; - } - if (hyphenType == 1) { - wrap = true; - } - } - - if (wrap) { - if (!findURL(0, 0, string, current, index)) { - if (hyphenPos == 0) { - mbHyphen = false; - ++index; - muWordWrapCounter = index; - return true; - } - - index = hyphenPos; - } - } else { - mbHyphen = false; - } - - ++index; - muWordWrapCounter = index; - return false; -} - -void Base::doLineFeed() { - ++muLine; - f32 height = getLineHeight(); - f32 cursorY = GetCursorY(); - SetCursorY(cursorY + height); - SetCursorX(getScale().x); -} - -bool Base::isOverLine(const DrawInfo& drawInfo) { - return GetCursorX() + drawInfo.rect.GetWidth() * getScale().x >= mRect.GetWidth() * getScale().x; -} - -void Base::drawFixString(u32 position) { - CursorPos cursor; - cursor.fCursorX = 0.0f; - cursor.fCursorY = 0.0f; - cursor.uCursorPos = position; - mCharColor.a = muGlobalAlpha; - SetTextColor(mCharColor); - u32 length = mpString->getLength(); - textdrawer::Base::setDrawString(mpString->getWCString(), 0, length); - textdrawer::Base::draw(&cursor); - drawCursor(cursor.fCursorX, cursor.fCursorY); -} - -void Base::draw() { - SetCursor(getScale().x, mfScrollY); - nw4r::math::VEC2 scale = getScale(); - nw4r::ut::Rect clip(0.0f, 0.0f, 0.0f, 0.0f); - nw4r::math::VEC2 origin = getGlobalLeftTopPos(); - clip.left = origin.x; - clip.bottom = origin.y; - clip.right = origin.x + scale.x * (mRect.right - mRect.left); - clip.top = origin.y + scale.y * (mRect.top - mRect.bottom); - u32 position = mpString->getCursorPos(); - beginDraw(clip); - drawFixString(position); - endDraw(); -} - -void Base::drawCursor(f32 x, f32 y) { - f32 opacity = static_cast(muGlobalAlpha) / 255.0f; - mfCursorX = x; - mfCursorY = y; - GXColor color = {scInputFormColorRU8, scInputFormColorGU8, scInputFormColorBU8, scInputFormColorAU8}; - f32 pulse = nw4r::math::SinFIdx(0.7111111f * muCursorTimer); - color.a = static_cast(opacity * (127.0f + 127.0f * pulse)); - f32 width = mfViewWidth - mfViewX; - debug::drawLine_(mfCursorX, 2.0f + mfCursorY, mfCursorX, (mfCursorY + GetFontHeight()) - 2.0f, 0.0f, static_cast(14592.0f / width), color); -} - void Base::doScroll(Scroll* scroll) { if (mScrollAnm.isActive()) return; if (scroll->absY) { @@ -3399,33 +1915,260 @@ void Base::doScroll(Scroll* scroll) { onSE(sound::SE_LINE_SCROLL); } -void Base::doBeforeDrawProcess(const wchar_t* string, u32 position, const DrawInfo& info) { - f32 cursorX = GetCursorX(); - if (doWordWrap(string, position, cursorX)) doLineFeed(); - if (isOverLine(info)) { - ++muLine; - f32 height = getLineHeight(); - f32 cursorY = GetCursorY(); - SetCursorY(cursorY + height); - SetCursorX(getScale().x); +void Base::autoScroll() { + if (mScrollAnm.isActive()) return; + if (u32(meScrollFlag - SF_ScrollOn) > 1) return; + f32 cursorY = mfCursorY + getLineHeight() / 2.0f; + if (cursorY < 0.0f) { + s32 lines = s32(cursorY / getLineHeight() - 1.0f); + mScrollAnm.startAnm(mfScrollY, mfScrollY - lines * getLineHeight(), 15.0f, NULL, NULL); + onSE(sound::SE_LINE_SCROLL); } - u32 start, end; - mpString->getSelected(start, end); - if (position >= start && position < end) { - f32 left = info.rect.left + GetCursorX(); - f32 top = info.rect.top + GetCursorY(); - f32 right = info.rect.right + GetCursorX(); - f32 bottom = info.rect.bottom + GetCursorY(); - debug::drawBox_(left, top, right, bottom, 0.0f, 1.0f, mSelectedColor); + if (cursorY >= (mRect.top - mRect.bottom) * getScale().y) { + s32 lines = s32((cursorY - (mRect.top - mRect.bottom) * getScale().y) / getLineHeight()) + 1; + mScrollAnm.startAnm(mfScrollY, mfScrollY - lines * getLineHeight(), 15.0f, NULL, NULL); + onSE(sound::SE_LINE_SCROLL); + } + meScrollFlag = SF_NoScroll; +} + +void Base::setAtokDictionary(void* atok, int atokSize, void* apot, int apotSize, void* nintendo, int nintendoSize) { + mpUnfixString->openDictionary(atok, atokSize, apot, apotSize, nintendo, nintendoSize); +} + +void Base::closeAtokDictionary() { + mpUnfixString->closeDictionary(); +} + +void Base::confirmInput_() { + if (!mbPredictOn) { + if (!mpString->isKanaFix()) { + mpString->getCursorPos(); + mpString->confirmKana(); + mpString->getCursorPos(); + } + } else if (mePredictMode == PM_Atok) { + if (mpUnfixString->isCandidateSelected()) { + s32 selected = mpUnfixString->getSelectedCandidate(); + onCommand(static_cast(21), &selected); + } else { + mpUnfixString->confirm(NULL); + wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); + mpString->getCursorPos(); + mpString->confirm(confirmed); + mpString->getCursorPos(); + mpUnfixString->enableConfirmedString(false); + } + } else { + const wchar_t* selected = mpZiString->getCurrentSelected(); + if (mpZiString->getInputStringLength()) { + mpString->getCursorPos(); + mpString->inputString(selected); + mpString->getCursorPos(); + if (meLanguage == CN) mpZiString->setCurrentWord(selected); + } + mpZiString->clearCandidates(); + mbZuSelected = false; + if (meLanguage == CN) mpZiString->update(); } } -void Base::finishDraw(u32) {} +void Base::initZiString() { + mpZiString->clearCandidates(); + mbZuSelected = false; +} -void Base::onSE(sound::SE) {} +void Base::inputInputting_(wchar_t character) { + tistring::Decolated* current = getCurrentString(false); + if (static_cast(character + 0xcf65) <= 1) { + onCommand(static_cast(27), NULL); + } else if (mbPredictOn && mePredictMode == PM_Atok) { + if (mpUnfixString->isCandidateSelected()) onCommand(static_cast(6), NULL); + mpUnfixString->setInputting(character); + } else { + if (mbPredictOn && getPredictMode() == PM_11 && !mpManager->getCandidateBox()->isInvalid()) { + if (util::isAlphabet(character) || (character >= L'1' && character <= L'5')) { + mpZiString->setInputting(character); + } else { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions && mpZiString->getInputStringLength() != 0 && (meLanguage != CN || !mpZiString->hasCandidate())) confirmInput_(); + mpZiString->setInputting(character); + mpZiString->setSelectedCandidate(-1); + return; + } + } else { + current->setCandidate(character); + } + } + if (character != 0) onSE(sound::SE_CHAR_INPUT); + meScrollFlag = SF_ScrollOn; +} -void Base::setString(const wchar_t* string) { - mpString->set(string); +void Base::confirmInputting_(wchar_t character, bool direct, u16 letterMode, bool confirmOnly, void* holdingKey) { + tistring::Decolated* current = getCurrentString(true); + if (!character) return; + if (mbPredictOn && getPredictMode() == PM_11) { + if (!mpManager->getCandidateBox()->isInvalid() && !util::isAlphabet(character) && (character < L'1' || character > L'5')) { + mpString->getCursorPos(); + mpString->inputChar(character); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + if (meLanguage == CN) { + mpZiString->clearCandidates(); + mbZuSelected = false; + mpZiString->update(); + } else confirmInput_(); + return; + } + } + if (direct) { + mpString->getCursorPos(); + mpString->inputChar(character); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } else { + if (current == mpZiString) { + if (!mpZiString->getInputStringLength()) { + mpZiString->changeLetterMode(static_cast(letterMode)); + mpZiString->setCellPhoneHoldingkey(holdingKey); + } + if (mpZiString->getInputStringLength() >= 32) { + onCommand(static_cast(6), NULL); + mpZiString->changeLetterMode(static_cast(letterMode)); + mpZiString->inputChar(character); + onSE(sound::SE_CHAR_DECIDE); + updateCandidateState_(); + return; + } + } else if (current == mpUnfixString) { + if (confirmOnly && !mpUnfixString->hasCandidate()) return; + } else if (mbPredictOn && mePredictMode == PM_Atok && current != mpUnfixString && character == L' ') { + character = 0x3000; + mpUnfixString->setCandidate(0); + } + if (current == mpString) { + mpString->getCursorPos(); + mpString->inputChar(character); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } else { + current->inputChar(character); + if (meLanguage == KR && mpManager->getToolBar()->isQwerty()) { + wchar_t predicted[64]; + mpZiString->getPredicted(0, predicted); + if (wcslen(predicted) >= 2) { + predicted[1] = 0; + mpString->getCursorPos(); + mpString->inputString(predicted); + mpString->getCursorPos(); + mpZiString->partialConfirmForKR(); + } + } + } + onSE(sound::SE_CHAR_INPUT); + } +} + +void Base::inputCharZi_(wchar_t character, u32 modifiers) { + if (meLanguage != KR && (modifiers & 3)) character = util::toWLower(character); + bool direct = false; + if (character == L' ') direct = true; + if (meLanguage == CN) { + if (!util::isAlphabet(character) && (character < L'1' || character > L'5' || !mpZiString->getInputStringLength())) direct = true; + } else if (meLanguage == KR) { + if (util::isAlphabet(character)) { + if (getCurrentString(true) == mpZiString && (modifiers & 2)) character = util::reverseLetterCaseW(character); + } else direct = true; + } + if (direct) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) confirmInput_(); + mpString->getCursorPos(); + mpString->inputChar(character); + mpString->getCursorPos(); + if (meLanguage == CN) { + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + onSE(sound::SE_CHAR_DECIDE); + } else { + u16 letterMode; + switch (modifiers & 3) { + case 1: letterMode = 0; break; + case 2: letterMode = 2; break; + default: letterMode = 1; break; + } + confirmInputting_(character, false, letterMode, false, NULL); + } + meScrollFlag = SF_ScrollOn; +} + +void Base::inputCharDefault_(wchar_t character, u32 modifiers) { + tistring::WithAtok* unfix; + tistring::Decolated* current = getCurrentString(true); + unfix = mpUnfixString; + if (getCurrentString(false) == unfix && !unfix->isConverting() && mpUnfixString->getSelectedCandidate() >= 0) { + confirmInput_(); + } + if (meLanguage == KR && mpManager->getPCKeyboard()->getTranslateMode() != keyboard::pctype::Base::TM_00) { + if (util::isAlphabet(character) && (modifiers & 2)) character = util::reverseLetterCaseW(character); + } + if (mpString == current) { + mpString->getCursorPos(); + mpString->inputChar(character); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predicted; + if (!mbPredictOn) predicted = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predicted = true; + else predicted = false; + if (predicted) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } else current->inputChar(character); + if (character == L' ') onSE(sound::SE_CHAR_DECIDE); + else if (character != L'\n') onSE(sound::SE_CHAR_INPUT); + meScrollFlag = SF_ScrollOn; } void Base::onClose() { @@ -3435,24 +2178,1231 @@ void Base::onClose() { static_cast(*this).dirtyCursorCache(); } -void AnmPane::changeAnimation(u32 id) { - meState = static_cast(id); - nw4rmanager::AnmPane::changeAnimation(id); +tistring::Decolated* Base::getCurrentString(bool inputting) { + if (!mbPredictOn) return mpString; + if (meLanguage == KR) { + if (mpManager->getToolBar()->isQwerty()) { + if (mpManager->getPCKeyboard()->getTranslateMode() == 0) return mpString; + } else { + if (mpManager->getCellPhoneKeyboard()->getInputMode() != 0) return mpString; + } + } + if (meLanguage == CN) { + if (mpManager->getCandidateBox()->isInvalid() || !mpManager->getCandidateBox()->isActive()) return mpString; + } + switch (mePredictMode) { + case PM_Atok: + if (!mpUnfixString->isFix() || inputting) return mpUnfixString; + break; + default: + if (!mpZiString->isFix() || inputting) return mpZiString; + break; + } + return mpString; } -void AnmPane::init() { - meState = ANM_Normal; +bool Base::usesZiPrediction() const { + if (!mbPredictOn) return false; + if (mePredictMode == PM_Atok) return false; + if (meLanguage == CN && static_cast(mpManager)->getCandidateBox()->isInvalid()) return false; + return true; } -KeyType AnmPane::getKeyType() const { - return meKeyType; +bool Base::hasZiPredictions() const { + if (!mbPredictOn) return false; + if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) return true; + return false; } -Animation AnmPane::getState() { - return meState; +bool Base::isAtokActive() const { + u32 enabled = mbPredictOn; + if (enabled == 0) return false; + return mePredictMode == PM_Atok; } -NormalButtonAnmPane::~NormalButtonAnmPane() {} +void Base::onHKBCtrlCode(HVKCode code, u32 modifiers) { + tistring::Decolated* current = getCurrentString(false); + switch (code) { + case 2: + if (mePredictMode == PM_Atok) toggleAtokMode_(0); + break; + case 17: + if (mePredictMode == PM_Atok) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Kana) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Roman); + } else if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Roman) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); + } + toggleAtokMode_(1); + } else if (meLanguage == KR && !mpManager->getPCKeyboard()->isQwertyOnly() && mpManager->getPCKeyboard()->isLanguageKeyActive()) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); + } else { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); + } + } + break; + case 18: + if (mePredictMode == PM_Atok) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00 && !mbPredictOn) { + if (!mpManager->getPCKeyboard()->isQwertyOnly()) onSE(sound::SE_CHAR_CURSOR_FIX); + } else toggleAtokMode_(2); + } + break; + case 36: + if (mePredictMode == PM_Atok) toggleAtokMode_(0); + else if (static_cast(meLanguage) - CN <= 1) { + if (!mpManager->getPCKeyboard()->isQwertyOnly() && mpManager->getPCKeyboard()->isLanguageKeyActive()) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); + } else { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); + } + } + } else if (mePredictMode != PM_Off && mpManager->getCandidateBox()->isActive()) { + mpManager->startPredictTurnOn(!mbPredictOn); + } + break; + case 1: + if (current == mpUnfixString) updateCandidateState_(); + break; + case 9: + onCommand(static_cast(7), NULL); + onCommand(static_cast(39), NULL); + break; + case 8: + onSpaceKeyHWKB(modifiers); + break; + case 29: + onCommand(static_cast(44), NULL); + break; + case 30: + onCommand(static_cast(45), NULL); + break; + case 31: + onCommand(static_cast(42), NULL); + break; + case 32: + onCommand(static_cast(43), NULL); + break; + case 16: + if (mePredictMode == PM_Atok) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Kana) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Roman); + } else if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Roman) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); + } else if (!mpManager->getPCKeyboard()->isQwertyOnly()) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); + } + } + break; + } +} + +void Base::moveCursorUp() { + f32 y = mfCursorY; + if (-(mfCursorY - mfScrollY) >= 0.0f) { + u32 start, end; + mpString->getCursorPos(&start, &end); + if (start == 0 && end == 0) onSE(sound::SE_CHAR_CURSOR_FIX); + else onSE(sound::SE_CHAR_CURSOR); + mpString->setCursorPos(0); + } else { + y = mfCursorY >= 0.0f ? mfCursorY : 0.0f; + f32 lineHeight = getLineHeight(); + f32 targetY = 1.0f + (y - lineHeight); + u32 position = calcCursorPos(mfCursorX, targetY); + mpString->setCursorPos(position); + onSE(sound::SE_CHAR_CURSOR); + } + meScrollFlag = SF_ScrollOn; +} + +void Base::moveCursorDown() { + if (-(mfCursorY - mfScrollY) < mfMinScrollY) { + u32 start, end; + mpString->getCursorPos(&start, &end); + if (start == mpString->getLength() && end == mpString->getLength()) onSE(sound::SE_CHAR_CURSOR_FIX); + else onSE(sound::SE_CHAR_CURSOR); + mpString->setCursorPos(mpString->getLength()); + } else { + f32 lineHeight = getLineHeight(); + f32 y = mfCursorY + lineHeight; + mpString->setCursorPos(calcCursorPos(mfCursorX, 1.0f + y)); + onSE(sound::SE_CHAR_CURSOR); + } + meScrollFlag = SF_ScrollOn; +} + +void Base::onPressUp() { + tistring::Decolated* current = getCurrentString(false); + if (mpZiString == current) return; + if (mpUnfixString == current) { + if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); + if (mpUnfixString->isConverting()) { + if (!mpManager->getCandidateBox()->isInScroll()) { + tistring::Decolated* active = getCurrentString(false); + if (active == mpUnfixString) { + s32 selected = static_cast(mpUnfixString->getSelectedConverting() - 1); + if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; + else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + } + onSE(sound::SE_CHAR_CURSOR_FIX); + } + } else startConverting_(); + } else if (current == mpString) { + if (meLanguage == KR && !getCurrentString(false)->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + if (current->hasCandidate() || !current->isKanaFix()) return; + resetRelation(); + updateCandidateState_(); + if (mpUnfixString->getCandidate() != L' ') { + moveCursorUp(); + onCommand(static_cast(47), NULL); + } + } +} + +void Base::onPressDown() { + tistring::Decolated* current = getCurrentString(false); + if (mpZiString == current) return; + if (mpUnfixString == current) { + if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); + if (mpUnfixString->isConverting()) { + if (!mpManager->getCandidateBox()->isInScroll()) { + tistring::Decolated* active = getCurrentString(false); + if (active == mpUnfixString) { + s32 selected = static_cast(mpUnfixString->getSelectedConverting() + 1); + if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; + else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + } + onSE(sound::SE_CHAR_CURSOR_FIX); + } + } else startConverting_(); + } else if (current == mpString) { + if (meLanguage == KR && !getCurrentString(false)->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + if (current->hasCandidate() || !current->isKanaFix()) return; + resetRelation(); + updateCandidateState_(); + if (mpUnfixString->getCandidate() != L' ') { + moveCursorDown(); + onCommand(static_cast(47), NULL); + } + } +} + +void Base::onPressLeft() { + tistring::Decolated* current = getCurrentString(false); + current->getCursorPos(); + if (current == mpString) { + if (meLanguage == KR) { + if (!getCurrentString(false)->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + current->getCursorPos(); + } + if (current->hasCandidate() || !current->isKanaFix()) return; + resetInputRelation(); + if (mpUnfixString->getCandidate() == L' ') return; + } + if (current->moveCursorLeft()) onSE(sound::SE_CHAR_CURSOR); + else onSE(sound::SE_CHAR_CURSOR_FIX); + if (current == mpUnfixString) updateCandidateState_(); + meScrollFlag = SF_ScrollOn; +} + +void Base::onPressRight() { + tistring::Decolated* current = getCurrentString(false); + current->getCursorPos(); + if (current == mpString) { + if (meLanguage == KR) { + if (!getCurrentString(false)->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + current->getCursorPos(); + } + if (current->hasCandidate() || !current->isKanaFix()) return; + resetInputRelation(); + if (mpUnfixString->getCandidate() == L' ') return; + } + if (current->moveCursorRight() && mbRightWithSpace) { + CharacterInput space = {L' ', 0, false, false, 0}; + onCommand(static_cast(0), &space); + onSE(sound::SE_CHAR_CURSOR); + } + if (current == mpZiString || current == mpUnfixString) onSE(sound::SE_CHAR_CURSOR_FIX); + else onSE(sound::SE_CHAR_CURSOR); + if (current == mpUnfixString) updateCandidateState_(); + meScrollFlag = SF_ScrollOn; +} + +void Base::onPressDownHWKB() { + s32 selected; + tistring::Decolated* current = getCurrentString(false); + u32 modifiers = input::HKBManager::getInstance().GetModifierState(); + if (current == mpString) { + resetRelation(); + updateCandidateState_(); + if (meLanguage == KR && !getCurrentString(false)->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + if (current->hasCandidate() || !current->isKanaFix()) return; + if (mpUnfixString->getCandidate() == L' ') return; + moveCursorDown(); + onCommand(static_cast(47), NULL); + + } else if (mpUnfixString == current) { + if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); + if (mpUnfixString->isConverting()) { + if (modifiers & 2) { + mpUnfixString->commitPredicted(mpUnfixString->getSelectedConverting()); + updateCandidateState_(); + } else { + if (!mpManager->getCandidateBox()->isInScroll()) { + tistring::Decolated* active = getCurrentString(false); + if (active == mpUnfixString) { + selected = static_cast(mpUnfixString->getSelectedConverting() + 1); + if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; + else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + } + onSE(sound::SE_CHAR_CURSOR_FIX); + } + } + } else startConverting_(); + } + else if (mpZiString == current) { + return; + } +} + +void Base::onPressLeftHWKB() { + tistring::Decolated* current = getCurrentString(false); + input::HKBManager::getInstance().GetModifierState(); + current->getCursorPos(); + if (current == mpString) { + if (meLanguage == KR) { + if (!getCurrentString(false)->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + current->getCursorPos(); + } + if (current->hasCandidate() || !current->isKanaFix()) return; + resetRelation(); + updateCandidateState_(); + if (current->moveCursorLeft()) onSE(sound::SE_CHAR_CURSOR); + else onSE(sound::SE_CHAR_CURSOR_FIX); + } else if (current == mpUnfixString) { + if (mpManager->getCandidateBox()->isInScroll()) return; + if (mpUnfixString->getCurrentNumPredicted() <= 0) return; + if (mpUnfixString->isConverting()) { + onPressLeft(); + return; + } + s32 selected = static_cast(mpUnfixString->getSelectedCandidate() - 1); + if (selected < -1) selected = 0; + else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + onSE(sound::SE_CHAR_CURSOR_FIX); + } else if (current == mpZiString) { + if (mpManager->getCandidateBox()->isInScroll()) return; + bool selectedAlready = mbZuSelected; + mbZuSelected = true; + if (mpZiString->getCurrentNumPredicted() < 0) return; + s32 selected = mpZiString->getSelectedCandidateIndex(); + if (selectedAlready) --selected; + if (selected < 0) selected = mpZiString->getCurrentNumPredicted() - 1; + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + onSE(sound::SE_CHAR_CURSOR_FIX); + } + meScrollFlag = SF_ScrollOn; +} + +void Base::onPressRightHWKB() { + tistring::Decolated* current = getCurrentString(false); + input::HKBManager::getInstance().GetModifierState(); + current->getCursorPos(); + if (current == mpString) { + if (meLanguage == KR) { + if (!getCurrentString(false)->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN) { + bool predictions; + if (!mbPredictOn) predictions = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predictions = true; + else predictions = false; + if (predictions) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + current->getCursorPos(); + } + if (current->hasCandidate() || !current->isKanaFix()) return; + resetRelation(); + updateCandidateState_(); + if (current->moveCursorRight()) onSE(sound::SE_CHAR_CURSOR_FIX); + else onSE(sound::SE_CHAR_CURSOR); + } else if (current == mpUnfixString) { + if (mpManager->getCandidateBox()->isInScroll()) return; + if (mpUnfixString->getCurrentNumPredicted() <= 0) return; + if (mpUnfixString->isConverting()) { + current->moveCursorRight(); + onSE(sound::SE_CHAR_CURSOR_FIX); + updateCandidateState_(); + } else { + s32 selected = static_cast(mpUnfixString->getSelectedCandidate() + 1); + if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + onSE(sound::SE_CHAR_CURSOR_FIX); + } + } else if (current == mpZiString) { + if (mpManager->getCandidateBox()->isInScroll()) return; + bool selectedAlready = mbZuSelected; + mbZuSelected = true; + if (mpZiString->getCurrentNumPredicted() < 0) return; + s32 selected = mpZiString->getSelectedCandidateIndex(); + if (selectedAlready) ++selected; + if (selected >= mpZiString->getCurrentNumPredicted()) selected = 0; + if (selected < 0) selected = 0; + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + onSE(sound::SE_CHAR_CURSOR_FIX); + } + meScrollFlag = SF_ScrollOn; +} + +void Base::moveCandidateToIdx(s32 index) { + if (mbPredictOn) { + if (mpManager->getCandidateBox()->isInScroll()) return; + if (mePredictMode == PM_Atok) { + if (mpUnfixString->getFixedPredictionNum() && !mpUnfixString->isConverting()) { + mpUnfixString->confirm(NULL); + wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); + mpString->getCursorPos(); + mpString->confirm(confirmed); + mpString->getCursorPos(); + mpUnfixString->enableConfirmedString(false); + } + mpUnfixString->setSelectedCandidate(index); + } else { + mpZiString->setSelectedCandidate(index); + } + mpManager->getCandidateBox()->getTextArea().ChangeSelectedText(index); + } else { + meScrollFlag = SF_ScrollOn; + } +} + +void Base::startConverting_() { + if (mpUnfixString->getInputStringLength()) { + mpUnfixString->startConverting(); + updateCandidateState_(); + moveCandidateToIdx(0); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + onCommand(static_cast(47), NULL); + } +} + +void Base::toggleAtokMode_(u8 operation) { + bool allowed; + if (!mpManager->getToolBar()->isEnableKeytopChange() && !mpManager->getToolBar()->isQwerty()) { + allowed = false; + } else allowed = !mpManager->getPCKeyboard()->isQwertyOnly(); + if (!allowed) return; + bool enabled; + if (mpManager->getCandidateBox()->isActive()) { + if (mpManager->isPredictTurning()) return; + enabled = !mbPredictOn; + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) enabled = true; + } else { + enabled = mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00; + } + if (enabled && operation == 2) enabled = false; + else if (!enabled && operation == 1) enabled = true; + if (enabled) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); + } + } else { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); + } + if (mpManager->getCandidateBox()->isActive() && mbPredictOn != enabled) { + mpManager->startPredictTurnOn(!mbPredictOn); + } +} + +bool Base::isVacancy() const { + if (mpString->getLength() != 0 || !mpString->isKanaFix()) return false; + if (mePredictMode == PM_Atok) { + if (!mpUnfixString->isFix()) return false; + if (mpString->getLength() != 0) return false; + if (mpUnfixString->isCandidateSelected()) return false; + } else { + if (mePredictMode == PM_12) return true; + if (mePredictMode != PM_Off) { + if (mpZiString->getLength() != 0) return false; + wchar_t input[16]; + if (mpZiString->getCurrentInput(input, 16) > 0) return false; + if (mbCursorSelected | mbZuSelected) { + const wchar_t* selected = mpZiString->getCurrentSelected(); + if (selected && *selected != 0xfffe) return false; + } + } + } + return true; +} + +void Base::dirtyCacheAll() { + dirtyCursorCache(); + dirtyDrawCache(); +} + +void Base::notifyChangeMode() { + if (mePredictMode == PM_Atok) { + if (mpManager->getToolBar()->isQwerty()) { + if (mpManager->getPCKeyboard()->isABC()) { + if (!mpManager->getPCKeyboard()->getTranslateMode()) goto checkInput; + } + } + if (!mpManager->getToolBar()->isQwerty()) mpManager->getCellPhoneKeyboard()->getInputMode(); +checkInput: + if (mpUnfixString->getInputStringLength() == 0) updateCandidateState_(); + } else if (mePredictMode == PM_12) { + tistring::WithZi::PredictLanguage language; + if (mpManager->getToolBar()->isQwerty()) language = static_cast(10); + else language = static_cast(11); + mpZiString->setPredictLaunguage(language); + } else if (mePredictMode == PM_11) { + if (mbPredictOn) mpZiString->setCurrentWord(NULL); + } +} + +void Base::resetContextPredict_() { + getCurrentString(false); + resetPredictionContext(); +} + +void Base::onSpaceKeyHWKB(u32 modifiers) { + tistring::Decolated* current = getCurrentString(false); + if (modifiers & 8) { + if (static_cast(meLanguage) - CN <= 1 && !mpManager->getPCKeyboard()->isQwertyOnly() && mpManager->getPCKeyboard()->isLanguageKeyActive()) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00) { + mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_Kana); + } else mpManager->getPCKeyboard()->setTranslateMode(keyboard::pctype::Base::TM_00); + } + return; + } + bool useZi; + if (!mbPredictOn) useZi = false; + else if (mePredictMode == PM_Atok) useZi = false; + else if (meLanguage == CN && static_cast(mpManager)->getCandidateBox()->isInvalid()) useZi = false; + else useZi = true; + if (useZi) { + bool predicted; + if (!mbPredictOn) predicted = false; + else if (mePredictMode != PM_Atok && mpZiString->getCurrentNumPredicted() > 0) predicted = true; + else predicted = false; + if (predicted) { + if (!(mbCursorSelected | mbZuSelected) && mpManager->getToolBar()->isQwerty()) { + if (meLanguage != CN && meLanguage != KR && mbPredictOn && mePredictMode != PM_Atok) { + wchar_t input[64]; + mpZiString->getCurrentInput(input, 64); + mpString->getCursorPos(); + mpString->inputString(input); + mpString->getCursorPos(); + mpZiString->clearCandidates(); + mbZuSelected = false; + getCurrentString(false); + if (mpZiString && meLanguage == CN) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + updateCandidateState_(); + } + } + } else confirmInput_(); + updateCandidateState_(); + } + } else { + bool useAtok; + u32 enabled = mbPredictOn; + if (enabled == 0) useAtok = false; + else useAtok = mePredictMode == PM_Atok; + if (useAtok && current == mpUnfixString) { + if (!mpUnfixString->isKanaFix()) mpUnfixString->confirmKana(); + if (mpUnfixString->isConverting()) { + if (!mpManager->getCandidateBox()->isInScroll()) { + if (modifiers & 2) { + tistring::Decolated* active = getCurrentString(false); + if (active == mpUnfixString) { + s32 selected = static_cast(mpUnfixString->getSelectedConverting() - 1); + if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; + else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + } + } else { + tistring::Decolated* active = getCurrentString(false); + if (active == mpUnfixString) { + s32 selected = static_cast(mpUnfixString->getSelectedConverting() + 1); + if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; + else if (selected < 0) selected = static_cast(mpUnfixString->getCurrentNumPredicted() - 1); + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + } + } + onSE(sound::SE_CHAR_CURSOR_FIX); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + } + } else startConverting_(); + return; + } + } + if (mDKStream.lookAhead()) mDKStream.putChar(0xffff); + else mDKStream.putChar(L' '); + if (!mbPredictOn) useZi = false; + else if (mePredictMode == PM_Atok) useZi = false; + else if (meLanguage == CN && static_cast(mpManager)->getCandidateBox()->isInvalid()) useZi = false; + else useZi = true; + if (useZi) { + wchar_t character; + for (;;) { + character = mDKStream.getChar(); + if (!character) break; + inputCharZi_(character, modifiers); + } + } else { + wchar_t character; + for (;;) { + character = mDKStream.getChar(); + if (!character) break; + inputCharDefault_(character, modifiers); + } + } + updateCandidateState_(); +} + +void Base::deselectCandidate() { + if (!mbPredictOn) return; + if (mePredictMode != PM_Atok) return; + mpUnfixString->setSelectedCandidate(-1); +} + +void Base::resetRelation() { + mpManager->getHWKeyboard()->resetQuoteState(); + mpUnfixString->resetRelation(); +} + +LayoutByNW4R::LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, const char* layout, EventObserver* observer, const char* fontName) + : Base(manager), nw4rmanager::Layout(accessor, layout, observer), mpLayoutData("T_2l_TextBox"), + mpLanguageData(&csLanguageDependencyDataUEJ__Q29textinput9inputform), mpFontName(fontName), + mbUpVisible(false), mbDownVisible(false), mbRepeat(false), mpInputEventHandler(NULL) {} + +LayoutByNW4R::~LayoutByNW4R() { + if (mpInputEventHandler) { + mpInputEventHandler->~TiEventHandler(); + MEMFreeToAllocator(mpAllocator, mpInputEventHandler); + } + nw4rmanager::AnmPane* pane = static_cast(nw4r::ut::List_GetNext(&mAnmPanes, NULL)); + while (pane) { + nw4r::ut::List_Remove(&mAnmPanes, pane); + pane->destroy(mpAllocator); + pane = static_cast(nw4r::ut::List_GetNext(&mAnmPanes, NULL)); + } +} + +EventHandler::~EventHandler() {} + +void LayoutByNW4R::create(MEMAllocator* allocator, EditBuffer* editBuffer) { + nw4r::lyt::Pane* pane; + void* handlerMemory; + mpAllocator = allocator; + textdrawer::Base::create(allocator); + mpString = static_cast(editBuffer->mpString); + mpUnfixString = static_cast(editBuffer->mpUnfixString); + mpZiString = static_cast(editBuffer->mpZiString); + mriManager.mpAllocator = allocator; + mriManager.mpInfo = static_cast(MEMAllocFromAllocator(allocator, (mriManager.mMaxLength + 2) * sizeof(Info_))); + mriManager.init(); + Info_* rows; + Info_* row; + u16 next; + u16 previous; + u16 selectedIndex; + Info_* listEnd; + Info_* info; + rows = mriManager.mpInfo; + row = &rows[mriManager.mMaxLength]; + row = &rows[row->Next]; + next = row->Next; + previous = row->Back; + selectedIndex = rows[next].Back; + rows[next].Back = previous; + rows[previous].Next = next; + row->Back = selectedIndex; + row->Next = selectedIndex; + info = mriManager.mpInfo; + listEnd = &info[info[static_cast(mriManager.mMaxLength + 1)].Back]; + if (row->Back == row->Next) { + u16 head = listEnd->Next; + row->Back = info[head].Back; + row->Next = head; + listEnd->Next = selectedIndex; + info[head].Back = selectedIndex; + } + row->StrCount = 0; + row->DispRowCount = 1; + mpCursorLine = row; + handlerMemory = MEMAllocFromAllocator(allocator, sizeof(EventHandler)); + mpInputEventHandler = new (handlerMemory) EventHandler(this); + nw4rmanager::Layout::createWithEventHandler(allocator, mpInputEventHandler); + if (!mpFontName) { + mpFontName = "RevoIpl_RodinNTLGProM_32_I4.brfnt"; + mFont.SetResource(mpMultiArcResourceAccessor->GetResource(0, mpFontName, NULL)); + mFont.SetAlternateChar(0xe06b); + setFont(mFont); + } else { + mpMultiArcResourceAccessor->GetFont(mpFontName)->SetAlternateChar(0xe06b); + setFont(*mpMultiArcResourceAccessor->GetFont(mpFontName)); + } + nw4r::lyt::TextBox* textBox = getTextBox(); + textBox->SetString(L"", 0); + mfCharacterSpacing = textBox->GetCharSpace(); + mfLineSpacing = textBox->GetLineSpace(); + mfFontWidth = textBox->GetFontSize().width; + mfFontHeight = textBox->GetFontSize().height; + mRect = textBox->GetPaneRect(mDrawInfo); + AdjustPaneMtx(mMtx.m, mDrawInfo, textBox->GetGlobalMtx()); + csCharColor = textBox->GetTextColor(nw4r::lyt::TEXTCOLOR_TOP); + setVisible("N_2line", true); + mpPaneManager->setAllComponentTriggerTarget(false); + mpPaneManager->setAllBoundingBoxComponentTriggerTarget(true); + pane = mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLanguageData)->textBox, true); + if (!pane) pane = mpLayout->GetRootPane()->FindPaneByName(selectInputTextName(*this, mpLanguageData), true); + mpPaneManager->getPaneComponentByPane(pane)->setTriggerTarget(true); + for (u16 buttonIndex = 0; buttonIndex < 2; buttonIndex++) { + const ButtonAnimations& button = csButtonAnimations[buttonIndex]; + nw4rmanager::AnmPane* animationPane = NULL; + switch (button.type) { + case KT_NormalButton: { + void* memory = MEMAllocFromAllocator(allocator, sizeof(NormalButtonAnmPane)); + animationPane = new (memory) NormalButtonAnmPane(getPane(button.paneName), NULL); + break; + } + } + nw4r::ut::List_Append(&mAnmPanes, animationPane); + for (u16 animationIndex = 0; animationIndex < button.count; animationIndex++) { + void* resource = mpMultiArcResourceAccessor->GetResource(0, button.files[animationIndex]->fileName); + AnimTransformPane* transform = static_cast(getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor)); + if (button.bindingName == NULL) { + animationPane->addAnimation(allocator, button.files[animationIndex]->id, transform, false, true); + } else { + animationPane->forceAddAnimation(allocator, button.files[animationIndex]->id, transform, button.bindingName, false, true); + } + } + } + init(); +} + +void LayoutByNW4R::init() { + Base::init(); + searchAnmPane("P_txtScrll_UP")->changeAnimation(ANM_Off); + searchAnmPane("P_txtScrll_DOWN")->changeAnimation(ANM_Off); + mbUpVisible = false; + mbDownVisible = false; + mUpRepeat = 0; + mDownRepeat = 0; + mLeftRepeat = 0; + mRightRepeat = 0; + mRepeatButtons = 0; + mCharColor = csCharColor; + visibleSeparator(false); + nw4r::lyt::TextBox* textBox = getTextBox(); + textBox->SetString(L"", 0); + mfCharacterSpacing = textBox->GetCharSpace(); + mfLineSpacing = textBox->GetLineSpace(); + mfFontWidth = textBox->GetFontSize().width; + mfFontHeight = textBox->GetFontSize().height; + mRect = textBox->GetPaneRect(mDrawInfo); + AdjustPaneMtx(mMtx.m, mDrawInfo, textBox->GetGlobalMtx()); + mpLayout->Animate(0); + mpLayout->CalculateMtx(mDrawInfo); + const VisiblePanes* visibility = static_cast(mpLanguageData)->visibility; + for (u16 index = 0; index < visibility->visibleCount; ++index) setVisible(visibility->visibleNames[index], true); + for (u16 index = 0; index < visibility->hiddenCount; ++index) setVisible(visibility->hiddenNames[index], false); +} + +void LayoutByNW4R::draw() { + nw4rmanager::Layout::draw(); + muGlobalAlpha = getLayout()->GetRootPane()->GetAlpha(); + nw4r::lyt::Pane* textBox = mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true); + AdjustPaneMtx(mMtx.m, mDrawInfo, textBox->GetGlobalMtx()); + Base::draw(); +} + +void LayoutByNW4R::calc() { + Base::calc(); + nw4rmanager::Layout::calc(); + bool up = false; + bool down = false; + const char* separator = static_cast(mpLanguageData)->separator; + if (getPane(separator)) setVisible(static_cast(mpLanguageData)->separator, mbRepeat); + else setVisible("N_separateBarAll", mbRepeat); + if (!mScrollAnm.isActive()) { + if (0.0f > mfScrollY) up = true; + if (mfMinScrollY < mfScrollY) down = true; + if (mbUpVisible != up) { + mbUpVisible = up; + if (up) { + searchAnmPane("P_txtScrll_UP")->onAnmEvent(nw4rmanager::AnmPane::PE_6); + mpPaneManager->searchPaneComponent("P_txtScrll_UP")->init(); + } else searchAnmPane("P_txtScrll_UP")->onAnmEvent(nw4rmanager::AnmPane::PE_7); + } + if (mbDownVisible != down) { + mbDownVisible = down; + if (down) { + searchAnmPane("P_txtScrll_DOWN")->onAnmEvent(nw4rmanager::AnmPane::PE_6); + mpPaneManager->searchPaneComponent("P_txtScrll_DOWN")->init(); + } else searchAnmPane("P_txtScrll_DOWN")->onAnmEvent(nw4rmanager::AnmPane::PE_7); + } + } +} + +void LayoutByNW4R::setLanguage(Language language) { + Base::setLanguage(language); + if (language == CN) mpLanguageData = &csLanguageDependencyDataCHN__Q29textinput9inputform; + else if (language == KR) mpLanguageData = &csLanguageDependencyDataKOR__Q29textinput9inputform; + else mpLanguageData = &csLanguageDependencyDataUEJ__Q29textinput9inputform; + const char* textName; + if (!getLanguageTextPane()) textName = "T_2l_TextBox"; + else textName = static_cast(mpLanguageData)->textBox; + mpLayoutData = textName; + if (::strcmp(static_cast(mpLayoutData), "T_2l_TextBox") != 0) setVisible("T_2l_TextBox", false); + nw4r::lyt::Pane* pane = mpLayout->GetRootPane()->FindPaneByName(selectInputTextName(*this, mpLanguageData), true); + static_cast(pane)->SetString(L"", 0); + const VisiblePanes* visibility = static_cast(mpLanguageData)->visibility; + for (u16 index = 0; index < visibility->visibleCount; ++index) setVisible(visibility->visibleNames[index], true); + for (u16 index = 0; index < visibility->hiddenCount; ++index) setVisible(visibility->hiddenNames[index], false); + pane = mpLayout->GetRootPane()->FindPaneByName(selectInputTextName(*this, mpLanguageData), true); + mpPaneManager->getPaneComponentByPane(pane)->setTriggerTarget(true); + if (getPane("T_title_text")) { + nw4r::lyt::TextBox* title = nw4r::ut::DynamicCast(getPane("T_title_text")); + const char* titleName = static_cast(mpLanguageData)->title; + if (getPane(titleName)) { + nw4r::lyt::TextBox* languageTitle = nw4r::ut::DynamicCast(getPane(static_cast(mpLanguageData)->title)); + title->SetCharSpace(languageTitle->GetCharSpace()); + title->SetLineSpace(languageTitle->GetLineSpace()); + title->SetFontSize(languageTitle->GetFontSize()); + title->SetTranslate(languageTitle->GetTranslate()); + title->SetSize(languageTitle->GetSize()); + } + } +} + +void LayoutByNW4R::updateInputCommon(int chan, u32 trig, u32 hold, u32 release, void* data) { + updateRepeatInput(trig, hold); + if (mRepeatButtons & WPAD_BUTTON_MINUS) onCommand(static_cast(1), NULL); +} + +bool LayoutByNW4R::updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) { + u32 buttons = mRepeatButtons; + if (buttons & WPAD_BUTTON_LEFT) onCommand(static_cast(8), NULL); + if (buttons & WPAD_BUTTON_RIGHT) onCommand(static_cast(9), NULL); + if (buttons & WPAD_BUTTON_UP) onCommand(static_cast(10), NULL); + if (buttons & WPAD_BUTTON_DOWN) onCommand(static_cast(11), NULL); + bool handled = nw4rmanager::Layout::updateInput(chan, x, y, trig, hold, release, data); + if ((release & WPAD_BUTTON_A) && mpString->isOnSustain()) { + onCommand(static_cast(13), NULL); + } + if (!handled && (hold & WPAD_BUTTON_A) && mpString->isOnSustain()) { + nw4r::math::VEC2 point; + point.x = x; + point.y = y; + if (-y < getGlobalLeftTopPos().y + (mRect.top - mRect.bottom) / 2.0f) { + point.y = getGlobalLeftTopPos().y - 1.0f; + } else { + point.y = 1.0f + ((mRect.top - mRect.bottom) + getGlobalLeftTopPos().y); + } + onCommand(static_cast(16), &point); + } + return handled; +} + +bool LayoutByNW4R::updateInput(textinput::input::HKBManager& hkbManager) { + return nw4rmanager::Layout::updateInput(hkbManager); +} + +void LayoutByNW4R::updateRepeatInput(u32 trig, u32 hold) { + mRepeatButtons = trig; + if (hold & WPAD_BUTTON_LEFT) { + if (--mLeftRepeat == 0) { + mRepeatButtons |= WPAD_BUTTON_LEFT; + mLeftRepeat = 9; + } + } else mLeftRepeat = 30; + if (hold & WPAD_BUTTON_RIGHT) { + if (--mRightRepeat == 0) { + trig = mRepeatButtons; + mRightRepeat = 9; + mRepeatButtons = trig | WPAD_BUTTON_RIGHT; + } + } else mRightRepeat = 30; + if (hold & WPAD_BUTTON_UP) { + if (--mUpRepeat == 0) { + trig = mRepeatButtons; + mUpRepeat = 9; + mRepeatButtons = trig | WPAD_BUTTON_UP; + } + } else mUpRepeat = 30; + if (hold & WPAD_BUTTON_DOWN) { + if (--mDownRepeat == 0) { + trig = mRepeatButtons; + mDownRepeat = 9; + mRepeatButtons = trig | WPAD_BUTTON_DOWN; + } + } else mDownRepeat = 30; + if (hold & WPAD_BUTTON_MINUS) { + if (--mDeleteRepeat == 0) { + trig = mRepeatButtons; + mDeleteRepeat = 9; + mRepeatButtons = trig | WPAD_BUTTON_MINUS; + } + } else mDeleteRepeat = 30; +} + +nw4r::math::VEC2 LayoutByNW4R::getScale() const { + return mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true)->GetScale(); +} + +void LayoutByNW4R::onCommand(INPUT_COMMAND command, void* data) { + mpEventObserver->onInput(command, data); + mpEventObserver->onCommand(command, data); + Base::onCommand(command, data); + if (command == 31) return; + u32 limit = muLimitStringLength; + if (meLanguage == KR) { + u32 start, end; + mpString->getCursorPos(&start, &end); + if (start >= limit && !mpString->isKanaFix()) { + mpString->clearKana(); + onSE(sound::SE_CHAR_DELETE_ERROR); + } + if (!mpString->isKanaFix()) limit = muLimitStringLength - 1; + } + if (limit < mpString->getLength()) { + u32 start, end; + mpString->getCursorPos(&start, &end); + if (start > limit || end > limit) { + onSE(sound::SE_CHAR_DELETE_ERROR); + Base::onCommand(static_cast(36), &limit); + } + } + switch (command) { + case 32: + case 33: + case 35: + break; + default: { + u32 trimLimit = limit; + if (trimLimit < mpString->getLength()) { + if (mpString->getLength() > trimLimit) mpString->getLength(); + mpString->setLength(static_cast(trimLimit)); + mpEventObserver->onOutOfLength(); + if (command == 6 || command == 5 || command == 0 || command == 38 || command == 21 || command == 7) { + onSE(sound::SE_CHAR_DELETE_ERROR); + } + } + break; + } + } + u32 excessPos = isOverRowLimit(muLimitRowNum, mpString->getWCString()); + u32 rowLimit = excessPos; + if (excessPos) { + if (mpString->getLength() > excessPos) mpString->getLength(); + mpString->setLength(static_cast(excessPos)); + mpEventObserver->onOutOfLength(); + onSE(sound::SE_CHAR_DELETE_ERROR); + Base::onCommand(static_cast(36), &rowLimit); + if (meLanguage == KR && !mpString->isKanaFix()) { + rowLimit = isOverRowLimit(muLimitRowNum, mpString->getWCString()); + if (rowLimit) mpString->clearKana(); + } + } +} + +u32 Base::isOverRowLimit(u32 limit, const wchar_t* string) { + const wchar_t* current; + u32 rows; + bool kanaHandled; + bool kana; + const wchar_t* character; + u32 pos; + f32 cursorX; + u32 cursorStart; + u32 cursorEnd; + current = string; + if (!*string) return 0; + cursorX = getScale().x; + nw4r::math::VEC2 scale = getScale(); + pos = 0; + rows = 0; + muWordWrapCounter = 0; + kanaHandled = false; + mbHyphen = false; + mpString->getCursorPos(&cursorStart, &cursorEnd); + for (;;) { + DrawInfo info; + info.rect.left = 0.0f; + info.rect.top = 0.0f; + info.rect.right = 0.0f; + info.rect.bottom = 0.0f; + kana = false; + if (meLanguage == KR && !kanaHandled && cursorStart == pos) { + kanaHandled = true; + character = mpString->getKanaBuffer(); + if (*character) kana = true; + } + if (!kana) { + if (!*current) break; + character = current; + } + info.character = *character; + calcRect(info); + f32 right = cursorX + scale.x * info.rect.GetWidth(); + if (kana) { + if (right >= scale.x * mRect.GetWidth()) { + cursorX = getScale().x; + ++rows; + if (rows >= limit) return pos; + } else { + cursorX = right; + } + continue; + } + if (doWordWrap(string, pos, cursorX)) { + ++rows; + if (rows >= limit) { + while (pos < muWordWrapCounter) { + f32 advance; + f32 nextCursorX; + advance = scale.x * info.rect.GetWidth(); + nextCursorX = cursorX + advance; + if (nextCursorX >= scale.x * mRect.GetWidth()) return pos; + ++current; + cursorX += advance; + info.character = *current; + calcRect(info); + ++pos; + } + return muWordWrapCounter - 1; + } + cursorX = getScale().x; + } else if (right >= scale.x * mRect.GetWidth()) { + cursorX = getScale().x; + ++rows; + if (rows >= limit) return pos; + } + if (*current == L'\n') { + cursorX = getScale().x; + ++rows; + if (rows >= limit) return pos; + if (!current[1]) return 0; + } else { + cursorX += scale.x * info.rect.GetWidth(); + } + ++pos; + ++current; + } + return 0; +} + +void LayoutByNW4R::onSE(sound::SE seId) { + mpEventObserver->onSE(seId); +} + +void LayoutByNW4R::setRootPaneScaleFor16x9() { + nw4rmanager::Layout::setRootPaneScaleFor16x9(); + textdrawer::Base::setAspectRatio(false); +} + +void LayoutByNW4R::setRootPaneScaleFor4x3() { + nw4rmanager::Layout::setRootPaneScaleFor4x3(); + textdrawer::Base::setAspectRatio(true); +} + +void EventHandler::onTiEvent(gui::PaneComponent* component, u32 event, Input* input) { + char animationName[17]; + const char* name = component->getPane()->GetName(); + nw4r::math::VEC2 cursor; + cursor.x = input->x; + cursor.y = -input->y; + if (name[0] == 'B') { + util::replaceChar(animationName, 17, name, 0, 'P'); + if (event == gui::EventHandler::ON_TRIG && (input->trigger & WPAD_BUTTON_A) && !mpInputForm->isInScroll()) { + if (mpInputForm->isAbleToUp() && util::strcmp("P_txtScrll_UP", animationName)) { + textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; + movement.fCursorY = mpInputForm->getLineHeight(); + mpInputForm->onCommand(static_cast(24), &movement); + mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); + } else if (mpInputForm->isAbleToDown() && util::strcmp("P_txtScrll_DOWN", animationName)) { + textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; + movement.fCursorY = -mpInputForm->getLineHeight(); + mpInputForm->onCommand(static_cast(24), &movement); + mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); + } + } + if (event == gui::EventHandler::ON_MOVE && (input->hold & WPAD_BUTTON_A) && !(input->trigger & WPAD_BUTTON_A)) { + if (mpInputForm->isAbleToUp() && util::strcmp("P_txtScrll_UP", animationName)) { + if (component->isDragging(input->controller)) { + u32 duration = mpInputForm->getFlightDuration(input->controller, name); + if (duration >= 60 && duration % 20 == 0) { + textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; + movement.fCursorY = mpInputForm->getLineHeight(); + mpInputForm->onCommand(static_cast(24), &movement); + mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); + } + } + } else if (mpInputForm->isAbleToDown() && util::strcmp("P_txtScrll_DOWN", animationName)) { + if (component->isDragging(input->controller)) { + u32 duration = mpInputForm->getFlightDuration(input->controller, name); + if (duration >= 60 && duration % 20 == 0) { + textdrawer::Base::CursorPos movement = {0, 0.0f, 0.0f}; + movement.fCursorY = -mpInputForm->getLineHeight(); + mpInputForm->onCommand(static_cast(24), &movement); + mpInputForm->searchAnmPane(animationName)->onAnmEvent(nw4rmanager::AnmPane::PE_0); + } + } + } + } + AnmPane* animation = static_cast(mpInputForm->searchAnmPane(animationName)); + if (animation) { + switch (event) { + case gui::EventHandler::ON_LEFT: animation->onAnmEvent(nw4rmanager::AnmPane::PE_2); break; + case gui::EventHandler::ON_POINT: + if (animation->getState() != ANM_Off) { + mpEventObserver->onSE(sound::SE_SELECT); + animation->onAnmEvent(nw4rmanager::AnmPane::PE_1); + } + break; + } + } + } else if (name[0] == 'P') { + AnmPane* animation = static_cast(mpInputForm->searchAnmPane(name)); + if (animation) { + switch (event) { + case gui::EventHandler::ON_POINT: + if (animation->getState() != ANM_Off) { + mpEventObserver->onSE(sound::SE_SELECT); + animation->onAnmEvent(nw4rmanager::AnmPane::PE_1); + } + break; + case gui::EventHandler::ON_LEFT: + if (animation->getState() != ANM_Off) { + mpEventObserver->onSE(sound::SE_SELECT); + animation->onAnmEvent(nw4rmanager::AnmPane::PE_2); + } + break; + } + } + } else { + const char* textPane; + LayoutByNW4R* form = mpInputForm; + const nw4rmanager::Layout& layout = *form; + if (layout.getPane(static_cast(form->mpLanguageData)->textBox)) textPane = static_cast(form->mpLanguageData)->textBox; + else textPane = "T_2l_TextBox"; + if (util::strcmp(name, textPane)) { + if (event == gui::EventHandler::ON_TRIG && (input->trigger & WPAD_BUTTON_A)) mpInputForm->onCommand(static_cast(14), &cursor); + if (event == gui::EventHandler::ON_RELEASE && (input->release & WPAD_BUTTON_A)) mpInputForm->onCommand(static_cast(15), &cursor); + if (event == gui::EventHandler::ON_MOVE && (input->hold & WPAD_BUTTON_A)) mpInputForm->onCommand(static_cast(16), &cursor); + } + } +} void NormalButtonAnmPane::onAnmEvent(AnmPaneEvent event) { if (event == PE_6 && meState == ANM_Off) { @@ -3491,198 +3441,5 @@ void NormalButtonAnmPane::onAnmEvent(AnmPaneEvent event) { } } -EventHandler::~EventHandler() {} - -wchar_t Base::getCandidate() const { - return mpString->getCandidate(); -} - -void* Base::getAtokString() { - return mpUnfixString; -} - -u32 Base::getCursorPos() { - u32 fixedStart, unfixedStart, end; - mpString->getCursorPos(&fixedStart, &end); - mpUnfixString->getCursorPos(&unfixedStart, &end); - return fixedStart + unfixedStart; -} - -wchar_t* Base::getWCString() const { - return mpString->getWCString(); -} - -bool Base::isInScroll() { - return mScrollAnm.isActive(); -} - -Base::PredictMode Base::getPredictMode() { - Base::PredictMode mode; - onCommand(static_cast(31), &mode); - return mode; -} - -void Base::setPredictMode(PredictMode predictMode) { - switch (meDestination) { - case DST_EU: - if (predictMode == PM_En || predictMode == PM_De || predictMode == PM_Fr || predictMode == PM_Sp || predictMode == PM_It || predictMode == PM_Nl) { - break; - } - return; - case DST_JP: - if (predictMode == PM_Atok) { - break; - } - return; - case DST_US: - if (predictMode == PM_USEn || predictMode == PM_USFr || predictMode == PM_USSp) { - break; - } - return; - case DST_CN: - if (predictMode == PM_11) { - break; - } - return; - case DST_KR: - if (predictMode != PM_12) { - return; - } - break; - } - PredictMode mode; - onCommand(static_cast(31), &mode); - mode = predictMode; - onCommand(static_cast(29), &mode); -} - -nw4r::math::VEC2 Base::getScale() const { - return nw4r::math::VEC2(1.0f, 1.0f); -} - -bool LayoutByNW4R::isAbleToUp() { - return mbUpVisible; -} - -bool LayoutByNW4R::isAbleToDown() { - return mbDownVisible; -} - -bool LayoutByNW4R::updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) { - u32 buttons = mRepeatButtons; - if (buttons & WPAD_BUTTON_LEFT) onCommand(static_cast(8), NULL); - if (buttons & WPAD_BUTTON_RIGHT) onCommand(static_cast(9), NULL); - if (buttons & WPAD_BUTTON_UP) onCommand(static_cast(10), NULL); - if (buttons & WPAD_BUTTON_DOWN) onCommand(static_cast(11), NULL); - bool handled = nw4rmanager::Layout::updateInput(chan, x, y, trig, hold, release, data); - if ((release & WPAD_BUTTON_A) && mpString->isOnSustain()) { - onCommand(static_cast(13), NULL); - } - if (!handled && (hold & WPAD_BUTTON_A) && mpString->isOnSustain()) { - nw4r::math::VEC2 point; - point.x = x; - point.y = y; - if (-y < getGlobalLeftTopPos().y + (mRect.top - mRect.bottom) / 2.0f) { - point.y = getGlobalLeftTopPos().y - 1.0f; - } else { - point.y = 1.0f + ((mRect.top - mRect.bottom) + getGlobalLeftTopPos().y); - } - onCommand(static_cast(16), &point); - } - return handled; -} - -bool LayoutByNW4R::updateInput(textinput::input::HKBManager& hkbManager) { - return nw4rmanager::Layout::updateInput(hkbManager); -} - -void LayoutByNW4R::visibleSeparator(bool flag) { - mbRepeat = flag; -} - -void LayoutByNW4R::setRootPaneScaleFor16x9() { - nw4rmanager::Layout::setRootPaneScaleFor16x9(); - textdrawer::Base::setAspectRatio(false); -} - -void LayoutByNW4R::setRootPaneScaleFor4x3() { - nw4rmanager::Layout::setRootPaneScaleFor4x3(); - textdrawer::Base::setAspectRatio(true); -} - -} -} - -void textinput::Base::create(MEMAllocator*) {} - -namespace textinput { -namespace tistring { - -void WithAtok::backSpace() {} -void WithAtok::changeKanaMode(bool kana) {} -void WithAtok::closeDictionary() {} -void WithAtok::commitPredicted(int index) {} -void WithAtok::confirm(const wchar_t* string) {} -void WithAtok::enableConfirmedString(bool enable) {} -void WithAtok::getCursorPos(u32* start, u32* end) {} -void WithAtok::getDrawString(DrawInfo& info) {} -void WithAtok::getPredicted(int index, wchar_t* string) {} -void WithAtok::initConverting() {} -void WithAtok::init() {} -void WithAtok::inputChar(wchar_t ch) {} -void WithAtok::openDictionary(void* atok, int atokSize, void* apot, int apotSize, void* nintendo, int nintendoSize) {} -void WithAtok::popBack() {} -void WithAtok::pushBack(wchar_t ch) {} -void WithAtok::resetRelation() {} -void WithAtok::setDefaultPrediction(int count, const char** predictions) {} -void WithAtok::setFixMode(bool fixed) {} -void WithAtok::setFixPrediction(int count, const char** predictions) {} -void WithAtok::setFix(bool fix) {} -void WithAtok::setInputting(wchar_t ch) {} -void WithAtok::setSelectedCandidate(s32 index) {} -void WithAtok::startConverting() {} -bool WithAtok::isFix() { return true; } -bool WithAtok::isConverting() { return false; } -s16 WithAtok::getSelectedConverting() { return 0; } -bool WithAtok::isDictionaryOpened() { return false; } -wchar_t* WithAtok::getConfirmedWCString() const { return NULL; } -bool WithAtok::hasConfirmedString() { return false; } -int WithAtok::getCurrentNumPredicted() { return 0; } -bool WithAtok::isCandidateSelected() { return false; } -s32 WithAtok::getSelectedCandidate() { return 0; } -s32 WithAtok::getFixedPredictionNum() { return 0; } -wchar_t WithAtok::getInputStringLength() { return 0; } -bool WithAtok::moveCursorLeft() { return false; } -bool WithAtok::moveCursorRight() { return false; } -void Decolated::EnableKSXFilter(bool enable) {} -void Decolated::deleteChar() {} - -} -} - -namespace textinput { -namespace tistring { -u32 Decolated::getCursorPos() const { return mCursorStart; } -bool Decolated::isOnSustain() { return mbSustain; } -void WithZi::setSelectedCandidate(s32 index) { mSelectedCandidate = index; } -void WithZi::setPredictLaunguage(PredictLanguage language) { mPredictLanguage = language; } -int WithZi::getCurrentNumPredicted() { return mCandidateCount; } -u16 WithZi::getInputStringLength() { return mInputLength; } -void WithZi::changeLetterMode(LetterMode mode) { mLetterMode = mode; } -void WithZi::setCellPhoneHoldingkey(void* key) { mpHoldingKey = key; } -} -namespace candidatebox { -bool Base::isInvalid() const { return mbInvalid; } -} -namespace textdrawer { -u32 Base::getEndPos() const { return muDrawEndPos; } -u32 Base::getDrawModifyStartLine() const { return muDrawModifyStartLine; } -u32 Base::getDrawModifyEndLine() const { return muDrawModifyEndLine; } -void Base::dirtyDrawCache() { mbDrawCache = false; } -void Base::dirtyCursorCache() { mbCursorCache = false; } -u32 Base::getDrawCacheStartPos() const { - if (mbDrawCache) return muCachedStartPos; - return 0x7fffffff; -} -} -} +} // namespace inputform +} // namespace textinput diff --git a/tools/decomp-assist/o-ifl.attempts.md b/tools/decomp-assist/o-ifl.attempts.md new file mode 100644 index 00000000..9fd6e6bc --- /dev/null +++ b/tools/decomp-assist/o-ifl.attempts.md @@ -0,0 +1,83 @@ +# o-ifl attempts: link src/keyboard/tiInputForm + +Worktree data-d4, branch agent/w1009/o-ifl, base 12e857a9. Start: 221/221 exact, code and data 100%, +NonMatching. A Matching flip failed with multiply-defined `Decolated` and `CommandReceiver` vtables; +37/221 functions were in target order. + +## How MWCC (GC/3.0a5.2, -ipa file) lays out this TU + +Measured with small test files and the real unit: + +- Non-inline definitions are emitted in source order. +- An inline function is emitted right after the definition that first "touches" it, if anything needs + an out-of-line copy (a non-inlined call, a virtual call, a vtable). A touch is any call in the source, + even one that is inlined and leaves no code, and an unused result still counts. +- When a non-inline function is inlined into a caller, its touches stay with its own definition. When an + inline-only helper is inlined, its touches go to the caller. +- Virtual calls touch the statically resolved function (no relocation, so dtk shows them as UNREF). +- A constructor touches the destructors of its bases. +- The key function is the first virtual declared in the class without a body. Defined non-inline here: + strong vtable. Defined `inline` out of class: weak vtable when referenced. Declared `inline` or with a + body in the class: skipped, the next one becomes the key. +- `.data` vtables are emitted in reverse class-definition order. The vtable tail (inline virtuals only a + vtable needs) follows the same order; per class: overrides with thunks first, then inherited inlines per + base in reverse slot order, then the class's own inlines in reverse declaration order. A class whose + vtable is never emitted (`Sample`) still runs this and re-touches inherited thunks. +- `.sdata2` constants follow emission order. Weak `.data` objects keep their space when the object's + `.data` is referenced section-relative (`...data.0`); weak `.sbss` and unreferenced `.sdata2` objects are + dropped by the linker. + +## Changes (all 221 functions stay exact; every other object is byte-identical) + +1. Vtable ownership. In this TU's view (TIINPUTFORM guards): `textinput::Base` is all inline and its weak + vtable is emitted here; `~Decolated`, `clear`, `set` and `~CommandReceiver` have bodies in the class, so + their key functions stay in tiString/tiTextInputBase. `GUIComponent::init` and the other header helpers + are `inline` in the .cpp. Decolated, CommandReceiver and GUIComponent vtables are no longer emitted. +2. Header classes' small functions (WithAtok stubs, Decolated/WithZi/StringBase/textdrawer/Animation + getters, candidatebox, `~RowInfoManager`) are inline instead of strong definitions here. +3. Definitions in target order. Base's small virtuals that the target emits from the vtable tail or after + their first caller are inline; `textinput::Base::init` is touched by an inlined + `CommandReceiver::init()` in `Base::init`. +4. Touch order inside `onCommand`/onPress*: the original factored some blocks into non-inline helpers + (inlined everywhere, then dead-stripped). Recovered as `usesZiPrediction`, `hasZiPredictions`, + `checkUnfixConverting_`, `setAtokMode_`, `trimString_`, `startConverting_`, `resetRelation()` calls, + and `int selected` before `commitPredicted`. Each one is inlined to the same code. +5. Include `tiUtil.h`/`tiGUIManager.h` first (target `.data` vtable order), the real `inputform::Sample` + (as in tiKeyboard.cpp) after the local classes (tail and thunk order, nothing emitted for it), + WithAtok declares `isFix/setFix/initConverting` before its overrides (tail order, same vtable). +6. Removed the `scInputForm*` dummy constants (nothing referenced them) and the unused + `extern "C" asm` declarations; `sbCompatibleFilterEnabled` now precedes `mbHyphen` in `.sdata` + (both were 0x01, objdiff could not see the swap). + +Result: 219/221 in target order; `.data`, `.rodata`, `.sdata`, `.sbss`, `.bss` and thunk order match. + +## The remaining two: a dead-stripped function after makeUpCursorPos + +Target emits `getDrawModifyEndLine` and `getEndPos` right after `makeUpCursorPos`, and `0.5f` right after +`getScale`'s `1.0f` in `.sdata2`, before `calc`'s constants. No code in the target calls the two getters, +and an unused virtual call is never removed. Skyward Sword's software keyboard REL (zeldaret/ss, +`d_SoftwareKeyboardNP` symbols, read-only) has the same `makeUpCursorPos` (0x44) followed by +`StringBase::getWCString`, `getDrawModifyEndLine`, `getEndPos`, `drawFixString`. So the original file had a +function here that touched those three and first used 0.5f, and the linker stripped it as unreferenced. +Its body is not recoverable. + +Proof: an external stand-in between `makeUpCursorPos` and `drawFixString` that calls the two getters and +returns 0.5f gives 221/221 in order and, with tiInputForm Matching, DOL SHA1 +26116613f624061ba99c8d1a299aaa6efa85670d, 0 differing bytes. An unused `static` stand-in fixes the +function order but not the constant (unused statics are not compiled). + +This stand-in is an uncalled function, so it is kept in a separate commit for the owner to accept or drop. + +## objdiff `.sdata2` artifact + +objdiff now scores `.sdata2` 92% (clean commit) / 96% (linked commit): the weak `GetTextColor` copy brings +the `NW4R_ASSERT` color constant `{255,255,255,0}` into `.sdata2`; the linker strips it, the original +object had it too (its `@STRING@GetTextColor` survives in `.data`). The old 100% came from the dummy +`scInputForm*` names. With the link, complete data is 3772/3772. + +## Dead ends + +- `s16` local before `commitPredicted`: extra `mr` (onCommand 99.84%); `int` is exact. +- Making AnmPane strong or NormalButtonAnmPane weak, moving the local classes: no effect on the tail. +- Removing `#pragma section const_type ".data"` (non-const local array): template moves to `.rodata`, + three functions change. Left as it was.