diff --git a/gui/Canvas.cpp b/gui/Canvas.cpp deleted file mode 100644 index 8851fd02..00000000 --- a/gui/Canvas.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#include -#include -#include -#include - -namespace aw { -namespace gui { -Canvas::elements_t::iterator Canvas::findElement(Element* e) -{ - auto compare = [&e] (std::unique_ptr& ptr) { - return ptr.get() == e; - }; - - return std::find_if(elements.begin(), elements.end(), compare); -} - -void Canvas::addElement(std::unique_ptr e) -{ - core::Logger::debug("[GUI] Canvas: Adding Element"); - e->setParent(this); - elements.push_back(std::move(e)); -} - -std::unique_ptr Canvas::removeElement(Element* e) -{ - core::Logger::debug("[GUI] Canvas: Removing Element"); - - auto element = findElement(e); - - if (element == elements.end()) - return nullptr; - - auto temp = std::move(*element); - temp->removeParent(); - - elements.erase(element); - - return std::move(temp); -} - -void Canvas::bringToFront(Element* e) -{ - auto element = findElement(e); - - if (element == elements.end()) - return; - - auto temp = std::move(*element); - elements.erase(element); - elements.push_back(std::move(temp)); -} - -void Canvas::sendToBack(Element* e) -{ - auto element = findElement(e); - - if (element == elements.end()) - return; - - auto temp = std::move(*element); - elements.erase(element); - elements.insert(std::begin(elements), std::move(temp)); -} - -Element* Canvas::getActiveElement() -{ - return active; -} - -bool Canvas::onEvent(Event* event) -{ - if (event->getType() == MouseEvent::type()) { - processEvent(event_cast(event)); - } else if (event->getType() == GUIEvent::type()) { - processEvent(event_cast(event)); - } - - Element* active = getActiveElement(); - - if (!active) - return false; - - return active->onEvent(event); -} - -void Canvas::accept(Visitor& visitor) -{ - visitor.visit(this); -} - -Element* Canvas::getElementFromPoint(Vector2d point, Vector2d bounds) { - Element* element = nullptr; - for (auto& e : make_reverse(elements)) { - bool within = pointWithinElement(point, *e, bounds); - if (within) { - element = e.get(); - break; - } - } - return element; -} - -bool Canvas::processEvent(MouseEvent* event) -{ - auto bounds = event->bounds; - auto mousePos = Vector2d(event->position.x() * bounds.x(), - event->position.y() * bounds.y()); - auto element = getElementFromPoint(mousePos, bounds); - - switch (event->action) { - case MouseEvent::Moved: { - GUIEvent hoveredEvent; - auto setHovered = [&hoveredEvent, &element, this] { - hoveredEvent.action = GUIEvent::Hovered; - element->onEvent(&hoveredEvent); - this->hovered = element; - }; - - if (element && hovered == element) { - setHovered(); - break; - } - if (hovered) { - hoveredEvent.action = GUIEvent::Left; - hovered->onEvent(&hoveredEvent); - hovered = nullptr; - } - if (element) - setHovered(); - break; - } - case MouseEvent::LButtonUp: - break; - case MouseEvent::LButtonDown: { - // If element under cursor is current active - // element, then we don't need to send any events. - if (active == element) - break; - - GUIEvent focusedEvent; - if (active) { - focusedEvent.action = GUIEvent::Unfocused; - active->onEvent(&focusedEvent); - active = nullptr; - } - if (element) { - focusedEvent.action = GUIEvent::Focused; - element->onEvent(&focusedEvent); - active = element; - } - } - default: - break; - } - - return false; -} - -bool Canvas::processEvent(GUIEvent* event) -{ - switch (event->type()) { - case GUIEvent::Focused: - if (getParent()) { - getParent()->toCanvas()->bringToFront(this); - } - return true; - } - return false; -} -} // namespace gui -} // namespace aw diff --git a/gui/Drawer.cpp b/gui/Drawer.cpp deleted file mode 100644 index 922f925c..00000000 --- a/gui/Drawer.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -namespace aw { -namespace gui { - -Drawer::~Drawer() -{ -} - -void Drawer::visit(Element* element) -{ -} - -void Drawer::visit(Canvas* element) -{ - //Skin* skin = element->getSkin(); - //skin->drawCanvas(element->getRect()); - drawChildren(element); -} - -void Drawer::visit(Window* element) -{ - Style* style = element->getStyle(); - auto windowStyle = style->getElementStyle("window"); - if (!windowStyle) { - // core::Logger::debug("[GUI] Drawer: Can't find style"); - return; //todo : default - } - - engine.drawBorder(element->getAbsoluteRect(), - windowStyle->getBorderStyle()); - - engine.drawBackground(element->getClientRect(), - windowStyle->getBackgroundStyle()); - - //if (element->hasTitleBar()) { - //} - drawChildren(element); -} - -void Drawer::visit(Widget* element) -{ - core::Logger::debug("[GUI] Drawer: Unknown Widget"); -} - -// TODO: replace pointer with reference -void Drawer::drawChildren(Canvas* element) -{ - for (auto& e : element) { - e.accept(*this); - } -} -} // namespace gui -} // namespace aw diff --git a/gui/InputManager.cpp b/gui/InputManager.cpp deleted file mode 100644 index b6480063..00000000 --- a/gui/InputManager.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#include - -#include - -#include - -namespace aw { -namespace gui { -namespace impl { -bool InputManager::convertEvent(const irr::SEvent& irrEvent, Event*& event) { - switch(irrEvent.EventType) { - case irr::EET_MOUSE_INPUT_EVENT: { - auto mevent = new MouseEvent(); - auto screen = device->getVideoDriver()->getScreenSize(); - mevent->position = Vector2d(f32(irrEvent.MouseInput.X) / screen.Width, - f32(irrEvent.MouseInput.Y) / screen.Height); - mevent->bounds = Vector2d(screen.Width, screen.Height); - mevent->wheel = irrEvent.MouseInput.Wheel; - mevent->buttonStates = irrEvent.MouseInput.ButtonStates; - - switch(irrEvent.MouseInput.Event) { - case irr::EMIE_LMOUSE_PRESSED_DOWN: - mevent->action = MouseEvent::LButtonDown; - break; - case irr::EMIE_RMOUSE_PRESSED_DOWN: - mevent->action = MouseEvent::RButtonDown; - break; - case irr::EMIE_MMOUSE_PRESSED_DOWN: - mevent->action = MouseEvent::MButtonDown; - break; - case irr::EMIE_LMOUSE_LEFT_UP: - mevent->action = MouseEvent::LButtonUp; - break; - case irr::EMIE_RMOUSE_LEFT_UP: - mevent->action = MouseEvent::RButtonUp; - break; - case irr::EMIE_MMOUSE_LEFT_UP: - mevent->action = MouseEvent::MButtonUp; - break; - case irr::EMIE_LMOUSE_DOUBLE_CLICK: - mevent->action = MouseEvent::LDoubleClick; - break; - case irr::EMIE_RMOUSE_DOUBLE_CLICK: - mevent->action = MouseEvent::RDoubleClick; - break; - case irr::EMIE_MMOUSE_DOUBLE_CLICK: - mevent->action = MouseEvent::MDoubleClick; - break; - case irr::EMIE_LMOUSE_TRIPLE_CLICK: - mevent->action = MouseEvent::LTripleClick; - break; - case irr::EMIE_RMOUSE_TRIPLE_CLICK: - mevent->action = MouseEvent::RTripleClick; - break; - case irr::EMIE_MMOUSE_TRIPLE_CLICK: - mevent->action = MouseEvent::MTripleClick; - break; - case irr::EMIE_MOUSE_MOVED: - mevent->action = MouseEvent::Moved; - break; - case irr::EMIE_MOUSE_WHEEL: - mevent->action = MouseEvent::Wheel; - break; - } - event = mevent; - return true; - } - case irr::EET_KEY_INPUT_EVENT: -#if 0 // Ignore keyboard event - I don't really need it while testing - hrgEvent.type = InputEventType::KeyboardEvent; - hrgEvent.key.Char = irrEvent.KeyInput.Char; - hrgEvent.key.keyCode = KeyCode(irrEvent.KeyInput.Key); - hrgEvent.key.pressedDown = irrEvent.KeyInput.PressedDown; - hrgEvent.key.control = irrEvent.KeyInput.Control; - hrgEvent.key.shift = irrEvent.KeyInput.Shift; - return true; -#endif - default: - return false; - } -} - -InputManager::InputManager(irr::IrrlichtDevice* device) - : device(device) -{ - device->setEventReceiver(this); - cursor_ = device->getCursorControl(); -} - -bool InputManager::OnEvent(const irr::SEvent& event) -{ - Event* hrEvent; - bool convert = convertEvent(event, hrEvent); - - if(!convert) - return false; - - for(auto listener : receivers_) { - listener->onEvent(hrEvent); - } - - // return false, so Irrlicht processes other events - return false; -} - -bool InputManager::registerReceiver(EventListener* receiver) -{ - receivers_.push_front(receiver); - return true; -} - -bool InputManager::unregisterReceiver(EventListener* receiver) -{ - //remove from mReceivers - - return true; -} -} // namespace impl -} // namespace io -} // namespace aw diff --git a/gui/IrrEngine.cpp b/gui/IrrEngine.cpp deleted file mode 100644 index bbce94c0..00000000 --- a/gui/IrrEngine.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include - -namespace aw { -namespace gui { -/* -IrrSkin::~IrrSkin() -{ -}*/ - -void IrrEngine::drawBorder(Rect const& rect, Border* style) -{ - switch (style->style()) { - case Border::None: - return; - case Border::Solid: - case Border::Outward: - case Border::Inward: - drawSolidBorder(toPixels(rect, getScreenSize()), - style->plain()); - break; - case Border::Image: - // drawImageBorder(toPixels(rect, getScreenSize()), style->image()); - break; - } -} - -void IrrEngine::drawSolidBorder(Rect rect, BorderPlain* style) -{ - auto color = style->color(); - auto width = style->width(); - - Rect tmp; - - if (style->style() == Border::Inward) { - u32 rest = width - width / 2; - - // top dark - tmp = rect; - tmp.lowerRight.y() = tmp.upperLeft.y() + rest; - drawRect(tmp, graphics::darken(color, 200)); - - if ((width / 2) > 0) { - // top bright - tmp = rect; - tmp.lowerRight.y() = tmp.upperLeft.y() + width; - tmp.upperLeft += rest; - drawRect(tmp, graphics::darken(color, 127)); - } - - // left dark - tmp = rect; - tmp.lowerRight.x() = tmp.upperLeft.x() + rest; - drawRect(tmp, graphics::darken(color, 200)); - - if ((width / 2) > 0) { - // left bright - tmp = rect; - tmp.lowerRight.x() = tmp.upperLeft.x() + width; - tmp.upperLeft += rest; - drawRect(tmp, graphics::darken(color, 127)); - } - } else { - // top - tmp = rect; - tmp.lowerRight.y() = tmp.upperLeft.y() + width; - drawRect(tmp, color); - - // left - tmp = rect; - tmp.lowerRight.x() = tmp.upperLeft.x() + width; - drawRect(tmp, color); - } - - - if (style->style() == Border::Outward) { - u32 rest = width - width / 2; - // bottom dark - tmp = rect; - tmp.upperLeft.y() = tmp.lowerRight.y() - rest; - drawRect(tmp, graphics::darken(color, 200)); - - if ((width / 2) > 0) { - // bottom bright - tmp = rect; - tmp.upperLeft.y() = tmp.lowerRight.y() - width; - tmp.lowerRight.y() = tmp.lowerRight.y() - rest; - tmp.lowerRight.x() -= rest; - drawRect(tmp, graphics::darken(color, 127)); - } - - // right dark - tmp = rect; - tmp.upperLeft.x() = tmp.lowerRight.x() - rest; - drawRect(tmp, graphics::darken(color, 200)); - - if ((width / 2) > 0) { - // right bright - tmp = rect; - tmp.upperLeft.x() = tmp.lowerRight.x() - width; - tmp.lowerRight.x() = tmp.lowerRight.x() - rest; - tmp.lowerRight.y() -= rest; - drawRect(tmp, graphics::darken(color, 127)); - } - } else { - // bottom - tmp = rect; - tmp.upperLeft.y() = tmp.lowerRight.y() - width; - tmp.upperLeft.x() += width; - drawRect(tmp, color); - - // right - tmp = rect; - tmp.upperLeft.x() = tmp.lowerRight.x() - width; - tmp.upperLeft.y() += width; - drawRect(tmp, color); - } -} - -void IrrEngine::drawBackground(Rect const& rect, Background* style) -{ - switch (style->style()) { - case Background::None: - //core::Logger::debug("[GUI] IrrEngine: Drawing empty bg"); - return; - case Background::Solid: - //core::Logger::debug("[GUI] IrrEngine: Drawing solid bg"); - drawRect(toPixels(rect, getScreenSize()), - style->solid()->color()); - break; - case Background::Gradient: { - //core::Logger::debug("[GUI] IrrEngine: Drawing gradient bg"); - auto s = style->gradient(); - auto c1 = s->color(Corner::TopLeft); - auto c2 = s->color(Corner::BottomLeft); - auto c3 = s->color(Corner::BottomRight); - auto c4 = s->color(Corner::TopRight); - drawRect(toPixels(rect, getScreenSize()), - c1, c2, c3, c4); - } - break; - case Background::Image: - // drawImageBorder(toPixels(rect, getScreenSize()), style->image()); - break; - } -} - -void IrrEngine::drawRect(Rect r, graphics::Color c) -{ - auto rect = toIrr(r); - auto color = toIrr(c); - driver->draw2DRectangle(color, rect); -} - -void IrrEngine::drawRect(Rect r, - graphics::Color c1, graphics::Color c2, - graphics::Color c3, graphics::Color c4) -{ - /*core::Logger::debug("[GUI] IrrEngine: Drawing rect: (" + - std::to_string(r.upperLeft.x()) + ", " + - std::to_string(r.upperLeft.y()) + ", " + - std::to_string(r.lowerRight.x()) + ", " + - std::to_string(r.lowerRight.y()) + ").");*/ - auto rect = toIrr(r); - auto lu = toIrr(c1); - auto ld = toIrr(c2); - auto rd = toIrr(c3); - auto ru = toIrr(c4); - driver->draw2DRectangle(rect, lu, ru, ld, rd); -} - -/* -void IrrRenderer::drawTitleBar(irr::core::rect r) -{ - rect = r; - rect.UpperLeftCorner.X += 2; - rect.UpperLeftCorner.Y += 2; - rect.LowerRightCorner.X -= 2; - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + getSize(EGDS_WINDOW_BUTTON_WIDTH) + 2; - - const irr::video::SColor c = titleBarColor.getInterpolated( irr::video::SColor(titleBarColor.getAlpha(),255,255,255), 0.8f); - driver->draw2DRectangle(rect, titleBarColor, titleBarColor, c, c); -}*/ -} // namespace gui -} // namespace aw diff --git a/gui/Style.cpp b/gui/Style.cpp deleted file mode 100644 index a143a505..00000000 --- a/gui/Style.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#include -namespace aw { -namespace gui { -void Style::initDefaults() -{ - ElementStyle windowStyle; - - windowStyle.setBorderStyle(std::make_unique(2,0xFFFFFFFF)); - windowStyle.setBackgroundStyle(std::make_unique( - 0xFF969696, 0xFF646464, - 0xFF646464, 0xFF969696)); - - properties["window"] = std::move(windowStyle); - - /* - properties["border-color"] = hdf::Value(0xFFFFFFFF); - properties["background-color"] = hdf::Value(0xFF969696); - - properties["window.border"] = hdf::Value("outset"); - properties["window.border-width"] = hdf::Value(2); - properties["window.border-color"] = hdf::Value(); - - properties["window.background"] = hdf::Value("gradient"); - properties["window.background-color-upper-left"] = - hdf::Value(0xFF969696); - properties["window.background-color-upper-right"] = - hdf::Value(0xFF969696); - properties["window.background-color-lower-left"] = - hdf::Value(0xFF646464); - properties["window.background-color-lower-right"] = - hdf::Value(0xFF646464); - - properties["titlebar.background-color"] = hdf::Value(0xFF9696C8);*/ -} -} // namespace gui -} // namespace aw diff --git a/gui/Window.cpp b/gui/Window.cpp deleted file mode 100644 index 2d1dc556..00000000 --- a/gui/Window.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#include - -#include -#include -#include - -namespace aw { -namespace gui { -bool Window::onEvent(Event* event) -{ - if(Canvas::onEvent(event)) - return true; - - bool consume = false; - if (event->getType() == MouseEvent::type()) { - consume = processEvent(event_cast(event)); - } else if (event->getType() == GUIEvent::type()) { - consume = processEvent(event_cast(event)); - } - - return consume; -} - -void Window::accept(Visitor& visitor) -{ - visitor.visit(this); -} - -Rect Window::getClientRect() const -{ - if (updateClientRect) - recalculateClientRect(); - - return clientRect; -} - -void Window::recalculateClientRect() const -{ - clientRect = getAbsoluteRect(); - auto style = getStyle()->getElementStyle("window"); - auto border = style->getBorderStyle(); - - u8 borderWidth = 0; - - switch(border->style()) { - case Border::None: - break; - case Border::Solid: - case Border::Inward: - case Border::Outward: - borderWidth = border->plain()->width(); - break; - case Border::Image: - borderWidth = border->image()->slice(); - break; - } - - clientRect.upperLeft += borderWidth; - clientRect.lowerRight -= borderWidth; - - updateClientRect = false; -} - -inline Vector2d localToWorld( - Vector2d const& local, - Rect const& parent) -{ - auto width = parent.getWidth(); - auto height = parent.getHeight(); - auto temp = parent.upperLeft; - - temp.x() += width * local.x().fraction + local.x().offset; - temp.y() += height * local.y().fraction + local.y().offset; - - return temp; -} - -inline Coordinate worldToLocal( - Coordinate const& world, - Coordinate const& origin, - Coordinate const& width) -{ - Coordinate temp = world - origin; - if (math::equals(width.fraction, 0.0f)) { - return temp; - } else if(math::equals(width.offset,0.0f)) { - temp.fraction /= width.fraction; - return temp; - } - - temp /= width; - i32 offset = width.offset * (temp.offset - temp.fraction); - - temp.offset = offset; - return temp; -} - -inline Vector2d worldToLocal( - Vector2d const& world, - Rect const& parent) -{ - auto width = parent.getWidth(); - auto height = parent.getHeight(); - - Vector2d temp(0,0); - temp.x() = worldToLocal(world.x(), parent.upperLeft.x(), width); - temp.y() = worldToLocal(world.y(), parent.upperLeft.y(), height); - - return temp; -} - -bool Window::mouseMoved(MouseEvent* event) -{ - if (!dragging) - return false; - - auto const& mousePos = event->position; - auto const& bounds = event->bounds; - auto parentRect = getParent()->getAbsoluteRect(); - - Vector2d pos(mousePos.x(), mousePos.y()); - pos = worldToLocal(pos, parentRect); - - Vector2d start(mouseStart.x(), mouseStart.y()); - start = worldToLocal(start, parentRect); - - mouseStart = mousePos; - - Vector2d delta = pos - start; - - auto oldPos = getPosition(); - auto newPos = oldPos + delta; - - setPosition(newPos); - - auto absoluteRect = toPixels(getAbsoluteRect(), bounds); - auto absoluteParentRect = toPixels(parentRect, bounds); - - if (absoluteRect.upperLeft.x() < absoluteParentRect.upperLeft.x() || - absoluteRect.upperLeft.y() < absoluteParentRect.upperLeft.y() || - absoluteRect.lowerRight.x() > absoluteParentRect.lowerRight.x() || - absoluteRect.lowerRight.y() > absoluteParentRect.lowerRight.y()) { - setPosition(oldPos); - return true; - } - return true; -} - -bool Window::processEvent(MouseEvent* event) -{ - switch (event->action) { - case MouseEvent::Moved: - return mouseMoved(event); - case MouseEvent::LButtonDown: - mouseStart = event->position; - dragging = isDraggable; - return true; - case MouseEvent::LButtonUp: - dragging = false; - return true; - default: - break; - } - return false; -} - -bool Window::processEvent(GUIEvent* event) -{ - switch (event->action) { - case GUIEvent::Focused: - if (getParent()) { - getParent()->toCanvas()->bringToFront(this); - } - return true; - case GUIEvent::FocusLost: - dragging = false; - return true; - default: - break; - } - return false; -} -/* -void Window::move(Vector2d delta) -{ - // TODO: check if within the parent's rectangle -}*/ -} // namespace gui -} // namespace aw diff --git a/gui/include/aw/gui/Canvas.h b/gui/include/aw/gui/Canvas.h deleted file mode 100644 index 205163f2..00000000 --- a/gui/include/aw/gui/Canvas.h +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUI_canvas_ -#define _aw_GUI_canvas_ -#include - -#include -namespace aw { -namespace gui { -class Canvas : public Element { -public: - typedef std::vector> elements_t; - - Canvas() = default; - virtual ~Canvas() = default; - - /*! - * Add a child element - */ - virtual void addElement(std::unique_ptr e); - - /*! - * Remove child. Returns unique_ptr to detached child, - * allowing to rebind it to different object. - */ - virtual std::unique_ptr removeElement(Element* e); - - /*! - * Get currently active element (which is - * currently being interacted with). - */ - virtual Element* getActiveElement(); - - void bringToFront(Element* e); - void sendToBack(Element* e); - virtual bool onEvent(Event* event); - virtual void accept(Visitor& visitor); - - virtual Canvas* toCanvas() - { - return this; - } - - virtual Widget* toWidget() - { - return nullptr; - } - - class iterator : - public std::iterator { - public: - typedef elements_t::const_iterator base_t; - - iterator(base_t base) - : base(base) - {} - - reference operator*() const - { - return **base; - } - - pointer operator->() const - { - return (*base).get(); - } - - iterator& operator++() - { - ++base; - return *this; - } - - iterator& operator--() - { - --base; - return *this; - } - - bool operator == (iterator const& other) - { - return base == other.base; - } - - bool operator != (iterator const& other) - { - return base != other.base; - } - - bool operator == (base_t const& other) - { - return base == other; - } - - bool operator != (base_t const& other) - { - return base != other; - } - private: - friend class Canvas; - base_t base; - }; - - typedef std::reverse_iterator reverse_iterator; - - virtual iterator getFirstChild() const - { - return iterator(std::begin(elements)); - } - virtual iterator getLastChild() const - { - return iterator(std::end(elements)); - } - - virtual reverse_iterator rbegin() const - { - return reverse_iterator(std::rbegin(elements)); - } - virtual reverse_iterator rend() const - { - return reverse_iterator(std::rend(elements)); - } - - iterator findElement(Element* e) const; - - virtual void invalidate() - { - Element::invalidate(); - } -protected: - void makeActive(Element* element) { - // TODO: assert(isChild(element)); - active = element; - } - Element* getElementFromPoint(Vector2d point, Vector2d bounds); - -private: - elements_t::iterator findElement(Element* e); - bool processEvent(MouseEvent* event); - bool processEvent(GUIEvent* event); - - elements_t elements; - Element* active; - Element* hovered; -}; - -inline Canvas::iterator begin(Canvas* canvas) -{ - return canvas->getFirstChild(); -} - -inline Canvas::iterator end(Canvas* canvas) -{ - return canvas->getLastChild(); -} - -inline auto rbegin(Canvas& canvas) -{ - return Canvas::reverse_iterator(canvas.getLastChild()); -} - -inline auto rend(Canvas& canvas) -{ - return Canvas::reverse_iterator(canvas.getFirstChild()); -} -} // namespace gui -} // namespace aw -#endif //_aw_GUI_canvas_ diff --git a/gui/include/aw/gui/Coordinate.h b/gui/include/aw/gui/Coordinate.h deleted file mode 100644 index dfda369d..00000000 --- a/gui/include/aw/gui/Coordinate.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_gui_Coordinate_ -#define _aw_gui_Coordinate_ -#include - -namespace aw { -namespace gui { - -struct Coordinate { - Coordinate(f32 fraction) - : fraction(fraction), offset(0) - {} - Coordinate(f64 fraction) - : fraction(fraction), offset(0) - {} - Coordinate(i32 offset) - : fraction(0.0), offset(offset) - {} - Coordinate(f32 fraction, i32 offset) - : fraction(fraction), offset(offset) - {} - - Coordinate operator +(Coordinate const& other) const - { - return Coordinate(fraction + other.fraction, - offset + other.offset); - } - Coordinate operator -(Coordinate const& other) const - { - return Coordinate(fraction - other.fraction, - offset - other.offset); - } - Coordinate operator *(Coordinate const& other) const - { - return Coordinate(fraction * other.fraction, - offset * other.offset); - } - Coordinate operator /(Coordinate const& other) const - { - return Coordinate(fraction / other.fraction, - offset / other.offset); - } - - Coordinate operator + (i32 v) const - { - return Coordinate(fraction, - offset + v); - } - Coordinate operator - (i32 v) const - { - return Coordinate(fraction, - offset - v); - } - - Coordinate operator * (f32 v) const - { - return Coordinate(fraction * v, - offset * v); - } - Coordinate operator / (f32 v) const - { - return Coordinate(fraction / v, - offset / v); - } - - Coordinate& operator +=(Coordinate const& other) - { - fraction += other.fraction; - offset += other.offset; - return *this; - } - Coordinate& operator -=(Coordinate const& other) - { - fraction -= other.fraction; - offset -= other.offset; - return *this; - } - Coordinate& operator *=(Coordinate const& other) - { - fraction *= other.fraction; - offset *= other.offset; - return *this; - } - Coordinate& operator /=(Coordinate const& other) - { - fraction /= other.fraction; - offset /= other.offset; - return *this; - } - Coordinate& operator +=(i32 v) - { - offset += v; - return *this; - } - Coordinate& operator -=(i32 v) - { - offset -= v; - return *this; - } - - /*! - * Fraction of a parent element's size - */ - f32 fraction; - /*! - * Offset in pixels, applied after calculating - * the fraction - */ - f32 offset; -}; - -inline Vector2d toPixels(Vector2d const& vec, - Vector2d const& screen) -{ - Vector2d tmp; - tmp.x() = vec.x().fraction * screen.x(); - tmp.x() += vec.x().offset; - tmp.y() = vec.y().fraction * screen.y(); - tmp.y() += vec.y().offset; - return tmp; -} - -inline Rect toPixels(Rect const& rect, - Vector2d const& screen) -{ - Rect tmp; - tmp.upperLeft.x() = rect.upperLeft.x().fraction * screen.x(); - tmp.upperLeft.x() += rect.upperLeft.x().offset; - tmp.upperLeft.y() = rect.upperLeft.y().fraction * screen.y(); - tmp.upperLeft.y() += rect.upperLeft.y().offset; - tmp.lowerRight.x() = rect.lowerRight.x().fraction * screen.x(); - tmp.lowerRight.x() += rect.lowerRight.x().offset; - tmp.lowerRight.y() = rect.lowerRight.y().fraction * screen.y(); - tmp.lowerRight.y() += rect.lowerRight.y().offset; - return tmp; -} - -} // namespace gui -} // namespace aw -#endif//_aw_gui_Coordinate_ diff --git a/gui/include/aw/gui/Cursor.h b/gui/include/aw/gui/Cursor.h deleted file mode 100644 index b37fe361..00000000 --- a/gui/include/aw/gui/Cursor.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_Cursor_ -#define _aw_Cursor_ - -namespace aw { -namespace graphics { - -} // namespace graphics -} // namespace aw -#endif//_aw_Cursor_ diff --git a/gui/include/aw/gui/Drawer.h b/gui/include/aw/gui/Drawer.h deleted file mode 100644 index 3089ab67..00000000 --- a/gui/include/aw/gui/Drawer.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_gui_drawer_ -#define _aw_gui_drawer_ -#include - -namespace aw { -namespace gui { -class Engine; - -//! Drawing visitor. Used for GUI rendering. -class Drawer : public Visitor { -public: - Drawer(Engine& engine) - : engine(engine) - { - } - virtual ~Drawer(); - - virtual void visit(Element* element); - virtual void visit(Canvas* element); - virtual void visit(Window* element); - virtual void visit(Widget* element); -private: - void drawChildren(Canvas* element); - - Engine& engine; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_gui_drawer_ diff --git a/gui/include/aw/gui/Element.h b/gui/include/aw/gui/Element.h deleted file mode 100644 index 092b3aff..00000000 --- a/gui/include/aw/gui/Element.h +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUIElement_ -#define _aw_GUIElement_ -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace aw { -namespace gui { -class Canvas; -class Widget; -class Style; -class Visitor; - -//! Base class for GUI elements -class Element : public EventListener { -public: - virtual ~Element() = default; - - /*! - * Returns pointer to parent element. - */ - virtual Element* getParent() const - { - return parent; - } - - virtual Vector2d getPosition() - { - return rect.getUpperLeft(); - } - - virtual Vector2d getAbsolutePosition() - { - return absoluteRect.getUpperLeft(); - } - - virtual Coordinate getWidth() const - { - return rect.getWidth(); - } - - virtual Coordinate getHeight() const - { - return rect.getHeight(); - } - - virtual Rect getRect() const - { - return rect; - } - - virtual Rect getAbsoluteRect() const - { - // Absolute rect needs updating (element moved, - // parent moved, etc) - if (updateAbsoluteRect) - recalculateAbsoluteRect(); - - return absoluteRect; - } - - virtual Style* getStyle() const - { - if (!style) - return parent->getStyle(); - - return style; - } - - virtual void setPosition(Vector2d position) - { - rect.setPosition(position); - invalidate(); - } - - virtual void setWidth(Coordinate width) - { - rect.setWidth(width); - invalidate(); - } - - virtual void setHeight(Coordinate height) - { - rect.setHeight(height); - invalidate(); - } - - virtual void setRect(Rect newRect) - { - rect = newRect; - invalidate(); - } - - void setParent(Element* newParent) - { - parent = newParent; - invalidate(); - } - - void removeParent() - { - parent = nullptr; - invalidate(); - } - - virtual void setStyle(Style* newStyle) - { - // TODO: if newStyle == parent->style, should it be reset to 0? - style = newStyle; - invalidate(); - } - - - virtual Canvas* toCanvas() = 0; - virtual Widget* toWidget() = 0; - - /*! - * Accept a GUI Element Visitor. Useful for performing - * various operations on Elements and their children. - */ - virtual void accept(gui::Visitor& visitor) = 0; - - /*! - * Receive event. - * Most commonly used to receive user input. - * \return - * true if event was consumed. - */ - virtual bool onEvent(Event* event) = 0; - - virtual void invalidate() - { - updateAbsoluteRect = true; - } - - void setName(std::string name) - { - } -protected: - Element() - : parent(nullptr), updateAbsoluteRect(true) - { - } -private: - void recalculateAbsoluteRect() const - { - if (!getParent()) { - absoluteRect = getRect(); - return; - } - - // compute parent rect - Rect parentRect = parent->getAbsoluteRect(); - Coordinate height = parentRect.getHeight(); - Coordinate width = parentRect.getWidth(); - - // references to local rect coordinates, for convenience - auto& ulx = rect.upperLeft.x(); - auto& uly = rect.upperLeft.y(); - auto& lrx = rect.lowerRight.x(); - auto& lry = rect.lowerRight.y(); - - // go from local coordinates to absolute (move origin) - Rect temp; - temp.upperLeft = parentRect.upperLeft; - temp.lowerRight = parentRect.upperLeft; - - // compute using Coordinate's definition: - // parent_dimension * fraction + offset - temp.upperLeft.x() += width * ulx.fraction + ulx.offset; - temp.upperLeft.y() += height * uly.fraction + uly.offset; - temp.lowerRight.x() += width * lrx.fraction + lrx.offset; - temp.lowerRight.y() += height * lry.fraction + lry.offset; - - absoluteRect = temp; - updateAbsoluteRect = false; - } - - Rect rect; - - mutable bool updateAbsoluteRect; - mutable Rect absoluteRect; - - Style* style; - Element* parent; -}; - -inline bool pointWithinElement(Vector2d point, - Element const& element, - Vector2d screen) -{ - auto rect = element.getAbsoluteRect(); - Rect screenRect = toPixels(rect, screen); - return pointWithinRect(point, screenRect); -} - -} // namespace gui -} // namespace aw -#endif //_aw_GUIElement_ diff --git a/gui/include/aw/gui/Engine.h b/gui/include/aw/gui/Engine.h deleted file mode 100644 index ad6c028c..00000000 --- a/gui/include/aw/gui/Engine.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUI_skin_ -#define _aw_GUI_skin_ -#include -#include - -namespace aw { -namespace gui { -class Border; -class Background; - -class Engine { -public: - virtual ~Engine() = default; - - virtual void drawBorder(Rect const& rect, - Border* style) = 0; - virtual void drawBackground(Rect const& rect, - Background* style) = 0; -}; -} // namespace gui -} // namespace aw -#endif //_aw_GUI_skin_ diff --git a/gui/include/aw/gui/GUIEvent.h b/gui/include/aw/gui/GUIEvent.h deleted file mode 100644 index de11e5c6..00000000 --- a/gui/include/aw/gui/GUIEvent.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUIEvent_ -#define _aw_GUIEvent_ -#include -#include -#include -namespace aw { -namespace gui { - -struct GUIEvent : public EventId{ -public: - enum Action { - Unknown, - Closed, - Hovered, - Left, - Focused, - Unfocused, - FocusLost = Unfocused, - }; - - Action action; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_GUIEvent_ diff --git a/gui/include/aw/gui/InputManager.h b/gui/include/aw/gui/InputManager.h deleted file mode 100644 index c72ce61f..00000000 --- a/gui/include/aw/gui/InputManager.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_InputManager_ -#define _aw_InputManager_ -#include -#include - -#include -#include -#include - -namespace aw { -namespace gui { -//! Handles user input and generates input events -class InputManager { -public: - virtual bool registerReceiver(EventListener* receiver) = 0; - virtual bool unregisterReceiver(EventListener* receiver) = 0; - - #if 0 - virtual void seizeControl(bool seizeCusror, bool seizeKeyboard) = 0; - #endif -}; -} // namespace io -} // namespace aw -#endif//_aw_InputManager_ diff --git a/gui/include/aw/gui/KeyboardEvent.h b/gui/include/aw/gui/KeyboardEvent.h deleted file mode 100644 index 805f6cc3..00000000 --- a/gui/include/aw/gui/KeyboardEvent.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_KeyboardEvent_ -#define _aw_KeyboardEvent_ -#include -#include -#include - -namespace aw { -namespace gui { -struct KeyboardEvent : public EventId { - KeyCode keyCode; - u32 Char; - bool pressedDown:1; - bool shift:1; - bool control:1; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_KeyboardEvent_ diff --git a/gui/include/aw/gui/ListBox.h b/gui/include/aw/gui/ListBox.h deleted file mode 100644 index 15ff4131..00000000 --- a/gui/include/aw/gui/ListBox.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUIListBox_ -#define _aw_GUIListBox_ - -#include - -#include - -namespace aw { -namespace gui { - -//! List box GUI element -class GUIListBox : public GUIElement { -public: - virtual ~GUIListBox() {}; - - /*! Add an item to list box - \param text Text of the inserted item - \return Item id - */ - virtual u32 addItem(std::string text) = 0; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_GUIListBox_ diff --git a/gui/include/aw/gui/Menu.h b/gui/include/aw/gui/Menu.h deleted file mode 100644 index 8d080dd4..00000000 --- a/gui/include/aw/gui/Menu.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ diff --git a/gui/include/aw/gui/MouseEvent.h b/gui/include/aw/gui/MouseEvent.h deleted file mode 100644 index dcba94d1..00000000 --- a/gui/include/aw/gui/MouseEvent.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_MouseEvent_ -#define _aw_MouseEvent_ -#include -#include - -namespace aw { -namespace gui { -enum MouseState { - MOUSE_LEFT = 0x01, - MOUSE_RIGHT = 0x02, - MOUSE_MIDDLE = 0x04 -}; - -class MouseEvent : public EventId { -public: - enum Action { - Moved, - Wheel, - LButtonDown, - RButtonDown, - MButtonDown, - LButtonUp, - RButtonUp, - MButtonUp, - LDoubleClick, - RDoubleClick, - MDoubleClick, - LTripleClick, - RTripleClick, - MTripleClick - }; - - Action action; - Vector2d position; - Vector2d bounds; - f32 wheel; - u8 buttonStates; -}; -} // namespace gui -} // namespace aw -#endif //_aw_MouseEvent_ diff --git a/gui/include/aw/gui/ScrollBar.h b/gui/include/aw/gui/ScrollBar.h deleted file mode 100644 index 8d080dd4..00000000 --- a/gui/include/aw/gui/ScrollBar.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ diff --git a/gui/include/aw/gui/Style.h b/gui/include/aw/gui/Style.h deleted file mode 100644 index 65cae066..00000000 --- a/gui/include/aw/gui/Style.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUI_Style_ -#define _aw_GUI_Style_ -#include -#include - -#include -#include - -namespace aw { -namespace gui { -class AW_GUI_EXP Style { -public: - virtual ~Style() = default; - - void initDefaults(); - - ElementStyle* getElementStyle(std::string element) - { - auto found = properties.find(element); - - if (found != properties.end()) { - return &found->second; - } - - return nullptr; - } - - void setElementStyle(std::string element, ElementStyle style) - { - properties[element] = std::move(style); - } -private: - std::map properties; -}; -} // namespace gui -} // namespace aw -#endif //_aw_GUI_Style_ diff --git a/gui/include/aw/gui/TextArea.h b/gui/include/aw/gui/TextArea.h deleted file mode 100644 index 8d080dd4..00000000 --- a/gui/include/aw/gui/TextArea.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ diff --git a/gui/include/aw/gui/TextBox.h b/gui/include/aw/gui/TextBox.h deleted file mode 100644 index 7cba1c0d..00000000 --- a/gui/include/aw/gui/TextBox.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUITextBox_ -#define _aw_GUITextBox_ - -#include - -namespace aw { -namespace gui { - -//! Text box GUI element -class GUITextBox : public GUIElement { -public: - virtual ~GUITextBox() {}; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_GUITextBox_ diff --git a/gui/include/aw/gui/Visitor.h b/gui/include/aw/gui/Visitor.h deleted file mode 100644 index b125cd81..00000000 --- a/gui/include/aw/gui/Visitor.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_gui_visitor_ -#define _aw_gui_visitor_ -namespace aw { -namespace gui { -class Element; -class Canvas; -class Widget; -class Window; - -//! Base class for GUI visitor (see Visitor pattern) -class Visitor { -public: - virtual ~Visitor() = default; - - virtual void visit(Element* element) = 0; - virtual void visit(Canvas* element) = 0; - virtual void visit(Window* element) = 0; - virtual void visit(Widget* element) = 0; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_gui_visitor_ diff --git a/gui/include/aw/gui/Widget.h b/gui/include/aw/gui/Widget.h deleted file mode 100644 index 1f3d8a95..00000000 --- a/gui/include/aw/gui/Widget.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_gui_widget_ -#define _aw_gui_widget_ -#include - -namespace aw { -namespace gui { -//! Base class for GUI widget -class Widget : public Element { -public: - virtual ~Widget() {}; - virtual Canvas* toCanvas() - { - return nullptr; - } - virtual Widget* toWidget() - { - return this; - } -}; - -} // namespace gui -} // namespace aw -#endif //_aw_gui_widget_ diff --git a/gui/include/aw/gui/Window.h b/gui/include/aw/gui/Window.h deleted file mode 100644 index 2e215d55..00000000 --- a/gui/include/aw/gui/Window.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2014 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUIWindow_ -#define _aw_GUIWindow_ -#include - -namespace aw { -namespace gui { - -//! Typical “Window” with a title bar -class Window : public Canvas { -public: - Window() = default; - virtual ~Window() = default; - - virtual bool onEvent(Event* event); - virtual void accept(Visitor& visitor); - - virtual Rect getClientRect() const; - - virtual void setDraggable(bool draggable) - { - isDraggable = draggable; - } - - virtual void invalidate() - { - Canvas::invalidate(); - updateClientRect = true; - } -protected: - virtual void recalculateClientRect() const; -private: - bool processEvent(MouseEvent* event); - bool mouseMoved(MouseEvent* event); - //bool processEvent(KeyboardEvent* event); - bool processEvent(GUIEvent* event); - - mutable bool updateClientRect; - mutable Rect clientRect; - - bool dragging; - bool resizing; - Vector2d mouseStart; - - bool hasTitlebar; - bool isDraggable; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_GUIWindow_ diff --git a/gui/include/aw/gui/gui.h b/gui/include/aw/gui/gui.h deleted file mode 100644 index 724eb736..00000000 --- a/gui/include/aw/gui/gui.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2014-2016 absurdworlds - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_gui_ -#define _aw_gui_ -#include - -#ifdef AW_MODULE_GUI - #define AW_GUI_EXP AW_EXPORT -#else - #define AW_GUI_EXP AW_IMPORT -#endif -#endif//_aw_gui_ diff --git a/gui/include/aw/gui/style/Background.h b/gui/include/aw/gui/style/Background.h deleted file mode 100644 index 0ca029d3..00000000 --- a/gui/include/aw/gui/style/Background.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUI_Background_ -#define _aw_GUI_Background_ -#include - -#include -#include - -namespace aw { -namespace gui { -class BackgroundNone; -class BackgroundSolid; -class BackgroundGradient; -class BackgroundImage; - -class Background { -public: - enum Style { - None, - Solid, - Gradient, - Image - }; - - virtual BackgroundNone* none() - { - return nullptr; - } - virtual BackgroundSolid* solid() - { - return nullptr; - } - virtual BackgroundGradient* gradient() - { - return nullptr; - } - virtual BackgroundImage* image() - { - return nullptr; - } - - Style style() const - { - return s; - } -public: - Background(Style style) - : s(style) - { - } - -private: - - Style s; -}; - -class BackgroundNone : public Background { -public: - BackgroundNone() - : Background(Background::None) - { - } - - virtual BackgroundNone* none() - { - return this; - } -}; - -class BackgroundSolid : public Background { -public: - BackgroundSolid(Style s, graphics::Color color) - : Background(Background::Solid), c(color) - { - } - - graphics::Color color() const - { - return c; - } - virtual BackgroundSolid* solid() - { - return this; - } -private: - graphics::Color c; -}; - -class BackgroundGradient : public Background { -public: - /*! - * Construct a Backfround Gradient with colors c1-c4. - * - * Colors c1-c4 located in corners, starting from - * top left, and going counter-clockwise: - * - * c1 ----- c4 - * | | - * c2 ----- c3 - */ - BackgroundGradient( - graphics::Color c1, graphics::Color c2, - graphics::Color c3, graphics::Color c4) - : Background(Background::Gradient), colors({c1, c2, c3, c4}) - { - } - - graphics::Color color(Corner pos) const - { - size_t tmp = size_t(pos); - return tmp < 4 ? colors[tmp] : graphics::Color(0); - } - - virtual BackgroundGradient* gradient() - { - return this; - } -private: - std::array colors; -}; - -class BackgroundImage : public Background { -public: - BackgroundImage(std::string path, - ImageRepeat tiling = ImageRepeat::Stretch) - : Background(Background::Image), img(path), tiling(tiling) - { - } - - std::string path() const - { - return img; - } - - ImageRepeat repeat() const - { - return tiling; - } - virtual BackgroundImage* image() - { - return this; - } -private: - std::string img; - ImageRepeat tiling; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_GUI_Background_ diff --git a/gui/include/aw/gui/style/Border.h b/gui/include/aw/gui/style/Border.h deleted file mode 100644 index bd092f48..00000000 --- a/gui/include/aw/gui/style/Border.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUI_Border_ -#define _aw_GUI_Border_ -#include - -#include -#include -#include - -namespace aw { -namespace gui { -class BorderNone; -class BorderPlain; -class BorderSolid; -class BorderInward; -class BorderOutward; -class BorderImage; - -class Border { -public: - enum Style { - None, - Solid, - Inward, - Outward, - Image - }; - - virtual BorderNone* none() - { - return nullptr; - } - virtual BorderPlain* plain() - { - return nullptr; - } - virtual BorderSolid* solid() - { - return nullptr; - } - virtual BorderInward* inward() - { - return nullptr; - } - virtual BorderOutward* outward() - { - return nullptr; - } - virtual BorderImage* image() - { - return nullptr; - } - - Style style() - { - return s; - } - -protected: - Border(Style s) - : s(s) - { - } - - Style s; -}; - -class BorderNone : public Border { -public: - BorderNone() - : Border(Border::None) - { - } - - virtual BorderNone* none() - { - return this; - } -}; - -class BorderPlain : public Border { -protected: - BorderPlain(u8 width, graphics::Color color, Border::Style s) - : w(width), c(color), Border(s) - { - } - -public: - u8 width() const - { - return w; - } - - graphics::Color color() const - { - return c; - } - - virtual BorderPlain* plain() - { - return this; - } -private: - //! Border width in pixels - u8 w; - graphics::Color c; - -}; - -class BorderSolid : public BorderPlain { -public: - BorderSolid(u8 width, graphics::Color color) - : BorderPlain(width, color, Border::Solid) - { - } - - virtual BorderSolid* solid() - { - return this; - } -}; - -class BorderInward : public BorderPlain { -public: - BorderInward(u8 width, graphics::Color color) - : BorderPlain(width, color, Border::Inward) - { - } - - virtual BorderInward* inward() - { - return this; - } -}; - -class BorderOutward : public BorderPlain { -public: - BorderOutward(u8 width, graphics::Color color) - : BorderPlain(width, color, Border::Outward) - { - } - - virtual BorderOutward* outward() - { - return this; - } -}; - -class BorderImage : public Border { -public: - BorderImage(std::string path, - u8 slice, - ImageRepeat mode = ImageRepeat::Tile) - : img(path), mode(mode), Border(Border::Image) - { - } - - std::string path() const - { - return img; - } - - u8 slice() const - { - return width; - } - - ImageRepeat repeat() const - { - return mode; - } - - virtual BorderImage* image() - { - return this; - } -private: - std::string img; - u8 width; - ImageRepeat mode; -}; - -} // namespace gui -} // namespace aw -#endif //_aw_GUI_Border_ diff --git a/gui/include/aw/gui/style/ElementStyle.h b/gui/include/aw/gui/style/ElementStyle.h deleted file mode 100644 index 9964d57e..00000000 --- a/gui/include/aw/gui/style/ElementStyle.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUI_ElementStyle_ -#define _aw_GUI_ElementStyle_ -#include -#include -#include - -#include -#include - -namespace aw { -namespace gui { -class ElementStyle { -public: - ElementStyle() = default; - ~ElementStyle() = default; - - ElementStyle(ElementStyle&& other) - { - border = std::move(other.border); - background = std::move(other.background); - } - - ElementStyle& operator =(ElementStyle&& other) - { - border = std::move(other.border); - background = std::move(other.background); - return *this; - } - - void setBorderStyle(std::unique_ptr newBorder) - { - border = std::move(newBorder); - } - - void setBackgroundStyle(std::unique_ptr newBackground) - { - background = std::move(newBackground); - } - - Border* getBorderStyle() const - { - return border.get(); - } - - Background* getBackgroundStyle() const - { - return background.get(); - } -private: - std::unique_ptr border; - std::unique_ptr background; -}; -} // namespace gui -} // namespace aw -#endif //_aw_GUI_ElementStyle_ diff --git a/gui/include/aw/gui/style/Shared.h b/gui/include/aw/gui/style/Shared.h deleted file mode 100644 index 0946e66d..00000000 --- a/gui/include/aw/gui/style/Shared.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2015 hedede - * - * License LGPLv3 or later: - * GNU Lesser GPL version 3 - * This is free software: you are free to change and redistribute it. - * There is NO WARRANTY, to the extent permitted by law. - */ -#ifndef _aw_GUI_Style_Shared_ -#define _aw_GUI_Style_Shared_ -namespace aw { -namespace gui { -enum class ImageRepeat { - Stretch, - Tile -}; - -enum Corner { - TopLeft, - BottomLeft, - BottomRight, - TopRight, -}; -} // namespace gui -} // namespace aw -#endif //_aw_GUI_Style_Shared_ diff --git a/gui/tests/main.cpp b/gui/tests/main.cpp deleted file mode 100644 index 4ea39a47..00000000 --- a/gui/tests/main.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include - -#include - -#include -#include -#include -#include - -#include -#include - -#include - -using namespace irr; -namespace irr { -extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice( - video::E_DRIVER_TYPE deviceType = video::EDT_SOFTWARE, - // parantheses are necessary for some compilers - const core::dimension2d& windowSize = (core::dimension2d(640,480)), - u32 bits = 16, - bool fullscreen = false, - bool stencilbuffer = false, - bool vsync = false, - IEventReceiver* receiver = 0); -} -namespace aw { -size_t Event::eventTypes; - -class Couter : public core::LogBook { -public: - virtual void log(std::string msg, core::LogLevel level) - { - std::cout << msg << std::endl; - } -}; - -namespace gui { - - -int guimain() -{ - Couter cou; - core::Logger* log = core::createLogger(); - log->registerLog(&cou); - core::Logger::setGlobalLogger(log); - IrrlichtDevice * device = createDevice(video::EDT_OPENGL, - irr::core::dimension2d(800, 600)); - auto driver = device->getVideoDriver(); - auto input = std::make_unique(device); - std::unique_ptr engine = std::make_unique(driver); - std::unique_ptr canvas = std::make_unique(); - std::unique_ptr