Skip to content

Commit

Permalink
more blo changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Astral-C committed Dec 30, 2024
1 parent a07a9a8 commit 73df891
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 36 deletions.
30 changes: 27 additions & 3 deletions include/io/BloIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ namespace Blo {
uint8_t mAccumulateAlpha;
std::map<std::string, bool> mPaneArgs;


public:
std::shared_ptr<Pane> mToDelete { nullptr };

uint32_t mID;
int16_t mRect[4] {32, 32, 100, 100};
uint8_t mAlpha;
Expand Down Expand Up @@ -154,34 +157,40 @@ namespace Blo {
void SetWidth(uint16_t w) { mRect[2] = w; }
void SetHeight(uint16_t h) { mRect[3] = h; }

glm::vec4* GetToColor(){ return &mToColor; }
glm::vec4* GetFromColor(){ return &mFromColor; }

Picture();
};

class Window : public Pane {
std::shared_ptr<Image> mTextures[4] { nullptr, nullptr, nullptr, nullptr };
std::shared_ptr<Image> mContentTexture { nullptr };
Palette mPalette;
Bti mContectBG;

int16_t mContentRect[4];
glm::vec4 mFromColor;
glm::vec4 mToColor;
std::map<std::string, bool> mWindowArgs;
public:
int16_t mContentRect[4];
bool Load(bStream::CStream* stream, std::shared_ptr<Pane> parent, std::shared_ptr<Archive::Folder> timg);
void DrawHierarchy(std::shared_ptr<Blo::Pane>& selection);
void Draw(std::shared_ptr<Blo::Pane>& selection);
void Save(bStream::CStream* stream);

std::shared_ptr<Image> GetContentTexture() { return mContentTexture; }

std::shared_ptr<Image> GetTexture(uint32_t id) { if(id < 4) { return mTextures[id]; } else { return nullptr; } }
void SetTexture(std::shared_ptr<Image> img, uint32_t id) { if(id < 4) { mTextures[id] = img; } }

glm::vec4* GetToColor(){ return &mToColor; }
glm::vec4* GetFromColor(){ return &mFromColor; }

Window();
};

class Textbox : public Pane {
Font mFont;
glm::vec4 mTopColor {1.0f, 1.0f, 1.0f, 1.0f}, mBottomColor {1.0f, 1.0f, 1.0f, 1.0f};
uint8_t mHAlign, mVAlign;

uint16_t mFontSpacing;
Expand All @@ -195,6 +204,18 @@ namespace Blo {
glm::vec4 mToColor;
std::map<std::string, bool> mTextboxArgs;
public:

int GetFontSpacing() { return static_cast<int>(mFontSpacing); };
int GetFontLeading() { return static_cast<int>(mFontLeading); };
int GetFontWidth() { return static_cast<int>(mFontWidth); };
int GetFontHeight() { return static_cast<int>(mFontHeight); };

void SetFontSpacing(int n) { mFontSpacing = static_cast<uint16_t>(n); };
void SetFontLeading(int n) { mFontLeading = static_cast<uint16_t>(n); };
void SetFontWidth(int n) { mFontWidth = static_cast<uint16_t>(n); };
void SetFontHeight(int n) { mFontHeight = static_cast<uint16_t>(n); };

glm::vec4 mTopColor {1.0f, 1.0f, 1.0f, 1.0f}, mBottomColor {1.0f, 1.0f, 1.0f, 1.0f};
bool Load(bStream::CStream* stream, std::shared_ptr<Pane> parent, std::shared_ptr<Archive::Folder> timg);
void DrawHierarchy(std::shared_ptr<Blo::Pane>& selection);
void Draw(std::shared_ptr<Blo::Pane>& selection);
Expand All @@ -203,6 +224,9 @@ namespace Blo {
Font* GetFont() { return &mFont; };
std::string* GetText() { return &mText; }

glm::vec4* GetToColor(){ return &mToColor; }
glm::vec4* GetFromColor(){ return &mFromColor; }

Textbox();
};

Expand Down
100 changes: 91 additions & 9 deletions src/io/BloIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,50 @@ namespace Blo {
static int blockCount = 0;

Pane::Pane() : mType(ElementType::Pane), mID(0x50414E45) {}
Pane::Pane(ElementType t, uint32_t id) : mType(t), mID(id) {}

Pane::Pane(ElementType t, uint32_t id) : mType(t), mID(id) {
mAlpha = 0x00;
}

Screen::Screen() : Pane(ElementType::Screen, 0x5343524E) {}
Picture::Picture() : Pane(ElementType::Picture, 0x50494354) { mTextures[0] = std::make_shared<Image>(); }
Textbox::Textbox() : Pane(ElementType::Textbox, 0x54585442) { mText = "Text"; }
Window::Window() : Pane(ElementType::Window, 0x57494E44) {}

Picture::Picture() : Pane(ElementType::Picture, 0x50494354) {
mTextures[0] = std::make_shared<Image>();
mBinding = (uint8_t)Binding::Top;
mAnchor = (uint8_t)Anchor::CenterMiddle;
mMirror = MirrorMode::None;
mWrapX = 3;
mWrapY = 3;

mPictArgs["mirror"] = true;
mPictArgs["wrap"] = true;
mPictArgs["fromColor"] = true;
mPictArgs["toColor"] = true;

}

Textbox::Textbox() : Pane(ElementType::Textbox, 0x54585442) {
mText = "Text";
mTextboxArgs["connectParent"] = true;
mTextboxArgs["fromColor"] = true;
mTextboxArgs["toColor"] = true;
}

Window::Window() : Pane(ElementType::Window, 0x57494E44) {
mTextures[0] = std::make_shared<Image>();
mTextures[1] = std::make_shared<Image>();
mTextures[1]->mMirror |= MirrorMode::X;
mTextures[2] = std::make_shared<Image>();
mTextures[2]->mMirror |= MirrorMode::Y;
mTextures[3] = std::make_shared<Image>();
mTextures[3]->mMirror |= MirrorMode::X | MirrorMode::Y;
mContentTexture = std::make_shared<Image>();
mContentTexture->mTextureID = 0xFFFFFFFF;

mWindowArgs["contenttex"] = true;
mWindowArgs["fromColor"] = true;
mWindowArgs["toColor"] = true;
}

void Resource::Load(bStream::CStream* stream, std::shared_ptr<Archive::Folder> timg){
mType = stream->readUInt8();
Expand Down Expand Up @@ -694,8 +733,6 @@ bool Textbox::Load(bStream::CStream* stream, std::shared_ptr<Pane> parent, std::
}

void Window::Draw(std::shared_ptr<Blo::Pane>& selection){
// draw borders

int vidx;
bool clicked = false;

Expand Down Expand Up @@ -804,7 +841,7 @@ void Picture::Draw(std::shared_ptr<Blo::Pane>& selection){
ImSwap(UV0.y, UV1.y);
}

ImGui::Image(static_cast<uintptr_t>(mTextures[0]->mTextureID), {mRect[2] , mRect[3]}, UV0, UV1, ImVec4(mToColor.r, mToColor.g, mToColor.b, mToColor.a * (mAlpha / 255.0f)));
ImGui::Image(static_cast<uintptr_t>(mTextures[0]->mTextureID), {static_cast<float>(mRect[2]) , static_cast<float>(mRect[3])}, UV0, UV1, ImVec4(mToColor.r, mToColor.g, mToColor.b, mToColor.a * (mAlpha / 255.0f)));

if(ImGui::IsItemClicked()){
selection = shared_from_this();
Expand Down Expand Up @@ -921,8 +958,8 @@ void Screen::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
}
ImGui::Separator();
if(ImGui::Selectable("Delete")){
auto iter = std::find(mParent->mChildren.begin(), mParent->mChildren.end(), shared_from_this());
mParent->mChildren.erase(iter);
selection = nullptr;
mParent->mToDelete = shared_from_this();
}
ImGui::EndPopup();
}
Expand All @@ -938,6 +975,11 @@ void Screen::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
}
ImGui::TreePop();
}

if(mToDelete != nullptr){
std::erase(mChildren, mToDelete);
mToDelete = nullptr;
}
}

void Pane::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
Expand Down Expand Up @@ -970,6 +1012,11 @@ void Pane::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
if(ImGui::Selectable("TextBox")){
mChildren.push_back(std::make_shared<Textbox>());
}
ImGui::Separator();
if(ImGui::Selectable("Delete")){
selection = nullptr;
mParent->mToDelete = shared_from_this();
}
ImGui::EndPopup();
}

Expand All @@ -985,6 +1032,11 @@ void Pane::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){

ImGui::TreePop();
}

