wiesel / src / common / wiesel / graph / 2d / node2d.h

/**
 * Copyright (C) 2012
 * Christian Fischer
 *
 * https://bitbucket.org/baldur/wiesel/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 */
#ifndef __WIESEL_GRAPH_2D_NODE2D_H__
#define	__WIESEL_GRAPH_2D_NODE2D_H__

#include <wiesel/wiesel-common.def>

#include "wiesel/graph/node.h"
#include "wiesel/math/vector2d.h"
#include "wiesel/geometry.h"


namespace wiesel {

	class WIESEL_COMMON_EXPORT Node2D : public Node
	{
	public:
		Node2D();
		virtual ~Node2D();

	// getter/setter
	public:
		/// set the content size of this node
		void setContentSize(const dimension &size);

		/// set the content size of this node
		void setContentSize(float width, float height);

		/// set the pivot point of this node.
		/// usually this value would be between 0,0 (bottom left) and 1,1 (top right).
		void setPivot(const vector2d &pivot);

		/// set the pivot point of this node.
		/// usually this value would be between 0,0 (bottom left) and 1,1 (top right).
		void setPivot(float x, float y);

		/// set the 2D bounding rectangle of this node.
		void setBounds(const rectangle &bounds);

		/// get the content size of this node.
		inline const dimension& getContentSize() const {
			return bounds.size;
		}

		/// get the pivot point of this node.
		/// usually this value would be between 0,0 (bottom left) and 1,1 (top right).
		inline const vector2d& getPivot() const {
			return pivot;
		}

		/// get the pivot offset in units, relative to the node's boundings
		vector2d getPivotInUnits() const;

		/// get the bounding rect of this node.
		/// boundings will be stored in local coordinates, which means, a point,
		/// which should be compared to the boundings, needs to be transformed first.
		inline const rectangle& getBounds() const {
			return bounds;
		}

	// transformation setter/getter
	public:
		/// set the position of this node, relative to it's parent.
		void setPosition(const vector2d &v);

		/// set the position of this node.
		void setPosition(float x, float y);

		/// set the rotation of this node.
		/// unless other transformation methods,
		/// this function will take values in degrees
		void setRotation(float a);

		/// set the scale value of this node.
		void setScale(float s);

		/// set the scale value of this node.
		void setScaleX(float sx);

		/// set the scale value of this node.
		void setScaleY(float sy);

		/// get the position of this node, relative to it's parent.
		inline const vector2d& getPosition() const {
			return position;
		}

		/// get the rotation of this node.
		inline float getRotation() const {
			return rotation;
		}

		/// get the scale value of this node.
		inline float getScaleX() const {
			return scale_x;
		}

		/// get the scale value of this node.
		inline float getScaleY() const {
			return scale_y;
		}

		/// get the scale value of this node.
		inline float getScale() const {
			return scale_x;
		}

		/// update the transform matrices
		void updateTransform();


	public:
		/// Tests, if a point is within this node.
		/// The point should already be transformed into the node's coordinate system.
		virtual bool hitBy(const vector2d &local) const;


	// overridables
	protected:


	private:
		rectangle	bounds;
		vector2d	pivot;

		vector2d	position;
		float		rotation;
		float		scale_x;
		float		scale_y;
	};

}

#endif	/* __WIESEL_GRAPH_2D_NODE2D_H__ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.