bool TextBox::SetProperty(UIProperty::Enum prop, const char* val) { switch (prop) { case UIProperty::BACKGROUND_IMAGE_NOATLAS: { mStrBackImage = val; if (!mImage) { mImage = ImageBox::Create(); mImage->SetHwndId(GetHwndId()); mImage->SetRender3D(mRender3D, GetRenderTargetSize()); mImage->SetManualParent(mSelfPtr.lock()); mImage->ChangePos(GetFinalPos()); mImage->ChangeSize(GetFinalSize()); } UIManager::GetInstance().DirtyRenderList(GetHwndId()); mImage->SetTexture(val); return true; } case UIProperty::KEEP_IMAGE_RATIO: { mStrKeepRatio = val; if (!mImage) { mImage = ImageBox::Create(); mImage->SetHwndId(GetHwndId()); mImage->SetRender3D(mRender3D, GetRenderTargetSize()); mImage->SetManualParent(mSelfPtr.lock()); mImage->ChangePos(GetFinalPos()); mImage->ChangeSize(GetFinalSize()); } UIManager::GetInstance().DirtyRenderList(GetHwndId()); mImage->SetKeepImageRatio(StringConverter::ParseBool(val, true)); return true; } case UIProperty::TEXTBOX_MATCH_HEIGHT: { mMatchHeight = StringConverter::ParseBool(val); if (mMatchHeight) { unsigned height = GetTextBoxHeight(); ChangeSizeY(height); } return true; } } return __super::SetProperty(prop, val); }
void TextField::OnClicked(void* arg) { assert(this == arg); if (!IsKeyboardFocused()) { UIManager::GetInstance().SetFocusUI(mSelfPtr.lock()); } auto injector = InputManager::GetInstance().GetInputInjector(); long x, y; injector->GetMousePos(x, y); Vec2I cursorPos(x, y); const auto& finalPos = GetFinalPos(); cursorPos = cursorPos - finalPos; cursorPos.x -= mTextGap.x; cursorPos.x += mCursorOffset; auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize); if (font) { float length = 0.f; if (cursorPos.x >= (int)mTextWidth) { UIManager::GetInstance().GetTextManipulator()->SetCursorPos(mTextw.size()); } else { for (int i = 0; i < (int)mTextw.size(); i++) { float halfLength = font->GetTextWidth((const char*)&mTextw[i], 2) *.5f; length += halfLength; if (cursorPos.x < length) { UIManager::GetInstance().GetTextManipulator()->SetCursorPos(i); break; } length += halfLength; } } } injector->Invalidate(InputDevice::Mouse); }
void TextBox::OnPosChanged(bool anim) { __super::OnPosChanged(anim); if (mImage) mImage->SetPos(GetFinalPos()); }