Browse Source

change API to use new request reference prototype

master
Odilitime 5 years ago
parent
commit
f8f1e99f17
  1. 17
      src/graphics/elements/AElement.cpp
  2. 2
      src/graphics/elements/AElement.h
  3. 8
      src/graphics/elements/DIVElement.cpp
  4. 2
      src/graphics/elements/DIVElement.h
  5. 6
      src/graphics/elements/H1Element.cpp
  6. 2
      src/graphics/elements/H1Element.h
  7. 6
      src/graphics/elements/H2Element.cpp
  8. 2
      src/graphics/elements/H2Element.h
  9. 6
      src/graphics/elements/H3Element.cpp
  10. 2
      src/graphics/elements/H3Element.h
  11. 4
      src/graphics/elements/INPUTElement.cpp
  12. 2
      src/graphics/elements/INPUTElement.h
  13. 6
      src/graphics/elements/LIElement.cpp
  14. 2
      src/graphics/elements/LIElement.h
  15. 9
      src/graphics/elements/SPANElement.cpp
  16. 2
      src/graphics/elements/SPANElement.h
  17. 6
      src/graphics/elements/STRONGElement.cpp
  18. 2
      src/graphics/elements/STRONGElement.h

17
src/graphics/elements/AElement.cpp

@ -1,25 +1,28 @@ @@ -1,25 +1,28 @@
#include "AElement.h"
#include "../../html/TagNode.h"
#include <iostream>
#include "../opengl/Window.h"
#include "../../browser.h"
extern const std::unique_ptr<Window> window;
extern const std::unique_ptr<Browser> browser;
AElement::AElement() {
isInline = true;
}
std::unique_ptr<Component> AElement::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
std::unique_ptr<Component> AElement::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, x, y, 12, false, 0x00FFFF, windowWidth, windowHeight);
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, 0, 0, 12, false, 0x00FFFF, request.parentComponent->win->windowWidth, request.parentComponent->win->windowHeight);
TagNode *tagNode = dynamic_cast<TagNode*>(textNode->parent.get());
if (tagNode) {
std::map<std::string, std::string>::const_iterator hrefPair = tagNode->properties.find("href");
if (hrefPair != tagNode->properties.end()) {
component->onClick = [hrefPair]() {
component->onClick = [request, hrefPair]() {
std::cout << "AElement::renderer:::onClick - Direct to: " << hrefPair->second << std::endl;
window->navTo(hrefPair->second);
// new window
// new tab
// same documentComponent (iframe, document, tab)
browser->getActiveDocumentComponent()->navTo(hrefPair->second);
};
}
}

2
src/graphics/elements/AElement.h

@ -11,7 +11,7 @@ void navTo(std::string url); // forward declaration @@ -11,7 +11,7 @@ void navTo(std::string url); // forward declaration
class AElement : public Element {
public:
AElement();
virtual std::unique_ptr<Component> renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight);
virtual std::unique_ptr<Component> renderer(const ElementRenderRequest &request);
};
#endif

8
src/graphics/elements/DIVElement.cpp

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

2
src/graphics/elements/DIVElement.h

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

6
src/graphics/elements/H1Element.cpp

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
#include "H1Element.h"
std::unique_ptr<Component> H1Element::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
std::unique_ptr<Component> H1Element::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, x, y, 24, true, 0x000000FF, windowWidth, windowHeight);
return std::make_unique<TextComponent>(textNode->text, 0, 0, 24, true, 0x000000FF, request.parentComponent->win->windowWidth, request.parentComponent->win->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 std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight);
virtual std::unique_ptr<Component> renderer(const ElementRenderRequest &request);
};
#endif

6
src/graphics/elements/H2Element.cpp

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
#include "H2Element.h"
std::unique_ptr<Component> H2Element::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
std::unique_ptr<Component> H2Element::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, x, y, 18, true, 0x000000FF, windowWidth, windowHeight);
return std::make_unique<TextComponent>(textNode->text, 0, 0, 18, true, 0x000000FF, request.parentComponent->win->windowWidth, request.parentComponent->win->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 std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight);
virtual std::unique_ptr<Component> renderer(const ElementRenderRequest &request);
};
#endif

