Пример #1
0
	/**
	 * Convert a position on screen to a position on the field.
	 *
	 * @param  p  [in, out] A reference to a FieldPoint which contains the
	 *            position on screen. The X and Y members will be changed
	 *            to the position on the field. This position is clamped
	 *            so that it is always within the field's dimensions.
	 * @return True if the calculated position hadn't to be clamped to fit
	 *         in the field's dimensions, false otherwise.
	 * @require field != null
	 */
	public static bool ScreenPosToFieldPos(ref FieldPoint p, Field field, uint zoomLevel) {
		bool result = true;

		if (p.X / zoomLevel >= field.Width) {
			p.X = field.Width - 1;
			result = false;
		} else {
			p.X /= zoomLevel;
		}

		if (p.Y / zoomLevel >= field.Height) {
			p.Y = 0;
			result = false;
		} else {
			p.Y = field.Height - (p.Y / zoomLevel) - 1;
		}

		return result;
	}
Пример #2
0
	/**
	 * Convert a point on the field to a point on screen.
	 *
	 * @require field != null
	 */
	public static void FieldPosToScreenPos(ref FieldPoint p, Field field, uint zoomLevel) {
		p.X *= zoomLevel;
		p.Y = (field.Height - p.Y - 1) * zoomLevel;
	}