diff --git a/include/JSystem/J2DGraph/J2DPicture.h b/include/JSystem/J2DGraph/J2DPicture.h index 89912640e..20de10c0d 100644 --- a/include/JSystem/J2DGraph/J2DPicture.h +++ b/include/JSystem/J2DGraph/J2DPicture.h @@ -29,14 +29,17 @@ public: virtual void drawSelf(f32 x, f32 y, Mtx* mtx); virtual void drawOut(f32, f32, f32, f32, f32, f32); virtual void drawOut(f32, f32, f32, f32, f32, f32, f32, f32); + JUTTexture * getTexture(u8 idx) const { + return idx < mNumTexture ? mpTexture[idx] : NULL; + } void initiate(const ResTIMG*, const ResTLUT*); void private_initiate(const ResTIMG*, const ResTLUT*); void initinfo(); bool insert(const ResTIMG*, u8, f32); bool insert(const char*, u8, f32); bool remove(u8); - int changeTexture(const ResTIMG*, u8); - int changeTexture(const char*, u8); + const ResTIMG * changeTexture(const ResTIMG*, u8); + const ResTIMG * changeTexture(const char*, u8); void drawFullSet(f32, f32, f32, f32, J2DBinding, J2DMirror, bool, Mtx*); void draw(f32, f32, f32, f32, bool, bool, bool); void draw(f32 x, f32 y, bool, bool, bool) { @@ -87,7 +90,7 @@ public: private: /* 0x0CC */ JUTTexture* mpTexture[4]; /* 0x0DC */ u8 mNumTexture; - /* 0x0DD */ u8 field_0xdd; + /* 0x0DD */ u8 mValidTexture; /* 0x0DE */ u8 field_0xde; /* 0x0DF */ u8 field_0xdf; /* 0x0E0 */ f32 mBlendKonstColorF[4]; diff --git a/include/JSystem/J2DGraph/J2DTextBox.h b/include/JSystem/J2DGraph/J2DTextBox.h index 2ac26546b..417a2eb35 100644 --- a/include/JSystem/J2DGraph/J2DTextBox.h +++ b/include/JSystem/J2DGraph/J2DTextBox.h @@ -66,7 +66,7 @@ public: virtual u16 getTypeID() { return 19; }; private: - /* 0xCC */ JUTResFont* mpFont; + /* 0xCC */ JUTFont* mpFont; /* 0xD0 */ JUtility::TColor mCharColor; /* 0xD4 */ JUtility::TColor mGradColor; /* 0xD8 */ f32 field_0xd8; diff --git a/src/JSystem/J2DGraph/J2DPicture.cpp b/src/JSystem/J2DGraph/J2DPicture.cpp index 085a42af3..ed32cce03 100644 --- a/src/JSystem/J2DGraph/J2DPicture.cpp +++ b/src/JSystem/J2DGraph/J2DPicture.cpp @@ -62,7 +62,7 @@ J2DPicture::J2DPicture(J2DPane* param_1, JSURandomInputStream* param_2) : mpPale param_2->seek(r31, JSUStreamSeekFrom_SET); mpTexture[0] = NULL; mNumTexture = 0; - field_0xdd = 1; + mValidTexture = 1; if (r30) { mpTexture[0] = new JUTTexture(r30, 0); mNumTexture++; @@ -115,7 +115,7 @@ void J2DPicture::initiate(const ResTIMG* pTimg, const ResTLUT* pTlut) { /* 802D3530-802D35FC .text private_initiate__10J2DPictureFPC7ResTIMGPC7ResTLUT */ void J2DPicture::private_initiate(const ResTIMG* pTimg, const ResTLUT* pTlut) { mpTexture[0] = NULL; - field_0xdd = 1; + mValidTexture = 1; mNumTexture = 0; if (pTimg) { mpTexture[0] = new JUTTexture(pTimg, 0); @@ -143,7 +143,7 @@ void J2DPicture::initinfo() { /* 802D3774-802D3824 .text __dt__10J2DPictureFv */ J2DPicture::~J2DPicture() { for (int i = 0; i < mNumTexture; i++) { - if (field_0xdd & 1 << i) { + if (mValidTexture & 1 << i) { delete mpTexture[i]; } } @@ -162,10 +162,10 @@ bool J2DPicture::insert(const ResTIMG* pTimg, u8 idx, f32 param_3) { mBlendKonstColorF[i] = mBlendKonstColorF[i - 1]; mBlendKonstAlphaF[i] = mBlendKonstAlphaF[i - 1]; } - s32 tmp = (1 << idx) - 1; - field_0xdd = (field_0xdd & tmp) | ((field_0xdd & ~tmp) << 1); + s32 mask = (1 << idx) - 1; + mValidTexture = (mValidTexture & mask) | ((mValidTexture & ~mask) << 1); mpTexture[idx] = texture; - field_0xdd |= (1 << idx); + mValidTexture |= (1 << idx); mBlendKonstColorF[idx] = param_3; mBlendKonstAlphaF[idx] = param_3; if (mNumTexture == 0 && mpTexture[0]) { @@ -188,7 +188,7 @@ bool J2DPicture::remove(u8 idx) { if (mNumTexture <= idx || mNumTexture == 1) { return false; } - if (field_0xdd & 1 << idx) { + if (mValidTexture & 1 << idx) { delete mpTexture[idx]; } for (u8 i = idx; i < mNumTexture - 1; i++) { @@ -196,7 +196,7 @@ bool J2DPicture::remove(u8 idx) { mBlendKonstColorF[i] = mBlendKonstColorF[i + 1]; mBlendKonstAlphaF[i] = mBlendKonstAlphaF[i + 1]; } - field_0xdd = field_0xdd & (1 << idx) - 1 | ((field_0xdd & ~((1 << idx + 1) - 1)) >> 1); + mValidTexture = mValidTexture & (1 << idx) - 1 | ((mValidTexture & ~((1 << idx + 1) - 1)) >> 1); mNumTexture--; setBlendKonstColor(); setBlendKonstAlpha(); @@ -204,12 +204,18 @@ bool J2DPicture::remove(u8 idx) { } /* 802D3B78-802D3C34 .text changeTexture__10J2DPictureFPC7ResTIMGUc */ -int J2DPicture::changeTexture(const ResTIMG*, u8) { - /* Nonmatching */ +const ResTIMG * J2DPicture::changeTexture(const ResTIMG* timg, u8 idx) { + if (idx >= mNumTexture) + return NULL; + if (getTexture(idx) == NULL || timg == NULL) + return NULL; + const ResTIMG * oldImg = getTexture(idx)->getTexInfo(); + getTexture(idx)->storeTIMG(timg, (u8)0); + return oldImg; } /* 802D3C34-802D3C84 .text changeTexture__10J2DPictureFPCcUc */ -int J2DPicture::changeTexture(const char* name, u8 param_2) { +const ResTIMG * J2DPicture::changeTexture(const char* name, u8 param_2) { return changeTexture((ResTIMG*)JKRGetNameResource(name, NULL), param_2); } @@ -303,7 +309,7 @@ void J2DPicture::drawOut(const JGeometry::TBox2&, const JGeometry::TBox2load(GXTexMapID(i)); @@ -327,16 +333,16 @@ void J2DPicture::drawTexCoord(f32 x, f32 y, f32 width, f32 height, f32 p5, f32 p GXBegin(GX_QUADS, GX_VTXFMT0, 4); GXPosition3f32(x, y, 0.0f); GXColor1u32(colors[0]); - GXTexCoord2f32(p5, p6); + GXTexCoord2f32(s0, t0); GXPosition3f32(x2, y, 0.0f); GXColor1u32(colors[1]); - GXTexCoord2f32(p7, p8); + GXTexCoord2f32(s1, t1); GXPosition3f32(x2, y2, 0.0f); GXColor1u32(colors[3]); - GXTexCoord2f32(p11, p12); + GXTexCoord2f32(s2, t2); GXPosition3f32(x, y2, 0.0f); GXColor1u32(colors[2]); - GXTexCoord2f32(p9, p10); + GXTexCoord2f32(s3, t3); GXEnd(); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U16, 0xf); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); diff --git a/src/JSystem/J2DGraph/J2DTextBox.cpp b/src/JSystem/J2DGraph/J2DTextBox.cpp index b04bc13b9..13f887224 100644 --- a/src/JSystem/J2DGraph/J2DTextBox.cpp +++ b/src/JSystem/J2DGraph/J2DTextBox.cpp @@ -17,61 +17,115 @@ J2DTextBox::J2DTextBox(J2DPane*, JSURandomInputStream*) { } /* 802D55D4-802D5660 .text __ct__10J2DTextBoxFUlRCQ29JGeometry8TBox2PC7ResFONTPCc18J2DTextBoxHBinding18J2DTextBoxVBinding */ -J2DTextBox::J2DTextBox(unsigned long, const JGeometry::TBox2&, const ResFONT*, const char*, J2DTextBoxHBinding, J2DTextBoxVBinding) { +J2DTextBox::J2DTextBox(u32, const JGeometry::TBox2&, const ResFONT*, const char*, J2DTextBoxHBinding, J2DTextBoxVBinding) { /* Nonmatching */ } /* 802D5660-802D5820 .text initiate__10J2DTextBoxFPC7ResFONTPCc18J2DTextBoxHBinding18J2DTextBoxVBinding */ -void J2DTextBox::initiate(const ResFONT*, const char*, J2DTextBoxHBinding, J2DTextBoxVBinding) { +void J2DTextBox::initiate(const ResFONT* font, const char* str, J2DTextBoxHBinding bindingH, J2DTextBoxVBinding bindingV) { /* Nonmatching */ + if (font != NULL) + mpFont = new JUTResFont(font, NULL); + + mCharColor.set(0xFFFFFFFF); + mGradColor.set(0xFFFFFFFF); + mBlack = JUtility::TColor(0x00000000); + mWhite = JUtility::TColor(0xFFFFFFFF); + mBindingH = bindingH; + mBindingV = bindingV; + mStringPtr = new char[strlen(str) + 1]; + strcpy(mStringPtr, str); + field_0xd8 = 0.0f; + field_0xdc = 0.0f; + mCharSpace = 0.0f; + if (mpFont == NULL) { + mLineSpace = 0.0f; + mFontSizeX = 0.0f; + mFontSizeY = 0.0f; + } else { + mLineSpace = mpFont->getLeading(); + mFontSizeX = mpFont->getWidth(); + mFontSizeY = mpFont->getHeight(); + } + mMagic = 'TBX1'; + mTextFontOwned = true; } /* 802D5820-802D58B8 .text __dt__10J2DTextBoxFv */ J2DTextBox::~J2DTextBox() { - /* Nonmatching */ + if (mTextFontOwned) + delete mpFont; + delete[] mStringPtr; } /* 802D58B8-802D5928 .text setFont__10J2DTextBoxFP7JUTFont */ -void J2DTextBox::setFont(JUTFont*) { - /* Nonmatching */ +void J2DTextBox::setFont(JUTFont* font) { + if (font) { + if (mTextFontOwned) + delete mpFont; + mpFont = font; + mTextFontOwned = false; + } } /* 802D5928-802D5AA4 .text draw__10J2DTextBoxFfff18J2DTextBoxHBinding */ -void J2DTextBox::draw(float, float, float, J2DTextBoxHBinding) { +void J2DTextBox::draw(f32, f32, f32, J2DTextBoxHBinding) { /* Nonmatching */ } /* 802D5AA4-802D5AAC .text getStringPtr__10J2DTextBoxCFv */ -void J2DTextBox::getStringPtr() const { - /* Nonmatching */ +char* J2DTextBox::getStringPtr() const { + return mStringPtr; } /* 802D5AAC-802D5B6C .text setString__10J2DTextBoxFPCce */ -void J2DTextBox::setString(const char*, ...) { - /* Nonmatching */ +s32 J2DTextBox::setString(const char* str, ...) { + va_list args; + va_start(args, str); + + delete[] mStringPtr; + u32 strLen = strlen(str); + mStringPtr = new char[strLen + 1]; + strcpy(mStringPtr, str); + + va_end(args); + return strLen; } /* 802D5B6C-802D5BE4 .text setConnectParent__10J2DTextBoxFb */ -void J2DTextBox::setConnectParent(bool) { - /* Nonmatching */ +bool J2DTextBox::setConnectParent(bool v) { + if (getPaneTree()->getParent() == NULL) + return false; + if (getPaneTree()->getParent()->getObject()->getTypeID() != 17) + return false; + mIsConnectParent = v; + return v; } /* 802D5BE4-802D5C4C .text drawSelf__10J2DTextBoxFff */ -void J2DTextBox::drawSelf(float, float) { - /* Nonmatching */ +void J2DTextBox::drawSelf(f32 x, f32 y) { + Mtx mtx; + MTXIdentity(mtx); + drawSelf(x, y, &mtx); } /* 802D5C4C-802D5DA4 .text drawSelf__10J2DTextBoxFffPA3_A4_f */ -void J2DTextBox::drawSelf(float, float, float(*)[3][4]) { +void J2DTextBox::drawSelf(f32, f32, Mtx*) { /* Nonmatching */ } /* 802D5DA4-802D5EB0 .text resize__10J2DTextBoxFff */ -void J2DTextBox::resize(float, float) { - /* Nonmatching */ -} +void J2DTextBox::resize(f32 w, f32 h) { + if (mIsConnectParent && getPaneTree() != NULL && getPaneTree()->getParent() != NULL) { + J2DPane * pane = getPaneTree()->getParent()->getObject(); -/* 802D5EB0-802D5EB8 .text getTypeID__10J2DTextBoxFv */ -void J2DTextBox::getTypeID() { - /* Nonmatching */ + if (pane->getTypeID() == 17) { + f32 newW = pane->getWidth() + (w - getWidth()); + f32 newH = pane->getHeight() + (h - getHeight()); + pane->resize(newW, newH); + return; + } + } + + J2DPane::resize(w, h); }