if(mToDelete != nullptr){
std::erase(mChildren, mToDelete);
mToDelete = nullptr;
}
}

void Picture::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
Expand Down Expand Up @@ -1017,6 +1069,11 @@ void Picture::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
if(ImGui::Selectable("TextBox")){
mChildren.push_back(std::make_shared<Textbox>());
}
ImGui::Separator();
if(ImGui::Selectable("Delete")){
selection = nullptr;
mParent->mToDelete = shared_from_this();
}
ImGui::EndPopup();
}

Expand All @@ -1032,6 +1089,11 @@ void Picture::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){

ImGui::TreePop();
}

if(mToDelete != nullptr){
std::erase(mChildren, mToDelete);
mToDelete = nullptr;
}
}

void Window::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
Expand Down Expand Up @@ -1064,6 +1126,11 @@ void Window::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){
if(ImGui::Selectable("TextBox")){
mChildren.push_back(std::make_shared<Textbox>());
}
ImGui::Separator();
if(ImGui::Selectable("Delete")){
selection = nullptr;
mParent->mToDelete = shared_from_this();
}
ImGui::EndPopup();
}

Expand All @@ -1079,6 +1146,11 @@ void Window::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection){

ImGui::TreePop();
}

if(mToDelete != nullptr){
std::erase(mChildren, mToDelete);
mToDelete = nullptr;
}
}

