Browse Source

Merge branch 'master' of https://gitgud.io/odilitime/netrunner

# Conflicts:
#	src/CFGFileParser.cpp
#	src/main.cpp
master
despair 5 years ago
parent
commit
aff58638d0
  1. 3
      src/CFGFileParser.cpp
  2. 77
      src/browser.cpp
  3. 60
      src/browser.h
  4. 15
      src/graphics/components/Component.h
  5. 62
      src/graphics/components/ComponentBuilder.cpp
  6. 7
      src/graphics/components/ComponentBuilder.h
  7. 70
      src/graphics/components/DocumentComponent.cpp
  8. 8
      src/graphics/components/DocumentComponent.h
  9. 17
      src/graphics/components/InputComponent.cpp
  10. 3
      src/graphics/components/InputComponent.h
  11. 4
      src/graphics/components/MultiComponent.cpp
  12. 7
      src/graphics/components/MultiComponent.h
  13. 68
      src/graphics/components/TabbedComponent.cpp
  14. 13
      src/graphics/components/TabbedComponent.h
  15. 4
      src/graphics/components/TextComponent.cpp
  16. 2
      src/graphics/components/TextComponent.h
  17. 17
      src/graphics/elements/AElement.cpp
  18. 2
      src/graphics/elements/AElement.h
  19. 9
      src/graphics/elements/BLOCKQUOTEElement.cpp
  20. 14
      src/graphics/elements/BLOCKQUOTEElement.h
  21. 8
      src/graphics/elements/DIVElement.cpp
  22. 2
      src/graphics/elements/DIVElement.h
  23. 3
      src/graphics/elements/Element.cpp
  24. 26
      src/graphics/elements/Element.h
  25. 6
      src/graphics/elements/H1Element.cpp
  26. 2
      src/graphics/elements/H1Element.h
  27. 6
      src/graphics/elements/H2Element.cpp
  28. 2
      src/graphics/elements/H2Element.h
  29. 6
      src/graphics/elements/H3Element.cpp
  30. 2
      src/graphics/elements/H3Element.h
  31. 4
      src/graphics/elements/INPUTElement.cpp
  32. 2
      src/graphics/elements/INPUTElement.h
  33. 6
      src/graphics/elements/LIElement.cpp
  34. 2
      src/graphics/elements/LIElement.h
  35. 11
      src/graphics/elements/PElement.cpp
  36. 14
      src/graphics/elements/PElement.h
  37. 9
      src/graphics/elements/SPANElement.cpp
  38. 2
      src/graphics/elements/SPANElement.h
  39. 6
      src/graphics/elements/STRONGElement.cpp
  40. 2
      src/graphics/elements/STRONGElement.h
  41. 133
      src/graphics/opengl/Window.cpp
  42. 11
      src/graphics/opengl/Window.h
  43. 13
      src/graphics/text/TextRasterizer.cpp
  44. 2
      src/graphics/text/TextRasterizer.h
  45. 4
      src/graphics/text/TextRasterizerCache.cpp
  46. 56
      src/main.cpp

3
src/CFGFileParser.cpp

