Commit 9b9552c6 by Jessica Hawkwell

adding Dimension and Point for #1

1 parent 19f2b663
......@@ -11,6 +11,7 @@ nitrogen/nwt/Border.cpp
nitrogen/nwt/Color.cpp
nitrogen/nwt/Component.cpp
nitrogen/nwt/ComponentEvent.cpp
nitrogen/nwt/Dimension.cpp
nitrogen/nwt/EventListener.cpp
nitrogen/nwt/EventObject.cpp
nitrogen/nwt/Font.cpp
......@@ -21,6 +22,7 @@ nitrogen/nwt/Insets.cpp
nitrogen/nwt/MouseEvent.cpp
nitrogen/nwt/MouseListener.cpp
nitrogen/nwt/NWTEvent.cpp
nitrogen/nwt/Point.cpp
)
......
/*
* Copyright (c) 2018, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Dimension.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 12:30 AM
*/
#include "Dimension.h"
namespace nitrogen {
namespace nwt {
Dimension::Dimension() {
w = 0;
h = 0;
}
Dimension::Dimension(unsigned int width, unsigned int height) {
w = width;
h = height;
}
unsigned int Dimension::getHeight() const {
return h;
}
unsigned int Dimension::getWitdh() const {
return w;
}
Dimension* Dimension::getSize() const {
Dimension* d = new Dimension(w, h);
return d;
}
void Dimension::setSize(Dimension* size) {
w = size->w;
h = size->h;
}
void Dimension::setSize(unsigned int width, unsigned int height) {
w = width;
h = height;
}
void Dimension::setSize(double width, double height) {
w = width;
h = height;
}
std::string* Dimension::toString() const {
std::string* out;
out->append(getTypeName(this));
out->append("(");
out->append(std::to_string(w));
out->append(",");
out->append(std::to_string(h));
out->append(")");
return out;
}
Dimension& Dimension::operator()(unsigned int width, unsigned int height) const {
Dimension* d = new Dimension(width, height);
return *d;
}
Dimension& Dimension::operator=(const Dimension& right) {
if (*this != right) {
w = right.w;
h = right.h;
}
return *this;
}
bool Dimension::operator==(const Dimension& right) const {
if (w != right.w) {
return false;
}
else if (h != right.h) {
return false;
}
return true;
}
}
}
/*
* Copyright (c) 2018, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Dimension.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 12:30 AM
*/
#ifndef DIMENSION_H
#define DIMENSION_H
#include <ntk.h>
namespace nitrogen {
namespace nwt {
class Dimension : public NObject {
public:
Dimension();
Dimension(unsigned int width, unsigned int height);
virtual unsigned int getHeight() const;
virtual unsigned int getWitdh() const;
virtual Dimension* getSize() const;
virtual void setSize(Dimension* size);
virtual void setSize(unsigned int width, unsigned int height);
virtual void setSize(double width, double height);
virtual std::string* toString() const;
virtual Dimension& operator()(unsigned int width, unsigned int height) const;
virtual Dimension& operator=(const Dimension& right);
virtual bool operator==(const Dimension& right) const;
protected:
unsigned int w;
unsigned int h;
private:
};
}
}
#endif /* DIMENSION_H */
/*
* Copyright (c) 2018, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Point.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 12:44 AM
*/
#include "Point.h"
namespace nitrogen {
namespace nwt {
Point::Point() {
px = 0;
py = 0;
}
Point::Point(int x, int y) {
px = x;
py = y;
}
Point* Point::getLocation() const {
Point *p = new Point(px, py);
return p;
}
int Point::getX() const {
return px;
}
int Point::getY() const {
return py;
}
void Point::move(int x, int y) {
px = x;
py = y;
}
void Point::setLocation(int x, int y) {
move(x, y);
}
void Point::setLocation(Point* loc) {
move(loc->px, loc->py);
}
void Point::translate(int x, int y) {
px += x;
py += y;
}
std::string* Point::toString() const {
std::string* out;
out->append(getTypeName(this));
out->append("(");
out->append(std::to_string(px));
out->append(",");
out->append(std::to_string(py));
out->append(")");
return out;
}
Point& Point::operator()(int x, int y) const {
Point* p = new Point(x, y);
return *p;
}
Point& Point::operator=(const Point& right) {
if (*this != right) {
move(right.px, right.py);
}
return *this;
}
bool Point::operator==(const Point& right) const {
if (px != right.px) {
return false;
}
else if (py != right.py) {
return false;
}
return true;
}
}
}
/*
* Copyright (c) 2018, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Point.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 12:44 AM
*/
#ifndef POINT_H
#define POINT_H
#include <ntk.h>
namespace nitrogen {
namespace nwt {
class Point : public NObject {
public:
Point();
Point(int x, int y);
virtual Point* getLocation() const;
virtual int getX() const;
virtual int getY() const;
virtual void move(int x, int y);
virtual void setLocation(int x, int y);
virtual void setLocation(Point* loc);
virtual void translate(int x, int y);
virtual std::string* toString() const;
virtual Point& operator()(int x, int y) const;
virtual Point& operator=(const Point& right);
virtual bool operator==(const Point& right) const;
protected:
int px;
int py;
private:
};
}
}
#endif /* POINT_H */
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!