SystemCursor (wrapper class for SDL_Cursor)

Home Forums Monkey 2 Code Library SystemCursor (wrapper class for SDL_Cursor)

Tagged: ,

This topic contains 6 replies, has 2 voices, and was last updated by  AdamStrange 2 months, 1 week ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10438

    nerobot
    Participant

    This class allow us to change system app cursor.

    Profit: all raw SDL_ structures are hidden / incapsulated here.

    One use case is – If you want to change cursor when mouse enter your view, and restore when mouse leave.

    To do that, you need to override OnMouseEvent (or OnContentMouseEvent):

    Available cursors:

    • Arrow
    • Beam
    • Wait
    • WaitArrow
    • Hand
    • No
    • CrossHair,
    • SizeNWSE, SizeNESW, SizeWE, SizeNS, SizeAll

    Source code:

    #10440

    AdamStrange
    Participant

    Brilliant work.

    Here’s a proper class version of the above for you as well:

    and to use:

    #10441

    nerobot
    Participant

    Here’s a proper class version of the above for you as well

    In what place it’s proper?

    1. System cursor is a global thing, so we can manege it the sane way – via global functions. In your case we must create instance or instances.
    2. Separated global consts bring some noise in autocompletion, if I would write game for mobiles, I will see them when type cur somewhere.
    3. You restore CURSOR_ARROW, but cursor might be not an arrow type.

    My class present not a single cursor – it is cursor manager. 😉

    #10442

    AdamStrange
    Participant

    mmmm, not sure about the cursor and mobile thing. in ‘general’ mobile stuff does not use cursors. Cursors are a desktop thing.

    the default cursor IS an Arrow. You are assuming that is ‘could’ be something else. It won’t. it WILL be an arrow. Unless already set by something and not put back to an arrow <- in which case it’s an error and the Arrow should be used.

    A control may have different cursors, but the default will always be an arrow. it is up to you to decide, but it should always  be set back to an Arrow.

    But… There can be issues with controls not setting the cursor back to the default arrow, and thus affecting the required use in other controls. hence using Arrow as the default.

     

    The reason I used ‘proper’ as the use for the class is you are not really using the class. you are using just functions and some globals. you can remove the class entirely and it still functions. So. in this case it is not really a class.

    Also you are using globals inside a class, thus breaking the reason for using oop in the first place.

     

    in essence you’ve just got a bunch of functions and some globals wrapped up in a class that doesn’t need them. so either write the code to use a class or don’t use a class at all.

     

    to quote you:

    1. System cursor is a global thing, so we can manege it the sane way – via global functions. In your case we must create instance or instances.

    if it is global and accessed by functions then it is functional programming NOT a class. you don’t need a class and are just adding unneeded code.

    You really then just update the functions names with something like:

    function CursorStore(

    function CursorRestore(

    etc

     

    I’m not sure about the following statement:

    Separated global consts bring some noise in autocompletion

     

    doesn’t that suggest the possibility that there might be something off with the autocomplete in its operation? I don’t know about that as I don’t use it. But if you need to program something (in a very particular way)  to avoid it doing something… possibly?

     

    But as I said, brilliant work, either way 😉

    #10443

    nerobot
    Participant

    Yes, in some cases I use classes just as a container for functions.

    It’s convenient way for me – keep all similar functions in one place / scope / entry_point.

    #10453

    nerobot
    Participant

    I was confused to know – there is MouseDevice.Cursor property to deal with system cursors. 🙂

    #10454

    AdamStrange
    Participant

    ???? Checked and confirmed in mojo.MouseDevice

    tried setting it by using:

    and it worked!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.