2011-06-24 10:41:16 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
#ifndef MOZILLA_GFX_POINT_H_
|
|
|
|
#define MOZILLA_GFX_POINT_H_
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
#include "Types.h"
|
|
|
|
#include "BasePoint.h"
|
|
|
|
#include "BaseSize.h"
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
// This should only be used by the typedefs below.
|
|
|
|
struct UnknownUnits {};
|
2011-11-13 20:29:01 -08:00
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
template<class units>
|
|
|
|
struct IntPointTyped :
|
|
|
|
public BasePoint< int32_t, IntPointTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BasePoint< int32_t, IntPointTyped<units> > Super;
|
|
|
|
|
|
|
|
IntPointTyped() : Super() {}
|
|
|
|
IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {}
|
2013-06-11 15:13:11 -07:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
|
|
|
static IntPointTyped<units> FromUnknownPoint(const IntPointTyped<UnknownUnits>& aPoint) {
|
|
|
|
return IntPointTyped<units>(aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntPointTyped<UnknownUnits> ToUnknownPoint() const {
|
|
|
|
return IntPointTyped<UnknownUnits>(this->x, this->y);
|
|
|
|
}
|
2011-11-13 20:29:01 -08:00
|
|
|
};
|
2013-05-29 06:32:30 -07:00
|
|
|
typedef IntPointTyped<UnknownUnits> IntPoint;
|
2011-11-13 20:29:01 -08:00
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
template<class units>
|
|
|
|
struct PointTyped :
|
|
|
|
public BasePoint< Float, PointTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BasePoint< Float, PointTyped<units> > Super;
|
2011-11-13 20:29:01 -08:00
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
PointTyped() : Super() {}
|
|
|
|
PointTyped(Float aX, Float aY) : Super(aX, aY) {}
|
|
|
|
PointTyped(const IntPointTyped<units>& point) : Super(float(point.x), float(point.y)) {}
|
2013-05-30 18:30:13 -07:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
2013-06-11 15:13:11 -07:00
|
|
|
static PointTyped<units> FromUnknownPoint(const PointTyped<UnknownUnits>& aPoint) {
|
|
|
|
return PointTyped<units>(aPoint.x, aPoint.y);
|
2013-05-30 18:30:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PointTyped<UnknownUnits> ToUnknownPoint() const {
|
|
|
|
return PointTyped<UnknownUnits>(this->x, this->y);
|
|
|
|
}
|
2011-06-24 10:41:16 -07:00
|
|
|
};
|
2013-05-29 06:32:30 -07:00
|
|
|
typedef PointTyped<UnknownUnits> Point;
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2013-06-14 13:11:31 -07:00
|
|
|
template<class units>
|
|
|
|
IntPointTyped<units> RoundedToInt(const PointTyped<units>& aPoint) {
|
|
|
|
return IntPointTyped<units>(NS_lround(aPoint.x),
|
|
|
|
NS_lround(aPoint.y));
|
|
|
|
}
|
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
template<class units>
|
|
|
|
struct IntSizeTyped :
|
|
|
|
public BaseSize< int32_t, IntSizeTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BaseSize< int32_t, IntSizeTyped<units> > Super;
|
2011-11-13 20:29:01 -08:00
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
IntSizeTyped() : Super() {}
|
|
|
|
IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
|
2013-06-11 15:13:11 -07:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
|
|
|
static IntSizeTyped<units> FromUnknownSize(const IntSizeTyped<UnknownUnits>& aSize) {
|
|
|
|
return IntSizeTyped<units>(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSizeTyped<UnknownUnits> ToUnknownSize() const {
|
|
|
|
return IntSizeTyped<UnknownUnits>(this->width, this->height);
|
|
|
|
}
|
2011-06-24 10:41:16 -07:00
|
|
|
};
|
2013-05-29 06:32:30 -07:00
|
|
|
typedef IntSizeTyped<UnknownUnits> IntSize;
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
template<class units>
|
|
|
|
struct SizeTyped :
|
|
|
|
public BaseSize< Float, SizeTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BaseSize< Float, SizeTyped<units> > Super;
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2013-05-29 06:32:30 -07:00
|
|
|
SizeTyped() : Super() {}
|
|
|
|
SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
|
|
|
|
explicit SizeTyped(const IntSizeTyped<units>& size) :
|
2013-03-04 06:38:11 -08:00
|
|
|
Super(float(size.width), float(size.height)) {}
|
2013-06-11 15:13:11 -07:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
|
|
|
static SizeTyped<units> FromUnknownSize(const SizeTyped<UnknownUnits>& aSize) {
|
|
|
|
return SizeTyped<units>(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
SizeTyped<UnknownUnits> ToUnknownSize() const {
|
|
|
|
return SizeTyped<UnknownUnits>(this->width, this->height);
|
|
|
|
}
|
2011-05-26 12:41:33 -07:00
|
|
|
};
|
2013-05-29 06:32:30 -07:00
|
|
|
typedef SizeTyped<UnknownUnits> Size;
|
2011-05-26 12:41:33 -07:00
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
}
|
2011-05-26 12:41:33 -07:00
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
#endif /* MOZILLA_GFX_POINT_H_ */
|