6
src/graphics/elements/H3Element.cpp

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
#include "H3Element.h"
std::unique_ptr<Component> H3Element::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
std::unique_ptr<Component> H3Element::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, x, y, 14, true, 0x000000FF, windowWidth, windowHeight); // Should be 14.04pt
return std::make_unique<TextComponent>(textNode->text, 0, 0, 14, true, 0x000000FF, request.parentComponent->win->windowWidth, request.parentComponent->win->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 std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight);
virtual std::unique_ptr<Component> renderer(const ElementRenderRequest &request);
};
#endif

4
src/graphics/elements/INPUTElement.cpp

@ -4,11 +4,11 @@ INPUTElement::INPUTElement() { @@ -4,11 +4,11 @@ INPUTElement::INPUTElement() {
isInline = true;
}
std::unique_ptr<Component> INPUTElement::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
std::unique_ptr<Component> INPUTElement::renderer(const ElementRenderRequest &request) {
// const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int windowWidth, const int windowHeight
// what should our default size be?
//std::cout << "INPUTElement::renderer - creating InputComponent at " << x << "x" << y << std::endl;
std::unique_ptr<Component> component = std::make_unique<InputComponent>(x, y, 125.0f, 13.0f, windowWidth, windowHeight);
std::unique_ptr<Component> component = std::make_unique<InputComponent>(0, 0, 125.0f, 13.0f, request.parentComponent->win->windowWidth, request.parentComponent->win->windowHeight);
return component;
/*

2
src/graphics/elements/INPUTElement.h

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

6
src/graphics/elements/LIElement.cpp

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
#include "LIElement.h"
std::unique_ptr<Component> LIElement::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
std::unique_ptr<Component> LIElement::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
return std::make_unique<TextComponent>("" + textNode->text, x, y, 12, false, 0x000000FF, windowWidth, windowHeight);
return std::make_unique<TextComponent>("" + textNode->text, 0, 0, 12, false, 0x000000FF, request.parentComponent->win->windowWidth, request.parentComponent->win->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 std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight);
virtual std::unique_ptr<Component> renderer(const ElementRenderRequest &request);
};
#endif

9
src/graphics/elements/SPANElement.cpp

@ -4,11 +4,12 @@ SPANElement::SPANElement() { @@ -4,11 +4,12 @@ SPANElement::SPANElement() {
isInline = true;
}
std::unique_ptr<Component> SPANElement::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
std::unique_ptr<Component> SPANElement::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
if (node->parent->children.size() == 1) {
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, x, y, 12, false, 0x000000FF, windowWidth, windowHeight);
// only create a dummy component if we have one child, why?
if (request.node->parent->children.size() == 1) {
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, 0, 0, 12, false, 0x000000FF, request.parentComponent->win->windowWidth, request.parentComponent->win->windowHeight);
return component;
}
}

2
src/graphics/elements/SPANElement.h

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

6
src/graphics/elements/STRONGElement.cpp

@ -4,11 +4,11 @@ STRONGElement::STRONGElement() { @@ -4,11 +4,11 @@ STRONGElement::STRONGElement() {
isInline = true;
}
std::unique_ptr<Component> STRONGElement::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
TextNode *textNode = dynamic_cast<TextNode*>(node.get());
std::unique_ptr<Component> STRONGElement::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
//if (node->parent->children.size() == 1) {
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, x, y, 12, true, 0x000000FF, windowWidth, windowHeight);
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, 0, 0, 12, true, 0x000000FF, request.parentComponent->win->windowWidth, request.parentComponent->win->windowHeight);
return component;
//}
}

2
src/graphics/elements/STRONGElement.h

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

Loading…
Cancel
Save