Jump to content

Widget flashes purple while changing an icon or pixmap


Go to solution Solved by Josh,

Recommended Posts

Posted

For some reason usual widgets don't change icon at all so had to create little custom widget with AddBlock();

#include "UltraEngine.h"

using namespace UltraEngine;

shared_ptr<Window> window;
shared_ptr<Framebuffer> framebuffer;
shared_ptr<World> menuWold;
shared_ptr<Interface> ui;
shared_ptr<Camera> uiCamera;

shared_ptr<Widget> panel;
shared_ptr<Widget> btn;

bool isFirst = true;

class TestWidget : public Widget
{
protected:
    virtual void Draw(const int x, const int y, const int width, const int height)
    {
        blocks.clear();
        int blockId = AddBlock(pixmap, iVec2(0), Vec4(1));
    }

public:
    static shared_ptr<TestWidget> create(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const int style = 0)
    {
        struct Struct : public TestWidget {
        };
        auto instance = std::make_shared<Struct>();
        instance->Initialize("", x, y, width, height, parent, style);
        return instance;
    }
};

void initGui()
{
    auto default_font = LoadFont("Fonts\\arial.ttf");
    ui = CreateInterface(menuWold, default_font, framebuffer->GetSize());
    ui->SetRenderLayers(2);
    ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);

    panel = TestWidget::create(10, 50, 64, 64, ui->root);
    auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
    panel->SetIcon(icon);
    btn = CreateButton("Change an icon", 10, 10, 150, 20, ui->root);
}


int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 200, 200, displays[0], WINDOW_DEFAULT);

    //Create a world
    menuWold = CreateWorld();

    //Create a framebuffer
    framebuffer = CreateFramebuffer(window);

    //Create light
    auto light = CreateBoxLight(menuWold);
    light->SetRange(-10, 10);
    light->SetRotation(15, 15, 0);
    light->SetColor(2);

    //Create camera
    auto camera = CreateCamera(menuWold);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -3);
    camera->SetFov(70);

    initGui();

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        while (PeekEvent())
        {
            const Event ev = WaitEvent();
            if (ev.source == btn && ev.id == EVENT_WIDGETACTION)
            {
                isFirst = !isFirst;
                if (isFirst)
                {
                    auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
                    //panel->SetPixmap(icon->Rasterize(1));
                    panel->SetIcon(icon);
                }
                else
                {
                    auto icon2 = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/new.svg");
                    //panel->SetPixmap(icon2->Rasterize(1));
                    panel->SetIcon(icon2);
                }
            }
            ui->ProcessEvent(ev);
        }
        menuWold->Update();
        menuWold->Render(framebuffer);
    }
    return 0;
}

 

  • 1 month later...
Posted

This may be fixed already in the incoming build. I could not produce the described error on my end.

My job is to make tools you love, with the features you want, and performance you can't live without.

  • Solution
Posted

This is probably solved, please let me know if any problem continues.

My job is to make tools you love, with the features you want, and performance you can't live without.

  • Josh locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...