this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #1322 from nalquas/master

Clip mouse values in SDL and Sokol

authored by

Vadim Grigoruk and committed by
GitHub
4493f351 77bf472a

+31 -7
+21 -5
src/system/sdl/main.c
··· 524 524 #if defined(CRT_SHADER_SUPPORT) 525 525 if(crtMonitorEnabled()) 526 526 { 527 - if(rect.w) input->mouse.x = (mx - rect.x) * TIC80_FULLWIDTH / rect.w; 528 - if(rect.h) input->mouse.y = (my - rect.y) * TIC80_FULLHEIGHT / rect.h; 527 + if(rect.w) { 528 + int temp_x = (mx - rect.x) * TIC80_FULLWIDTH / rect.w; 529 + if (temp_x < 0) temp_x = 0; else if (temp_x >= TIC80_FULLWIDTH) temp_x = TIC80_FULLWIDTH-1; // clip: 0 to TIC80_FULLWIDTH-1 530 + input->mouse.x = temp_x; 531 + } 532 + if(rect.h) { 533 + int temp_y = (my - rect.y) * TIC80_FULLHEIGHT / rect.h; 534 + if (temp_y < 0) temp_y = 0; else if (temp_y >= TIC80_FULLHEIGHT) temp_y = TIC80_FULLHEIGHT-1; // clip: 0 to TIC80_FULLHEIGHT-1 535 + input->mouse.y = temp_y; 536 + } 529 537 } 530 538 else 531 - #endif 539 + #endif 532 540 { 533 - if(rect.w) input->mouse.x = (mx - rect.x) * TIC80_WIDTH / rect.w + TIC80_OFFSET_LEFT; 534 - if(rect.h) input->mouse.y = (my - rect.y) * TIC80_HEIGHT / rect.h + TIC80_OFFSET_TOP; 541 + if (rect.w) { 542 + int temp_x = (mx - rect.x) * TIC80_WIDTH / rect.w + TIC80_OFFSET_LEFT; 543 + if (temp_x < 0) temp_x = 0; else if (temp_x >= TIC80_FULLWIDTH) temp_x = TIC80_FULLWIDTH-1; // clip: 0 to TIC80_FULLWIDTH-1 544 + input->mouse.x = temp_x; 545 + } 546 + if (rect.h) { 547 + int temp_y = (my - rect.y) * TIC80_HEIGHT / rect.h + TIC80_OFFSET_TOP; 548 + if (temp_y < 0) temp_y = 0; else if (temp_y >= TIC80_FULLHEIGHT) temp_y = TIC80_FULLHEIGHT-1; // clip: 0 to TIC80_FULLHEIGHT-1 549 + input->mouse.y = temp_y; 550 + } 535 551 } 536 552 } 537 553
+10 -2
src/system/sokol/sokol.c
··· 356 356 struct {s32 x, y, w, h;}rect; 357 357 sokol_calc_viewport(&rect.x, &rect.y, &rect.w, &rect.h); 358 358 359 - if(rect.w) input->mouse.x = ((s32)event->mouse_x - rect.x) * TIC80_FULLWIDTH / rect.w; 360 - if(rect.h) input->mouse.y = ((s32)event->mouse_y - rect.y) * TIC80_FULLHEIGHT / rect.h; 359 + if (rect.w) { 360 + int temp_x = ((s32)event->mouse_x - rect.x) * TIC80_FULLWIDTH / rect.w 361 + if (temp_x < 0) temp_x = 0; else if (temp_x >= TIC80_FULLWIDTH) temp_x = TIC80_FULLWIDTH-1; // clip: 0 to TIC80_FULLWIDTH-1 362 + input->mouse.x = temp_x; 363 + } 364 + if (rect.h) { 365 + int temp_y = ((s32)event->mouse_y - rect.y) * TIC80_FULLHEIGHT / rect.h; 366 + if (temp_y < 0) temp_y = 0; else if (temp_y >= TIC80_FULLHEIGHT) temp_y = TIC80_FULLHEIGHT-1; // clip: 0 to TIC80_FULLHEIGHT-1 367 + input->mouse.y = temp_y; 368 + } 361 369 } 362 370 break; 363 371 case SAPP_EVENTTYPE_MOUSE_DOWN: