VIDEO: Add hot location functionality to cursor support.

Also sanely report memory allocation errors.
This commit is contained in:
Mark Pizzolato 2016-01-28 07:58:02 -08:00
parent 0897320a16
commit 21b31fc3a8
3 changed files with 17 additions and 6 deletions

View file

@ -794,7 +794,7 @@ if ((vc_dev.dctrl & DBG_CURSOR) && (vc_dev.dctrl & DBG_TCURSOR)) {
} }
} }
} }
vid_set_cursor (visible, 16, 16, data, mask); vid_set_cursor (visible, 16, 16, data, mask, 0, 0);
} }
void vc_checkint (void) void vc_checkint (void)

View file

@ -608,11 +608,20 @@ uint32 *vid_data;
sim_debug (SIM_VID_DBG_VIDEO, vid_dev, "vid_draw(%d, %d, %d, %d)\n", x, y, w, h); sim_debug (SIM_VID_DBG_VIDEO, vid_dev, "vid_draw(%d, %d, %d, %d)\n", x, y, w, h);
vid_dst = (SDL_Rect *)malloc (sizeof(*vid_dst)); vid_dst = (SDL_Rect *)malloc (sizeof(*vid_dst));
if (!vid_dst) {
sim_printf ("%s: vid_draw() memory allocation error\n", vid_dev ? sim_dname(vid_dev) : "Video Device");
return;
}
vid_dst->x = x; vid_dst->x = x;
vid_dst->y = y; vid_dst->y = y;
vid_dst->w = w; vid_dst->w = w;
vid_dst->h = h; vid_dst->h = h;
vid_data = (uint32 *)malloc (w*h*sizeof(*buf)); vid_data = (uint32 *)malloc (w*h*sizeof(*buf));
if (!vid_data) {
sim_printf ("%s: vid_draw() memory allocation error\n", vid_dev ? sim_dname(vid_dev) : "Video Device");
free (vid_dst);
return;
}
memcpy (vid_data, buf, w*h*sizeof(*buf)); memcpy (vid_data, buf, w*h*sizeof(*buf));
user_event.type = SDL_USEREVENT; user_event.type = SDL_USEREVENT;
user_event.user.code = EVENT_DRAW; user_event.user.code = EVENT_DRAW;
@ -626,9 +635,9 @@ if (SDL_PushEvent (&user_event) < 0) {
#endif #endif
} }
t_stat vid_set_cursor (t_bool visible, uint32 width, uint32 height, uint8 *data, uint8 *mask) t_stat vid_set_cursor (t_bool visible, uint32 width, uint32 height, uint8 *data, uint8 *mask, uint32 hot_x, uint32 hot_y)
{ {
SDL_Cursor *cursor = SDL_CreateCursor (data, mask, width, height, 0, 0); SDL_Cursor *cursor = SDL_CreateCursor (data, mask, width, height, hot_x, hot_y);
SDL_Event user_event; SDL_Event user_event;
sim_debug (SIM_VID_DBG_CURSOR, vid_dev, "vid_set_cursor(%s, %d, %d) Setting New Cursor\n", visible ? "visible" : "invisible", width, height); sim_debug (SIM_VID_DBG_CURSOR, vid_dev, "vid_set_cursor(%s, %d, %d) Setting New Cursor\n", visible ? "visible" : "invisible", width, height);
@ -1348,7 +1357,7 @@ if (visible)
if ((vid_window == SDL_GetMouseFocus ()) && visible) if ((vid_window == SDL_GetMouseFocus ()) && visible)
SDL_WarpMouseInWindow (NULL, vid_cursor_x, vid_cursor_y);/* sync position */ SDL_WarpMouseInWindow (NULL, vid_cursor_x, vid_cursor_y);/* sync position */
#endif #endif
if (vid_cursor) if ((vid_cursor != cursor) && (vid_cursor))
SDL_FreeCursor (vid_cursor); SDL_FreeCursor (vid_cursor);
vid_cursor = cursor; vid_cursor = cursor;
SDL_ShowCursor (visible); SDL_ShowCursor (visible);
@ -2089,6 +2098,8 @@ if (!vid_active) {
return SCPE_UDIS | SCPE_NOMESSAGE; return SCPE_UDIS | SCPE_NOMESSAGE;
} }
fullname = malloc (strlen(filename) + 5); fullname = malloc (strlen(filename) + 5);
if (!filename)
return SCPE_MEM;
#if SDL_MAJOR_VERSION == 1 #if SDL_MAJOR_VERSION == 1
#if defined(HAVE_LIBPNG) #if defined(HAVE_LIBPNG)
sprintf (fullname, "%s.png", filename); sprintf (fullname, "%s.png", filename);
@ -2267,7 +2278,7 @@ void vid_draw (int32 x, int32 y, int32 w, int32 h, uint32 *buf)
return; return;
} }
t_stat vid_set_cursor (t_bool visible, uint32 width, uint32 height, uint8 *data, uint8 *mask) t_stat vid_set_cursor (t_bool visible, uint32 width, uint32 height, uint8 *data, uint8 *mask, uint32 hot_x, uint32 hot_y)
{ {
return SCPE_NOFNC; return SCPE_NOFNC;
} }

View file

@ -181,7 +181,7 @@ void vid_draw (int32 x, int32 y, int32 w, int32 h, uint32 *buf);
void vid_beep (void); void vid_beep (void);
void vid_refresh (void); void vid_refresh (void);
const char *vid_version (void); const char *vid_version (void);
t_stat vid_set_cursor (t_bool visible, uint32 width, uint32 height, uint8 *data, uint8 *mask); t_stat vid_set_cursor (t_bool visible, uint32 width, uint32 height, uint8 *data, uint8 *mask, uint32 hot_x, uint32 hot_y);
t_stat vid_set_release_key (FILE* st, UNIT* uptr, int32 val, void* desc); t_stat vid_set_release_key (FILE* st, UNIT* uptr, int32 val, void* desc);
t_stat vid_show_release_key (FILE* st, UNIT* uptr, int32 val, void* desc); t_stat vid_show_release_key (FILE* st, UNIT* uptr, int32 val, void* desc);
t_stat vid_show_video (FILE* st, UNIT* uptr, int32 val, void* desc); t_stat vid_show_video (FILE* st, UNIT* uptr, int32 val, void* desc);