1 /**Test app for set_mouse_position function of the game kit
2 @author Tim de Jong
3 @date 09/09/2002
4 @version 1.0
5 */
6 #include <Application.h>
7 #include <Screen.h>
8 #include <WindowScreen.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #define DELAY 2000
13
14 class TestMouse: public BApplication
15 {
16 public:
17 TestMouse(int times);
18
19 };
20
21 //screenheight and screenwidth
22 int32 height, width;
23
mouse_move_up(int32 x)24 void mouse_move_up(int32 x)
25 {
26 for (int32 t = (height); t > 0; t--)
27 {
28 set_mouse_position(x, t);
29 snooze(DELAY);
30 }
31 }
32
mouse_move_down(int32 x)33 void mouse_move_down(int32 x)
34 {
35 for (int32 t = 0; t < (height); t++)
36 {
37 set_mouse_position(x,t);
38 snooze(DELAY);
39 }
40 }
41
mouse_move_left(int32 y)42 void mouse_move_left(int32 y)
43 {
44 for (int32 t = (width); t > 0; t--)
45 {
46 set_mouse_position(t,y);
47 snooze(DELAY);
48 }
49 }
50
mouse_move_right(int32 y)51 void mouse_move_right(int32 y)
52 {
53 for (int32 t = 0; t < (width); t++)
54 {
55 set_mouse_position(t,y);
56 snooze(DELAY);
57 }
58 }
59
mouse_move_diagonal1(int32 x,int32 y)60 void mouse_move_diagonal1(int32 x, int32 y)
61 {
62 int32 t1 = x;
63 double xmin = (double)x/y;
64 for (int32 t2 = y; t2 > 0; t2--)
65 {
66 t1 = int32(t1 - xmin);
67 set_mouse_position(t1,t2);
68 snooze(DELAY);
69 }
70 }
71
mouse_move_diagonal2(int32 x,int32 y)72 void mouse_move_diagonal2(int32 x, int32 y)
73 {
74 int32 t1 = x;
75 double xplus = (double)width/y;
76 for (int32 t2 = y; t2 > 0; t2--)
77 {
78 t1 = int32(t1 + xplus);
79 set_mouse_position(t1,t2);
80 snooze(DELAY);
81 }
82 }
83
main(int argc,char * argv[])84 int main(int argc, char *argv[])
85 {
86 int times;
87
88 if (argc != 2)
89 {
90 printf("\n Usage: %s param: times, where times is the number of loops \n", argv[0]);
91 times = 1;
92 }
93 else
94 {
95 times = atoi(argv[1]);
96 }
97
98 if (times > 0)
99 {
100 printf("\n times = %d \n", times);
101 TestMouse test(times);
102 test.Run();
103 }
104 else
105 printf("\n Error! times must be an integer greater than 0 \n");
106 return 0;
107 }
108
TestMouse(int times)109 TestMouse::TestMouse(int times)
110 :BApplication("application/x-vnd.test_mouse")
111 {
112
113 //determine screenBounds
114 BScreen screen;
115 BRect screenBounds = screen.Frame();
116 //save screenwidth and screenheight in height and width
117 height = int32(screenBounds.bottom - screenBounds.top) - 5;
118 width = int32(screenBounds.right - screenBounds.left) - 5;
119
120 for (int t = 0; t < times; t++)
121 {
122 //make mouse moves
123 mouse_move_down(0);
124 mouse_move_right(height);
125 mouse_move_diagonal1(width,height);
126 mouse_move_right(0);
127 mouse_move_down(width);
128 mouse_move_left(height);
129 mouse_move_diagonal2(0,height);
130 }
131 //quit app
132 be_app -> PostMessage(B_QUIT_REQUESTED);
133 }
134