Example #1
0
void handleMouseMove(SDL_MouseMotionEvent *event)
{
    int x = event->x;
    int y = event->y;

    sdl_mouse_x = x;
    sdl_mouse_y = y;

    if(CURRENT_ITEM_DRAGGED != -1)
    {
        mouse_move(-1,-1);
        return;
    }

    if(x < SCREEN_SHIFT_X || x > SCREEN_SHIFT_X+SCREEN_WIDTH || y < SCREEN_SHIFT_Y || y > SCREEN_SHIFT_Y+SCREEN_HEIGHT)
    {
        if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))
            mouse_move(x-SCREEN_SHIFT_X,y-SCREEN_SHIFT_Y);
        else
            mouse_move(-1,-1);

        return;
    }

    mouse_move(x-SCREEN_SHIFT_X,y-SCREEN_SHIFT_Y);
}
Example #2
0
/**
* Click and drag absolute: move to a relative coordinate within the window
* windowname, clamped.
*/
bool clickAndDragAbsolute(std::string window_name, nlohmann::json action){
   //populate the window variables. 
  int x_start, x_end, y_start, y_end, mouse_button;
  bool no_clamp = false; 
  bool success = populateClickAndDragValues(action, window_name, x_start,
                       x_end, y_start, y_end, mouse_button, no_clamp);
  
  //if we couldn't populate the values, do nothing (window doesn't exist)
  if(!success){ 
    std::cout << "Click and drag unsuccessful due to failure to populate click and drag values." << std::endl;
    return false;
  }


  int start_x_position = action.value("start_x", -1);
  int start_y_position = action.value("start_y", -1);

  int end_x_position = action.value("end_x", -1);
  int end_y_position = action.value("end_y", -1);

  if (start_x_position == end_x_position && start_y_position == end_y_position){
    std::cout << "Error, the click and drag action did not specify movement." << std::endl;
    return false;
  }

  if(end_x_position == -1 || end_y_position == -1){
    std::cout << "ERROR: the click and drag action must include an ending position" << std::endl;
    return false;
  }
  


  //get the mouse into starting position if they are specified.
  if(start_x_position != -1 && start_y_position != -1){ 
    start_x_position = start_x_position + x_start;
    start_y_position = start_y_position + y_start;

    //don't move out of the window.
    clamp(start_x_position, x_start, x_end); 
    clamp(start_y_position, y_start, y_end);
    mouse_move(window_name, start_x_position, start_y_position,x_start, x_end, 
                                                        y_start, y_end, false); 
  }
  
  end_x_position = end_x_position + x_start;
  end_y_position = end_y_position + y_start;
  
  //clamp the end position so we don't exit the window. 
  clamp(end_x_position, x_start, x_end); 
  clamp(end_y_position, y_start, y_end);

  //These functions won't do anything if the window doesn't exist. 
  mouseDown(window_name,mouse_button); 
  mouse_move(window_name, end_x_position, end_y_position,x_start, x_end, 
                                                  y_start, y_end, false);
  mouseUp(window_name,mouse_button);  

  return true;
}
Example #3
0
/*
 * performActions()
 *  Evaluate all keyboard and mouse events
 * Parameters:
 *  char* - data from device
 * Returns:
 *  -none-
 */
void performActions(char *data)
{

	/* Mouse joystick */
	mouse_move(IS_JOYSTICK_UP(data), IS_JOYSTICK_DOWN(data),
	IS_JOYSTICK_LEFT(data), IS_JOYSTICK_RIGHT(data));

	/* Mouse clicks */
	mouse_click(IS_BUTTON_3(data), &click_mode_left, 1);
	mouse_click(IS_BUTTON_4(data), &click_mode_right, 3);

	/* Keys events */
	keyboard_press(IS_CURSOR_UP(data), &key_up, "Up");
	keyboard_press(IS_CURSOR_DOWN(data), &key_down, "Down");
	keyboard_press(IS_CURSOR_LEFT(data), &key_left, "Left");
	keyboard_press(IS_CURSOR_RIGHT(data), &key_right, "Right");

	keyboard_press(IS_BUTTON_6(data), &key_pprior, "Prior");
	keyboard_press(IS_BUTTON_8(data), &key_pnext, "Next");

	keyboard_press(IS_BUTTON_1(data), &key_return, "Return");
	keyboard_press(IS_BUTTON_2(data), &key_escape, "Escape");

	/* Keys speed config */
	mouse_speed(IS_BUTTON_5(data), &speed_decrement, 1, "Increment");
	mouse_speed(IS_BUTTON_7(data), &speed_increment, -1, "Decrement");
}
Example #4
0
static void
handle_event( XEvent *event )
{
	uint button;
	XKeyEvent kev;
	
	switch( event->type - dga.ev_base ) {
	case ButtonPress:
		button = ((XDGAButtonEvent*)event)->button;
		if( button < 4)	/* 1..3 */
			mouse_but_event( kMouseEvent_Down1 << (button-1) );
		break;

	case ButtonRelease:
		button = ((XDGAButtonEvent*)event)->button;
		if( button < 4)
			mouse_but_event( kMouseEvent_Up1 << (button-1) );
		break;

	case MotionNotify:
		mouse_move( ((XDGAMotionEvent*)event)->dx, ((XDGAMotionEvent*)event)->dy );
		break;

	case KeyPress:
	case KeyRelease:
		XDGAKeyEventToXKeyEvent( (XDGAKeyEvent*)event, &kev );
		kev.type = event->type - dga.ev_base;
		x11_key_event( &kev );
		break;
	}
}
Example #5
0
static void mouse_start_timer(DDContext *ctx, HWND hWnd, GF_VideoOutput *vout)
{
	if (ctx->fullscreen) {
		if (!ctx->timer) ctx->timer = SetTimer(hWnd, 10, 1000, NULL);
		mouse_move(ctx, vout);
	}
}
Example #6
0
void move_mouse(GameState* state) {
	MouseMoveEvent e;
	e.screen_x = state->mouse.screen_x;
	e.screen_y = state->mouse.screen_y;
	e.screen_dx = e.screen_x;
	e.screen_dy = e.screen_y;
	e.type = EVENT_MOUSE_MOVE;
	mouse_move(&e, state);
}
Example #7
0
/** Move the selected client
 * \param cmd uicb_t type unused
*/
void
uicb_mouse_move(uicb_t cmd)
{
     (void)cmd;
     CHECK(sel);

     mouse_move(sel);

     return;
}
Example #8
0
/** Process gui events and deliver them as required. 
 \todo This should probably limit how frequently it calls draw 
 render thread
 */
void sdl_master::process_events()
{
	bool done = false;
	
	SDL_MouseMotionEvent mouse_position;
	mouse_position.state = 0;
	mouse_position.x = 0;
	mouse_position.y = 0;
	
	add_draw_timer(50);	//20 fps
	
	SDL_Event event;
	while(!done)
	{
		if (SDL_WaitEvent(&event))
		{ //wait on an event
			switch(event.type)
			{ //Check event type
				case SDL_USEREVENT:
					switch (event.user.code)
					{
						case 0:
							draw();
							break;
						default:
							break;
					}
					break;
				case SDL_MOUSEMOTION:
					mouse_move(&mouse_position, &event.motion);
					mouse_position = event.motion;
					break;
				case SDL_MOUSEBUTTONDOWN:
				case SDL_MOUSEBUTTONUP:
					mouse_click(&event.button);
					break;
				case SDL_KEYDOWN:
				case SDL_KEYUP:
					key_press(&event.key);
					break;
				case SDL_QUIT:
					quit_request();
					break;
				case SDL_VIDEORESIZE: //User resized window
					display = SDL_SetVideoMode(event.resize.w, event.resize.h, 16,
						SDL_HWSURFACE | SDL_DOUBLEBUF); // Create new window
					break;
			}
		}
		done = check_users(done);
	}
//	int status;
//	if (game_client[0] != 0)
//		SDL_WaitThread(game_client[0], &status);
}
Example #9
0
void EMSCRIPTEN_KEEPALIVE main_loop(void)
{
    time_t now = time(NULL);
    static time_t graph_update;
    char url[64];
    static int tatami = 1;
    static time_t forced_update;
#if 1
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
	switch(event.type) {
	case SDL_MOUSEBUTTONDOWN: {
	    SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event;
	    //printf("button down: %d,%d  %d,%d\n", m->button, m->state, m->x, m->y);
	    button_pressed(m->x, m->y);
	    break;
	}
	}
    }

    if (now > next_update ||
	now > forced_update + 3 ||
	icontimer == 1) {
	refresh_window();
	forced_update = now;
    }

    timeout_ask_for_data(NULL);

    if (now > graph_update+2) {
	graph_update = now;
	emscripten_async_wget_data("matchinfo?t=0", NULL, onloadabstract, onerror);
    }

    mouse_move();

    if (icontimer > 0) {
	icontimer--;
    }

    SDL_Rect dest;
    dest.x = dest.y = dest.w = dest.h = 0;
    //dest.y = icontimer - 50;
    //if (dest.y > 0) dest.y = 0;
    if (menuicon && icontimer > 2) {
	SDL_BlitSurface(menuicon, NULL, darea, &dest);
    }

    if (menu_on && menubg) {
	icontimer = 50;
	show_menu();
    }
