|
Size: 958
Comment: minor change
|
Size: 2378
Comment: Added example.
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 26: | Line 26: |
| You can add your code example here | #include "SDL.h" int main(int argc, char *argv[]) { SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; SDL_Surface *surface = NULL; SDL_Cursor *cursor = NULL; SDL_bool error = SDL_TRUE; if (SDL_Init(SDL_INIT_VIDEO) < 0) { goto exit; } if (SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer) < 0) { goto exit; } surface = SDL_LoadBMP((1 < argc) ? argv[1] : "cursor.bmp"); if (!surface) { goto exit; } cursor = SDL_CreateColorCursor(surface, 0, 0); if (!cursor) { goto exit; } SDL_SetCursor(cursor); SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); while (SDL_TRUE) { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEBUTTONUP: case SDL_QUIT: error = SDL_FALSE; goto exit; } } SDL_RenderClear(renderer); SDL_RenderPresent(renderer); } exit: if (error) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError()); } if (cursor) { SDL_FreeCursor(cursor); } if (surface) { SDL_FreeSurface(surface); } if (renderer) { SDL_DestroyRenderer(renderer); } if (window) { SDL_DestroyWindow(window); } SDL_Quit(); return error; } |
SDL_CreateColorCursor
Use this function to create a color cursor.
Contents
Syntax
SDL_Cursor* SDL_CreateColorCursor(SDL_Surface* surface,
int hot_x,
int hot_y)
Function Parameters
surface |
an SDL_Surface structure representing the cursor image |
hot_x |
the x position of the cursor hot spot |
hot_y |
the y position of the cursor hot spot |
Return Value
Returns the new cursor on success or NULL on failure; call SDL_GetError() for more information.
Code Examples
#include "SDL.h"
int
main(int argc, char *argv[])
{
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Surface *surface = NULL;
SDL_Cursor *cursor = NULL;
SDL_bool error = SDL_TRUE;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
goto exit;
}
if (SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer) < 0) {
goto exit;
}
surface = SDL_LoadBMP((1 < argc) ? argv[1] : "cursor.bmp");
if (!surface) {
goto exit;
}
cursor = SDL_CreateColorCursor(surface, 0, 0);
if (!cursor) {
goto exit;
}
SDL_SetCursor(cursor);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
while (SDL_TRUE) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONUP:
case SDL_QUIT:
error = SDL_FALSE;
goto exit;
}
}
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
exit:
if (error) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError());
}
if (cursor) {
SDL_FreeCursor(cursor);
}
if (surface) {
SDL_FreeSurface(surface);
}
if (renderer) {
SDL_DestroyRenderer(renderer);
}
if (window) {
SDL_DestroyWindow(window);
}
SDL_Quit();
return error;
}
Remarks
You can add useful comments here
