Commit 6b1be3ff by Jessica Hawkwell

Added new classes for #1

1 parent 9b9552c6
Showing with 1091 additions and 359 deletions
#include "NitroWin.h" #include "NitroWin.h"
#include <nitrogen/nwt/Color.h> #include <nitrogen/nwt/Color.h>
#include <nitrogen/NObject.h> #include <nitrogen/Object.h>
#include "NWManager.h" #include "NWManager.h"
#include <iostream> #include <iostream>
int main ( int argc, char** argv ) int main(int argc, char** argv) {
{
std::cout << NITROWIN_NAME << " v" << NITROWIN_VERSION << std::endl; std::cout << NITROWIN_NAME << " v" << NITROWIN_VERSION << std::endl;
nitrogen::nwt::Color no = nitrogen::nwt::Color(255, 255, 255); nitrogen::nwt::Color no = nitrogen::nwt::Color(255, 255, 255);
std::cout << "Color: "; std::cout << "Color: ";
......
...@@ -28,66 +28,6 @@ ...@@ -28,66 +28,6 @@
namespace nitrogen { namespace nitrogen {
/*template <typename T>
NPosition<T>::NPosition(T x, T y) {
px = x;
py = y;
} // */
/*template <typename T>
NPosition<T>::NPosition(const NPosition<T>& other) {
px = other.px;
py = other.py;
} // */
/*template <typename T>
NPosition<T>& NPosition<T>::operator=(const NPosition<T>&& other) {
px = other.px;
py = other.py;
return *this;
} // */
/*template <typename T>
NPosition<T> NPosition<T>::operator+(const NPosition<T>& other) {
NPosition<T> rt = NPosition<T>(px + other.px, py + other.py);
return rt;
} // */
/*template <typename T>
NPosition<T> NPosition<T>::operator-(const NPosition<T>& other) {
NPosition<T> rt = NPosition<T>(px - other.px, py - other.py);
return rt;
} // */
/*template <typename T>
bool NPosition<T>::operator==(const NPosition<T>& other) const {
if (px != other.getX()) { return false; }
if (py != other.getY()) { return false; }
return true;
} // */
/*template <typename T>
std::string NPosition<T>::toString() {
std::string out = std::string();
out.append("(");
out.append(std::to_string(px));
out.append(", ");
out.append(std::to_string(py));
out.append(")");
return out;
} // */
/*template <typename T>
T NPosition<T>::getX() { return px; } // */
/*template <typename T>
T NPosition<T>::getY() { return py; } // */
/*template <typename T>
void NPosition<T>::setZeroIfNegative() {
if (px < 0) { px = 0; }
if (py < 0) { py = 0;}
} // */
void testNPositionInt() { void testNPositionInt() {
NPosition<int> rawr = NPosition<int>(1, 1); NPosition<int> rawr = NPosition<int>(1, 1);
rawr.getX(); rawr.getX();
......
...@@ -6,11 +6,14 @@ find_package(X11) ...@@ -6,11 +6,14 @@ find_package(X11)
find_library(BoehmGC gc-threaded) find_library(BoehmGC gc-threaded)
add_library(${PROJECT_NAME} SHARED ntkMain.cpp add_library(${PROJECT_NAME} SHARED ntkMain.cpp
nitrogen/NObject.cpp nitrogen/Object.cpp
nitrogen/nwt/ActionEvent.cpp
nitrogen/nwt/ActionListener.cpp
nitrogen/nwt/Border.cpp nitrogen/nwt/Border.cpp
nitrogen/nwt/Color.cpp nitrogen/nwt/Color.cpp
nitrogen/nwt/Component.cpp nitrogen/nwt/Component.cpp
nitrogen/nwt/ComponentEvent.cpp nitrogen/nwt/ComponentEvent.cpp
nitrogen/nwt/Container.cpp
nitrogen/nwt/Dimension.cpp nitrogen/nwt/Dimension.cpp
nitrogen/nwt/EventListener.cpp nitrogen/nwt/EventListener.cpp
nitrogen/nwt/EventObject.cpp nitrogen/nwt/EventObject.cpp
...@@ -19,10 +22,12 @@ nitrogen/nwt/FontMetrics.cpp ...@@ -19,10 +22,12 @@ nitrogen/nwt/FontMetrics.cpp
nitrogen/nwt/Graphics.cpp nitrogen/nwt/Graphics.cpp
nitrogen/nwt/InputEvent.cpp nitrogen/nwt/InputEvent.cpp
nitrogen/nwt/Insets.cpp nitrogen/nwt/Insets.cpp
nitrogen/nwt/LayoutManager.cpp
nitrogen/nwt/MouseEvent.cpp nitrogen/nwt/MouseEvent.cpp
nitrogen/nwt/MouseListener.cpp nitrogen/nwt/MouseListener.cpp
nitrogen/nwt/NWTEvent.cpp nitrogen/nwt/NWTEvent.cpp
nitrogen/nwt/Point.cpp nitrogen/nwt/Point.cpp
nitrogen/nwt/Rectangle.cpp
) )
......
...@@ -25,51 +25,51 @@ ...@@ -25,51 +25,51 @@
*/ */
/* /*
* File: NObject.cpp * File: Object.cpp
* Author: jlhawkwell * Author: jlhawkwell
* *
* Created on March 16, 2018, 11:12 AM * Created on March 16, 2018, 11:12 AM
*/ */
#include "NObject.h" #include "Object.h"
#include <ostream> #include <ostream>
namespace nitrogen { namespace nitrogen {
NObject::NObject() { Object::Object() {
} }
std::string* NObject::toString() const { std::string* Object::toString() {
std::string* str; std::string* str;
str->append(getTypeName(this)); str->append(getTypeName(this));
return str; return str;
} }
NObject& NObject::operator()() const { Object& Object::operator()() {
NObject *tmp = new NObject(); Object *tmp = new Object();
return *tmp; return *tmp;
} }
NObject& NObject::operator=(const NObject& right) { Object& Object::operator=(Object& right) {
if (this == &right) { if (*this == right) {
return *this; // Yes, so skip assignment, and just return *this. return *this; // Yes, so skip assignment, and just return *this.
} }
return *this; return *this;
} }
bool NObject::operator!=(const NObject& right) const { bool Object::operator!=(Object& right) {
return !(*this == right); return !(*this == right);
} }
bool NObject::operator==(const NObject& right) const { bool Object::operator==(Object& right) {
bool result = false; bool result = false;
return result; return result;
} }
std::ostream& operator<<(std::ostream& os, const NObject& obj) { std::ostream& operator<<(std::ostream& os, Object& obj) {
// Write obj to stream // Write obj to stream
os << *obj.toString(); os << obj.toString()->c_str();
return os; return os;
} }
} }
...@@ -25,30 +25,30 @@ ...@@ -25,30 +25,30 @@
*/ */
/* /*
* File: NObject.h * File: Object.h
* Author: jlhawkwell * Author: jlhawkwell
* *
* Created on March 16, 2018, 11:12 AM * Created on March 16, 2018, 11:12 AM
*/ */
#ifndef NOBJECT_H #ifndef OBJECT_H
#define NOBJECT_H #define OBJECT_H
#include <ntk.h> #include <ntk.h>
namespace nitrogen { namespace nitrogen {
class NObject : public gc { class Object : public gc {
public: public:
NObject(); Object();
virtual std::string* toString() const; virtual std::string* toString();
virtual NObject& operator()() const; virtual Object& operator()();
virtual NObject& operator=(const NObject& right); virtual Object& operator=(Object& right);
virtual bool operator!=(const NObject& right) const; virtual bool operator!=(Object& right);
virtual bool operator==(const NObject& right) const; virtual bool operator==(Object& right);
friend std::ostream& operator<<(std::ostream& os, const NObject& obj); friend std::ostream& operator<<(std::ostream& os, Object& obj);
private: private:
}; };
} }
#endif /* NOBJECT_H */ #endif /* OBJECT_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: ActionEvent.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 9:24 AM
*/
#include "ActionEvent.h"
namespace nitrogen {
namespace nwt {
ActionEvent::ActionEvent(Object* object, int i, std::string* cmd)
: NWTEvent(object, i) {
source = object;
id = i;
command = cmd;
}
ActionEvent::ActionEvent(Object* object, int i, std::string& cmd)
: NWTEvent(object, i) {
source = object;
id = i;
command = &cmd;
}
ActionEvent::ActionEvent(Object* object, std::string* cmd)
: NWTEvent(object, 0) {
source = object;
id = 0;
command = cmd;
}
ActionEvent::ActionEvent(Object* object, std::string& cmd)
: NWTEvent(object, 0) {
source = object;
id = 0;
command = &cmd;
}
std::string* ActionEvent::toString() {
std::string* out;
out->append(getTypeName(this));
out->append("(");
out->append(source->toString()->c_str());
out->append(",");
out->append(std::to_string(id));
out->append(",");
out->append(command->c_str());
out->append(")");
return out;
}
ActionEvent& ActionEvent::operator()(Object& object, int i, std::string* cmd) {
ActionEvent* ae = new ActionEvent(&object, i, cmd);
return *ae;
}
ActionEvent& ActionEvent::operator()(Object& object, std::string* cmd) {
ActionEvent* ae = new ActionEvent(&object, 0, cmd);
return *ae;
}
ActionEvent& ActionEvent::operator=(ActionEvent& right) {
if (*this != right) {
NWTEvent::operator=(right);
command = right.command;
}
return *this;
}
bool ActionEvent::operator==(ActionEvent& right) {
if (*command != *right.command) {
return false;
}
return NWTEvent::operator==(right);
}
}
}
/*
* 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: ActionEvent.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 9:24 AM
*/
#ifndef ACTIONEVENT_H
#define ACTIONEVENT_H
#include <ntk.h>
#include <nitrogen/nwt/NWTEvent.h>
namespace nitrogen {
namespace nwt {
class ActionEvent : public NWTEvent {
public:
ActionEvent(Object* object, int i, std::string* cmd);
ActionEvent(Object* object, int i, std::string& cmd);
ActionEvent(Object* object, std::string* cmd);
ActionEvent(Object* object, std::string& cmd);
virtual std::string* toString() override;
virtual ActionEvent& operator()(Object& object, int i, std::string* cmd);
virtual ActionEvent& operator()(Object& object, std::string* cmd);
virtual ActionEvent& operator=(ActionEvent& right);
virtual bool operator==(ActionEvent& right);
protected:
std::string* command;
private:
};
}
}
#endif /* ACTIONEVENT_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: ActionListener.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 9:43 AM
*/
#include "ActionListener.h"
namespace nitrogen {
namespace nwt {
ActionListener::ActionListener() {
}
}
}
/*
* 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: ActionListener.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 9:43 AM
*/
#ifndef ACTIONLISTENER_H
#define ACTIONLISTENER_H
#include <ntk.h>
#include <nitrogen/nwt/EventListener.h>
namespace nitrogen {
namespace nwt {
class ActionEvent;
class ActionListener : public EventListener {
public:
ActionListener();
virtual void actionPerformed(ActionEvent* event) = 0;
private:
};
}
}
#endif /* ACTIONLISTENER_H */
...@@ -36,25 +36,23 @@ ...@@ -36,25 +36,23 @@
#include <ntk.h> #include <ntk.h>
//#include <nitrogen/nwt/Component.h>
#include <nitrogen/nwt/Graphics.h>
#include <nitrogen/nwt/Insets.h>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Component; class Component;
class Graphics;
class Insets;
class Border : public NObject { class Border : public Object {
public: public:
virtual Insets* getBorderInsets(Component* comp) = 0; virtual Insets* getBorderInsets(Component* comp) = 0;
virtual bool isBorderOpaque() = 0; virtual bool isBorderOpaque() = 0;
virtual void paintBorder(Component* comp, Graphics* g, int, int, unsigned int, unsigned int) = 0; virtual void paintBorder(Component* comp, Graphics* g, int, int, unsigned int, unsigned int) = 0;
virtual std::string* toString() const = 0; virtual std::string* toString() const = 0;
virtual Border& operator()(Component* comp) const = 0; virtual Border& operator()(Component& comp) const = 0;
virtual Border& operator=(const Border& right) = 0; virtual Border& operator=(Border& right) = 0;
//virtual bool operator!=(const Color& right) const = 0; //virtual bool operator!=(Color& right) const = 0;
virtual bool operator==(const Border& right) const = 0; virtual bool operator==(Border& right) const = 0;
protected: protected:
Component* c; Component* c;
......
...@@ -57,31 +57,31 @@ namespace nitrogen { ...@@ -57,31 +57,31 @@ namespace nitrogen {
blue = b; blue = b;
} }
unsigned char Color::getAlpha() const { unsigned char Color::getAlpha() {
return alpha; return alpha;
} }
unsigned char Color::getBlue() const { unsigned char Color::getBlue() {
return blue; return blue;
} }
unsigned char Color::getGreen() const { unsigned char Color::getGreen() {
return green; return green;
} }
unsigned int Color::getRGB() const { unsigned int Color::getRGB() {
return (red << 16) + (green << 8) + blue; return (red << 16) + (green << 8) + blue;
} }
unsigned int Color::getARGB() const { unsigned int Color::getARGB() {
return (alpha << 24) +getRGB(); return (alpha << 24) +getRGB();
} }
unsigned char Color::getRed() const { unsigned char Color::getRed() {
return red; return red;
} }
std::string* Color::toString() const { std::string* Color::toString() {
std::string *out = new (UseGC) std::string(); std::string *out = new (UseGC) std::string();
std::string t = getTypeName(this); std::string t = getTypeName(this);
...@@ -99,22 +99,22 @@ namespace nitrogen { ...@@ -99,22 +99,22 @@ namespace nitrogen {
return out; return out;
} }
Color& Color::operator()(unsigned int c) const { Color& Color::operator()(unsigned int c) {
Color *nc = new Color(c); Color *nc = new Color(c);
return *nc; return *nc;
} }
Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b) const { Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b) {
Color *nc = new Color(r, g, b); Color *nc = new Color(r, g, b);
return *nc; return *nc;
} }
Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b, unsigned char a) const { Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
Color *nc = new Color(r, g, b, a); Color *nc = new Color(r, g, b, a);
return *nc; return *nc;
} }
Color& Color::operator=(const Color& right) { Color& Color::operator=(Color& right) {
if (*this != right) { if (*this != right) {
alpha = right.getAlpha(); alpha = right.getAlpha();
red = right.getRed(); red = right.getRed();
...@@ -124,11 +124,11 @@ namespace nitrogen { ...@@ -124,11 +124,11 @@ namespace nitrogen {
return *this; return *this;
} }
/*bool Color::operator!=(const Color& right) const { /*bool Color::operator!=(Color& right) {
return !(*this == right); return !(*this == right);
}// */ }// */
bool Color::operator==(const Color& right) const { bool Color::operator==(Color& right) {
return (getARGB() == right.getARGB()); return (getARGB() == right.getARGB());
} }
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Color : public NObject { class Color : public Object {
public: public:
static const unsigned int MASK_ALPHA = 0xff000000; static const unsigned int MASK_ALPHA = 0xff000000;
static const unsigned int MASK_RED = 0x00ff0000; static const unsigned int MASK_RED = 0x00ff0000;
...@@ -67,20 +67,20 @@ namespace nitrogen { ...@@ -67,20 +67,20 @@ namespace nitrogen {
Color(unsigned char red, unsigned char green, unsigned char blue); Color(unsigned char red, unsigned char green, unsigned char blue);
Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha); Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha);
unsigned char getAlpha() const; unsigned char getAlpha();
unsigned char getRed() const; unsigned char getRed();
unsigned char getGreen() const; unsigned char getGreen();
unsigned char getBlue() const; unsigned char getBlue();
unsigned int getRGB() const; unsigned int getRGB();
unsigned int getARGB() const; unsigned int getARGB();
virtual std::string* toString() const; virtual std::string* toString() override;
virtual Color& operator()(unsigned int c) const; virtual Color& operator()(unsigned int c);
virtual Color& operator()(unsigned char red, unsigned char green, unsigned char blue) const; virtual Color& operator()(unsigned char red, unsigned char green, unsigned char blue);
virtual Color& operator()(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) const; virtual Color& operator()(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha);
virtual Color& operator=(const Color& right); virtual Color& operator=(Color& right);
//virtual bool operator!=(const Color& right) const; //virtual bool operator!=(Color& right);
virtual bool operator==(const Color& right) const; virtual bool operator==(Color& right);
private: private:
unsigned char red; unsigned char red;
......
...@@ -42,27 +42,43 @@ namespace nitrogen { ...@@ -42,27 +42,43 @@ namespace nitrogen {
//font //font
foreground = Color::BLACK; foreground = Color::BLACK;
//graphics //graphics
location = new NPosition<int>(0, 0); cx = 0;
cy = 0;
cw = 0;
ch = 0;
//me_list = new std::list<MouseEvent>(); //me_list = new std::list<MouseEvent>();
parent = nullptr; parent = nullptr;
preferredSize = new NSize<unsigned int>(0, 0); preferredSize = new Rectangle(0, 0);
size = new NSize<unsigned int>(0, 0);
} }
void Component::addMouseListener(MouseListener* m) { Border* Component::getBorder() {
return border;
}
Dimension* Component::getSize() {
Dimension* d = new Dimension(cw, ch);
return d;
} }
void Component::dispatchEvent(NWTEvent* e) { Rectangle* Component::getBounds() {
Rectangle* r = new Rectangle(cx, cy, cw, ch);
return r;
}
int Component::getX() {
return cx;
} }
Color* Component::getBackground() { int Component::getY() {
return background; return cy;
} }
Border* Component::getBorder() { Component* Component::getParent() {
return border; return parent;
}
Graphics* Component::getGraphics() {
return graphics;
} }
nitrogen::nwt::Font* Component::getFont() { nitrogen::nwt::Font* Component::getFont() {
...@@ -77,43 +93,53 @@ namespace nitrogen { ...@@ -77,43 +93,53 @@ namespace nitrogen {
return foreground; return foreground;
} }
Graphics* Component::getGraphics() { Color* Component::getBackground() {
return graphics; return background;
} }
Component* Component::getParent() { Component* Component::getComponentAt(int x, int y) {
return parent; if (getBounds()->contains(x, y)) {
return this;
} }
return nullptr;
NPosition<int>* Component::getLocation() {
return location;
} }
NSize<unsigned int>* Component::getPreferredSize() { Dimension* Component::getPreferredSize() {
return preferredSize; Dimension* d = new Dimension(cw, ch);
return d;
} }
NSize<unsigned int>* Component::getSize() { void Component::setBorder(Border* b) {
return size; border = b;
} }
void Component::paint(Graphics* g) { void Component::setFont(nitrogen::nwt::Font* f) {
font = f;
} }
void Component::paintAll(Graphics* g) { void Component::setForeground(Color* c) {
foreground = c;
} }
void Component::processEvent(NWTEvent* e) { void Component::setBackground(Color* c) {
background = c;
}
void Component::setSize(Dimension* s) {
setSize(s->getWidth(), s->getHeight());
} }
void Component::processMouseEvent(MouseEvent* e) { void Component::setSize(unsigned int width, unsigned int height) {
cw = width;
ch = height;
}
void Component::setLocation(unsigned int x, unsigned int y) {
cx = x;
cy = y;
} }
void Component::removeNotify() { void Component::paint(Graphics* g) {
} }
...@@ -121,35 +147,35 @@ namespace nitrogen { ...@@ -121,35 +147,35 @@ namespace nitrogen {
} }
void Component::setBackground(Color* c) { void Component::paintAll(Graphics* g) {
background = c;
} }
void Component::setBorder(Border* b) { void Component::update(Graphics* g) {
border = b;
} }
void Component::setFont(nitrogen::nwt::Font* f) { void Component::validate() {
font = f;
} }
void Component::setForeground(Color* c) { void Component::removeNotify() {
foreground = c;
} }
void Component::setLocation(NPosition<int>* p) { void Component::addMouseListener(MouseListener* m) {
location = p;
} }
void Component::setSize(NSize<unsigned int>* s) { void Component::dispatchEvent(NWTEvent* e) {
size = s;
} }
void Component::update(Graphics* g) { void Component::processEvent(NWTEvent* e) {
} }
void Component::validate() { void Component::processMouseEvent(MouseEvent* e) {
} }
} }
......
...@@ -36,17 +36,16 @@ ...@@ -36,17 +36,16 @@
#include <ntk.h> #include <ntk.h>
#include <nitrogen/NPosition.h>
#include <nitrogen/NSize.h>
#include <nitrogen/nwt/Border.h> #include <nitrogen/nwt/Border.h>
#include <nitrogen/nwt/Color.h> #include <nitrogen/nwt/Color.h>
#include <nitrogen/nwt/Dimension.h>
#include <nitrogen/nwt/Font.h> #include <nitrogen/nwt/Font.h>
#include <nitrogen/nwt/FontMetrics.h> #include <nitrogen/nwt/FontMetrics.h>
#include <nitrogen/nwt/Graphics.h> #include <nitrogen/nwt/Graphics.h>
#include <nitrogen/nwt/NWTEvent.h>
#include <nitrogen/nwt/MouseEvent.h> #include <nitrogen/nwt/MouseEvent.h>
#include <nitrogen/nwt/MouseListener.h> #include <nitrogen/nwt/MouseListener.h>
#include <nitrogen/nwt/NWTEvent.h>
#include <nitrogen/nwt/Rectangle.h>
#include <list> #include <list>
...@@ -58,25 +57,29 @@ namespace nitrogen { ...@@ -58,25 +57,29 @@ namespace nitrogen {
class MouseEvent; class MouseEvent;
class MouseListener; class MouseListener;
class Component : public NObject { class Component : public Object {
public: public:
virtual Border* getBorder(); virtual Border* getBorder();
virtual NSize<unsigned int>* getSize(); virtual Dimension* getSize();
virtual NPosition<int>* getLocation(); virtual Rectangle* getBounds();
virtual int getX();
virtual int getY();
virtual Component* getParent(); virtual Component* getParent();
virtual Graphics* getGraphics(); virtual Graphics* getGraphics();
virtual nitrogen::nwt::Font* getFont(); virtual nitrogen::nwt::Font* getFont();
virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font* f); virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font* f);
virtual Color* getForeground(); virtual Color* getForeground();
virtual Color* getBackground(); virtual Color* getBackground();
virtual NSize<unsigned int>* getPreferredSize(); virtual Component* getComponentAt(int x, int y);
virtual Dimension* getPreferredSize();
virtual void setBorder(Border* b); virtual void setBorder(Border* b);
virtual void setFont(nitrogen::nwt::Font* f); virtual void setFont(nitrogen::nwt::Font* f);
virtual void setForeground(Color* c); virtual void setForeground(Color* c);
virtual void setBackground(Color* c); virtual void setBackground(Color* c);
virtual void setSize(NSize<unsigned int>* s); virtual void setSize(Dimension* s);
virtual void setLocation(NPosition<int>* p); virtual void setSize(unsigned int width, unsigned int height);
virtual void setLocation(unsigned int x, unsigned int y);
virtual void paint(Graphics *g); virtual void paint(Graphics *g);
virtual void repaint(); virtual void repaint();
virtual void paintAll(Graphics* g); virtual void paintAll(Graphics* g);
...@@ -88,16 +91,18 @@ namespace nitrogen { ...@@ -88,16 +91,18 @@ namespace nitrogen {
virtual void dispatchEvent(NWTEvent* e); virtual void dispatchEvent(NWTEvent* e);
protected: protected:
Component *parent; Component* parent;
Graphics *graphics; Graphics* graphics;
NPosition<int> *location; int cx;
Border *border; int cy;
nitrogen::nwt::Font *font; unsigned int cw;
Color *foreground; unsigned int ch;
Color *background; Border* border;
NSize<unsigned int> *size; nitrogen::nwt::Font* font;
std::list<MouseEvent> *me_list; Color* foreground;
NSize<unsigned int> *preferredSize; Color* background;
std::list<MouseEvent>* me_list;
Rectangle* preferredSize;
Component(); Component();
virtual void processEvent(NWTEvent *e); virtual void processEvent(NWTEvent *e);
......
...@@ -41,12 +41,12 @@ namespace nitrogen { ...@@ -41,12 +41,12 @@ namespace nitrogen {
} }
Component* ComponentEvent::getComponent() const { Component* ComponentEvent::getComponent() {
return (Component*) source; return (Component*) source;
} }
ComponentEvent& ComponentEvent::operator()(Component* comp, int i) const { ComponentEvent& ComponentEvent::operator()(Component& comp, int i) {
ComponentEvent* ce = new ComponentEvent(comp, i); ComponentEvent* ce = new ComponentEvent(&comp, i);
return *ce; return *ce;
} }
} }
......
...@@ -45,9 +45,9 @@ namespace nitrogen { ...@@ -45,9 +45,9 @@ namespace nitrogen {
class ComponentEvent : public NWTEvent { class ComponentEvent : public NWTEvent {
public: public:
ComponentEvent(Component* comp, int i); ComponentEvent(Component* comp, int i);
virtual Component* getComponent() const; virtual Component* getComponent();
virtual ComponentEvent& operator()(Component* comp, int i) const; virtual ComponentEvent& operator()(Component& comp, int i);
private: private:
}; };
......
/*
* 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: Container.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 10:30 AM
*/
#include "Container.h"
namespace nitrogen {
namespace nwt {
Component* Container::add(Component* comp) {
std::vector<Component*>::iterator it;
it = lst->end();
lst->insert(it, comp);
return comp;
}
Component* Container::getComponent(unsigned int n) {
if (lst->size() >= n) {
return nullptr;
}
return (*lst)[n];
}
Component* Container::getComponentAt(int x, int y) {
Component* c;
Rectangle* bounds;
Component* target = this->Component::getComponentAt(x, y);
unsigned int cnt = lst->size();
for (int a = 0; a < cnt; a++) {
c = (*lst)[a];
bounds = c->getBounds();
if (bounds->contains(x, y)) {
target = c;
if ((c = c->getComponentAt(x - bounds->getX(), y = bounds->getY()))) {
target = c;
}
}
}
return target;
}
unsigned int Container::getComponentCount() {
return lst->size();
}
LayoutManager* Container::getLayout() {
return lm;
}
void Container::setLayout(LayoutManager* layout) {
lm = layout;
}
void Container::paintAll(Graphics* g) {
}
void Container::paintComponents(Graphics* g) {
}
void Container::update(Graphics* g) {
}
void Container::validate() {
}
void Container::removeNotify() {
}
Container::Container() {
lst = new std::vector<Component*>();
}
}
}
/*
* 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: Container.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 10:30 AM
*/
#ifndef CONTAINER_H
#define CONTAINER_H
#include <ntk.h>
#include <nitrogen/nwt/Component.h>
#include <nitrogen/nwt/Graphics.h>
#include <nitrogen/nwt/LayoutManager.h>
#include <vector>
namespace nitrogen {
namespace nwt {
class Container : public Component {
public:
virtual Component* add(Component* comp);
virtual Component* getComponent(unsigned int n);
virtual Component* getComponentAt(int x, int y) override;
virtual unsigned int getComponentCount();
virtual LayoutManager* getLayout();
virtual void setLayout(LayoutManager* layout);
virtual void paintAll(Graphics* g) override;
virtual void paintComponents(Graphics* g);
virtual void update(Graphics* g) override;
virtual void validate() override;
virtual void removeNotify() override;
protected:
std::vector<Component*>* lst;
LayoutManager* lm;
Container();
private:
};
}
}
#endif /* CONTAINER_H */
...@@ -46,15 +46,15 @@ namespace nitrogen { ...@@ -46,15 +46,15 @@ namespace nitrogen {
h = height; h = height;
} }
unsigned int Dimension::getHeight() const { unsigned int Dimension::getHeight() {
return h; return h;
} }
unsigned int Dimension::getWitdh() const { unsigned int Dimension::getWidth() {
return w; return w;
} }
Dimension* Dimension::getSize() const { Dimension* Dimension::getSize() {
Dimension* d = new Dimension(w, h); Dimension* d = new Dimension(w, h);
return d; return d;
} }
...@@ -74,7 +74,7 @@ namespace nitrogen { ...@@ -74,7 +74,7 @@ namespace nitrogen {
h = height; h = height;
} }
std::string* Dimension::toString() const { std::string* Dimension::toString() {
std::string* out; std::string* out;
out->append(getTypeName(this)); out->append(getTypeName(this));
...@@ -87,12 +87,12 @@ namespace nitrogen { ...@@ -87,12 +87,12 @@ namespace nitrogen {
return out; return out;
} }
Dimension& Dimension::operator()(unsigned int width, unsigned int height) const { Dimension& Dimension::operator()(unsigned int width, unsigned int height) {
Dimension* d = new Dimension(width, height); Dimension* d = new Dimension(width, height);
return *d; return *d;
} }
Dimension& Dimension::operator=(const Dimension& right) { Dimension& Dimension::operator=(Dimension& right) {
if (*this != right) { if (*this != right) {
w = right.w; w = right.w;
h = right.h; h = right.h;
...@@ -100,7 +100,7 @@ namespace nitrogen { ...@@ -100,7 +100,7 @@ namespace nitrogen {
return *this; return *this;
} }
bool Dimension::operator==(const Dimension& right) const { bool Dimension::operator==(Dimension& right) {
if (w != right.w) { if (w != right.w) {
return false; return false;
} }
......
...@@ -39,21 +39,21 @@ ...@@ -39,21 +39,21 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Dimension : public NObject { class Dimension : public Object {
public: public:
Dimension(); Dimension();
Dimension(unsigned int width, unsigned int height); Dimension(unsigned int width, unsigned int height);
virtual unsigned int getHeight() const; virtual unsigned int getHeight();
virtual unsigned int getWitdh() const; virtual unsigned int getWidth();
virtual Dimension* getSize() const; virtual Dimension* getSize();
virtual void setSize(Dimension* size); virtual void setSize(Dimension* size);
virtual void setSize(unsigned int width, unsigned int height); virtual void setSize(unsigned int width, unsigned int height);
virtual void setSize(double width, double height); virtual void setSize(double width, double height);
virtual std::string* toString() const; virtual std::string* toString() override;
virtual Dimension& operator()(unsigned int width, unsigned int height) const; virtual Dimension& operator()(unsigned int width, unsigned int height);
virtual Dimension& operator=(const Dimension& right); virtual Dimension& operator=(Dimension& right);
virtual bool operator==(const Dimension& right) const; virtual bool operator==(Dimension& right);
protected: protected:
unsigned int w; unsigned int w;
......
...@@ -36,15 +36,15 @@ ...@@ -36,15 +36,15 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
EventObject::EventObject(NObject* object) { EventObject::EventObject(Object* object) {
source = object; source = object;
} }
NObject* EventObject::getSource() { Object* EventObject::getSource() {
return source; return source;
} }
std::string* EventObject::toString() const { std::string* EventObject::toString() {
std::string *out; std::string *out;
out->append(getTypeName(this)); out->append(getTypeName(this));
...@@ -55,19 +55,19 @@ namespace nitrogen { ...@@ -55,19 +55,19 @@ namespace nitrogen {
return out; return out;
} }
EventObject& EventObject::operator()(NObject* object) const { EventObject& EventObject::operator()(Object& object) {
EventObject* eo = new EventObject(object); EventObject* eo = new EventObject(&object);
return *eo; return *eo;
} }
EventObject& EventObject::operator=(const EventObject& right) { EventObject& EventObject::operator=(EventObject& right) {
if (*this != right) { if (*this != right) {
source = right.source; source = right.source;
} }
return *this; return *this;
} }
bool EventObject::operator==(const EventObject& right) const { bool EventObject::operator==(EventObject& right) {
return (source == right.source); return (source == right.source);
} }
......
...@@ -39,18 +39,18 @@ ...@@ -39,18 +39,18 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class EventObject : public NObject { class EventObject : public Object {
public: public:
EventObject(NObject* object); EventObject(Object* object);
virtual NObject* getSource(); virtual Object* getSource();
virtual std::string* toString() const; virtual std::string* toString() override;
virtual EventObject& operator()(NObject* object) const; virtual EventObject& operator()(Object& object);
virtual EventObject& operator=(const EventObject& right); virtual EventObject& operator=(EventObject& right);
virtual bool operator==(const EventObject& right) const; virtual bool operator==(EventObject& right);
protected: protected:
NObject* source; Object* source;
private: private:
}; };
......
...@@ -48,19 +48,19 @@ namespace nitrogen { ...@@ -48,19 +48,19 @@ namespace nitrogen {
style = st; style = st;
} }
std::string* Font::getFontName() const { std::string* Font::getFontName() {
return fontName; return fontName;
} }
int Font::getStyle() const { int Font::getStyle() {
return style; return style;
} }
unsigned int Font::getSize() const { unsigned int Font::getSize() {
return size; return size;
} }
std::string* Font::toString() const { std::string* Font::toString() {
std::string* out; std::string* out;
out->append(getTypeName(*this)); out->append(getTypeName(*this));
...@@ -75,18 +75,18 @@ namespace nitrogen { ...@@ -75,18 +75,18 @@ namespace nitrogen {
return out; return out;
} }
Font& Font::operator()(std::string* fn, int st, unsigned int si) const { Font& Font::operator()(std::string* fn, int st, unsigned int si) {
Font *n = new Font(fn, st, si); Font *n = new Font(fn, st, si);
return *n; return *n;
} }
Font& Font::operator()(std::string& fn, int st, unsigned int si) const { Font& Font::operator()(std::string& fn, int st, unsigned int si) {
Font *n = new Font(fn, st, si); Font *n = new Font(fn, st, si);
return *n; return *n;
} }
Font& Font::operator=(const Font& right) { Font& Font::operator=(Font& right) {
if (this != &right) { if (*this != right) {
*fontName = *right.fontName; *fontName = *right.fontName;
size = right.size; size = right.size;
style = right.style; style = right.style;
...@@ -94,12 +94,12 @@ namespace nitrogen { ...@@ -94,12 +94,12 @@ namespace nitrogen {
return *this; return *this;
} }
/*bool Font::operator!=(const Font& right) const { /*bool Font::operator!=(Font& right) {
return !(*this == right); return !(*this == right);
}// */ }// */
bool Font::operator==(const Font& right) const { bool Font::operator==(Font& right) {
if (*fontName != *right.fontName) { if (*fontName != *(right.fontName)) {
return false; return false;
} }
if (size != right.size) { if (size != right.size) {
......
...@@ -39,21 +39,21 @@ ...@@ -39,21 +39,21 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Font : public NObject { class Font : public Object {
public: public:
Font(std::string*, int, unsigned int); Font(std::string*, int, unsigned int);
Font(std::string&, int, unsigned int); Font(std::string&, int, unsigned int);
virtual std::string* getFontName() const; virtual std::string* getFontName();
virtual int getStyle() const; virtual int getStyle();
virtual unsigned int getSize() const; virtual unsigned int getSize();
virtual std::string* toString() const; virtual std::string* toString() override;
virtual nitrogen::nwt::Font& operator()(std::string*, int, unsigned int) const; virtual nitrogen::nwt::Font& operator()(std::string*, int, unsigned int);
virtual nitrogen::nwt::Font& operator()(std::string&, int, unsigned int) const; virtual nitrogen::nwt::Font& operator()(std::string&, int, unsigned int);
Font& operator=(const nitrogen::nwt::Font& right); Font& operator=(nitrogen::nwt::Font& right);
//bool operator!=(const nitrogen::nwt::Font& right) const; //bool operator!=(nitrogen::nwt::Font& right);
bool operator==(const nitrogen::nwt::Font& right) const; bool operator==(nitrogen::nwt::Font& right);
protected: protected:
std::string* fontName; std::string* fontName;
......
...@@ -47,23 +47,23 @@ namespace nitrogen { ...@@ -47,23 +47,23 @@ namespace nitrogen {
font_info = XLoadQueryFont(disp, f->getFontName()->c_str()); font_info = XLoadQueryFont(disp, f->getFontName()->c_str());
} }
unsigned int FontMetrics::getAscent() const { unsigned int FontMetrics::getAscent() {
return font_info->max_bounds.ascent; return font_info->max_bounds.ascent;
} }
unsigned int FontMetrics::getHeight() const { unsigned int FontMetrics::getHeight() {
return font_info->max_bounds.ascent + font_info->max_bounds.descent; return font_info->max_bounds.ascent + font_info->max_bounds.descent;
} }
unsigned int FontMetrics::stringWidth(std::string* str) const { unsigned int FontMetrics::stringWidth(std::string* str) {
return XTextWidth(font_info, str->c_str(), str->length()); return XTextWidth(font_info, str->c_str(), str->length());
} }
unsigned int FontMetrics::stringWidth(std::string& str) const { unsigned int FontMetrics::stringWidth(std::string& str) {
return stringWidth(&str); return stringWidth(&str);
} }
std::string* FontMetrics::toString() const { std::string* FontMetrics::toString() {
std::string *out; std::string *out;
out->append(getTypeName(this)); out->append(getTypeName(this));
...@@ -74,23 +74,23 @@ namespace nitrogen { ...@@ -74,23 +74,23 @@ namespace nitrogen {
return out; return out;
} }
FontMetrics& FontMetrics::operator()(nitrogen::nwt::Font* f) const { FontMetrics& FontMetrics::operator()(nitrogen::nwt::Font& f) {
FontMetrics *n = new FontMetrics(f); FontMetrics *n = new FontMetrics(&f);
return *n; return *n;
} }
FontMetrics& FontMetrics::operator=(const FontMetrics& right) { FontMetrics& FontMetrics::operator=(FontMetrics& right) {
if (*this != right) { if (*this != right) {
font_info = right.font_info; font_info = right.font_info;
} }
return *this; return *this;
} }
/*bool FontMetrics::operator!=(const FontMetrics& right) const { /*bool FontMetrics::operator!=(FontMetrics& right) {
return !(*this == right); return !(*this == right);
}// */ }// */
bool FontMetrics::operator==(const FontMetrics& right) const { bool FontMetrics::operator==(FontMetrics& right) {
return (font_info == right.font_info); return (font_info == right.font_info);
} }
} }
......
...@@ -44,19 +44,19 @@ namespace nitrogen { ...@@ -44,19 +44,19 @@ namespace nitrogen {
namespace nwt { namespace nwt {
class Font; class Font;
class FontMetrics : public NObject { class FontMetrics : public Object {
public: public:
FontMetrics(nitrogen::nwt::Font* f); FontMetrics(nitrogen::nwt::Font* f);
virtual unsigned int getAscent() const; virtual unsigned int getAscent();
virtual unsigned int getHeight() const; virtual unsigned int getHeight();
virtual unsigned int stringWidth(std::string* str) const; virtual unsigned int stringWidth(std::string* str);
virtual unsigned int stringWidth(std::string& str) const; virtual unsigned int stringWidth(std::string& str);
virtual std::string* toString() const; virtual std::string* toString() override;
FontMetrics& operator()(nitrogen::nwt::Font* f) const; FontMetrics& operator()(nitrogen::nwt::Font& f);
FontMetrics& operator=(const FontMetrics& right); FontMetrics& operator=(FontMetrics& right);
//bool operator!=(const FontMetrics& right) const; //bool operator!=(FontMetrics& right);
bool operator==(const FontMetrics& right) const; bool operator==(FontMetrics& right);
private: private:
XFontStruct* font_info; XFontStruct* font_info;
......
...@@ -36,44 +36,40 @@ ...@@ -36,44 +36,40 @@
#include <ntk.h> #include <ntk.h>
#include <nitrogen/NPosition.h>
#include <nitrogen/NSize.h>
#include <nitrogen/nwt/Color.h>
#include <nitrogen/nwt/Font.h>
#include <nitrogen/nwt/FontMetrics.h>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Color;
class Font;
class FontMetrics;
class Graphics : public NObject { class Graphics : public Object {
public: public:
virtual void drawPoint(NPosition<int>* point) = 0; virtual void drawPoint(int x, int y) = 0;
virtual void drawLine(NPosition<int>* start, NPosition<int>* end) = 0; virtual void drawLine(int sx, int xy, int dx, int dy) = 0;
virtual void drawRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void drawRect(int x, int y, unsigned int width, unsigned int height) = 0;
virtual void fillRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void fillRect(int x, int y, unsigned int width, unsigned int height) = 0;
virtual void fill3DRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void fill3DRect(int x, int y, unsigned int width, unsigned int height) = 0;
virtual void draw3DRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void draw3DRect(int x, int y, unsigned int width, unsigned int height, bool = false) = 0;
virtual void drawString(std::string* str, NPosition<int>* point) = 0; virtual void drawString(std::string* str, int x, int y) = 0;
virtual void drawString(std::string& str, NPosition<int>* point) = 0; virtual void drawString(std::string& str, int x, int y) = 0;
virtual Color* getColor() const = 0; virtual Color* getColor() const = 0;
virtual nitrogen::nwt::Font* getFont() const = 0; virtual nitrogen::nwt::Font* getFont() const = 0;
virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font* f) const = 0; virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font* f) const = 0;
virtual FontMetrics* getFontMetrics() const = 0; virtual FontMetrics* getFontMetrics() const = 0;
virtual void setClip(NPosition<int>* start, NSize<unsigned int> size) = 0; virtual void setClip(int x, int y, unsigned int width, unsigned int height) = 0;
virtual void setColor(Color* c) = 0; virtual void setColor(Color* c) = 0;
virtual void setFont(nitrogen::nwt::Font* f) = 0; virtual void setFont(nitrogen::nwt::Font* f) = 0;
virtual void translate(NPosition<int>* pos) = 0; virtual void translate(int x, int y) = 0;
virtual std::string* toString() const = 0; virtual std::string* toString() const = 0;
virtual Graphics& operator()() const = 0; virtual Graphics& operator()() const = 0;
virtual Graphics& operator=(const Graphics& right) = 0; virtual Graphics& operator=(Graphics& right) = 0;
//virtual bool operator!=(const Graphics& right) const = 0; //virtual bool operator!=(Graphics& right) const = 0;
virtual bool operator==(const Graphics& right) const = 0; virtual bool operator==(Graphics& right) const = 0;
protected: protected:
static nitrogen::nwt::Font* ntk_font; static nitrogen::nwt::Font* ntk_font;
......
...@@ -40,11 +40,11 @@ namespace nitrogen { ...@@ -40,11 +40,11 @@ namespace nitrogen {
time = std::time(0); time = std::time(0);
} }
long InputEvent::getWhen() const { long InputEvent::getWhen() {
return time; return time;
} }
InputEvent& InputEvent::operator=(const InputEvent& right) { InputEvent& InputEvent::operator=(InputEvent& right) {
if (*this != right) { if (*this != right) {
consumed = right.consumed; consumed = right.consumed;
id = right.id; id = right.id;
...@@ -54,7 +54,7 @@ namespace nitrogen { ...@@ -54,7 +54,7 @@ namespace nitrogen {
return *this; return *this;
} }
bool InputEvent::operator==(const InputEvent& right) const { bool InputEvent::operator==(InputEvent& right) {
if (time != right.time) { if (time != right.time) {
return false; return false;
} }
......
...@@ -47,10 +47,10 @@ namespace nitrogen { ...@@ -47,10 +47,10 @@ namespace nitrogen {
class InputEvent : public ComponentEvent { class InputEvent : public ComponentEvent {
public: public:
InputEvent(Component* comp, int i); InputEvent(Component* comp, int i);
virtual long getWhen() const; virtual long getWhen();
virtual InputEvent& operator=(const InputEvent& right); virtual InputEvent& operator=(InputEvent& right);
virtual bool operator==(const InputEvent& right) const; virtual bool operator==(InputEvent& right);
protected: protected:
time_t time; time_t time;
......
...@@ -43,23 +43,23 @@ namespace nitrogen { ...@@ -43,23 +43,23 @@ namespace nitrogen {
r = right; r = right;
} }
unsigned int Insets::getBottom() const { unsigned int Insets::getBottom() {
return b; return b;
} }
unsigned int Insets::getLeft() const { unsigned int Insets::getLeft() {
return l; return l;
} }
unsigned int Insets::getRight() const { unsigned int Insets::getRight() {
return r; return r;
} }
unsigned int Insets::getTop() const { unsigned int Insets::getTop() {
return t; return t;
} }
std::string* Insets::toString() const { std::string* Insets::toString() {
std::string *out; std::string *out;
out->append(getTypeName(this)); out->append(getTypeName(this));
...@@ -76,12 +76,12 @@ namespace nitrogen { ...@@ -76,12 +76,12 @@ namespace nitrogen {
return out; return out;
} }
Insets& Insets::operator()(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right) const { Insets& Insets::operator()(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right) {
Insets *i = new Insets(top, left, bottom, right); Insets *i = new Insets(top, left, bottom, right);
return *i; return *i;
} }
Insets& Insets::operator=(const Insets& right) { Insets& Insets::operator=(Insets& right) {
if (*this != right) { if (*this != right) {
t = right.t; t = right.t;
l = right.l; l = right.l;
...@@ -91,11 +91,11 @@ namespace nitrogen { ...@@ -91,11 +91,11 @@ namespace nitrogen {
return *this; return *this;
} }
/*bool Insets::operator==(const Insets& right) const { /*bool Insets::operator==(Insets& right) {
return !(*this == right); return !(*this == right);
} // */ } // */
bool Insets::operator==(const Insets& right) const { bool Insets::operator==(Insets& right) {
if (t != right.t) { if (t != right.t) {
return false; return false;
} }
......
...@@ -39,19 +39,19 @@ ...@@ -39,19 +39,19 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Insets : public NObject { class Insets : public Object {
public: public:
Insets(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right); Insets(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right);
virtual unsigned int getTop() const; virtual unsigned int getTop();
virtual unsigned int getLeft() const; virtual unsigned int getLeft();
virtual unsigned int getBottom() const; virtual unsigned int getBottom();
virtual unsigned int getRight() const; virtual unsigned int getRight();
virtual std::string* toString() const; virtual std::string* toString() override;
virtual Insets& operator()(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right) const; virtual Insets& operator()(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right);
virtual Insets& operator=(const Insets& right); virtual Insets& operator=(Insets& right);
//virtual bool operator!=(const Insets& right) const; //virtual bool operator!=(Insets& right);
virtual bool operator==(const Insets& right) const; virtual bool operator==(Insets& right);
protected: protected:
unsigned int t; unsigned int t;
......
/*
* 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: LayoutManager.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 10:40 AM
*/
#include "LayoutManager.h"
namespace nitrogen {
namespace nwt {
LayoutManager::LayoutManager() {
}
}
}
/*
* 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: LayoutManager.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 10:40 AM
*/
#ifndef LAYOUTMANAGER_H
#define LAYOUTMANAGER_H
#include <ntk.h>
namespace nitrogen {
namespace nwt {
class Component;
class Container;
class Dimension;
class LayoutManager : public Object {
public:
LayoutManager();
virtual void addLayoutComponent(std::string*, Component* comp) = 0;
virtual void addLayoutComponent(std::string&, Component* comp) = 0;
virtual void removeLayoutComponent(Component* comp) = 0;
virtual Dimension minimumLayoutSize(Container* cont) = 0;
virtual Dimension preferredLayoutSize(Container* cont) = 0;
virtual void layoutContainer(Container* cont) = 0;
private:
};
}
}
#endif /* LAYOUTMANAGER_H */
...@@ -41,27 +41,27 @@ namespace nitrogen { ...@@ -41,27 +41,27 @@ namespace nitrogen {
} }
int MouseEvent::getModifiers() const { int MouseEvent::getModifiers() {
return modifiers; return modifiers;
} }
int MouseEvent::getX() const { int MouseEvent::getX() {
return mx; return mx;
} }
int MouseEvent::getY() const { int MouseEvent::getY() {
return my; return my;
} }
int MouseEvent::getClickCount() const { int MouseEvent::getClickCount() {
return clickCount; return clickCount;
} }
bool MouseEvent::isPopupTrigger() const { bool MouseEvent::isPopupTrigger() {
return popupTrigger; return popupTrigger;
} }
std::string* MouseEvent::toString() const { std::string* MouseEvent::toString() {
std::string *out; std::string *out;
out->append(getTypeName(this)); out->append(getTypeName(this));
...@@ -87,12 +87,12 @@ namespace nitrogen { ...@@ -87,12 +87,12 @@ namespace nitrogen {
} }
MouseEvent& MouseEvent::operator() MouseEvent& MouseEvent::operator()
(Component* comp, int i, long when, int mods, int x, int y, int clicks, bool popup) const { (Component* comp, int i, long when, int mods, int x, int y, int clicks, bool popup) {
MouseEvent* me = new MouseEvent(comp, i, when, mods, x, y, clicks, popup); MouseEvent* me = new MouseEvent(comp, i, when, mods, x, y, clicks, popup);
return *me; return *me;
} }
bool MouseEvent::operator==(const MouseEvent& right) const { bool MouseEvent::operator==(MouseEvent& right) {
if (modifiers != right.modifiers) { if (modifiers != right.modifiers) {
return false; return false;
} }
......
...@@ -47,15 +47,15 @@ namespace nitrogen { ...@@ -47,15 +47,15 @@ namespace nitrogen {
class MouseEvent : public InputEvent { class MouseEvent : public InputEvent {
public: public:
MouseEvent(Component* comp, int i, long when, int mods, int x, int y, int clicks, bool popupTrigger = false); MouseEvent(Component* comp, int i, long when, int mods, int x, int y, int clicks, bool popupTrigger = false);
virtual int getModifiers() const; virtual int getModifiers();
virtual int getX() const; virtual int getX();
virtual int getY() const; virtual int getY();
virtual int getClickCount() const; virtual int getClickCount();
virtual bool isPopupTrigger() const; virtual bool isPopupTrigger();
virtual std::string* toString() const; virtual std::string* toString() override;
virtual MouseEvent& operator()(Component* comp, int i, long when, int mods, int x, int y, int clicks, bool popup = false) const; virtual MouseEvent& operator()(Component* comp, int i, long when, int mods, int x, int y, int clicks, bool popup = false);
bool operator==(const MouseEvent& right) const; bool operator==(MouseEvent& right);
protected: protected:
int modifiers; int modifiers;
......
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
#include <ntk.h> #include <ntk.h>
#include <nitrogen/nwt/EventListener.h> #include <nitrogen/nwt/EventListener.h>
#include <nitrogen/nwt/MouseEvent.h>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class MouseEvent;
class MouseListener : public EventListener { class MouseListener : public EventListener {
public: public:
......
...@@ -36,18 +36,18 @@ ...@@ -36,18 +36,18 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
NWTEvent::NWTEvent(NObject* object, int i) : EventObject((NObject*) object) { NWTEvent::NWTEvent(Object* object, int i) : EventObject((Object*) object) {
//EventObject((NObject) * object); //EventObject((Object) * object);
//source = object; //source = object;
id = i; id = i;
consumed = false; consumed = false;
} }
int NWTEvent::getId() const { int NWTEvent::getId() {
return id; return id;
} }
bool NWTEvent::isConsumed() const { bool NWTEvent::isConsumed() {
return consumed; return consumed;
} }
...@@ -55,7 +55,7 @@ namespace nitrogen { ...@@ -55,7 +55,7 @@ namespace nitrogen {
consumed = true; consumed = true;
} }
std::string* NWTEvent::toString() const { std::string* NWTEvent::toString() {
std::string *out; std::string *out;
out->append(getTypeName(this)); out->append(getTypeName(this));
...@@ -68,12 +68,12 @@ namespace nitrogen { ...@@ -68,12 +68,12 @@ namespace nitrogen {
return out; return out;
} }
NWTEvent& NWTEvent::operator()(NObject* object, int i) const { NWTEvent& NWTEvent::operator()(Object& object, int i) {
NWTEvent* e = new NWTEvent(object, i); NWTEvent* e = new NWTEvent(&object, i);
return *e; return *e;
} }
NWTEvent& NWTEvent::operator=(const NWTEvent& right) { NWTEvent& NWTEvent::operator=(NWTEvent& right) {
if (*this != right) { if (*this != right) {
source = right.source; source = right.source;
id = right.id; id = right.id;
...@@ -82,7 +82,7 @@ namespace nitrogen { ...@@ -82,7 +82,7 @@ namespace nitrogen {
return *this; return *this;
} }
bool NWTEvent::operator==(const NWTEvent& right) const { bool NWTEvent::operator==(NWTEvent& right) {
if (source != right.source) { if (source != right.source) {
return false; return false;
} }
......
...@@ -42,15 +42,15 @@ namespace nitrogen { ...@@ -42,15 +42,15 @@ namespace nitrogen {
class NWTEvent : public EventObject { class NWTEvent : public EventObject {
public: public:
NWTEvent(NObject* object, int i); NWTEvent(Object* object, int i);
virtual int getId() const; virtual int getId();
virtual bool isConsumed() const; virtual bool isConsumed();
virtual void consume(); virtual void consume();
virtual std::string* toString() const; virtual std::string* toString() override;
virtual NWTEvent& operator()(NObject* object, int i) const; virtual NWTEvent& operator()(Object& object, int i);
virtual NWTEvent& operator=(const NWTEvent& right); virtual NWTEvent& operator=(NWTEvent& right);
virtual bool operator==(const NWTEvent& right) const; virtual bool operator==(NWTEvent& right);
protected: protected:
int id; int id;
......
...@@ -46,16 +46,16 @@ namespace nitrogen { ...@@ -46,16 +46,16 @@ namespace nitrogen {
py = y; py = y;
} }
Point* Point::getLocation() const { Point* Point::getLocation() {
Point *p = new Point(px, py); Point *p = new Point(px, py);
return p; return p;
} }
int Point::getX() const { int Point::getX() {
return px; return px;
} }
int Point::getY() const { int Point::getY() {
return py; return py;
} }
...@@ -77,7 +77,7 @@ namespace nitrogen { ...@@ -77,7 +77,7 @@ namespace nitrogen {
py += y; py += y;
} }
std::string* Point::toString() const { std::string* Point::toString() {
std::string* out; std::string* out;
out->append(getTypeName(this)); out->append(getTypeName(this));
...@@ -90,19 +90,19 @@ namespace nitrogen { ...@@ -90,19 +90,19 @@ namespace nitrogen {
return out; return out;
} }
Point& Point::operator()(int x, int y) const { Point& Point::operator()(int x, int y) {
Point* p = new Point(x, y); Point* p = new Point(x, y);
return *p; return *p;
} }
Point& Point::operator=(const Point& right) { Point& Point::operator=(Point& right) {
if (*this != right) { if (*this != right) {
move(right.px, right.py); move(right.px, right.py);
} }
return *this; return *this;
} }
bool Point::operator==(const Point& right) const { bool Point::operator==(Point& right) {
if (px != right.px) { if (px != right.px) {
return false; return false;
} }
......
...@@ -39,22 +39,22 @@ ...@@ -39,22 +39,22 @@
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Point : public NObject { class Point : public Object {
public: public:
Point(); Point();
Point(int x, int y); Point(int x, int y);
virtual Point* getLocation() const; virtual Point* getLocation();
virtual int getX() const; virtual int getX();
virtual int getY() const; virtual int getY();
virtual void move(int x, int y); virtual void move(int x, int y);
virtual void setLocation(int x, int y); virtual void setLocation(int x, int y);
virtual void setLocation(Point* loc); virtual void setLocation(Point* loc);
virtual void translate(int x, int y); virtual void translate(int x, int y);
virtual std::string* toString() const; virtual std::string* toString() override;
virtual Point& operator()(int x, int y) const; virtual Point& operator()(int x, int y);
virtual Point& operator=(const Point& right); virtual Point& operator=(Point& right);
virtual bool operator==(const Point& right) const; virtual bool operator==(Point& right);
protected: protected:
int px; int px;
......
/*
* 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: Rectangle.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 11:24 AM
*/
#include "Rectangle.h"
namespace nitrogen {
namespace nwt {
Rectangle::Rectangle(unsigned int width, unsigned int height) {
rx = 0;
ry = 0;
rw = width;
rh = height;
}
Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height) {
rx = x;
ry = y;
rw = width;
rh = height;
}
bool Rectangle::contains(int x, int y) {
if (rx <= x && x <= rw) {
if (ry <= y & y <= rh) {
return true;
}
}
return false;
}
int Rectangle::getX() {
return rx;
}
int Rectangle::getY() {
return ry;
}
int Rectangle::getWidth() {
return rw;
}
int Rectangle::getHeight() {
return rh;
}
std::string* Rectangle::toString() {
std::string* out;
out->append(getTypeName(this));
out->append("(");
out->append(std::to_string(rx));
out->append(",");
out->append(std::to_string(ry));
out->append(",");
out->append(std::to_string(rw));
out->append(",");
out->append(std::to_string(rh));
out->append(")");
return out;
}
Rectangle& Rectangle::operator()(unsigned int width, unsigned int height) {
Rectangle* r = new Rectangle(width, height);
return *r;
}
Rectangle& Rectangle::operator()(int x, int y, unsigned int width, unsigned int height) {
Rectangle* r = new Rectangle(x, y, width, height);
return *r;
}
Rectangle& Rectangle::operator=(Rectangle& right) {
if (*this != right) {
rx = right.rx;
ry = right.ry;
rw = right.rw;
rh = right.rh;
}
return *this;
}
bool Rectangle::operator==(Rectangle& right) {
if (rx != right.rx) {
return false;
}
else if (ry != right.ry) {
return false;
}
else if (rw != right.rw) {
return false;
}
else if (rh != right.rh) {
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: Rectangle.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 11:24 AM
*/
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include <ntk.h>
namespace nitrogen {
namespace nwt {
class Rectangle : public Object {
public:
Rectangle(unsigned int width, unsigned int height);
Rectangle(int x, int y, unsigned int width, unsigned int height);
bool contains(int x, int y);
int getX();
int getY();
int getWidth();
int getHeight();
virtual std::string* toString() override;
Rectangle& operator()(unsigned int width, unsigned int height);
Rectangle& operator()(int x, int y, unsigned int width, unsigned int height);
Rectangle& operator=(Rectangle& right);
bool operator==(Rectangle& right);
protected:
unsigned int rw;
unsigned int rh;
int rx;
int ry;
private:
};
}
}
#endif /* RECTANGLE_H */
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
#define NTK_VERSION_TWEAK 0 #define NTK_VERSION_TWEAK 0
#define NTK_VERSION "1.0.0.0" #define NTK_VERSION "1.0.0.0"
#ifndef NOBJECT_H #ifndef OBJECT_H
#include <nitrogen/NObject.h> #include <nitrogen/Object.h>
#endif #endif
namespace nitrogen { namespace nitrogen {
......
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
#define NTK_VERSION_TWEAK @Nitrogen_VERSION_TWEAK@ #define NTK_VERSION_TWEAK @Nitrogen_VERSION_TWEAK@
#define NTK_VERSION "@Nitrogen_VERSION_MAJOR@.@Nitrogen_VERSION_MINOR@.@Nitrogen_VERSION_PATCH@.@Nitrogen_VERSION_TWEAK@" #define NTK_VERSION "@Nitrogen_VERSION_MAJOR@.@Nitrogen_VERSION_MINOR@.@Nitrogen_VERSION_PATCH@.@Nitrogen_VERSION_TWEAK@"
#ifndef NOBJECT_H #ifndef OBJECT_H
#include <nitrogen/NObject.h> #include <nitrogen/Object.h>
#endif #endif
namespace nitrogen { namespace nitrogen {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!