Commit d408b565 by Jessica Hawkwell

added Insets and Border for #1, restructured libntk, arranged includes

1 parent 6908dbda
...@@ -53,6 +53,7 @@ build ...@@ -53,6 +53,7 @@ build
### KDevelop4 ### ### KDevelop4 ###
*.kdev4 *.kdev4
.kdev4/ .kdev4/
*.kateproject
### NetBeans ### ### NetBeans ###
nbproject/ nbproject/
......
...@@ -9,7 +9,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/bin) ...@@ -9,7 +9,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib)
include_directories("/usr/local/include") if (EXISTS /usr/local/include)
include_directories(/usr/local/include)
endif()
add_subdirectory(src/libnde) add_subdirectory(src/libnde)
add_subdirectory(src/libntk) add_subdirectory(src/libntk)
......
...@@ -23,18 +23,19 @@ For example: ...@@ -23,18 +23,19 @@ For example:
None yet. :crying_cat_face: None yet. :crying_cat_face:
--- ---
## Requirements ## Runtime Requirements
+ [FreeBSD](http://freebsd.org/) `>= 10.1` (tested using FreeBSD 11) + [FreeBSD](http://freebsd.org/) `>= 10.1` (tested using FreeBSD `11.1-RELEASE`)
+ [`x11/libX11`](https://www.freshports.org/x11/libX11/) + [`x11/libX11`](https://www.freshports.org/x11/libX11/)
+ [`x11/xproto`](https://www.freshports.org/x11/xproto/) + [`x11/xproto`](https://www.freshports.org/x11/xproto/)
+ [`devel/cmake`](https://www.freshports.org/devel/cmake/)
+ [`devel/cmake-modules`](https://www.freshports.org/devel/cmake-modules/) (if this port is not available, then it has been merged with [`devel/cmake`](https://www.freshports.org/devel/cmake/))
+ [`devel/boehm-gc`](https://www.freshports.org/devel/boehm-gc/) + [`devel/boehm-gc`](https://www.freshports.org/devel/boehm-gc/)
+ [`devel/boehm-gc-threaded`](https://www.freshports.org/devel/boehm-gc-threaded/) + [`devel/boehm-gc-threaded`](https://www.freshports.org/devel/boehm-gc-threaded/)
--- ---
## Misc Tooling ## Tooling
+ [`devel/git`](https://www.freshports.org/devel/git/) **or** [`devel/git-gui`](https://www.freshports.org/devel/git-gui/) + [`devel/git`](https://www.freshports.org/devel/git/) **or** [`devel/git-gui`](https://www.freshports.org/devel/git-gui/) (these ports are mutually exclusive, you can only have one of them installed)
+ [`devel/cmake`](https://www.freshports.org/devel/cmake/)
+ [`devel/cmake-modules`](https://www.freshports.org/devel/cmake-modules/) (if this port is not available, then it has been merged with [`devel/cmake`](https://www.freshports.org/devel/cmake/))
+ CLang from the base system (`4.0.0`) is all that's required to build. No need for extra compilers from Ports or `pkg`.
--- ---
## Building the NDE ## Building the NDE
...@@ -60,3 +61,7 @@ $ make ...@@ -60,3 +61,7 @@ $ make
```console ```console
$ ./test_Nitrogen.sh $ ./test_Nitrogen.sh
``` ```
---
## Notes
**I do not recommend using NitroWin as a primary window manager. It is still in very early development.**
#include "NitroWin.h" #include "NitroWin.h"
#include <Color.h> #include <nitrogen/nwt/Color.h>
#include <NObject.h> #include <nitrogen/NObject.h>
#include "NWManager.h" #include "NWManager.h"
#include <iostream> #include <iostream>
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
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::Color no = nitrogen::Color(255, 255, 255); nitrogen::nwt::Color no = nitrogen::nwt::Color(255, 255, 255);
std::cout << "Color: "; std::cout << "Color: ";
std::cout << no std::cout << no
<< std::endl; << std::endl;
......
...@@ -4,19 +4,22 @@ configure_file(${PROJECT_NAME}.h.in ${PROJECT_NAME}.h) ...@@ -4,19 +4,22 @@ configure_file(${PROJECT_NAME}.h.in ${PROJECT_NAME}.h)
find_package(X11) find_package(X11)
find_library(BoehmGC gc-threaded) find_library(BoehmGC gc-threaded)
#include_directories("/usr/local/include")
add_library(${PROJECT_NAME} SHARED ntkMain.cpp add_library(${PROJECT_NAME} SHARED ntkMain.cpp
NObject.cpp nitrogen/NObject.cpp
Color.cpp nitrogen/nwt/Color.cpp
Font.cpp nitrogen/nwt/Font.cpp
FontMetrics.cpp nitrogen/nwt/FontMetrics.cpp
nitrogen/nwt/Graphics.cpp
nitrogen/nwt/Insets.cpp
# nitrogen/nwt/Border.cpp
# nitrogen/nwt/Component.cpp
) )
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/${PROJECT_NAME}) install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/${PROJECT_NAME})
file(GLOB HEADERS "*.h") file(GLOB HEADERS "*.h")
install(FILES ${HEADERS} DESTINATION include/${PROJECT_NAME}) install(FILES ${HEADERS} DESTINATION include/nitrogen/)
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC nde ${BoehmGC}) target_link_libraries(${PROJECT_NAME} LINK_PUBLIC nde ${BoehmGC})
target_include_directories (ntk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories (ntk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
/*
* 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: Border.cpp
* Author: jlhawkwell
*
* Created on March 23, 2018, 1:44 PM
*/
#include "Border.h"
namespace nitrogen {
namespace nwt {
Border::Border() {
}
Border::~Border() {
}
}
}
/*
* 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: Border.h
* Author: jlhawkwell
*
* Created on March 23, 2018, 1:44 PM
*/
#ifndef BORDER_H
#define BORDER_H
#include <ntk.h>
#include <nitrogen/nwt/Component.h>
#include <nitrogen/nwt/Graphics.h>
#include <nitrogen/nwt/Insets.h>
namespace nitrogen {
namespace nwt {
class Border : public NObject {
public:
virtual Insets* getBorderInsets(Component* comp) = 0;
virtual bool isBorderOpaque() = 0;
virtual void paintBorder(Component* comp, Graphics* g, int, int, unsigned int, unsigned int) = 0;
virtual ~Border();
protected:
Border();
private:
};
}
}
#endif /* BORDER_H */
...@@ -34,120 +34,121 @@ ...@@ -34,120 +34,121 @@
#include "Color.h" #include "Color.h"
namespace nitrogen { namespace nitrogen {
namespace nwt {
Color::Color(unsigned int c) {
alpha = 255;
red = ((c & MASK_RED) >> 16);
green = ((c & MASK_GREEN) >> 8);
blue = (c & MASK_BLUE);
}
Color::Color(unsigned int c) { Color::Color(unsigned char r, unsigned char g, unsigned char b) {
alpha = 255; alpha = 255;
red = ((c & MASK_RED) >> 16); red = r;
green = ((c & MASK_GREEN) >> 8); green = g;
blue = (c & MASK_BLUE); blue = b;
} }
Color::Color(unsigned char r, unsigned char g, unsigned char b) { Color::Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
alpha = 255; alpha = a;
red = r; red = r;
green = g; green = g;
blue = b; blue = b;
} }
Color::Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { unsigned char Color::getAlpha() const {
alpha = a; return alpha;
red = r; }
green = g;
blue = b;
}
unsigned char Color::getAlpha() const { unsigned char Color::getBlue() const {
return alpha; return blue;
} }
unsigned char Color::getBlue() const { unsigned char Color::getGreen() const {
return blue; return green;
} }
unsigned char Color::getGreen() const { unsigned int Color::getRGB() const {
return green; return (red << 16) + (green << 8) + blue;
} }
unsigned int Color::getRGB() const { unsigned int Color::getARGB() const {
return (red << 16) + (green << 8) + blue; return (alpha << 24) + getRGB();
} }
unsigned int Color::getARGB() const { unsigned char Color::getRed() const {
return (alpha << 24) + getRGB(); return red;
} }
unsigned char Color::getRed() const { Color::~Color() {
return red; }
}
Color::~Color() { std::string* Color::toString() const {
} std::string *out = new (UseGC) std::string();
std::string t = getTypeName(this);
out->append((char *)t.c_str());
out->append("(");
out->append(std::to_string(alpha));
out->append(",");
out->append(std::to_string(red));
out->append(",");
out->append(std::to_string(green));
out->append(",");
out->append(std::to_string(blue));
out->append(")");
return out;
}
std::string* Color::toString() const { Color& Color::operator()(unsigned int c) const {
std::string *out = new (UseGC) std::string(); Color *nc = new Color(c);
return *nc;
std::string t = getTypeName(this); }
out->append((char *)t.c_str());
out->append("(");
out->append(std::to_string(alpha));
out->append(",");
out->append(std::to_string(red));
out->append(",");
out->append(std::to_string(green));
out->append(",");
out->append(std::to_string(blue));
out->append(")");
return out;
}
Color& Color::operator()(unsigned int c) const { Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b) const {
Color *nc = new Color(c); Color *nc = new Color(r, g, b);
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, unsigned char a) const {
Color *nc = new Color(r, g, b); Color *nc = new Color(r, g, b, a);
return *nc; return *nc;
} }
Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b, unsigned char a) const { Color& Color::operator=(const Color& right) {
Color *nc = new Color(r, g, b, a); if (this != &right) {
return *nc; alpha = right.getAlpha();
} red = right.getRed();
green = right.getGreen();
blue = right.getBlue();
}
return *this;
}
Color& Color::operator=(const Color& right) { bool Color::operator!=(const Color& right) const {
if (this != &right) { return !(*this == right);
alpha = right.getAlpha();
red = right.getRed();
green = right.getGreen();
blue = right.getBlue();
} }
return *this;
}
bool Color::operator!=(const Color& right) const { bool Color::operator==(const Color& right) const {
return !(*this == right); return (getARGB() == right.getARGB());
} }
bool Color::operator==(const Color& right) const { Color* BLACK = new Color(0, 0, 0);
return (getARGB() == right.getARGB()); Color* RED = new Color(128, 0, 0);
Color* GREEN = new Color(0, 128, 0);
Color* YELLOW = new Color(128, 128, 0);
Color* BLUE = new Color(0, 0, 128);
Color* MAGENTA = new Color(128, 0, 128);
Color* CYAN = new Color(0, 128, 128);
Color* WHITE = new Color(192, 192, 192);
Color* BRIGHT_BLACK = new Color(128, 128, 128);
Color* BRIGHT_RED = new Color(255, 0, 0);
Color* BRIGHT_GREEN = new Color(0, 255, 0);
Color* BRIGHT_YELLOW = new Color(255, 255, 0);
Color* BRIGHT_BLUE = new Color(0, 0, 255);
Color* BRIGHT_MAGENTA = new Color(255, 0, 255);
Color* BRIGHT_CYAN = new Color(0, 255, 255);
Color* BRIGHT_WHITE = new Color(255, 255, 255);
} }
Color* BLACK = new Color(0, 0, 0);
Color* RED = new Color(128, 0, 0);
Color* GREEN = new Color(0, 128, 0);
Color* YELLOW = new Color(128, 128, 0);
Color* BLUE = new Color(0, 0, 128);
Color* MAGENTA = new Color(128, 0, 128);
Color* CYAN = new Color(0, 128, 128);
Color* WHITE = new Color(192, 192, 192);
Color* BRIGHT_BLACK = new Color(128, 128, 128);
Color* BRIGHT_RED = new Color(255, 0, 0);
Color* BRIGHT_GREEN = new Color(0, 255, 0);
Color* BRIGHT_YELLOW = new Color(255, 255, 0);
Color* BRIGHT_BLUE = new Color(0, 0, 255);
Color* BRIGHT_MAGENTA = new Color(255, 0, 255);
Color* BRIGHT_CYAN = new Color(0, 255, 255);
Color* BRIGHT_WHITE = new Color(255, 255, 255);
} }
...@@ -37,57 +37,59 @@ ...@@ -37,57 +37,59 @@
#include <ntk.h> #include <ntk.h>
namespace nitrogen { namespace nitrogen {
class Color : public NObject { namespace nwt {
public: class Color : public NObject {
static const unsigned int MASK_ALPHA = 0xff000000; public:
static const unsigned int MASK_RED = 0x00ff0000; static const unsigned int MASK_ALPHA = 0xff000000;
static const unsigned int MASK_GREEN = 0x0000ff00; static const unsigned int MASK_RED = 0x00ff0000;
static const unsigned int MASK_BLUE = 0x000000ff; static const unsigned int MASK_GREEN = 0x0000ff00;
static const unsigned int MASK_BLUE = 0x000000ff;
static Color* BLACK; static Color* BLACK;
static Color* RED; static Color* RED;
static Color* GREEN; static Color* GREEN;
static Color* YELLOW; static Color* YELLOW;
static Color* BLUE; static Color* BLUE;
static Color* MAGENTA; static Color* MAGENTA;
static Color* CYAN; static Color* CYAN;
static Color* WHITE; static Color* WHITE;
static Color* BRIGHT_BLACK; static Color* BRIGHT_BLACK;
static Color* BRIGHT_RED; static Color* BRIGHT_RED;
static Color* BRIGHT_GREEN; static Color* BRIGHT_GREEN;
static Color* BRIGHT_YELLOW; static Color* BRIGHT_YELLOW;
static Color* BRIGHT_BLUE; static Color* BRIGHT_BLUE;
static Color* BRIGHT_MAGENTA; static Color* BRIGHT_MAGENTA;
static Color* BRIGHT_CYAN; static Color* BRIGHT_CYAN;
static Color* BRIGHT_WHITE; static Color* BRIGHT_WHITE;
Color(unsigned int c); Color(unsigned int c);
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() const;
unsigned char getRed() const; unsigned char getRed() const;
unsigned char getGreen() const; unsigned char getGreen() const;
unsigned char getBlue() const; unsigned char getBlue() const;
unsigned int getRGB() const; unsigned int getRGB() const;
unsigned int getARGB() const; unsigned int getARGB() const;
virtual ~Color(); virtual ~Color();
virtual std::string* toString() const; virtual std::string* toString() const;
virtual Color& operator()(unsigned int c) const; virtual Color& operator()(unsigned int c) const;
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) const;
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) const;
virtual Color& operator=(const Color& right); virtual Color& operator=(const Color& right);
virtual bool operator!=(const Color& right) const; virtual bool operator!=(const Color& right) const;
virtual bool operator==(const Color& right) const; virtual bool operator==(const Color& right) const;
private: private:
unsigned char red; unsigned char red;
unsigned char green; unsigned char green;
unsigned char blue; unsigned char blue;
unsigned char alpha; unsigned char alpha;
}; };
}
} }
#endif /* COLOR_H */ #endif /* COLOR_H */
......
...@@ -34,127 +34,128 @@ ...@@ -34,127 +34,128 @@
#include "Component.h" #include "Component.h"
namespace nitrogen { namespace nitrogen {
namespace nwt {
Component::Component() {
background = Color::BRIGHT_BLACK;
//border
//font
foreground = Color::BLACK;
//graphics
location = new NPosition<int>(0, 0);
//me_list = new std::list<MouseEvent>();
parent = nullptr;
preferredSize = new NSize<unsigned int>(0, 0);
size = new NSize<unsigned int>(0, 0);
}
Component::Component() { void Component::addMouseListener(MouseListener* m) {
background = Color::BRIGHT_BLACK;
//border
//font
foreground = Color::BLACK;
//graphics
location = new NPosition<int>(0, 0);
//me_list = new std::list<MouseEvent>();
parent = nullptr;
preferredSize = new NSize<unsigned int>(0, 0);
size = new NSize<unsigned int>(0, 0);
}
void Component::addMouseListener(MouseListener* m) { }
} void Component::dispatchEvent(Event* e) {
void Component::dispatchEvent(Event* e) { }
} Color* Component::getBackground() {
return background;
}
Color* Component::getBackground() { Border* Component::getBorder() {
return background; return border;
} }
Border* Component::getBorder() { nitrogen::Font* Component::getFont() {
return border; return font;
} }
nitrogen::Font* Component::getFont() {
return font;
}
FontMetrics* Component::getFontMetrics(nitrogen::Font* f) { FontMetrics* Component::getFontMetrics(nitrogen::Font* f) {
} }
Color* Component::getForeground() { Color* Component::getForeground() {
return foreground; return foreground;
} }
Graphics* Component::getGraphics() { Graphics* Component::getGraphics() {
return graphics; return graphics;
} }
Component* Component::getParent() { Component* Component::getParent() {
return parent; return parent;
} }
NPosition<int>* Component::getLocation() { NPosition<int>* Component::getLocation() {
return location; return location;
} }
NSize<unsigned int>* Component::getPreferredSize() { NSize<unsigned int>* Component::getPreferredSize() {
return preferredSize; return preferredSize;
} }
NSize<unsigned int>* Component::getSize() { NSize<unsigned int>* Component::getSize() {
return size; return size;
} }
void Component::paint(Graphics* g) { void Component::paint(Graphics* g) {
} }
void Component::paintAll(Graphics* g) { void Component::paintAll(Graphics* g) {
} }
void Component::processEvent(Event* e) { void Component::processEvent(Event* e) {
} }
void Component::processMouseEvent(MouseEvent* e) { void Component::processMouseEvent(MouseEvent* e) {
} }
void Component::removeNotify() { void Component::removeNotify() {
} }
void Component::repaint() { void Component::repaint() {
} }
void Component::setBackground(Color* c) { void Component::setBackground(Color* c) {
background = c; background = c;
} }
void Component::setBorder(Border* b) { void Component::setBorder(Border* b) {
delete border; delete border;
border = b; border = b;
} }
void Component::setFont(nitrogen::Font* f) { void Component::setFont(nitrogen::Font* f) {
delete font; delete font;
font = f; font = f;
} }
void Component::setForeground(Color* c) { void Component::setForeground(Color* c) {
foreground = c; foreground = c;
} }
void Component::setLocation(NPosition<int>* p) { void Component::setLocation(NPosition<int>* p) {
location = p; location = p;
} }
void Component::setSize(NSize<unsigned int>* s) { void Component::setSize(NSize<unsigned int>* s) {
size = s; size = s;
} }
void Component::update(Graphics* g) { void Component::update(Graphics* g) {
} }
void Component::validate() { void Component::validate() {
} }
Component::~Component() { Component::~Component() {
}
} }
} }
...@@ -35,63 +35,71 @@ ...@@ -35,63 +35,71 @@
#define COMPONENT_H #define COMPONENT_H
#include <ntk.h> #include <ntk.h>
#include <Color.h>
#include <NSize.h>
#include <NPosition.h> #include <NPosition.h>
#include <NSize.h>
#include <nitrogen/nwt/Border.h>
#include <nitrogen/nwt/Color.h>
#include <nitrogen/nwt/Font.h>
#include <nitrogen/nwt/FontMetrics.h>
#include <nitrogen/nwt/Graphics.h>
#include <list> #include <list>
namespace nitrogen { namespace nitrogen {
class Component : public NObject { namespace nwt {
public: class Component : public NObject {
virtual ~Component(); public:
virtual ~Component();
virtual Border* getBorder();
virtual NSize<unsigned int>* getSize();
virtual NPosition<int>* getLocation();
virtual Component* getParent();
virtual Graphics* getGraphics();
virtual nitrogen::nwt::Font* getFont();
virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font *f);
virtual Color* getForeground();
virtual Color* getBackground();
virtual NSize<unsigned int>* getPreferredSize();
virtual void setBorder(Border* b);
virtual void setFont(nitrogen::nwt::Font *f);
virtual void setForeground(Color* c);
virtual void setBackground(Color* c);
virtual void setSize(NSize<unsigned int> *s);
virtual void setLocation(NPosition<int> *p);
virtual void paint(Graphics *g);
virtual void repaint();
virtual void paintAll(Graphics *g);
virtual void update(Graphics *g);
virtual void validate();
virtual void removeNotify();
virtual Border* getBorder(); virtual void addMouseListener(MouseListener *m);
virtual NSize<unsigned int>* getSize(); virtual void dispatchEvent(Event *e);
virtual NPosition<int>* getLocation();
virtual Component* getParent();
virtual Graphics* getGraphics();
virtual nitrogen::Font* getFont();
virtual FontMetrics* getFontMetrics(nitrogen::Font *f);
virtual Color* getForeground();
virtual Color* getBackground();
virtual NSize<unsigned int>* getPreferredSize();
virtual void setBorder(Border* b); protected:
virtual void setFont(nitrogen::Font *f); Component *parent;
virtual void setForeground(Color* c); Graphics *graphics;
virtual void setBackground(Color* c); NPosition<int> *location;
virtual void setSize(NSize<unsigned int> *s); Border *border;
virtual void setLocation(NPosition<int> *p); nitrogen::nwt::Font *font;
virtual void paint(Graphics *g); Color *foreground;
virtual void repaint(); Color *background;
virtual void paintAll(Graphics *g); NSize<unsigned int> *size;
virtual void update(Graphics *g); std::list<MouseEvent> *me_list;
virtual void validate(); NSize<unsigned int> *preferredSize;
virtual void removeNotify();
virtual void addMouseListener(MouseListener *m); Component();
virtual void dispatchEvent(Event *e); virtual void processEvent(Event *e);
virtual void processMouseEvent(MouseEvent *e);
protected:
Component *parent;
Graphics *graphics;
NPosition<int> *location;
Border *border;
nitrogen::Font *font;
Color *foreground;
Color *background;
NSize<unsigned int> *size;
std::list<MouseEvent> *me_list;
NSize<unsigned int> *preferredSize;
Component();
virtual void processEvent(Event *e);
virtual void processMouseEvent(MouseEvent *e);
private: private:
}; };
}
} }
#endif /* COMPONENT_H */ #endif /* COMPONENT_H */
...@@ -33,72 +33,71 @@ ...@@ -33,72 +33,71 @@
#include "Font.h" #include "Font.h"
#include <ntk.h>
#include <string>
namespace nitrogen { namespace nitrogen {
Font::Font(std::string* fn, int st, unsigned int si) { namespace nwt {
fontName = fn; Font::Font(std::string* fn, int st, unsigned int si) {
size = si; fontName = fn;
style = st; size = si;
} style = st;
Font::Font(std::string& fn, int st, unsigned int si) { }
fontName = &fn; Font::Font(std::string& fn, int st, unsigned int si) {
size = si; fontName = &fn;
style = st; size = si;
} style = st;
}
std::string* Font::getFontName() const { return fontName; } std::string* Font::getFontName() const { return fontName; }
int Font::getStyle() const { return style; } int Font::getStyle() const { return style; }
unsigned int Font::getSize() const { return size; } unsigned int Font::getSize() const { return size; }
Font::~Font() { Font::~Font() {
delete fontName; delete fontName;
} }
std::string* Font::toString() const { std::string* Font::toString() const {
std::string* out; std::string* out;
out->append(getTypeName(*this)); out->append(getTypeName(*this));
out->append("("); out->append("(");
out->append(fontName->c_str()); out->append(fontName->c_str());
out->append(","); out->append(",");
out->append(std::to_string(style)); out->append(std::to_string(style));
out->append(","); out->append(",");
out->append(std::to_string(size)); out->append(std::to_string(size));
out->append(")"); out->append(")");
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) const {
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) const {
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=(const 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;
}
return *this;
} }
return *this;
}
bool Font::operator!=(const Font& right) const { bool Font::operator!=(const Font& right) const {
return !(*this == right); return !(*this == right);
} }
bool Font::operator==(const Font& right) const { bool Font::operator==(const Font& right) const {
if (*fontName != *right.fontName) { return false; } if (*fontName != *right.fontName) { return false; }
if (size != right.size) { return false; } if (size != right.size) { return false; }
if (style != right.style) { return false; } if (style != right.style) { return false; }
return true; return true;
}
} }
} }
...@@ -37,30 +37,32 @@ ...@@ -37,30 +37,32 @@
#include <ntk.h> #include <ntk.h>
namespace nitrogen { namespace nitrogen {
class Font : public NObject { namespace nwt {
public: class Font : public NObject {
Font(std::string*, int, unsigned int); public:
Font(std::string&, int, unsigned int); Font(std::string*, int, unsigned int);
Font(std::string&, int, unsigned int);
virtual std::string* getFontName() const;
virtual int getStyle() const;
virtual unsigned int getSize() const;
virtual ~Font();
virtual std::string* toString() const; virtual std::string* getFontName() const;
virtual nitrogen::Font& operator()(std::string*, int, unsigned int) const; virtual int getStyle() const;
virtual nitrogen::Font& operator()(std::string&, int, unsigned int) const; virtual unsigned int getSize() const;
Font& operator=(const nitrogen::Font& right); virtual ~Font();
bool operator!=(const nitrogen::Font& right) const;
bool operator==(const nitrogen::Font& right) const;
protected: virtual std::string* toString() const;
std::string* fontName; virtual nitrogen::nwt::Font& operator()(std::string*, int, unsigned int) const;
int style; virtual nitrogen::nwt::Font& operator()(std::string&, int, unsigned int) const;
unsigned int size; Font& operator=(const nitrogen::nwt::Font& right);
private: bool operator!=(const nitrogen::nwt::Font& right) const;
bool operator==(const nitrogen::nwt::Font& right) const;
}; protected:
std::string* fontName;
int style;
unsigned int size;
private:
};
}
} }
#endif /* FONT_H */ #endif /* FONT_H */
...@@ -34,65 +34,66 @@ ...@@ -34,65 +34,66 @@
#include "FontMetrics.h" #include "FontMetrics.h"
#include <ntk.h> #include <ntk.h>
#include <string>
#include "Font.h" #include "nitrogen/nwt/Font.h"
#include <string>
#include "X11/Xlib.h" #include "X11/Xlib.h"
#include "ntk.h"
namespace nitrogen { namespace nitrogen {
namespace nwt {
FontMetrics::FontMetrics(nitrogen::nwt::Font* f) {
font_info = XLoadQueryFont(disp, f->getFontName()->c_str());
}
FontMetrics::FontMetrics(Font* f) { unsigned int FontMetrics::getAscent() const {
font_info = XLoadQueryFont(disp, f->getFontName()->c_str()); return font_info->max_bounds.ascent;
} }
unsigned int FontMetrics::getAscent() const {
return font_info->max_bounds.ascent;
}
unsigned int FontMetrics::getHeight() const { unsigned int FontMetrics::getHeight() const {
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) const {
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) const {
return stringWidth(&str); return stringWidth(&str);
} }
FontMetrics::~FontMetrics() { FontMetrics::~FontMetrics() {
delete font_info; delete font_info;
} }
std::string* FontMetrics::toString() const { std::string* FontMetrics::toString() const {
std::string *out; std::string *out;
out->append(getTypeName(this)); out->append(getTypeName(this));
out->append("("); out->append("(");
out->append(std::to_string(font_info->fid)); out->append(std::to_string(font_info->fid));
out->append(")"); out->append(")");
return out; return out;
} }
FontMetrics& FontMetrics::operator()(Font* f) const { FontMetrics& FontMetrics::operator()(nitrogen::nwt::Font* f) const {
FontMetrics *n = new FontMetrics(f); FontMetrics *n = new FontMetrics(f);
return *n; return *n;
} }
FontMetrics& FontMetrics::operator=(const FontMetrics& right) { FontMetrics& FontMetrics::operator=(const 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!=(const FontMetrics& right) const {
return !(*this == right); return !(*this == right);
} }
bool FontMetrics::operator==(const FontMetrics& right) const { bool FontMetrics::operator==(const FontMetrics& right) const {
return (font_info == right.font_info); return (font_info == right.font_info);
}
} }
} }
...@@ -35,30 +35,33 @@ ...@@ -35,30 +35,33 @@
#define FONTMETRICS_H #define FONTMETRICS_H
#include <ntk.h> #include <ntk.h>
#include <Font.h>
#include <nitrogen/nwt/Font.h>
#include <X11/X.h> #include <X11/X.h>
namespace nitrogen { namespace nitrogen {
class Font; namespace nwt {
class Font;
class FontMetrics : public NObject { class FontMetrics : public NObject {
public: public:
FontMetrics(Font* f); FontMetrics(nitrogen::nwt::Font* f);
virtual unsigned int getAscent() const; virtual unsigned int getAscent() const;
virtual unsigned int getHeight() const; virtual unsigned int getHeight() const;
virtual unsigned int stringWidth(std::string* str) const; virtual unsigned int stringWidth(std::string* str) const;
virtual unsigned int stringWidth(std::string& str) const; virtual unsigned int stringWidth(std::string& str) const;
virtual ~FontMetrics(); virtual ~FontMetrics();
virtual std::string* toString() const; virtual std::string* toString() const;
FontMetrics& operator()(Font* f) const; FontMetrics& operator()(nitrogen::nwt::Font* f) const;
FontMetrics& operator=(const FontMetrics& right); FontMetrics& operator=(const FontMetrics& right);
bool operator!=(const FontMetrics& right) const; bool operator!=(const FontMetrics& right) const;
bool operator==(const FontMetrics& right) const; bool operator==(const FontMetrics& right) const;
private: private:
XFontStruct* font_info; XFontStruct* font_info;
}; };
}
} }
#endif /* FONTMETRICS_H */ #endif /* FONTMETRICS_H */
......
...@@ -34,5 +34,6 @@ ...@@ -34,5 +34,6 @@
#include "Graphics.h" #include "Graphics.h"
namespace nitrogen { namespace nitrogen {
namespace nwt {
}
} }
...@@ -35,49 +35,53 @@ ...@@ -35,49 +35,53 @@
#define GRAPHICS_H #define GRAPHICS_H
#include <ntk.h> #include <ntk.h>
#include <Font.h>
#include <FontMetrics.h>
#include <Color.h>
#include <NPosition.h> #include <NPosition.h>
#include <NSize.h> #include <NSize.h>
#include <nitrogen/nwt/Color.h>
#include <nitrogen/nwt/Font.h>
#include <nitrogen/nwt/FontMetrics.h>
namespace nitrogen { namespace nitrogen {
class Graphics : public NObject { namespace nwt {
public: class Graphics : public NObject {
virtual void drawPoint(NPosition<int>* point) = 0; public:
virtual void drawLine(NPosition<int>* start, NPosition<int>* end) = 0; virtual void drawPoint(NPosition<int>* point) = 0;
virtual void drawRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void drawLine(NPosition<int>* start, NPosition<int>* end) = 0;
virtual void fillRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void drawRect(NPosition<int>* start, NSize<int>* size) = 0;
virtual void fill3DRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void fillRect(NPosition<int>* start, NSize<int>* size) = 0;
virtual void draw3DRect(NPosition<int>* start, NSize<int>* size) = 0; virtual void fill3DRect(NPosition<int>* start, NSize<int>* size) = 0;
virtual void draw3DRect(NPosition<int>* start, NSize<int>* size) = 0;
virtual void drawString(std::string* str, NPosition<int>* point) = 0;
virtual void drawString(std::string& str, NPosition<int>* point) = 0;
virtual void drawString(std::string* str, NPosition<int>* point) = 0; virtual Color* getColor() const = 0;
virtual void drawString(std::string& str, NPosition<int>* point) = 0; virtual nitrogen::nwt::Font* getFont() const = 0;
virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font* f) const = 0;
virtual FontMetrics* getFontMetrics() const = 0;
virtual Color* getColor() const = 0; virtual void setClip(NPosition<int>* start, NSize<unsigned int> size) = 0;
virtual nitrogen::Font* getFont() const = 0; virtual void setColor(Color* c) = 0;
virtual FontMetrics* getFontMetrics(nitrogen::Font* f) const = 0; virtual void setFont(nitrogen::nwt::Font* f) = 0;
virtual FontMetrics* getFontMetrics() const = 0;
virtual void setClip(NPosition<int>* start, NSize<unsigned int> size) = 0; virtual void translate(NPosition<int>* pos) = 0;
virtual void setColor(Color* c) = 0;
virtual void setFont(nitrogen::Font* f) = 0;
virtual void translate(NPosition<int>* pos) = 0;
virtual ~Graphics() = 0; virtual ~Graphics() = 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=(const Graphics& right) = 0;
virtual bool operator!=(const Graphics& right) const = 0; virtual bool operator!=(const Graphics& right) const = 0;
virtual bool operator==(const Graphics& right) const = 0; virtual bool operator==(const Graphics& right) const = 0;
protected: protected:
static nitrogen::Font* ntk_font; static nitrogen::nwt::Font* ntk_font;
private: private:
}; };
}
} }
#endif /* GRAPHICS_H */ #endif /* GRAPHICS_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: Insets.cpp
* Author: jlhawkwell
*
* Created on March 23, 2018, 1:53 PM
*/
#include "Insets.h"
namespace nitrogen {
namespace nwt {
Insets::Insets(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right) {
t = top;
l = left;
b = bottom;
r = right;
}
unsigned int Insets::getBottom() const { return b; }
unsigned int Insets::getLeft() const { return l; }
unsigned int Insets::getRight() const { return r; }
unsigned int Insets::getTop() const { return t; }
Insets::~Insets() {
}
std::string* Insets::toString() const {
std::string *out;
out->append(getTypeName(this));
out->append("(");
out->append(std::to_string(t));
out->append(",");
out->append(std::to_string(l));
out->append(",");
out->append(std::to_string(b));
out->append(",");
out->append(std::to_string(r));
out->append(")");
return out;
}
Insets& Insets::operator()(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right) const {
Insets *i = new Insets(top, left, bottom, right);
return *i;
}
Insets& Insets::operator=(const Insets& right) {
if (*this != right) {
t = right.t;
l = right.l;
b = right.b;
r = right.r;
}
return *this;
}
bool Insets::operator!=(const Insets& right) const {
return !(*this == right);
}
bool Insets::operator==(const Insets& right) const {
if (t != right.t) { return false; }
else if (l != right.l) { return false; }
else if (b != right.b) { return false; }
else if (r != right.r) { 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: Insets.h
* Author: jlhawkwell
*
* Created on March 23, 2018, 1:53 PM
*/
#ifndef INSETS_H
#define INSETS_H
#include <ntk.h>
namespace nitrogen {
namespace nwt {
class Insets : public NObject {
public:
Insets(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right);
virtual unsigned int getTop() const;
virtual unsigned int getLeft() const;
virtual unsigned int getBottom() const;
virtual unsigned int getRight() const;
virtual ~Insets();
virtual std::string* toString() const;
virtual Insets& operator()(unsigned int top, unsigned int left, unsigned int bottom, unsigned int right) const;
virtual Insets& operator=(const Insets& right);
virtual bool operator!=(const Insets& right) const;
virtual bool operator==(const Insets& right) const;
protected:
unsigned int t;
unsigned int l;
unsigned int b;
unsigned int r;
private:
};
}
}
#endif /* INSETS_H */
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#define NTK_VERSION "1.0.0.0" #define NTK_VERSION "1.0.0.0"
#ifndef NOBJECT_H #ifndef NOBJECT_H
#include <NObject.h> #include <nitrogen/NObject.h>
#endif #endif
namespace nitrogen { namespace nitrogen {
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#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 NOBJECT_H
#include <NObject.h> #include <nitrogen/NObject.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!