Results 1 to 15 of 15
  1. #1
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default Creating a Clickable user interface with Canvas.

    Hi, I am looking to create a canvas interface with clickable buttons.

    Well, I only need a way to create buttons really, I already have the mouseclicking and the interface itself. I just need a way to define an area, and to do something if the cursor within that area and the mouse button is clicked.

    I already know about the interface gem, but that seems to be aimed towards iOS. I'm needing a mouse and keyboard interface.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  2. #2
    MSgt. Shooter Person
    Join Date
    Apr 2011
    Location
    Vancouver, Canada
    Posts
    84

    Default

    Well I think the mouse interface gem does have most of the bits you need. You can just ignore the Scaleform bits and concentrate on the Canvas usage. That won't give you buttons by default, but it can steer you in the right direction in creating your own.

    For reference to anyone else reading this that may want the convenient link: http://udn.epicgames.com/Three/Devel...Interface.html

  3. #3
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Can't say I can see anything I can use. Could you point me to anything of interest?
    I already have a mouse interface, I just need a button.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  4. #4
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    902

    Default

    maybe the link in my sig could help you. (shameless self promotion detected)

    it might be able to give you ideas on how to create a button.

  5. #5
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,365

    Default

    Code:
    class UIWidget extends Object
        abstract;
    
    
    var Vector2D Location, Size;
    var string Label;
    var delegate<ClickCallback> Click;
    
    delegate ClickCallback();
    
    function Update( Canvas C, Vector2D mouse, bool bMouseClicked );
    
    function bool MouseOver( Vector2D mouse )
    {
        return ( mouse.x > Location.x && mouse.y > Location.y && mouse.x < Location.x + Size.x && mouse.y < Location.y + Size.y );
    }
    Code:
    class CustomHUD extends HUD;
    
    var array<UIWidget> AllWidgets;
    
    
    // called from PostRender
    function Update()
    {
        local UIWidget W;
        foreach AllWidgets(W)
        {
            W.Update(Canvas, mousePosition, bMouseWasClicked);
        }
    }
    
    
    event PostBeginPlay()
    {
        local UIWidget W;
    
        W = new (self) class'UIButton';
        W.Location.x = 100;
        W.Location.y = 100;
        W.Size.x = 128;
        W.Size.y = 48;
        W.Label = "Click me!";
        W.Click = ButtonHandler1;
    
        AllWidgets.AddItem(W);
    }
    
    
    function ButtonHandler1()
    {
        `log("Hurrah!");
    }
    Code:
    class UIButton extends UIWidget;
    
    function Update( Canvas C, Vector2D mouse, bool bMouseClicked )
    {
        // button rendering here...
        // ...
    
        if( bMouseClicked && MouseOver(mouse) )
        {
            Click();
        }
    }

  6. #6
    Palace Guard

    Join Date
    Jun 2007
    Location
    Christchurch
    Posts
    3,556

    Default

    Why not just use the existing menu system?

  7. #7
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Thanks, I imagine that will be perfect. But I am having a hell of a time incorporating it into my hud.

    What sort of variable should MousePosition be? I have a Vector2d, but that's not working.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  8. #8
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,365

    Default

    My post is just a basis for learning one, simple approach. As Snake points out you could also use the existing system, which I'm not familiar with.

    Yes, Vector2D for mouse coords. In what way isn't it working? You should just be able to plug them straight in. The only part you need to figure out is how to set bMouseClicked for the one tick.

    Btw the code is untested so there may be hiccups. All the buttons are updated by passing the canvas, mouse position and click state. Each object then renders it's own button through the canvas reference. If bMouseClicked is true it will check if the mouse coords are within the button's rectangle, calling the assigned delegate if so.

    It's the sort of thing you can flesh out to accomodate different types of widgets, though that can lead to a lot more work - if you're heading in that direction it may be better to go with whatever's available in the API.

  9. #9
    Palace Guard
    Join Date
    Feb 2010
    Location
    Tegleg Records
    Posts
    3,785
    Gamer IDs

    Gamertag: tegleg digital

    Default

    make sure you update the mouse position vector2d every draw. it doesnt work if you just call the function (the one from udn anywayz)
    Code:
    We.spazmodicaly.simulate.new.sound.with.technical.equipment.that.is.specificaly.manufactured.for.humans.to.communicate.in.outer.space.Tegleg.manipulates.time.and.space.to.create.new.experiences.to.generate.a.hardcore.database.generation.
    LOOK>> Please ask questions in the forum, NOT a private message <<LOOK
    tegleg.co.uk
    My Tutorials n Stuff
    Games: Tegs Playground - Unwheel2 - VCTF Game - Sponic Mesh 3D - Shh.. dont tell anyone about my android apps.
    will code for money

  10. #10
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Ah, yes. I already have mouseclicks implemented myself. I think I can figure it out.
    I think I am on the verge of implementing it in one of my huds now.

    Can't say I'm familiar with any existing system myself. Other than the mobile interfaces.

    Edit: I am completely new to widgets, so I apologize if this should be obvious.
    But is there more I need to do? I implemented your example base class widget, but I am not seeing anything being drawn. I have also bound my left and right mouse buttons to a custom exec function (for my custom weapon systems and the interface buttons).
    Would that break the delegate ClickCallback(); stuff?

    I have implemented all you have pointed out except for the button example.
    Last edited by Graylord; 07-05-2012 at 07:16 AM.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  11. #11
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Hi, I'm afraid I still don't quite understand the example and I am still having the issue explained above.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  12. #12

    Default

    I'm having some issues with this too.. I can get the button to render and work but only
    if i add it inside of PostRender() the issue I'm running into is performance related.. When
    its iterating through the Array my fps drops ~1-2 fps a sec until its around ~9 fps

  13. #13
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    I'm afraid I cannot see it even if I add it within the PostRender function.

    (I understand how all of it works now by the way, that delegate stuff is a really nifty feature. And how to do the mouseover detection is so obvious when you see it)

    Edit: Got it working by doing the update in the postrender instead. Everything is working perfectly now
    Last edited by Graylord; 08-18-2012 at 01:45 AM.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  14. #14

    Default

    and u don't see any frame rate drop at all doing it like that ? now i don't have the best
    when it comes to a GPU(HD4000 Ivy bridge) but i get a pretty solid 50 fps as long as i
    don't go to crazy with the resolution when playing UT.. so i don't get how 1 iterator in
    my HUD is killing my fps unless i am doing something wrong

  15. #15
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,365

    Default

    Quote Originally Posted by Damage Inc. View Post
    I'm having some issues with this too.. I can get the button to render and work but only
    if i add it inside of PostRender() the issue I'm running into is performance related.. When
    its iterating through the Array my fps drops ~1-2 fps a sec until its around ~9 fps
    Sounds like you are adding the same button to the array each tick, producing multiple copies. Hence the slowdown over time. You shouldn't be adding widgets during PostRender.

    I suggest implementing Crusha's solution http://forums.epicgames.com/threads/...y-Code-Project since its complete and well supported. I only offered mine as an example pattern, and there's no point in me taking it any further.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.