Jump to content

Widget's icon can't change a color in real time


Dreikblack
 Share

Recommended Posts

#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<Icon> icon;

bool isFirst = true;

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 = CreatePanel(10, 50, 64, 64, ui->root, PANEL_DEFAULT);
    icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
    icon->SetColor(0.5, 0.5, 1.0);
    panel->SetIcon(icon);
    panel->Redraw();
}


int main(int argc, const char* argv[]) {
    auto displays = GetDisplays();
    window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_DEFAULT);
    menuWold = CreateWorld();
    menuWold->RecordStats();
    framebuffer = CreateFramebuffer(window);
    auto light = CreateBoxLight(menuWold);
    auto camera = CreateCamera(menuWold);
    camera->SetClearColor(0.125);

    initGui();

    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        if (window->KeyHit(KEY_SPACE)) {           
            isFirst = !isFirst;
            if (isFirst) {
                panel->icon->SetColor(0.5, 0.5, 0.5);
                panel->SetIcon(panel->icon);
                panel->Redraw();
            } else {
                panel->icon->SetColor(1.0, 1.0, 0.5);
                panel->SetIcon(panel->icon);
                panel->Redraw();
            }
        }
        menuWold->Update();
        menuWold->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

The way setIcon works is it rasterizes a pixmap with the required scale and applies that to the widget. Setting an icon color will clear all cached pixmaps the icon stores, but the icon does not store a list of widget it has been applied to. I could add this using weak pointers, but I am leaning towards leaving the current behavior alone, since it is a pretty rare use case.

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...