コード例 #1
0
void DrawRectangleTool::updateHover(bool mouse_down)
{
	if (shift_pressed)
		constrained_pos_map = MapCoordF(snap_helper->snapToObject(cur_pos_map, cur_map_widget));
	else
		constrained_pos_map = cur_pos_map;
	
	if (!editingInProgress())
	{
		setPreviewPointsPosition(constrained_pos_map);
		updateDirtyRect();
		
		if (mouse_down && ctrl_pressed)
			pickDirection(constrained_pos_map, cur_map_widget);
		else if (!mouse_down)
			angle_helper->setCenter(constrained_pos_map);
	}
	else
	{
		hidePreviewPoints();
		if (mouse_down && !dragging && (cur_pos - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx())
		{
			// Start dragging
			dragging = true;
		}
		if (!mouse_down || dragging)
			updateRectangle();
	}
}
コード例 #2
0
void FourDirectionsEnemy::startMoving() {
	GameDirection d  = pickDirection();
	if (d != GameDirectionUnknown){
		direction = d;
	}
	AbstractEnemy::startMoving();
	
	// runAction(
		//		CCRepeatForever::create(CCSequence::create(CCRotateBy::create(0.3, 15) ,CCRotateBy::create(0.3, -15) , NULL ))
		//);
}
コード例 #3
0
bool DrawRectangleTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	cur_pos = event->pos();
	cur_pos_map = map_coord;
	if (shift_pressed)
		cur_pos_map = MapCoordF(snap_helper->snapToObject(cur_pos_map, widget));
	constrained_pos_map = cur_pos_map;
	
	if (no_more_effect_on_click)
	{
		no_more_effect_on_click = false;
		return true;
	}
	
	if (ctrl_pressed && event->button() == Qt::LeftButton && !editingInProgress())
	{
		pickDirection(cur_pos_map, widget);
		return true;
	}
	
	bool result = false;
	if (editingInProgress())
	{
		if (isDrawingButton(event->button()) && dragging)
		{
			dragging = false;
			result = mousePressEvent(event, cur_pos_map, widget);
		}
		
		if (event->button() == Qt::RightButton && drawOnRightClickEnabled())
		{
			if (!dragging)
			{
				constrained_pos_map = MapCoordF(preview_path->getCoordinate(angles.size() - 1));
				undoLastPoint();
			}
			if (editingInProgress()) // despite undoLastPoint()
				finishDrawing();
			return true;
		}
	}
	return result;
}
コード例 #4
0
bool DrawRectangleTool::mousePressEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	// Adjust flags to have possibly more recent state
	int modifiers = (event->modifiers() | (key_button_bar ? key_button_bar->activeModifiers() : 0));
	ctrl_pressed = modifiers & Qt::ControlModifier;
	shift_pressed = modifiers & Qt::ShiftModifier;
	cur_map_widget = widget;
	if (isDrawingButton(event->button()))
	{
		dragging = false;
		click_pos = event->pos();
		click_pos_map = map_coord;
		cur_pos = event->pos();
		cur_pos_map = click_pos_map;
		if (shift_pressed)
			cur_pos_map = MapCoordF(snap_helper->snapToObject(cur_pos_map, widget));
		constrained_pos_map = cur_pos_map;
		
		if (!editingInProgress())
		{
			if (ctrl_pressed)
			{
				// Pick direction
				pickDirection(cur_pos_map, widget);
			}
			else
			{
				// Start drawing
				if (angle_helper->isActive())
					angle_helper->setCenter(click_pos_map);
				startDrawing();
				MapCoord coord = MapCoord(cur_pos_map);
				coord.setDashPoint(draw_dash_points);
				preview_path->addCoordinate(coord);
				preview_path->addCoordinate(coord);
				angles.push_back(0);
				updateStatusText();
			}
		}
		else
		{
			if (angles.size() >= 2 && drawingParallelTo(angles[angles.size() - 2]))
			{
				// Drawing parallel to last section, just move the last point
				undoLastPoint();
			}
			
			// Add new point
			int cur_point_index = angles.size();
			if (!preview_path->getCoordinate(cur_point_index).isPositionEqualTo(preview_path->getCoordinate(cur_point_index - 1)))
			{
				MapCoord coord = MapCoord(cur_pos_map);
				coord.setDashPoint(draw_dash_points);
				preview_path->addCoordinate(coord);
				if (angles.size() == 1)
				{
					// Bring to correct number of points: line becomes a rectangle
					preview_path->addCoordinate(coord);
				}
				angles.push_back(0);
				
				angle_helper->setActive(true, MapCoordF(preview_path->getCoordinate(cur_point_index)));
				angle_helper->clearAngles();
				angle_helper->addAngles(angles[0], M_PI/4);
			
				if (event->button() != Qt::RightButton || !drawOnRightClickEnabled())
				{
					updateHover(false);
					updateHover(false); // Call it again, really.
				}
			}
		}
	}
	else if (event->button() == Qt::RightButton && editingInProgress())
	{
		constrained_pos_map = MapCoordF(preview_path->getCoordinate(angles.size() - 1));
		undoLastPoint();
		if (editingInProgress()) // despite undoLastPoint()
			finishDrawing();
		no_more_effect_on_click = true;
	}
	else
	{
		return false;
	}
	
	return true;
}