Browse Source

Elements can only render text nodes

pull/1/head
gyroninja 5 years ago
parent
commit
5ab9f2f7e1
  1. 11
      src/graphics/components/ComponentBuilder.cpp
  2. 8
      src/graphics/elements/AElement.cpp
  3. 2
      src/graphics/elements/AElement.h
  4. 8
      src/graphics/elements/BLOCKQUOTEElement.cpp
  5. 2
      src/graphics/elements/BLOCKQUOTEElement.h
  6. 2
      src/graphics/elements/Element.h
  7. 8
      src/graphics/elements/H1Element.cpp
  8. 2
      src/graphics/elements/H1Element.h
  9. 8
      src/graphics/elements/H2Element.cpp
  10. 2
      src/graphics/elements/H2Element.h
  11. 8
      src/graphics/elements/H3Element.cpp
  12. 2
      src/graphics/elements/H3Element.h
  13. 8
      src/graphics/elements/LIElement.cpp
  14. 2
      src/graphics/elements/LIElement.h
  15. 8
      src/graphics/elements/PElement.cpp
  16. 2
      src/graphics/elements/PElement.h
  17. 11
      src/graphics/elements/SPANElement.cpp
  18. 2
      src/graphics/elements/SPANElement.h

11
src/graphics/components/ComponentBuilder.cpp

@ -1,12 +1,6 @@ @@ -1,12 +1,6 @@
#include "ComponentBuilder.h"
#include <iostream>
//const ElementRendererMap ComponentBuilder::tagRenderers {
//};
//
//const ElementRendererMap ComponentBuilder::textRenderers {
//};
const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder::elementMap {
{"a", std::make_shared<AElement>()},
{"blockquote", std::make_shared<BLOCKQUOTEElement>()},
@ -39,10 +33,7 @@ std::unique_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -39,10 +33,7 @@ std::unique_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
if (elementPair != elementMap.end()) {
std::shared_ptr<Element> element = elementPair->second;
int y = parentComponent != nullptr ? (parentComponent->y + (!element->isInline ? 0 : parentComponent->y)) : 0;
y += 500;
std::cout << tag << std::endl;
std::cout << y << std::endl;
component = element->renderer(*node.get(), y, windowWidth, windowHeight);
component = element->renderer(node, y, windowWidth, windowHeight);
}
return component;

8
src/graphics/elements/AElement.cpp

@ -1,5 +1,9 @@ @@ -1,5 +1,9 @@
#include "AElement.h"
std::unique_ptr<Component> AElement::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
return std::make_unique<TextComponent>(static_cast<const TextNode&>(node).text, 0, y, 12, false, 0x00FFFF, windowWidth, windowHeight);
std::unique_ptr<Component> AElement::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, 0, y, 12, false, 0x00FFFF, windowWidth, windowHeight);
}
return nullptr;
}

2
src/graphics/elements/AElement.h

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
class AElement : public Element {
public:
bool isInline = true;
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

8
src/graphics/elements/BLOCKQUOTEElement.cpp

@ -1,5 +1,9 @@ @@ -1,5 +1,9 @@
#include "BLOCKQUOTEElement.h"
std::unique_ptr<Component> BLOCKQUOTEElement::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
return std::make_unique<TextComponent>(static_cast<const TextNode&>(node).text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
std::unique_ptr<Component> BLOCKQUOTEElement::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}

2
src/graphics/elements/BLOCKQUOTEElement.h

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
class BLOCKQUOTEElement : public Element {
public:
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

2
src/graphics/elements/Element.h

@ -10,7 +10,7 @@ class Element { @@ -10,7 +10,7 @@ class Element {
public:
bool isInline = false;
virtual ~Element();
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

8
src/graphics/elements/H1Element.cpp

@ -1,5 +1,9 @@ @@ -1,5 +1,9 @@
#include "H1Element.h"
std::unique_ptr<Component> H1Element::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
return std::make_unique<TextComponent>(static_cast<const TextNode&>(node).text, 0, y, 24, true, 0x000000FF, windowWidth, windowHeight);
std::unique_ptr<Component> H1Element::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, 0, y, 24, true, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}

2
src/graphics/elements/H1Element.h

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
class H1Element : public Element {
public:
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

8
src/graphics/elements/H2Element.cpp

@ -1,5 +1,9 @@ @@ -1,5 +1,9 @@
#include "H2Element.h"
std::unique_ptr<Component> H2Element::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
return std::make_unique<TextComponent>(static_cast<const TextNode&>(node).text, 0, y, 18, true, 0x000000FF, windowWidth, windowHeight);
std::unique_ptr<Component> H2Element::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, 0, y, 18, true, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}

2
src/graphics/elements/H2Element.h

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
class H2Element : public Element {
public:
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

8
src/graphics/elements/H3Element.cpp

@ -1,5 +1,9 @@ @@ -1,5 +1,9 @@
#include "H3Element.h"
std::unique_ptr<Component> H3Element::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
return std::make_unique<TextComponent>(static_cast<const TextNode&>(node).text, 0, y, 14, true, 0x000000FF, windowWidth, windowHeight); // Should be 14.04pt
std::unique_ptr<Component> H3Element::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, 0, y, 14, true, 0x000000FF, windowWidth, windowHeight); // Should be 14.04pt
}
return nullptr;
}

2
src/graphics/elements/H3Element.h

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
class H3Element : public Element {
public:
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

8
src/graphics/elements/LIElement.cpp

@ -1,5 +1,9 @@ @@ -1,5 +1,9 @@
#include "LIElement.h"
std::unique_ptr<Component> LIElement::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
return std::make_unique<TextComponent>("" + static_cast<const TextNode&>(node).text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
std::unique_ptr<Component> LIElement::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
return std::make_unique<TextComponent>("" + textNode->text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}

2
src/graphics/elements/LIElement.h

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
class LIElement : public Element {
public:
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

8
src/graphics/elements/PElement.cpp

@ -2,6 +2,10 @@ @@ -2,6 +2,10 @@
#include "../components/TextComponent.h"
#include "../../html/TextNode.h"
std::unique_ptr<Component> PElement::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
return std::make_unique<TextComponent>(static_cast<const TextNode&>(node).text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
std::unique_ptr<Component> PElement::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}

2
src/graphics/elements/PElement.h

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
class PElement : public Element {
public:
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

11
src/graphics/elements/SPANElement.cpp

@ -1,9 +1,12 @@ @@ -1,9 +1,12 @@
#include "SPANElement.h"
std::unique_ptr<Component> SPANElement::renderer(const Node &node, int y, int windowWidth, int windowHeight) {
if (node.parent->children.size() == 1) {
std::unique_ptr<Component> component = std::make_unique<TextComponent>(static_cast<const TextNode&>(node).text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
return component;
std::unique_ptr<Component> SPANElement::renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
if (textNode) {
if (node->parent->children.size() == 1) {
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, 0, y, 12, false, 0x000000FF, windowWidth, windowHeight);
return component;
}
}
return nullptr;
}

2
src/graphics/elements/SPANElement.h

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
class SPANElement : public Element {
public:
bool isInline = true;
virtual std::unique_ptr<Component> renderer(const Node &node, int y, int windowWidth, int windowHeight);
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int y, const int windowWidth, const int windowHeight);
};
#endif

Loading…
Cancel
Save