Jump to content

SpiderPig

Members
  • Posts

    2,407
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. The escape isn't quitting the application anymore either...

    #include "Engine.h"
    #include "DynamicUI.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    • Thanks 1
  2. Thankyou, it all compiles now and that example works fine.  But my UI has cracked it. 😧  It's probably because some of the child widgets are the exact same size as their parents but I will have to look into this tomorrow as right now I require slumber. 😴

    UIError.thumb.png.66197357de49f116a7dc5615029f8ac8.png

    • Confused 1
  3. Have just noticed while the clipping of widgets is off by 1 pixel, a child of clipped widget is not clipped at all.  Here the blue panel is a child of the red, which is very large and extends well beyond the region of the green panel.  Perhaps the two clipping issues are related.

    UnclippedUI.png.f6584d8e23bf559b9596e7616ed8e18d.png

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
        
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto w1 = CreatePanel(20, 20, 128, 128, ui->root);
        w1->SetColor(0, 1, 0);
    
        auto w2 = CreatePanel(-10, 10, 1024, 64, w1);
        w2->SetColor(1, 0, 0);
    
        auto w3 = CreatePanel(512, 10, 32, 32, w2);
        w3->SetColor(0, 0, 1);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            while (PeekEvent()) {
                auto ev = WaitEvent();
                ui->ProcessEvent(ev);
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    • Thanks 1
  4. I'm also getting an "Unknown texture format 0"  error loading this specific texture but can't figure it out.  I've tried converting it a few times but it's still no good.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
        
        auto texture = LoadTexture("Basket.dds");
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    Basket.zip

  5. Just a small problem here with changing textures of a widget.  Transparency stops working after it is changed.

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    //Declare new style constants
    enum CustomWidgetStyle
    {
        CUSTOMWIDGET_DEFAULT = 0
    };
    
    //Declare new widget class
    class CustomWidget : public Widget
    {
        //Custom members
        bool hover;
        shared_ptr<Texture> t1, t2;
    
    protected:
    
        virtual bool Initialize(const WString& text, const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const int style)
        {
            t1 = LoadTexture("pinkgrid.dds");
            t2 = LoadTexture("bluegrid.dds");
            return Widget::Initialize(text, x, y, width, height, parent, style);
        }
    
        //Called when the mouse moves if this widget has the focus
        virtual void MouseMove(const int x, const int y) {}
    
        //Called when the mouse cursor enters the widget bounds
        virtual void MouseEnter(const int x, const int y)
        {
            hover = true;
            Redraw();
        }
    
        //Called when the mouse cursor leaves the widget bounds
        virtual void MouseLeave(const int x, const int y)
        {
            hover = false;
            Redraw();
        }
    
        //Called when the mouse button is pressed
        virtual void MouseDown(const MouseButton button, const int x, const int y)
        {
            if (button == MOUSE_LEFT) EmitEvent(EVENT_WIDGETACTION, Self());
        }
    
        //Called when the mouse button is released
        virtual void MouseUp(const MouseButton button, const int x, const int y) {}
    
        //Called when another widget becomes selected
        virtual void LoseFocus() {}
    
        //Called when mouse double-click occurs
        virtual void DoubleClick(const MouseButton button, const int x, const int y) {}
    
        //Called when mouse triple-click occurs
        virtual void TripleClick(const MouseButton button, const int x, const int y) {}
    
        //Called when widget is selected
        virtual void GainFocus() {}
    
        //Called when key is pressed
        virtual void KeyDown(const KeyCode key) {}
    
        //Called when key is released
        virtual void KeyUp(const KeyCode key) {}
    
        //Called for each keydown event
        virtual void KeyChar(const int keychar) {}
    
        //Called when mouse wheel turns and mouse is hovered over this widget
        virtual void MouseWheel(const int delta, const int x, const int y) {}
    
        //Called each time the widget is redrawn
        virtual void Draw(const int x, const int y, const int width, const int height)
        {
            blocks.clear();
    
            //Background rectangle
            int b = AddBlock(iVec2(0), this->size, Vec4(1));
            blocks[b].texture = (hover ? t1 : t2);
    
            //Foreground text
           // AddBlock(text, iVec2(0), this->size, Vec4(1), TEXT_CENTER | TEXT_MIDDLE);
        }
    public:
    
        //Constructor
        CustomWidget() : hover(false)
        {}
    
        friend shared_ptr<Widget> CreateCustomWidget(const WString&, const int, const int, const int, const int, shared_ptr<Widget>, const CustomWidgetStyle);
    };
    
    //Create function
    shared_ptr<Widget> CreateCustomWidget(const WString& text, const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const CustomWidgetStyle style)
    {
        auto widget = std::make_shared<CustomWidget>();
        widget->Initialize(text, x, y, width, height, parent, style);
        return widget;
    }
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 0, -3);
        camera->SetClearColor(1, 0, 0);
    
        auto box = CreateBox(world);
    
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        //Create widget
        auto widget = CreateCustomWidget("Custom", 20, 20, 128, 128, ui->root, CUSTOMWIDGET_DEFAULT);
    
        while (true)
        {
            while (PeekEvent()) {
                auto ev = WaitEvent();
                ui->ProcessEvent(ev);
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    Textures.zip

  6. 35 minutes ago, Josh said:

    There is a "z'" member of the widget class now that stores the Z-position of the first widget block's sprite. This is a temporary hack and it will eventually go away

    I'm getting a value of 731.0f - what's the range of z now?

  7. Ah I see.  I thought I'd be doing something silly for that not too work.  Did you notice that hovering over the custom widget doesn't change the texture?  The draw event is triggered and hover is set to true so it should use texture 't1' and turn pink but it remains blue.

  8. Essentially a repost of the problem I posted earlier but with an additional problem.  The panel on the right has a border drawn on the pixmap itself but it is not visible on the panel.  The panels here are sized 64x64 and the textures are 128x128.  I might be making the wrong assumption that the widgets texture coords are 0 to 1 respectively regards of their size?

    There's also the alpha issue here too.

    PixmapIssues.png.4d9e9dbb62016765d76367b1e0de383e.png

     

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
        auto font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto light = CreateBoxLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        auto box = CreateBox(world);
        box->SetColor(0, 0, 1);
    
        auto actor = CreateActor(box);
        auto component = actor->AddComponent<Mover>();
        component->rotation.y = 45;
    
        auto widget = CreatePanel(600, 350, 64, 64, ui->root, PANEL_BORDER);
        widget->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
        widget->SetPixmap(LoadPixmap("Background.dds"));
    
        auto w2 = CreatePanel(670, 350, 64, 64, ui->root);
        w2->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
        w2->SetPixmap(LoadPixmap("NewBackground.dds"));
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    Background.zip

  9. 10 hours ago, Josh said:

    Widgets don't have a persistent order. Widget blocks are assigned an order any time anything changes. The number of widget blocks, and whether they are hidden or shown, can change from one action to the next.

    What's really needed here is a widget block that can display a line. I don't want to add this until there is time to test on Quartz, GDI, and XRender, because I don't want to start adding features to the 3D GUI that are not supported by a GUI created on a window.

    Yeah I agree.  Having said that though, I would still like to know at what depth the widget is at.  In my case I would ping the depth every loop and set my sprites accordingly anyway, so it doesn't matter if it changes.  At least it would be a fix until you're ready to work on widget blocks supporting lines.

  10. I'd like to use a custom widget for a button that uses textures, one for the normal state and another for the hover.  I don't know if I should do it like this though, the textures don't show.  In one project the normal state shows but the hover state doesn't, here neither show up.

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    //Declare new style constants
    enum CustomWidgetStyle
    {
        CUSTOMWIDGET_DEFAULT = 0
    };
    
    //Declare new widget class
    class CustomWidget : public Widget
    {
        //Custom members
        bool hover;
        shared_ptr<Texture> t1, t2;
    
    protected:
    
        virtual bool Initialize(const WString& text, const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const int style)
        {
            t1 = LoadTexture("pinkgrid.dds");
            t2 = LoadTexture("bluegrid.dds");
            return Widget::Initialize(text, x, y, width, height, parent, style);
        }
    
        //Called when the mouse moves if this widget has the focus
        virtual void MouseMove(const int x, const int y) {}
    
        //Called when the mouse cursor enters the widget bounds
        virtual void MouseEnter(const int x, const int y)
        {
            hover = true;
            Redraw();
        }
    
        //Called when the mouse cursor leaves the widget bounds
        virtual void MouseLeave(const int x, const int y)
        {
            hover = false;
            Redraw();
        }
    
        //Called when the mouse button is pressed
        virtual void MouseDown(const MouseButton button, const int x, const int y)
        {
            if (button == MOUSE_LEFT) EmitEvent(EVENT_WIDGETACTION, Self());
        }
    
        //Called when the mouse button is released
        virtual void MouseUp(const MouseButton button, const int x, const int y) {}
    
        //Called when another widget becomes selected
        virtual void LoseFocus() {}
    
        //Called when mouse double-click occurs
        virtual void DoubleClick(const MouseButton button, const int x, const int y) {}
    
        //Called when mouse triple-click occurs
        virtual void TripleClick(const MouseButton button, const int x, const int y) {}
    
        //Called when widget is selected
        virtual void GainFocus() {}
    
        //Called when key is pressed
        virtual void KeyDown(const KeyCode key) {}
    
        //Called when key is released
        virtual void KeyUp(const KeyCode key) {}
    
        //Called for each keydown event
        virtual void KeyChar(const int keychar) {}
    
        //Called when mouse wheel turns and mouse is hovered over this widget
        virtual void MouseWheel(const int delta, const int x, const int y) {}
    
        //Called each time the widget is redrawn
        virtual void Draw(const int x, const int y, const int width, const int height)
        {
            blocks.clear();
    
            //Background rectangle
            int b = AddBlock(iVec2(0), this->size, Vec4(1));
            blocks[b].texture = (hover ? t1 : t2);
    
            //Foreground text
            AddBlock(text, iVec2(0), this->size, Vec4(1), TEXT_CENTER | TEXT_MIDDLE);
        }
    public:
    
        //Constructor
        CustomWidget() : hover(false)
        {}
    
        friend shared_ptr<Widget> CreateCustomWidget(const WString&, const int, const int, const int, const int, shared_ptr<Widget>, const CustomWidgetStyle);
    };
    
    //Create function
    shared_ptr<Widget> CreateCustomWidget(const WString& text, const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const CustomWidgetStyle style)
    {
        auto widget = std::make_shared<CustomWidget>();
        widget->Initialize(text, x, y, width, height, parent, style);
        return widget;
    }
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        auto camera = CreateCamera(world);
        camera->Move(0, 0, -3);
    
        auto box = CreateBox(world);
    
        auto default_font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, default_font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        //Create widget
        auto widget = CreateCustomWidget("Custom", 20, 20, 120, 36, ui->root, CUSTOMWIDGET_DEFAULT);
      
        auto panel = CreatePanel(100, 100, 100, 100, ui->root);
        panel->SetColor(1, 0, 0);
    
        while (true)
        {
            while (PeekEvent()) {
                auto ev = WaitEvent();
                switch (ev.id)
                {
                case EVENT_WIDGETACTION:
                    Print("Widget action: " + String(ev.data));
                    break;
                case EVENT_WINDOWCLOSE:
                    return 0;
                    break;
                }
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    Images.zip

  11. 3 minutes ago, Josh said:

    Is the child always in the way, and doesn't get used for anything? Is it just decorative? If that is the case, you can call child->SetInteractive(false) and it will be ignored by events. Any mouse events will occur on the parent, and the child will be considered just visual.

    This is how I made the icon and text labels appear on the project buttons in the client app.

    Perfect!  That'll do it.  Thankyou.

    • Like 1
  12. 6 hours ago, Josh said:

    It's working perfectly. Notice the MOUSELEAVE event is even being emitted when you hover over the child. This is exactly what it is supposed to do. :)

    Don't think in terms of hierarchies, think in terms of "which widget is directly under the mouse cursor?".

    Oh I understand now.  So if I wanted to send the MOUSE_ENTER and MOUSE_MOVE events to the parents I simply need to call the call-back on the parent too?  Pretty much exactly what @Dreikblack said but in my case like this:

    bool EventCallback(const Event& event, shared_ptr<Object> extra) {
      //Do Stuff
      
      auto parent = event.source->As<Widget>()->Getparent();
      if(parent != nullptr) {
      	event.source = parent;
      	EventCallback(event, extra);
      }
    }

     

    This example no longer works with Widget::Initialize being inaccessible.

    https://www.ultraengine.com/learn/CustomWidgets?lang=cpp

  13. I think I've narrowed down a problem I've been having with the GUI call-backs.  The child seems to be blocking a lot of the events to its parent.  If the child is smaller than the parent it receives more events but I don't think it gets all of them, hard to tell.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    bool EventCallback(const Event& event, shared_ptr<Object> extra) {
        switch (event.id) {
        case EVENT_MOUSEENTER:
            Print("MOUSE_ENTER");
            break;
        case EVENT_MOUSELEAVE:
            Print("MOUSE_LEAVE");
            break;
        case EVENT_MOUSEDOWN:
            Print("MOUSE_DOWN");
            break;
        case EVENT_MOUSEMOVE:
            Print("MOUSE_MOVE");
            break;
        case EVENT_MOUSEUP:
            Print("MOUSE_UP");
            break;
        case EVENT_MOUSEWHEEL:
            Print("MOUSE_WHEEL");
            break;
        }
    
        return true;
    }
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
        auto font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, font, framebuffer->size);
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_camera->SetRenderLayers(2);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        auto light = CreateBoxLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        auto box = CreateBox(world);
        box->SetColor(0, 0, 1);
    
        auto actor = CreateActor(box);
        auto component = actor->AddComponent<Mover>();
        component->rotation.y = 45;
    
        auto w0 = CreatePanel(10, 10, 128, 128, ui->root);
        auto w1 = CreatePanel(10, 10, 128, 128, w0);
        w1->SetColor(1, 0, 0);
    
    
        ListenEvent(EVENT_NONE, w0, EventCallback);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            while (PeekEvent()) {
                auto event = WaitEvent();
                ui->ProcessEvent(event);
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  14. GetBonePosition(true) is not returning the global position of the bone.  It's not taking into account the model scale and I don't think the rotation either...

    bone_pos = TransformPoint(bone_pos, Mat4(), model->GetMatrix().Inverse());

    EDIT : Yeah, it's just not being transformed.

  15. If you could at least initialize the order variable and keep it public I can do the rest.  Maybe make it a const so we can't edit?  Do you think there might be issues involved in moving sprites between widgets other than z-fighting?

×
×
  • Create New...