Jump to content

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


Dreikblack
 Share

Go to solution Solved by Josh,

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

  • 1 month later...

I considered it but there are two things that made me decide against it.

  • An icon may be in use across many widgets, so using it to indicate state isn't a great idea.
  • Rasterization is of an icon into a pixmap (which must be done to make it visible) is a relatively slow step and should be avoided in real-time.

If anything, it would probably be better to have the widget foreground color affect the widget pixmap.

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

  • 2 weeks later...
  • Solution

I am going to mark this as solved and icons, for the time being, will be considered a vector image from which pixmaps are rasterized. I need to focus on the more basic functionality and make sure that works before adding more complexity.

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...