|
|
|
@ -1,15 +1,16 @@
@@ -1,15 +1,16 @@
|
|
|
|
|
#include "browser.h" |
|
|
|
|
#include "scheduler.h" |
|
|
|
|
#include "graphics/components/TabbedComponent.h" |
|
|
|
|
#include "parsers/ntrml/NTRMLParser.h" |
|
|
|
|
#include "html/HTMLParser.h" |
|
|
|
|
#include "interfaces/components/TabbedComponent.h" |
|
|
|
|
#include "parsers/markup/ntrml/NTRMLParser.h" |
|
|
|
|
#include "parsers/markup/html/HTMLParser.h" |
|
|
|
|
|
|
|
|
|
#include "graphics/components/InputComponent.h" |
|
|
|
|
#include "graphics/components/ImageComponent.h" |
|
|
|
|
#include "graphics/components/TabbedComponent.h" |
|
|
|
|
#include "graphics/components/ButtonComponent.h" |
|
|
|
|
#include "interfaces/components/InputComponent.h" |
|
|
|
|
#include "interfaces/components/ImageComponent.h" |
|
|
|
|
#include "interfaces/components/TabbedComponent.h" |
|
|
|
|
#include "interfaces/components/ButtonComponent.h" |
|
|
|
|
|
|
|
|
|
#include <fstream> |
|
|
|
|
#include <glob.h> |
|
|
|
|
|
|
|
|
|
// why can't I const this?
|
|
|
|
|
std::unique_ptr<Scheduler> scheduler = std::make_unique<Scheduler>(); |
|
|
|
@ -97,7 +98,244 @@ void doOnClick(std::string type, Component *component, Window *win) {
@@ -97,7 +98,244 @@ void doOnClick(std::string type, Component *component, Window *win) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::shared_ptr<Node> Browser::loadTheme(std::string filename) { |
|
|
|
|
std::string ntrml, line; |
|
|
|
|
std::ifstream myfile(filename); |
|
|
|
|
if (myfile.is_open()) { |
|
|
|
|
while(getline(myfile, line)) { |
|
|
|
|
ntrml += line; |
|
|
|
|
} |
|
|
|
|
myfile.close(); |
|
|
|
|
} else { |
|
|
|
|
std::cout << "Couldnt read " << filename << std::endl; |
|
|
|
|
} |
|
|
|
|
NTRMLParser uiParser; |
|
|
|
|
//std::cout << "Browser read [" << ntrml << "]" << std::endl;
|
|
|
|
|
return uiParser.parse(ntrml); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::destroyTheme() { |
|
|
|
|
for(auto win: this->windows) { |
|
|
|
|
if (win->tabComponent) { |
|
|
|
|
TabbedComponent *tabbedComponent = dynamic_cast<TabbedComponent *>(win->tabComponent.get()); |
|
|
|
|
for(auto tab: tabbedComponent->tabs) { |
|
|
|
|
tabbedComponent->removeTab(tab->id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
win->addressComponent = nullptr; |
|
|
|
|
win->tabComponent = nullptr; |
|
|
|
|
for(auto layer: win->ui->layers) { |
|
|
|
|
layer.reset(); |
|
|
|
|
} |
|
|
|
|
win->ui->layers.clear(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::rebuildTheme() { |
|
|
|
|
for(auto win: this->windows) { |
|
|
|
|
|
|
|
|
|
// convert uiRootNode into a component list
|
|
|
|
|
std::shared_ptr<Component> rootComponent = std::make_shared<Component>(); |
|
|
|
|
rootComponent->name = "rootComponent of browser"; |
|
|
|
|
// we build one global tree that each layer has a child node in
|
|
|
|
|
this->layers.clear(); // nuke any layers we have
|
|
|
|
|
this->createComponentTree(this->uiRootNode, rootComponent, win); |
|
|
|
|
//Component::printComponentTree(rootComponent, 0);
|
|
|
|
|
|
|
|
|
|
// these probably should be fatal
|
|
|
|
|
if (!win->addressComponent) { |
|
|
|
|
std::cout << "ERROR: no addressComponent" << std::endl; |
|
|
|
|
} |
|
|
|
|
if (!win->tabComponent) { |
|
|
|
|
std::cout << "ERROR: no tabComponent" << std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// we want each window to has it's own component tree, so each address bar can have different values
|
|
|
|
|
size_t layerCount = 0; |
|
|
|
|
for(auto layer: this->layers) { |
|
|
|
|
// set proper vertices
|
|
|
|
|
layer->resize(win->windowWidth, win->windowHeight); |
|
|
|
|
// transfer layer
|
|
|
|
|
win->ui->layers.push_back(layer); |
|
|
|
|
// debug
|
|
|
|
|
/*
|
|
|
|
|
std::cout << "layer: " << layerCount << std::endl; |
|
|
|
|
Component::printComponentTree(layer, 0); |
|
|
|
|
*/ |
|
|
|
|
layerCount++; |
|
|
|
|
layer.reset(); // deallocate our local layers
|
|
|
|
|
} |
|
|
|
|
rootComponent.reset(); |
|
|
|
|
|
|
|
|
|
//newWindow->rootComponent = rootComponent;
|
|
|
|
|
//newWindow->ui->rootComponent = rootComponent;
|
|
|
|
|
win->renderDirty = true; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::transferTheme(std::string filename) { |
|
|
|
|
// assuming we don't need the NodeTree to get our values
|
|
|
|
|
this->uiRootNode.reset(); |
|
|
|
|
this->uiRootNode = this->loadTheme(filename); |
|
|
|
|
|
|
|
|
|
for(auto win: this->windows) { |
|
|
|
|
glfwMakeContextCurrent(win->window); |
|
|
|
|
|
|
|
|
|
TabbedComponent *oldTabbedComponent = nullptr; |
|
|
|
|
if (win->tabComponent) { |
|
|
|
|
oldTabbedComponent = dynamic_cast<TabbedComponent *>(win->tabComponent.get()); |
|
|
|
|
} |
|
|
|
|
win->tabComponent = nullptr; // release to release
|
|
|
|
|
win->addressComponent = nullptr; // I think this is ok to release now
|
|
|
|
|
|
|
|
|
|
// convert uiRootNode into a component list
|
|
|
|
|
std::shared_ptr<Component> rootComponent = std::make_shared<Component>(); |
|
|
|
|
rootComponent->name = "rootComponent of browser"; |
|
|
|
|
this->layers.clear(); // nuke any layers we had (doesn't nuke window layers)
|
|
|
|
|
// we build one global tree that each layer has a child node in
|
|
|
|
|
this->createComponentTree(this->uiRootNode, rootComponent, win); |
|
|
|
|
//Component::printComponentTree(rootComponent, 0);
|
|
|
|
|
|
|
|
|
|
// these probably should be fatal
|
|
|
|
|
if (!win->addressComponent) { |
|
|
|
|
std::cout << "ERROR: no addressComponent" << std::endl; |
|
|
|
|
} |
|
|
|
|
if (!win->tabComponent) { |
|
|
|
|
std::cout << "ERROR: no tabComponent" << std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ok now we need to transfer the tabs over
|
|
|
|
|
if (oldTabbedComponent) { |
|
|
|
|
// should have been set in createComponentTree
|
|
|
|
|
TabbedComponent *newTabbedComponent = dynamic_cast<TabbedComponent *>(win->tabComponent.get()); |
|
|
|
|
if (newTabbedComponent) { |
|
|
|
|
size_t oldSelectedTabId = oldTabbedComponent->selectedTabId; |
|
|
|
|
std::shared_ptr<Tab> newSelectedTab = nullptr; |
|
|
|
|
std::cout << "going to copy " << oldTabbedComponent->tabs.size() << " tab(s) over to new theme" << std::endl; |
|
|
|
|
for(auto tab: oldTabbedComponent->tabs) { |
|
|
|
|
DocumentComponent *oldDocComponent = dynamic_cast<DocumentComponent *>(tab->contents.get()); |
|
|
|
|
if (oldDocComponent) { |
|
|
|
|
//std::cout << "Reading DOM" << std::endl;
|
|
|
|
|
//printNode(oldDocComponent->domRootNode, 0);
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Tab> nTab = newTabbedComponent->addTab(tab->titleBox->text); |
|
|
|
|
newTabbedComponent->selectTab(nTab); |
|
|
|
|
// maybe faster if we can skip the component tree rebuild
|
|
|
|
|
newTabbedComponent->loadDomIntoTab(oldDocComponent->domRootNode, tab->titleBox->text); |
|
|
|
|
//newTabbedComponent->documentComponent.get()
|
|
|
|
|
DocumentComponent *newDocComponent = dynamic_cast<DocumentComponent *>(newTabbedComponent->tabs.back()->contents.get()); |
|
|
|
|
if (newDocComponent) { |
|
|
|
|
// really slow and we don't need to do this for all tabs
|
|
|
|
|
// not sure why this is required...
|
|
|
|
|
//newDocComponent->setDOM(oldDocComponent->domRootNode);
|
|
|
|
|
//std::cout << "Checking DOM" << std::endl;
|
|
|
|
|
//printNode(newTabbedComponent->documentComponent->, 0);
|
|
|
|
|
newDocComponent->render(); // flush out components
|
|
|
|
|
//newDocComponent->domDirty = true; // is most accurate
|
|
|
|
|
} else { |
|
|
|
|
std::cout << "new tab had no doc" << std::endl; |
|
|
|
|
} |
|
|
|
|
if (tab->id == oldSelectedTabId) { |
|
|
|
|
// translate old selected id into new id
|
|
|
|
|
newSelectedTab = nTab; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
std::cout << "old tab had no doc" << std::endl; |
|
|
|
|
} |
|
|
|
|
// this breaks everything
|
|
|
|
|
//oldTabbedComponent->removeTab(tab->id);
|
|
|
|
|
} |
|
|
|
|
if (newSelectedTab) { |
|
|
|
|
newTabbedComponent->selectTab(newSelectedTab); |
|
|
|
|
/*
|
|
|
|
|
DocumentComponent *newDocComponent = dynamic_cast<DocumentComponent *>(newTabbedComponent->documentComponent.get()); |
|
|
|
|
if (newDocComponent) { |
|
|
|
|
// FIXME: can only in render active window/ogl context
|
|
|
|
|
newDocComponent->render(); // flush out components
|
|
|
|
|
} else { |
|
|
|
|
std::cout << "new selected tab had no doc" << std::endl; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
} else { |
|
|
|
|
std::cout << "no new selected tab" << std::endl; |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
std::cout << "new tabbed component has " << newTabbedComponent->tabs.size() << " tab(s) over from old theme" << std::endl; |
|
|
|
|
for(auto tab: newTabbedComponent->tabs) { |
|
|
|
|
DocumentComponent *newDocComponent = dynamic_cast<DocumentComponent *>(tab->contents.get()); |
|
|
|
|
std::cout << "checking tab DOM" << std::endl; |
|
|
|
|
printNode(newDocComponent->domRootNode, 0); |
|
|
|
|
} |
|
|
|
|
if (newTabbedComponent->documentComponent) { |
|
|
|
|
DocumentComponent *newDocComponent = dynamic_cast<DocumentComponent *>(newTabbedComponent->documentComponent.get()); |
|
|
|
|
std::cout << "checking selected DOM" << std::endl; |
|
|
|
|
printNode(newDocComponent->domRootNode, 0); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
} else { |
|
|
|
|
std::cout << "new theme didnt have tab component" << std::endl; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
std::cout << "old theme didnt have tab component" << std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// now we're officially done with old layer, nuked them
|
|
|
|
|
for(auto layer: win->ui->layers) { |
|
|
|
|
layer.reset(); |
|
|
|
|
} |
|
|
|
|
win->ui->layers.clear(); |
|
|
|
|
|
|
|
|
|
// we want each window to has it's own component tree, so each address bar can have different values
|
|
|
|
|
size_t layerCount = 0; |
|
|
|
|
for(auto layer: this->layers) { |
|
|
|
|
// set proper vertices
|
|
|
|
|
layer->resize(win->windowWidth, win->windowHeight); |
|
|
|
|
// transfer layer
|
|
|
|
|
win->ui->layers.push_back(layer); |
|
|
|
|
// debug
|
|
|
|
|
/*
|
|
|
|
|
std::cout << "layer: " << layerCount << std::endl; |
|
|
|
|
Component::printComponentTree(layer, 0); |
|
|
|
|
*/ |
|
|
|
|
layerCount++; |
|
|
|
|
layer.reset(); // deallocate our local layers
|
|
|
|
|
} |
|
|
|
|
rootComponent.reset(); |
|
|
|
|
|
|
|
|
|
//newWindow->rootComponent = rootComponent;
|
|
|
|
|
//newWindow->ui->rootComponent = rootComponent;
|
|
|
|
|
win->renderDirty = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::NextTheme() { |
|
|
|
|
glob_t glob_result; |
|
|
|
|
static unsigned int t = 0; |
|
|
|
|
glob("*.ntrml", GLOB_TILDE, NULL, &glob_result); |
|
|
|
|
t++; |
|
|
|
|
if (t == glob_result.gl_pathc) t = 0; |
|
|
|
|
/*
|
|
|
|
|
for(unsigned int i = 0; i < glob_result.gl_pathc; ++i){ |
|
|
|
|
if (t == i) std::cout << "*"; |
|
|
|
|
std::cout << glob_result.gl_pathv[i] << std::endl; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
// this works decently, but only destroys first window
|
|
|
|
|
/*
|
|
|
|
|
this->destroyTheme(); |
|
|
|
|
//deleteNode(this->uiRootNode);
|
|
|
|
|
this->uiRootNode.reset(); |
|
|
|
|
this->uiRootNode = this->loadTheme(std::string(glob_result.gl_pathv[t])); |
|
|
|
|
this->rebuildTheme(); |
|
|
|
|
*/ |
|
|
|
|
this->transferTheme(glob_result.gl_pathv[t]); |
|
|
|
|
// start with removing existing theme
|
|
|
|
|
// and replacing with new version of existing theme
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Browser::Browser() { |
|
|
|
|
/*
|
|
|
|
|
std::string ntrml, line; |
|
|
|
|
std::ifstream myfile("browser.ntrml"); |
|
|
|
|
if (myfile.is_open()) { |
|
|
|
@ -110,11 +348,13 @@ Browser::Browser() {
@@ -110,11 +348,13 @@ Browser::Browser() {
|
|
|
|
|
} |
|
|
|
|
NTRMLParser uiParser; |
|
|
|
|
//std::cout << "Browser read [" << ntrml << "]" << std::endl;
|
|
|
|
|
this->uiRootNode = uiParser.parse(ntrml); |
|
|
|
|
*/ |
|
|
|
|
//this->uiRootNode = uiParser.parse(ntrml);
|
|
|
|
|
this->uiRootNode = this->loadTheme("browser.ntrml"); |
|
|
|
|
printNode(this->uiRootNode, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent, const std::shared_ptr<Window> win) { |
|
|
|
|
void Browser::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr<Component> &parentComponent, std::shared_ptr<Window> win) { |
|
|
|
|
// FIXME: remove these 2 vars
|
|
|
|
|
int winWidth = win->windowWidth; |
|
|
|
|
int winHeight = win->windowHeight; |
|
|
|
@ -135,14 +375,24 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -135,14 +375,24 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
tag = tagNode->tag; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::shared_ptr<Component> component = nullptr; |
|
|
|
|
if (!tagNode) { |
|
|
|
|
// usually the root node...
|
|
|
|
|
//std::cout << "!tagnode" << std::endl;
|
|
|
|
|
component = std::make_shared<Component>(); |
|
|
|
|
for (std::shared_ptr<Node> child : node->children) { |
|
|
|
|
createComponentTree(child, component, win); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//std::cout << "Looking at tag[" << tag << "]" << std::endl;
|
|
|
|
|
if (tag == "layer") { |
|
|
|
|
// the layering only works for default layout due to the ordering we're doign in window.render
|
|
|
|
|
component = std::make_shared<Component>(); |
|
|
|
|
|
|
|
|
|
this->layers.push_back(component); |
|
|
|
|
//parentComponent = component;
|
|
|
|
|
//std::swap(component, parentComponent);
|
|
|
|
|
//std::cout << "there are now " << this->layers.size() << " layers" << std::endl;
|
|
|
|
|
} else if (tag == "body") { |
|
|
|
|
if (tagNode->properties.find("bgcolor") != tagNode->properties.end()) { |
|
|
|
@ -158,23 +408,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -158,23 +408,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
glClearColor(r, g, b, a); |
|
|
|
|
} |
|
|
|
|
} else if (tag == "img") { |
|
|
|
|
/*
|
|
|
|
|
UILayoutV2 imgSetup; |
|
|
|
|
imgSetup.width.px = 512; |
|
|
|
|
imgSetup.height.px = 512; |
|
|
|
|
if (tagNode->properties.find("width") != tagNode->properties.end()) { |
|
|
|
|
imgSetup.width.requested = true; |
|
|
|
|
imgSetup.width.px = std::stoi(tagNode->properties["width"]); |
|
|
|
|
} |
|
|
|
|
if (tagNode->properties.find("height") != tagNode->properties.end()) { |
|
|
|
|
imgSetup.height.requested = true; |
|
|
|
|
imgSetup.height.px = std::stoi(tagNode->properties["height"]); |
|
|
|
|
} |
|
|
|
|
if (tagNode->properties.find("left") != tagNode->properties.end()) { |
|
|
|
|
imgSetup.left.requested = true; |
|
|
|
|
imgSetup.left.pct = std::stoi(tagNode->properties["left"]); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
std::string src = "anime.pnm"; |
|
|
|
|
if (tagNode->properties.find("src") != tagNode->properties.end()) { |
|
|
|
|
src = tagNode->properties["src"]; |
|
|
|
@ -189,13 +422,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -189,13 +422,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
//doOnClick(std::string type, Component &component, Window *win)
|
|
|
|
|
doOnClick(tagNode->properties["onClick"], img.get(), win.get()); |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
img->uiControl.x = { imgSetup.left.pct , imgSetup.left.px }; |
|
|
|
|
img->uiControl.y = { imgSetup.top.pct , imgSetup.top.px }; |
|
|
|
|
img->uiControl.w = { imgSetup.width.pct, imgSetup.width.px }; |
|
|
|
|
img->uiControl.h = { imgSetup.width.pct, imgSetup.height.px }; |
|
|
|
|
img->boundToPage = false; |
|
|
|
|
*/ |
|
|
|
|
img->isPickable = false; |
|
|
|
|
img->name = "img"; |
|
|
|
|
if (tagNode->properties.find("name") != tagNode->properties.end()) { |
|
|
|
@ -219,58 +445,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -219,58 +445,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
} |
|
|
|
|
component = text; |
|
|
|
|
} else if (tag == "box") { |
|
|
|
|
/*
|
|
|
|
|
UILayoutV2 boxSetup; |
|
|
|
|
boxSetup.width.px = 32; |
|
|
|
|
boxSetup.height.px = 32; |
|
|
|
|
if (tagNode->properties.find("width") != tagNode->properties.end()) { |
|
|
|
|
boxSetup.width.requested = true; |
|
|
|
|
boxSetup.width.px = std::stoi(tagNode->properties["width"]); |
|
|
|
|
} |
|
|
|
|
if (tagNode->properties.find("height") != tagNode->properties.end()) { |
|
|
|
|
boxSetup.height.requested = true; |
|
|
|
|
boxSetup.height.px = std::stoi(tagNode->properties["height"]); |
|
|
|
|
} |
|
|
|
|
if (tagNode->properties.find("top") != tagNode->properties.end()) { |
|
|
|
|
boxSetup.top.requested = true; |
|
|
|
|
boxSetup.top.px = std::stoi(tagNode->properties["top"]); |
|
|
|
|
} |
|
|
|
|
if (tagNode->properties.find("bottom") != tagNode->properties.end()) { |
|
|
|
|
boxSetup.bottom.requested = true; |
|
|
|
|
boxSetup.bottom.px = std::stoi(tagNode->properties["bottom"]); |
|
|
|
|
} |
|
|
|
|
if (tagNode->properties.find("left") != tagNode->properties.end()) { |
|
|
|
|
boxSetup.left.requested = true; |
|
|
|
|
boxSetup.left.px = std::stoi(tagNode->properties["left"]); |
|
|
|
|
} |
|
|
|
|
if (tagNode->properties.find("right") != tagNode->properties.end()) { |
|
|
|
|
boxSetup.right.requested = true; |
|
|
|
|
boxSetup.right.px = std::stoi(tagNode->properties["right"]); |
|
|
|
|
} |
|
|
|
|
std::unique_ptr<std::pair<UImetricV2, UImetricV2>> xUI = getUIMetric(boxSetup.left, boxSetup.right, boxSetup.width); |
|
|
|
|
std::unique_ptr<std::pair<UImetricV2, UImetricV2>> yUI = getUIMetric(boxSetup.top, boxSetup.bottom, boxSetup.height); |
|
|
|
|
int cX = 0, cY = 0, cW = boxSetup.width.px, cH = boxSetup.height.px; |
|
|
|
|
double wPct = 100, hPct = 100; |
|
|
|
|
int wPx = 0, hPx = 0; |
|
|
|
|
if (xUI) { |
|
|
|
|
//std::cout << "box XUI at " << xUI->first.pct << "% +" << xUI->first.px << std::endl;
|
|
|
|
|
//std::cout << "box XUI for " << xUI->second.pct << "% +" << xUI->second.px << std::endl;
|
|
|
|
|
cX = (xUI->first.pct * 0.01 * winWidth) + xUI->first.px; |
|
|
|
|
cW = (xUI->second.pct * 0.01 * winWidth) + xUI->second.px; |
|
|
|
|
wPct = xUI->second.pct; |
|
|
|
|
wPx = xUI->second.px; |
|
|
|
|
std::cout << "box X at " << cX << " for " << cW << std::endl; |
|
|
|
|
std::cout << "box W at " << wPct << "% for " << wPx << std::endl; |
|
|
|
|
} |
|
|
|
|
if (yUI) { |
|
|
|
|
cY = (yUI->first.pct * 0.01 * winHeight) + yUI->first.px; |
|
|
|
|
cH = (yUI->second.pct * 0.01 * winHeight) + yUI->second.px; |
|
|
|
|
hPct = yUI->second.pct; |
|
|
|
|
hPx = yUI->second.px; |
|
|
|
|
std::cout << "box Y at " << cY << " for " << cH << std::endl; |
|
|
|
|
std::cout << "box H at " << hPct << "% for " << hPx << std::endl; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
unsigned int color = 0x888888FF; |
|
|
|
|
if (tagNode->properties.find("color") != tagNode->properties.end()) { |
|
|
|
|
std::stringstream ss; |
|
|
|
@ -288,13 +462,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -288,13 +462,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
} else { |
|
|
|
|
box = std::make_unique<BoxComponent>(0, 0, 1, 1, color, winWidth, winHeight); |
|
|
|
|
} |
|
|
|
|
//navBackground->y = -64;
|
|
|
|
|
/*
|
|
|
|
|
box->uiControl.x = { 0, cX }; //
|
|
|
|
|
box->uiControl.y = { 100, -cH - cY }; //
|
|
|
|
|
box->uiControl.w = { wPct, wPx }; //
|
|
|
|
|
box->uiControl.h = { hPct, hPx }; //
|
|
|
|
|
*/ |
|
|
|
|
box->boundToPage = false; // have to set this before setUpUI
|
|
|
|
|
box->setUpUI(tagNode->properties, win.get()); |
|
|
|
|
box->isPickable = false; |
|
|
|
@ -353,14 +520,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -353,14 +520,6 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
std::shared_ptr<InputComponent> navAddressBar = std::make_unique<InputComponent>(0, 0, 384.0f, 24.0f, winWidth, winHeight); |
|
|
|
|
navAddressBar->boundToPage = false; // have to set this before setUpUI
|
|
|
|
|
navAddressBar->setUpUI(tagNode->properties, win.get()); |
|
|
|
|
/*
|
|
|
|
|
navAddressBar->x = 192.0f; |
|
|
|
|
navAddressBar->y = winHeight - 48.0f; |
|
|
|
|
navAddressBar->uiControl.x = { 0, 192 }; // 192px
|
|
|
|
|
navAddressBar->uiControl.y = { 100, -48 }; // top - 48px
|
|
|
|
|
navAddressBar->uiControl.w = { 100, -384 }; // w - 384px
|
|
|
|
|
navAddressBar->uiControl.h = { 0, 24 }; // 24px
|
|
|
|
|
*/ |
|
|
|
|
navAddressBar->name = "navAddressBar"; |
|
|
|
|
|
|
|
|
|
navAddressBar->onEnter=[win](std::string value) { |
|
|
|
@ -392,6 +551,8 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -392,6 +551,8 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
component = navAddressBar; |
|
|
|
|
} else if (tag == "tabselector") { |
|
|
|
|
std::shared_ptr<TabbedComponent> tabbedComponent = std::make_shared<TabbedComponent>(0, 0, static_cast<float>(winWidth), static_cast<float>(winHeight - 64), winWidth, winHeight); |
|
|
|
|
tabbedComponent->win = win; |
|
|
|
|
win->tabComponent = tabbedComponent; |
|
|
|
|
tabbedComponent->boundToPage = false; // have to set this before setUpUI
|
|
|
|
|
tabbedComponent->setUpUI(tagNode->properties, win.get()); |
|
|
|
|
tabbedComponent->name = "tabbedComponent"; |
|
|
|
@ -403,9 +564,9 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -403,9 +564,9 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
tabbedComponent->uiControl.h = { 100, -64 }; // 100% - 64px
|
|
|
|
|
tabbedComponent->boundToPage = false; |
|
|
|
|
*/ |
|
|
|
|
tabbedComponent->win = win; |
|
|
|
|
win->tabComponent = tabbedComponent; |
|
|
|
|
component = tabbedComponent; |
|
|
|
|
// make the UI focus on it to relay keyboard events
|
|
|
|
|
win->ui->relayKeyboardComponent = tabbedComponent; |
|
|
|
|
} else { |
|
|
|
|
std::cout << "Browser::createComponentTree - unknown tag[" << tag << "]" << std::endl; |
|
|
|
|
} |
|
|
|
@ -421,6 +582,7 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
@@ -421,6 +582,7 @@ void Browser::createComponentTree(const std::shared_ptr<Node> node, const std::s
|
|
|
|
|
for (std::shared_ptr<Node> child : node->children) { |
|
|
|
|
createComponentTree(child, component, win); |
|
|
|
|
} |
|
|
|
|
component.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::addWindow() { |
|
|
|
@ -431,18 +593,44 @@ void Browser::addWindow() {
@@ -431,18 +593,44 @@ void Browser::addWindow() {
|
|
|
|
|
newWindow->windowHeight = 640; |
|
|
|
|
newWindow->init(); // load our UI into it
|
|
|
|
|
|
|
|
|
|
// we want each window to has it's own component tree, so each address bar can have different values
|
|
|
|
|
// convert uiRootNode into a component list
|
|
|
|
|
std::shared_ptr<Component> p_rootComponent = std::make_shared<Component>(); |
|
|
|
|
p_rootComponent->name = "rootComponent of browser"; |
|
|
|
|
// we build one global tree that each layer has a child node in
|
|
|
|
|
this->layers.clear(); // nuke any layers we have
|
|
|
|
|
this->createComponentTree(this->uiRootNode, p_rootComponent, newWindow); |
|
|
|
|
p_rootComponent->resize(newWindow->windowWidth, newWindow->windowHeight); |
|
|
|
|
|
|
|
|
|
Component::printComponentTree(p_rootComponent, 0); |
|
|
|
|
|
|
|
|
|
newWindow->rootComponent = p_rootComponent; |
|
|
|
|
// these probably should be fatal
|
|
|
|
|
if (!newWindow->addressComponent) { |
|
|
|
|
std::cout << "ERROR: no addressComponent" << std::endl; |
|
|
|
|
} |
|
|
|
|
if (!newWindow->tabComponent) { |
|
|
|
|
std::cout << "ERROR: no tabComponent" << std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// we want each window to has it's own component tree, so each address bar can have different values
|
|
|
|
|
size_t layerCount = 0; |
|
|
|
|
for(auto layer: this->layers) { |
|
|
|
|
// set proper vertices
|
|
|
|
|
layer->resize(newWindow->windowWidth, newWindow->windowHeight); |
|
|
|
|
// transfer layer
|
|
|
|
|
newWindow->ui->layers.push_back(layer); |
|
|
|
|
// debug
|
|
|
|
|
std::cout << "layer: " << layerCount << std::endl; |
|
|
|
|
Component::printComponentTree(layer, 0); |
|
|
|
|
layerCount++; |
|
|
|
|
layer.reset(); // deallocate our local layers
|
|
|
|
|
} |
|
|
|
|
p_rootComponent.reset(); |
|
|
|
|
|
|
|
|
|
//newWindow->rootComponent = rootComponent;
|
|
|
|
|
//newWindow->ui->rootComponent = rootComponent;
|
|
|
|
|
newWindow->renderDirty = true; |
|
|
|
|
|
|
|
|
|
this->windows.push_back(std::move(newWindow)); |
|
|
|
|
this->windows.push_back(newWindow); |
|
|
|
|
newWindow.reset(); |
|
|
|
|
|
|
|
|
|
if (!activeWindow) { |
|
|
|
|
//std::cout << "Browser::addWindow - setting active window" << std::endl;
|
|
|
|
|
activeWindow = this->windows.back().get(); |
|
|
|
|