Skip to content

Commit

Permalink
Progress on J2DPane, JUTResFont (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yotona authored Sep 16, 2023
1 parent f67a9d9 commit a321031
Show file tree
Hide file tree
Showing 6 changed files with 508 additions and 129 deletions.
39 changes: 4 additions & 35 deletions include/JSystem/J2DGraph/J2DPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@
#include "JSystem/JGeometry.h"
#include "JSystem/JSupport/JSUList.h"
#include "SSystem/SComponent/c_xyz.h"
#include "dolphin/gx/GXEnum.h"
#include "dolphin/mtx/mtx.h"

class J2DAnmBase;
class J2DAnmColor;
class J2DAnmTransform;
class J2DAnmTevRegKey;
class J2DAnmTextureSRTKey;
class J2DAnmVisibilityFull;
class J2DAnmVtxColor;
class J2DGrafContext;
class J2DScreen;
class J2DAnmTexPattern;
class JKRArchive;
class JSURandomInputStream;
struct ResFONT;
struct ResTIMG;

enum J2DRotateAxis {
/* 0x78 */ ROTATE_X = 'x',
Expand All @@ -46,44 +33,26 @@ class J2DPane {
J2DPane();
J2DPane(J2DPane*, bool, u32, const JGeometry::TBox2<f32>&);
J2DPane(u32, const JGeometry::TBox2<f32>&);
J2DPane(J2DPane* other, JSURandomInputStream* stream, u8 arg3);
J2DPane(J2DPane*, JSURandomInputStream*);
void initiate();
void initialize(J2DPane*, bool, u64, const JGeometry::TBox2<f32>&);
void initialize(u64 tag, const JGeometry::TBox2<f32>& dim);
void makePaneStream(J2DPane* other, JSURandomInputStream* stream);
void changeUseTrans(J2DPane* other);
bool appendChild(J2DPane* child);
bool insertChild(J2DPane* before, J2DPane* child);
void draw(f32 a1, f32 a2, const J2DGrafContext* ctx, bool a4);
void place(const JGeometry::TBox2<f32>& dim);
JGeometry::TBox2<f32>& getBounds();
void rotate(f32 offsetX, f32 offsetY, J2DRotateAxis axis, f32 angle);
void rotate(f32 angle);
void clip(const JGeometry::TBox2<f32>& bounds);
void setBasePosition(J2DBasePosition position);
void setInfluencedAlpha(bool arg1, bool arg2);
JGeometry::TVec3<f32> getGlbVtx(u8 arg1) const;
J2DPane* getFirstChildPane();
J2DPane* getNextChildPane();
J2DPane* getParentPane();
void makePaneExStream(J2DPane* other, JSURandomInputStream* stream);
void* getPointer(JSURandomInputStream* stream, u32 size, JKRArchive* archive);
void animationTransform();
void updateTransform(const J2DAnmTransform* transform);

virtual ~J2DPane();
virtual u16 getTypeID() { return 16; }
virtual void move(f32 x, f32 y);
virtual void add(f32 x, f32 y);
virtual void resize(f32 x, f32 y);
virtual bool setConnectParent(bool connected);
virtual void update();
virtual void calcMtx();
virtual void update();
virtual void drawSelf(f32 arg1, f32 arg2);
virtual void drawSelf(f32 arg1, f32 arg2, Mtx* mtx){};
virtual void makeMatrix(f32, f32);
virtual J2DPane* search(u32 tag);
virtual u16 getTypeID() { return 16; }
virtual void makeMatrix(f32, f32);

JSUTree<J2DPane>* getFirstChild() { return mPaneTree.getFirstChild(); }
JSUTree<J2DPane>* getEndChild() { return mPaneTree.getEndChild(); }
Expand All @@ -100,7 +69,7 @@ class J2DPane {
/* 0x6C */ Mtx mDrawMtx;
/* 0x9C */ cXy mBasePosition;
/* 0xA4 */ f32 mRotation;
/* 0xA8 */ u8 mRotationAxis;
/* 0xA8 */ s8 mRotationAxis;
/* 0xA9 */ u8 m2DBasePosition;
/* 0xAA */ bool mVisible;
/* 0xAB */ u8 mCullMode;
Expand Down
63 changes: 63 additions & 0 deletions include/JSystem/J2DGraph/J2DTextBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef J2DTEXTBOX_H
#define J2DTEXTBOX_H

#include "JSystem/J2DGraph/J2DPane.h"
#include "JSystem/JKernel/JKRArchive.h"
#include "JSystem/JUtility/JUTResFont.h"

enum J2DTextBoxHBinding {
/* 0x0 */ HBIND_CENTER,
/* 0x1 */ HBIND_RIGHT,
/* 0x2 */ HBIND_LEFT
};

enum J2DTextBoxVBinding {
/* 0x0 */ VBIND_CENTER,
/* 0x1 */ VBIND_BOTTOM,
/* 0x2 */ VBIND_TOP
};

struct J2DTbxBlockHeader {
/* 0x00 */ u32 mMagic;
/* 0x04 */ s32 mSize;
};

class J2DTextBox : public J2DPane {
public:
J2DTextBox(const char*, const char*);
J2DTextBox(J2DPane*, JSURandomInputStream*);
J2DTextBox(u32, const JGeometry::TBox2<f32>&, const ResFONT*, const char*, J2DTextBoxHBinding,
J2DTextBoxVBinding);

void initiate(const ResFONT*, const char*, J2DTextBoxHBinding, J2DTextBoxVBinding);
void setFont(JUTFont*);
void draw(f32, f32, f32, J2DTextBoxHBinding);
char* getStringPtr() const;
s32 setString(const char*, ...);

virtual ~J2DTextBox();
virtual bool setConnectParent(bool);
virtual void drawSelf(f32, f32);
virtual void drawSelf(f32, f32, Mtx*);
virtual void resize(f32, f32);
virtual u16 getTypeID() { return 19; };

private:
/* 0xCC */ JUTResFont* mpFont;
/* 0xD0 */ JUtility::TColor mGradientFirst;
/* 0xD4 */ JUtility::TColor mGradientSecond;
/* 0xD8 */ f32 field_0xd8;
/* 0xDC */ f32 field_0xdc;
/* 0xD0 */ f32 field_0xe0;
/* 0xE4 */ f32 mFontLeading;
/* 0xE8 */ f32 mFontWidth;
/* 0xEC */ f32 mFontHeight;
/* 0xF0 */ char* mStringPtr;
/* 0xF4 */ JUtility::TColor mTextColor;
/* 0xF8 */ JUtility::TColor mTextBGColor;
/* 0xFC */ u8 mBindingH;
/* 0xFD */ u8 mBindingV;
/* 0xFE */ bool mTextFontOwned;
}; // Size: 0x100

#endif /* J2DTEXTBOX_H */
26 changes: 13 additions & 13 deletions include/JSystem/JUtility/JUTFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
#include "JSystem/JUtility/TColor.h"
#include "MSL_C/string.h"

struct BlockHeader {
const BlockHeader* getNext() const {
return reinterpret_cast<const BlockHeader*>(reinterpret_cast<const u8*>(this) + size);
}
u32 magic;
u32 size;
};

struct ResFONT {
struct INF1 {
/* 0x00 */ u32 magic;
/* 0x04 */ u32 size;
struct INF1 : BlockHeader {
/* 0x08 */ u16 fontType;
/* 0x0A */ u16 ascent;
/* 0x0C */ u16 descent;
Expand All @@ -16,27 +22,21 @@ struct ResFONT {
/* 0x12 */ u16 defaultCode;
};

struct WID1 {
/* 0x00 */ u32 magic;
/* 0x04 */ u32 size;
struct WID1 : BlockHeader {
/* 0x08 */ u16 startCode;
/* 0x0A */ u16 endCode;
/* 0x0C */ u8 mChunkNum[4];
};

struct MAP1 {
/* 0x00 */ u32 magic;
/* 0x04 */ u32 size;
struct MAP1 : BlockHeader {
/* 0x08 */ u16 mappingMethod;
/* 0x0A */ u16 startCode;
/* 0x0C */ u16 endCode;
/* 0x0E */ u16 numEntries;
/* 0x10 */ u16 mLeading;
};

struct GLY1 {
/* 0x00 */ u32 magic;
/* 0x04 */ u32 size;
struct GLY1 : BlockHeader {
/* 0x08 */ u16 startCode;
/* 0x0A */ u16 endCode;
/* 0x0C */ u16 cellWidth;
Expand Down Expand Up @@ -80,7 +80,7 @@ class JUTFont {
/* 0x30 */ virtual int getCellWidth() const;
/* 0x34 */ virtual s32 getCellHeight() const;
/* 0x38 */ virtual int getFontType() const = 0;
/* 0x3C */ virtual ResFONT* getResFont() const = 0;
/* 0x3C */ virtual const ResFONT* getResFont() = 0;
/* 0x40 */ virtual bool isLeadByte(int a1) const = 0;

static bool isLeadByte_1Byte(int b);
Expand Down
73 changes: 33 additions & 40 deletions include/JSystem/JUtility/JUTResFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,36 @@ class JKRHeap;

typedef bool (*IsLeadByte_func)(int);

struct BlockHeader {
const BlockHeader* getNext() const { return reinterpret_cast<const BlockHeader*>(reinterpret_cast<const u8*>(this) + size); }
u32 magic;
u32 size;
};

class JUTResFont : public JUTFont {
public:
/* 802DF000 */ virtual ~JUTResFont();
/* 802DF48C */ virtual void setGX();
/* 802DF584 */ virtual void setGX(JUtility::TColor, JUtility::TColor);
/* 802DF7C4 */ virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool);
/* 802DDFEC */ virtual int getLeading() const;
/* 802DE004 */ virtual s32 getAscent() const;
/* 802DE010 */ virtual s32 getDescent() const;
/* 802DE01C */ virtual s32 getHeight() const;
/* 802DDFF8 */ virtual s32 getWidth() const;
/* 802DFC64 */ virtual void getWidthEntry(int, JUTFont::TWidth*) const;
/* 802DFD0C */ virtual int getCellWidth() const;
/* 802DFD58 */ virtual s32 getCellHeight() const;
/* 802DDFE0 */ virtual int getFontType() const;
/* 802DDFD8 */ virtual ResFONT* getResFont() const;
/* 802DFDA4 */ virtual bool isLeadByte(int) const;
/* 802DFF60 */ virtual void loadImage(int, _GXTexMapID);
/* 802DF344 */ virtual void setBlock();
virtual ~JUTResFont();
virtual void setGX();
virtual void setGX(JUtility::TColor, JUtility::TColor);
virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool);
virtual int getLeading() const { return mInfoBlock->leading; }
virtual s32 getAscent() const { return mInfoBlock->ascent; }
virtual s32 getDescent() const { return mInfoBlock->descent; }
virtual s32 getHeight() const { return getAscent() + getDescent(); }
virtual s32 getWidth() const { return mInfoBlock->width; }
virtual void getWidthEntry(int, JUTFont::TWidth*) const;
virtual int getCellWidth() const;
virtual s32 getCellHeight() const;
virtual int getFontType() const { return mInfoBlock->fontType; }
virtual const ResFONT* getResFont() { return mResFont; }
virtual bool isLeadByte(int) const;
virtual void loadImage(int, _GXTexMapID);
virtual void setBlock();

/* 802DEF94 */ JUTResFont(ResFONT const*, JKRHeap*);
/* 802DEF48 */ JUTResFont();
/* 802DF08C */ void deleteMemBlocks_ResFont();
/* 802DF0B0 */ void initialize_state();
/* 802DF0DC */ bool initiate(ResFONT const*, JKRHeap*);
/* 802DF13C */ bool protected_initiate(ResFONT const*, JKRHeap*);
/* 802DF248 */ void countBlock();
/* 802DFBE8 */ void loadFont(int, _GXTexMapID, JUTFont::TWidth*);
/* 802DFDD8 */ int getFontCode(int) const;
/* 802E00C4 */ int convertSjis(int, u16*) const;
JUTResFont(ResFONT const*, JKRHeap*);
JUTResFont();
void deleteMemBlocks_ResFont();
void initialize_state();
bool initiate(ResFONT const*, JKRHeap*);
bool protected_initiate(ResFONT const*, JKRHeap*);
void countBlock();
void loadFont(int, _GXTexMapID, JUTFont::TWidth*);
int getFontCode(int) const;
int convertSjis(int, u16*) const;

inline void delete_and_initialize() {
deleteMemBlocks_ResFont();
Expand All @@ -52,20 +46,19 @@ class JUTResFont : public JUTFont {

static IsLeadByte_func const saoAboutEncoding_[3];

// some types uncertain, may need to be fixed
/* 0x1C */ int mWidth;
/* 0x20 */ int mHeight;
/* 0x24 */ _GXTexObj field_0x24;
/* 0x44 */ int field_0x44;
/* 0x44 */ int mTexPageIdx;
/* 0x48 */ const ResFONT* mResFont;
/* 0x4C */ ResFONT::INF1* mInf1Ptr;
/* 0x50 */ void** mMemBlocks;
/* 0x4C */ ResFONT::INF1* mInfoBlock;
/* 0x50 */ void** mpMemBlocks;
/* 0x54 */ ResFONT::WID1** mpWidthBlocks;
/* 0x58 */ ResFONT::GLY1** mpGlyphBlocks;
/* 0x5C */ ResFONT::MAP1** mpMapBlocks;
/* 0x60 */ u16 mWid1BlockNum;
/* 0x62 */ u16 mGly1BlockNum;
/* 0x64 */ u16 mMap1BlockNum;
/* 0x60 */ u16 mWidthBlockNum;
/* 0x62 */ u16 mGlyphBlockNum;
/* 0x64 */ u16 mMapBlockNum;
/* 0x66 */ u16 field_0x66;
/* 0x68 */ u16 mMaxCode;
/* 0x6C */ IsLeadByte_func* mIsLeadByte;
Expand Down
25 changes: 13 additions & 12 deletions src/JSystem/J2DGraph/J2DPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "JSystem/J2DGraph/J2DPane.h"
#include "JSystem/JSupport/JSURandomInputStream.h"
#include "dolphin/gx/GXEnum.h"
#include "dolphin/types.h"

/* 802CF8F4-802CF984 .text __ct__7J2DPaneFv */
Expand Down Expand Up @@ -180,8 +181,18 @@ J2DPane* J2DPane::search(u32 tag) {
}

/* 802D0714-802D0800 .text makeMatrix__7J2DPaneFff */
void J2DPane::makeMatrix(float, float) {
/* Nonmatching */
void J2DPane::makeMatrix(f32 x, f32 y) {
Mtx stack1, stack2, stack3;
if (mRotation != 0.0f) {
MTXTrans(stack1, -mBasePosition.x, -mBasePosition.y, 0.0f);
f32 rot = mRotationAxis == ROTATE_Z ? -mRotation : mRotation;
MTXRotRad(stack2, mRotationAxis, rot * 0.017445329f);
MTXTrans(stack3, mBasePosition.x + x, mBasePosition.y + y, 0.0f);
MTXConcat(stack2, stack1, mMtx);
MTXConcat(stack3, mMtx, mMtx);
} else {
MTXTrans(mMtx, x, y, 0.0f);
}
}

/* 802D0800-802D08D8 .text setBasePosition__7J2DPaneF15J2DBasePosition */
Expand Down Expand Up @@ -209,13 +220,3 @@ void J2DPane::setBasePosition(J2DBasePosition pos) {
mRotationAxis = ROTATE_Z;
calcMtx();
}

/* 802D08D8-802D08DC .text drawSelf__7J2DPaneFffPA3_A4_f */
// void J2DPane::drawSelf(float, float, float (*)[3][4]) {
// /* Nonmatching */
// }

/* 802D08DC-802D08E4 .text getTypeID__7J2DPaneFv */
// u16 J2DPane::getTypeID() {
// /* Nonmatching */
// }
Loading

0 comments on commit a321031

Please sign in to comment.