From 3abbb3c85c68f296f52d0d44c6ebbac2ae8ac1d8 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 15 Jan 2021 18:53:38 +0100 Subject: [PATCH] Updated TextEditComponent to scale properly on high resolution diplays. Also changed to SVG graphic files for the text input box frame in order to look smoother at higher resolutions. --- es-core/src/components/TextEditComponent.cpp | 24 +++++++++++------- es-core/src/components/TextEditComponent.h | 1 + resources/graphics/textinput.svg | 6 +++++ resources/graphics/textinput_focused.svg | 6 +++++ resources/graphics/textinput_ninepatch.png | Bin 1275 -> 0 bytes .../graphics/textinput_ninepatch_active.png | Bin 3084 -> 0 bytes 6 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 resources/graphics/textinput.svg create mode 100644 resources/graphics/textinput_focused.svg delete mode 100644 resources/graphics/textinput_ninepatch.png delete mode 100644 resources/graphics/textinput_ninepatch_active.png diff --git a/es-core/src/components/TextEditComponent.cpp b/es-core/src/components/TextEditComponent.cpp index 3fb6e9058..23aeab722 100644 --- a/es-core/src/components/TextEditComponent.cpp +++ b/es-core/src/components/TextEditComponent.cpp @@ -20,7 +20,7 @@ TextEditComponent::TextEditComponent( Window* window) : GuiComponent(window), - mBox(window, ":/graphics/textinput_ninepatch.png"), + mBox(window, ":/graphics/textinput.svg"), mFocused(false), mScrollOffset(0.0f, 0.0f), mCursor(0), mEditing(false), @@ -29,24 +29,26 @@ TextEditComponent::TextEditComponent( { addChild(&mBox); onFocusLost(); - setSize(4096, mFont->getHeight() + TEXT_PADDING_VERT); + mResolutionAdjustment = -(34 * Renderer::getScreenWidthModifier() - 34); + setSize(4096, mFont->getHeight() + (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier())); } void TextEditComponent::onFocusGained() { mFocused = true; - mBox.setImagePath(":/graphics/textinput_ninepatch_active.png"); + mBox.setImagePath(":/graphics/textinput_focused.svg"); } void TextEditComponent::onFocusLost() { mFocused = false; - mBox.setImagePath(":/graphics/textinput_ninepatch.png"); + mBox.setImagePath(":/graphics/textinput.svg"); } void TextEditComponent::onSizeChanged() { - mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-34, -32 - TEXT_PADDING_VERT)); + mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-34 + mResolutionAdjustment, -32 - + (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier()))); onTextChanged(); // Wrap point probably changed. } @@ -308,8 +310,8 @@ void TextEditComponent::render(const Transform4x4f& parentTrans) } float cursorHeight = mFont->getHeight() * 0.8f; - Renderer::drawRect(cursorPos.x(), cursorPos.y() + (mFont->getHeight() - - cursorHeight) / 2, 2.0f, cursorHeight, 0x000000FF, 0x000000FF); + Renderer::drawRect(cursorPos.x(), cursorPos.y() + (mFont->getHeight() - cursorHeight) / 2, + 2.0f * Renderer::getScreenWidthModifier(), cursorHeight, 0x000000FF, 0x000000FF); } } @@ -320,12 +322,16 @@ bool TextEditComponent::isMultiline() Vector2f TextEditComponent::getTextAreaPos() const { - return Vector2f(TEXT_PADDING_HORIZ / 2.0f, TEXT_PADDING_VERT / 2.0f); + return Vector2f((-mResolutionAdjustment + + (TEXT_PADDING_HORIZ * Renderer::getScreenWidthModifier())) / 2.0f, + (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier()) / 2.0f); } Vector2f TextEditComponent::getTextAreaSize() const { - return Vector2f(mSize.x() - TEXT_PADDING_HORIZ, mSize.y() - TEXT_PADDING_VERT); + return Vector2f(mSize.x() + mResolutionAdjustment - + (TEXT_PADDING_HORIZ * Renderer::getScreenWidthModifier()), mSize.y() - + (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier())); } std::vector TextEditComponent::getHelpPrompts() diff --git a/es-core/src/components/TextEditComponent.h b/es-core/src/components/TextEditComponent.h index 69688224c..a95905db4 100644 --- a/es-core/src/components/TextEditComponent.h +++ b/es-core/src/components/TextEditComponent.h @@ -67,6 +67,7 @@ private: Vector2f mScrollOffset; NinePatchComponent mBox; + float mResolutionAdjustment; std::shared_ptr mFont; std::unique_ptr mTextCache; diff --git a/resources/graphics/textinput.svg b/resources/graphics/textinput.svg new file mode 100644 index 000000000..a08132aab --- /dev/null +++ b/resources/graphics/textinput.svg @@ -0,0 +1,6 @@ + + + + diff --git a/resources/graphics/textinput_focused.svg b/resources/graphics/textinput_focused.svg new file mode 100644 index 000000000..935653393 --- /dev/null +++ b/resources/graphics/textinput_focused.svg @@ -0,0 +1,6 @@ + + + + diff --git a/resources/graphics/textinput_ninepatch.png b/resources/graphics/textinput_ninepatch.png deleted file mode 100644 index 9ba16d6f294c26d9a65989a72ee58c19fc38a044..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1275 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWuD@%o&*>5hW46K32*3xq68pHF_1f1wh>l3^w)^1&PVosU-?Y zsp*+{wo31J?^jaDOtDo8H}y5}EpSfF$n>ZxN)4{^3rViZPPR-@vbR&PsjvbXkegbP zs8ErclUHn2VXFi-*9yo63F|8KW+g=7RhMR$W{Yl!|Z$R@KEJl?AE#L8-<0 zrA5iW_()TRX$FQJev3c~fv&OgFUkZ)N@9*nesXDUYF>$_i>(q+MlU5Z#md#v(A3=A z*vZh)$iU3P(9pub!r0l|)!5M0(bUo0)EH(4HoeA9=1ykD=4O^I7C@b@#*UVTE>13P zE+z(+mPW3waJ`;+#U+V($*C}VGlBM6TDVvkSh|`3^_t_~2E*d&d1&^_H%Avt_F9 z?tNRXb$yS!bE4Bw&HK^1*D7&~S_GElM(6zCTB2R^C0Kv*N0sObmYf8Z>{C)(`Xel# zckQ$;Ut|3F_u*%IKG)B6Id#F~;X(#h4F^W9fCeU!1-O|17BkFyUoSV&`=sn^Q6}~^ zNj*n79&ELH%D~9u=V8H~Im^x9&&2ElY;HYLOLB6AA`-qmsIZz=^4IXq$25aYi@Lpj qFZz4oo>ALARksacr~ZA_J-}f7EO2V&>sl62apdXh=d#Wzp$Pze+_d`u diff --git a/resources/graphics/textinput_ninepatch_active.png b/resources/graphics/textinput_ninepatch_active.png deleted file mode 100644 index 2381af87e71766444e1a9fe33edc8be08f79c7fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3084 zcmV+n4D<7eP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(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