Home > database >  SDL_SetWindowHitTest - callback & callback_data? (SDL 2.0.5)
SDL_SetWindowHitTest - callback & callback_data? (SDL 2.0.5)

Time:06-25

Could someone please help me to understand what these two parameters are, and how to interact with/utilize them? The Wiki says that callback is a function - itself - what should the call of it be like and what should it be returning/doing?

Current Purpose: to Move a Borderless Window (via mouse click and drag)

Alternative: SDL_SetWindowPosition (it's incredibly jittery for manual moving)

I'm on Windows 10, if there is something I can (even more) directly interface with... I've never done that, but if it's a feasible solution I'd also be willing to try that!

CodePudding user response:

Here's how SDL_HitTest (the callback type) is defined:

/**
 * Callback used for hit-testing.
 *
 * \param win the SDL_Window where hit-testing was set on
 * \param area an SDL_Point which should be hit-tested
 * \param data what was passed as `callback_data` to SDL_SetWindowHitTest()
 * \return an SDL_HitTestResult value.
 *
 * \sa SDL_SetWindowHitTest
 */
typedef SDL_HitTestResult (SDLCALL *SDL_HitTest)(SDL_Window *win,
                                                 const SDL_Point *area,
                                                 void *data);

So you need to provide a function with arguments (SDL_Window *win, const SDL_Point *area, void *data), returning SDL_HitTestResult.

The void *callback_data can be anything. It'll be saved and passed to your callback every time. You'll see this pattern a lot in C libraries that work with callbacks, since it allows you to pass additional state into callbacks - a poor man's std::function.

Your function, given coordinates, needs to return if they belong to a window title, or border (which one), or neither.

  • Related