Esempio n. 1
0
GUI_status ScrollWidgetGump::MouseDown(int x, int y, int button)
{
	ScrollEventType event = SCROLL_ESCAPE;

	switch(button)
	{
	case SDL_BUTTON_WHEELDOWN : event = SCROLL_DOWN; break;
	case SDL_BUTTON_WHEELUP : event = SCROLL_UP; break;
	case SDL_BUTTON_LEFT : {
	                       x -= area.x;
	                       y -= area.y;
	                       if(HitRect(x,y, arrow_up_rect[0]))
	                           event = SCROLL_UP;
	                       else if(HitRect(x,y, arrow_down_rect[0]))
	                           event = SCROLL_DOWN;
// FIXME - uncomment when we get a checkmark
//	                       else if(show_down_arrow || show_up_arrow) // don't close if scrollable
//	                           return GUI_YUM;
	                       break;
	}
	default : break;
	}

	return scroll_movement_event(event);
}
Esempio n. 2
0
/* Main event handler function.
   This function gets raw SDL events from the GUI.
 */
GUI_status
GUI_Widget:: HandleEvent(const SDL_Event *event)
{
	switch (event->type) {
		case SDL_KEYDOWN: {
			return(KeyDown(event->key.keysym));
		}
		break;
		case SDL_KEYUP: {
			return(KeyUp(event->key.keysym));
		}
		break;
		case SDL_MOUSEBUTTONDOWN: {
			int x, y, button;
			x = event->button.x;
			y = event->button.y;
			if ( HitRect(x, y) ) {
				button = event->button.button;
				return(MouseDown(x, y, button));
			}
		}
		break;
		case SDL_MOUSEBUTTONUP: {
			int x, y, button;
			x = event->button.x;
			y = event->button.y;
			button = event->button.button;
			if ( HitRect(x, y) )
			{
				button = event->button.button;
				return(MouseUp(x, y, button));
			}
			/* if widget was clicked before we must let it deactivate itself*/
			else if (ClickState(1)) return(MouseUp(-1,-1,button));
		}
		break;
		case SDL_MOUSEMOTION: {
			int x, y;
			Uint8 state;
			x = event->motion.x;
			y = event->motion.y;
			state = event->motion.state;
			if ( HitRect(x, y) )
			{
  			  return(MouseMotion(x, y, state));
			}
			/* if widget was clicked before we must let it react*/
			else if (ClickState(1)) return(MouseMotion(-1,-1,state));
		}
		break;
		default: {
			/* Pass it along.. */;
		}
		break;
	}
	return(GUI_PASS);
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pView - 
//			pt - Point in client coordinates.
//			bValidOnly - 
// Output : 
//-----------------------------------------------------------------------------
int Box3D::HitTest(CMapView *pView, const Vector2D &ptClient, bool bTestHandles)
{
	bool bHit = false;

	if ( pView->HitTest( ptClient, bmins, bmaxs ) )
	{
		// The point is inside the main rect.
		m_LastHitTestHandle.Init();
		bHit = true;
	}

	if ( !m_bEnableHandles || !bTestHandles )
	{
		// Handles are turned off, so we don't need to do any more testing.
		// Return whether we hit the main rect or not.
		return bHit;
	}

	// check if we hit a handle

	Vector handles[3*3*3];
	int numHandles = GetVisibleHandles( handles, pView, m_TranslateMode );


	Vector vOffset(HANDLE_OFFSET,HANDLE_OFFSET,HANDLE_OFFSET);

	if ( pView->IsOrthographic() )
	{
		vOffset /= pView->GetCamera()->GetZoom();
	}
	else
	{
		vOffset.Init();
	}
		
	
	Vector vCenter = (bmins+bmaxs)/2;
	Vector vDelta = (bmaxs + vOffset) - vCenter;

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

		Vector pos = vCenter + vDelta * handles[i];

		if ( HitRect( pView, ptClient, pos, HANDLE_RADIUS ) )
		{
			// remember handle found
			m_LastHitTestHandle = handles[i];
			bHit = true;
			break;
		}
	}

	return bHit;
}
Esempio n. 4
0
GUI_status
GUI_GenericWidget:: HandleEvent(const SDL_Event *event)
{
	GUI_status status;

	status = GUI_PASS;
	if ( EventProc ) {
		int handle_it;

		/* Mouse events outside the widget area are ignored */
		handle_it = 1;
		switch (event->type) {
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP: {
				int x, y;
				x = event->button.x;
				y = event->button.y;
				if ( ! HitRect(x, y) ) {
					handle_it = 0;
				}
			}
			break;
			case SDL_MOUSEMOTION: {
				int x, y;
				x = event->motion.x;
				y = event->motion.y;
				if ( ! HitRect(x, y) ) {
					handle_it = 0;
				}
			}
			break;
		}
		if ( handle_it ) {
			widget_info info;

			FillInfo(&info);
			status = EventProc(&info, event);
		}
	}
	return(status);
}
Esempio n. 5
0
GUI_status GUI_TextInput::MouseUp(int x, int y, int button)
{
 if(button == SDL_BUTTON_WHEELUP || button == SDL_BUTTON_WHEELDOWN)
   return GUI_PASS;
 //release focus if we click outside the text box.
 if(focused && !HitRect(x, y))
   release_focus();
 else
  {
   if(!focused)
     {
      grab_focus();
      SDL_EnableUNICODE(1); //turn on unicode processing.
     }
  }

 return(GUI_PASS);
}
Esempio n. 6
0
GUI_status DraggableView::MouseDown(int x, int y, int button)
{
	if(bg_image && HitRect(x, y))
	{
		Uint32 pixel = sdl_getpixel(bg_image, x - area.x, y - area.y);
		if(pixel == bg_color_key)
		{
			return GUI_PASS;
		}
	}
 drag = true;
 button_x = x;
 button_y = y;

 moveToFront();
 if(Game::get_game()->is_new_style())
 {
	 Game::get_game()->get_scroll()->moveToFront();
 }
 grab_focus();

 return GUI_YUM;
}
Esempio n. 7
0
// change container, ready/unready object, activate arrows
GUI_status InventoryWidget::MouseUp(int x,int y,int button)
{

 CommandBar *command_bar = Game::get_game()->get_command_bar();

 if(button == USE_BUTTON || (button == ACTION_BUTTON
    && command_bar->get_selected_action() > 0)) // Exclude attack mode too
   {
    x -= area.x;
    y -= area.y;
    if(x >= icon_x && x <= icon_x + 15 && // hit top icon either actor or container
       y >= 0 && y <= 15)
      {
		Event *event = Game::get_game()->get_event();

		if(button == ACTION_BUTTON && event->get_mode() == MOVE_MODE)
		{
			if(command_bar->try_selected_action() == false) // start new action
				return GUI_PASS; // false if new event doesn't need target
		}

		if(event->can_target_icon())
		{
			if(is_showing_container() && event->get_last_mode() != PUSH_MODE)
				event->select_obj((Obj *)container_obj, actor);
			else if(is_showing_container() && get_container()->get_engine_loc() == OBJ_LOC_CONT)
				event->select_obj((Obj *)get_container()->parent, actor);
			else
				event->select_actor(actor);
			 return GUI_YUM;
		}

			 if(is_showing_container())
				 set_prev_container(); //return to previous container or main actor inventory
			 else if(!event->using_control_cheat())
				 Game::get_game()->get_view_manager()->set_party_mode();

       Redraw();
      }

    if((button == SDL_BUTTON_WHEELUP || HitRect(x,y,arrow_rects[0])) //up arrow hit rect
       && Game::get_game()->get_game_type() == NUVIE_GAME_U6)
       up_arrow();

    if((button == SDL_BUTTON_WHEELDOWN || HitRect(x,y,arrow_rects[1])) //down arrow hit rect
       && Game::get_game()->get_game_type() == NUVIE_GAME_U6)
       down_arrow();

    // only act now if objects can't be used with DoubleClick
    if(selected_obj && !Game::get_game()->get_map_window()->is_doubleclick_enabled())
        try_click();
    else if(selected_obj)
      {
        wait_for_mouseclick(USE_BUTTON);
        ready_obj = selected_obj;
      }
   }
   else if(button == SDL_BUTTON_WHEELUP && Game::get_game()->get_game_type() == NUVIE_GAME_U6)
       up_arrow();
   else if(button == SDL_BUTTON_WHEELDOWN && Game::get_game()->get_game_type() == NUVIE_GAME_U6)
       down_arrow();

 selected_obj = NULL;

 return GUI_YUM;
}
Esempio n. 8
0
/* Check to see if a point intersects the bounds of the widget.
 */
int
GUI_Widget:: HitRect(int x, int y)
{
	return(HitRect(x, y, area));
}