From 2c5c982ae40366e7931190bec705362aafb7d259 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 00:02:08 +0000 Subject: [PATCH] tiInputForm: 208/221 functions (worker 66d51a87) --- README.md | 4 +- include/keyboard/tiCandidateBox.h | 3 + include/keyboard/tiCellPhone.h | 23 +- include/keyboard/tiHwKeyboard.h | 8 + include/keyboard/tiInputForm.h | 81 +- include/keyboard/tiKeyboard.h | 2 +- include/keyboard/tiManager.h | 4 + include/keyboard/tiNw4rManager.h | 10 + include/keyboard/tiPcKeyboard.h | 35 +- include/keyboard/tiString.h | 108 + include/keyboard/tiTextDrawer.h | 43 +- include/keyboard/tiTextInputBase.h | 6 +- include/keyboard/tiUtil.h | 9 +- include/keyboard/tiZiString.h | 52 + src/keyboard/tiInputForm.cpp | 3241 +++++++++++++------ tools/decomp-assist/tiInputForm.attempts.md | 61 + 16 files changed, 2592 insertions(+), 1098 deletions(-) create mode 100644 tools/decomp-assist/tiInputForm.attempts.md diff --git a/README.md b/README.md index 57738729..12274b62 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 81.02% | 72.42% | 56.76% | 86.28% | +| 82.03% | 72.73% | 56.76% | 86.28% | -units 748/1027 complete, functions 10585/12563 matched. +units 748/1027 complete, functions 10617/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/include/keyboard/tiCandidateBox.h b/include/keyboard/tiCandidateBox.h index 86129c99..a50a5480 100644 --- a/include/keyboard/tiCandidateBox.h +++ b/include/keyboard/tiCandidateBox.h @@ -323,6 +323,9 @@ namespace textinput { virtual void cancelStateFocusIn(); // 0x128 virtual void onEvent(UIObj*, u32, void*) override; // 0x12C +#ifdef TIINPUTFORM_IMPLEMENTATION + UITextArea& getTextArea() { return mTextArea; } +#endif void onPressedShift(bool shift); void onReleasedShift(); void startTurnOn(bool); diff --git a/include/keyboard/tiCellPhone.h b/include/keyboard/tiCellPhone.h index 3f66728f..139db5b5 100644 --- a/include/keyboard/tiCellPhone.h +++ b/include/keyboard/tiCellPhone.h @@ -2,20 +2,20 @@ #define TEXTINPUT_CELL_PHONE_H #include "tiNw4rManager.h" -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) #include "tiKeyboard.h" #endif namespace textinput { namespace keyboard { namespace cellphonetype { -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) class Base : public textinput::keyboard::KeyboardBase { #else class Base { #endif public: -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) enum InputMode { IM_00, IM_01, @@ -74,7 +74,7 @@ namespace textinput { virtual void vt_0x4C(); virtual void vt_0x50(); -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) virtual void doNumericMode(bool); #else virtual void vt_0x54(); @@ -90,8 +90,11 @@ namespace textinput { // TODO enum? int getInputType() const; +#ifdef TIINPUTFORM_IMPLEMENTATION + void resetHoldingButton(); +#endif -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) private: u32 mPreviousInputMode; u32 mCurrentInputMode; @@ -111,7 +114,7 @@ namespace textinput { class LayoutByNW4R : public Base, public nw4rmanager::Layout { public: -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) virtual void doNumericMode(bool); virtual void setPredictLanguageDialog(void*); virtual void setSignWindow(void*); @@ -124,7 +127,13 @@ namespace textinput { void onPressedShift(bool shift); void onReleasedShift(); -#ifdef MYTIMANAGER_IMPLEMENTATION +#ifdef TIINPUTFORM_IMPLEMENTATION + bool hasLineFeedButton() const { return mbLineFeedButton; } + private: + bool mbLineFeedButton; + public: +#endif +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) override; virtual bool updateInput(input::HKBManager& hkbManager) override; #endif diff --git a/include/keyboard/tiHwKeyboard.h b/include/keyboard/tiHwKeyboard.h index a3918baf..482be0f1 100644 --- a/include/keyboard/tiHwKeyboard.h +++ b/include/keyboard/tiHwKeyboard.h @@ -25,6 +25,9 @@ namespace textinput { #endif virtual bool updateInput(input::HKBManager& hkbManager); +#ifdef TIINPUTFORM_IMPLEMENTATION + void resetQuoteState() { mbSingleQuoteClosing = 0; mbDoubleQuoteClosing = 0; } +#endif private: void updateShift(input::HKBManager& hkbManager); void controlKeyTriggeredHandler(input::HKBManager); @@ -33,8 +36,13 @@ namespace textinput { Manager* mpManager; // 0x10 u8 field_0x14; // 0x14 +#ifdef TIINPUTFORM_IMPLEMENTATION + u8 mbSingleQuoteClosing; + u8 mbDoubleQuoteClosing; +#else u8 field_0x15; // 0x15 u8 field_0x16; // 0x16 +#endif }; diff --git a/include/keyboard/tiInputForm.h b/include/keyboard/tiInputForm.h index 0d4ecc6e..72fd5b1c 100644 --- a/include/keyboard/tiInputForm.h +++ b/include/keyboard/tiInputForm.h @@ -13,14 +13,32 @@ #include "tiZiString.h" #include "tiSEId.h" +#ifdef TIINPUTFORM_IMPLEMENTATION +extern "C" wchar_t KPRGetChar(KPRQueue* queue); +extern "C" void KPRPutChar(KPRQueue* queue, wchar_t character); +extern "C" void KPRClearQueue(KPRQueue* queue); +extern "C" u8 KPRLookAhead(KPRQueue* queue, wchar_t* character, wchar_t* combining); +#endif + namespace textinput { namespace inputform { +#ifdef TIINPUTFORM_IMPLEMENTATION + class EventHandler; + class LayoutByNW4R; +#endif class EditBuffer { +#ifdef TIINPUTFORM_IMPLEMENTATION + friend class LayoutByNW4R; +#endif public: #ifdef MYTIMANAGER_IMPLEMENTATION void create(MEMAllocator* allocator); #endif +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual ~EditBuffer(); +#else ~EditBuffer(); +#endif private: void* mpString; // 0x04 @@ -30,7 +48,19 @@ namespace textinput { }; class DeadKeyStream { -#ifdef TI_PC_KEYBOARD_IMPLEMENTATION +#if defined(TIINPUTFORM_IMPLEMENTATION) + public: + static wchar_t ToCombineClass(Language language, wchar_t code); + static wchar_t ToIndependentClass(wchar_t code); + inline wchar_t getChar(); + u8 lookAhead() { return KPRLookAhead(&mKPRQueue, NULL, NULL); } + void putChar(wchar_t character) { KPRPutChar(&mKPRQueue, character); } + bool isEmpty() const { return mKPRQueue.oCount == 0; } + void clear() { KPRClearQueue(&mKPRQueue); } + private: + static bool sbCompatibleFilterEnabled; + static inline bool isCompatible(wchar_t character); +#elif defined(TI_PC_KEYBOARD_IMPLEMENTATION) public: static wchar_t ToIndependentClass(wchar_t code); #endif @@ -82,6 +112,12 @@ namespace textinput { // TODO - location class RowInfoManager { +#ifdef TIINPUTFORM_IMPLEMENTATION + friend class LayoutByNW4R; + public: + void init(); + ~RowInfoManager(); +#endif private: Info_* mpInfo; // 0x00 u16 mMaxLength; // 0x04 @@ -89,6 +125,33 @@ namespace textinput { }; virtual ~Base(); +#ifdef TIINPUTFORM_IMPLEMENTATION + Base(Manager* manager); + virtual void create(MEMAllocator* allocator); + virtual void init(); + virtual void onCommand(INPUT_COMMAND command, void* data); + void setCursorPos(tistring::Decolated* string, u32 pos); + void calcCursorTimer(); + bool isAtokActive() const; + void dirtyCacheAll(); + tistring::Decolated* getCurrentString(bool inputting); + void moveCandidateToIdx(s32 index); + void onPressDownHWKB(); + void onPressLeftHWKB(); + void onPressRightHWKB(); + void toggleAtokMode_(u8 operation); + void onSpaceKeyHWKB(u32 modifiers); + void onHKBCtrlCode(HVKCode code, u32 modifiers); + void confirmInput_(); + void confirmInputting_(wchar_t character, bool direct, u16 letterMode, bool confirmOnly, void* holdingKey); + 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; + inline void resetPredictionContext(); + inline void resetInputRelation(); +#endif virtual void create(MEMAllocator* allocator, EditBuffer* editBuffer); @@ -199,15 +262,17 @@ namespace textinput { virtual void makeUpCursorPos(CursorPos* cursorPos, u32 pos, s32 startLine, s32 endLine); -#ifdef MYTIINPUTFORM_IMPLEMENTATION +#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) protected: +#ifndef TIINPUTFORM_IMPLEMENTATION void setCursorPos(tistring::Decolated* string, u32 pos); - void resetRelation(); void calcCursorTimer(); +#endif + void resetRelation(); #else private: #endif -#ifdef MYTIINPUTFORM_IMPLEMENTATION +#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) nw4r::ut::Rect mRect; #else Rect mRect; @@ -254,8 +319,12 @@ namespace textinput { }; class LayoutByNW4R : public Base, public nw4rmanager::Layout { +#ifdef TIINPUTFORM_IMPLEMENTATION + friend class EventHandler; + inline const nw4r::lyt::Pane* getLanguageTextPane() const; +#endif public: -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) LayoutByNW4R(textinput::Manager*, nw4r::lyt::MultiArcResourceAccessor*, const char*, EventObserver*, const char*); #endif ~LayoutByNW4R(); @@ -284,7 +353,7 @@ namespace textinput { virtual void visibleSeparator(bool flag); -#ifdef MYTIINPUTFORM_IMPLEMENTATION +#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) protected: const void* mpLayoutData; const void* mpLanguageData; diff --git a/include/keyboard/tiKeyboard.h b/include/keyboard/tiKeyboard.h index bb3c6d6c..30b9aad0 100644 --- a/include/keyboard/tiKeyboard.h +++ b/include/keyboard/tiKeyboard.h @@ -16,7 +16,7 @@ namespace textinput { virtual void sendCommand(u32 command, void*) override; #endif virtual void updateFromReceiver(u32, void*) override; -#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TI_PC_KEYBOARD_IMPLEMENTATION) +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TI_PC_KEYBOARD_IMPLEMENTATION) virtual void onKey(u32, void*); #else virtual void onKey(u32); diff --git a/include/keyboard/tiManager.h b/include/keyboard/tiManager.h index 802f9cd1..133c40d4 100644 --- a/include/keyboard/tiManager.h +++ b/include/keyboard/tiManager.h @@ -146,6 +146,10 @@ namespace textinput { void enableCompatibleFilter(bool compatibleFilter); bool isVacancy() const; +#ifdef TIINPUTFORM_IMPLEMENTATION + bool isPredictTurning() const; + void startPredictTurnOn(bool enabled); +#endif private: MEMAllocator* mpAllocator; // 0x04 diff --git a/include/keyboard/tiNw4rManager.h b/include/keyboard/tiNw4rManager.h index 2c3b98c8..3069cdfa 100644 --- a/include/keyboard/tiNw4rManager.h +++ b/include/keyboard/tiNw4rManager.h @@ -14,12 +14,22 @@ namespace textinput { class TiEventHandler : public gui::EventHandler { public: typedef struct Input { +#ifdef TIINPUTFORM_IMPLEMENTATION + u32 controller; + f32 x; + f32 y; + u32 trigger; + u32 hold; + u32 release; + u8 remaining[8]; +#else // todo u32 field_0x00; // 0x00 u8 dummy[8]; u32 field_0x0C; // 0x0C u32 field_0x10; // 0x10 u8 dummy2[12]; +#endif } Input; virtual void onEvent(gui::GUIComponent& comp, u32 event, void* data); // 0x0C diff --git a/include/keyboard/tiPcKeyboard.h b/include/keyboard/tiPcKeyboard.h index 633442bb..6402708e 100644 --- a/include/keyboard/tiPcKeyboard.h +++ b/include/keyboard/tiPcKeyboard.h @@ -7,7 +7,7 @@ #include "tiNw4rManager.h" #include "tiTextInputBase.h" -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) #include "tiKeyboard.h" #endif @@ -18,7 +18,7 @@ namespace textinput { namespace pctype { -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) class UIObj { public: class Listener { @@ -29,7 +29,7 @@ namespace textinput { #endif // TODO -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) class Base : public textinput::keyboard::KeyboardBase { #else class Base : public CommandSender { @@ -37,6 +37,10 @@ namespace textinput { public: enum TranslateMode { TM_00, +#ifdef TIINPUTFORM_IMPLEMENTATION + TM_Kana, + TM_Roman, +#endif }; enum InputType { @@ -47,7 +51,7 @@ namespace textinput { IT_04, }; -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) enum InputMode { IM_00, IM_01, @@ -126,7 +130,7 @@ namespace textinput { virtual void updateFixMode(); #endif -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) private: u8 mKeyboardInputFlags[8]; const void* mpKeyStateTable; @@ -136,6 +140,9 @@ namespace textinput { u32 mCurrentInputType; u32 mInputState; const void* mpLanguageData; +#ifdef TIINPUTFORM_IMPLEMENTATION + MEMAllocator* mpAllocator; +#endif bool mbOnlyQwerty; bool mbLanguageKeyActive; u16 mKeyboardFlags; @@ -143,6 +150,10 @@ namespace textinput { void* mpCurrentKeyState; public: +#ifdef TIINPUTFORM_IMPLEMENTATION + bool isQwertyOnly() const { return mbOnlyQwerty; } + bool isLanguageKeyActive() const { return mbLanguageKeyActive; } +#endif u32 getTranslateModeForMemo() const { return mTranslateMode; } u32 getABCInputModeForMemo() const { return mABCInputMode; } u32 getAIUInputModeForMemo() const { return mAIUInputMode; } @@ -151,14 +162,14 @@ namespace textinput { // TODO class LayoutByNW4R : public Base, public nw4rmanager::Layout -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) , public UIObj::Listener #endif { public: // TODO - ... -#ifdef MYTIMANAGER_IMPLEMENTATION +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) virtual void draw(); virtual void calc(); virtual void setPredictLanguageDialog(void*); @@ -171,7 +182,15 @@ namespace textinput { void onPressedShift(bool shift); void onReleasedShift(); -#ifdef MYTIMANAGER_IMPLEMENTATION +#ifdef TIINPUTFORM_IMPLEMENTATION + bool hasLineFeedButton() const { return mbLineFeedButton; } + private: + void* mpPredictLanguageDialog; + void* mpSignWindow; + bool mbLineFeedButton; + public: +#endif +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) override; virtual bool updateInput(input::HKBManager& hkbManager) override; #endif diff --git a/include/keyboard/tiString.h b/include/keyboard/tiString.h index d8b8c70d..73943e94 100644 --- a/include/keyboard/tiString.h +++ b/include/keyboard/tiString.h @@ -36,7 +36,11 @@ namespace textinput { virtual wchar_t* getWCString() const { return mpszString; } virtual void setCandidate(wchar_t candidate) { mwcCandidate = candidate; } + #ifdef TIINPUTFORM_IMPLEMENTATION + virtual wchar_t getCandidate() const { return mwcCandidate; } +#else virtual wchar_t getCandidate() { return mwcCandidate; } +#endif virtual bool hasCandidate() const; virtual wchar_t getLastWChar(); @@ -60,8 +64,54 @@ namespace textinput { class Decolated : public StringBase { public: +#ifdef TIINPUTFORM_IMPLEMENTATION + Decolated(u16 maxLen) : StringBase(maxLen), mCursorStart(0), mCursorEnd(0), mbSustain(false), mTranslateMode(0) { initKanaConverter(); } +#else Decolated(u16 maxLen) : StringBase(maxLen), field_0x18(0), field_0x1C(0), field_0x20(0), field_0x24(0) { initKanaConverter(); } +#endif +#ifdef TIINPUTFORM_IMPLEMENTATION + enum TranslateMode { TM_Direct, TM_Kana, TM_Roman, TM_Hangul }; + void setTranslateMode(TranslateMode mode); + TranslateMode getTranslateMode() const { return static_cast(mTranslateMode); } + void inputString(const wchar_t* string, TranslateMode mode); + virtual void inputChar(wchar_t ch); + virtual void inputString(const wchar_t* string); + virtual void deleteChar(); + virtual void backSpace(); + virtual void confirm(const wchar_t* string); + virtual bool moveCursorRight(); + virtual bool moveCursorLeft(); + virtual void setCursorPos(u32 pos); + virtual void onSustain(); + virtual void offSustain(); + virtual bool isOnSustain(); + virtual u32 getCursorPos() const; + virtual void getCursorPos(u32* start, u32* end); + virtual bool canBackSpace(); +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual bool deleteForward(); +#else + virtual void deleteForward(); +#endif + virtual void getSelected(u32& start, u32& end); + virtual wchar_t getWCharAtCursor(); + virtual void replaceAtCursor(wchar_t ch); + virtual bool isDakuten(); + virtual void converDakuten(); + virtual bool isHandaku(); + virtual void converHandaku(); + virtual void convertAll(); + virtual bool isSmall(); + virtual void converSmall(); + virtual bool atTheBeginningOfASentence(); + virtual void initKanaConverter(); + virtual wchar_t* getKanaBuffer(); + virtual bool isKanaFix() const; + virtual void confirmKana(); + virtual void clearKana(); + virtual void EnableKSXFilter(bool enable); +#else virtual void inputChar(); virtual void inputString(); virtual void deleteChar(); @@ -95,15 +145,73 @@ namespace textinput { virtual void clearKana(); virtual void EnableKSXFilter(); +#endif + private: +#ifdef TIINPUTFORM_IMPLEMENTATION + u32 mCursorStart; + u32 mCursorEnd; + bool mbSustain; + u32 mTranslateMode; +#else u32 field_0x18; // 0x18 u32 field_0x1C; // 0x1C u8 field_0x20; // 0x20 u32 field_0x24; // 0x24 +#endif KanaStream mKanaStream; // 0x28 }; +#ifdef TIINPUTFORM_IMPLEMENTATION + class WithAtok : public Decolated { + public: + virtual void pushBack(wchar_t ch); + virtual void popBack(); + virtual void inputChar(wchar_t ch); + virtual void backSpace(); + virtual void confirm(const wchar_t* string); + virtual bool moveCursorRight(); + virtual bool moveCursorLeft(); + virtual void getCursorPos(u32* start, u32* end); + struct DrawInfo { + const wchar_t* string; + u32 start; + u32 end; + 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(); + virtual void getPredicted(int index, wchar_t* string); + virtual void commitPredicted(int index); + virtual void setSelectedCandidate(s32 index); + virtual bool isCandidateSelected(); + virtual s32 getSelectedCandidate(); + virtual void init(); + virtual void setInputting(wchar_t ch); + virtual void getDrawString(DrawInfo& info); + virtual void openDictionary(void* atok, int atokSize, void* apot, int apotSize, void* nintendo, int nintendoSize); + virtual void closeDictionary(); + virtual bool hasConfirmedString(); + virtual void enableConfirmedString(bool enable); + virtual void startConverting(); + virtual bool isDictionaryOpened(); + virtual void changeKanaMode(bool kana); + virtual wchar_t getInputStringLength(); + virtual void resetRelation(); + virtual void setFixMode(bool fixed); + virtual void setFixPrediction(int count, const char** predictions); + virtual void setDefaultPrediction(int count, const char** predictions); + virtual s16 getSelectedConverting(); + virtual s16 getFixedPredictionNum(); + }; +#else class WithAtok : public StringBase {}; +#endif } } diff --git a/include/keyboard/tiTextDrawer.h b/include/keyboard/tiTextDrawer.h index 3a1b7cf4..7c6b4ea8 100644 --- a/include/keyboard/tiTextDrawer.h +++ b/include/keyboard/tiTextDrawer.h @@ -9,7 +9,7 @@ namespace textinput { namespace textdrawer { -#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION) +#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) class Base : public nw4r::ut::CharWriter { #else class Base : nw4r::ut::CharWriter { @@ -31,7 +31,12 @@ namespace textinput { } CursorPos; typedef struct DrawInfo { +#ifdef TIINPUTFORM_IMPLEMENTATION + nw4r::ut::Rect rect; + wchar_t character; +#else u8 unk_0x00[32]; +#endif } DrawInfo; virtual void create(MEMAllocator* allocator); @@ -80,17 +85,51 @@ namespace textinput { virtual void setDrawModifyScopeLine(); virtual void setDrawCacheScopeLine(); virtual void modifyCursorCache(); +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual bool isEnableCursorCache() const; +#else virtual void isEnableCursorCache(); +#endif +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual u32 getDrawModifyStartLine() const; + virtual u32 getDrawModifyEndLine() const; +#else virtual void getDrawModifyStartLine(); virtual void getDrawModifyEndLine(); +#endif virtual u32 getDrawCacheStartPos() const; virtual void dirtyDrawCache(); virtual void dirtyCursorCache(); +#ifdef TIINPUTFORM_IMPLEMENTATION + protected: + u8 mDrawConfiguration[0x50]; + u32 muLine; + f32 mfLineSpacing; + f32 mfCharacterSpacing; + f32 mfFontWidth; + f32 mfFontHeight; + u32 muModifyStartLine; + u32 muModifyEndLine; + u32 muDrawStartPos; + u32 muDrawEndPos; + u32 muDrawCacheStartPos; +#else private: u8 unk_0x50[0x78]; +#endif bool mbSecretMode; // 0xC8 -#ifdef MYTIINPUTFORM_IMPLEMENTATION +#ifdef TIINPUTFORM_IMPLEMENTATION + u32 muDrawModifyStartLine; + u32 muDrawModifyEndLine; + u32 muDrawModifyStartPos; + u32 muDrawModifyEndPos; + u32 muCachedStartPos; + u32 muCachedEndPos; + bool mbDrawCache; + u8 mCursorCacheConfiguration[0x1F]; + bool mbCursorCache; +#elif defined(MYTIINPUTFORM_IMPLEMENTATION) protected: u8 mDrawState[0x27]; f32 mfDrawScrollY; diff --git a/include/keyboard/tiTextInputBase.h b/include/keyboard/tiTextInputBase.h index e5d03c2e..6858a425 100644 --- a/include/keyboard/tiTextInputBase.h +++ b/include/keyboard/tiTextInputBase.h @@ -39,6 +39,10 @@ namespace textinput { f32 y; // 0x08 } Scroll; +#ifdef TIINPUTFORM_IMPLEMENTATION + enum HVKCode { HVK_None = 0 }; +#endif + class Base { public : virtual ~Base() {} @@ -50,7 +54,7 @@ namespace textinput { class CommandSender; class CommandReceiver : public Base { public: -#ifdef MYTIINPUTFORM_IMPLEMENTATION +#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) struct Scroll { bool absY; f32 x; diff --git a/include/keyboard/tiUtil.h b/include/keyboard/tiUtil.h index 2d4b5a44..341477ca 100644 --- a/include/keyboard/tiUtil.h +++ b/include/keyboard/tiUtil.h @@ -7,6 +7,9 @@ namespace textinput { namespace util { +#ifdef TIINPUTFORM_IMPLEMENTATION + wchar_t HankakuToZenkaku(wchar_t ch); +#endif wchar_t toWLower(wchar_t ch); wchar_t toWUpper(wchar_t ch); @@ -46,7 +49,11 @@ namespace textinput { public: Animation() : mfAnimationTime(0.0f), mbInAnimation(false), mbSE(false), mpAnimObserver(NULL) {} - virtual void startAnm(AnimObserver*, f32, f32, f32, void*); // 0x08 +#ifdef TIINPUTFORM_IMPLEMENTATION + virtual void startAnm(f32 start, f32 end, f32 duration, AnimObserver* observer, void* data); +#else + virtual void startAnm(AnimObserver*, f32, f32, f32, void*); +#endif // 0x08 virtual void calc(); // 0x0C virtual f32 getValue(); // 0x10 virtual bool isActive(); // 0x14 diff --git a/include/keyboard/tiZiString.h b/include/keyboard/tiZiString.h index 2c98f4fb..b7ef92f8 100644 --- a/include/keyboard/tiZiString.h +++ b/include/keyboard/tiZiString.h @@ -1,14 +1,66 @@ #ifndef TEXTINPUT_ZI_STRING_H #define TEXTINPUT_ZI_STRING_H +#ifdef TIINPUTFORM_IMPLEMENTATION +#include "tiString.h" +#include +#endif + namespace textinput { namespace tistring { + #ifdef TIINPUTFORM_IMPLEMENTATION + class WithZi : public Decolated { + public: + enum PredictLanguage { PL_Default }; + enum LetterMode { LM_Lower, LM_Normal, LM_Upper }; + virtual ~WithZi(); + virtual void init(); + virtual void setInputting(wchar_t ch); + virtual int getCurrentNumPredicted(); + virtual void getPredicted(int index, wchar_t* string); + virtual const wchar_t* getCurrentSelected(); + virtual u16 getInputStringLength(); + virtual void setSelectedCandidate(s32 index); + virtual bool isFix(); + virtual void setPredictLaunguage(PredictLanguage language); + virtual void changeLetterMode(LetterMode mode); + virtual void ChangeDictionaryLanguage(u8 language); + virtual void setCellPhoneHoldingkey(void* key); + virtual void setElementBuffer(); + virtual u8 getPredictLanguage(); + s32 getSelectedCandidateIndex() const { return mSelectedCandidate; } + void openDictionary(void* ziDict, void* ziOemDict); + void setCurrentWord(const wchar_t* string); + void update(); + const wchar_t* getCurrentInput(); + void getCurrentInput(wchar_t* buffer, u32 length); + void clearCandidates(); + void partialConfirmForKR(); + private: + EZTXGetParam mSearch; + u32 mSearchState; + bool mbDictionaryOpen; + bool mbContextChanged; + u32 mCurrentWordLength; + EZTXLanguageEntry* mpDictionaries; + void* mpDictionaryWork; + u16 mInputLength; + s32 mCandidateCount; + u32 mOemDictionaryId; + u8 mDictionaryLanguage; + s32 mSelectedCandidate; + u32 mPredictLanguage; + u32 mLetterMode; + void* mpHoldingKey; + }; +#else class WithZi { public: virtual ~WithZi(); void openDictionary(void* ziDict, void* ziOemDict); }; +#endif } } diff --git a/src/keyboard/tiInputForm.cpp b/src/keyboard/tiInputForm.cpp index 52a2ffda..6ed9c8e3 100644 --- a/src/keyboard/tiInputForm.cpp +++ b/src/keyboard/tiInputForm.cpp @@ -1,11 +1,82 @@ +#define TIINPUTFORM_IMPLEMENTATION #include "keyboard/tiInputForm.h" #include "keyboard/tiManager.h" +#include "keyboard/tiDebug.h" +#include "keyboard/tiLayoutGather.h" #include +#include +#include namespace textinput { namespace inputform { +struct VisiblePanes { + u16 visibleCount; + u16 hiddenCount; + const char* visibleNames[4]; + const char* hiddenNames[4]; +}; + +struct LanguagePaneData { + const VisiblePanes* visibility; + const char* separator; + const char* textBox; + const char* title; +}; + +enum Animation { + ANM_Normal, + ANM_FocusIn, + ANM_FocusOut, + ANM_RollOver, + ANM_Pushed, + ANM_FadeIn, + ANM_FadeOut, + ANM_Off +}; + +enum KeyType { + KT_NormalButton +}; + +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(); + +protected: + Animation meState; + KeyType meKeyType; +}; + +class NormalButtonAnmPane : public AnmPane { +public: + NormalButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { meKeyType = KT_NormalButton; } + virtual ~NormalButtonAnmPane(); + virtual void onAnmEvent(AnmPaneEvent event); +}; + +class EventHandler : public nw4rmanager::TiEventHandler { +public: + EventHandler(LayoutByNW4R* form) : mpInputForm(form) {} + virtual ~EventHandler(); + virtual void onTiEvent(gui::PaneComponent* component, u32 event, Input* input); +private: + LayoutByNW4R* mpInputForm; +}; + +nw4r::ut::Color csUnInputedWCharColor(200, 50, 50, 255); +nw4r::ut::Color csCharColor(20, 20, 20, 255); +nw4r::ut::Color csZiStringColorLeft(255, 50, 50, 255); +nw4r::ut::Color csZiStringNonSelectColorRight(192, 192, 192, 255); +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(); @@ -39,7 +110,6 @@ extern "C" asm void addCandidate__Q39textinput12candidatebox18CandidateBoxCaller extern "C" asm void updateCandidate__Q39textinput12candidatebox18CandidateBoxCallerFv(); extern "C" asm void setCurrentWord__Q39textinput8tistring6WithZiFPCw(); extern "C" asm void update__Q39textinput8tistring6WithZiFv(); -extern "C" asm void wcslen(); extern "C" asm void wcsnicmp(); extern "C" asm void List_Append__Q24nw4r2utFPQ34nw4r2ut4ListPv(); extern "C" asm void List_GetNext__Q24nw4r2utFPCQ34nw4r2ut4ListPCv(); @@ -52,7 +122,6 @@ 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 KPRLookAhead(); extern "C" asm void set__Q39textinput8tistring10StringBaseFPCw(); extern "C" asm void clear__Q39textinput8tistring10StringBaseFv(); extern "C" asm void updateRepeatInput__Q39textinput9inputform12LayoutByNW4RFUlUl(); @@ -538,152 +607,34 @@ inputInputting_L_done: addi r1, r1, 0x20 blr } -extern "C" asm void inputCharDefault___Q39textinput9inputform4BaseFwUl() { - nofralloc - stwu r1, -0x20(r1) - mflr r0 - stw r0, 0x24(r1) - addi r11, r1, 0x20 - bl _savegpr_27 - mr r28, r4 - mr r27, r3 - mr r29, r5 - li r4, 1 - bl getCurrentString__Q39textinput9inputform4BaseFb - lwz r31, 0x168(r27) - mr r30, r3 - mr r3, r27 - li r4, 0 - bl getCurrentString__Q39textinput9inputform4BaseFb - cmplw r3, r31 - bne inputCharDefault_L_language - lwz r12, 0(r31) - mr r3, r31 - lwz r12, 0xdc(r12) - mtctr r12 - bctrl - cmpwi r3, 0 - bne inputCharDefault_L_language - lwz r3, 0x168(r27) - lwz r12, 0(r3) - lwz r12, 0xf8(r12) - mtctr r12 - bctrl - cmpwi r3, 0 - blt inputCharDefault_L_language - mr r3, r27 - bl confirmInputting___Q39textinput9inputform4BaseFwbUsbPv -inputCharDefault_L_language: - lwz r0, 0x1f0(r27) - cmpwi r0, 9 - bne inputCharDefault_L_string - lwz r3, 0x1d4(r27) - lwz r12, 0(r3) - lwz r12, 0x74(r12) - mtctr r12 - bctrl - lwz r12, 0(r3) - lwz r12, 0x58(r12) - mtctr r12 - bctrl - cmpwi r3, 0 - beq inputCharDefault_L_string - mr r3, r28 - bl reverseLetterCaseW__Q29textinput4utilFw - cmpwi r3, 0 - beq inputCharDefault_L_string - rlwinm. r0, r29, 0, 0x1e, 0x1e - beq inputCharDefault_L_string - mr r3, r28 - bl reverseLetterCaseW__Q29textinput4utilFw - mr r28, r3 -inputCharDefault_L_string: - lwz r3, 0x164(r27) - cmplw r3, r30 - bne inputCharDefault_L_post_string - lwz r12, 0(r3) - lwz r12, 0x7c(r12) - mtctr r12 - bctrl - lwz r3, 0x164(r27) - clrlwi r4, r28, 0x10 - lwz r12, 0(r3) - lwz r12, 0x50(r12) - mtctr r12 - bctrl - lwz r3, 0x164(r27) - lwz r12, 0(r3) - lwz r12, 0x7c(r12) - mtctr r12 - bctrl - lwz r0, 0x1f0(r27) - cmpwi r0, 8 - bne inputCharDefault_L_post_string_cont - lbz r0, 0x178(r27) - cmpwi r0, 0 - bne inputCharDefault_L_predict - li r0, 0 - b inputCharDefault_L_predict_check -inputCharDefault_L_predict: - lwz r0, 0x174(r27) - cmpwi r0, 1 - beq inputCharDefault_L_predict_false - lwz r3, 0x16c(r27) - lwz r12, 0(r3) - lwz r12, 0xd8(r12) - mtctr r12 - bctrl - cmpwi r3, 0 - ble inputCharDefault_L_predict_false - li r0, 1 - b inputCharDefault_L_predict_check -inputCharDefault_L_predict_false: - li r0, 0 -inputCharDefault_L_predict_check: - cmpwi r0, 0 - beq inputCharDefault_L_post_string_cont - lwz r3, 0x16c(r27) - li r4, 0 - bl setCurrentWord__Q39textinput8tistring6WithZiFPCw - lwz r3, 0x16c(r27) - bl update__Q39textinput8tistring6WithZiFv - b inputCharDefault_L_post_string_cont -inputCharDefault_L_post_string: - lwz r12, 0(r30) - mr r3, r30 - clrlwi r4, r28, 0x10 - lwz r12, 0x50(r12) - mtctr r12 - bctrl -inputCharDefault_L_post_string_cont: - clrlwi r0, r28, 0x10 - cmplwi r0, 0x20 - bne inputCharDefault_L_newline - lwz r12, 0(r27) - mr r3, r27 - li r4, 9 - lwz r12, 0x178(r12) - mtctr r12 - bctrl - b inputCharDefault_L_set -inputCharDefault_L_newline: - cmplwi r0, 0xa - beq inputCharDefault_L_set - lwz r12, 0(r27) - mr r3, r27 - li r4, 0xa - lwz r12, 0x178(r12) - mtctr r12 - bctrl -inputCharDefault_L_set: - li r0, 1 - addi r11, r1, 0x20 - stw r0, 0x1b0(r27) - bl _restgpr_27 - lwz r0, 0x24(r1) - mtlr r0 - addi r1, r1, 0x20 - blr +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(static_cast(9)); + else if (character != L'\n') onSE(static_cast(10)); + meScrollFlag = SF_ScrollOn; } extern "C" asm void calc__Q39textinput9inputform12LayoutByNW4RFv() { nofralloc @@ -950,12 +901,8 @@ extern "C" asm void draw__Q39textinput9inputform12LayoutByNW4RFv() { addi r1, r1, 0x50 blr } -extern "C" asm void calcCursorTimer__Q39textinput9inputform4BaseFv() { - nofralloc - lwz r4, 0x214(r3) - addi r0, r4, 8 - stw r0, 0x214(r3) - blr +void Base::calcCursorTimer() { + muCursorTimer += 8; } extern "C" asm bool isAtokActive__Q39textinput9inputform4BaseCFv() { nofralloc @@ -971,28 +918,9 @@ isAtokActive_L1: srwi r3, r0, 5 blr } -extern "C" asm void dirtyCacheAll__Q39textinput9inputform4BaseFv() { - nofralloc - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - stw r31, 0xc(r1) - mr r31, r3 - lwz r12, 0x5c(r3) - lwz r12, 0x94(r12) - mtctr r12 - addi r3, r3, 0x10 - bctrl - lwz r12, 0x5c(r31) - addi r3, r31, 0x10 - lwz r12, 0x90(r12) - mtctr r12 - bctrl - lwz r0, 0x14(r1) - lwz r31, 0xc(r1) - mtlr r0 - addi r1, r1, 0x10 - blr +void Base::dirtyCacheAll() { + dirtyCursorCache(); + dirtyDrawCache(); } extern "C" asm void initZiString__Q39textinput9inputform4BaseFv() { nofralloc @@ -1162,39 +1090,27 @@ bool mbHyphen; #pragma section const_type ".data" extern "C" const char lbl_8165C820[] = "P_txtScrll_UP"; extern "C" const char lbl_8165C830[] = "P_txtScrll_DOWN"; -extern "C" const void* lbl_8165C840[32] = { - 0, - lbl_8165C820, - (const void*)0x00000008, - 0, - csAninationFile__Q29textinput9inputform, - csAninationFile__Q29textinput9inputform + 1, - csAninationFile__Q29textinput9inputform + 2, - csAninationFile__Q29textinput9inputform + 3, - csAninationFile__Q29textinput9inputform + 4, - csAninationFile__Q29textinput9inputform + 5, - csAninationFile__Q29textinput9inputform + 6, - 0, - 0, - 0, - 0, - 0, - lbl_8165C830, - (const void*)0x00000008, - 0, - csAninationFile__Q29textinput9inputform, - csAninationFile__Q29textinput9inputform + 1, - csAninationFile__Q29textinput9inputform + 2, - csAninationFile__Q29textinput9inputform + 3, - csAninationFile__Q29textinput9inputform + 4, - csAninationFile__Q29textinput9inputform + 5, - csAninationFile__Q29textinput9inputform + 6, - 0, - 0, - 0, - 0, - 0, - 0, +struct ButtonAnimations { + KeyType type; + const char* paneName; + u32 count; + const char* bindingName; + const InputFormAnimationFile* files[12]; +}; + +const char* csScrollButtonAnimationTarget = lbl_8165C820; + +const ButtonAnimations csButtonAnimations[] = { + {KT_NormalButton, lbl_8165C820, 8, NULL, { + &csAninationFile__Q29textinput9inputform[0], &csAninationFile__Q29textinput9inputform[1], + &csAninationFile__Q29textinput9inputform[2], &csAninationFile__Q29textinput9inputform[3], + &csAninationFile__Q29textinput9inputform[4], &csAninationFile__Q29textinput9inputform[5], + &csAninationFile__Q29textinput9inputform[6], &csAninationFile__Q29textinput9inputform[7]}}, + {KT_NormalButton, lbl_8165C830, 8, csScrollButtonAnimationTarget, { + &csAninationFile__Q29textinput9inputform[0], &csAninationFile__Q29textinput9inputform[1], + &csAninationFile__Q29textinput9inputform[2], &csAninationFile__Q29textinput9inputform[3], + &csAninationFile__Q29textinput9inputform[4], &csAninationFile__Q29textinput9inputform[5], + &csAninationFile__Q29textinput9inputform[6], &csAninationFile__Q29textinput9inputform[7]}} }; extern "C" const char lbl_8165C8C0[] = "N_JPNUSAEUR"; extern "C" const char lbl_8165C8CC[] = "N_separateBarAll"; @@ -1206,12 +1122,29 @@ extern "C" const char lbl_8165C928[] = "T_title_textKOR"; extern "C" const char lbl_8165C938[] = "N_separateBarCHN"; extern "C" const char lbl_8165C950[] = "T_2l_TextBoxCHN"; extern "C" const char lbl_8165C960[] = "T_title_textCHN"; -extern "C" const u16 lbl_8165C970[16] = { - 0x00a4, 0x00ac, 0x00af, 0x00b2, 0x00b3, 0x00b6, 0x00b8, 0x00b9, - 0x00bc, 0x00bd, 0x00be, 0x00d0, 0x00de, 0x00f0, 0x00fe, 0x0000, -}; +bool DeadKeyStream::sbCompatibleFilterEnabled = true; -extern "C" u16 ToIndependentClass__Q39textinput9inputform13DeadKeyStreamFw(u16 code) { +inline bool DeadKeyStream::isCompatible(wchar_t character) { + const wchar_t excluded[] = { + 0x00a4, 0x00ac, 0x00af, 0x00b2, 0x00b3, 0x00b6, 0x00b8, 0x00b9, + 0x00bc, 0x00bd, 0x00be, 0x00d0, 0x00de, 0x00f0, 0x00fe, 0x0000 + }; + if (character < excluded[0] || character > excluded[14]) return true; + for (u32 index = 0; index < 15; ++index) { + if (character == excluded[index]) return false; + } + return true; +} + +inline wchar_t DeadKeyStream::getChar() { + wchar_t character = KPRGetChar(&mKPRQueue); + if (sbCompatibleFilterEnabled) { + while (!isCompatible(character)) character = KPRGetChar(&mKPRQueue); + } + return character; +} + +wchar_t DeadKeyStream::ToIndependentClass(wchar_t code) { if (code < 0x300 || code > 0x330) { return code; } @@ -1283,45 +1216,848 @@ void Base::setLanguage(Language language) { } } -extern "C" const char lbl_8165CBE0[] = "T_2l_TextBox"; -extern "C" const char lbl_8165D258[] = "RevoIpl_RodinNTLGProM_32_I4.brfnt"; -extern "C" const char lbl_8165D27C[] = "P_txtScrll_UP"; -extern "C" const char lbl_8165D28C[] = "P_txtScrll_DOWN"; +struct CharacterInput { + wchar_t character; + u32 modifiers; + bool keyboardMode; + bool deadKey; +}; + +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_(); + } +} + +inline void Base::resetInputRelation() { + mpManager->getHWKeyboard()->resetQuoteState(); + mpUnfixString->resetRelation(); + updateCandidateState_(); +} + +void Base::onCommand(INPUT_COMMAND command, void* data) { + CommandReceiver::onCommand(command, data); + tistring::Decolated* current = getCurrentString(false); + tistring::Decolated* fixed = mpString; + bool currentIsFixed = current == fixed; + switch (command) { + case 40: + if (current == mpUnfixString) { + if (LayoutGather::Singleton::getInstance().isHoldingShift()) onPressUp(); + else onPressDown(); + return; + } + if (mDKStream.lookAhead()) mDKStream.putChar(0xffff); + else mDKStream.putChar(L' '); + if (mDKStream.isEmpty()) onSE(static_cast(10)); + { + tistring::WithAtok* unfix = mpUnfixString; + if (getCurrentString(false) == unfix) unfix->isConverting(); + } + for (;;) { + wchar_t character = mDKStream.getChar(); + if (!character) break; + if (usesZiPrediction()) inputCharZi_(character, 0); + else inputCharDefault_(character, 0); + } + break; + case 0: { + CharacterInput* input = static_cast(data); + wchar_t character = input->character; + u32 modifiers = input->modifiers; + tistring::Decolated::TranslateMode savedMode = current->getTranslateMode(); + bool savedFix = false; + bool savedKana = false; + if (input->keyboardMode) { + tistring::Decolated::TranslateMode keyboardMode = static_cast(mpManager->getPCKeyboard()->getTranslateMode()); + bool direct = mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00; + bool kana = mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_Kana; + tistring::Decolated* active = getCurrentString(false); + savedMode = active->getTranslateMode(); + if (active == mpString) { + tistring::Decolated::TranslateMode mode = keyboardMode; + if (meLanguage == KR) { + if (mode != tistring::Decolated::TM_Direct) mode = tistring::Decolated::TM_Hangul; + } else if (meLanguage == CN) mode = tistring::Decolated::TM_Direct; + mpString->getCursorPos(); + mpString->setTranslateMode(mode); + mpString->getCursorPos(); + } else active->setTranslateMode(keyboardMode); + bool useAtok; + if (!mbPredictOn) useAtok = false; + else useAtok = mePredictMode == PM_Atok; + if (useAtok) { + mpUnfixString->setFixMode(direct); + mpUnfixString->changeKanaMode(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(static_cast(10)); + { + tistring::WithAtok* unfix = mpUnfixString; + if (getCurrentString(false) == unfix) unfix->isConverting(); + } + for (;;) { + wchar_t queued = mDKStream.getChar(); + if (!queued) break; + if (usesZiPrediction()) inputCharZi_(queued, modifiers); + else inputCharDefault_(queued, modifiers); + } + if (current == mpZiString) mbZuSelected = false; + if (input->keyboardMode) { + tistring::Decolated* active = getCurrentString(false); + if (active == mpString) { + tistring::Decolated::TranslateMode mode = savedMode; + if (meLanguage == KR) { + if (mode != tistring::Decolated::TM_Direct) mode = tistring::Decolated::TM_Hangul; + } else if (meLanguage == CN) mode = tistring::Decolated::TM_Direct; + mpString->getCursorPos(); + mpString->setTranslateMode(mode); + mpString->getCursorPos(); + } else active->setTranslateMode(savedMode); + bool useAtok; + if (!mbPredictOn) useAtok = false; + else useAtok = mePredictMode == PM_Atok; + if (useAtok) { + mpUnfixString->setFixMode(savedFix); + mpUnfixString->changeKanaMode(savedKana); + } + } + if (checkHeadOfSentence(true)) onCommand(static_cast(33), NULL); + break; + } + case 1: + if (!current->canBackSpace()) onSE(static_cast(8)); + else onSE(static_cast(7)); + if (current == mpString) { + resetInputRelation(); + mpString->getCursorPos(); + mpString->backSpace(); + if (mpManager->getCellPhoneKeyboard()) mpManager->getCellPhoneKeyboard()->resetHoldingButton(); + mpString->getCursorPos(); + getCurrentString(false); + resetPredictionContext(); + } else if (current == mpZiString) { + mbZuSelected = false; + current->backSpace(); + if (mpManager->getCellPhoneKeyboard()) mpManager->getCellPhoneKeyboard()->resetHoldingButton(); + } else { + if (!mpUnfixString->isConverting()) { + mpUnfixString->backSpace(); + if (mpManager->getCellPhoneKeyboard()) mpManager->getCellPhoneKeyboard()->resetHoldingButton(); + } + updateCandidateState_(); + } + meScrollFlag = SF_ScrollByBS; + if (checkHeadOfSentence(true)) onCommand(static_cast(33), NULL); + break; + case 2: + if (!currentIsFixed) { + onSE(static_cast(8)); + return; + } + if (!fixed->deleteForward()) onSE(static_cast(8)); + else onSE(static_cast(7)); + break; + case 7: + if (currentIsFixed) { + if (meLanguage == KR) { + tistring::Decolated* active = getCurrentString(false); + if (!active->isKanaFix()) { + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN && hasZiPredictions()) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } + } + resetInputRelation(); + bool lineFeed; + if (!mpManager->getToolBar()->isQwerty()) lineFeed = mpManager->getCellPhoneKeyboard()->hasLineFeedButton(); + else lineFeed = mpManager->getPCKeyboard()->hasLineFeedButton(); + bool allowed = true; + if (mpString->isKanaFix()) { + bool withinLimit = false; + if (lineFeed && static_cast(getLine() + 1) <= muLimitRowNum) withinLimit = true; + if (!withinLimit) allowed = false; + } + bool atLimit = true; + if (static_cast(getLine() + 1) <= muLimitRowNum && !mpManager->getCandidateBox()->isActive()) atLimit = false; + if (!allowed) { + if (atLimit) onSE(static_cast(8)); + return; + } + onSE(static_cast(9)); + mpString->getCursorPos(); + mpString->inputChar(L'\n'); + mpString->getCursorPos(); + if (meLanguage == CN && hasZiPredictions()) { + mpZiString->setCurrentWord(NULL); + mpZiString->update(); + } + } else if (current == mpZiString) { + onSE(static_cast(9)); + if (getPredictMode() == PM_11 || getPredictMode() == PM_12) confirmInput_(); + else if (!(mbCursorSelected | mbZuSelected) && mpManager->getToolBar()->isQwerty()) { + if (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); + resetPredictionContext(); + } + } else confirmInput_(); + } else { + onSE(static_cast(9)); + if (!mpUnfixString->isConverting()) confirmInput_(); + else { + mpUnfixString->commitPredicted(mpUnfixString->getSelectedConverting()); + updateCandidateState_(); + } + } + meScrollFlag = SF_ScrollOn; + if (checkHeadOfSentence(true)) onCommand(static_cast(33), NULL); + break; + case 6: + confirmInput_(); + meScrollFlag = SF_ScrollOn; + break; + case 3: + if (mePredictMode == PM_11 && current == mpZiString) mbZuSelected = false; + inputInputting_(*static_cast(data)); + break; + case 5: { + ConfirmInput* input = static_cast(data); + if (!input->character) return; + confirmInputting_(input->character, input->direct, input->letterMode, input->confirmOnly, input->holdingKey); + if (!input->silent) { + if (!input->confirmOnly) onSE(static_cast(10)); + else onSE(static_cast(9)); + } + meScrollFlag = SF_ScrollOn; + if (checkHeadOfSentence(true)) onCommand(static_cast(33), NULL); + break; + } + case 8: + if (currentIsFixed) onPressLeft(); + else onHKBCtrlCode(static_cast(31), 0); + return; + case 9: + if (currentIsFixed) onPressRight(); + else onHKBCtrlCode(static_cast(32), 0); + return; + case 10: onPressUp(); return; + case 11: onPressDown(); return; + case 14: + if (currentIsFixed && current->isKanaFix()) { + nw4r::math::VEC2 origin = getGlobalLeftTopPos(); + nw4r::math::VEC2* cursor = static_cast(data); + current->setCursorPos(calcCursorPos(cursor->x - origin.x, cursor->y - origin.y)); + onSE(static_cast(5)); + onCommand(static_cast(12), NULL); + resetInputRelation(); + } else { + onSE(static_cast(9)); + onCommand(static_cast(6), NULL); + } + return; + case 15: + if (current->isOnSustain()) { + nw4r::math::VEC2 origin = getGlobalLeftTopPos(); + nw4r::math::VEC2* cursor = static_cast(data); + current->setCursorPos(calcCursorPos(cursor->x - origin.x, cursor->y - origin.y)); + onCommand(static_cast(13), NULL); + } + return; + case 16: + if (current->isOnSustain()) { + nw4r::math::VEC2 origin = getGlobalLeftTopPos(); + u32 previous, end; + current->getCursorPos(&previous, &end); + nw4r::math::VEC2* cursor = static_cast(data); + u32 position = calcCursorPos(cursor->x - origin.x, cursor->y - origin.y); + current->setCursorPos(position); + if (previous != position) onSE(static_cast(5)); + meScrollFlag = SF_ScrollOn; + } + return; + case 17: + if (data && *static_cast(data)) { + mpUnfixString->confirm(NULL); + onCommand(static_cast(6), NULL); + resetCandidate(); + updateCandidate(); + } + break; + case 18: { + tistring::Decolated::TranslateMode mode = *static_cast(data); + if (meLanguage != JP && meLanguage != KR) mode = tistring::Decolated::TM_Direct; + tistring::Decolated::TranslateMode fixedMode = mode; + if (meLanguage == KR) { + if (mode != tistring::Decolated::TM_Direct) fixedMode = tistring::Decolated::TM_Hangul; + } else if (meLanguage == CN) fixedMode = tistring::Decolated::TM_Direct; + fixed->getCursorPos(); + mpString->setTranslateMode(fixedMode); + mpString->getCursorPos(); + mpUnfixString->setTranslateMode(mode); + break; + } + case 19: mpUnfixString->changeKanaMode(*static_cast(data)); break; + case 20: mpUnfixString->setFixMode(*static_cast(data)); break; + case 21: { + s32 index = *static_cast(data); + if (mbPredictOn) { + if (mePredictMode == PM_Atok) { + if (!mpUnfixString->isConverting()) { + wchar_t predicted[96]; + mpUnfixString->getPredicted(index, predicted); + mpString->getCursorPos(); + mpString->inputString(predicted, tistring::Decolated::TM_Direct); + mpString->getCursorPos(); + mpUnfixString->commitPredicted(index); + } else mpUnfixString->commitPredicted(index); + } else { + wchar_t predicted[64]; + mpZiString->getPredicted(index, predicted); + mpString->getCursorPos(); + mpString->inputString(predicted); + mpString->getCursorPos(); + mpZiString->clearCandidates(); + mbZuSelected = false; + if (meLanguage == CN) { + mpZiString->setCurrentWord(predicted); + mpZiString->update(); + } + } + } + meScrollFlag = SF_ScrollOn; + break; + } + case 22: + moveCandidateToIdx(*static_cast(data)); + meScrollFlag = SF_ScrollOn; + return; + case 23: + if (!mbPredictOn) break; + if (mePredictMode == PM_Atok) mpUnfixString->setSelectedCandidate(-1); + else if (mePredictMode == PM_11) { + mpZiString->setSelectedCandidate(-1); + mbZuSelected = false; + } + meScrollFlag = SF_ScrollOn; + return; + case 24: doScroll(static_cast(data)); return; + case 25: current->converDakuten(); onSE(static_cast(10)); break; + case 26: current->converHandaku(); onSE(static_cast(10)); break; + case 27: current->convertAll(); break; + case 28: current->converSmall(); onSE(static_cast(10)); break; + case 29: { + PredictionState* prediction = static_cast(data); + mePredictMode = prediction->mode; + bool enabled = prediction->enabled != false; + if (mbPredictOn != enabled) { + mbPredictOn = enabled; + if (meLanguage == KR) mpManager->getPCKeyboard()->refreshState(); + } + tistring::Decolated::TranslateMode fixedMode = mpString->getTranslateMode(); + tistring::Decolated::TranslateMode unfixMode = mpUnfixString->getTranslateMode(); + mpString->initKanaConverter(); + mpUnfixString->initKanaConverter(); + if (meLanguage == KR) { + if (fixedMode != tistring::Decolated::TM_Direct) fixedMode = tistring::Decolated::TM_Hangul; + } else if (meLanguage == CN) fixedMode = tistring::Decolated::TM_Direct; + mpString->getCursorPos(); + mpString->setTranslateMode(fixedMode); + mpString->getCursorPos(); + mpUnfixString->setTranslateMode(unfixMode); + switch (mePredictMode) { + case PM_Atok: + if (!mbPredictOn) { + if (mpUnfixString->isDictionaryOpened() && current == mpUnfixString) { + mpUnfixString->confirm(NULL); + wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); + mpString->getCursorPos(); + mpString->confirm(confirmed); + mpString->getCursorPos(); + mpUnfixString->enableConfirmedString(false); + } + } else resetInputRelation(); + return; + case PM_USEn: mpZiString->setPredictLaunguage(static_cast(0)); break; + case PM_USFr: mpZiString->setPredictLaunguage(static_cast(1)); break; + case PM_USSp: mpZiString->setPredictLaunguage(static_cast(2)); break; + case PM_En: mpZiString->setPredictLaunguage(static_cast(3)); break; + case PM_De: mpZiString->setPredictLaunguage(static_cast(4)); break; + case PM_Fr: mpZiString->setPredictLaunguage(static_cast(5)); break; + case PM_Sp: mpZiString->setPredictLaunguage(static_cast(6)); break; + case PM_It: mpZiString->setPredictLaunguage(static_cast(7)); break; + case PM_Nl: mpZiString->setPredictLaunguage(static_cast(8)); break; + case PM_11: mpZiString->setPredictLaunguage(static_cast(9)); break; + case PM_12: + mpZiString->setPredictLaunguage(static_cast(mpManager->getToolBar()->isQwerty() ? 10 : 11)); + break; + } + onCommand(static_cast(30), NULL); + return; + } + case 30: { + mpUnfixString->confirm(NULL); + wchar_t* confirmed = mpUnfixString->getConfirmedWCString(); + mpString->getCursorPos(); + mpString->confirm(confirmed); + mpString->getCursorPos(); + mpUnfixString->enableConfirmedString(false); + mpZiString->clearCandidates(); + mbZuSelected = false; + getCurrentString(false); + resetPredictionContext(); + resetCandidate(); + return; + } + case 31: { + PredictionState* prediction = static_cast(data); + prediction->mode = mePredictMode; + prediction->enabled = mbPredictOn; + return; + } + case 32: *static_cast(data) = hasZiPredictions(); return; + case 36: { + u32 length = *static_cast(data); + if (length < fixed->getLength()) mpString->getLength(); + mpString->setLength(static_cast(length)); + return; + } + case 38: { + ControlInput* input = static_cast(data); + onHKBCtrlCode(input->code, input->modifiers); + return; + } + case 39: mDKStream.clear(); return; + case 41: notifyChangeMode(); return; + case 42: onPressLeftHWKB(); return; + case 43: onPressRightHWKB(); return; + case 44: onPressUp(); return; + case 45: onPressDownHWKB(); return; + case 46: + if (meLanguage == CN && !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 47: return; + default: break; + } + 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); + } + } + break; + case 18: + if (mePredictMode == PM_Atok) { + if (mpManager->getPCKeyboard()->getTranslateMode() == keyboard::pctype::Base::TM_00 && !mbPredictOn) { + if (!mpManager->getPCKeyboard()->isQwertyOnly()) onSE(static_cast(6)); + } 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; + } +} + +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) {} + +void LayoutByNW4R::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_* selected = &mriManager.mpInfo[mriManager.mpInfo[mriManager.mMaxLength].Next]; + u16 previous = selected->Back; + u16 next = selected->Next; + u16 selectedIndex = mriManager.mpInfo[next].Back; + mriManager.mpInfo[next].Back = previous; + mriManager.mpInfo[previous].Next = next; + selected->Back = selectedIndex; + selected->Next = selectedIndex; + Info_* listEnd = &mriManager.mpInfo[mriManager.mpInfo[static_cast(mriManager.mMaxLength + 1)].Back]; + next = listEnd->Next; + selected->Back = mriManager.mpInfo[next].Back; + selected->Next = next; + listEnd->Next = selectedIndex; + mriManager.mpInfo[next].Back = selectedIndex; + selected->StrCount = 0; + selected->DispRowCount = 1; + mpCursorLine = selected; + void* handlerMemory = MEMAllocFromAllocator(allocator, sizeof(EventHandler)); + mpInputEventHandler = handlerMemory ? new (handlerMemory) EventHandler(this) : NULL; + 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 = static_cast(mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true)); + 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(0); + setVisible("N_2line", true); + mpPaneManager->setAllComponentTriggerTarget(false); + mpPaneManager->setAllBoundingBoxComponentTriggerTarget(true); + nw4r::lyt::Pane* pane = mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLanguageData)->textBox, true); + if (!pane) pane = mpLayout->GetRootPane()->FindPaneByName(getLanguageTextPane() ? static_cast(mpLanguageData)->textBox : "T_2l_TextBox", true); + mpPaneManager->getPaneComponentByPane(pane)->setTriggerTarget(true); + for (u32 buttonIndex = 0; buttonIndex < 2; ++buttonIndex) { + nw4rmanager::AnmPane* animationPane = NULL; + if (csButtonAnimations[static_cast(buttonIndex)].type == KT_NormalButton) { + void* memory = MEMAllocFromAllocator(allocator, sizeof(NormalButtonAnmPane)); + if (memory) animationPane = new (memory) NormalButtonAnmPane(getPane(csButtonAnimations[static_cast(buttonIndex)].paneName), NULL); + } + nw4r::ut::List_Append(&mAnmPanes, animationPane); + const char* bindingName = csButtonAnimations[static_cast(buttonIndex)].bindingName; + u32 count = csButtonAnimations[static_cast(buttonIndex)].count; + for (u16 animationIndex = 0; animationIndex < count; ++animationIndex) { + const InputFormAnimationFile* file = csButtonAnimations[static_cast(buttonIndex)].files[animationIndex]; + void* resource = mpMultiArcResourceAccessor->GetResource(0, file->fileName, NULL); + AnimTransformPane* transform = static_cast(getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor)); + if (!bindingName) animationPane->addAnimation(allocator, file->id, transform, false, true); + else animationPane->forceAddAnimation(allocator, file->id, transform, bindingName, false, true); + } + } + init(); +} +inline const nw4r::lyt::Pane* LayoutByNW4R::getLanguageTextPane() const { + return getPane(static_cast(mpLanguageData)->textBox); +} + +void LayoutByNW4R::init() { + Base::init(); + searchAnmPane("P_txtScrll_UP")->changeAnimation(7); + searchAnmPane("P_txtScrll_DOWN")->changeAnimation(7); + mbUpVisible = false; + mbDownVisible = false; + mUpRepeat = 0; + mDownRepeat = 0; + mLeftRepeat = 0; + mRightRepeat = 0; + mRepeatButtons = 0; + mCharColor = csCharColor; + visibleSeparator(false); + nw4r::lyt::TextBox* textBox = static_cast(mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true)); + 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); +} extern "C" const char lbl_8165D2A0[] = "N_separateBarAll"; -extern "C" const char lbl_8165D2B0[] = "T_title_text"; -extern "C" const char lbl_8165D2C0[] = "OutOfLength\n"; -extern "C" const char lbl_8165D2D0[] = "Error#004\nAn error has occurred.\nThe system files are corrupted."; +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(getLanguageTextPane() ? static_cast(mpLanguageData)->textBox : "T_2l_TextBox", 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(getLanguageTextPane() ? static_cast(mpLanguageData)->textBox : "T_2l_TextBox", 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(static_cast(8)); + } + if (!mpString->isKanaFix()) limit = muLimitStringLength - 1; + } + if (limit < mpString->getLength()) { + u32 start, end; + mpString->getCursorPos(&start, &end); + if (start > limit || end > limit) { + onSE(static_cast(8)); + 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(static_cast(8)); + } + } + 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(static_cast(8)); + Base::onCommand(static_cast(36), &rowLimit); + if (meLanguage == KR && !mpString->isKanaFix()) { + rowLimit = isOverRowLimit(muLimitRowNum, mpString->getWCString()); + if (rowLimit) mpString->clearKana(); + } + } +} + + #pragma pop -enum Animation { - ANM_Normal -}; - -enum KeyType { - KT_NormalButton -}; - -class AnmPane : public nw4rmanager::AnmPane { -public: - virtual void init(); - virtual void changeAnimation(u32 id); - virtual KeyType getKeyType() const; - virtual Animation getState(); - -protected: - Animation meState; - KeyType meKeyType; -}; - -class NormalButtonAnmPane : public AnmPane { -public: - virtual ~NormalButtonAnmPane(); -}; - -class EventHandler : public nw4rmanager::TiEventHandler { -public: - virtual ~EventHandler(); -}; +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 == 4 && (input->trigger & 0x800) && !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 == 2 && (input->hold & 0x800) && !(input->trigger & 0x800)) { + 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 1: animation->onAnmEvent(nw4rmanager::AnmPane::PE_2); break; + case 0: + if (animation->getState() != ANM_Off) { + mpEventObserver->onSE(static_cast(4)); + animation->onAnmEvent(nw4rmanager::AnmPane::PE_1); + } + break; + } + } + } else if (name[0] == 'P') { + AnmPane* animation = static_cast(mpInputForm->searchAnmPane(name)); + if (animation) { + switch (event) { + case 0: + if (animation->getState() != ANM_Off) { + mpEventObserver->onSE(static_cast(4)); + animation->onAnmEvent(nw4rmanager::AnmPane::PE_1); + } + break; + case 1: + if (animation->getState() != ANM_Off) { + mpEventObserver->onSE(static_cast(4)); + 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 == 4 && (input->trigger & 0x800)) mpInputForm->onCommand(static_cast(14), &cursor); + if (event == 5 && (input->release & 0x800)) mpInputForm->onCommand(static_cast(15), &cursor); + if (event == 2 && (input->hold & 0x800)) mpInputForm->onCommand(static_cast(16), &cursor); + } + } +} void Base::enableSpaceByRight(bool rightWithSpace) { mbRightWithSpace = rightWithSpace; @@ -1623,30 +2359,22 @@ autoScroll_Lend: blr } -extern "C" asm void startAnm__Q39textinput4util9AnimationFfffPQ39textinput4util12AnimObserverPv() { - nofralloc - lfs f0, lbl_81694D28(r0) - li r6, 1 - li r0, 0 - cmpwi r4, 0 - stfs f1, 4(r3) - stfs f2, 8(r3) - stfs f3, 0x10(r3) - stfs f0, 0xc(r3) - stb r6, 0x14(r3) - stw r4, 0x18(r3) - stw r5, 0x1c(r3) - stb r0, 0x15(r3) - beqlr - mr r3, r4 - li r4, 0 - lwz r12, 0(r3) - lwz r12, 8(r12) - mtctr r12 - bctr - blr } +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 { + extern "C" asm void deselectCandidate__Q39textinput9inputform4BaseFv() { nofralloc lbz r0, 0x178(r3) @@ -2542,6 +3270,565 @@ moveCursorDown_L4: blr } +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(static_cast(9)); + 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(static_cast(10)); + } +} + +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(static_cast(9)); + } 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; + if (!mbPredictOn) 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(static_cast(6)); + 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(static_cast(6)); + } + } 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()) { + if (!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(static_cast(6)); + } + } 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()) { + if (!current->isKanaFix()) return; + mpManager->getHWKeyboard()->resetQuoteState(); + mpUnfixString->resetRelation(); + updateCandidateState_(); + if (mpUnfixString->getCandidate() != L' ') { + moveCursorDown(); + onCommand(static_cast(47), NULL); + } + } + } +} + +void Base::onPressDownHWKB() { + tistring::Decolated* current = getCurrentString(false); + s32 selected; + 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()) { + if (!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(static_cast(6)); + } + } + } else { + if (mpUnfixString->getInputStringLength()) { + mpUnfixString->startConverting(); + updateCandidateState_(); + moveCandidateToIdx(0); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + onCommand(static_cast(47), NULL); + } + } + } +} + +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()) return; + switch (current->isKanaFix()) { + case true: break; + default: return; + } + mpManager->getHWKeyboard()->resetQuoteState(); + mpUnfixString->resetRelation(); + updateCandidateState_(); + if (current->moveCursorLeft()) onSE(static_cast(5)); + else onSE(static_cast(6)); + } 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(static_cast(6)); + } 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(static_cast(6)); + } + 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()) return; + switch (current->isKanaFix()) { + case true: break; + default: return; + } + mpManager->getHWKeyboard()->resetQuoteState(); + mpUnfixString->resetRelation(); + updateCandidateState_(); + if (current->moveCursorRight()) onSE(static_cast(6)); + else onSE(static_cast(5)); + } else if (current == mpUnfixString) { + if (mpManager->getCandidateBox()->isInScroll()) return; + if (mpUnfixString->getCurrentNumPredicted() <= 0) return; + if (mpUnfixString->isConverting()) { + current->moveCursorRight(); + onSE(static_cast(6)); + updateCandidateState_(); + } else { + s32 selected = static_cast(mpUnfixString->getSelectedCandidate() + 1); + if (selected >= mpUnfixString->getCurrentNumPredicted()) selected = 0; + moveCandidateToIdx(selected); + mpManager->getCandidateBox()->getTextArea().ScrollToSelectedText(); + onSE(static_cast(6)); + } + } 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(static_cast(6)); + } + meScrollFlag = SF_ScrollOn; +} + extern "C" asm void onPressLeft__Q39textinput9inputform4BaseFv() { nofralloc stwu r1, -0x10(r1) @@ -3087,42 +4374,12 @@ calc_L7: blr } -extern "C" asm void __dt__Q39textinput9inputform4BaseFv() { - nofralloc - stwu r1, -0x10(r1) - mflr r0 - cmpwi r3, 0 - stw r0, 0x14(r1) - stw r31, 0xc(r1) - mr r31, r4 - stw r30, 8(r1) - mr r30, r3 - beq baseDestructor_L1 - addic. r0, r3, 0x1f8 - beq baseDestructor_L2 - lwz r3, 0x200(r3) - lwz r4, 0x1f8(r30) - bl MEMFreeToAllocator -baseDestructor_L2: - addic. r3, r30, 0x10 - beq baseDestructor_L3 - li r4, 0 - bl __dt__Q34nw4r2ut10CharWriterFv -baseDestructor_L3: - cmpwi r31, 0 - ble baseDestructor_L1 - mr r3, r30 - bl __dl__FPv -baseDestructor_L1: - mr r3, r30 - lwz r31, 0xc(r1) - lwz r30, 8(r1) - lwz r0, 0x14(r1) - mtlr r0 - addi r1, r1, 0x10 - blr +Base::RowInfoManager::~RowInfoManager() { + MEMFreeToAllocator(mpAllocator, mpInfo); } +Base::~Base() {} + extern "C" asm void __ct__Q39textinput9inputform4BaseFPQ29textinput7Manager() { nofralloc stwu r1, -0x20(r1) @@ -3259,239 +4516,76 @@ extern "C" asm void __ct__Q39textinput9inputform4BaseFPQ29textinput7Manager() { blr } -extern "C" asm void EnableKSXFilter__Q39textinput8tistring9DecolatedFb() { - nofralloc - blr -} -extern "C" asm void backSpace__Q39textinput8tistring8WithAtokFv() { - nofralloc - blr -} -extern "C" asm void changeKanaMode__Q39textinput8tistring8WithAtokFb() { - nofralloc - blr -} -extern "C" asm void closeDictionary__Q39textinput8tistring8WithAtokFv() { - nofralloc - blr -} -extern "C" asm void commitPredicted__Q39textinput8tistring8WithAtokFi() { - nofralloc - blr -} -extern "C" asm void confirm__Q39textinput8tistring8WithAtokFPCw() { - nofralloc - blr -} -extern "C" asm void deleteChar__Q39textinput8tistring9DecolatedFv() { - nofralloc - blr -} -extern "C" asm void enableConfirmedString__Q39textinput8tistring8WithAtokFb() { - nofralloc - blr -} -extern "C" asm void getCursorPos__Q39textinput8tistring8WithAtokFPUlPUl() { - nofralloc - blr -} -extern "C" asm void getDrawString__Q39textinput8tistring8WithAtokFRQ49textinput8tistring8WithAtok8DrawInfo() { - nofralloc - blr -} -extern "C" asm void getPredicted__Q39textinput8tistring8WithAtokFiPw() { - nofralloc - blr -} -extern "C" asm void initConverting__Q39textinput8tistring8WithAtokFv() { - nofralloc - blr -} + + + + + + + + + + + + extern "C" asm void init__Q29textinput4BaseFv() { nofralloc blr } -extern "C" asm void init__Q39textinput8tistring8WithAtokFv() { - nofralloc - blr -} -extern "C" asm void inputChar__Q39textinput8tistring8WithAtokFw() { - nofralloc - blr -} -extern "C" asm void openDictionary__Q39textinput8tistring8WithAtokFPviPviPvi() { - nofralloc - blr -} -extern "C" asm void popBack__Q39textinput8tistring8WithAtokFv() { - nofralloc - blr -} -extern "C" asm void pushBack__Q39textinput8tistring8WithAtokFw() { - nofralloc - blr -} -extern "C" asm void resetRelation__Q39textinput8tistring8WithAtokFv() { - nofralloc - blr -} -extern "C" asm void setDefaultPrediction__Q39textinput8tistring8WithAtokFiPPCc() { - nofralloc - blr -} -extern "C" asm void setFixMode__Q39textinput8tistring8WithAtokFb() { - nofralloc - blr -} -extern "C" asm void setFixPrediction__Q39textinput8tistring8WithAtokFiPPCc() { - nofralloc - blr -} -extern "C" asm void setFix__Q39textinput8tistring8WithAtokFb() { - nofralloc - blr -} -extern "C" asm void setInputting__Q39textinput8tistring8WithAtokFw() { - nofralloc - blr -} -extern "C" asm void setSelectedCandidate__Q39textinput8tistring8WithAtokFl() { - nofralloc - blr -} -extern "C" asm void startConverting__Q39textinput8tistring8WithAtokFv() { - nofralloc - blr -} -extern "C" asm void dirtyDrawCache__Q39textinput10textdrawer4BaseFv() { - nofralloc - li r0, 0 - stb r0, 0xe4(r3) - blr -} -extern "C" asm void dirtyCursorCache__Q39textinput10textdrawer4BaseFv() { - nofralloc - li r0, 0 - stb r0, 0x104(r3) - blr -} -extern "C" asm void getCursorPos__Q39textinput8tistring9DecolatedCFv() { - nofralloc - lwz r3, 0x18(r3) - blr -} -extern "C" asm void getCellPhoneKeyboard__Q29textinput7ManagerFv() { - nofralloc - lwz r3, 0x18(r3) - blr -} -extern "C" asm void isConverting__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} + + + + + + + + + + + + + + + + + + extern "C" asm void getLine__Q39textinput10textdrawer4BaseFv() { nofralloc lwz r3, 0xa0(r3) addi r3, r3, 1 blr } -extern "C" asm void getSelectedConverting__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr + + + + + + + + + + + + } -extern "C" asm void isOnSustain__Q39textinput8tistring9DecolatedFv() { - nofralloc - lbz r3, 0x20(r3) - blr -} -extern "C" asm void setSelectedCandidate__Q39textinput8tistring6WithZiFl() { - nofralloc - stw r4, 0x98(r3) - blr -} -extern "C" asm void isDictionaryOpened__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void getConfirmedWCString__Q39textinput8tistring8WithAtokCFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void setPredictLaunguage__Q39textinput8tistring6WithZiFQ49textinput8tistring6WithZi15PredictLanguage() { - nofralloc - stw r4, 0x9c(r3) - blr -} -extern "C" asm void hasConfirmedString__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void getCurrentNumPredicted__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void getCurrentNumPredicted__Q39textinput8tistring6WithZiFv() { - nofralloc - lwz r3, 0x8c(r3) - blr -} -extern "C" asm void getDrawModifyEndLine__Q39textinput10textdrawer4BaseCFv() { - nofralloc - lwz r3, 0xd0(r3) - blr -} -extern "C" asm void getEndPos__Q39textinput10textdrawer4BaseCFv() { - nofralloc - lwz r3, 0xc0(r3) - blr -} -extern "C" asm void getLength__Q39textinput8tistring10StringBaseCFv() { - nofralloc - lhz r3, 0x6(r3) - blr -} -extern "C" asm void isActive__Q39textinput4util9AnimationFv() { - nofralloc - lbz r3, 0x14(r3) - blr + +bool textinput::util::Animation::isActive() { + return mbInAnimation; } + +namespace inputform { extern "C" asm void getKanaBuffer__Q39textinput8tistring9DecolatedFv() { nofralloc addi r3, r3, 0x42 blr } -extern "C" asm void getCandidate__Q39textinput8tistring10StringBaseCFv() { - nofralloc - lhz r3, 0x10(r3) - blr -} -extern "C" asm void getInputStringLength__Q39textinput8tistring6WithZiFv() { - nofralloc - lhz r3, 0x88(r3) - blr -} -extern "C" asm void isCandidateSelected__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void getSelectedCandidate__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void isInvalid__Q39textinput12candidatebox4BaseCFv() { - nofralloc - lbz r3, 0x19(r3) - blr -} + + + + + extern "C" asm void hasCandidate__Q39textinput8tistring10StringBaseCFv() { nofralloc lhz r3, 0x10(r3) @@ -3500,119 +4594,56 @@ extern "C" asm void hasCandidate__Q39textinput8tistring10StringBaseCFv() { srwi r3, r0, 31 blr } -extern "C" asm void setCandidate__Q39textinput8tistring10StringBaseFw() { - nofralloc - sth r4, 0x10(r3) - blr -} -extern "C" asm void changeLetterMode__Q39textinput8tistring6WithZiFQ49textinput8tistring6WithZi10LetterMode() { - nofralloc - stw r4, 0xa0(r3) - blr -} -extern "C" asm void setCellPhoneHoldingkey__Q39textinput8tistring6WithZiFPv() { - nofralloc - stw r4, 0xa4(r3) - blr -} -extern "C" asm void isFix__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 1 - blr -} -extern "C" asm void getCandidateBox__Q29textinput7ManagerCFv() { - nofralloc - lwz r3, 0x20(r3) - blr -} -extern "C" asm void getFixedPredictionNum__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void getInputStringLength__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr -} -extern "C" asm void getHWKeyboard__Q29textinput7ManagerFv() { - nofralloc - lwz r3, 0x10(r3) - blr -} + + + + + + + + extern "C" asm void create__Q39textinput9inputform4BaseFP12MEMAllocator() { nofralloc blr } -extern "C" asm void getDrawModifyStartLine__Q39textinput10textdrawer4BaseCFv() { - nofralloc - lwz r3, 0xcc(r3) - blr -} -extern "C" asm void getStartPos__Q39textinput10textdrawer4BaseCFv() { - nofralloc - lwz r3, 0xbc(r3) - blr -} + extern "C" asm void setVIWidth__Q39textinput10textdrawer4BaseFf() { nofralloc stfs f1, 0x98(r3) blr } -extern "C" asm void setCandidateBox__Q39textinput12candidatebox18CandidateBoxCallerFPQ39textinput12candidatebox4Base() { - nofralloc - stw r4, 4(r3) - blr + + + } -extern "C" asm void moveCursorLeft__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr + +void textinput::util::Animation::stop() { + mbInAnimation = false; } -extern "C" asm void moveCursorRight__Q39textinput8tistring8WithAtokFv() { - nofralloc - li r3, 0 - blr + +namespace inputform { } -extern "C" asm void stop__Q39textinput4util9AnimationFv() { - nofralloc - li r0, 0 - stb r0, 0x14(r3) - blr + +bool textinput::util::Animation::isSEFlag() { + return mbSE; } -extern "C" asm void isSEFlag__Q39textinput4util9AnimationFv() { - nofralloc - lbz r3, 0x15(r3) - blr + +namespace inputform { } -extern "C" asm void setSEFlag__Q39textinput4util9AnimationFb() { - nofralloc - stb r4, 0x15(r3) - blr + +void textinput::util::Animation::setSEFlag(bool flag) { + mbSE = flag; } -extern "C" asm void getValue__Q39textinput4util9AnimationFv() { - nofralloc - lfs f2, lbl_81694D28(r0) - lfs f1, 0xc(r3) - fmr f4, f2 - lfs f3, 0x4(r3) - fmr f7, f2 - lfs f5, 0x10(r3) - lfs f6, 0x8(r3) - b hermiteInterporation__Q29textinput4utilFfffffff + +namespace inputform { } -extern "C" asm u32 getDrawCacheStartPos__Q39textinput10textdrawer4BaseCFv() { - nofralloc - lbz r0, 0xe4(r3) - cmpwi r0, 0 - beq getDrawCacheStartPos_L1 - lwz r3, 0xdc(r3) - blr -getDrawCacheStartPos_L1: - lis r3, 0x8000 - subi r3, r3, 1 - blr + +f32 textinput::util::Animation::getValue() { + return hermiteInterporation(mfCurrentFrame, 0.0f, mfStartPoint, 0.0f, mfAnimationTime, mfEndPoint, 0.0f); } + +namespace inputform { + extern "C" asm void onSE__Q39textinput9inputform12LayoutByNW4RFQ39textinput5sound2SE() { nofralloc lwz r3, 0x22c(r3) @@ -3729,45 +4760,30 @@ isKanaFix_L2: addi r1, r1, 0x10 blr } -extern "C" asm void calc__Q39textinput4util9AnimationFv() { - nofralloc - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - stw r31, 0xc(r1) - mr r31, r3 - lbz r0, 0x14(r3) - cmpwi cr1, r0, 0 - beq cr1, calc_Animation_L4 - lfs f1, 0xc(r3) - lfs f0, 0x10(r3) - fcmpo cr0, f1, f0 - bge calc_Animation_L1 - lfs f0, lbl_81694D38(r0) - fadds f0, f0, f1 - stfs f0, 0xc(r3) - b calc_Animation_L4 -calc_Animation_L1: - beq cr1, calc_Animation_L3 - lwz r3, 0x18(r3) - cmpwi r3, 0 - beq calc_Animation_L3 - lwz r12, 0(r3) - li r4, 1 - lwz r5, 0x1c(r31) - lwz r12, 8(r12) - mtctr r12 - bctrl -calc_Animation_L3: - li r0, 0 - stb r0, 0x14(r31) -calc_Animation_L4: - lwz r0, 0x14(r1) - lwz r31, 0xc(r1) - mtlr r0 - addi r1, r1, 0x10 - blr } + +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 { extern "C" asm void set__Q39textinput8tistring9DecolatedFPCw() { nofralloc stwu r1, -0x10(r1) @@ -3857,162 +4873,22 @@ init_RowInfo_L1: sth r0, 2(r4) blr } -asm nw4r::math::VEC2 LayoutByNW4R::getScale() const { - nofralloc - stwu r1, -0x10(r1) - mflr r0 - lwz r6, 0x21c(r3) - li r5, 1 - stw r0, 0x14(r1) - lwz r4, 0x2c0(r3) - lwz r3, 0x10(r6) - lwz r12, 0(r3) - lwz r12, 0x3c(r12) - mtctr r12 - bctrl - lwz r0, 0x14(r1) - mr r4, r3 - lwz r3, 0x44(r3) - lwz r4, 0x48(r4) - mtlr r0 - addi r1, r1, 0x10 - blr +nw4r::math::VEC2 LayoutByNW4R::getScale() const { + return mpLayout->GetRootPane()->FindPaneByName(static_cast(mpLayoutData), true)->GetScale(); } -extern "C" asm void __dt__Q39textinput9inputform12LayoutByNW4RFv() { - nofralloc - stwu r1, -0x20(r1) - mflr r0 - cmpwi r3, 0 - stw r0, 0x24(r1) - stw r31, 0x1c(r1) - stw r30, 0x18(r1) - mr r30, r4 - stw r29, 0x14(r1) - mr r29, r3 - beq __dt_Layout_L1 - lwz r7, 0x2d0(r3) - lis r6, __vt__Q39textinput9inputform12LayoutByNW4R@ha - addi r6, r6, __vt__Q39textinput9inputform12LayoutByNW4R@l - addi r5, r6, 0x20 - cmpwi r7, 0 - addi r4, r6, 0xb8 - addi r0, r6, 0x1a8 - stw r6, 0(r3) - stw r5, 0x5c(r3) - stw r4, 0x118(r3) - stw r0, 0x218(r3) - beq __dt_Layout_L2 - lwz r12, 0(r7) - mr r3, r7 - li r4, -1 - lwz r12, 8(r12) - mtctr r12 - bctrl - lwz r3, 0x1d0(r29) - lwz r4, 0x2d0(r29) - bl MEMFreeToAllocator -__dt_Layout_L2: - addi r3, r29, 0x284 - li r4, 0 - bl List_GetNext__Q24nw4r2utFPCQ34nw4r2ut4ListPCv - mr r31, r3 - b __dt_Layout_L4 -__dt_Layout_L3: - mr r4, r31 - addi r3, r29, 0x284 - bl List_Remove__Q24nw4r2utFPQ34nw4r2ut4ListPv - lwz r4, 0x1d0(r29) - mr r3, r31 - bl destroy__Q39textinput11nw4rmanager7AnmPaneFP12MEMAllocator - addi r3, r29, 0x284 - li r4, 0 - bl List_GetNext__Q24nw4r2utFPCQ34nw4r2ut4ListPCv - mr r31, r3 -__dt_Layout_L4: - cmpwi r31, 0 - bne __dt_Layout_L3 - addi r3, r29, 0x2d4 - li r4, -1 - bl __dt__Q34nw4r2ut7ResFontFv - addi r3, r29, 0x218 - li r4, 0 - bl __dt__Q39textinput11nw4rmanager6LayoutFv - cmpwi r29, 0 - beq __dt_Layout_L5 - addic. r0, r29, 0x1f8 - beq __dt_Layout_L6 - lwz r3, 0x200(r29) - lwz r4, 0x1f8(r29) - bl MEMFreeToAllocator -__dt_Layout_L6: - addic. r3, r29, 0x10 - beq __dt_Layout_L5 - li r4, 0 - bl __dt__Q34nw4r2ut10CharWriterFv -__dt_Layout_L5: - cmpwi r30, 0 - ble __dt_Layout_L1 - mr r3, r29 - bl __dl__FPv -__dt_Layout_L1: - lwz r31, 0x1c(r1) - mr r3, r29 - lwz r30, 0x18(r1) - lwz r29, 0x14(r1) - lwz r0, 0x24(r1) - mtlr r0 - addi r1, r1, 0x20 - blr -} -extern "C" asm void __ct__Q39textinput9inputform12LayoutByNW4RFPQ29textinput7ManagerPQ34nw4r3lyt24MultiArcResourceAccessorPCcPQ29textinput13EventObserverPCc() { - nofralloc - stwu r1, -0x20(r1) - mflr r0 - stw r0, 0x24(r1) - addi r11, r1, 0x20 - bl _savegpr_27 - mr r27, r3 - mr r28, r5 - mr r29, r6 - mr r30, r7 - mr r31, r8 - bl __ct__Q39textinput9inputform4BaseFPQ29textinput7Manager - mr r4, r28 - mr r5, r29 - mr r6, r30 - addi r3, r27, 0x218 - bl __ct__Q39textinput11nw4rmanager6LayoutFPQ34nw4r3lyt24MultiArcResourceAccessorPCcPQ29textinput13EventObserver - lis r6, __vt__Q39textinput9inputform12LayoutByNW4R@ha - li r0, 0 - addi r6, r6, __vt__Q39textinput9inputform12LayoutByNW4R@l - lis r5, lbl_8165CBE0@ha - lis r4, csLanguageDependencyDataUEJ__Q29textinput9inputform@ha - stw r6, 0(r27) - addi r3, r6, 0x20 - addi r7, r6, 0xb8 - addi r6, r6, 0x1a8 - addi r5, r5, lbl_8165CBE0@l - addi r4, r4, csLanguageDependencyDataUEJ__Q29textinput9inputform@l - stw r3, 0x5c(r27) - addi r3, r27, 0x2d4 - stw r7, 0x118(r27) - stw r6, 0x218(r27) - stw r5, 0x2c0(r27) - stw r4, 0x2c4(r27) - stw r31, 0x2c8(r27) - stb r0, 0x2cc(r27) - stb r0, 0x2cd(r27) - stb r0, 0x2ce(r27) - stw r0, 0x2d0(r27) - bl __ct__Q34nw4r2ut7ResFontFv - addi r11, r1, 0x20 - mr r3, r27 - bl _restgpr_27 - lwz r0, 0x24(r1) - mtlr r0 - addi r1, r1, 0x20 - blr +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)); + } } + extern "C" asm void create__Q39textinput9inputform10EditBufferFP12MEMAllocator() { nofralloc stwu r1, -0x20(r1) @@ -4330,93 +5206,32 @@ updateRepeatInput_L9: stw r0, 0x2fc(r3) blr } -extern "C" asm void ToCombineClass__Q39textinput9inputform13DeadKeyStreamFQ29textinput8Languagew() { - nofralloc - cmpwi r3, 5 - beq ToCombineClass_L9 - bge ToCombineClass_L1 - cmpwi r3, 3 - beq ToCombineClass_L2 - bge ToCombineClass_L3 - b ToCombineClass_L9 -ToCombineClass_L1: - cmpwi r3, 7 - beq ToCombineClass_L8 - bge ToCombineClass_L9 - b ToCombineClass_L4 -ToCombineClass_L3: - cmplwi r4, 0xb4 - bne ToCombineClass_L3a - li r3, 0x301 - blr -ToCombineClass_L3a: - cmplwi r4, 0x60 - bne ToCombineClass_L9 - li r3, 0x300 - blr -ToCombineClass_L2: - cmplwi r4, 0x5e - bne ToCombineClass_L2a - li r3, 0x302 - blr -ToCombineClass_L2a: - cmplwi r4, 0xa8 - bne ToCombineClass_L9 - li r3, 0x308 - blr -ToCombineClass_L4: - cmplwi r4, 0x60 - bne ToCombineClass_L4a - li r3, 0x300 - blr -ToCombineClass_L4a: - cmplwi r4, 0xb4 - bne ToCombineClass_L4b - li r3, 0x301 - blr -ToCombineClass_L4b: - cmplwi r4, 0x5e - bne ToCombineClass_L4c - li r3, 0x302 - blr -ToCombineClass_L4c: - cmplwi r4, 0x7e - bne ToCombineClass_L4d - li r3, 0x303 - blr -ToCombineClass_L4d: - cmplwi r4, 0xa8 - bne ToCombineClass_L9 - li r3, 0x308 - blr -ToCombineClass_L8: - cmplwi r4, 0x60 - bne ToCombineClass_L8a - li r3, 0x300 - blr -ToCombineClass_L8a: - cmplwi r4, 0x5e - bne ToCombineClass_L8b - li r3, 0x302 - blr -ToCombineClass_L8b: - cmplwi r4, 0x7e - bne ToCombineClass_L8c - li r3, 0x303 - blr -ToCombineClass_L8c: - cmplwi r4, 0x27 - bne ToCombineClass_L8d - li r3, 0x30d - blr -ToCombineClass_L8d: - cmplwi r4, 0x22 - bne ToCombineClass_L9 - li r3, 0x30e - blr -ToCombineClass_L9: - mr r3, r4 - blr +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; } extern "C" asm void init__Q39textinput3gui12GUIComponentFv() { nofralloc @@ -4476,115 +5291,37 @@ extern "C" asm void init__Q39textinput3gui12GUIComponentFv() { blr } -asm bool Base::isEditMode() { - nofralloc - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - lwz r0, 0x174(r3) - cmpwi r0, 2 - bge isEditMode_L1 - cmpwi r0, 0 - bge isEditMode_L2 -isEditMode_L1: - lwz r3, 0x16c(r3) - lwz r12, 0(r3) - lwz r12, 0xec(r12) - mtctr r12 - bctrl - cmpwi r3, 0 - bne isEditMode_L2 - li r3, 0 - b isEditMode_L3 -isEditMode_L2: - li r3, 1 -isEditMode_L3: - lwz r0, 0x14(r1) - mtlr r0 - addi r1, r1, 0x10 - blr +bool Base::isEditMode() { + switch (mePredictMode) { + case PM_Off: + case PM_Atok: + break; + default: + if (!mpZiString->isFix()) return false; + break; + } + return true; } -asm bool Base::checkHeadOfSentence(bool checkSpace) { - nofralloc - stwu r1, -0x20(r1) - mflr r0 - stw r0, 0x24(r1) - addi r5, r1, 8 - stw r31, 0x1c(r1) - stw r30, 0x18(r1) - mr r30, r4 - li r4, 0x20 - stw r29, 0x14(r1) - mr r29, r3 - lwz r12, 0(r3) - lwz r12, 0x18(r12) - mtctr r12 - bctrl - lbz r0, 8(r1) - cmpwi r0, 0 - beq checkHeadOfSentence_L1 - li r3, 0 - b checkHeadOfSentence_L7 -checkHeadOfSentence_L1: - lwz r3, 0x164(r29) - li r31, 0 - lwz r12, 0(r3) - lwz r12, 0x7c(r12) - mtctr r12 - bctrl - cmplwi r3, 1 - bge checkHeadOfSentence_L2 - li r3, 1 - b checkHeadOfSentence_L7 -checkHeadOfSentence_L2: - cmpwi r30, 0 - beq checkHeadOfSentence_L5 - lwz r3, 0x164(r29) - lwz r12, 0(r3) - lwz r12, 0x90(r12) - mtctr r12 - bctrl - clrlwi r0, r3, 0x10 - cmpwi r0, 0x20 - beq checkHeadOfSentence_L4 - bge checkHeadOfSentence_L3 - cmpwi r0, 0xa - beq checkHeadOfSentence_L4 -checkHeadOfSentence_L3: - li r3, 0 - b checkHeadOfSentence_L7 -checkHeadOfSentence_L4: - lwz r3, 0x164(r29) - lwz r12, 0(r3) - lwz r12, 0x68(r12) - mtctr r12 - bctrl - mr r31, r3 -checkHeadOfSentence_L5: - lwz r3, 0x164(r29) - lwz r12, 0(r3) - lwz r12, 0xb4(r12) - mtctr r12 - bctrl - cmpwi r31, 0 - mr r31, r3 - beq checkHeadOfSentence_L6 - lwz r3, 0x164(r29) - lwz r12, 0(r3) - lwz r12, 0x64(r12) - mtctr r12 - bctrl -checkHeadOfSentence_L6: - mr r3, r31 -checkHeadOfSentence_L7: - lwz r0, 0x24(r1) - lwz r31, 0x1c(r1) - lwz r30, 0x18(r1) - lwz r29, 0x14(r1) - mtlr r0 - addi r1, r1, 0x20 - blr +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) { @@ -4600,41 +5337,20 @@ void Base::limitStringLength(u32 limitStringLength) { muLimitStringLength = limitStringLength; } -asm void Base::setAtokDictionary(void*, int, void*, int, void*, int) { - nofralloc - lwz r3, 0x168(r3) - lwz r12, 0(r3) - lwz r12, 0x108(r12) - mtctr r12 - bctr +void Base::setAtokDictionary(void* atok, int atokSize, void* apot, int apotSize, void* nintendo, int nintendoSize) { + mpUnfixString->openDictionary(atok, atokSize, apot, apotSize, nintendo, nintendoSize); } -extern "C" asm void setCursorPos__Q39textinput9inputform4BaseFPQ39textinput8tistring9DecolatedUl() { - nofralloc - mr r3, r4 - mr r4, r5 - lwz r12, 0(r3) - lwz r12, 0x6c(r12) - mtctr r12 - bctr +void Base::setCursorPos(tistring::Decolated* string, u32 pos) { + string->setCursorPos(pos); } -asm void Base::closeAtokDictionary() { - nofralloc - lwz r3, 0x168(r3) - lwz r12, 0(r3) - lwz r12, 0x10c(r12) - mtctr r12 - bctr +void Base::closeAtokDictionary() { + mpUnfixString->closeDictionary(); } -asm bool Base::isAtokDictionaryOpened() { - nofralloc - lwz r3, 0x168(r3) - lwz r12, 0(r3) - lwz r12, 0x11c(r12) - mtctr r12 - bctr +bool Base::isAtokDictionaryOpened() { + return mpUnfixString->isDictionaryOpened(); } void Base::limitRowNum(u32 limitRowNum) { @@ -4660,6 +5376,286 @@ void Base::clear() { mpString->clear(); } +u32 Base::isOverRowLimit(u32 limit, const wchar_t* string) { + const wchar_t* current = string; + if (!*string) return 0; + f32 cursorX = getScale().x; + nw4r::math::VEC2 scale = getScale(); + f32 scaleX = scale.x; + u32 pos = 0; + u32 rows = 0; + muWordWrapCounter = 0; + bool kanaHandled = false; + mbHyphen = false; + u32 cursorStart, cursorEnd; + 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; + bool kana = false; + const wchar_t* character = current; + if (meLanguage == KR && !kanaHandled && cursorStart == pos) { + kanaHandled = true; + character = mpString->getKanaBuffer(); + if (*character) kana = true; + } + if (!kana) { + if (!*current) return 0; + character = current; + } + info.character = *character; + calcRect(info); + f32 right = cursorX + scaleX * (info.rect.right - info.rect.left); + if (kana) { + if (right >= scaleX * (mRect.right - mRect.left)) { + 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 = scaleX * (info.rect.right - info.rect.left); + if (cursorX + advance >= scaleX * (mRect.right - mRect.left)) return pos; + ++current; + cursorX += advance; + info.character = *current; + calcRect(info); + ++pos; + } + return muWordWrapCounter - 1; + } + cursorX = getScale().x; + } else if (right >= scaleX * (mRect.right - mRect.left)) { + 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 += scaleX * (info.rect.right - info.rect.left); + } + ++pos; + ++current; + } +} + +bool Base::onCursor(CursorPos* cursor) { + bool positioned = false; + nw4r::ut::Color savedColor = GetTextColor(); + SetupGX(); + const wchar_t* kana = mpString->getKanaBuffer(); + wchar_t candidate = mpString->getCandidate(); + if (mbPredictOn && mePredictMode != PM_Atok) { + const wchar_t* predicted = mpZiString->getCurrentSelected(); + if (getPredictMode() == PM_11) { + if (mbCursorSelected) mbZuSelected = true; + if (!(mbCursorSelected | mbZuSelected)) predicted = mpZiString->getCurrentInput(); + } + if (predicted) { + u16 index = 0; + SetTextColor(csZiStringColorLeft); + for (; *predicted;) { + if (!(mbCursorSelected | mbZuSelected) && index == mpZiString->getInputStringLength()) { + positioned = true; + cursor->fCursorX = GetCursorX(); + cursor->fCursorY = GetCursorY(); + } + if (getPredictMode() != PM_11 && mpZiString->getInputStringLength() <= index) { + if (mbCursorSelected | mbZuSelected) SetTextColor(csZiStringColorRight); + else SetTextColor(csZiStringNonSelectColorRight); + } + if (*predicted == 0xFFFE) SetTextColor(csZiStringColorLeft); + DrawInfo glyph; + glyph.rect.left = 0.0f; + glyph.rect.top = 0.0f; + glyph.rect.right = 0.0f; + glyph.rect.bottom = 0.0f; + glyph.character = *predicted; + calcRect(glyph); + f32 width = glyph.rect.right - glyph.rect.left; + f32 fieldWidth = mRect.right - mRect.left; + f32 cursorX = GetCursorX(); + if (cursorX + width >= fieldWidth) doLineFeed(); + Print(*predicted); + MoveCursorX(mfCharacterSpacing); + ++predicted; + ++index; + } + } + } + if (meDestination == DST_JP && candidate) { + DrawInfo glyph; + glyph.rect.left = 0.0f; + glyph.rect.top = 0.0f; + glyph.rect.right = 0.0f; + glyph.rect.bottom = 0.0f; + glyph.character = candidate; + calcRect(glyph); + static GXColor candidateBackground = {255, 210, 12, 255}; + f32 left = glyph.rect.left + GetCursorX(); + f32 top = glyph.rect.top + GetCursorY(); + f32 right = glyph.rect.right + GetCursorX(); + f32 bottomEdge = GetCursorY() + GetFontHeight(); + candidateBackground.a = muGlobalAlpha; + debug::drawBox_(left, top, right, bottomEdge, 0.0f, 1.0f, candidateBackground); + SetupGX(); + SetTextColor(mCharColor); + switch (candidate) { + case L' ': + case 0x3000: { + DrawInfo space; + DrawInfo marker; + space.rect.left = 0.0f; + space.rect.top = 0.0f; + space.rect.right = 0.0f; + space.rect.bottom = 0.0f; + marker.rect.left = 0.0f; + marker.rect.top = 0.0f; + marker.rect.right = 0.0f; + marker.rect.bottom = 0.0f; + space.character = candidate; + marker.character = 0xE057; + calcRect(space); + calcRect(marker); + f32 markerWidth = marker.rect.right - marker.rect.left; + f32 spaceWidth = space.rect.right - space.rect.left; + f32 offset = ((spaceWidth - markerWidth) * 0.5f) * getScale().x; + MoveCursorX(offset); + Print(0xE057); + MoveCursorX(offset); + break; + } + default: + Print(candidate); + break; + } + MoveCursorX(mfCharacterSpacing); + } + if (meDestination != DST_JP) { + wchar_t pending = mpString->getCandidate(); + if (pending) { + SetTextColor(csUnInputedWCharColor); + if (pending == L' ') { + SetTextColor(csUnInputedWCharColorSpace); + pending = 0xE057; + } + Print(pending); + MoveCursorX(mfCharacterSpacing); + } + } + for (; *kana; ++kana) { + wchar_t character = *kana; + if (mbPredictOn) character = util::HankakuToZenkaku(character); + DrawInfo glyph; + glyph.rect.left = 0.0f; + glyph.rect.top = 0.0f; + glyph.rect.right = 0.0f; + glyph.rect.bottom = 0.0f; + glyph.character = character; + calcRect(glyph); + if (meLanguage == JP) { + static GXColor kanaBackground = {128, 255, 128, 255}; + f32 left = glyph.rect.left + GetCursorX(); + f32 top = glyph.rect.top + GetCursorY(); + f32 right = glyph.rect.right + GetCursorX(); + f32 bottomEdge = GetCursorY() + GetFontHeight(); + kanaBackground.a = muGlobalAlpha; + debug::drawBox_(left, top, right, bottomEdge, 0.0f, 1.0f, kanaBackground); + SetupGX(); + mCharColor.a = muGlobalAlpha; + SetTextColor(mCharColor); + } else if (meLanguage == KR) { + SetupGX(); + mCharColor.a = muGlobalAlpha; + SetTextColor(csZiStringColorLeft); + if (isOverLine(glyph)) { + ++muLine; + SetCursorY(GetCursorY() + getLineHeight()); + SetCursorX(getScale().x); + } + } + Print(character); + MoveCursorX(mfCharacterSpacing); + } + SetTextColor(savedColor); + return positioned; +} + +u32 Base::calcCursorPos(f32 x, f32 y) { + f32 localY = y - mfScrollY; + const wchar_t* string = mpString->getWCString(); + if (!*string) return 0; + f32 cursorX = getScale().x; + f32 lineTop = 0.0f; + f32 lineBottom = lineTop; + nw4r::math::VEC2 scale = getScale(); + u32 pos = 0; + muWordWrapCounter = 0; + mbHyphen = false; + while (*string) { + DrawInfo info; + info.rect.left = 0.0f; + info.rect.top = 0.0f; + info.rect.right = 0.0f; + info.rect.bottom = 0.0f; + info.character = *string; + calcRect(info); + lineBottom = lineTop + scale.y * (info.rect.bottom - info.rect.top); + f32 right = cursorX + scale.x * (info.rect.right - info.rect.left); + if (doWordWrap(mpString->getWCString(), pos, cursorX)) { + if (localY >= lineTop && localY <= lineBottom) { + if (pos != 0) return pos - 1; + return pos; + } + lineTop += scale.y * getLineHeight(); + cursorX = getScale().x; + lineBottom = lineTop + scale.y * (info.rect.bottom - info.rect.top); + right = cursorX + scale.x * (info.rect.right - info.rect.left); + } + if (right >= scale.x * (mRect.right - mRect.left)) { + if (localY >= lineTop && localY <= lineBottom) return pos; + lineTop += scale.y * getLineHeight(); + cursorX = getScale().x; + lineBottom = lineTop + scale.y * (info.rect.bottom - info.rect.top); + right = cursorX + scale.x * (info.rect.right - info.rect.left); + } + if (x <= info.rect.left && localY >= lineTop && localY <= lineBottom) return pos; + if (*string == L'\n') { + if (localY >= lineTop && localY <= lineBottom) return pos; + lineTop += scale.y * getLineHeight(); + cursorX = getScale().x; + lineBottom = lineTop + scale.y * (info.rect.bottom - info.rect.top); + if (!string[1] && localY >= lineTop && localY <= lineBottom) return pos + 1; + } else { + if (cursorX <= x && x < right && localY >= lineTop && localY < lineBottom) { + if (cursorX + (right - cursorX) * 0.5f > x) return pos; + return pos + 1; + } + cursorX += scale.x * (info.rect.right - info.rect.left); + } + ++string; + ++pos; + if (!*string && localY >= lineTop && localY <= lineBottom) return pos; + } + if (lineTop + (lineBottom - lineTop) * 0.5f <= localY) { + return Base::calcCursorPos(x, 1.0f + lineTop + mfScrollY); + } + return Base::calcCursorPos(x, 1.0f); +} + nw4r::math::VEC2 Base::getGlobalLeftTopPos() const { nw4r::math::VEC3 position; position.x = mRect.left; @@ -5316,6 +6312,43 @@ Animation AnmPane::getState() { NormalButtonAnmPane::~NormalButtonAnmPane() {} +void NormalButtonAnmPane::onAnmEvent(AnmPaneEvent event) { + if (event == PE_6 && meState == ANM_Off) { + changeAnimation(ANM_FadeIn); + } else if (event == PE_7 && meState != ANM_Off) { + changeAnimation(ANM_FadeOut); + } else if (event == PE_0) { + changeAnimation(ANM_Pushed); + } + switch (meState) { + case ANM_FocusOut: + if (event == PE_4) changeAnimation(ANM_Normal); + if (event == PE_1) changeAnimation(ANM_FocusIn); + break; + case ANM_Normal: + if (event == PE_1) changeAnimation(ANM_FocusIn); + break; + case ANM_FocusIn: + if (event == PE_4) changeAnimation(ANM_RollOver); + if (event == PE_2) changeAnimation(ANM_FocusOut); + break; + case ANM_RollOver: + if (event == PE_2) changeAnimation(ANM_FocusOut); + break; + case ANM_FadeIn: + if (event == PE_4) changeAnimation(ANM_Normal); + if (event == PE_1) changeAnimation(ANM_FocusIn); + break; + case ANM_Pushed: + if (event == PE_4) changeAnimation(ANM_RollOver); + if (event == PE_2) changeAnimation(ANM_FocusOut); + break; + case ANM_FadeOut: + if (event == PE_4) changeAnimation(ANM_Off); + break; + } +} + EventHandler::~EventHandler() {} wchar_t Base::getCandidate() const { @@ -5326,35 +6359,11 @@ void* Base::getAtokString() { return mpUnfixString; } -asm u32 Base::getCursorPos() { - nofralloc - stwu r1, -0x20(r1) - mflr r0 - stw r0, 0x24(r1) - addi r4, r1, 0x10 - addi r5, r1, 8 - stw r31, 0x1c(r1) - mr r31, r3 - lwz r3, 0x164(r3) - lwz r12, 0(r3) - lwz r12, 0x80(r12) - mtctr r12 - bctrl - lwz r3, 0x168(r31) - addi r4, r1, 0xc - addi r5, r1, 8 - lwz r12, 0(r3) - lwz r12, 0x80(r12) - mtctr r12 - bctrl - lwz r3, 0x10(r1) - lwz r0, 0xc(r1) - lwz r31, 0x1c(r1) - add r3, r3, r0 - lwz r0, 0x24(r1) - mtlr r0 - addi r1, r1, 0x20 - blr +u32 Base::getCursorPos() { + u32 fixedStart, unfixedStart, end; + mpString->getCursorPos(&fixedStart, &end); + mpUnfixString->getCursorPos(&unfixedStart, &end); + return fixedStart + unfixedStart; } wchar_t* Base::getWCString() const { @@ -5409,16 +6418,36 @@ nw4r::math::VEC2 Base::getScale() const { return nw4r::math::VEC2(1.0f, 1.0f); } -asm bool LayoutByNW4R::isAbleToUp() { - nofralloc - lbz r3, 0x2cc(r3) - blr +bool LayoutByNW4R::isAbleToUp() { + return mbUpVisible; } -asm bool LayoutByNW4R::isAbleToDown() { - nofralloc - lbz r3, 0x2cd(r3) - blr +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 & 1) onCommand(static_cast(8), NULL); + if (buttons & 2) onCommand(static_cast(9), NULL); + if (buttons & 8) onCommand(static_cast(10), NULL); + if (buttons & 4) onCommand(static_cast(11), NULL); + bool handled = nw4rmanager::Layout::updateInput(chan, x, y, trig, hold, release, data); + if ((release & 0x800) && mpString->isOnSustain()) { + onCommand(static_cast(13), NULL); + } + if (!handled && (hold & 0x800) && 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) { @@ -5426,7 +6455,7 @@ bool LayoutByNW4R::updateInput(textinput::input::HKBManager& hkbManager) { } void LayoutByNW4R::visibleSeparator(bool flag) { - unk_0x2C0[0x0E] = flag; + mbRepeat = flag; } void LayoutByNW4R::setRootPaneScaleFor16x9() { @@ -5443,3 +6472,75 @@ void LayoutByNW4R::setRootPaneScaleFor4x3() { } 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; } +s16 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; +} +} +} diff --git a/tools/decomp-assist/tiInputForm.attempts.md b/tools/decomp-assist/tiInputForm.attempts.md new file mode 100644 index 00000000..bad5cecc --- /dev/null +++ b/tools/decomp-assist/tiInputForm.attempts.md @@ -0,0 +1,61 @@ +# tiInputForm attempts + +Target: 4.3U, `src/keyboard/tiInputForm`. Initial gate: 175/221 instruction-exact, objdiff 176/221, code 19124/50656, data 864/3772. All shared-header changes use `TIINPUTFORM_IMPLEMENTATION`, defined only in this source file. + +- `DeadKeyStream::ToCombineClass`: translated the original switch and per-language comparisons. First build: 69/69 instructions, zero differences. `ToIndependentClass` now uses its real static member declaration; 30/30, zero differences. +- `RowInfoManager::init`: direct references produced 40/39 instructions. A cached last-row index and array pointer produced 38/39. Widening the index and narrowing only the array subscript retained 38/39. Restored the original asm to avoid regression. The remaining difference includes a repeated maximum-length load and indexing/store scheduling. +- `Base::~Base`: restored the row-manager destructor and the real C++ destructor. First build: 29/29, zero differences. This also restores twelve exact inheritance thunks. +- `LayoutByNW4R::~LayoutByNW4R`: used the sibling event handler and animation list, with explicit event-handler destruction and allocator release. First successful build: 77/77, zero differences. This restores ten additional exact inheritance thunks. +- `Base::calcCursorTimer`, `dirtyCacheAll`, `setCursorPos`, `setAtokDictionary`, `closeAtokDictionary`, `isAtokDictionaryOpened`, `getCursorPos`, and `LayoutByNW4R::isAbleToUp`/`isAbleToDown`: converted existing asm into real members. Each first build was instruction-exact. `getCursorPos` is 27/27 instructions with zero differences. +- `Base::isAtokActive`: early false return: 10/10 instructions, seven differences in branch direction/block order. A result variable: 10/10, eight differences. Positive conditional return: 10/10, seven differences. Boolean switch: 11/10. Restored the original asm to avoid regression. +- `NormalButtonAnmPane::onAnmEvent`: added the missing state-machine member. Natural numeric case order gave 147/147 instructions with 23 differences in switch-block order. Ordering the cases as the target emits them gave 147/147, zero differences. +- `Base::calcCursorPos`: direct translation with the empty-input recursion at the loop head gave 329/326 instructions and an oversized frame. Moving the empty-input handling after the loop gave 332/326. Reducing DrawInfo to its actual rectangle and character fields and introducing scalar scale components gave 323/326. Restoring aggregate scale and initializing line bottom beside line top gave 332/326. Qualifying recursive calls as Base calls and matching comparison operand direction gave 326/326, with 81 differences in floating-point allocation and scheduling. This implementation remains partial. +- `LayoutByNW4R::updateInput`: direct translation gave 155/154 instructions. Inverting the midpoint branch gave 154/154 with five operand-order differences. Reordering commutative expressions did not change those five differences. Dividing the height by two and using separate bottom-position temporaries reduced this to three. Correcting the bottom expression to add height and origin before adding one gave 154/154, zero differences. + +Every measured state retained the original 20-string pool. The first gate lacked its current merge-base baseline; the baseline became available during the run. Subsequent quick gates passed with zero regressions and zero forbidden/readability additions. The unit remains NonMatching. + +- `Base::isOverRowLimit`: direct glyph/row walk gave 239/238 instructions. Separating scale construction from assignment and adding an explicit null pointer initialization gave 241/238. Restoring aggregate initialization and arranging the cursor/scale temporaries gave 236/238; the retained implementation has an undersized frame plus floating-point scheduling/register differences. +- `LayoutByNW4R::onCommand`: translated the length trimming and row-limit handling. Reusing one limit variable, introducing a separate trim limit, then separating the excess position reached 251/251 instructions with 17 differences. Calling the existing inline observer method emitted an additional `OutOfLength` string. Declaring it out of line and placing its real definition at the existing string position emitted a vtable and an additional `Cancel!` string. Restored the original state; the candidate is not included because its pool did not pass. +- `RowInfoManager::init`: a fourth attempt using a typed row accessor still gave 38/39 instructions. Restored the original asm. +- `Animation::startAnm`, `getValue`, `isActive`, `setSEFlag`, `isSEFlag`, `stop`: translated into their real class members; each is instruction-exact. `Animation::calc`: reversing the commutative increment expression matches the original raw 33-instruction bytes. ctxdiff still prints two differing CR1 branch offsets; its disassembly normalization depends on each object's function offset. This is a tooling discrepancy, not an instruction-count claim. +- Static colors: restored the seven actual color objects and their constructors. Their compiler-generated initializer is 83/87 instructions. The target also registers a real LayoutGather singleton in the still-missing command handler and dynamically initializes an animation table pointer. Those missing objects account for destructor-chain offsets and the final four instructions. No artificial placement was added. +- `LayoutByNW4R::getScale`: root-pane lookup using the existing layout and pane headers. First build: 18/18 instructions, zero differences. +- `WithAtok`: replaced 36 existing no-op/constant-return asm methods with C++ bodies reproducing the original disabled Atok implementation. Also converted the original no-op `Decolated::EnableKSXFilter` and `deleteChar`. Corrected the confirmed-string getter's const qualifier. The fresh gate retains 199/221 instruction-exact functions, with zero regressions; these conversions improve source quality rather than function counts. +- `Base::checkHeadOfSentence`: translated the observer command, previous-character switch, cursor move and sentence check. First build: 71/71 instructions, zero differences. +- `Base::isOverLine`: aggregate scale locals gave 55/51 instructions due to duplicate temporary copies. Scalar scale values gave 59/51 with four saved floating-point registers. A single return expression gave 43/51 by delaying width loads. Const references retained 55/51; separate scale assignments gave 59/51. Restored the existing exact asm body. + +- `Base::isEditMode`: a direct Boolean range and tail return gave 13/22 instructions. Switching on the two direct-edit prediction modes and explicitly testing the Zi fix state gave 22/22, zero differences. +- `Base::onPressUp` and `onPressDown`: literal translation gave 245/246 instructions. Reversing pointer comparison operands, preserving the current-string call result in a separate local, and making the prediction test positive reduced the differences to the final kana branch. An explicit common exit retained 245/246. Boolean switches with the false case first gave 247/246; the true case first gave 246/246 with only the comparison constant and branch polarity differing. A negated switch gave 247/246 and changed register allocation. Restored the readable 245/246 version; the target retains one extra unconditional branch. Guarded sibling headers expose actual Zi methods, candidate text area, and the hardware keyboard's single/double quote state. +- `Base::onPressDownHWKB`: initial nested conversion-first handling gave 266/270 with large block-order differences. Putting the modifier-driven commit before candidate navigation retained 266/270 and aligned the blocks. Hoisting the selected index and splitting the kana/candidate tests retained 266/270. The retained partial has one conditional branch difference, selected-index register allocation, and an original trailing Zi comparison whose no-op body is not reconstructed. +- `Base::onCursor`: literal candidate/kana drawing gave 475/473 instructions. Combining selection flags, ordering rectangle assignments and explicitly calculating box coordinates gave 473/473 with 22 differences. Reordering color branches and centering widths gave 473/473 with seven differences. Separate font-height temporaries regressed to 475/473. Using direct cursor-height call expressions restored 473/473 with five differences, confined to the centered-space calculation's floating-point registers and commutative operand order. Retained the best real C++ implementation, including genuine candidate/kana background colors and typed drawer fields. + +- `Base::onPressLeftHWKB` and `onPressRightHWKB`: initial typed translation gave 263/264 and 274/275 instructions. Using the target's nonpositive candidate-count test and placing the active-conversion block first removed the remaining block-order differences. A true-case Boolean switch gave 264/264 and 275/275, each with two differences: compare-to-one/branch-equal instead of compare-to-zero/branch-not-equal. Retained this source variant. Zi's selected-candidate access uses the actual class state and the SDK's EZTXGetParam, guarded for this source; the selected field load agrees with the target at 0x98. The extra search-state word at 0x74 is present in the original 0x2c cleared parameter range but its precise semantics remain uncertain. + +- `Base::toggleAtokMode_`: first typed translation gave 154/154 with 56 differences. Inverting the toolbar permission condition, placing active-candidate handling first, and putting mode-enable handling first gave 154/154, zero differences. The sibling PC header omitted its original allocator at 0x38; exposing that field only under this unit's macro places the original QWERTY/language flags at 0x3c/0x3d. Guarding KeyboardBase's existing two-argument onKey signature prevents an extra virtual slot. +- `Base::onHKBCtrlCode`: numeric case order gave 375/375 with 314 differences. Reordering the cases to their original emitted order reduced this to two range-test differences. Writing the inclusive CN/KR range as an unsigned difference <= 1 gave 375/375, zero differences. + +- `Base::inputCharZi_`: direct translation gave 163/166 instructions. Explicitly setting the direct-input Boolean, placing the Korean alphabet branch first, and reordering letter-mode cases gave 166/166 with seven block-order differences. Ordering letter-mode cases as lower, upper, default gave 166/166, zero differences. +- `Base::confirmInputting_`: direct translation gave 345/346 instructions with the direct-input block emitted last. Moving that block first aligned the remaining code; inclusive input and prediction-length comparisons remove two comparison differences. Factoring an unconfirmed Boolean gave 349/346; two separate pointer predicates gave 347/346. Retaining the original else-if chain and its repeated unconfirmed-pointer predicate gave 346/346 and byte-identical raw text (1384 bytes). ctxdiff reports two CR1 offsets because of its disassembly normalization; objdiff is the authority for this function's score. + +- `Base::inputCharDefault_`: literal C++ restored from asm: 135/135, 14 differences. Correct cursor-query calls, positive prediction branch, and local declaration order: 135/135, diffs 0. +- `Base::onSpaceKeyHWKB`: literal C++ plus semantic dead-key compatibility filter: 592/603. Original candidate/body order, inline context reset, explicit Atok boolean, and bottom-tested input loops: 603/603, 21 differences. Active-string temporary and positive boolean branch: 603/603, seven differences. Boolean switch: 607/603. Retained 603/603; seven differences are the Atok boolean block order only. Pool identical; filter loop and both candidate cycling bodies are instruction exact. + +- `LayoutByNW4R::init`: qualified Layout calls: 136/151. Virtual dispatch restored: 151/151, diffs 0; pool identical. Text-drawer fields reconstructed at original offsets with no sibling output changes. +- `EventHandler::onTiEvent`: literal event dispatch: 423/419. Hoisted animation buffer and ordinary fallback literal: 420/419, but pool gains an extra `T_2l_TextBox`. Pane-name load before cursor initialization and existing base-pane field as fallback: 423/419, 96.10501%; pool identical. Remaining string-base addressing, register allocation, and fallback load differ; retained complete readable implementation. + +- `LayoutByNW4R` constructor: real initializer list replaces asm: 46/46, diffs 0. +- `LayoutByNW4R::setLanguage`: literal helper: 234/237, extra inline-helper string pool. Expanded queries: 240/237, cached base-subobject register. Const pane-query helper: 237/237, 22 scheduling differences. Conditional argument form: same 22. Fallback passed into a string helper: 237/237, 64 differences. Retained const pane-query helper with pool identical. +- `EventHandler::onTiEvent`: ordinary fallback literal shared with restored constructor, pane-query reference, event-case order, inclusive repeat threshold: 419/419, five differences, all string offsets. Original table data before the second string group is still missing. +- `LayoutByNW4R::create`: literal calls to Base create: 303/356. Inlined row-list allocation and selection, real animation records, font and event handler setup: 358/356. Correct EditBuffer virtual layout and full-width outer button loop: 359/356. Pool identical. Remaining register allocation, row-list scheduling and loop lowering; complete implementation retained. Corrected missing eighth animation file pointers in both actual button records. Removed legacy duplicate font/assert string objects; ordinary literals now emit them. + +- `Base::onCommand`: complete C++ dispatcher, real command payloads and Zi/dead-key/context helpers: 2038/2053, 87.37506%. Correct boolean delete-forward result, initialized saved translation mode, explicit Atok predicate: 2053/2053. Cached fixed-string selection across commands: 2056/2053; retained with gate passing. Remaining stack-frame layout (0x280 vs 0x250), register allocation, predicate lowering and case scheduling. Moved the hardware-control dispatcher before layout strings; its real jump table plus the new command jump tables fix all five event-handler offsets (419/419, diffs 0). + +- `LayoutByNW4R::onCommand`: after restoring the constructor/ordinary literal pool, removing its legacy duplicate OutOfLength object allows the existing observer method to emit the real string. The earlier complete candidate is now pool-identical (251/251, 17 differences). Scope the trim limit inside the default branch, compare length on the left, and initialize the row-limit payload before its nonzero test: 251/251, diffs 0. +- `__sinit_\tiInputForm_cpp`: reconstructed the actual down-button binding target from the original final initializer store (table offset 0x4c): its animation files target the up-button pane. Using that real mutable target pointer in the down-button record emits the original dynamic initialization. 87/87, diffs 0. This object has a real runtime role, not a placement role. +- Cursor-cache symbol: restored `textdrawer::Base::isEnableCursorCache() const` and `getStartPos() const` from actual typed state. The report names the former by concatenating its mangled name with the latter. Direct bool return: raw 8 bytes `886301044e800020`, identical to the malformed original entry. Positive branch: same 8 bytes. Comparison to false: 20 bytes. Retained direct return; exact-name gate still cannot pair it with the malformed report symbol. `getStartPos`: 2/2, diffs 0. No function/config aliases were added. + +- Small accessor conversion: removed 22 asm bodies in favor of existing real header definitions or typed C++ members (StringBase, Decolated, WithZi, Manager, CandidateBox and text-drawer cache state). Fresh gate: 208/221 objdiff exact, 206/221 instruction-exact, zero baseline regressions. Draw-cache getter 8/8, dirty cache 3/3, Zi candidate-count getter 2/2, string length getter 2/2, all diffs 0. Reconstructed draw/cache fields from their original loads and preserved the nested CommandReceiver::Scroll signature under the unit macro. + +- `Base::onCursor`: final centered-space variation initializes the real offset before width locals and puts scale/half-width operands first: 473/473, seven differences. Restored the five-difference version. + +- Final clean full gate: GATE PASS; pool IDENTICAL; instruction-exact 206/221 (baseline 175/221); objdiff functions 208/221 (baseline 176/221); code 28300/50656 (baseline 19124/50656); data 868/3772 (baseline 864/3772); zero regressions, forbidden additions and readability warnings. Full build passes and DOL SHA1 is 26116613f624061ba99c8d1a299aaa6efa85670d. Partial result: 46 existing asm bodies remain and data is below 100%. Every remaining report-nonmatching entry has at least three logged source-level attempts. -- 2.49.1