#endif
}
Example #10
0
void mouse_click(int button, int state, int x, int y)
{
	if (button == GLUT_LEFT_BUTTON)
	{
		if (state == GLUT_DOWN) {
			v_cursor_down = true;
			mouse_move(x, y);
		} else if (state == GLUT_UP) {
			v_cursor_down = false;
		}
	}
}
Example #11
0
void mouse_circle(int r,int dirx,int diry)
{
	int i,d,incX,incY,x,y;
	int dd[8]=
	{
		1, 0,-1,-1,-1, 0, 1, 1
	};

	for(i=0;i<8;i++)
	{
		d=1-r;
		incX=0;
		incY=2*r;
		x=0;
		y=r;
		while(x<y)
		{
			if(d>=0)
			{
				y--;
				incY-=2;
				d-=incY;
				mouse_move(dirx*dd[i],
					   diry*dd[(i+8-6)%8],0,0);
			}
			else
			{
				mouse_move(dirx*dd[(i+8-1)%8],
					   diry*dd[(i+8-7)%8],0,0);
			}
			x++;
			incX+=2;
			d+=incX+1;
			usleep(1);
		}
	}
}
Example #12
0
bool color_picker::mouse_press( const point &p, int b )
{
	if ( b == 1 )
	{
		coord_type r = point::distance( p, center() ) / radius();
		if ( r > 0.70 && r < 0.95 )
		{
			_tracking = true;
			point d = p.delta( center() );
			coord_type h = std::atan2( d.y(), d.x() );
			_current.set_hsl( h, 1.0, 0.5 );
			return mouse_move( p );
		}
	}

	return widget::mouse_press( p, b );
}
Example #13
0
/**
* Moves the mouse to the upper left of the window associated with windowname 
* if it exists.
*/
bool moveMouseToOrigin(std::string window_name){
  //populate the window vals to get the center.
  int height, width, x_start, x_end, y_start, y_end; 
  bool success = populateWindowData(window_name, height, width, x_start,x_end,
                                                                y_start,y_end);

  //wait until the last moment to check window existence.
  if(success&& windowExists(window_name)){ 

    success = mouse_move(window_name, x_start, y_start, x_start, x_end, y_start, y_end, false);
    return success;
  }
  else{
    std::cout << "Attempted to move mouse to origin of nonexistent window" 
                << std::endl;
    return false;
  }
}
Example #14
0
/**
* Centers the mouse on the window associated with windowname if it exists.
*/
bool centerMouse(std::string window_name){
  //populate the window vals to get the center.
  int height, width, x_start, x_end, y_start, y_end; 
  bool success = populateWindowData(window_name, height, width, x_start,x_end,
                                                                y_start,y_end);
  int x_middle = x_start + (width/2);
  int y_middle = y_start+(height/2);

  //wait until the last moment to check window existence.
  if(success && windowExists(window_name)){ 
    success = mouse_move(window_name, x_middle, y_middle, x_start, x_end, y_start, y_end, false);
    return success;
  }
  else{
    std::cout << "Attempted to center mouse on a nonexistent window" 
                << std::endl;
    return false;
  }
}
Example #15
0
int Header::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: mouse_release((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 1: mouse_move((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 2: mouse_left_press((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 3: mouse_left_press(); break;
        case 4: mouse_right_press(); break;
        case 5: mouse_mid_press(); break;
        case 6: mouse_double_click(); break;
        case 7: frame_close(); break;
        case 8: quit_frame(); break;
        default: ;
        }
        _id -= 9;
    }
    return _id;
}
Example #16
0
void wframe::mouseMoveEvent(QMouseEvent *event)
{
	emit mouse_move(event);
}
Example #17
0
int main(int argc, char *argv[]) {
	/*set line buffering of stdout*/
	setvbuf(stdout, NULL, _IOLBF, 0);

	int maxloops;	
	if(argc == 1)
		maxloops = 100;
	else
		maxloops = atoi(argv[1]);
	printf("EVaura activated for %i mining loops\n", maxloops);

	/*Initialize random number generator*/
	point rsult;
	points rsults = {0, NULL};
	gsl_rng_default_seed = time(NULL);
   	r = gsl_rng_alloc (gsl_rng_default);


	current_time = time(NULL);
	int shieldson = 0;
	int randompulse, pulsetimer;
	char number_of_belts = 0;
	char current_belt = 0;
	char is_belt_toast[20] = {0};
	char unable_to_lock = 0;

    display = XOpenDisplay(NULL); // Open first (-best) display
    screen = DefaultScreenOfDisplay(display);
	assert(display);
	
	xdodisplay = xdo_new_with_opened_display (display,":0",1);
	xdo_window_select_with_click(xdodisplay, &EVEwindow);	

	update_screenshot(); //obtain display properties
	initialize_images(); 
	initialize_ore_tables();

	ship *s = &mackinaw;

	for(int i = 0; i < maxloops; i++){

		undock();

		//Warp to belt
		click_on(&menu_belts_inactive, 1, "");
		mysleep(500);

		update_screenshot();
		number_of_belts = find_multiple(&aba_menu, NULL);
		if(number_of_belts < 1){
			printf("No belts found!!!\n Docking!");
			//dock();
			//break;
		}
		else 
			printf("We found %i belts\n", number_of_belts);

		//choose random belt which isn't already depleted
		while((current_belt = random_int(1, number_of_belts)) && 
				is_belt_toast[(int)current_belt] == 1) {
			printf("We chosed %i. belt, but is is empty\n", current_belt);
		}

		if (findmatch(&menu_name, &rsult) == 0){
			click(rsult.X + random_int(0,30), rsult.Y + 19*current_belt, 1, "s");
			printf("Warping to %i. belt\n", current_belt);
		}

		if(random_int(0,3) > 1) {
			start_shields(s);
			shieldson = 1;
		}
		else
			shieldson = 0;
	
		wait_for_warp(s);
		//arrived to belt

		launch_drones(s);

		click_on(&menu_mining_inactive, 1, "");
		mysleep(1500);

		lock_nearest_roid();
		start_mining(&pulsetimer, &randompulse);

		if(shieldson == 0)
			start_shields(s);

		while(1){
			sleep(1);
			update_screenshot();

			if (findmatch(&full_cargo2, NULL) == 0)
				break;

			if (findmatch(&invalid_target, NULL) == 0)
				click_on(&OK, 1, "");

			switch (check_roid_lock()) {
				case 0 :
					unable_to_lock++;
					if(unable_to_lock > 6){
						printf("We were repeatedly unable to lock anything, this belt is probably toast\n");
						//FIXME: this could probably also happen with pirates or roids too far to lock
						is_belt_toast[(int)current_belt] = 1;
						i--;//decrease counter, sice this loop wasnt finished
						goto dock;
					}
					printf("we didnt found any locked roids, attempting to lock one\n");
					if (lock_best_roid() == 0) {	
						start_mining(&pulsetimer, &randompulse);
						unable_to_lock = 0;
					}
					continue;
				case 1 :
					if(find_multiple(&i_mining_laser_active, &rsults) == 0){
						start_mining(&pulsetimer, &randompulse);
					}
					lock_best_roid();
					unable_to_lock = 0;
					continue;
			}

			switch (find_multiple(&i_mining_laser_active, &rsults)) {
				case 0 :
					printf("we have a locked roid however lasers were not active\n");
					start_mining(&pulsetimer, &randompulse);
					continue;
				case 1 :
					xdo_keysequence(xdodisplay, CURRENTWINDOW, "F1", 5);
					//pulse random laser, if we are lucky we turn on the right one
					//if not, we will turn on both next time
					break;
			}

			sleep(2);

			if ( (time(NULL) - pulsetimer) > randompulse ) {
				printf("cycling lasers\n");
				xdo_keysequence(xdodisplay, CURRENTWINDOW, "F1", 5);
				xdo_keysequence(xdodisplay, CURRENTWINDOW, "F2", 5);
				mysleep(1000);
				update_screenshot();
				if (check_roid_lock() == 1) {
					mysleep(50);
					xdo_keysequence(xdodisplay, CURRENTWINDOW, "F1", 5);
					xdo_keysequence(xdodisplay, CURRENTWINDOW, "F2", 5);
					mysleep(random_int(100,300));
				}
				else if(check_roid_lock() > 1 ){
					mouse_move(locked_roids.rsult[0].X, locked_roids.rsult[0].Y);
					xdo_click(xdodisplay, CURRENTWINDOW, 1);
					xdo_keysequence(xdodisplay, CURRENTWINDOW, "F1", 5);
					mysleep(550);
					mouse_move(locked_roids.rsult[1].X, locked_roids.rsult[1].Y);
					xdo_click(xdodisplay, CURRENTWINDOW, 1);
					xdo_keysequence(xdodisplay, CURRENTWINDOW, "F2", 5);
				}

				pulsetimer = time(NULL);
				randompulse = random_int(50,150);
			}
		}

dock:
		dock_drones(s);//we can dock while preparing to warp
		if (click_on(&menu_default_inactive, 1, "") == 0) {
			printf("defalut menu inactive, clicking on it\n");
			mysleep(random_int(800,1200));
		}
		else
			printf("default menu probably active, no need to click\n");

		update_screenshot();
		if(click_on(&aba_peace_station, 1, "d") == 0) {
			printf("found Aba station, attempting a warp\n");
		}
		else 
			printf ("Cant find Aba station, something bad is going on.\n");
	
		wait_for_warp(s);
		mysleep(10000);//FIXME: new function wait for dock???

		
		for (int i = 0; unload_ore(s) == 1; i++){
			mysleep(5000);
			if(i > 4){		
				printf("Unable to unload ore\n");
				goto exit;
			}
		}


	}

exit:

	if(displayImage)
		cvReleaseImage(&displayImage);

	XCloseDisplay(display);

	return 0;
}
Example #18
0
/* unused ? */
void ui_dispatch_next_event(void)
{
#ifdef ANDROID_COMPILE
    struct locnet_al_event event;

    if (Android_PollEvent(&event)) {
#else
    SDL_Event e;

    if (SDL_PollEvent(&e)) {
        ui_handle_misc_sdl_event(e);
#endif
    } else {
        /* Add a small delay to not hog the host CPU when remote
           monitor is being used. */
        SDL_Delay(10);
    }
}
#endif

/* Main event handler */
ui_menu_action_t ui_dispatch_events(void)
{
    SDL_Event e;
    ui_menu_action_t retval = MENU_ACTION_NONE;

#ifdef ANDROID_COMPILE
    struct locnet_al_event event1;

    if (loader_showinfo) {
        int value = loader_showinfo;

        loader_showinfo = 0;
        loader_set_statusbar((value == 1) ? 1 : 0);
    }
    if (loader_true_drive) {
        int value = loader_true_drive;

        loader_true_drive = 0;
        loader_set_drive_true_emulation((value == 1) ? 1 : 0);
    }
    if (loader_turbo) {
        int value = loader_turbo;

        loader_turbo = 0;
        loader_set_warpmode((value == 1) ? 1 : 0);
    }
    if (loadf->frameskip) {
        int value = loadf->frameskip;

        loadf->frameskip = 0;
        resources_set_int("RefreshRate", ((value > 0) && (value <= 10)) ? (value + 1) : 1);
    }
    if (loadf->abort) {
        loadf->abort = 0;
        ui_pause_emulation(1);
        ui_sdl_quit();
        ui_pause_emulation(0);
        return MENU_ACTION_NONE;
    } else if (loader_loadstate) {
        loader_loadstate = 0;
        loader_load_snapshot(savestate_filename);
        ui_pause_emulation(0);
        return MENU_ACTION_NONE;
    } else if (loader_savestate) {
        loader_savestate = 0;
        loader_save_snapshot(savestate_filename);
        ui_pause_emulation(0);
        return MENU_ACTION_NONE;
    }

    int stopPoll = 0;

    while ((!stopPoll) && Android_PollEvent(&event1)) {
        struct locnet_al_event *event = &event1;

        switch (event->eventType) {
            case SDL_MOUSEMOTION:
                {
                    //locnet, 2011-06-16, detect auto calibrate
                    if ((event->x == -2048) && (event->y == -2048)) {
                        down_x = -1;
                        down_y = -1;
                        oldx = 0;
                        oldy = 0;
                        stopPoll = 1;
                    //locnet, 2011-07-01, detect pure relative move
                    } else if ((event->down_x == -1024) && (event->down_y == -1024)) {
                        down_x = 0;
                        down_y = 0;
                        oldx = 0;
                        oldy = 0;
                    } else if ((down_x != event->down_x) || (down_y != event->down_y)) {
                        down_x = event->down_x;
                        down_y = event->down_y;
                        oldx = down_x;
                        oldy = down_y;
                    }
                    mouse_move((int)(event->x - oldx), (int)(event->y - oldy));
                    oldx = event->x;
                    oldy = event->y;
                }
                break;
            case SDL_MOUSEBUTTONDOWN:
                {
                    if ((event->down_x >= 0) && (event->down_y >= 0)) {
                        mouse_x = 640 * event->down_x / 1000.0f - 64;
                        mouse_y = 400 * (1000 - event->down_y) / 1000.0f - 200;
                    }
                    if (event->keycode >= 0) {
                        mouse_button((int)(event->keycode) ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT, 1);
                    }
                    stopPoll = 1;
                }
                break;
            case SDL_MOUSEBUTTONUP:
                {
                    if (event->keycode >= 0) {
                        mouse_button((int)(event->keycode) ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT, 0);
                    }
                    stopPoll = 1;
                }
                break;
            case SDL_JOYAXISMOTION:
                {
                    float x = event->x / 256.0f;
                    float y = event->y / 256.0f;
                    int left = 0, top = 0, right = 0, bot = 0;
                    int value;

                    if (y < -DEAD_ZONE) {
                        top = 1;
                    }
                    if (y > DEAD_ZONE) {
                        bot = 1;
                    }
                    if (x < -DEAD_ZONE) {
                        left = 1;
                    }
                    if (x > DEAD_ZONE) {
                        right = 1;
                    }

                    value = 0;

                    if (left) {
                        value |= 4;
                    }
                    if (right) {
                        value |= 8;
                    }
                    if (top) {
                        value |= 1;
                    }
                    if (bot) {
                        value |= 2;
                    }
                    retval = sdljoy_axis_event(0, 0, event->x / 256.0f * 32767);
                    ui_menu_action_t retval2 = sdljoy_axis_event(0, 1, event->y / 256.0f * 32767);
                    if (retval == MENU_ACTION_NONE) {
                        retval = retval2;
                    }
                    old_joy_direction = value;
                    stopPoll = 1;
                }
                break;
            case SDL_JOYBUTTONDOWN:
                {
                    retval = sdljoy_button_event(0, event->keycode, 1);

                    //2011-09-20, buffer overflow when autofire if stopPoll
                    if (!Android_HasRepeatEvent(SDL_JOYBUTTONDOWN, event->keycode)) {
                        stopPoll = 1;
                    }
                }
                break;
            case SDL_JOYBUTTONUP:
                {
                    retval = sdljoy_button_event(0, event->keycode, 0);

                    //2011-09-20, buffer overflow when autofire if stopPoll
                    if (!Android_HasRepeatEvent(SDL_JOYBUTTONUP, event->keycode)) {
                        stopPoll = 1;
                    }
                }
                break;
            case SDL_KEYUP:
            case SDL_KEYDOWN:
                {
                    static int ctrl_down = 0;
                    static int alt_down = 0;
                    static int shift_down = 0;

                    int down = (event->eventType == SDL_KEYDOWN);
                    unsigned long modifier = event->modifier;
                    int ctrl = ((modifier & KEYBOARD_CTRL_FLAG) != 0);
                    int alt = ((modifier & KEYBOARD_ALT_FLAG) != 0);
                    int shift = ((modifier & KEYBOARD_SHIFT_FLAG) != 0);
                    unsigned long kcode = (unsigned long)event->keycode;

                    int kmod = 0;

                    if (ctrl) {
                        kmod |= KMOD_LCTRL;
                    }
                    if (alt) {
                        kmod |= KMOD_LALT;
                    }
                    if (shift) {
                        kmod |= KMOD_LSHIFT;
                    }
                    if (down) {
                        if (ctrl || (kcode == SDLK_TAB)) {
                            if (!ctrl_down) {
                                keyboard_key_pressed((unsigned long)SDLK_TAB);
                            }
                            ctrl_down++;
                        }
                        if (alt || (kcode == SDLK_LCTRL)) {
                            if (!alt_down) {
                                keyboard_key_pressed((unsigned long)SDLK_LCTRL);
                            }
                            alt_down++;
                        }
                        if (shift || (kcode == SDLK_LSHIFT)) {
                            if (!shift_down) {
                                keyboard_key_pressed((unsigned long)SDLK_LSHIFT);
                            }
                            shift_down++;
                        }
                        retval = sdlkbd_press(kcode, 0);
                    } else {
                        retval = sdlkbd_release(kcode, 0);

                        if (ctrl || (kcode == SDLK_TAB)) {
                            if (kcode == SDLK_TAB) {
                                ctrl_down = 0;
                            }
                            if (ctrl_down) {
                                ctrl_down--;
                            }
                            if (!ctrl_down) {
                                keyboard_key_released((unsigned long)SDLK_TAB);
                            }
                        }
                        if (alt || (kcode == SDLK_LCTRL)) {
                            if (kcode == SDLK_LCTRL) {
                                alt_down = 0;
                            }
                            if (alt_down) {
                                alt_down--;
                            }
                            if (!alt_down) {
                                keyboard_key_released((unsigned long)SDLK_LCTRL);
                            }
                        }
                        if (shift || (kcode == SDLK_LSHIFT)) {
                            if (kcode == SDLK_LSHIFT) {
                                shift_down = 0;
                            }
                            if (shift_down) {
                                shift_down--;
                            }
                            if (!shift_down) {
                                keyboard_key_released((unsigned long)SDLK_LSHIFT);
                            }
                        }
                    }
                    stopPoll = 1;
                }
                break;
        }
    }
#else
    while (SDL_PollEvent(&e)) {
        switch (e.type) {
            case SDL_KEYDOWN:
                retval = sdlkbd_press(e.key.keysym.sym, e.key.keysym.mod);
                break;
            case SDL_KEYUP:
                retval = sdlkbd_release(e.key.keysym.sym, e.key.keysym.mod);
                break;
#ifdef HAVE_SDL_NUMJOYSTICKS
            case SDL_JOYAXISMOTION:
                retval = sdljoy_axis_event(e.jaxis.which, e.jaxis.axis, e.jaxis.value);
                break;
            case SDL_JOYBUTTONDOWN:
                retval = sdljoy_button_event(e.jbutton.which, e.jbutton.button, 1);
                break;
            case SDL_JOYBUTTONUP:
                retval = sdljoy_button_event(e.jbutton.which, e.jbutton.button, 0);
                break;
            case SDL_JOYHATMOTION:
                retval = sdljoy_hat_event(e.jhat.which, e.jhat.hat, e.jhat.value);
                break;
#endif
            case SDL_MOUSEMOTION:
                if (_mouse_enabled) {
                    mouse_move((int)(e.motion.xrel), (int)(e.motion.yrel));
                }
                break;
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                if (_mouse_enabled) {
                    mouse_button((int)(e.button.button), (e.button.state == SDL_PRESSED));
                }
                break;
            default:
                /* SDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE); */
                ui_handle_misc_sdl_event(e);
                /* SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE); */
                break;
        }
        /* When using the menu or vkbd, pass every meaningful event to the caller */
        if (((sdl_menu_state) || (sdl_vkbd_state & SDL_VKBD_ACTIVE)) && (retval != MENU_ACTION_NONE) && (retval != MENU_ACTION_NONE_RELEASE)) {
            break;
        }
    }
#endif
    return retval;
}
Example #19
0
static LRESULT CALLBACK window_handler( HWND window_handle, UINT message,
                                        WPARAM word_param, LPARAM long_param )
{
    bool result = false;

    switch (message)
    {
    case WM_SYSCOMMAND:
    {
        //the application doesn't seem to process sc_close correctly anymore. force an
        //exit of the game here. -ddn
        if (word_param == SC_CLOSE)
        {
            t_game_application::exit(0);
            PostQuitMessage(0);
            return 0;
        }
    }
    break;

    case WM_COMMAND:
        if (g_clearing_messages)
            break;
        if ( t_window::get_modal_window())
        {
            if (t_window::get_modal_window()->menu_click( LOWORD( word_param )))
                return 0;
        }
        else if ( t_window::get_main_window() )
        {
            if ( t_window::get_main_window()->menu_click( LOWORD( word_param ) ) )
                return 0;
        }
        else if ( g_game && g_game->menu_click( LOWORD(word_param) ))
            return 0;
        break;

    case WM_DESTROY:
        t_game_application::exit(0);
        PostQuitMessage(0);
        return 0;

    case WM_LBUTTONDBLCLK:
        if (g_clearing_messages)
            break;

        left_double_click( window_handle, word_param, long_param );
        return 0;

    case WM_LBUTTONDOWN:
        if (g_clearing_messages)
            break;

        left_button_down( window_handle, word_param, long_param );
        return 0;

    case WM_LBUTTONUP:
        if (g_clearing_messages)
            break;

        left_button_up( window_handle, word_param, long_param );
        return 0;

    case WM_MOVE:
        // handle_move( LOWORD(long_param), HIWORD(long_param) );
        return 0;

    case WM_MOUSEMOVE:
        mouse_move( window_handle, word_param, long_param );
        return 0;

    case WM_PAINT:
    {
        PAINTSTRUCT   ps;
        HDC           device_context = BeginPaint(window_handle, &ps);
        t_screen_rect rect = from_windows_rect( ps.rcPaint );
        t_window::invalidate_main_window( rect );
        g_dc = device_context;
        paint_windows();
        EndPaint(window_handle, &ps);
        return 0;
    }

    case WM_RBUTTONDBLCLK:
        if (g_clearing_messages)
            break;
        right_double_click( window_handle, word_param, long_param );
        return 0;

    case WM_RBUTTONDOWN:
        if (g_clearing_messages)
            break;
        right_button_down( window_handle, word_param, long_param );
        return 0;

    case WM_RBUTTONUP:
        if (g_clearing_messages)
            break;
        right_button_up( window_handle, word_param, long_param );
        return 0;

    case WM_SIZE:
        // handle_size( word_param, LOWORD(long_param), HIWORD(long_param) );
        return 0;

    case WM_ACTIVATE:
        if ( (LOWORD(word_param) == WA_ACTIVE)  || (LOWORD(word_param) == 	WA_CLICKACTIVE))
        {
            set_resolution(g_window_width , g_window_height, true);
            handle_adventure_sound_minimization(false);
        }


        if ( LOWORD(word_param) == 	WA_INACTIVE )
        {
            handle_adventure_sound_minimization(true);
        }
        break;

    case WM_DISPLAYCHANGE:
        break;
    }
    return DefWindowProc(window_handle, message, word_param, long_param);
}
Example #20
0
/*
** There is a delay between when the VIC sends its signal, and when the display
** shows that signal.  There is another delay between the display and when
** the lightpen says that it saw that signal. Each display and pen is different.
** Therefore, the driver must be calibrated to them.  A white bar is painted on
** the screen; and, a line is drawn down the middle of it.  When the user clicks
** on that line, the difference between its position and where the VIC thinks
** that the pen is pointing becomes an offset that is subtracted from what the
** VIC sees.
*/
void __fastcall__ pen_calibrate (unsigned char *XOffset)
{
    unsigned char oldBg = bgcolor (COLOR_BLUE);
    unsigned char oldText = textcolor (COLOR_GRAY3);
    unsigned char oldRev = revers (1);
    unsigned char sprite0Color = VIC.spr_color[0];
    unsigned char width, width2, height, height4, height8;
    struct mouse_info info;

    screensize (&width, &height);
    width2 = width / 2;
    height4 = height / 4;
    height8 = height4 * 8;

    /* Draw a bar and line. */

    clrscr ();
    cclearxy (0, height4, height4 * width);
    cvlinexy (width2, height4 + 1, height4 - 2);
    revers (0);

    /* Print instructions. */

    cputsxy (width2 - (sizeof COMMAND1) / 2, height / 2 + 1, COMMAND1);
    cputsxy (width2 - (sizeof COMMAND2) / 2, height / 2 + 3, COMMAND2);

    VIC.spr_color[0] = COLOR_GRAY2;
    mouse_show ();
    mouse_move (width2 * 8, height8 / 2);

    for (;;) {
        /* Wait for the main button to be released. */

        do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));

        /* Wait for the main button to be pressed. */

        do {
            mouse_info (&info);
        } while (!(info.buttons & MOUSE_BTN_LEFT));

        /* Find out if the pen is on or off the bar. */

        if (info.pos.y < height8 || info.pos.y >= height8 * 2) {
            break;
        }

        /* On the bar; adjust the offset. */
        /* Characters are eight pixels wide.
        ** The VIC-II sees every other pixel;
        ** so, we use half of the difference.
        */

        *XOffset += (info.pos.x - (width2 * 8 + 8/2)) / 2;
    }

    /* Off the bar; wait for the main button to be released. */

    do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));

    mouse_hide ();
    VIC.spr_color[0] = sprite0Color;
    revers (oldRev);
    textcolor (oldText);
    bgcolor (oldBg);
    clrscr ();
}
Example #21
0
File: edit.c Project: jff/mathspad
static void edit_motion(void *data, int x, int y)
{
    mouse_move(x-edit_margin(data),y);
}
Example #22
0
static void mouse_handler(GtkWidget *w, GdkEvent *event, gpointer data)
{
    video_canvas_t *canvas = (video_canvas_t *)data;

    if (event->type == GDK_BUTTON_PRESS) {
        GdkEventButton *bevent = (GdkEventButton*)event;
        if (_mouse_enabled || lightpen_enabled) {
            mouse_button(bevent->button-1, TRUE);
            gtk_lightpen_setbutton(bevent->button, TRUE);
        } else {
            if (bevent->button == 1) {
                ui_menu_update_all_GTK();
                gtk_menu_popup(GTK_MENU(left_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
            } else if (bevent->button == 3) {
                ui_menu_update_all_GTK();
                gtk_menu_popup(GTK_MENU(right_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
            }
        }
    } else if (event->type == GDK_BUTTON_RELEASE && (_mouse_enabled || lightpen_enabled)) {
        GdkEventButton *bevent = (GdkEventButton*)event;
        mouse_button(bevent->button-1, FALSE);
        gtk_lightpen_setbutton(bevent->button, FALSE);
   } else if (event->type == GDK_MOTION_NOTIFY) {
        GdkEventMotion *mevent = (GdkEventMotion*)event;
        if (_mouse_enabled) {
            /* handle pointer motion events for mouse emulation */
            gint x=0, y=0, w=0, h=0, warp=0;
            gint xoff=0, yoff=0;
            gint ptrx, ptry;
            GdkDisplay *display = NULL;
            GdkScreen *screen = NULL;

            /* get default display and screen */
            display = gdk_display_get_default ();
            screen = gdk_display_get_default_screen (display);

            /* get cursor position */
            gdk_display_get_pointer (display, NULL, &x, &y, NULL);

            ptrx = (int)mevent->x;
            ptry = (int)mevent->y;
            xoff = x - ptrx;
            yoff = y - ptry;

            /* w = canvas->draw_buffer->canvas_physical_width; */
            w = gtk_widget_get_allocated_width(canvas->emuwindow);
            h = canvas->draw_buffer->canvas_physical_height;

            /* DBG(("ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", ptrx, ptry, x, y, w, h)); */

            if (mouse_warpx == 1) {
                /* from left to right */
                if ((ptrx > mouse_lasteventx) && (ptrx >= (w - (MOUSE_WRAP_MARGIN * 2))) && (ptrx <= (w - MOUSE_WRAP_MARGIN))) {
                    mouse_warpx = 0;
                    mouse_lasteventx = ptrx;
                }
            } else if (mouse_warpx == 2) {
                /* from right to left */
                if ((ptrx < mouse_lasteventx) && (ptrx <= (MOUSE_WRAP_MARGIN * 2)) && (ptrx >= MOUSE_WRAP_MARGIN)) {
                    mouse_warpx = 0;
                    mouse_lasteventx = ptrx;
                }
            }

            if (mouse_warpy == 1) {
                /* from top to bottom */
                if ((ptry > mouse_lasteventy) && (ptry >= (h - (MOUSE_WRAP_MARGIN * 2))) && (ptry <= (h - MOUSE_WRAP_MARGIN))) {
                    mouse_warpy = 0;
                    mouse_lasteventy = ptry;
                }
            } else if (mouse_warpy == 2) {
                /* from bottom to top */
                if ((ptry < mouse_lasteventy) && (ptry <= (MOUSE_WRAP_MARGIN * 2)) && (ptry >= MOUSE_WRAP_MARGIN)) {
                    mouse_warpy = 0;
                    mouse_lasteventy = ptry;
                }
            }

            if (mouse_warped || mouse_warpx || mouse_warpy) {
                /* ignore this event, its the result of us having moved the pointer */
                /* DBG(("warped!:%d/%d/%d ptrx:%d ptry:%d lastx:%d lasty:%d", mouse_warped, mouse_warpx, mouse_warpy, ptrx, ptry, mouse_lasteventx, mouse_lasteventy)); */
                if (mouse_warped) {
                    --mouse_warped;
                }
            } else {

                if (ptrx < MOUSE_WRAP_MARGIN) {
                    /* from left to right */
                    mouse_lasteventx = ptrx;
                    ptrx = w - (MOUSE_WRAP_MARGIN + 10);
                    mouse_warpx = 1;
                    warp = 1;
                }
                else if (ptrx > (w - MOUSE_WRAP_MARGIN)) {
                    /* from right to left */
                    mouse_lasteventx = ptrx;
                    ptrx = (MOUSE_WRAP_MARGIN + 10);
                    mouse_warpx = 2;
                    warp = 1;
                }

                if (ptry < (MOUSE_WRAP_MARGIN)) {
                    /* from top to bottom */
                    mouse_lasteventy = ptry;
                    ptry = (h - (MOUSE_WRAP_MARGIN + 10));
                    mouse_warpy = 1;
                    warp = 1;
                } else if (ptry > (h - MOUSE_WRAP_MARGIN)) {
                    /* from bottom to top */
                    mouse_lasteventy = ptry;
                    ptry = (MOUSE_WRAP_MARGIN + 10);
                    mouse_warpy = 2;
                    warp = 1;
                }
                /* DBG(("warp:%d ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", warp, ptrx, ptry, x, y, w, h)); */

                if (warp) {
                    /* set new cusor position */
                    ++mouse_warped;
                    /* DBG(("warp to: x:%d y:%d", ptrx, ptry)); */
                    gdk_display_warp_pointer (display, screen, ptrx + xoff, ptry + yoff);
                } else {
                    mouse_dx = (ptrx - mouse_lasteventx) / (canvas->videoconfig->doublesizex + 1);
                    mouse_dy = (ptry - mouse_lasteventy) / (canvas->videoconfig->doublesizey + 1);
                    DBG(("mouse move dx:%8d dy:%8d", mouse_dx, mouse_dy));
                    mouse_move((float)mouse_dx, (float)mouse_dy);
                    mouse_lasteventx = ptrx;
                    mouse_lasteventy = ptry;
                }
            }
        }
#ifdef HAVE_FULLSCREEN
        fullscreen_mouse_moved(canvas, (int)mevent->x, (int)mevent->y, 0);
#endif
   }
}
Example #23
0
int main( void )
{

  int i = 0;
  int bufIndx;
  int bufPage;
  int charCnt;
  char cursorx;
  char cursory;


  memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));


  /* Load and install the mouse driver */
   mouse_load_driver (&mouse_def_callbacks, DRIVER);
/* Set the VIC sprite pointer */
    *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;

    VIC.spr0_color = COLOR_WHITE;



  bgcolor (0);
  bordercolor (0);

  clrscr ();

  
  while( showAddrsBar()<1){bufPage=1;}

  bufPage=1;
  bufIndx=0;
  charCnt = screenRender(bufIndx);


  cursorx=20;
  cursory=11;

  mouse_show();
  mouse_move (cursorx , cursory);

  while( sRunning )
  {

    if( kbhit() )
    {
      //uint8_t pet = cgetc();
      char pet = cgetc();

      switch( pet )
      {
        //Move cursor down
        case PETSCII_DOWN:

          if(cursory < screenPixH){
            cursory++;
            mouse_move (cursorx , cursory);

          }
          break;

        //Move cursor up
        case PETSCII_UP:

          if(cursory > 0){
            cursory--;
            mouse_move (cursorx , cursory);

          }
          break;

        //Move cursor left
        case PETSCII_LEFT:

          if(cursorx > 0){
            cursorx--;
            mouse_move (cursorx , cursory);
          }
          break;

        //Move cursor right
        case PETSCII_RIGHT:

          if(cursorx < screenPixW-1){
            cursorx++;

            mouse_move (cursorx , cursory);
          }
          break;


        //Scroll UP
        case PETSCII_F1:

          bufIndx = bufIndx - charCnt;
          if(bufIndx <0){
            
            if(bufPage>1){
              getData();
              bufIndx=bufSize - charCnt;

              bufPage--;
              textcolor(bufPage);
            }
            else{bufIndx=0;}
          }
          charCnt = screenRender(bufIndx);
          break;

        //Scroll DOWN
        case PETSCII_F7:

          bufIndx = bufIndx + charCnt;
          if(bufIndx > bufSize){
            
            cbm_read( 2, sRecvBuf, sizeof(sRecvBuf));
            bufIndx=0;

            bufPage++;
            textcolor(bufPage);
          }
          charCnt = screenRender(bufIndx);
          break;

        //Show URL address entry bar
        case PETSCII_STOP:

          if(showAddrsBar() >0){
             bufPage=1;
             bufIndx=0;
             charCnt = screenRender(bufIndx);
          }
          break;

      }
    }

  }


  cbm_close( 2 );
  cbm_close( 7 );
  cbm_close( 8 );

  return(0);
}
Example #24
0
void grab_mouse(DDContext *ctx, GF_VideoOutput *vout)
{
	if (ctx->fullscreen) DD_SetCursor(vout, GF_CURSOR_NORMAL);
	SetCapture(ctx->cur_hwnd);
	mouse_move(ctx, vout);
}
Example #25
0
File: view.cpp Project: nobbk/copo
/// event handling
int view::handle(int event) {
	int mx;
	int my;
	int dx=0;
	int dy=0;
	int mouse_x;
	int mouse_y;
	unsigned int button;
	int result;
	switch(event) {
		case fltk::SHORTCUT:
		case fltk::KEY:
			make_current(); // make OpenGL context current
			// keypress, key is in fltk::event_key(), ascii in fltk::event_text()
			// Return 1 if you understand/use the keyboard event, 0 otherwise...
			KeyPressed(FltkToSnowKey(fltk::event_key()));
			return 1;
			break;
		case fltk::MOVE:
			make_current(); // make OpenGL context current
			mouse_x = fltk::event_x();
			mouse_y = fltk::event_y();
			if (m_world) {
				mouse_move(mouse_x,mouse_y);
			}
			result = 1;
			break;
		case fltk::PUSH:
			make_current(); // make OpenGL context current
			mx = fltk::event_x();
			my = fltk::event_y();
			mouse_x_old = mx;
			mouse_y_old = my;

			take_focus();

			button = fltk::event_button();
			if (m_world) {
				mouse_push(button);
			}
			result = 1;
			break;
		case fltk::RELEASE:
			make_current(); // make OpenGL context current
			mx = fltk::event_x();
			my = fltk::event_y();
			dx = mx-mouse_x_old;
			dy = my-mouse_y_old;
			mouse_x_old = mx;
			mouse_y_old = my;
			button = fltk::event_button();
			return 1;
			break;
		case fltk::DRAG:
			make_current(); // make OpenGL context current
			mx = fltk::event_x();
			my = fltk::event_y();
			dx = mx-mouse_x_old;
			dy = my-mouse_y_old;
			mouse_x_old = fltk::event_x();
			mouse_y_old = fltk::event_y();
			button = fltk::event_button();
			if (m_world) {
				mouse_move_button_pressed(button, dx, dy);
			}
			result = 1;
			break;
		case fltk::FOCUS:
			return 1;
			break;
		case fltk::UNFOCUS:
			return 1;
			break;
		default:
			// let the base class handle all other events:
			result = fltk::GlWindow::handle(event);
			break;
	}
	redraw();
	return result;
}
Example #26
0
/**
* The 'delta' version of the click and drag command. This function moves an xy
* distance from a startpoint. This distance is 'wrapping', so if it is outside 
* of the window, we mouseup, return to the start position, mousedown, and then
* move again. We give a one pixel border at each side of the window and clamp 
* using that value to avoid accidental resizing.
*/
bool clickAndDragDelta(std::string window_name, nlohmann::json action){
  //get the values of the student's window.
  int x_start, x_end, y_start, y_end, mouse_button; 
  bool no_clamp = false; 
  bool success = populateClickAndDragValues(action, window_name, x_start, 
                      x_end, y_start, y_end, mouse_button, no_clamp);
  
  //if we can't populate the click and drag values, do nothing.
  if(!success){ 
    std::cout << "Could not populate the click and drag values."<< std::endl;
    return false;
  }
  
  //Define the corners of our window. (We use vectors as 2d points.)
  std::vector<int> upper_left, upper_right, lower_left, lower_right; 
  upper_left.push_back(x_start); upper_left.push_back(y_start);
  upper_right.push_back(x_end); upper_right.push_back(y_start);
  lower_left.push_back(x_start); lower_left.push_back(y_end);
  lower_right.push_back(x_end); lower_right.push_back(y_end);

  
  //delta version, 2 values movement x and movement y.
  int amt_x_movement_remaining = action.value("x_distance", 0);
  int amt_y_movement_remaining = action.value("y_distance", 0);
  std::string start_location   = action.value("start_location", "center");

  //This shouldn't fail unless there isn't a mouse.
  std::string mouse_location_string = output_of_system_command("xdotool getmouselocation"); 
  std::vector<int> xy = extractIntsFromString(mouse_location_string);                      
  
  //if the mouse isn't detected, fail.
  if(xy.size() < 2){ 
    std::cout << "Mouse coordinates couldn't be found. Mouse undetected." 
                << std::endl;
    return false;
  }
  //get the current mouse location
  int start_mouse_x = xy[0];
  int start_mouse_y = xy[1];
  //clamp the mouse within the screen (and move in by a pixel).
  clamp(start_mouse_x, x_start+1, x_end-1); 
  clamp(start_mouse_y, y_start+1, y_end-1);

  //get the center of the window
  int width  = x_end - x_start;
  int height = y_end - y_start;
  int x_middle = x_start + (width/2);
  int y_middle = y_start+(height/2);

  //NOTE: check my arithmetic. 
  /**
  * The process that this algorithm goes through is as follows:
  * 1) Determine the slope of the dragged line and its distance.
  * 2) while we have not traversed the necessary distance
  * 3) project a line from the current mouse position towards the end 
  *      position with length equal to the remaining distance. 
  * 4) Now that we have a line segment defined, find where/if it intersects
  *      any of the window's edges
  * 5) if it does intersect, cut it off at the point of intersection, and only
  *      drag that far. Else, if it doesn't intersect, we can assume we are 
  *      inside of the window, due to the clamp, and can drag.
  * 6) update remaining distance and continue to loop.
  */

  //rise / run
  float slope=(float)amt_y_movement_remaining/(float)amt_x_movement_remaining;
  float total_distance_needed = sqrt(pow(amt_x_movement_remaining, 2) 
                                    + pow (amt_y_movement_remaining, 2)); 

  //remaining distance needed.
  float remaining_distance_needed = total_distance_needed; 

  int action_start_x = (start_location == "current") ? start_mouse_x : x_middle;
  int action_start_y = (start_location == "current") ? start_mouse_y : y_middle;

  std::cout << "start x " << start_mouse_x << " our x " << action_start_x;
  std::cout << "start y " << start_mouse_y << " our y " << action_start_y;

  //The functions called within this loop will not fire if the window doesn't 
  // exist. This check just short circuits to avoid additional printing.
  while(remaining_distance_needed >= 1 && windowExists(window_name)){ 
    int curr_x = action_start_x;                                             
    int curr_y = action_start_y;                                              
    int moved_mouse_x, moved_mouse_y;
    //reset the mouse to the start location.
    mouse_move(window_name, action_start_x, action_start_y, x_start, x_end, y_start, y_end,
                                                                        false); 
    //determine how far we've come.
    float fraction_of_distance_remaining = remaining_distance_needed 
                                            / total_distance_needed; 
    //project in the direction of the move to find the end of our line segment.
    float projected_x = action_start_x + (amt_x_movement_remaining * fraction_of_distance_remaining); 
    float projected_y = action_start_y + (amt_y_movement_remaining * fraction_of_distance_remaining);  

    //we are using vectors as 2d points.
    std::vector<int> current_point, projected_point;  
    current_point.push_back(curr_x); current_point.push_back(curr_y);
    projected_point.push_back(projected_x); 
    projected_point.push_back(projected_y);

    std::vector<float> intersection_point; 
    intersection_point=getLineIntersectionPoint(current_point,projected_point,
                                                      upper_left, upper_right);
    

    /**
    * TODO make this block smaller. 
    * These if statements just test all edges of the window against our 
    * projected line.
    */

    //found is just a quick short-circuit to keep the code from ballooning.
    bool found = false; 
    if(intersection_point.size() != 0){ //TOP
      std::cout << "intersected top" << std::endl;
      moved_mouse_x = (int)intersection_point[0]; 
      moved_mouse_y = (int)intersection_point[1];
      found = true;
    }

    if(!found) //RIGHT
    {
      intersection_point = getLineIntersectionPoint(current_point, 
                            projected_point, upper_right, lower_right);
      if(intersection_point.size() != 0){ 
        std::cout << "intersected right" << std::endl;
        moved_mouse_x = (int)intersection_point[0]; 
        moved_mouse_y = (int)intersection_point[1];
        found = true;
      }
    }

    if(!found) //BOTTOM
    {
      intersection_point = getLineIntersectionPoint(current_point, 
                              projected_point, lower_right, lower_left);
      if(intersection_point.size() != 0){
        std::cout << "intersected bottom" << std::endl;
        moved_mouse_x = (int)intersection_point[0]; 
        moved_mouse_y = (int)intersection_point[1];
        found = true;
      }
    }

    if(!found) //LEFT
    {
      intersection_point = getLineIntersectionPoint(current_point,
                             projected_point, lower_left, upper_left);
      if(intersection_point.size() != 0){
        std::cout << "intersected left" << std::endl;
        moved_mouse_x = (int)intersection_point[0]; 
        moved_mouse_y = (int)intersection_point[1];
        found = true;
      }
    }

    //if we didn't intersect, we are inside of the box (guaranteed by clamp)
    // so we can move freely.
    if(!found) 
    {
      std::cout << "No intersection at all"<< std::endl;
      moved_mouse_x = projected_x;
      moved_mouse_y = projected_y;
    }

    //the distance we can move
    float distance_of_move = sqrt(pow(moved_mouse_x - action_start_x, 2) 
                                    + pow (moved_mouse_y - action_start_y, 2)); 
    //we are moving distance_of_move
    remaining_distance_needed -= distance_of_move; 
    std::cout << "after the move, we had " << remaining_distance_needed 
                                          << " distance left " << std::endl;
    mouseDown(window_name,mouse_button); //click
    mouse_move(window_name, moved_mouse_x, moved_mouse_y,x_start, x_end, //drag
                                                        y_start, y_end, false); 
    mouseUp(window_name,mouse_button); //release
  } //end loop.

  //to preserve backwards compatibility.
  if(start_location != "current"){
    //put the mouse back where we found it.
    mouse_move(window_name, start_mouse_x, start_mouse_y, x_start, x_end, y_start, y_end,false);
  }

  return true;
}
Example #27
0
/**
* The central routing function for for all actions. Takes in a vector of 
* actions and the # of actions taken thus far. It then passes the current 
* action to be taken through tests to see which function to route to.
* This function requires all parameters to for execute.cpp's delayAndMemCheck
* function. 
*/
void takeAction(const std::vector<nlohmann::json>& actions, int& actions_taken, 
  std::string window_name, int childPID, 
  float &elapsed, float& next_checkpoint, float seconds_to_run, 
  int& rss_memory, int allowed_rss_memory, int& memory_kill, int& time_kill,
  std::ostream &logfile){

  //We get the window data at every step in case it has changed size.

  //if we make it past this check, we'll assume an action has been taken.
  if(!windowExists(window_name)){ 
    return;
  }
  
  nlohmann::json action = actions[actions_taken];
  
  // std::vector<std::string> vec = stringOrArrayOfStrings(action, "action");

  // if (vec.size() == 0){
  //   std::cout << "ERROR: poorly formatted action (no 'action' type specified)" << std::endl;
  //   action_name = "INVALID: NAME MISSING";
  // }
  // else{
  //     std::string action_name = vec[0];
  // }

  std::string action_name = action.value("action", "ACTION_NOT_SPECIFIED");

  std::cout <<"Taking action "<<actions_taken+1<<" of "<<actions.size() <<": "<< action_name<< std::endl;

  float delay_time = 0;
  bool success = false;
  //DELAY            
  if(action_name == "delay"){
    float time_in_secs = action.value("seconds", 0);
    delay_time = delay(time_in_secs);
    success = true;
  }
  //SCREENSHOT
  else if(action_name == "screenshot"){ 
    std::string screenshot_name = action["name"];
    success = screenshot(window_name, screenshot_name);
  }
  //TYPE
  else if(action_name == "type"){ 

    float delay_in_secs = action["delay_in_seconds"];
    int presses = action["presses"];
    std::string string_to_type = action["string"];

    success = type(string_to_type, delay_in_secs, presses, window_name,childPID,elapsed, next_checkpoint, 
      seconds_to_run, rss_memory, allowed_rss_memory, memory_kill, time_kill, logfile);
  }
  //KEY
  else if(action_name == "key"){
    std::string key_to_type = action["key_combination"];
    success = key(key_to_type, window_name);
  }
  //CLICK AND DRAG    
  else if(action_name == "click and drag"){ 
    success = clickAndDragAbsolute(window_name,action);
  }
  else if(action_name == "click and drag delta"){
    success = clickAndDragDelta(window_name,action);
  }
  //CLICK
  else if(action_name == "click"){ 
    std::string mouse_button = action["mouse_button"];
    if(mouse_button == "left"){
      success = click(window_name, 1);
    }
    else if(mouse_button == "middle"){
      success = click(window_name, 2);
    }
    else if(mouse_button == "right"){
      success = click(window_name, 3);
    }
    else{
      success = click(window_name, 1);
    }
  }
  //MOUSE MOVE
  else if(action_name == "move mouse"){
    //TODO: implement later if deemed prudent.
    bool no_clamp = false;
    
    int moved_x = action["end_x"];
    int moved_y = action["end_y"];

    int height, width, x_start, x_end, y_start, y_end;
    bool populated = populateWindowData(window_name, height, width, x_start, x_end, y_start, y_end);
    if(populated){
        moved_x += x_start;
        moved_y += y_start;
        success = mouse_move(window_name, moved_x, moved_y, x_start, x_end, y_start, y_end, no_clamp);
    }
  }
  //CENTER
  else if(action_name == "center"){ 
    success = centerMouse(window_name);
  }
  //ORIGIN
  else if(action_name == "origin"){ 
    success = moveMouseToOrigin(window_name);
  }
  else if(action_name == "gif"){ 
    std::string gif_name = action["name"];
    float duration_in_seconds = action["seconds"];
    int fps = action["frames_per_second"];
    bool save_pngs = action["preserve_individual_frames"];

    success = make_gif(window_name, gif_name, duration_in_seconds, fps, save_pngs,
                        childPID, elapsed, next_checkpoint, seconds_to_run, 
                        rss_memory, allowed_rss_memory, memory_kill, time_kill,
                        logfile);
  }
   //BAD COMMAND
  else{
    std::cout << "ERROR: ill formatted action: " << actions[actions_taken] << std::endl;
  }

  if(success){
    std::cout << "The action was successful" << std::endl;
    actions_taken++;
  }else{
    std::cout << "The action was unsuccessful" << std::endl;
  }

  delay_and_mem_check(delay_time, childPID, elapsed, next_checkpoint, 
    seconds_to_run, rss_memory, allowed_rss_memory, memory_kill, time_kill,logfile);   
}
Example #28
0
void mouse_conv(int rep,char *button,char *remote)
{
	struct trans_mouse *tm;
	int found=0;
	
	tm=tm_first;
	while(tm!=NULL)
	{
		if(tm->tm_remote!=ALL)
		{
			if(strcasecmp(remote,tm->tm_remote)!=0)
			{
				tm=tm->tm_next;
				continue;
			}
		}
		if(tm->tm_button!=ALL)
		{
			if(strcasecmp(button,tm->tm_button)!=0)
			{
				tm=tm->tm_next;
				continue;
			}
		}
		if(tm->tm_directive==mouse_activate)
		{
			if(ms.active==0 && ms.always_active==0)
			{
				activate();
			}
		}
		else if(tm->tm_directive==mouse_toggle_activate && rep==0)
		{
			if(ms.always_active==0)
			{
				if(ms.active==0)
				{
					activate();
					ms.toggle_active=1;
				}
				else
				{
					deactivate();
				}
			}
		}
		
		if(ms.active || ms.always_active)
		{
			int i;
			for(i=0;config_table[i].string!=NULL;i++)
			{
				if(tm->tm_directive==config_table[i].d)
				{
					int x,y,z,up,down,toggle;

					x=config_table[i].x;
					y=config_table[i].y;
					z=config_table[i].z;
					down=config_table[i].down;
					up=config_table[i].up;
					toggle=config_table[i].toggle;

					if(x || y || z)
					{
						mouse_move(x,y,z,rep);
					}
					if(toggle)
					{
						/*
						  assert(down==up); 
						  assert(up==BUTTON1
						  || up==BUTTON2
						  || up==BUTTON3);
						*/
						if(ms.buttons[map_buttons(up)]==button_up)
							mouse_button(down,0,rep);
						else
							mouse_button(0,up,rep);
					}
					else
					{
						if(down && up) /* click */
						{
							mouse_button(down,0,rep);
#ifdef CLICK_DELAY
							usleep(CLICK_DELAY);
#endif
							mouse_button(0,up,rep);
						}
						else if(down || up);
						{
							mouse_button(down,up,rep);
						}
					}
					break;
				}
			}

		}
		found=1;
		tm=tm->tm_next;
	}
	if(found==0)
	{
		if(ms.active==1 &&
		   ms.always_active==0 &&
		   ms.toggle_active==0)
		{
			deactivate();
		}
	}
}
Example #29
0
int run_game_loop(GameState * state) {
	int done = 0;
	int i = 0;

	/* Initialise gui */
	init_gui(SCREEN_WIDTH,SCREEN_HEIGHT);

	/* Load resources */
	init_sprite_cache();
	render_world_to_sprite(&state->world);
	update_hud(
		&state->hud, 
		&state->score,
		&state->mana,
		&state->money, 
		&state->world.castle->castle.health,
		&state->wave.wave_number,
		&state->play);

	/* Initialise game loop */
	init_game_loop(FPS);
	while (!done) {
		
			/* Get events */
			Event ev;
			wait_for_event(&ev);

			/* Event handlers */
			switch (ev.type) {
			case EVENT_TIMER:
				state->redraw = 1;
				if (!state->game_over) {
					if (*state->hud.play) {
						check_spells(state);
						check_enemy_wave(state);
						update_movement(state);
						do_tower_attacks(state);
					}
				}
				break;
			case EVENT_MOUSE_MOVE:
				mouse_move(&ev.mouseMoveEvent, state);
				break;
			case EVENT_MOUSE_DOWN:
				mouse_down(&ev.mouseDownEvent, state);
				break;
			case EVENT_MOUSE_UP:
				mouse_up(&ev.mouseUpEvent, state);
				break;
			case EVENT_DISPLAY_CLOSE:
				done = 1;
				break;
			} 

			/* Render only on timer event AND if all movement and logic was processed */
			if (state->redraw && all_events_processed()) { 
				render_game(state);
			}
	}
	/* Cleanup */
	cleanup_game_loop();
	cleanup_sprite_cache();
	return 0;
}
Example #30
-1
int m_exec(wchar_t* app, int param_count, wchar_t* param[]) 
{
	if (param_count <= 0) {
		return 0;
	} 

	bool valid = false;
	std::wstring action ;
	long x, y;
	std::wstring win_name;
	std::wstring btn_event;
	
	for (int i = 0; i < param_count; i++) {
		if (i == 1) {
			action = param[0];
		}
		else {
			if (action == L"m"
				|| action == L"to"
				) {
				wchar_t* end;
				x = std::wcstol(param[1], &end, 10);
				y = std::wcstol(param[2], &end, 10);
				if (param_count == 4) {
					btn_event = param[3];
				}
				break;
			}
			else if (action == L"w") {
				win_name = param[1];
				if (param_count == 3) {
					btn_event = param[2];
				}
				break;
			}
		}

	}

	if (action== L"m") {
		int ret = mouse_move(x, y);
		mouse_event(btn_event);
	} 
	else if (action == L"to") {
		int ret = mouse_move(x, y);
		mouse_event(btn_event);
	}
	else if (action == L"w") {
		int ret = mouse_to_window(win_name);
		mouse_event(btn_event);
	}
	else {
		print_usage(app);
	}

	
}