void Textbox::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection) {
Expand Down Expand Up @@ -1112,6 +1184,11 @@ void Textbox::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection) {
if(ImGui::Selectable("TextBox")){
mChildren.push_back(std::make_shared<Textbox>());
}
ImGui::Separator();
if(ImGui::Selectable("Delete")){
selection = nullptr;
mParent->mToDelete = shared_from_this();
}
ImGui::EndPopup();
}

Expand All @@ -1127,6 +1204,11 @@ void Textbox::DrawHierarchy(std::shared_ptr<Blo::Pane>& selection) {
ImGui::TreePop();
}

if(mToDelete != nullptr){
std::erase(mChildren, mToDelete);
mToDelete = nullptr;
}

}

}
41 changes: 20 additions & 21 deletions src/io/BtiIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ uint16_t RGBA8toRGB565(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {

uint16_t RGBA8toRGB5A3(uint8_t r, uint8_t g, uint8_t b, uint8_t a){
uint16_t color = 0x0000;
if(a != 0xFF){
a >>= 5;
r >>= 4;
g >>= 4;
b >>= 4;
if(a != 255){
uint8_t na = a >> 5;
uint8_t nr = r >> 4;
uint8_t ng = g >> 4;
uint8_t nb = b >> 4;
color = 0x0000;
color |= ((a & 0x7) << 12);
color |= ((r & 0xF) << 8);
color |= ((g & 0xF) << 4);
color |= ((b & 0xF) << 0);
color |= ((na & 0x7) << 12);
color |= ((nr & 0xF) << 8);
color |= ((ng & 0xF) << 4);
color |= ((nb & 0xF) << 0);
} else {
r >>= 3;
g >>= 3;
b >>= 3;
uint8_t nr = r >> 3;
uint8_t ng = g >> 3;
uint8_t nb = b >> 3;
color = 0x8000;
color |= ((r & 0x1F) << 10);
color |= ((g & 0x1F) << 5);
color |= ((b & 0x1F) << 0);
color |= ((nr & 0x1F) << 10);
color |= ((ng & 0x1F) << 5);
color |= ((nb & 0x1F) << 0);
}
return color;
}
Expand Down Expand Up @@ -236,11 +236,11 @@ namespace Decode {
for (int pixelY = 0; pixelY < 4; pixelY++) {
for (int pixelX = 0; pixelX < 4; pixelX++) {
// Bounds check to ensure the pixel is within the image.
uint16_t data = stream->readUInt16();
if ((blockX * 4 + pixelX >= width) || (blockY * 4 + pixelY >= height))
continue;

// RGB values for this pixel are stored in a 16-bit integer.
uint16_t data = stream->readUInt16();
uint32_t rgba8 = ColorFormat::RGB5A3toRGBA8(data);

uint32_t destIndex = (width * ((blockY * 4) + pixelY) + (blockX * 4) + pixelX) * 4;
Expand Down Expand Up @@ -432,7 +432,6 @@ namespace Encode {
for (int pixelX = 0; pixelX < 4; pixelX++) {
// Bounds check to ensure the pixel is within the image.
if ((blockX * 4 + pixelX >= width) || (blockY * 4 + pixelY >= height)){
stream->writeUInt16(0xFFFF);
continue;
}

Expand Down Expand Up @@ -460,19 +459,19 @@ namespace Encode {
uint32_t numBlocksH = height / 4;

// Iterate the blocks in the image
for (int blockY = 0; blockY < numBlocksH; blockY++) {
for (int blockX = 0; blockX < numBlocksW; blockX++) {
for (int blockY = 0; blockY < height; blockY+=4) {
for (int blockX = 0; blockX < width; blockX+=4) {
// Iterate the pixels in the current block
for (int pixelY = 0; pixelY < 4; pixelY++) {
for (int pixelX = 0; pixelX < 4; pixelX++) {
// Bounds check to ensure the pixel is within the image.
if ((blockX * 4 + pixelX >= width) || (blockY * 4 + pixelY >= height)){
if ((blockX + pixelX >= width) || (blockY + pixelY >= height)){
stream->writeUInt16(0xFFFF);
continue;
}

// RGB values for this pixel are stored in a 16-bit integer.
uint32_t destIndex = (width * ((blockY * 4) + pixelY) + (blockX * 4) + pixelX) * 4;
uint32_t destIndex = ((width * (blockY + pixelY)) + (blockX + pixelX)) * 4;
uint8_t r = imageData[destIndex];
uint8_t g = imageData[destIndex + 1];
uint8_t b = imageData[destIndex + 2];
Expand Down
Loading

0 comments on commit 73df891

Please sign in to comment.