Skip to content

Commit

Permalink
libdeng2: Imported Hawthorn code
Browse files Browse the repository at this point in the history
Added Rectangle, Clock, Animation, rules, Widget and RootWidget.
  • Loading branch information
skyjake committed Jan 21, 2013
1 parent decaa5e commit 4cb8e40
Show file tree
Hide file tree
Showing 43 changed files with 2,518 additions and 12 deletions.
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/Animation
@@ -0,0 +1 @@
#include "widgets/animation.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/AnimationVector
@@ -0,0 +1 @@
#include "widgets/animationvector.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/Clock
@@ -0,0 +1 @@
#include "core/clock.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/ConstantRule
@@ -0,0 +1 @@
#include "widgets/constantrule.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/DerivedRule
@@ -0,0 +1 @@
#include "widgets/derivedrule.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/OperatorRule
@@ -0,0 +1 @@
#include "widgets/operatorrule.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/Rectangle
@@ -0,0 +1 @@
#include "rectangle.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/RectangleRule
@@ -0,0 +1 @@
#include "widgets/rectanglerule.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/RootWidget
@@ -0,0 +1 @@
#include "widgets/rootwidget.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/Rule
@@ -0,0 +1 @@
#include "widgets/rule.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/ScalarRule
@@ -0,0 +1 @@
#include "widgets/scalarrule.h"
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/Widget
@@ -0,0 +1 @@
#include "widgets/widget.h"
6 changes: 6 additions & 0 deletions doomsday/libdeng2/include/de/core/app.h
Expand Up @@ -21,6 +21,7 @@
#define LIBDENG2_APP_H

#include "../libdeng2.h"
#include "../Clock"
#include "../CommandLine"
#include "../NativePath"
#include "../LogBuffer"
Expand Down Expand Up @@ -100,6 +101,11 @@ class DENG2_PUBLIC App : public QApplication

static App &app();

/**
* Returns the primary (wall) clock.
*/
static Clock &clock();

/**
* Returns the command line used to start the application.
*/
Expand Down
56 changes: 56 additions & 0 deletions doomsday/libdeng2/include/de/core/clock.cpp
@@ -0,0 +1,56 @@
/** @file clock.cpp Time source.
*
* @authors Copyright © 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "de/Clock"

namespace de {

Clock::Clock()
{}

Clock::~Clock()
{}

void Clock::setTime(Time const &currentTime)
{
bool changed = (_time != currentTime);

_time = currentTime;

if(changed)
{
emit timeChanged();
}
}

void Clock::advanceTime(Time::Delta const &span)
{
setTime(_time + span);
}

Time::Delta Clock::elapsed() const
{
return _time - _startedAt;
}

Time const &Clock::time() const
{
return _time;
}

} // namespace de
68 changes: 68 additions & 0 deletions doomsday/libdeng2/include/de/core/clock.h
@@ -0,0 +1,68 @@
/*
* The Doomsday Engine Project -- libdeng2
*
* Copyright (c) 2009-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBDENG2_CLOCK_H
#define LIBDENG2_CLOCK_H

#include <QObject>
#include "../Time"

namespace de {

/**
* Time source.
* @ingroup core
*/
class Clock : public QObject
{
Q_OBJECT

public:
Clock();

virtual ~Clock();

virtual void setTime(Time const &currentTime);

void advanceTime(Time::Delta const &span);

/**
* Returns the amount of time elapsed since the clock was created.
* @return Elapsed time.
*/
Time::Delta elapsed() const;

/**
* Returns a reference to the current time.
*
* @return Current time.
*/
Time const &time() const;

signals:
void timeChanged();

private:
Time _startedAt;
Time _time;
};

} // namespace de

#endif /* LIBDENG2_ICLOCK_H */
13 changes: 12 additions & 1 deletion doomsday/libdeng2/include/de/data/time.h
Expand Up @@ -44,7 +44,7 @@ class DENG2_PUBLIC Time : public ISerializable
/**
* Difference between two points in time. @ingroup types
*/
class DENG2_PUBLIC Delta
class DENG2_PUBLIC Delta : public ISerializable
{
public:
/**
Expand All @@ -71,6 +71,11 @@ class DENG2_PUBLIC Time : public ISerializable

Delta operator - (ddouble const &d) const;

Delta &operator -= (ddouble const &d) {
_seconds -= d;
return *this;
}

/**
* Convert the delta to milliseconds.
*
Expand All @@ -93,6 +98,10 @@ class DENG2_PUBLIC Time : public ISerializable
*/
void sleep() const;

// Implements ISerializable.
void operator >> (Writer &to) const;
void operator << (Reader &from);

private:
ddouble _seconds;
};
Expand Down Expand Up @@ -128,6 +137,8 @@ class DENG2_PUBLIC Time : public ISerializable

bool operator == (Time const &t) const;

bool operator != (Time const &t) const { return !(*this == t); }

