Jump to content

Cannot create TreeView on 3D rendering viewport.


MarKli
 Share

Go to solution Solved by Josh,

Recommended Posts

When creating it I get an access violation when reading at position 0x0000000000000000.

 

#include "UltraEngine.h"

using namespace UltraEngine;

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

    //Create window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0]);

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

    //Create world
    auto world = CreateWorld();

    //Load a font
    auto font = LoadFont("Fonts/arial.ttf");

    //Create user interface
    auto ui = CreateInterface(world, font, framebuffer->size);

    //Create camera
    auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    camera->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0);

    //Create widget
    iVec2 sz = ui->root->ClientSize();

    auto treeview = CreateTreeView(10, 10, sz.x - 20, sz.y - 20, ui->root, TREEVIEW_DRAGANDDROP | TREEVIEW_DRAGINSERT);
    treeview->SetLayout(1, 1, 1, 1);

    auto node = treeview->root->AddNode("Node 1");
    node->AddNode("Subnode 1");
    node->AddNode("Subnode 2");
    node->AddNode("Subnode 3");

    node = treeview->root->AddNode("Node 2");
    node->AddNode("Subnode 1");
    node->AddNode("Subnode 2");
    node->AddNode("Subnode 3");

    node = treeview->root->AddNode("Node 3");
    node->AddNode("Subnode 1");
    node->AddNode("Subnode 2");
    node->AddNode("Subnode 3");

    while (true)
    {
        while (PeekEvent())
        {
            const Event event = WaitEvent();
            switch (event.id)
            {
            case EVENT_WIDGETSELECT:
                if (event.source == treeview and event.data == 1)
                {
                    node = event.extra->As<Widget>();
                    Print("Selected: " + node->text);
                }
                break;
            case EVENT_WIDGETACTION:
                if (event.source == treeview)
                {
                    node = event.extra->As<Widget>();
                    Print("Action: " + node->text);
                    if (!node->kids.empty())
                    {
                        if (node->Collapsed())
                        {
                            node->Expand();
                        }
                        else
                        {
                            node->Collapse();
                        }
                    }
                }
                break;
            case EVENT_WIDGETDROP:
            {
                auto child = event.source->As<Widget>();
                auto parent = event.extra->As<Widget>();
                child->SetParent(parent, event.data);
            }
            break;
            case EVENT_WINDOWCLOSE:
                if (event.source == window)
                {
                    return 0;
                }
                break;
            default:
                ui->ProcessEvent(event);
                break;
            }
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

 

  • Thanks 1
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...