added a test app for set_mouse_position function of the game kit

written by Tim de Jong


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1294 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2002-09-29 16:54:44 +00:00
parent b11e9aaa12
commit 697bf7deb7
3 changed files with 120 additions and 0 deletions

View File

@ -1,4 +1,5 @@
SubDir OBOS_TOP src tests kits game ;
SubInclude OBOS_TOP src tests kits game file_game_sound_test ;
SubInclude OBOS_TOP src tests kits game set_mouse_position_test ;

View File

@ -0,0 +1,7 @@
SubDir OBOS_TOP src tests kits game set_mouse_position_test ;
SimpleTest set_mouse_position_test
: test_mouse.cpp
: game be root
;

View File

@ -0,0 +1,112 @@
/**Test app for set_mouse_position function of the game kit
@author Tim de Jong
@date 09/09/2002
@version 1.0
*/
#include <Application.h>
#include <Screen.h>
#include <WindowScreen.h>
#include <stdio.h>
#include <stdlib.h>
class TestMouse: public BApplication
{
public:
TestMouse(int times);
};
//screenheight and screenwidth
int32 height, width;
void mouse_move_up(int32 x)
{
for (int32 t = (height); t > 0; t--)
set_mouse_position(x, t);
}
void mouse_move_down(int32 x)
{
for (int32 t = 0; t < (height); t++)
set_mouse_position(x,t);
}
void mouse_move_left(int32 y)
{
for (int32 t = (width); t > 0; t--)
set_mouse_position(t,y);
}
void mouse_move_right(int32 y)
{
for (int32 t = 0; t < (width); t++)
set_mouse_position(t,y);
}
void mouse_move_diagonal1(int32 x, int32 y)
{
int32 t1 = x;
double xmin = (double)x/y;
for (int32 t2 = y; t2 > 0; t2--)
{
t1 = int32(t1 - xmin);
set_mouse_position(t1,t2);
}
}
void mouse_move_diagonal2(int32 x, int32 y)
{
int32 t1 = x;
double xplus = (double)width/y;
for (int32 t2 = y; t2 > 0; t2--)
{
t1 = int32(t1 + xplus);
set_mouse_position(t1,t2);
}
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("\n Usage: %s param: times, where times is the number of loops \n", argv[0]);
}
else
{
int times = atoi(argv[1]);
if (times > 0)
{
printf("\n times = %d \n", times);
TestMouse test(times);
test.Run();
}
else printf("\n Error! times must be an integer greater than 0 \n");
}
return 0;
}
TestMouse::TestMouse(int times)
:BApplication("application/x-vnd.test_mouse")
{
//determine screenBounds
BScreen screen;
BRect screenBounds = screen.Frame();
//save screenwidth and screenheight in height and width
height = int32(screenBounds.bottom - screenBounds.top) - 5;
width = int32(screenBounds.right - screenBounds.left) - 5;
for (int t = 0; t < times; t++)
{
//make mouse moves
mouse_move_down(0);
mouse_move_right(height);
mouse_move_diagonal1(width,height);
mouse_move_right(0);
mouse_move_down(width);
mouse_move_left(height);
mouse_move_diagonal2(0,height);
}
//quit app
be_app -> PostMessage(B_QUIT_REQUESTED);
}