Jump to content

Pixmap usage in UI is only updated when using Pixmap::Fill


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

#include "UltraEngine.h"

using namespace UltraEngine;

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

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0], WINDOW_TITLEBAR | WINDOW_RESIZABLE);

    //Create User Interface
    auto ui = CreateInterface(window);
    auto sz = ui->root->ClientSize();

    //Create widget
    auto panel = CreatePanel(50, 50, sz.x - 100, sz.y - 100, ui->root);
    panel->SetColor(0, 0, 0, 1);
    panel->SetLayout(1, 1, 1, 1);

    auto pixmap = CreatePixmap(256, 256);
    pixmap->Fill(0xFF0000FF);
    panel->SetPixmap(pixmap);

    auto btnChangeColor1 = CreateButton("Change Color without fill", 50, 10, 200, 30, ui->root);
    auto btnChangeColor2 = CreateButton("Change Color with fill", 260, 10, 200, 30, ui->root);

    while (true)
    {
        const Event ev = WaitEvent();
        switch (ev.id)
        {
        case EVENT_WIDGETACTION:
        {
            if (ev.source == btnChangeColor1)
            {
                int color = Rgba(Random(255), Random(255), Random(255), 255);
                for (int x = 0; x < pixmap->size.width; x++)
                    for (int y = 0; y < pixmap->size.height; y++)
                        pixmap->WritePixel(x, y, color);
            }
            else if (ev.source == btnChangeColor2)
            {
                pixmap->Fill(Rgba(Random(255), Random(255), Random(255), 255));
            }

            panel->Paint();
            break;
        }

        case EVENT_WINDOWCLOSE:
            return 0;
            break;
        }
    }
    return 0;
}

I am currently experimenting with redirecting the scintilla rendering to a pixmap and found a small bug.

The pixmap is only updated, in this case on the panel, but also when using just the WidgetBlock, when you use the Fill method. any other pixel manipulation is not working when using pixmaps in the ui. I assume, that it might have to do with the underlying Bitmap object is not updated. 

A nice way would be to have something to mark the pixmap as dirty, as i need to use memcpy for performance reasons and then the pixmap will not know if it has chnaged or not.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

I have not run your example yet but I think I know what you are referring to. For some reason I had this commented out in the source in WritePixel...

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

Please think about some kind of setpixels(void* buffer) which uses the update mechanic, writepixel might be much to slow for a lot of scenarios.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

There is a pixels member that is a buffer. You can use Buffer::Poke to set all the pixel data at once. Or maybe even better, just use Pixmap->pixels->Data() to get the memory pointer and use that for whatever functions is writing to a block of memory.

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

That’s what I’m currently doing, but to have the pixmap update correctly in the ui, I needed to cheat a bit, to get access to the getbitmap method and update it myself. A method which would trigger the bitmap update would be useful. Or unify the getbitmap method on all so, withjust diefferent return types.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

Depends. If the update is immediately, I would go with Refresh else I would use invalidate. The problem with this is that it more or less is only valid for the ui system in all other cases the pixmap works well without it. So maybe it should be named to something like RefreshUi?

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
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...