Commit b2184285 by Jessica Hawkwell

fleshed out empty methods

1 parent 6b1be3ff
...@@ -46,7 +46,7 @@ namespace nitrogen { ...@@ -46,7 +46,7 @@ namespace nitrogen {
cy = 0; cy = 0;
cw = 0; cw = 0;
ch = 0; ch = 0;
//me_list = new std::list<MouseEvent>(); me_list = new std::vector<MouseEvent*>();
parent = nullptr; parent = nullptr;
preferredSize = new Rectangle(0, 0); preferredSize = new Rectangle(0, 0);
} }
...@@ -140,43 +140,101 @@ namespace nitrogen { ...@@ -140,43 +140,101 @@ namespace nitrogen {
} }
void Component::paint(Graphics* g) { void Component::paint(Graphics* g) {
if (border != nullptr) {
border->paintBorder(*this, g, cx, cy, cw, ch);
}
} }
void Component::repaint() { void Component::repaint() {
if (graphics != nullptr) {
paint(graphics);
}
} }
void Component::paintAll(Graphics* g) { void Component::paintAll(Graphics* g) {
if (g != nullptr) {
paint(g);
}
} }
void Component::update(Graphics* g) { void Component::update(Graphics* g) {
if (g) {
if (graphics != g) {
if (graphics) {
graphics->dispose();
graphics = g->create();
}
}
graphics->setColor(background);
graphics->fillRect(0, 0, cw, ch);
graphics->setColor(foreground);
paint(graphics);
}
} }
void Component::validate() { void Component::validate() {
Dimension* d;
d = getPreferredSize();
std::cout << "d: " << *d << std::endl;
} }
void Component::removeNotify() { void Component::removeNotify() {
if (graphics) {
graphics->dispose();
}
graphics = nullptr;
} }
void Component::addMouseListener(MouseListener* m) { void Component::addMouseListener(MouseListener* m) {
me_list->insert(me_list->end(), m);
} }
void Component::dispatchEvent(NWTEvent* e) { void Component::dispatchEvent(NWTEvent* e) {
processEvent(e);
} }
void Component::processEvent(NWTEvent* e) { void Component::processEvent(NWTEvent* e) {
if (parent) {
parent->processEvent(e);
}
unsigned int size = me_list->size();
if (size) {
MouseEvent* me = (MouseEvent*) e;
if (me) {
processMouseEvent(me);
}
}
} }
void Component::processMouseEvent(MouseEvent* e) { void Component::processMouseEvent(MouseEvent* e) {
MouseListener* l;
unsigned int count = me_list->size();
for (int a = 0; a < count; a++) {
l = (*me_list)[a];
switch (e->getId()) {
case MouseEvent::MOUSE_CLICKED:
l->mouseClicked(e);
break;
case MouseEvent::MOUSE_ENTERED:
l->mouseEntered(e);
break;
case MouseEvent::MOUSE_EXITED:
l->mouseExited(e);
break;
case MouseEvent::MOUSE_PRESSED:
l->mousePressed(e);
break;
case MouseEvent::MOUSE_RELEASED:
l->mouseReleased(e);
break;
}
}
} }
} }
} }
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
#include <nitrogen/nwt/NWTEvent.h> #include <nitrogen/nwt/NWTEvent.h>
#include <nitrogen/nwt/Rectangle.h> #include <nitrogen/nwt/Rectangle.h>
#include <list> #include <vector>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
...@@ -58,6 +58,7 @@ namespace nitrogen { ...@@ -58,6 +58,7 @@ namespace nitrogen {
class MouseListener; class MouseListener;
class Component : public Object { class Component : public Object {
friend class Container;
public: public:
virtual Border* getBorder(); virtual Border* getBorder();
virtual Dimension* getSize(); virtual Dimension* getSize();
...@@ -101,7 +102,7 @@ namespace nitrogen { ...@@ -101,7 +102,7 @@ namespace nitrogen {
nitrogen::nwt::Font* font; nitrogen::nwt::Font* font;
Color* foreground; Color* foreground;
Color* background; Color* background;
std::list<MouseEvent>* me_list; std::vector<MouseEvent*>* me_list;
Rectangle* preferredSize; Rectangle* preferredSize;
Component(); Component();
......
...@@ -32,15 +32,14 @@ ...@@ -32,15 +32,14 @@
*/ */
#include "Container.h" #include "Container.h"
#include "Insets.h"
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
Component* Container::add(Component* comp) { Component* Container::add(Component* comp) {
std::vector<Component*>::iterator it; comp->parent = this;
it = lst->end(); lst->insert(lst->end(), comp);
lst->insert(it, comp);
return comp; return comp;
} }
...@@ -83,23 +82,85 @@ namespace nitrogen { ...@@ -83,23 +82,85 @@ namespace nitrogen {
} }
void Container::paintAll(Graphics* g) { void Container::paintAll(Graphics* g) {
this->Component.paintAll(g);
Dimension* size = getSize();
unsigned int count = lst->size();
Component* c;
Rectangle* bounds;
for (int a = 0; a < count; a++) {
c = getComponent(a);
bounds = c->getBounds();
g->translate(bounds->getX(), bounds->getY());
g->setClip(bounds->getX(), bounds->getY(), bounds->getWidth(), bounds->getHeight());
c->paint(g);
g->setClip(-bounds->getX(), -bounds->getY(), bounds->getWidth(), bounds->getHeight());
g->translate(-bounds->getX(), -bounds->getY());
}
} }
void Container::paintComponents(Graphics* g) { void Container::paintComponents(Graphics* g) {
paintAll(g);
} }
void Container::update(Graphics* g) { void Container::update(Graphics* g) {
this->Component::update(g);
unsigned int count = lst->size();
if (count) {
Dimension* s = getSize();
Insets* i;
if (border) {
i = border->getBorderInsets(this);
}
else {
i = new Insets(0, 0, 0, 0);
}
s->w -= (i->getLeft() + i->getRight());
s->h -= (i->getTop() + i->getBottom());
Component* c;
Rectangle* bounds;
for (int a = 0; a < count; a++) {
c = getComponent(a);
bounds = c->getBounds();
g->translate(bounds->getX(), bounds->getY());
g->setClip(bounds->getX(), bounds->getY(), bounds->getWidth(), bounds->getHeight());
c->update(g);
g->setClip(-bounds->getX(), -bounds->getY(), -bounds->getWidth(), -bounds->getHeight());
g->translate(-bounds->getX(), -bounds->getY());
}
}
} }
void Container::validate() { void Container::validate() {
this->Component::validate();
unsigned int count = lst->size();
for (int a = 0; a < count; a++) {
(*lst)[a]->validate();
}
lm->layoutContainer(this);
} }
void Container::removeNotify() { void Container::removeNotify() {
this->Component->removeNotify();
unsigned int count = lst->size();
for (int a = 0; a < count; a++) {
(*lst)[a]->removeNotify();
}
} }
Container::Container() { Container::Container() {
......
...@@ -41,6 +41,9 @@ namespace nitrogen { ...@@ -41,6 +41,9 @@ namespace nitrogen {
class Dimension : public Object { class Dimension : public Object {
public: public:
unsigned int w;
unsigned int h;
Dimension(); Dimension();
Dimension(unsigned int width, unsigned int height); Dimension(unsigned int width, unsigned int height);
virtual unsigned int getHeight(); virtual unsigned int getHeight();
...@@ -56,8 +59,6 @@ namespace nitrogen { ...@@ -56,8 +59,6 @@ namespace nitrogen {
virtual bool operator==(Dimension& right); virtual bool operator==(Dimension& right);
protected: protected:
unsigned int w;
unsigned int h;
private: private:
}; };
......
...@@ -44,6 +44,7 @@ namespace nitrogen { ...@@ -44,6 +44,7 @@ namespace nitrogen {
class Graphics : public Object { class Graphics : public Object {
public: public:
virtual Graphics* create() = 0;
virtual void drawPoint(int x, int y) = 0; virtual void drawPoint(int x, int y) = 0;
virtual void drawLine(int sx, int xy, int dx, int dy) = 0; virtual void drawLine(int sx, int xy, int dx, int dy) = 0;
virtual void drawRect(int x, int y, unsigned int width, unsigned int height) = 0; virtual void drawRect(int x, int y, unsigned int width, unsigned int height) = 0;
...@@ -64,6 +65,7 @@ namespace nitrogen { ...@@ -64,6 +65,7 @@ namespace nitrogen {
virtual void setFont(nitrogen::nwt::Font* f) = 0; virtual void setFont(nitrogen::nwt::Font* f) = 0;
virtual void translate(int x, int y) = 0; virtual void translate(int x, int y) = 0;
virtual void dispose() = 0;
virtual std::string* toString() const = 0; virtual std::string* toString() const = 0;
virtual Graphics& operator()() const = 0; virtual Graphics& operator()() const = 0;
......
...@@ -46,6 +46,16 @@ namespace nitrogen { ...@@ -46,6 +46,16 @@ namespace nitrogen {
class MouseEvent : public InputEvent { class MouseEvent : public InputEvent {
public: public:
static const int MOUSE_CLICKED = 0;
static const int MOUSE_DRAGGED = 1;
static const int MOUSE_ENTERED = 3;
static const int MOUSE_EXITED = 4;
static const int MOUSE_FIRST = 5;
static const int MOUSE_LAST = 6;
static const int MOUSE_MOVED = 7;
static const int MOUSE_PRESSED = 8;
static const int MOUSE_RELEASED = 9;
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(); virtual int getModifiers();
virtual int getX(); virtual int getX();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!