Commit f7aa26b0 by Jessica Hawkwell

Adding GridLayout

1 parent b2184285
......@@ -20,6 +20,7 @@ nitrogen/nwt/EventObject.cpp
nitrogen/nwt/Font.cpp
nitrogen/nwt/FontMetrics.cpp
nitrogen/nwt/Graphics.cpp
nitrogen/nwt/GridLayout.cpp
nitrogen/nwt/InputEvent.cpp
nitrogen/nwt/Insets.cpp
nitrogen/nwt/LayoutManager.cpp
......
......@@ -46,7 +46,7 @@ namespace nitrogen {
cy = 0;
cw = 0;
ch = 0;
me_list = new std::vector<MouseEvent*>();
ml_list = new std::vector<MouseListener*>();
parent = nullptr;
preferredSize = new Rectangle(0, 0);
}
......@@ -141,7 +141,7 @@ namespace nitrogen {
void Component::paint(Graphics* g) {
if (border != nullptr) {
border->paintBorder(*this, g, cx, cy, cw, ch);
border->paintBorder(this, g, cx, cy, cw, ch);
}
}
......@@ -178,7 +178,6 @@ namespace nitrogen {
Dimension* d;
d = getPreferredSize();
std::cout << "d: " << *d << std::endl;
}
void Component::removeNotify() {
......@@ -189,7 +188,7 @@ namespace nitrogen {
}
void Component::addMouseListener(MouseListener* m) {
me_list->insert(me_list->end(), m);
ml_list->insert(ml_list->end(), m);
}
void Component::dispatchEvent(NWTEvent* e) {
......@@ -201,10 +200,10 @@ namespace nitrogen {
parent->processEvent(e);
}
unsigned int size = me_list->size();
unsigned int size = ml_list->size();
if (size) {
MouseEvent* me = (MouseEvent*) e;
if (me) {
if (e) {
processMouseEvent(me);
}
}
......@@ -212,10 +211,10 @@ namespace nitrogen {
void Component::processMouseEvent(MouseEvent* e) {
MouseListener* l;
unsigned int count = me_list->size();
unsigned int count = ml_list->size();
for (int a = 0; a < count; a++) {
l = (*me_list)[a];
l = (*ml_list)[a];
switch (e->getId()) {
case MouseEvent::MOUSE_CLICKED:
......
......@@ -102,7 +102,7 @@ namespace nitrogen {
nitrogen::nwt::Font* font;
Color* foreground;
Color* background;
std::vector<MouseEvent*>* me_list;
std::vector<MouseListener*>* ml_list;
Rectangle* preferredSize;
Component();
......
......@@ -82,7 +82,7 @@ namespace nitrogen {
}
void Container::paintAll(Graphics* g) {
this->Component.paintAll(g);
this->Component::paintAll(g);
Dimension* size = getSize();
unsigned int count = lst->size();
......@@ -155,7 +155,7 @@ namespace nitrogen {
}
void Container::removeNotify() {
this->Component->removeNotify();
this->Component::removeNotify();
unsigned int count = lst->size();
for (int a = 0; a < count; a++) {
......
/*
* 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: GridLayout.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 5:46 PM
*/
#include "GridLayout.h"
#include "Insets.h"
namespace nitrogen {
namespace nwt {
GridLayout::GridLayout(unsigned int rows, unsigned int cols) {
glr = rows;
glc = cols;
glh = 5;
glv = 5;
}
GridLayout::GridLayout(unsigned int rows, unsigned int cols, unsigned int hgap, unsigned int vgap) {
glr = rows;
glc = cols;
glh = hgap;
glv = vgap;
}
void GridLayout::addLayoutComponent(std::string* s, Component* c) {
}
void GridLayout::addLayoutComponent(std::string& s, Component* c) {
}
void GridLayout::remoteLayoutComponent(Component* c) {
}
Dimension* GridLayout::minimumLayoutSize(Container* c) {
return c->getSize();
}
Dimension* GridLayout::preferredLayoutSize(Container* c) {
return c->getSize();
}
void GridLayout::layoutContainer(Container* parent) {
Dimension* d = parent->getSize();
Border* b = parent->getBorder();
Insets* i = new Insets(0, 0, 0, 0);
if (b) {
i = b->getBorderInsets(parent);
}
d->setSize(d->w - (i->getLeft() + i->getRight()), d->h - (i->getTop() + i->getBottom()));
unsigned int ew = ((d->w - ((glc - 1) * glh)) / glc);
unsigned int eh = ((d->h - ((glr - 1) * glv)) / glr);
unsigned int count = parent->getComponentCount();
unsigned int x = 0;
unsigned int y = 0;
unsigned int k = 0;
Component* c;
if (count) {
for (int a = 0; a < glr; a++) {
y = i->getTop() + (a * (eh + glv));
for (int b = 0; b < glc; b++) {
x = i->getLeft() + (b * (eh + glh));
c = parent->getComponent(k);
c->setSize(ew, eh);
c->setLocation(x, y);
k++;
}
}
}
}
}
}
/*
* 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: GridLayout.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 5:46 PM
*/
#ifndef GRIDLAYOUT_H
#define GRIDLAYOUT_H
#include <ntk.h>
#include <nitrogen/nwt/Component.h>
#include <nitrogen/nwt/Container.h>
#include <nitrogen/nwt/LayoutManager.h>
namespace nitrogen {
namespace nwt {
class GridLayout : public LayoutManager {
public:
GridLayout(unsigned int rows, unsigned int cols);
GridLayout(unsigned int rows, unsigned int cols, unsigned int hgap, unsigned int vgap);
virtual void addLayoutComponent(std::string*, Component*) override;
virtual void addLayoutComponent(std::string&, Component*) override;
virtual void remoteLayoutComponent(Component*);
virtual Dimension* minimumLayoutSize(Container*) override;
virtual Dimension* preferredLayoutSize(Container*) override;
void layoutContainer(Container*) override;
protected:
unsigned int glr;
unsigned int glc;
unsigned int glh;
unsigned int glv;
private:
};
}
}
#endif /* GRIDLAYOUT_H */
......@@ -48,8 +48,8 @@ namespace nitrogen {
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 Dimension* minimumLayoutSize(Container* cont) = 0;
virtual Dimension* preferredLayoutSize(Container* cont) = 0;
virtual void layoutContainer(Container* cont) = 0;
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: NativeGraphics.cpp
* Author: jlhawkwell
*
* Created on March 24, 2018, 5:16 PM
*/
#include "NativeGraphics.h"
namespace nitrogen {
namespace nwt {
NativeGraphics::NativeGraphics() {
}
}
}
/*
* 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: NativeGraphics.h
* Author: jlhawkwell
*
* Created on March 24, 2018, 5:16 PM
*/
#ifndef NATIVEGRAPHICS_H
#define NATIVEGRAPHICS_H
#include <ntk.h>
#include <nitrogen/nwt/Graphics.h>
#include <nitrogen/nwt/Rectangle.h>
namespace nitrogen {
namespace nwt {
class NativeGraphics : public Graphics {
//friend class Frame;
public:
NativeGraphics();
protected:
unsigned long mask;
private:
};
}
}
#endif /* NATIVEGRAPHICS_H */
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!