michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NSPOINT_H michael@0: #define NSPOINT_H michael@0: michael@0: #include "nsCoord.h" michael@0: #include "mozilla/gfx/BaseSize.h" michael@0: #include "mozilla/gfx/BasePoint.h" michael@0: #include "nsSize.h" michael@0: michael@0: struct nsIntPoint; michael@0: michael@0: // nsPoint represents a point in app units. michael@0: michael@0: struct nsPoint : public mozilla::gfx::BasePoint { michael@0: typedef mozilla::gfx::BasePoint Super; michael@0: michael@0: nsPoint() : Super() {} michael@0: nsPoint(const nsPoint& aPoint) : Super(aPoint) {} michael@0: nsPoint(nscoord aX, nscoord aY) : Super(aX, aY) {} michael@0: michael@0: inline nsIntPoint ScaleToNearestPixels(float aXScale, float aYScale, michael@0: nscoord aAppUnitsPerPixel) const; michael@0: inline nsIntPoint ToNearestPixels(nscoord aAppUnitsPerPixel) const; michael@0: michael@0: // Converts this point from aFromAPP, an appunits per pixel ratio, to aToAPP. michael@0: inline nsPoint ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const; michael@0: }; michael@0: michael@0: // nsIntPoint represents a point in one of the types of pixels. michael@0: // Uses of nsIntPoint should eventually be converted to CSSIntPoint, michael@0: // LayoutDeviceIntPoint, etc. (see layout/base/Units.h). michael@0: michael@0: struct nsIntPoint : public mozilla::gfx::BasePoint { michael@0: typedef mozilla::gfx::BasePoint Super; michael@0: michael@0: nsIntPoint() : Super() {} michael@0: nsIntPoint(const nsIntPoint& aPoint) : Super(aPoint) {} michael@0: nsIntPoint(int32_t aX, int32_t aY) : Super(aX, aY) {} michael@0: michael@0: inline nsPoint ToAppUnits(nscoord aAppUnitsPerPixel) const; michael@0: }; michael@0: michael@0: inline nsIntPoint michael@0: nsPoint::ScaleToNearestPixels(float aXScale, float aYScale, michael@0: nscoord aAppUnitsPerPixel) const michael@0: { michael@0: return nsIntPoint( michael@0: NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel) * aXScale), michael@0: NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel) * aYScale)); michael@0: } michael@0: michael@0: inline nsIntPoint michael@0: nsPoint::ToNearestPixels(nscoord aAppUnitsPerPixel) const michael@0: { michael@0: return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel); michael@0: } michael@0: michael@0: inline nsPoint michael@0: nsPoint::ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const michael@0: { michael@0: if (aFromAPP != aToAPP) { michael@0: nsPoint point; michael@0: point.x = NSToCoordRound(NSCoordScale(x, aFromAPP, aToAPP)); michael@0: point.y = NSToCoordRound(NSCoordScale(y, aFromAPP, aToAPP)); michael@0: return point; michael@0: } michael@0: return *this; michael@0: } michael@0: michael@0: // app units are integer multiples of pixels, so no rounding needed michael@0: inline nsPoint michael@0: nsIntPoint::ToAppUnits(nscoord aAppUnitsPerPixel) const michael@0: { michael@0: return nsPoint(NSIntPixelsToAppUnits(x, aAppUnitsPerPixel), michael@0: NSIntPixelsToAppUnits(y, aAppUnitsPerPixel)); michael@0: } michael@0: michael@0: #endif /* NSPOINT_H */