/**
* Add a delta to the point of time.
*
Expand Down
92 changes: 92 additions & 0 deletions doomsday/libdeng2/include/de/rectangle.h
@@ -0,0 +1,92 @@
/*
* The Doomsday Engine Project -- libdeng2
*
* Copyright (c) 2009-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBDENG2_RECTANGLE_H
#define LIBDENG2_RECTANGLE_H

#include "../Vector"

namespace de {

/**
* Template for 2D rectangles. The members are public for convenient access.
*
* @ingroup math
*/
template <typename VectorType>
class Rectangle
{
public:
typedef VectorType Corner;
typedef typename Corner::ValueType Type;

public:
Rectangle() {}
Rectangle(const Corner& tl, const Corner& br) : topLeft(tl), bottomRight(br) {}
Type width() const { return abs(bottomRight.x - topLeft.x); }
Type height() const { return abs(bottomRight.y - topLeft.y); }
Vector2<Type> size() const { return Vector2<Type>(width(), height()); }
void setWidth(Type w) { bottomRight.x = topLeft.x + w; }
void setHeight(Type h) { bottomRight.y = topLeft.y + h; }
void setSize(const Vector2<Type>& s) { setWidth(s.x); setHeight(s.y); }
void include(const Corner& point) {
topLeft = topLeft.min(point);
bottomRight = bottomRight.max(point);
}
bool contains(const Corner& point) const {
return point >= topLeft && point <= bottomRight;
}
String asText() const {
return "[" + topLeft.asText() + ", " + bottomRight.asText() + "]";
}
Corner topRight() const {
return Corner(bottomRight.x, topLeft.y);
}
Corner bottomLeft() const {
return Corner(topLeft.x, bottomRight.y);
}
Corner midLeft() const {
return Corner(topLeft.x, (topLeft.y + bottomRight.y)/2.0);
}
Corner midRight() const {
return Corner(bottomRight.x, (topLeft.y + bottomRight.y)/2.0);
}
Corner midTop() const {
return Corner((topLeft.x + bottomRight.x)/2.0, topLeft.y);
}
Corner midBottom() const {
return Corner((topLeft.x + bottomRight.x)/2.0, bottomRight.y);
}
Corner middle() const {
return Corner((topLeft.x + bottomRight.x)/2.0, (topLeft.y + bottomRight.y)/2.0);
}

public:
Corner topLeft;
Corner bottomRight;
};

// Common types.
typedef Rectangle<Vector2i> Rectanglei;
typedef Rectangle<Vector2ui> Rectangleui;
typedef Rectangle<Vector2f> Rectanglef;

} // namespace de

#endif /* LIBDENG2_RECTANGLE_H */
18 changes: 9 additions & 9 deletions doomsday/libdeng2/include/de/vector.h
Expand Up @@ -440,17 +440,17 @@ inline bool operator == (Vector4<duint> const &a, Vector4<duint> const &b)

//@{
/// @ingroup types
typedef Vector2<dint> Vector2i; ///< 2-component vector of integer values.
typedef Vector2<duint> Vector2ui; ///< 2-component vector of unsigned integer values.
typedef Vector2<dfloat> Vector2f; ///< 2-component vector of floating point values.
typedef Vector2<dint> Vector2i; ///< 2-component vector of integer values.
typedef Vector2<duint> Vector2ui; ///< 2-component vector of unsigned integer values.
typedef Vector2<dfloat> Vector2f; ///< 2-component vector of floating point values.
typedef Vector2<ddouble> Vector2d; ///< 2-component vector of high-precision floating point values.
typedef Vector3<dint> Vector3i; ///< 3-component vector of integer values.
typedef Vector3<duint> Vector3ui; ///< 3-component vector of unsigned integer values.
typedef Vector3<dfloat> Vector3f; ///< 3-component vector of floating point values.
typedef Vector3<dint> Vector3i; ///< 3-component vector of integer values.
typedef Vector3<duint> Vector3ui; ///< 3-component vector of unsigned integer values.
typedef Vector3<dfloat> Vector3f; ///< 3-component vector of floating point values.
typedef Vector3<ddouble> Vector3d; ///< 3-component vector of high-precision floating point values.
typedef Vector4<dint> Vector4i; ///< 4-component vector of integer values.
typedef Vector4<duint> Vector4ui; ///< 4-component vector of unsigned integer values.
typedef Vector4<dfloat> Vector4f; ///< 4-component vector of floating point values.
typedef Vector4<dint> Vector4i; ///< 4-component vector of integer values.
typedef Vector4<duint> Vector4ui; ///< 4-component vector of unsigned integer values.
typedef Vector4<dfloat> Vector4f; ///< 4-component vector of floating point values.
typedef Vector4<ddouble> Vector4d; ///< 4-component vector of high-precision floating point values.
//@}

Expand Down

0 comments on commit 4cb8e40

Please sign in to comment.