Commit d408b565 by Jessica Hawkwell

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

1 parent 6908dbda
......@@ -53,6 +53,7 @@ build
### KDevelop4 ###
*.kdev4
.kdev4/
*.kateproject
### NetBeans ###
nbproject/
......
......@@ -9,7 +9,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/bin)
set(CMAKE_ARCHIVE_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/libntk)
......
......@@ -23,18 +23,19 @@ For example:
None yet. :crying_cat_face:
---
## Requirements
+ [FreeBSD](http://freebsd.org/) `>= 10.1` (tested using FreeBSD 11)
## Runtime Requirements
+ [FreeBSD](http://freebsd.org/) `>= 10.1` (tested using FreeBSD `11.1-RELEASE`)
+ [`x11/libX11`](https://www.freshports.org/x11/libX11/)
+ [`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-threaded`](https://www.freshports.org/devel/boehm-gc-threaded/)
---
## Misc Tooling
+ [`devel/git`](https://www.freshports.org/devel/git/) **or** [`devel/git-gui`](https://www.freshports.org/devel/git-gui/)
## Tooling
+ [`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
......@@ -60,3 +61,7 @@ $ make
```console
$ ./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 <Color.h>
#include <NObject.h>
#include <nitrogen/nwt/Color.h>
#include <nitrogen/NObject.h>
#include "NWManager.h"
#include <iostream>
......@@ -9,7 +9,7 @@
int main ( int argc, char** argv )
{
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 << no
<< std::endl;
......
......@@ -4,19 +4,22 @@ configure_file(${PROJECT_NAME}.h.in ${PROJECT_NAME}.h)
find_package(X11)
find_library(BoehmGC gc-threaded)
#include_directories("/usr/local/include")
add_library(${PROJECT_NAME} SHARED ntkMain.cpp
NObject.cpp
Color.cpp
Font.cpp
FontMetrics.cpp
nitrogen/NObject.cpp
nitrogen/nwt/Color.cpp
nitrogen/nwt/Font.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})
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_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 @@
#include "Color.h"
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) {
alpha = 255;
red = ((c & MASK_RED) >> 16);
green = ((c & MASK_GREEN) >> 8);
blue = (c & MASK_BLUE);
}
Color::Color(unsigned char r, unsigned char g, unsigned char b) {
alpha = 255;
red = r;
green = g;
blue = b;
}
Color::Color(unsigned char r, unsigned char g, unsigned char b) {
alpha = 255;
red = r;
green = g;
blue = b;
}
Color::Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
alpha = a;
red = r;
green = g;
blue = b;
}
Color::Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
alpha = a;
red = r;
green = g;
blue = b;
}
unsigned char Color::getAlpha() const {
return alpha;
}
unsigned char Color::getAlpha() const {
return alpha;
}
unsigned char Color::getBlue() const {
return blue;
}
unsigned char Color::getBlue() const {
return blue;
}
unsigned char Color::getGreen() const {
return green;
}
unsigned char Color::getGreen() const {
return green;
}
unsigned int Color::getRGB() const {
return (red << 16) + (green << 8) + blue;
}
unsigned int Color::getRGB() const {
return (red << 16) + (green << 8) + blue;
}
unsigned int Color::getARGB() const {
return (alpha << 24) + getRGB();
}
unsigned int Color::getARGB() const {
return (alpha << 24) + getRGB();
}
unsigned char Color::getRed() const {
return red;
}
unsigned char Color::getRed() const {
return red;
}
Color::~Color() {
}
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 {
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;
}
Color& Color::operator()(unsigned int c) const {
Color *nc = new Color(c);
return *nc;
}
Color& Color::operator()(unsigned int c) const {
Color *nc = new Color(c);
return *nc;
}
Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b) const {
Color *nc = new Color(r, g, b);
return *nc;
}
Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b) const {
Color *nc = new Color(r, g, b);
return *nc;
}
Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b, unsigned char a) const {
Color *nc = new Color(r, g, b, a);
return *nc;
}
Color& Color::operator()(unsigned char r, unsigned char g, unsigned char b, unsigned char a) const {
Color *nc = new Color(r, g, b, a);
return *nc;
}
Color& Color::operator=(const Color& right) {
if (this != &right) {
alpha = right.getAlpha();
red = right.getRed();
green = right.getGreen();
blue = right.getBlue();
}
return *this;
}
Color& Color::operator=(const Color& right) {
if (this != &right) {
alpha = right.getAlpha();
red = right.getRed();
green = right.getGreen();
blue = right.getBlue();
bool Color::operator!=(const Color& right) const {
return !(*this == right);
}
return *this;
}
bool Color::operator!=(const Color& right) const {
return !(*this == right);
}
bool Color::operator==(const Color& right) const {
return (getARGB() == right.getARGB());
}
bool Color::operator==(const Color& right) const {
return (getARGB() == right.getARGB());
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);
}
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 @@
#include <ntk.h>
namespace nitrogen {
class Color : public NObject {
public:
static const unsigned int MASK_ALPHA = 0xff000000;
static const unsigned int MASK_RED = 0x00ff0000;
static const unsigned int MASK_GREEN = 0x0000ff00;
static const unsigned int MASK_BLUE = 0x000000ff;
namespace nwt {
class Color : public NObject {
public:
static const unsigned int MASK_ALPHA = 0xff000000;
static const unsigned int MASK_RED = 0x00ff0000;
static const unsigned int MASK_GREEN = 0x0000ff00;
static const unsigned int MASK_BLUE = 0x000000ff;
static Color* BLACK;
static Color* RED;
static Color* GREEN;
static Color* YELLOW;
static Color* BLUE;
static Color* MAGENTA;
static Color* CYAN;
static Color* WHITE;
static Color* BRIGHT_BLACK;
static Color* BRIGHT_RED;
static Color* BRIGHT_GREEN;
static Color* BRIGHT_YELLOW;
static Color* BRIGHT_BLUE;
static Color* BRIGHT_MAGENTA;
static Color* BRIGHT_CYAN;
static Color* BRIGHT_WHITE;
static Color* BLACK;
static Color* RED;
static Color* GREEN;
static Color* YELLOW;
static Color* BLUE;
static Color* MAGENTA;
static Color* CYAN;
static Color* WHITE;
static Color* BRIGHT_BLACK;
static Color* BRIGHT_RED;
static Color* BRIGHT_GREEN;
static Color* BRIGHT_YELLOW;
static Color* BRIGHT_BLUE;
static Color* BRIGHT_MAGENTA;
static Color* BRIGHT_CYAN;
static Color* BRIGHT_WHITE;
Color(unsigned int c);
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 int c);
Color(unsigned char red, unsigned char green, unsigned char blue);
Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha);
unsigned char getAlpha() const;
unsigned char getRed() const;
unsigned char getGreen() const;
unsigned char getBlue() const;
unsigned int getRGB() const;
unsigned int getARGB() const;
unsigned char getAlpha() const;
unsigned char getRed() const;
unsigned char getGreen() const;
unsigned char getBlue() const;
unsigned int getRGB() const;
unsigned int getARGB() const;
virtual ~Color();
virtual ~Color();
virtual std::string* toString() 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, unsigned char alpha) const;
virtual Color& operator=(const Color& right);
virtual bool operator!=(const Color& right) const;
virtual bool operator==(const Color& right) const;
virtual std::string* toString() 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, unsigned char alpha) const;
virtual Color& operator=(const Color& right);
virtual bool operator!=(const Color& right) const;
virtual bool operator==(const Color& right) const;
private:
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
};
private:
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
};
}
}
#endif /* COLOR_H */
......
......@@ -34,127 +34,128 @@
#include "Component.h"
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() {
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::addMouseListener(MouseListener* m) {
}
}
void Component::dispatchEvent(Event* e) {
void Component::dispatchEvent(Event* e) {
}
}
Color* Component::getBackground() {
return background;
}
Color* Component::getBackground() {
return background;
}
Border* Component::getBorder() {
return border;
}
Border* Component::getBorder() {
return border;
}
nitrogen::Font* Component::getFont() {
return font;
}
nitrogen::Font* Component::getFont() {
return font;
}
FontMetrics* Component::getFontMetrics(nitrogen::Font* f) {
FontMetrics* Component::getFontMetrics(nitrogen::Font* f) {
}
}
Color* Component::getForeground() {
return foreground;
}
Color* Component::getForeground() {
return foreground;
}
Graphics* Component::getGraphics() {
return graphics;
}
Graphics* Component::getGraphics() {
return graphics;
}
Component* Component::getParent() {
return parent;
}
Component* Component::getParent() {
return parent;
}
NPosition<int>* Component::getLocation() {
return location;
}
NPosition<int>* Component::getLocation() {
return location;
}
NSize<unsigned int>* Component::getPreferredSize() {
return preferredSize;
}
NSize<unsigned int>* Component::getPreferredSize() {
return preferredSize;
}
NSize<unsigned int>* Component::getSize() {
return size;
}
NSize<unsigned int>* Component::getSize() {
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) {
background = c;
}
void Component::setBackground(Color* c) {
background = c;
}
void Component::setBorder(Border* b) {
delete border;
border = b;
}
void Component::setBorder(Border* b) {
delete border;
border = b;
}
void Component::setFont(nitrogen::Font* f) {
delete font;
font = f;
}
void Component::setFont(nitrogen::Font* f) {
delete font;
font = f;
}
void Component::setForeground(Color* c) {
foreground = c;
}
void Component::setForeground(Color* c) {
foreground = c;
}
void Component::setLocation(NPosition<int>* p) {
location = p;
}
void Component::setLocation(NPosition<int>* p) {
location = p;
}
void Component::setSize(NSize<unsigned int>* s) {
size = s;
}
void Component::setSize(NSize<unsigned int>* 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 @@
#define COMPONENT_H
#include <ntk.h>
#include <Color.h>
#include <NSize.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>
namespace nitrogen {
class Component : public NObject {
public:
virtual ~Component();
namespace nwt {
class Component : public NObject {
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 NSize<unsigned int>* getSize();
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 addMouseListener(MouseListener *m);
virtual void dispatchEvent(Event *e);
virtual void setBorder(Border* b);
virtual void setFont(nitrogen::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();
protected:
Component *parent;
Graphics *graphics;
NPosition<int> *location;
Border *border;
nitrogen::nwt::Font *font;
Color *foreground;
Color *background;
NSize<unsigned int> *size;
std::list<MouseEvent> *me_list;
NSize<unsigned int> *preferredSize;
virtual void addMouseListener(MouseListener *m);
virtual void dispatchEvent(Event *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);
Component();
virtual void processEvent(Event *e);
virtual void processMouseEvent(MouseEvent *e);
private:
private:
};
};
}
}
#endif /* COMPONENT_H */
......@@ -33,72 +33,71 @@
#include "Font.h"
#include <ntk.h>
#include <string>
namespace nitrogen {
Font::Font(std::string* fn, int st, unsigned int si) {
fontName = fn;
size = si;
style = st;
}
Font::Font(std::string& fn, int st, unsigned int si) {
fontName = &fn;
size = si;
style = st;
}
namespace nwt {
Font::Font(std::string* fn, int st, unsigned int si) {
fontName = fn;
size = si;
style = st;
}
Font::Font(std::string& fn, int st, unsigned int si) {
fontName = &fn;
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() {
delete fontName;
}
Font::~Font() {
delete fontName;
}
std::string* Font::toString() const {
std::string* out;
std::string* Font::toString() const {
std::string* out;
out->append(getTypeName(*this));
out->append("(");
out->append(fontName->c_str());
out->append(",");
out->append(std::to_string(style));
out->append(",");
out->append(std::to_string(size));
out->append(")");
out->append(getTypeName(*this));
out->append("(");
out->append(fontName->c_str());
out->append(",");
out->append(std::to_string(style));
out->append(",");
out->append(std::to_string(size));
out->append(")");
return out;
}
return out;
}
Font& Font::operator()(std::string* fn, int st, unsigned int si) const {
Font *n = new Font(fn, st, si);
return *n;
}
Font& Font::operator()(std::string& fn, int st, unsigned int si) const {
Font *n = new Font(fn, st, si);
return *n;
}
Font& Font::operator()(std::string* fn, int st, unsigned int si) const {
Font *n = new Font(fn, st, si);
return *n;
}
Font& Font::operator()(std::string& fn, int st, unsigned int si) const {
Font *n = new Font(fn, st, si);
return *n;
}
Font& Font::operator=(const Font& right) {
if (this != &right) {
*fontName = *right.fontName;
size = right.size;
style = right.style;
Font& Font::operator=(const Font& right) {
if (this != &right) {
*fontName = *right.fontName;
size = right.size;
style = right.style;
}
return *this;
}
return *this;
}
bool Font::operator!=(const Font& right) const {
return !(*this == right);
}
bool Font::operator!=(const Font& right) const {
return !(*this == right);
}
bool Font::operator==(const Font& right) const {
if (*fontName != *right.fontName) { return false; }
if (size != right.size) { return false; }
if (style != right.style) { return false; }
return true;
bool Font::operator==(const Font& right) const {
if (*fontName != *right.fontName) { return false; }
if (size != right.size) { return false; }
if (style != right.style) { return false; }
return true;
}
}
}
......@@ -37,30 +37,32 @@
#include <ntk.h>
namespace nitrogen {
class Font : public NObject {
public:
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();
namespace nwt {
class Font : public NObject {
public:
Font(std::string*, int, unsigned int);
Font(std::string&, int, unsigned int);
virtual std::string* toString() const;
virtual nitrogen::Font& operator()(std::string*, int, unsigned int) const;
virtual nitrogen::Font& operator()(std::string&, int, unsigned int) const;
Font& operator=(const nitrogen::Font& right);
bool operator!=(const nitrogen::Font& right) const;
bool operator==(const nitrogen::Font& right) const;
virtual std::string* getFontName() const;
virtual int getStyle() const;
virtual unsigned int getSize() const;
virtual ~Font();
protected:
std::string* fontName;
int style;
unsigned int size;
private:
virtual std::string* toString() const;
virtual nitrogen::nwt::Font& operator()(std::string*, int, unsigned int) const;
virtual nitrogen::nwt::Font& operator()(std::string&, int, unsigned int) const;
Font& operator=(const nitrogen::nwt::Font& right);
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 */
......@@ -34,65 +34,66 @@
#include "FontMetrics.h"
#include <ntk.h>
#include <string>
#include "Font.h"
#include "nitrogen/nwt/Font.h"
#include <string>
#include "X11/Xlib.h"
#include "ntk.h"
namespace nitrogen {
namespace nwt {
FontMetrics::FontMetrics(nitrogen::nwt::Font* f) {
font_info = XLoadQueryFont(disp, f->getFontName()->c_str());
}
FontMetrics::FontMetrics(Font* f) {
font_info = XLoadQueryFont(disp, f->getFontName()->c_str());
}
unsigned int FontMetrics::getAscent() const {
return font_info->max_bounds.ascent;
}
unsigned int FontMetrics::getAscent() const {
return font_info->max_bounds.ascent;
}
unsigned int FontMetrics::getHeight() const {
return font_info->max_bounds.ascent + font_info->max_bounds.descent;
}
unsigned int FontMetrics::getHeight() const {
return font_info->max_bounds.ascent + font_info->max_bounds.descent;
}
unsigned int FontMetrics::stringWidth(std::string* str) const {
return XTextWidth(font_info, str->c_str(), str->length());
}
unsigned int FontMetrics::stringWidth(std::string& str) const {
return stringWidth(&str);
}
unsigned int FontMetrics::stringWidth(std::string* str) const {
return XTextWidth(font_info, str->c_str(), str->length());
}
unsigned int FontMetrics::stringWidth(std::string& str) const {
return stringWidth(&str);
}
FontMetrics::~FontMetrics() {
delete font_info;
}
FontMetrics::~FontMetrics() {
delete font_info;
}
std::string* FontMetrics::toString() const {
std::string *out;
std::string* FontMetrics::toString() const {
std::string *out;
out->append(getTypeName(this));
out->append("(");
out->append(std::to_string(font_info->fid));
out->append(")");
out->append(getTypeName(this));
out->append("(");
out->append(std::to_string(font_info->fid));
out->append(")");
return out;
}
return out;
}
FontMetrics& FontMetrics::operator()(Font* f) const {
FontMetrics *n = new FontMetrics(f);
return *n;
}
FontMetrics& FontMetrics::operator()(nitrogen::nwt::Font* f) const {
FontMetrics *n = new FontMetrics(f);
return *n;
}
FontMetrics& FontMetrics::operator=(const FontMetrics& right) {
if (*this != right) {
font_info = right.font_info;
FontMetrics& FontMetrics::operator=(const FontMetrics& right) {
if (*this != right) {
font_info = right.font_info;
}
return *this;
}
return *this;
}
bool FontMetrics::operator!=(const FontMetrics& right) const {
return !(*this == right);
}
bool FontMetrics::operator!=(const FontMetrics& right) const {
return !(*this == right);
}
bool FontMetrics::operator==(const FontMetrics& right) const {
return (font_info == right.font_info);
bool FontMetrics::operator==(const FontMetrics& right) const {
return (font_info == right.font_info);
}
}
}
......@@ -35,30 +35,33 @@
#define FONTMETRICS_H
#include <ntk.h>
#include <Font.h>
#include <nitrogen/nwt/Font.h>
#include <X11/X.h>
namespace nitrogen {
class Font;
class FontMetrics : public NObject {
public:
FontMetrics(Font* f);
virtual unsigned int getAscent() const;
virtual unsigned int getHeight() const;
virtual unsigned int stringWidth(std::string* str) const;
virtual unsigned int stringWidth(std::string& str) const;
virtual ~FontMetrics();
namespace nwt {
class Font;
class FontMetrics : public NObject {
public:
FontMetrics(nitrogen::nwt::Font* f);
virtual unsigned int getAscent() const;
virtual unsigned int getHeight() const;
virtual unsigned int stringWidth(std::string* str) const;
virtual unsigned int stringWidth(std::string& str) const;
virtual ~FontMetrics();
virtual std::string* toString() const;
FontMetrics& operator()(Font* f) const;
FontMetrics& operator=(const FontMetrics& right);
bool operator!=(const FontMetrics& right) const;
bool operator==(const FontMetrics& right) const;
virtual std::string* toString() const;
FontMetrics& operator()(nitrogen::nwt::Font* f) const;
FontMetrics& operator=(const FontMetrics& right);
bool operator!=(const FontMetrics& right) const;
bool operator==(const FontMetrics& right) const;
private:
XFontStruct* font_info;
};
private:
XFontStruct* font_info;
};
}
}
#endif /* FONTMETRICS_H */
......
......@@ -34,5 +34,6 @@
#include "Graphics.h"
namespace nitrogen {
namespace nwt {
}
}
......@@ -35,49 +35,53 @@
#define GRAPHICS_H
#include <ntk.h>
#include <Font.h>
#include <FontMetrics.h>
#include <Color.h>
#include <NPosition.h>
#include <NSize.h>
#include <nitrogen/nwt/Color.h>
#include <nitrogen/nwt/Font.h>
#include <nitrogen/nwt/FontMetrics.h>
namespace nitrogen {
class Graphics : public NObject {
public:
virtual void drawPoint(NPosition<int>* point) = 0;
virtual void drawLine(NPosition<int>* start, NPosition<int>* end) = 0;
virtual void drawRect(NPosition<int>* start, NSize<int>* size) = 0;
virtual void fillRect(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;
namespace nwt {
class Graphics : public NObject {
public:
virtual void drawPoint(NPosition<int>* point) = 0;
virtual void drawLine(NPosition<int>* start, NPosition<int>* end) = 0;
virtual void drawRect(NPosition<int>* start, NSize<int>* size) = 0;
virtual void fillRect(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 void drawString(std::string& str, NPosition<int>* point) = 0;
virtual Color* getColor() const = 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 nitrogen::Font* getFont() const = 0;
virtual FontMetrics* getFontMetrics(nitrogen::Font* f) const = 0;
virtual FontMetrics* getFontMetrics() const = 0;
virtual void setClip(NPosition<int>* start, NSize<unsigned int> size) = 0;
virtual void setColor(Color* c) = 0;
virtual void setFont(nitrogen::nwt::Font* f) = 0;
virtual void setClip(NPosition<int>* start, NSize<unsigned int> size) = 0;
virtual void setColor(Color* c) = 0;
virtual void setFont(nitrogen::Font* f) = 0;
virtual void translate(NPosition<int>* pos) = 0;
virtual void translate(NPosition<int>* pos) = 0;
virtual ~Graphics() = 0;
virtual ~Graphics() = 0;
virtual std::string* toString() const = 0;
virtual Graphics& operator()() const = 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 std::string* toString() const = 0;
virtual Graphics& operator()() const = 0;
virtual Graphics& operator=(const Graphics& right) = 0;
virtual bool operator!=(const Graphics& right) const = 0;
virtual bool operator==(const Graphics& right) const = 0;
protected:
static nitrogen::Font* ntk_font;
private:
protected:
static nitrogen::nwt::Font* ntk_font;
private:
};
};
}
}
#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 @@
#define NTK_VERSION "1.0.0.0"
#ifndef NOBJECT_H
#include <NObject.h>
#include <nitrogen/NObject.h>
#endif
namespace nitrogen {
......
......@@ -55,7 +55,7 @@
#define NTK_VERSION "@Nitrogen_VERSION_MAJOR@.@Nitrogen_VERSION_MINOR@.@Nitrogen_VERSION_PATCH@.@Nitrogen_VERSION_TWEAK@"
#ifndef NOBJECT_H
#include <NObject.h>
#include <nitrogen/NObject.h>
#endif
namespace nitrogen {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!