Ticket #7979: sdl.diff
File sdl.diff, 4.6 KB (added by , 22 years ago) |
---|
-
.cpp
old new 153 153 154 154 /* Keyboard mouse emulation */ 155 155 struct KbdMouse { 156 int16 x, y, x v, yv, xm, ym, xd, yd;157 uint32 last , delay, xdown, ydown;156 int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count; 157 uint32 last_time, delay_time, x_down_time, y_down_time; 158 158 } km; 159 159 160 160 struct MousePos { … … 371 371 } 372 372 373 373 // keyboard cursor control, some other better place for it? 374 km.x m= SCREEN_WIDTH * scaling;375 km.y m= SCREEN_HEIGHT * scaling;376 km.delay = 25;377 km.last = 0;374 km.x_max = SCREEN_WIDTH * scaling; 375 km.y_max = SCREEN_HEIGHT * scaling; 376 km.delay_time = 25; 377 km.last_time = 0; 378 378 379 379 } 380 380 … … 704 704 705 705 void OSystem_SDL::kbd_mouse() { 706 706 uint32 time = get_msecs(); 707 if (time >= km.last + km.delay) { 708 km.last = time; 709 if (km.xd == 1) { 710 km.xdown = time; 711 km.xd = 2; 712 } 713 if (km.yd == 1) { 714 km.ydown = time; 715 km.yd = 2; 716 } 717 718 if (km.xv || km.yv) { 719 if (km.xd) { 720 if (time > km.xdown + km.delay*12) { 721 if (km.xv > 0) 722 km.xv++; 723 else 724 km.xv--; 725 } else if (time > km.xdown + km.delay*8) { 726 if (km.xv > 0) 727 km.xv = 5; 728 else 729 km.xv = -5; 730 } 707 if (time >= km.last_time + km.delay_time) { 708 km.last_time = time; 709 710 if (km.x_down_count == 1) { // just pressed X direction 711 km.x_down_time = time; 712 km.x_down_count = 2; 713 } 714 if (km.y_down_count == 1) { // just pressed Y direction 715 km.y_down_time = time; 716 km.y_down_count = 2; 717 } 718 719 if (km.x_vel || km.y_vel) { 720 if (km.x_down_count) { 721 if (time > km.x_down_time + km.delay_time*12) 722 (km.x_vel > 0) ? km.x_vel++ : km.x_vel--; 723 else if (time > km.x_down_time + km.delay_time*8) 724 (km.x_vel > 0) ? km.x_vel = 5 : km.x_vel = -5; 731 725 } 732 if (km.yd) { 733 if (time > km.ydown + km.delay*12) { 734 if (km.yv > 0) 735 km.yv++; 736 else 737 km.yv--; 738 } else if (time > km.ydown + km.delay*8) { 739 if (km.yv > 0) 740 km.yv = 5; 741 else 742 km.yv = -5; 743 } 726 727 if (km.y_down_count) { 728 if (time > km.y_down_time + km.delay_time*12) 729 (km.y_vel > 0) ? km.y_vel++ : km.y_vel--; 730 else if (time > km.y_down_time + km.delay_time*8) 731 (km.y_vel > 0) ? km.y_vel = 5 : km.y_vel = -5; 744 732 } 745 733 746 km.x += km.x v;747 km.y += km.y v;734 km.x += km.x_vel; 735 km.y += km.y_vel; 748 736 749 if (km.x <= 0) { 750 km.x = 0; 751 km.xv = -1; 752 km.xd = 1; 753 } else if (km.x >= km.xm) { 754 km.x = km.xm - 1; 755 km.xv = 1; 756 km.xd = 1; 737 if (km.x < 0) 738 km.x = km.x_vel = km.x_down_count = 0; 739 else if (km.x >= km.x_max) { 740 km.x = km.x_max - 1; 741 km.x_vel = km.x_down_count = 0; 757 742 } 758 743 759 if (km.y <= 0) { 760 km.y = 0; 761 km.yv = -1; 762 km.yd = 1; 763 } else if (km.y >= km.ym) { 764 km.y = km.ym - 1; 765 km.yv = 1; 766 km.yd = 1; 744 if (km.y < 0) 745 km.y = km.y_vel = km.y_down_count = 0; 746 else if (km.y >= km.y_max) { 747 km.y = km.y_max - 1; 748 km.y_vel = km.y_down_count = 0; 767 749 } 768 750 769 751 SDL_WarpMouse(km.x, km.y); … … 874 856 event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod); 875 857 switch(ev.key.keysym.sym) { 876 858 case SDLK_LEFT: 877 km.x v= -1;878 km.x d= 1;859 km.x_vel = -1; 860 km.x_down_count = 1; 879 861 break; 880 862 case SDLK_RIGHT: 881 km.xv = 1; 882 km.xd = 1; 863 km.x_vel = km.x_down_count = 1; 883 864 break; 884 865 case SDLK_UP: 885 km.y v= -1;886 km.y d= 1;866 km.y_vel = -1; 867 km.y_down_count = 1; 887 868 break; 888 869 case SDLK_DOWN: 889 km.yv = 1; 890 km.yd = 1; 870 km.y_vel = km.y_down_count = 1; 891 871 break; 892 872 default: 893 873 break; … … 898 878 899 879 case SDL_KEYUP: { 900 880 switch(ev.key.keysym.sym){ 901 case SDLK_LEFT: 902 if (km.xv < 0) { 903 km.xv = 0; 904 km.xd = 0; 905 } 881 case SDLK_LEFT: 882 if (km.x_vel < 0) 883 km.x_vel = km.x_down_count = 0; 906 884 break; 907 885 case SDLK_RIGHT: 908 if (km.xv > 0) { 909 km.xv = 0; 910 km.xd = 0; 911 } 886 if (km.x_vel > 0) 887 km.x_vel = km.x_down_count = 0; 912 888 break; 913 889 case SDLK_UP: 914 if (km.yv < 0) { 915 km.yv = 0; 916 km.yd = 0; 917 } 890 if (km.y_vel < 0) 891 km.y_vel = km.y_down_count = 0; 918 892 break; 919 893 case SDLK_DOWN: 920 if (km.yv > 0) { 921 km.yv = 0; 922 km.yd = 0; 923 } 894 if (km.y_vel > 0) 895 km.y_vel = km.y_down_count = 0; 924 896 break; 925 897 default: 926 898 break;