@ -11,6 +11,9 @@ CFGFileParser::CFGFileParser(const char* filename){ @@ -11,6 +11,9 @@ CFGFileParser::CFGFileParser(const char* filename){
buffer = static_cast<char*>(tlsf_calloc(cfg_fileinfo->st_size & INT_MAX, sizeof(char) & INT_MAX));
cfg = new BrowserConfiguration();
bytesRead = fread(buffer, sizeof(char) & INT_MAX, cfg_fileinfo->st_size & INT_MAX, cfg_file);
if (!bytesRead) {
std::cout << "no config" << std::endl;
}
fclose(cfg_file);
}

77
src/browser.cpp

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
#include "browser.h"
#include "scheduler.h"
#include "graphics/components/TabbedComponent.h"
// why can't I const this?
std::unique_ptr<Scheduler> scheduler = std::make_unique<Scheduler>();
// Previously defined components with functionality
// 1+ image (no functionality)
// 1+ tabbed document
// 1+ back/fwd/reload/stop components
// 1+ address bar
Browser::Browser() {
}
void Browser::addWindow() {
windowCounter++;
std::shared_ptr<Window> newWindow = std::make_shared<Window>();
newWindow->id = windowCounter;
newWindow->windowWidth = 1024;
newWindow->windowHeight = 640;
newWindow->init(); // load our UI into it
this->windows.push_back(std::move(newWindow));
if (!activeWindow) {
std::cout << "Browser::addWindow - setting active window" << std::endl;
activeWindow = this->windows.back().get();
}
}
std::shared_ptr<DocumentComponent> Browser::getActiveDocumentComponent() {
if (!activeWindow) {
std::cout << "Browser::getActiveDocumentComponent - No active window" << std::endl;
return nullptr;
}
return this->activeWindow->getActiveDocumentComponent();
}
// FIXME: put quit check in here and clean up windows
void Browser::render() {
// guessing during render this iterator can be invalidated
size_t w = this->windows.size();
//for(std::vector<std::shared_ptr<Window>>::iterator it = this->windows.begin(); it != this->windows.end(); ++it) {
//it->get()->render();
// definitely safer
for(size_t i = 0; i < w; ++i) {
glfwMakeContextCurrent(this->windows[i]->window);
this->windows[i]->render();
}
}
void Browser::loop() {
bool shouldQuit = false;
while (!shouldQuit) {
//const std::clock_t begin = clock();
this->render();
scheduler->fireTimers(); // render may have taken some time
double next = scheduler->getNext();
//std::cout << "next timer at " << next << std::endl;
if (next == LONG_MAX) {
glfwWaitEvents(); // block until something changes
} else {
glfwWaitEventsTimeout(next / 1000);
}
scheduler->fireTimers(); // check before we go into render again
//glfwWaitEventsTimeout(1.0 / 60.0); // increase the cpu from 0% to 2% on idle
//const std::clock_t end = clock();
//std::cout << '\r' << std::fixed << (((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) * 1000) << std::scientific << " ms/f " << std::flush;
// FIXME: one close shouldn't close the app
for(std::vector<std::shared_ptr<Window>>::iterator it = this->windows.begin(); it != this->windows.end(); ++it) {
if (glfwWindowShouldClose(it->get()->window)) {
shouldQuit = true;
break;
}
}
}
}

60
src/browser.h

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
#ifndef BROWSER_H
#define BROWSER_H
#include "graphics/opengl/Window.h"
#include "graphics/components/Component.h"
#include "graphics/components/DocumentComponent.h"
#include "graphics/components/ComponentBuilder.h"
#include "html/Node.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <memory>
#include <vector>
#include <algorithm>
#include "networking/HTTPResponse.h"
#include "URL.h"
#include "graphics/opengl/Window.h"
// this is the actually application that
// contains a list of windows
// separate window functions from browser functions
class Browser {
private:
public:
Browser();
void addWindow();
void render();
void loop();
std::shared_ptr<DocumentComponent> getActiveDocumentComponent();
void navTo(std::string url);
// properties
std::vector<std::shared_ptr<Window>> windows;
Window *activeWindow = nullptr;
size_t windowCounter = 0;
std::shared_ptr<Node> domRootNode = nullptr;
bool domDirty = false;
bool renderDirty = true;
//bool uiSetUp = false;
std::shared_ptr<Component> rootComponent = std::make_shared<Component>();
// I hate doing this but we currently require this
std::shared_ptr<Component> tabComponent = nullptr;
std::shared_ptr<Component> addressComponent = nullptr;
// could break these out in some sort of cursor class
// to minimize dependencies
std::shared_ptr<Component> focusedComponent = nullptr;
std::shared_ptr<Component> hoverComponent = nullptr;
URL currentURL;
};
//bool setWindowContent(URL const& url);
//void handleRequest(const HTTPResponse &response);
extern const std::unique_ptr<Window> window;
#endif

15
src/graphics/components/Component.h

@ -6,19 +6,15 @@ @@ -6,19 +6,15 @@
#include <vector>
#include <string>
#include <GL/glew.h>
//#include "../opengl/Window.h"
class Window;
const unsigned int indices[6] = {
0, 1, 2,
0, 2, 3
};
struct rgba {
unsigned int r;
unsigned int g;
unsigned int b;
unsigned int a;
};
struct UImetric {
double lengthPct = 0;
int offset = 0;
@ -58,6 +54,7 @@ struct UILayoutV2 { @@ -58,6 +54,7 @@ struct UILayoutV2 {
// and renderable component
class Component {
public:
// constructing with a window would make a lot of sense (textcomponent can't rasterize until we have the max texture size)
virtual ~Component();
// we're currently constructed with a pos
// so recalculating it is only good for resize
@ -109,6 +106,8 @@ public: @@ -109,6 +106,8 @@ public:
// how are these used?
int windowWidth;
int windowHeight;
// handle to signal that a redraw is needed, and access to shader programs
std::shared_ptr<Window> win;
bool boundToPage = true;
bool useBoxShader = true;
bool verticesDirty = false;
@ -155,7 +154,7 @@ public: @@ -155,7 +154,7 @@ public:
//
UIlayout uiControl;
// color
rgba color;
unsigned int color;
bool isVisibile = true;
bool isInline = false; // text-only thing but there maybe other non-text inline
bool isPickable = true;

62
src/graphics/components/ComponentBuilder.cpp

@ -2,12 +2,10 @@ @@ -2,12 +2,10 @@
#include <iostream>
#include "../elements/AElement.h"
#include "../elements/BLOCKQUOTEElement.h"
#include "../elements/H1Element.h"
#include "../elements/H2Element.h"
#include "../elements/H3Element.h"
#include "../elements/LIElement.h"
#include "../elements/PElement.h"
#include "../elements/SPANElement.h"
#include "../elements/DIVElement.h"
#include "../elements/STRONGElement.h"
@ -18,12 +16,12 @@ std::shared_ptr<Component> searchComponentTree(const std::shared_ptr<Component> @@ -18,12 +16,12 @@ std::shared_ptr<Component> searchComponentTree(const std::shared_ptr<Component>
const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder::elementMap {
{"a", std::make_shared<AElement>()},
{"blockquote", std::make_shared<BLOCKQUOTEElement>()},
{"blockquote", std::make_shared<DIVElement>()},
{"h1", std::make_shared<H1Element>()},
{"h2", std::make_shared<H2Element>()},
{"h3", std::make_shared<H3Element>()},
{"li", std::make_shared<LIElement>()},
{"p", std::make_shared<PElement>()},
{"p", std::make_shared<DIVElement>()},
{"span", std::make_shared<SPANElement>()},
{"aside", std::make_shared<SPANElement>()},
{"div", std::make_shared<DIVElement>()},
@ -34,8 +32,7 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder @@ -34,8 +32,7 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder
{"i", std::make_shared<SPANElement>()}
};
// FIXME: pass the component it's attached too
std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent, int windowWidth, int windowHeight) {
std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent, const std::shared_ptr<Window> win) {
std::shared_ptr<Component> component;
std::string tag;
if (node == nullptr) {
@ -68,7 +65,11 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -68,7 +65,11 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
//std::tie(x,y) = getPos(parentComponent, isInline, windowWidth);
//auto [x, y]=getPos(parentComponent, isInline);
component = element->renderer(node, 0, 0, windowWidth, windowHeight); // doesn't always make a component
//component = element->renderer(node, 0, 0, windowWidth, windowHeight); // doesn't always make a component
ElementRenderRequest request;
request.node = node;
request.parentComponent = parentComponent;
component = element->renderer(request); // doesn't always make a component
} else {
//std::cout << "Unknown tag: " << tag << std::endl;
}
@ -81,70 +82,73 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -81,70 +82,73 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
if (textComponent) {
//std::cout << "compositing [" << textComponent->text << "]" << std::endl;
if (!textComponent->onMousedown) {
textComponent->onMousedown = [textComponent](int x, int y) {
if (window->selectionList.size()) {
textComponent->onMousedown = [textComponent, win](int x, int y) {
if (win->selectionList.size()) {
//std::cout << "unselecting text" << std::endl;
for(std::vector<std::shared_ptr<Component>>::iterator it = window->selectionList.begin(); it != window->selectionList.end(); ++it) {
for(std::vector<std::shared_ptr<Component>>::iterator it = win->selectionList.begin(); it != win->selectionList.end(); ++it) {
TextComponent *selectedTextComponent = dynamic_cast<TextComponent*>(it->get());
if (selectedTextComponent) {
selectedTextComponent->textSelected = false;
selectedTextComponent->updateHighlight();
}
}
window->selectionList.clear();
win->selectionList.clear();
}
//std::cout << "TextSelection starting at " << x << "," << y << std::endl;
// 0 to -640 (windowHeight)
// so if y=640 , f(y)=-640
//int ny = -y;
//std::cout << "TextSelection adjusted " << x << "," << ny << std::endl;
window->highlightStartX = x;
window->highlightStartY = y;
win->highlightStartX = x;
win->highlightStartY = y;
//std::cout << "Component at " << static_cast<int>(textComponent->x) << "," << static_cast<int>(textComponent->y) << std::endl;
};
// mouseover to update selection renderer
textComponent->onMouseup = [textComponent, parentComponent](int x, int y) {
textComponent->onMouseup = [textComponent, parentComponent, win](int x, int y) {
//std::cout << "TextSelection ending at " << x << "," << y << std::endl;
//int ny = -y;
//std::cout << "TextSelection adjusted " << x << "," << ny << std::endl;
// find all components in that range
//std::cout << "TextSelection started at " << window->highlightStartX << "," << window->highlightStartY << std::endl;
int minX = std::min(window->highlightStartX, x);
int maxX = std::max(window->highlightStartX, x);
int minY = std::min(window->highlightStartY, y);
int maxY = std::max(window->highlightStartY, y);
//std::cout << "TextSelection started at " << win->highlightStartX << "," << win->highlightStartY << std::endl;
int minX = std::min(win->highlightStartX, x);
int maxX = std::max(win->highlightStartX, x);
int minY = std::min(win->highlightStartY, y);
int maxY = std::max(win->highlightStartY, y);
// FIXME: find root component and search there
// can't use win because we maybe in a sub component
for(int cx = minX; cx < maxX; ++cx) {
for(int cy = minY; cy < maxY; ++cy) {
//std::cout << "textComponent inside " << cx << "," << cy << std::endl;
std::shared_ptr<Component> cp = searchComponentTree(parentComponent, cx, cy);
TextComponent *selectedTextComponent = dynamic_cast<TextComponent*>(cp.get());
if (selectedTextComponent) {
std::vector<std::shared_ptr<Component>>::iterator it = std::find(window->selectionList.begin(), window->selectionList.end(), cp);
if (it == window->selectionList.end()) {
std::vector<std::shared_ptr<Component>>::iterator it = std::find(win->selectionList.begin(), win->selectionList.end(), cp);
if (it == win->selectionList.end()) {
selectedTextComponent->textSelected = true;
selectedTextComponent->updateHighlight();
window->renderDirty = true;
window->selectionList.push_back(cp);
win->renderDirty = true;
win->selectionList.push_back(cp);
}
}
}
}
//std::cout << "selected " << window->selectionList.size() << " components" << std::endl;
//std::cout << "selected " << win->selectionList.size() << " components" << std::endl;
};
}
}
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component.get());
if (inputComponent) {
//if (inputComponent) {
// any input set up we need to do?
// boundToPage defaults to true for components, InputComponent doesn't have it overridded
//std::cout << "Just built an inputComponent" << std::endl;
inputComponent->win = window.get();
}
//inputComponent->win = win;
//}
//std::cout << "composting component, initial: " << (int)component->width << "x" << (int)component->height << std::endl;
// set our available dimensions
component->windowWidth = windowWidth;
component->windowHeight = windowHeight;
component->win = win;
component->windowWidth = win->windowWidth;
component->windowHeight = win->windowHeight;
// set our type
component->isInline = isInline;

7
src/graphics/components/ComponentBuilder.h

@ -5,18 +5,21 @@ @@ -5,18 +5,21 @@
#include <memory>
#include <unordered_map>
#include "Component.h"
#include "../elements/Element.h"
//#include "../elements/Element.h"
#include "../../html/TagNode.h"
#include "../../html/TextNode.h"
#include "../../html/Node.h"
class Element;
typedef std::unordered_map<std::string, std::function<std::unique_ptr<Component>(const Node &node, int y, int windowWidth, int windowHeight)>> ElementRendererMap;
class ComponentBuilder {
private:
const static std::unordered_map<std::string, std::shared_ptr<Element>> elementMap;
public:
std::shared_ptr<Component> build(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent, int windowWidth, int windowHeight);
// FIXME: consider passing the documentComponent we're bound too
std::shared_ptr<Component> build(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent, const std::shared_ptr<Window> win);
};
// getComponentType

70
src/graphics/components/DocumentComponent.cpp

@ -3,9 +3,12 @@ @@ -3,9 +3,12 @@
#include <iostream>
#include "../../Log.h"
#include "InputComponent.h"
#include "TabbedComponent.h"
#include <ctime>
#include "../opengl/Shader.h"
#include "../../WebResource.h"
#include "../../html/HTMLParser.h"
void deleteComponent(std::shared_ptr<Component> &component);
void deleteNode(std::shared_ptr<Node> node);
@ -276,13 +279,13 @@ void DocumentComponent::render() { @@ -276,13 +279,13 @@ void DocumentComponent::render() {
//if (transformMatrixDirty) {
//const std::clock_t begin = clock();
Shader *fontShader = window->shaderLoader.getShader(VertexShader("FontShader.vert"),
Shader *fontShader = this->win->shaderLoader.getShader(VertexShader("FontShader.vert"),
FragmentShader("FontShader.frag"));
GLint transformLocation = fontShader->uniform("transform");
glUniformMatrix4fv(transformLocation, 1, GL_FALSE, transformMatrix);
//const std::clock_t end = clock();
//std::cout << "Updated font matrix in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
Shader *textureShader = window->shaderLoader.getShader(VertexShader("TextureShader.vert"),
Shader *textureShader = this->win->shaderLoader.getShader(VertexShader("TextureShader.vert"),
FragmentShader("TextureShader.frag"));
GLint transformLocation2 = textureShader->uniform("transform");
glUniformMatrix4fv(transformLocation2, 1, GL_FALSE, transformMatrix);
@ -301,7 +304,7 @@ void DocumentComponent::render() { @@ -301,7 +304,7 @@ void DocumentComponent::render() {
// create this component and all it's children
void DocumentComponent::createComponentTree(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent) {
std::shared_ptr<Component> component = componentBuilder.build(node, parentComponent, windowWidth, windowHeight);
std::shared_ptr<Component> component = componentBuilder.build(node, parentComponent, this->win);
//std::cout << "DocumentComponent::createComponentTree" << std::endl;
if (!component) {
//std::cout << "DocumentComponent::createComponentTree - no component" << std::endl;
@ -348,7 +351,64 @@ std::shared_ptr<Component> DocumentComponent::searchComponentTree(const std::sha @@ -348,7 +351,64 @@ std::shared_ptr<Component> DocumentComponent::searchComponentTree(const std::sha
// preparation for multiple HTML documents
void DocumentComponent::navTo(const std::string url) {
logDebug() << "DocumentComponent::navTo(" << url << ")" << std::endl;
currentURL = currentURL.merge(URL(url));
this->currentURL = currentURL.merge(URL(url));
logDebug() << "DocumentComponent::navTo - go to: " << currentURL << std::endl;
setWindowContent(currentURL);
//setWindowContent(currentURL);
logDebug() << "main::setWindowContent - " << url << std::endl;
// integrity check
TabbedComponent *tabComponent = dynamic_cast<TabbedComponent*>(this->win->tabComponent.get());
if (!tabComponent->tabs.size()) {
std::cout << "DocumentComponent::navTo - There's a document when there's not tabs" << std::endl;
}
// download URL
WebResource res = getWebResource(this->currentURL);
if (res.resourceType == ResourceType::INVALID) {
logError() << "Invalid resource type: " << res.raw << std::endl;
return;
}
// parse HTML
if (res.resourceType == ResourceType::HTML) {
HTMLParser parser;
const std::clock_t begin = clock();
std::shared_ptr<Node> rootNode = parser.parse(res.raw);
const std::clock_t end = clock();
logDebug() << "main::setWindowContent - Parsed document in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
// send NodeTree to window
//this->win->setDOM(rootNode);
// we need a way to communicate with our tabComponent
// maybe an event is best
if (this->onBeforeLoad) {
this->onBeforeLoad(url);
}
this->setDOM(rootNode);
} else if (res.resourceType == ResourceType::TXT) {
std::cout << "Rendering text document" << std::endl;
std::shared_ptr<Node> rootNode = std::make_shared<Node>(NodeType::ROOT);
std::shared_ptr<TagNode> tagNode = std::make_shared<TagNode>();
tagNode->tag="p";
// bind tag to root
tagNode->parent = rootNode;
rootNode->children.push_back(tagNode);
std::shared_ptr<TextNode> textNode = std::make_shared<TextNode>();
textNode->text = res.raw;
// bind text to tag
textNode->parent = tagNode;
tagNode->children.push_back(textNode);
// send NodeTree to window
//this->win->setDOM(rootNode);
this->setDOM(rootNode);
} else {
std::cout << "setWindowContent() - I don't know how to render non-html files" << std::endl;
}
}

8
src/graphics/components/DocumentComponent.h

@ -3,14 +3,12 @@ @@ -3,14 +3,12 @@
#include <GL/glew.h>
#include "Component.h"
#include "MultiComponent.h"
#include "ComponentBuilder.h"
#include "../opengl/Window.h"
#include "../../html/Node.h"
#include "../../URL.h"
#include "../../networking/HTTPResponse.h"
#include "MultiComponent.h"
// document is scrollable until multicomponent
class DocumentComponent : public MultiComponent {
public:
@ -35,10 +33,8 @@ public: @@ -35,10 +33,8 @@ public:
0, 0, 0, 1
};
bool transformMatrixDirty = true;
std::function<void(std::string url)> onBeforeLoad = nullptr;
};
//bool setWindowContent(URL const& url);
//void handleRequest(const HTTPResponse &response);
#endif

17
src/graphics/components/InputComponent.cpp

@ -39,7 +39,9 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r @@ -39,7 +39,9 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
this->cursorBox->y = this->windowHeight + y - 13;
}
this->cursorBox->resize(this->windowWidth, this->windowHeight);
this->updateText();
// can't updateText because no win set yet
// don't seem to need it either
//this->updateText();
onFocus=[this]() {
this->focused = true;
@ -156,7 +158,7 @@ void InputComponent::render() { @@ -156,7 +158,7 @@ void InputComponent::render() {
// can actuall delete vertices here
if (userInputText) {
// make sure we're using win's transformMatrix
Shader *fontShader = window->shaderLoader.getShader(VertexShader("FontShader.vert"),
Shader *fontShader = this->win->shaderLoader.getShader(VertexShader("FontShader.vert"),
FragmentShader("FontShader.frag"));
fontShader->bind();
if (!boundToPage) {
@ -166,7 +168,7 @@ void InputComponent::render() { @@ -166,7 +168,7 @@ void InputComponent::render() {
std::cout << "InputComponent::render - glGetUniformLocation not ok: " << glErr << std::endl;
}
// it's about the document transformMatrix
glUniformMatrix4fv(transformLocation, 1, GL_FALSE, window->transformMatrix);
glUniformMatrix4fv(transformLocation, 1, GL_FALSE, this->win->transformMatrix);
glErr=glGetError();
if(glErr != GL_NO_ERROR) {
std::cout << "InputComponent::render - glUniformMatrix4fv not ok: " << glErr << std::endl;
@ -174,7 +176,7 @@ void InputComponent::render() { @@ -174,7 +176,7 @@ void InputComponent::render() {
}
//std::cout << "rendering some text" << std::endl;
userInputText->render();
Shader *textureShader = window->shaderLoader.getShader(VertexShader("TextureShader.vert"),
Shader *textureShader = this->win->shaderLoader.getShader(VertexShader("TextureShader.vert"),
FragmentShader("TextureShader.frag"));
textureShader->bind();
}
@ -304,6 +306,9 @@ void InputComponent::updateText() { @@ -304,6 +306,9 @@ void InputComponent::updateText() {
delete userInputText;
}
userInputText=new TextComponent(value, 0, 0, 12, false, 0x000000FF, windowWidth, windowHeight);
if (!userInputText->win && this->win) {
userInputText->win = this->win;
}
//std::cout << "placing userInputText at " << static_cast<int>(x) << "," << static_cast<int>(y) << std::endl;
userInputText->x = x;
if (y < 0) {
@ -345,5 +350,7 @@ void InputComponent::updateText() { @@ -345,5 +350,7 @@ void InputComponent::updateText() {
//std::cout << "InputComponent::updateText - our width: " << static_cast<int>(width) << " windowWidth: " << windowWidth << std::endl;
userInputText->resize(windowWidth, windowHeight, width); // need to make sure there's a texture
window->renderDirty = true;
if (this->win) {
this->win->renderDirty = true;
} // else it was called from cstr, and window isn't set up yet but no worrites, render will be dirty
}

3
src/graphics/components/InputComponent.h

@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
#include <string>
#include "BoxComponent.h"
#include "TextComponent.h"
#include "../opengl/Window.h"
#include "../../scheduler.h"
class Window;
@ -31,8 +30,6 @@ public: @@ -31,8 +30,6 @@ public:
bool focused = false;
bool showCursor = true;
std::shared_ptr<timer_handle> cursorTimer = nullptr;
// handle to signal that a redraw is needed, and access to shader programs
Window *win;
// store for cursor
int estWidth;
};

4
src/graphics/components/MultiComponent.cpp

@ -217,13 +217,13 @@ void MultiComponent::resize(const int passedWindowWidth, const int passedWindowH @@ -217,13 +217,13 @@ void MultiComponent::resize(const int passedWindowWidth, const int passedWindowH
void MultiComponent::render() {
//std::cout << "MultiComponent::render" << std::endl;
Shader *fontShader = window->shaderLoader.getShader(VertexShader("FontShader.vert"),
Shader *fontShader = this->win->shaderLoader.getShader(VertexShader("FontShader.vert"),
FragmentShader("FontShader.frag"));
fontShader->bind();
renderDocumentComponents(rootComponent);
fontShader->release();
Shader *textureShader = window->shaderLoader.getShader(VertexShader("TextureShader.vert"),
Shader *textureShader = this->win->shaderLoader.getShader(VertexShader("TextureShader.vert"),
FragmentShader("TextureShader.frag"));
textureShader->bind();
renderBoxComponents(rootComponent);

7
src/graphics/components/MultiComponent.h

@ -32,10 +32,7 @@ public: @@ -32,10 +32,7 @@ public:
// layers will replace rootComponent
std::vector<std::shared_ptr<Component>> layers; // each layer's root component
std::shared_ptr<Component> rootComponent = std::make_shared<Component>();
// handle to signal that a redraw is needed, and access to shader programs
Window *win;
// tabbed coordinate system?
bool tabbed = false;
@ -50,6 +47,4 @@ public: @@ -50,6 +47,4 @@ public:
double cursorY = 0;
};
//extern const std::unique_ptr<Window> window;
#endif

68
src/graphics/components/TabbedComponent.cpp

@ -37,7 +37,7 @@ TabbedComponent::TabbedComponent(const float rawX, const float rawY, const float @@ -37,7 +37,7 @@ TabbedComponent::TabbedComponent(const float rawX, const float rawY, const float
BoxComponent *addBoxHandle = addNewBox.get();
addNewBox->onMouseover = [addBoxHandle, this]() {
//std::cout << "addNewBox->onMouseover" << std::endl;
addBoxHandle->changeColor(this->tabHoverColor);
addBoxHandle->changeColor(this->tabAddHoverColor);
this->win->renderDirty = true;
};
addNewBox->onMouseout = [addBoxHandle, this]() {
@ -66,6 +66,7 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -66,6 +66,7 @@ void TabbedComponent::addTab(std::string passedTitle) {
//(const std::string &rawText, const int rawX, const int rawY, const unsigned int size, const bool bolded, const unsigned int hexColor, const int passedWindowWidth, const int passedWindowHeight)
std::shared_ptr<TextComponent> newTabTitle = std::make_shared<TextComponent>(passedTitle, 0, 0, 12, false, this->tabTextColor, windowWidth, windowHeight);
size_t textWidth = 0;
newTabTitle->win = this->win;
std::unique_ptr<std::pair<int, int>> textInfo = newTabTitle->size();
if (textInfo) {
textWidth = static_cast<size_t>(textInfo->first);
@ -147,7 +148,7 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -147,7 +148,7 @@ void TabbedComponent::addTab(std::string passedTitle) {
closeTabBox->onMouseover = [closeTabBox, this]() {
//std::cout << "closeTabBox->onMouseover" << std::endl;
closeTabBox->changeColor(0xF00000FF);
closeTabBox->changeColor(this->tabCloseHoverColor);
this->win->renderDirty = true;
};
closeTabBox->onMouseout = [closeTabBox, this]() {
@ -168,6 +169,38 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -168,6 +169,38 @@ void TabbedComponent::addTab(std::string passedTitle) {
docComponent->win = this->win;
docComponent->boundToPage = false;
docComponent->onBeforeLoad=[this](std::string url) {
//std::cout << "tabbedComponent::addTab:::docComponent->onBeforeLoad - fire" << std::endl;
// if we're in a tab
if (this->mpSelectedTab) {
// set tab
TextComponent *textComponent = this->mpSelectedTab->titleBox.get();
if (textComponent) {
// similar to loadDomIntoTab
textComponent->text = url;
textComponent->wrap();
// recalc what that just did to our fellow tabs
this->layoutTabs(this->selectedTab, 0);
}
} else {
std::cout << "tabbedComponent::addTab:::docComponent->onBeforeLoad - document component but no tab selected" << std::endl;
// but we're loading into a specific tab, we have a doc component...
if (!this->tabs.size()) {
std::cout << "tabbedComponent::addTab:::docComponent->onBeforeLoad - document component but no tabs!" << std::endl;
}
}
// set address bar
InputComponent *ab = dynamic_cast<InputComponent*>(this->win->addressComponent.get());
if (ab) {
ab->value = url;
ab->updateText();
} else {
std::cout << "No address component" << std::endl;
}
this->updateWindowState(url);
};
// set up position and resize info
docComponent->y = -96; // our bar
docComponent->uiControl.x = { 0, 0 }; // 0
@ -185,7 +218,12 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -185,7 +218,12 @@ void TabbedComponent::addTab(std::string passedTitle) {
newTab->history = std::make_unique<BrowsingHistory>([this](URL const& goToURL) {
std::cout << "history goto " << goToURL << std::endl;
this->win->navTo(goToURL.toString());
std::shared_ptr<DocumentComponent> p_docComponent = std::static_pointer_cast<DocumentComponent>(this->documentComponent);
if (p_docComponent) {
// now tell it to navigate somewhere
p_docComponent->navTo(goToURL.toString());
}
//this->win->navTo(goToURL.toString());
});
if (tabs.size()) {
@ -216,7 +254,15 @@ void TabbedComponent::updateWindowState(std::string newTitle) { @@ -216,7 +254,15 @@ void TabbedComponent::updateWindowState(std::string newTitle) {
// need to update currentURL for navTo
// if we're no tab, we have no relative point, no harm in setting http://
//if (ab->value!="http://") {
this->win->currentURL = newTitle;
//this->win->currentURL = newTitle;
// I'm not sure we need this
/*
DocumentComponent *docComponent = dynamic_cast<DocumentComponent*>(this->documentComponent.get());
if (docComponent) {
docComponent->currentURL = newTitle;
}
*/
//}
// redraw pls
@ -242,7 +288,7 @@ std::vector<std::shared_ptr<Tab>>::iterator TabbedComponent::getTab(size_t tabId @@ -242,7 +288,7 @@ std::vector<std::shared_ptr<Tab>>::iterator TabbedComponent::getTab(size_t tabId
void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
//std::cout << "TabbedComponent::selectTab - select tab " << tabId << std::endl;
// locate tabId
// locate tab
if (tab == nullptr) {
std::cout << "TabbedComponent::selectTab - tab is nullptr" << std::endl;
return;
@ -269,6 +315,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -269,6 +315,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
it2 = std::find(this->rootComponent->children.begin(), this->rootComponent->children.end(), this->documentComponent);
if ( it2 != this->rootComponent->children.end() ) {
//std::cout << "Found old contents" << std::endl;
// FIXME: cast to doccomp and setDOM to null to make sure its clean
it2->get()->parent = nullptr;
this->rootComponent->children.erase(it2);
}
@ -289,7 +336,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -289,7 +336,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
}
ab->updateText();
} else {
std::cout << "Window addressComponent isnt an inputcomponent" << std::endl;
std::cout << "TabbedComponent::selectTab - Window addressComponent isnt an inputcomponent" << std::endl;
}
// I can't get selectedTab to works always (tab size = 1 or 2)
@ -306,6 +353,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -306,6 +353,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
i++;
}
//std::cout << "i" << i << "/" << this->tabs.size() << std::endl;
std::cout << "TabbedComponent::selectTab - selector found: " << found << std::endl;
if (found) {
// was there a previously selected tab?
//if (this->selectedTab != this->tabs.end() && this->selectedTab != this->tabs.begin()) {
@ -314,9 +362,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -314,9 +362,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
selector->changeColor(this->tabActiveColor);
}
// if we had something selected
// make sure we didn't just reselect ourself
//if (this->selectedTabId != newTab->get()->id) {
if (this->mpSelectedTab != tab) {
if (this->mpSelectedTab && this->mpSelectedTab != tab) {
selector = dynamic_cast<BoxComponent*>(this->selectedTab->get()->selectorBox.get());
if (selector) {
// reset it's color
@ -338,6 +387,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -338,6 +387,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
selector = dynamic_cast<BoxComponent*>(tab->selectorBox.get());
if (selector) {
selector->changeColor(this->tabActiveColor);
} else {
if (this->tabs.size()) {
std::cout << "TabbedComponent::selectTab - Can't find selectorBox for tab" << std::endl;
}
}
}
@ -503,6 +556,7 @@ void TabbedComponent::loadDomIntoTab(std::shared_ptr<Node> newRoot, std::string @@ -503,6 +556,7 @@ void TabbedComponent::loadDomIntoTab(std::shared_ptr<Node> newRoot, std::string
this->updateWindowState(newTitle);
}
//FIXME: make sure we update window's ptrs, we can't have documentComponent not pointing to nullptr when there's no tabs
void TabbedComponent::removeTab(size_t tabId) {
// find tabId
bool found = false;

13
src/graphics/components/TabbedComponent.h

@ -27,6 +27,7 @@ struct Tab { @@ -27,6 +27,7 @@ struct Tab {
// or create a special store/load system for it (might be less memory but more cpu)
std::shared_ptr<Node> domRootNode = nullptr;
//BrowsingHistory history;
// FIXME: we should move this into document component
std::unique_ptr<BrowsingHistory> history = nullptr;
std::shared_ptr<Tab> previousTab = nullptr;
};
@ -35,6 +36,7 @@ struct Tab { @@ -35,6 +36,7 @@ struct Tab {
class TabbedComponent : public MultiComponent {
public:
TabbedComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
// maybe you could return a handle so we can use it to select
void addTab(std::string passedTitle);
void updateWindowState(std::string newTitle);
std::vector<std::shared_ptr<Tab>>::iterator getTab(size_t tabId);
@ -55,14 +57,17 @@ public: @@ -55,14 +57,17 @@ public:
std::shared_ptr<Component> documentComponent = nullptr;
unsigned int tabAddColor = 0xF0F0F0FF;
unsigned int tabAddHoverColor = 0x008888FF;
unsigned int tabAddHoverColor = 0x008800FF;
unsigned int tabInactiveColor = 0x808080FF;
unsigned int tabHoverColor = 0x008888FF;
unsigned int tabActiveColor = 0x00FFFFFF;
unsigned int tabHoverColor = 0x8888BBFF;
unsigned int tabActiveColor = 0xE0E0E0FF;
unsigned int tabTextColor = 0x000000FF;
unsigned int tabTextHoverColor = 0x008888FF;
unsigned int tabCloseColor = 0x222222FF;
unsigned int tabCloseHoverColor = 0x008888FF;
unsigned int tabCloseHoverColor = 0x880000FF;
};
#endif

4
src/graphics/components/TextComponent.cpp

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#include "TextComponent.h"
#include <iostream>
#include <ctime>
#include <climits>
extern TextRasterizerCache *rasterizerCache;
@ -119,6 +120,9 @@ void TextComponent::rasterize(const int rawX, const int rawY) { @@ -119,6 +120,9 @@ void TextComponent::rasterize(const int rawX, const int rawY) {
request.availableWidth = availableWidth;
request.sourceStartX = rasterStartX;
request.sourceStartY = rasterStartY;
if (this->win) {
request.maxTextureSize = this->win->maxTextureSize & INT_MAX;
} // else called from input cstr, no win yet
request.noWrap = noWrap;
//std::cout << "rasterizing [" << text << "] @" << rawX << " availableWidth: " << availableWidth << " sourceStartX: " << rasterStartX << " noWrap: " << noWrap << std::endl;
std::shared_ptr<rasterizationResponse> response = textRasterizer->rasterize(request);

2
src/graphics/components/TextComponent.h

@ -45,7 +45,7 @@ public: @@ -45,7 +45,7 @@ public:
std::unique_ptr<unsigned char[]> textureData;
// backgroundColor
rgba backgroundColor;
unsigned int backgroundColor;
};
#endif

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

9
src/graphics/elements/BLOCKQUOTEElement.cpp

@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
#include "BLOCKQUOTEElement.h"
std::unique_ptr<Component> BLOCKQUOTEElement::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());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, x, y, 12, false, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}

14
src/graphics/elements/BLOCKQUOTEElement.h

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
#ifndef BLOCKQUOTEELEMENT_H
#define BLOCKQUOTEELEMENT_H
#include "Element.h"
#include "../components/Component.h"
#include "../components/TextComponent.h"
#include "../../html/TextNode.h"
class BLOCKQUOTEElement : 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);
};
#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

3
src/graphics/elements/Element.cpp

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
Element::~Element() {
}
std::unique_ptr<Component> Element::renderer(const std::shared_ptr<Node> node, const int x, const int y, const int windowWidth, const int windowHeight) {
std::unique_ptr<Component> Element::renderer(const ElementRenderRequest &request) {
return nullptr;
}

26
src/graphics/elements/Element.h

@ -4,18 +4,32 @@ @@ -4,18 +4,32 @@
#include <functional>
#include <memory>
#include "../components/Component.h"
#include "../opengl/Window.h"
#include "../../html/Node.h"
class ElementRenderRequest {
public:
// we read the attributes from node (color, size, positioning, font info)
// and pass them to a newly made component
// and then we set up behaviors for that new component
std::shared_ptr<Node> node;
// has really no purpose except to pass win
// it was supposed to be for positions, but ComponentBuilder handles all that now
// as an element we shouldn't really care too much about position
// if we set up the component right, it'll handle all that
std::shared_ptr<Component> parentComponent;
// can get this from parentComponent
//std::shared_ptr<Window> win;
};
// we define tokens in a language
// and convert them into a component (UI element)
class Element {
public:
bool isInline = false;
virtual ~Element();
// TODO: remove position
// add parent (node or component? well component because that's how the create component is going to calculate position
// well right now ComponentBuilder calls renderer and it has parent/window size
// component constructors don't really need parent/window size
// so we could remove window size too
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

11
src/graphics/elements/PElement.cpp

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
#include "PElement.h"
#include "../components/TextComponent.h"
#include "../../html/TextNode.h"
std::unique_ptr<Component> PElement::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());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, x, y, 12, false, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}

14
src/graphics/elements/PElement.h

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
#ifndef PELEMENT_H
#define PELEMENT_H
#include "Element.h"
#include "../components/Component.h"
#include "../components/TextComponent.h"
#include "../../html/TextNode.h"
class PElement : 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);
};
#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,</