From f1ee93c1383d28f272d1b9f641119f8a2c395dbb Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 11 Oct 2023 22:46:30 -0700 Subject: [PATCH] J2DScreen match --- configure.py | 2 +- include/JSystem/J2DGraph/J2DPane.h | 16 ++- include/JSystem/J2DGraph/J2DScreen.h | 7 +- include/JSystem/J2DGraph/J2DWindow.h | 48 +++++++++ include/JSystem/JSupport/JSUList.h | 2 - src/JSystem/J2DGraph/J2DPane.cpp | 6 +- src/JSystem/J2DGraph/J2DScreen.cpp | 52 +++++----- src/JSystem/J2DGraph/J2DWindow.cpp | 140 ++++++++++++++++++++++----- 8 files changed, 212 insertions(+), 61 deletions(-) create mode 100644 include/JSystem/J2DGraph/J2DWindow.h diff --git a/configure.py b/configure.py index e75a9ad43..1f6dedf35 100644 --- a/configure.py +++ b/configure.py @@ -840,7 +840,7 @@ config.libs = [ Object(Matching, "JSystem/J2DGraph/J2DOrthoGraph.cpp"), Object(NonMatching, "JSystem/J2DGraph/J2DPrint.cpp"), Object(Matching, "JSystem/J2DGraph/J2DPane.cpp"), - Object(NonMatching, "JSystem/J2DGraph/J2DScreen.cpp"), + Object(Matching, "JSystem/J2DGraph/J2DScreen.cpp"), Object(NonMatching, "JSystem/J2DGraph/J2DWindow.cpp"), Object(NonMatching, "JSystem/J2DGraph/J2DPicture.cpp"), Object(NonMatching, "JSystem/J2DGraph/J2DTextBox.cpp"), diff --git a/include/JSystem/J2DGraph/J2DPane.h b/include/JSystem/J2DGraph/J2DPane.h index ba1a3fc7a..5465a5dad 100644 --- a/include/JSystem/J2DGraph/J2DPane.h +++ b/include/JSystem/J2DGraph/J2DPane.h @@ -46,22 +46,28 @@ public: void setBasePosition(J2DBasePosition position); virtual ~J2DPane(); - virtual u16 getTypeID() { return 16; } + virtual u16 getTypeID() { return 0x10; } virtual void move(f32 x, f32 y); virtual void add(f32 x, f32 y); - virtual void resize(f32 x, f32 y); + virtual void resize(f32 w, f32 h) { + mBounds.f.x = mBounds.i.x + w; + mBounds.f.y = mBounds.i.y + h; + } virtual bool setConnectParent(bool connected); virtual void calcMtx(); virtual void update(); - virtual void drawSelf(f32 arg1, f32 arg2); - virtual void drawSelf(f32 arg1, f32 arg2, Mtx* mtx) {} + virtual void drawSelf(f32 x, f32 y); + virtual void drawSelf(f32 x, f32 y, Mtx* mtx) {} virtual J2DPane* search(u32 tag); virtual void makeMatrix(f32, f32); + f32 getWidth() const { return mBounds.getWidth(); } + f32 getHeight() const { return mBounds.getHeight(); } JSUTree* getFirstChild() { return mPaneTree.getFirstChild(); } JSUTree* getEndChild() { return mPaneTree.getEndChild(); } const JSUTree* getPaneTree() { return &mPaneTree; } u8 getAlpha() const { return mAlpha; } + bool isConnectParent() const { return mIsConnectParent; } public: /* 0x04 */ u32 mMagic; @@ -80,7 +86,7 @@ public: /* 0xAC */ u8 mAlpha; /* 0xAD */ u8 mDrawAlpha; /* 0xAE */ u8 mInheritAlpha; - /* 0xAF */ u8 field_0xaf; + /* 0xAF */ u8 mIsConnectParent; /* 0xB0 */ JSUTree mPaneTree; }; diff --git a/include/JSystem/J2DGraph/J2DScreen.h b/include/JSystem/J2DGraph/J2DScreen.h index acd897b4f..0e041e67a 100644 --- a/include/JSystem/J2DGraph/J2DScreen.h +++ b/include/JSystem/J2DGraph/J2DScreen.h @@ -2,6 +2,7 @@ #define J2DSCREEN_H #include "JSystem/J2DGraph/J2DPane.h" +#include "JSystem/JUtility/TColor.h" #include "dolphin/gx/GX.h" class JKRArchive; @@ -9,9 +10,9 @@ class JKRArchive; class J2DScreen : public J2DPane { public: virtual ~J2DScreen(); - virtual u16 getTypeID() { return 17; } + virtual u16 getTypeID() { return 0x08; } virtual void calcMtx() { makeMatrix(mBounds.i.x, mBounds.i.y); } - virtual void drawSelf(f32 arg1, f32 arg2, Mtx* mtx); + virtual void drawSelf(f32 x, f32 y, Mtx* mtx); virtual J2DPane* search(u32 tag); virtual J2DPane* createPane(J2DPane::J2DScrnBlockHeader const & header, JSURandomInputStream * pStream, J2DPane * pParent); @@ -26,7 +27,7 @@ protected: private: /* 0xCC */ bool mbClipToParent; /* 0xCD */ u8 pad_0xcd[3]; - /* 0xD0 */ GXColor mColor; + /* 0xD0 */ JUtility::TColor mColor; }; STATIC_ASSERT(sizeof(J2DScreen) == 0xD4); diff --git a/include/JSystem/J2DGraph/J2DWindow.h b/include/JSystem/J2DGraph/J2DWindow.h new file mode 100644 index 000000000..c51110fc3 --- /dev/null +++ b/include/JSystem/J2DGraph/J2DWindow.h @@ -0,0 +1,48 @@ +#ifndef J2DWINDOW_H +#define J2DWINDOW_H + +#include "JSystem/J2DGraph/J2DPane.h" +#include "JSystem/JGeometry.h" +#include "JSystem/JUtility/TColor.h" + +class JKRArchive; +class JUTTexture; +class JUTPalette; + +class J2DWindow : public J2DPane { +public: + J2DWindow(J2DPane*, JSURandomInputStream*); + + virtual ~J2DWindow(); + virtual u16 getTypeID() { return 0x11; } + virtual void resize(f32 x, f32 y); + virtual void drawSelf(f32 x, f32 y); + virtual void drawSelf(f32 x, f32 y, Mtx* mtx); + + void initinfo2(); + void draw_private(const JGeometry::TBox2&, const JGeometry::TBox2&); + void setContentsColor(JUtility::TColor, JUtility::TColor, JUtility::TColor, JUtility::TColor); + void drawContents(const JGeometry::TBox2&); + void drawFrameTexture(JUTTexture*, f32, f32, f32, f32, u16, u16, u16, u16, bool); + void drawFrameTexture(JUTTexture*, f32, f32, bool, bool, bool); + void drawContentsTexture(f32, f32, f32, f32); + void setTevMode(JUTTexture*, JUtility::TColor, JUtility::TColor); + +public: + /* 0x0CC */ JUTTexture * mpFrameTexture[4]; + /* 0x0DC */ JUTTexture * mpContentsTexture; + /* 0x0E0 */ JGeometry::TBox2 mWindowBox; + /* 0x0F0 */ JUTPalette * mpPalette; + /* 0x0F4 */ JUtility::TColor mColor[4]; + /* 0x104 */ JUtility::TColor mFrameColor[2]; + /* 0x10C */ s16 mTextureWidth; + /* 0x10E */ s16 mTextureHeight; + /* 0x110 */ u8 field_0x110; + /* 0x111 */ u8 field_0x111; + /* 0x112 */ u8 field_0x112; + /* 0x113 */ u8 field_0x113; +}; + +STATIC_ASSERT(sizeof(J2DWindow) == 0x114); + +#endif /* J2DWINDOW_H */ diff --git a/include/JSystem/JSupport/JSUList.h b/include/JSystem/JSupport/JSUList.h index bcc4f8374..6adb0bc74 100644 --- a/include/JSystem/JSupport/JSUList.h +++ b/include/JSystem/JSupport/JSUList.h @@ -201,8 +201,6 @@ public: bool operator!=(JSUTree* other) { return this->mTree != other; } - operator bool() const { return this->mTree != NULL; } - JSUTreeIterator operator++(int) { JSUTreeIterator prev = *this; this->mTree = this->mTree->getNextChild(); diff --git a/src/JSystem/J2DGraph/J2DPane.cpp b/src/JSystem/J2DGraph/J2DPane.cpp index 4dfdb177c..ccef174d9 100644 --- a/src/JSystem/J2DGraph/J2DPane.cpp +++ b/src/JSystem/J2DGraph/J2DPane.cpp @@ -53,7 +53,7 @@ void J2DPane::initiate() { mAlpha = 0xFF; mInheritAlpha = TRUE; mDrawAlpha = 0xFF; - field_0xaf = 0; + mIsConnectParent = 0; calcMtx(); } @@ -117,7 +117,7 @@ void J2DPane::makePaneStream(J2DPane* pParentPane, JSURandomInputStream* pStream mCullMode = GX_CULL_NONE; mDrawAlpha = 0xFF; - field_0xaf = 0; + mIsConnectParent = 0; calcMtx(); } @@ -196,7 +196,7 @@ void J2DPane::draw(float x, float y, const J2DGrafContext* pCtx, bool clip) { GXSetCullMode((GXCullMode)mCullMode); drawSelf(x, y, &ctx.mPosMtx); - for (JSUTreeIterator iter = mPaneTree.getFirstChild(); iter; ++iter) + for (JSUTreeIterator iter = mPaneTree.getFirstChild(); iter != mPaneTree.getEndChild(); ++iter) iter->draw(0.0f, 0.0f, pCtx, clip); } } diff --git a/src/JSystem/J2DGraph/J2DScreen.cpp b/src/JSystem/J2DGraph/J2DScreen.cpp index 2c3f28312..f68726d3a 100644 --- a/src/JSystem/J2DGraph/J2DScreen.cpp +++ b/src/JSystem/J2DGraph/J2DScreen.cpp @@ -14,11 +14,13 @@ class J2DWindow : public J2DPane { public: J2DWindow(J2DPane * pPane, JSURandomInputStream * pStream); + u8 pad[0x114 - 0x0cc]; }; class J2DPicture : public J2DPane { public: J2DPicture(J2DPane * pPane, JSURandomInputStream * pStream); + u8 pad[0x124 - 0x0cc]; }; /* 802D08E4-802D0944 .text __dt__9J2DScreenFv */ @@ -69,24 +71,29 @@ s32 J2DScreen::makeHierarchyPanes(J2DPane* pParent, JSURandomInputStream* pStrea /* 802D0B40-802D0CE0 .text createPane__9J2DScreenFRCQ27J2DPane18J2DScrnBlockHeaderP20JSURandomInputStreamP7J2DPane */ J2DPane * J2DScreen::createPane(const J2DPane::J2DScrnBlockHeader& header, JSURandomInputStream* pStream, J2DPane* pParent) { - /* Nonmatching - regalloc */ + J2DPane * pPane; switch (header.mMagic) { - case 'TBX1': - return new J2DTextBox(pParent, pStream); - case 'PIC1': - return new J2DPicture(pParent, pStream); case 'PAN1': - return new J2DPane(pParent, pStream); + pPane = new J2DPane(pParent, pStream); + break; case 'WIN1': - return new J2DWindow(pParent, pStream); + pPane = new J2DWindow(pParent, pStream); + break; + case 'PIC1': + pPane = new J2DPicture(pParent, pStream); + break; + case 'TBX1': + pPane = new J2DTextBox(pParent, pStream); + break; default: JUT_WARN(0x9f, "%s", "unknown pane"); u32 pos = pStream->getPosition() + header.mSize; - J2DPane * pPane = new J2DPane(pPane, pStream); + pPane = new J2DPane(pParent, pStream); pStream->seek(pos, JSUStreamSeekFrom_SET); - return pPane; } + + return pPane; } /* 802D0CE0-802D0D70 .text set__9J2DScreenFP20JSURandomInputStream */ @@ -117,28 +124,26 @@ bool J2DScreen::checkSignature(JSURandomInputStream* pStream) { /* 802D0DE8-802D0F2C .text getScreenInformation__9J2DScreenFP20JSURandomInputStream */ bool J2DScreen::getScreenInformation(JSURandomInputStream* pStream) { - /* Nonmatching - regalloc / load order */ - - struct { + struct J2DScrnInfoHeader { u32 mMagic; u32 mSize; u16 mWidth; u16 mHeight; - GXColor mColor; + u32 mColor; } header; pStream->read(&header, sizeof(header)); if (header.mMagic != 'INF1') { - JUT_WARN(0xf9, "%s", "SCRN resource is broken.\n"); + JUT_WARN(0xf2, "%s", "SCRN resource is broken.\n"); return false; } - GXColor color = header.mColor; JGeometry::TBox2 bounds(0.0f, 0.0f, header.mWidth, header.mHeight); - mBounds = bounds; calcMtx(); + + JUtility::TColor color(header.mColor); mColor = color; if (header.mSize > sizeof(header)) @@ -178,24 +183,25 @@ J2DPane * J2DScreen::search(u32 tag) { /* 802D1180-802D12E0 .text drawSelf__9J2DScreenFffPA3_A4_f */ void J2DScreen::drawSelf(f32 x, f32 y, Mtx* pMtx) { - GXColor color = mColor; + JUtility::TColor color(mColor); u8 alpha = ((color.a * mAlpha) / 0xFF); if (alpha == 0) return; - color.a = alpha; - JUtility::TColor vtxColor(color); + JUtility::TColor colorAlpha((color & 0xFFFFFF00) | alpha); + color = colorAlpha; + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRC_ALPHA, GX_BL_INV_SRC_ALPHA, GX_LO_SET); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXBegin(GX_QUADS, GX_VTXFMT0, 4); GXPosition3f32(0.0f, 0.0f, 0.0f); - GXColor1u32(vtxColor); + GXColor1u32(color); GXPosition3f32(mBounds.getWidth(), 0.0f, 0.0f); - GXColor1u32(vtxColor); + GXColor1u32(color); GXPosition3f32(mBounds.getWidth(), mBounds.getHeight(), 0.0f); - GXColor1u32(vtxColor); + GXColor1u32(color); GXPosition3f32(0.0f, mBounds.getHeight(), 0.0f); - GXColor1u32(vtxColor); + GXColor1u32(color); GXEnd(); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); } diff --git a/src/JSystem/J2DGraph/J2DWindow.cpp b/src/JSystem/J2DGraph/J2DWindow.cpp index 35c4023c4..211be6bd5 100644 --- a/src/JSystem/J2DGraph/J2DWindow.cpp +++ b/src/JSystem/J2DGraph/J2DWindow.cpp @@ -4,7 +4,9 @@ // #include "JSystem/J2DGraph/J2DWindow.h" -#include "dolphin/types.h" +#include "JSystem/JUtility/TColor.h" +#include "JSystem/JUtility/JUTTexture.h" +#include "dolphin/gx/GX.h" /* 802D12E0-802D1820 .text __ct__9J2DWindowFP7J2DPaneP20JSURandomInputStream */ J2DWindow::J2DWindow(J2DPane*, JSURandomInputStream*) { @@ -18,60 +20,150 @@ void J2DWindow::initinfo2() { /* 802D1A9C-802D1B44 .text __dt__9J2DWindowFv */ J2DWindow::~J2DWindow() { - /* Nonmatching */ } /* 802D1B44-802D1F5C .text draw_private__9J2DWindowFRCQ29JGeometry8TBox2RCQ29JGeometry8TBox2 */ -void J2DWindow::draw_private(const JGeometry::TBox2&, const JGeometry::TBox2&) { - /* Nonmatching */ +void J2DWindow::draw_private(const JGeometry::TBox2& frameBox, const JGeometry::TBox2& contentsBox) { + /* Nonmatching - not finished yet */ + drawContents(contentsBox); + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); + GXSetNumTexGens(1); + + if (mpFrameTexture[0] != NULL && mpFrameTexture[1] != NULL && mpFrameTexture[2] != NULL && mpFrameTexture[3] != NULL) { + f32 right = frameBox.getWidth() - mpFrameTexture[3]->getWidth(); + f32 bottom = frameBox.getHeight() - mpFrameTexture[3]->getHeight(); + f32 left = mpFrameTexture[0]->getWidth(); + f32 top = mpFrameTexture[0]->getHeight(); + + drawFrameTexture(mpFrameTexture[3], 0.0f, 0.0f, ((field_0x110 >> 7) & 1), ((field_0x110 >> 6) & 1), true); + drawFrameTexture(mpFrameTexture[1], left, 0.0f, ((field_0x110 >> 5) & 1), ((field_0x110 >> 4) & 1), (field_0x111 & 1)); + } + + GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetNumTexGens(0); + GXSetVtxDesc(GX_VA_TEX0, GX_NONE); } /* 802D1F5C-802D207C .text resize__9J2DWindowFff */ -void J2DWindow::resize(float, float) { - /* Nonmatching */ +void J2DWindow::resize(f32 w, f32 h) { + /* Nonmatching - regalloc */ + f32 oldW = getWidth(); + f32 oldH = getHeight(); + J2DPane::resize(w, h); + mWindowBox.f.x += w - oldW; + mWindowBox.f.y += h - oldH; + for (JSUTreeIterator iter = mPaneTree.getFirstChild(); iter != mPaneTree.getEndChild(); ++iter) { + if (iter->getTypeID() == 0x13 && iter->isConnectParent()) { + f32 childW = w - oldW + iter->getWidth(); + f32 childH = h - oldH + iter->getHeight(); + iter->J2DPane::resize(childW, childH); + } + } } /* 802D207C-802D2128 .text setContentsColor__9J2DWindowFQ28JUtility6TColorQ28JUtility6TColorQ28JUtility6TColorQ28JUtility6TColor */ -void J2DWindow::setContentsColor(JUtility::TColor, JUtility::TColor, JUtility::TColor, JUtility::TColor) { - /* Nonmatching */ +void J2DWindow::setContentsColor(JUtility::TColor c0, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3) { + mColor[0].set(c0); + mColor[1].set(c1); + mColor[2].set(c2); + mColor[3].set(c3); } /* 802D2128-802D2190 .text drawSelf__9J2DWindowFff */ -void J2DWindow::drawSelf(float, float) { - /* Nonmatching */ +void J2DWindow::drawSelf(f32 x, f32 y) { + Mtx m; + MTXIdentity(m); + drawSelf(x, y, &m); } /* 802D2190-802D2288 .text drawSelf__9J2DWindowFffPA3_A4_f */ -void J2DWindow::drawSelf(float, float, float(*)[3][4]) { - /* Nonmatching */ +void J2DWindow::drawSelf(f32 x, f32 y, Mtx *pMtx) { + JGeometry::TBox2 screenBounds = mScreenBounds; + screenBounds.addPos(JGeometry::TVec2(x, y)); + + if (screenBounds.getWidth() >= mTextureWidth && screenBounds.getHeight() >= mTextureHeight) { + Mtx m; + MTXConcat(*pMtx, mDrawMtx, m); + GXLoadPosMtxImm(m, GX_PNMTX0); + draw_private(screenBounds, mWindowBox); + } + + clip(mWindowBox); } /* 802D2288-802D2550 .text drawContents__9J2DWindowFRCQ29JGeometry8TBox2 */ -void J2DWindow::drawContents(const JGeometry::TBox2&) { - /* Nonmatching */ +void J2DWindow::drawContents(const JGeometry::TBox2& contentsBox) { + if (contentsBox.isValid()) { + GXSetNumChans(1); + GXSetNumTexGens(0); + GXSetNumTevStages(1); + GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + if ((mColor[0] & 0xFF) == 0xFF && (mColor[1] & 0xFF) == 0xFF && (mColor[2] & 0xFF) == 0xFF && (mColor[3] & 0xFF) == 0xFF && mDrawAlpha == 0xFF) { + GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET); + } else { + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRC_ALPHA, GX_BL_INV_SRC_ALPHA, GX_LO_SET); + } + } } /* 802D2550-802D26E4 .text drawFrameTexture__9J2DWindowFP10JUTTextureffffUsUsUsUsb */ -void J2DWindow::drawFrameTexture(JUTTexture*, float, float, float, float, unsigned short, unsigned short, unsigned short, unsigned short, bool) { - /* Nonmatching */ +void J2DWindow::drawFrameTexture(JUTTexture* pTexture, f32 x0, f32 y0, f32 w, f32 h, u16 s0, u16 t0, u16 s1, u16 t1, bool bSetupTev) { + f32 x1 = x0 + w; + f32 y1 = y0 + h; + + if (bSetupTev) { + pTexture->load(GX_TEXMAP0); + setTevMode(pTexture, mFrameColor[1], mFrameColor[0]); + } + + JUtility::TColor vtxColor(mDrawAlpha | 0xFFFFFF00); + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); + GXBegin(GX_QUADS, GX_VTXFMT0, 4); + + GXPosition3f32(x0, y0, 0.0f); + GXColor1u32(vtxColor); + GXTexCoord2s16(s1, t1); + + GXPosition3f32(x1, y0, 0.0f); + GXColor1u32(vtxColor); + GXTexCoord2s16(s0, t1); + + GXPosition3f32(x1, y1, 0.0f); + GXColor1u32(vtxColor); + GXTexCoord2s16(s0, t0); + + GXPosition3f32(x0, y1, 0.0f); + GXColor1u32(vtxColor); + GXTexCoord2s16(s1, t0); + + GXEnd(); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); } /* 802D26E4-802D2784 .text drawFrameTexture__9J2DWindowFP10JUTTextureffbbb */ -void J2DWindow::drawFrameTexture(JUTTexture*, float, float, bool, bool, bool) { +void J2DWindow::drawFrameTexture(JUTTexture* pTexture, f32 x, f32 y, bool flipS, bool flipT, bool bSetupTev) { /* Nonmatching */ + drawFrameTexture(pTexture, x, y, pTexture->getWidth(), pTexture->getHeight(), + flipS ? (u16)0 : (u16)0x8000, + flipT ? (u16)0 : (u16)0x8000, + flipS ? (u16)0x8000 : (u16)0, + flipT ? (u16)0x8000 : (u16)0, + bSetupTev); } /* 802D2784-802D29F4 .text drawContentsTexture__9J2DWindowFffff */ -void J2DWindow::drawContentsTexture(float, float, float, float) { +void J2DWindow::drawContentsTexture(f32, f32, f32, f32) { /* Nonmatching */ } /* 802D29F4-802D2D8C .text setTevMode__9J2DWindowFP10JUTTextureQ28JUtility6TColorQ28JUtility6TColor */ -void J2DWindow::setTevMode(JUTTexture*, JUtility::TColor, JUtility::TColor) { - /* Nonmatching */ -} - -/* 802D2D8C-802D2D94 .text getTypeID__9J2DWindowFv */ -void J2DWindow::getTypeID() { +void J2DWindow::setTevMode(JUTTexture* pTexture, JUtility::TColor c0, JUtility::TColor c1) { /* Nonmatching */ + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); }