Newer
Older
if (ev.wheel.y > 0)
ciomouse_gotevent(CIOLIB_BUTTON_PRESS(4), -1, -1, -1, -1);
if (ev.wheel.y < 0)
ciomouse_gotevent(CIOLIB_BUTTON_PRESS(5), -1, -1, -1, -1);
}
break;
case SDL_MOUSEBUTTONUP:
if(!ciolib_mouse_initialized)
switch(ev.button.button) {
case SDL_BUTTON_LEFT:
ciomouse_gotevent(CIOLIB_BUTTON_RELEASE(1),win_to_text_xpos(ev.button.x, &cvstat),win_to_text_ypos(ev.button.y, &cvstat), win_to_res_xpos(ev.button.x, &cvstat), win_to_res_ypos(ev.button.y, &cvstat));
ciomouse_gotevent(CIOLIB_BUTTON_RELEASE(2),win_to_text_xpos(ev.button.x, &cvstat),win_to_text_ypos(ev.button.y, &cvstat), win_to_res_xpos(ev.button.x, &cvstat), win_to_res_ypos(ev.button.y, &cvstat));
ciomouse_gotevent(CIOLIB_BUTTON_RELEASE(3),win_to_text_xpos(ev.button.x, &cvstat),win_to_text_ypos(ev.button.y, &cvstat), win_to_res_xpos(ev.button.x, &cvstat), win_to_res_ypos(ev.button.y, &cvstat));
break;
}
break;
case SDL_QUIT:
/*
* SDL2: Do we still need the reaper?
* This is what exit()s programs when the
* X is hit.
*/
if (ciolib_reaper)
sdl_user_func(SDL_USEREVENT_QUIT);
else
break;
case SDL_WINDOWEVENT:
switch(ev.window.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
// SDL2: User resized window
case SDL_WINDOWEVENT_RESIZED:
pthread_mutex_lock(&sdl_mode_mutex);
if (sdl_mode) {
pthread_mutex_unlock(&sdl_mode_mutex);
case SDL_WINDOWEVENT_EXPOSED:
bitmap_drv_request_pixels();
break;
}
break;
case SDL_USEREVENT: {
struct rectlist *list;
struct rectlist *old_next;
switch(ev.user.code) {
case SDL_USEREVENT_QUIT:
sdl_ufunc_retval=0;
if (ciolib_reaper)
exit(0);
sem_post(&sdl_ufunc_ret);
return;
case SDL_USEREVENT_FLUSH:
pthread_mutex_lock(&win_mutex);
if (win != NULL) {
pthread_mutex_lock(&sdl_headlock);
list = update_list;
update_list = update_list_tail = NULL;
bool skipit = sdl_mode;
pthread_mutex_unlock(&sdl_mode_mutex);
pthread_mutex_unlock(&sdl_headlock);
for (; list; list = old_next) {
SDL_Rect src;
SDL_Rect dst;
old_next = list->next;
void *pixels;
int pitch;
int row;
int tw, th;
if (internal_scaling) {
struct graphics_buffer *gb;
internal_scaling_factors(&xscale, &yscale, &cvstat);
cvstat.aspect_width, cvstat.aspect_height);
src.x = 0;
src.y = 0;
src.w = gb->w;
src.h = gb->h;
if (sdl.QueryTexture(texture, NULL, NULL, &tw, &th) != 0)
fprintf(stderr, "Unable to query texture (%s)\n", sdl.GetError());
sdl.RenderClear(renderer);
if (sdl.LockTexture(texture, &src, &pixels, &pitch) != 0)
fprintf(stderr, "Unable to lock texture (%s)\n", sdl.GetError());
if (pitch != gb->w * sizeof(gb->data[0])) {
// If this happens, we need to copy a row at a time...
for (row = 0; row < gb->h && row < th; row++) {
if (pitch < gb->w * sizeof(gb->data[0]))
memcpy(pixels, &gb->data[gb->w * row], pitch);
else
memcpy(pixels, &gb->data[gb->w * row], gb->w * sizeof(gb->data[0]));
pixels = (void *)((char*)pixels + pitch);
}
}
else {
int ch = gb->h;
if (ch > th)
ch = th;
memcpy(pixels, gb->data, gb->w * ch * sizeof(gb->data[0]));
sdl.UnlockTexture(texture);
dst.x = (cvstat.winwidth - gb->w) / 2;
dst.y = (cvstat.winheight - gb->h) / 2;
dst.w = gb->w;
dst.h = gb->h;
release_buffer(gb);
src.x = 0;
src.y = 0;
src.w = list->rect.width;
src.h = list->rect.height;
if (sdl.QueryTexture(texture, NULL, NULL, &tw, &th) != 0)
fprintf(stderr, "Unable to query texture (%s)\n", sdl.GetError());
sdl.RenderClear(renderer);
if (sdl.LockTexture(texture, &src, &pixels, &pitch) != 0)
fprintf(stderr, "Unable to lock texture (%s)\n", sdl.GetError());
if (pitch != list->rect.width * sizeof(list->data[0])) {
// If this happens, we need to copy a row at a time...
for (row = 0; row < list->rect.height && row < th; row++) {
if (pitch < list->rect.width * sizeof(list->data[0]))
memcpy(pixels, &list->data[list->rect.width * row], pitch);
else
memcpy(pixels, &list->data[list->rect.width * row], list->rect.width * sizeof(list->data[0]));
pixels = (void *)((char*)pixels + pitch);
}
}
else {
int ch = list->rect.height;
if (ch > th)
ch = th;
memcpy(pixels, list->data, list->rect.width * ch * sizeof(list->data[0]));
}
sdl.UnlockTexture(texture);
dst.w = cvstat.winwidth;
dst.h = cvstat.winheight;
// Get correct aspect ratio for dst...
aspect_fix(&dst.w, &dst.h, cvstat.aspect_width, cvstat.aspect_height);
dst.x = (cvstat.winwidth - dst.w) / 2;
dst.y = (cvstat.winheight - dst.h) / 2;
if (sdl.RenderCopy(renderer, texture, &src, &dst))
fprintf(stderr, "RenderCopy() failed! (%s)\n", sdl.GetError());
sdl.RenderPresent(renderer);
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
pthread_mutex_unlock(&win_mutex);
break;
case SDL_USEREVENT_SETNAME:
pthread_mutex_lock(&win_mutex);
sdl.SetWindowTitle(win, (char *)ev.user.data1);
pthread_mutex_unlock(&win_mutex);
free(ev.user.data1);
break;
case SDL_USEREVENT_SETICON:
if(sdl_icon != NULL)
sdl.FreeSurface(sdl_icon);
sdl_icon=sdl.CreateRGBSurfaceFrom(ev.user.data1
, *(unsigned long *)ev.user.data2
, *(unsigned long *)ev.user.data2
, 32
, *(unsigned long *)ev.user.data2*4
, *(DWORD *)"\377\0\0\0"
, *(DWORD *)"\0\377\0\0"
, *(DWORD *)"\0\0\377\0"
, *(DWORD *)"\0\0\0\377"
);
pthread_mutex_lock(&win_mutex);
sdl.SetWindowIcon(win, sdl_icon);
pthread_mutex_unlock(&win_mutex);
free(ev.user.data2);
break;
case SDL_USEREVENT_SETTITLE:
pthread_mutex_lock(&win_mutex);
sdl.SetWindowTitle(win, (char *)ev.user.data1);
pthread_mutex_unlock(&win_mutex);
free(ev.user.data1);
break;
case SDL_USEREVENT_SETVIDMODE:
pthread_mutex_lock(&sdl_mode_mutex);
sdl_mode = false;
pthread_mutex_unlock(&sdl_mode_mutex);
pthread_mutex_lock(&vstatlock);
cvstat = vstat;
pthread_mutex_unlock(&vstatlock);
internal_setwinsize(&cvstat);
sdl_ufunc_retval=0;
sem_post(&sdl_ufunc_ret);
break;
case SDL_USEREVENT_HIDEMOUSE:
sdl.ShowCursor(SDL_DISABLE);
break;
case SDL_USEREVENT_SHOWMOUSE:
sdl.ShowCursor(SDL_ENABLE);
break;
case SDL_USEREVENT_INIT:
if(!sdl_init_good) {
if(sdl.WasInit(SDL_INIT_VIDEO)==SDL_INIT_VIDEO) {
pthread_mutex_lock(&win_mutex);
_beginthread(sdl_mouse_thread, 0, NULL);
sdl_init_good=1;
pthread_mutex_unlock(&win_mutex);
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
}
sdl_ufunc_retval=0;
sem_post(&sdl_ufunc_ret);
break;
case SDL_USEREVENT_GETWINPOS:
sdl.GetWindowPosition(win, ev.user.data1, ev.user.data2);
sem_post(&sdl_ufunc_ret);
break;
case SDL_USEREVENT_MOUSEPOINTER:
{
int cid = INT_MIN;
SDL_Cursor *oc = curs;
switch((intptr_t)ev.user.data1) {
case CIOLIB_MOUSEPTR_ARROW:
break; // Default
case CIOLIB_MOUSEPTR_BAR:
cid = SDL_SYSTEM_CURSOR_IBEAM;
break;
}
if (cid == INT_MIN) {
sdl.SetCursor(sdl.GetDefaultCursor());
curs = NULL;
}
else {
curs = sdl.CreateSystemCursor(cid);
if (curs == NULL)
if (oc)
sdl.FreeCursor(oc);
break;
case SDL_SYSWMEVENT: /* ToDo... This is where Copy/Paste needs doing */
/* Ignore this stuff */
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
default:
break;
}
}
int sdl_initciolib(int mode)
{
#if defined(__DARWIN__)
if (initsdl_ret) {
#else
if(init_sdl_video()) {
fprintf(stderr,"SDL Video Initialization Failed\n");
return(-1);
sem_init(&sdl_key_pending, 0, 0);
sem_init(&sdl_ufunc_ret, 0, 0);
sem_init(&sdl_ufunc_rec, 0, 0);
pthread_mutex_init(&sdl_ufunc_mtx, NULL);
pthread_mutex_init(&sdl_headlock, NULL);
pthread_mutex_init(&win_mutex, NULL);
pthread_mutex_init(&sdl_keylock, NULL);
return(sdl_init(mode));
}
void
sdl_beep(void)
{
static unsigned char wave[2206];
if (wave[2205] == 0) {
xptone_makewave(440, wave, 2205, WAVE_SHAPE_SINE_SAW_HARM);
wave[2205] = 1;
}
xp_play_sample(wave, 2205, TRUE);
}