Browse Source

merge

master
Odilitime 5 years ago
parent
commit
3dccc6a1ab
  1. 64
      src/app/App.cpp
  2. 4
      src/app/browser/Browser.cpp
  3. 6
      src/app/browser/Browser.h
  4. 12
      src/interfaces/elements/SCRIPTElement.cpp
  5. 8
      src/interfaces/graphical/renderers/glfw/Window.cpp
  6. 42
      src/interfaces/graphical/renderers/glfw/opengl.cpp
  7. 22
      src/main.cpp
  8. 886
      src/parsers/scripting/javascript/JSParser.cpp

64
src/app/App.cpp

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
#include "App.h"
#include "../tools/Scheduler.h"
#include "app.h"
#include "../tools/scheduler.h"
#include "../interfaces/components/TabbedComponent.h"
#include "../parsers/markup/ntrml/NTRMLParser.h"
#include "../parsers/markup/html/HTMLParser.h"
@ -62,18 +62,18 @@ void doOnClick(std::string type, Component *component, Window *win) { @@ -62,18 +62,18 @@ void doOnClick(std::string type, Component *component, Window *win) {
return;
}
//std::cout << "Browser:zdoOnClick.navAddressBar->onClick - got " << value << std::endl;
TabbedComponent *p_tabComponent = dynamic_cast<TabbedComponent*>(win->tabComponent.get());
if (p_tabComponent) {
if (!p_tabComponent->tabs.size()) {
p_tabComponent->addTab("Loading...");
p_tabComponent->selectTab(p_tabComponent->tabs.back());
win->renderDirty = true;
win->render(); // display loading tab before IO
}
}
std::shared_ptr<DocumentComponent> docComponent = win->getActiveDocumentComponent();
if (docComponent) {
//std::cout << "Browser:zdoOnClick.navAddressBar->onClick - Found an active document component" << std::endl;
@ -137,7 +137,7 @@ void App::rebuildTheme() { @@ -137,7 +137,7 @@ void App::rebuildTheme() {
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;
@ -145,7 +145,7 @@ void App::rebuildTheme() { @@ -145,7 +145,7 @@ void App::rebuildTheme() {
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) {
@ -162,11 +162,11 @@ void App::rebuildTheme() { @@ -162,11 +162,11 @@ void App::rebuildTheme() {
layer.reset(); // deallocate our local layers
}
rootComponent.reset();
//newWindow->rootComponent = rootComponent;
//newWindow->ui->rootComponent = rootComponent;
win->renderDirty = true;
}
}
@ -177,14 +177,14 @@ void App::transferTheme(std::string filename) { @@ -177,14 +177,14 @@ void App::transferTheme(std::string 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";
@ -192,7 +192,7 @@ void App::transferTheme(std::string filename) { @@ -192,7 +192,7 @@ void App::transferTheme(std::string filename) {
// 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;
@ -200,7 +200,7 @@ void App::transferTheme(std::string filename) { @@ -200,7 +200,7 @@ void App::transferTheme(std::string filename) {
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
@ -214,7 +214,7 @@ void App::transferTheme(std::string filename) { @@ -214,7 +214,7 @@ void App::transferTheme(std::string filename) {
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
@ -275,13 +275,13 @@ void App::transferTheme(std::string filename) { @@ -275,13 +275,13 @@ void App::transferTheme(std::string filename) {
} 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) {
@ -298,7 +298,7 @@ void App::transferTheme(std::string filename) { @@ -298,7 +298,7 @@ void App::transferTheme(std::string filename) {
layer.reset(); // deallocate our local layers
}
rootComponent.reset();
//newWindow->rootComponent = rootComponent;
//newWindow->ui->rootComponent = rootComponent;
win->renderDirty = true;
@ -383,7 +383,7 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr< @@ -383,7 +383,7 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr<
ss << std::hex << tagNode->properties["bgcolor"];
ss >> win->clearColor;
//std::cout << "set clear color " << std::hex << win->clearColor << std::dec << std::endl;
float r = (static_cast<float>((win->clearColor >> 24) & 0xFF)) / 255;
float g = (static_cast<float>((win->clearColor >> 16) & 0xFF)) / 255;
float b = (static_cast<float>((win->clearColor >> 8) & 0xFF)) / 255;
@ -443,7 +443,7 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr< @@ -443,7 +443,7 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr<
ss >> color;
//std::cout << "read color " << tagNode->properties["color"] << " as " << std::hex << color << std::dec << std::endl;
}
// winHeight minus because box coordinates? yes
//std::cout << "placing box at " << cX << "," << cY << " " << cW << "x" << cH << " color: " << std::hex << color << std::dec << std::endl;
//std::shared_ptr<BoxComponent> box = std::make_unique<BoxComponent>(cX, winHeight - cH - cY, cW, cH, color, winWidth, winHeight);
@ -515,18 +515,18 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr< @@ -515,18 +515,18 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr<
navAddressBar->onEnter=[win](std::string value) {
std::cout << "navAddressBar::onEnter got " << value << std::endl;
TabbedComponent *p_tabComponent = dynamic_cast<TabbedComponent*>(win->tabComponent.get());
if (p_tabComponent) {
if (!p_tabComponent->tabs.size()) {
p_tabComponent->addTab("Loading...");
p_tabComponent->selectTab(p_tabComponent->tabs.back());
win->renderDirty = true;
win->render(); // display loading tab before IO
}
}
std::shared_ptr<DocumentComponent> docComponent = win->getActiveDocumentComponent();
if (docComponent) {
std::cout << "Found an active document component" << std::endl;
@ -536,7 +536,7 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr< @@ -536,7 +536,7 @@ void App::createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr<
std::cout << "No active document component" << std::endl;
}
};
navAddressBar->win = win;
win->addressComponent = navAddressBar;
component = navAddressBar;
@ -585,12 +585,12 @@ void App::addJSDebuggerWindow() { @@ -585,12 +585,12 @@ void App::addJSDebuggerWindow() {
newWindow->init(); // load our UI into it
std::shared_ptr<Component> p_rootComponent = std::make_shared<Component>();
p_rootComponent->name = "rootComponent of jsconsole";
std::shared_ptr<TextComponent> outputComp = std::make_shared<TextComponent>("NeTRunner JavaScript console", 0, 0, 12, false, 0x000000FF, newWindow->windowWidth, newWindow->windowHeight);
outputComp->win = newWindow;
newWindow->ui->layers.push_back(outputComp);
outputComp.reset();
/*
std::shared_ptr<InputComponent> inputComp = std::make_shared<InputComponent>(0, 0, 1024, 12, newWindow->windowWidth, newWindow->windowHeight);
inputComp->win = newWindow;
@ -609,15 +609,15 @@ void App::addWindow() { @@ -609,15 +609,15 @@ void App::addWindow() {
newWindow->windowWidth = 1024;
newWindow->windowHeight = 640;
newWindow->init(); // load our UI into it
// 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->createComponentTree(this->uiRootNode, p_rootComponent, newWindow);
//Component::printComponentTree(p_rootComponent, 0);
// these probably should be fatal
if (!newWindow->addressComponent) {
std::cout << "ERROR: no addressComponent" << std::endl;
@ -625,7 +625,7 @@ void App::addWindow() { @@ -625,7 +625,7 @@ void App::addWindow() {
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) {
@ -643,14 +643,14 @@ void App::addWindow() { @@ -643,14 +643,14 @@ void App::addWindow() {
}
this->layers.clear(); // nuke any layers we have
p_rootComponent.reset();
//newWindow->rootComponent = rootComponent;
//newWindow->ui->rootComponent = rootComponent;
newWindow->renderDirty = true;
this->windows.push_back(newWindow);
newWindow.reset();
if (!activeWindow) {
//std::cout << "Browser::addWindow - setting active window" << std::endl;
activeWindow = this->windows.back().get();

4
src/app/browser/Browser.cpp

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#include "Browser.h"
#include "browser.h"
#include "../../interfaces/components/TabbedComponent.h"
#include "../../parsers/markup/html/HTMLParser.h"
@ -27,9 +27,11 @@ Browser::Browser() { @@ -27,9 +27,11 @@ Browser::Browser() {
//printNode(this->uiRootNode, 0);
}
/*
void Browser::addWindow() {
App::addWindow();
}
*/
std::shared_ptr<DocumentComponent> Browser::getActiveDocumentComponent() {
if (!activeWindow) {

6
src/app/browser/Browser.h

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#ifndef BROWSER_H
#define BROWSER_H
#include "../App.h"
#include "../app.h"
//#include "interfaces/graphical/renderers/glfw/Window.h"
//#include "interfaces/components/Component.h"
#include "../../interfaces/components/DocumentComponent.h"
@ -21,9 +21,9 @@ class Browser : public App { @@ -21,9 +21,9 @@ class Browser : public App {
private:
public:
Browser();
void addWindow();
//void addWindow();
std::shared_ptr<DocumentComponent> getActiveDocumentComponent();
std::shared_ptr<Component> tabComponent = nullptr;
std::shared_ptr<Component> addressComponent = nullptr;

12
src/interfaces/elements/SCRIPTElement.cpp

@ -47,15 +47,17 @@ std::unique_ptr<Component> SCRIPTElement::renderer(const ElementRenderRequest &r @@ -47,15 +47,17 @@ std::unique_ptr<Component> SCRIPTElement::renderer(const ElementRenderRequest &r
// parse JS
//std::cout << "SCRIPTElement::renderer - source: " << source << std::endl;
JSParser parser;
std::shared_ptr<JavaScript> newScript = std::make_shared<JavaScript>();
// import current state (scope)
newScript = parser.append(newScript, request.docComponent->mainScript);
// parse it
const std::clock_t begin = clock();
std::shared_ptr<JavaScript> newScript = parser.parse(source);
newScript->tokens = parser.getTokens(source);
parser.parseTokens(newScript->tokens, &newScript->rootScope);
const std::clock_t end = clock();
logDebug() << "SCRIPTElement::renderer - Parsed javascript in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
// and flush our state back into mainScript
request.docComponent->mainScript = parser.append(request.docComponent->mainScript, newScript);
// we need to execute the new instructions with the combined scope
// copy scope back into our script
newScript->rootScope = request.docComponent->mainScript->rootScope;
}
return nullptr;
}

8
src/interfaces/graphical/renderers/glfw/Window.cpp

@ -77,7 +77,9 @@ bool Window::init() { @@ -77,7 +77,9 @@ bool Window::init() {
return true;
}
/*
bool Window::initGLFW() {
std::cout << "Window::initGLFW" << std::endl;
if (!glfwInit()) {
std::cout << "Could not initialize GLFW" << std::endl;
return false;
@ -129,6 +131,7 @@ bool Window::initGLFW() { @@ -129,6 +131,7 @@ bool Window::initGLFW() {
if (xPos < 0 || yPos < 0) return;
if (xPos > thiz->windowWidth || yPos > thiz->windowHeight) return;
// p. much worthless on double
*/
/*
static double lx = 0;
static double ly = 0;
@ -139,6 +142,7 @@ bool Window::initGLFW() { @@ -139,6 +142,7 @@ bool Window::initGLFW() {
ly = yPos;
std::cout << "Window::Window:onMousemove - noCache" << std::endl;
*/
/*
//std::cout << "Window::Window:onMousemove - begin search" << std::endl;
//std::cout << "Window::Window:onMousemove - windowHeight: " << thiz->windowHeight << " cursorY: " << thiz->cursorY << " scrollY: " << thiz->transformMatrix[13] << std::endl;
thiz->ui->onMousemove(thiz->cursorX, thiz->cursorY);
@ -171,7 +175,7 @@ bool Window::initGLFW() { @@ -171,7 +175,7 @@ bool Window::initGLFW() {
glfwSetKeyCallback(window, [](GLFWwindow *win, int key, int scancode, int action, int mods) {
Window *thiz = reinterpret_cast<Window*>(glfwGetWindowUserPointer(win));
//std::cout << "Key " << key << " action: " << action << "mods: " << mods << std::endl;
std::cout << "Key " << key << " action: " << action << "mods: " << mods << std::endl;
// command for OSX, otherwise control
#if defined(__APPLE__) && defined(__MACH__)
@ -217,8 +221,10 @@ bool Window::initGLFW() { @@ -217,8 +221,10 @@ bool Window::initGLFW() {
return true;
}
*/
void Window::onResize(int passedWidth, int passedHeight) {
//std::cout << "Window::onResize" << std::endl;
this->windowWidth = passedWidth;
this->windowHeight = passedHeight;
this->delayResize = 1;

42
src/interfaces/graphical/renderers/glfw/opengl.cpp

@ -192,24 +192,30 @@ OpenGLWindowHandle * OpenGL::createWindow(std::string title, Rect *position, uns @@ -192,24 +192,30 @@ OpenGLWindowHandle * OpenGL::createWindow(std::string title, Rect *position, uns
glfwSetKeyCallback(window, [](GLFWwindow *glfwwin, int key, int scancode, int action, int mods) {
OpenGLWindowHandle *thiz = reinterpret_cast<OpenGLWindowHandle*>(glfwGetWindowUserPointer(glfwwin));
if (action == GLFW_RELEASE) {
if (thiz->onKeyUp) {
thiz->onKeyUp(key, scancode, mods);
}
}
if (action == GLFW_REPEAT) {
//thiz->ui->onKeyRepeat(key, scancode, mods);
//thiz->ui->onKeyPress(key, scancode, action, mods);
if (thiz->onKeyRepeat) {
thiz->onKeyRepeat(key, scancode, mods);
}
}
if (action == GLFW_PRESS) {
//thiz->ui->onKeyDown(key, scancode, mods);
//thiz->ui->onKeyPress(key, scancode, action, mods);
if (thiz->onKeyRepeat) {
thiz->onKeyRepeat(key, scancode, mods);
}
std::cout << "opengl::glfwSetKeyCallback - Key " << key << " action: " << action << " mods: " << mods << std::endl;
switch(action) {
case GLFW_RELEASE:
if (thiz->onKeyUp) {
std::cout << "hasKeyUp" << std::endl;
thiz->onKeyUp(key, scancode, mods);
}
break;
case GLFW_PRESS:
//thiz->ui->onKeyDown(key, scancode, mods);
//thiz->ui->onKeyPress(key, scancode, action, mods);
if (thiz->onKeyDown) {
std::cout << "hasKeyDown" << std::endl;
thiz->onKeyDown(key, scancode, mods);
}
break;
case GLFW_REPEAT:
//thiz->ui->onKeyRepeat(key, scancode, mods);
//thiz->ui->onKeyPress(key, scancode, action, mods);
if (thiz->onKeyRepeat) {
std::cout << "hasKeyRepeat" << std::endl;
thiz->onKeyRepeat(key, scancode, mods);
}
break;
}
});

22
src/main.cpp

@ -52,6 +52,12 @@ bool fileExists(const std::string s) { @@ -52,6 +52,12 @@ bool fileExists(const std::string s) {
extern TextRasterizerCache *rasterizerCache;
#include <iostream>
#include <fstream>
std::ofstream assignfile;
std::ofstream execfile;
int main(int argc, char *argv[]) {
// show help msg when "--help" appears
if (argc > 1) {
@ -66,6 +72,10 @@ int main(int argc, char *argv[]) { @@ -66,6 +72,10 @@ int main(int argc, char *argv[]) {
init_heap(); // the NT port requires it. We do it at startup now, to allow 2LSF to run at any time
#endif
std::ofstream myfile;
assignfile.open ("js_assignments.txt");
execfile.open ("js_execution.txt");
std::cout \
<< "# # ######" << std::endl \
<< "## # ###### ##### # # # # # # # # ###### #####" << std::endl \
@ -92,13 +102,16 @@ int main(int argc, char *argv[]) { @@ -92,13 +102,16 @@ int main(int argc, char *argv[]) {
parser->WriteConfig(*config);
}
delete parser;
#ifdef DEBUG
bool jsConsole = false;
std::cout << "Global Settings contains, in no particular order:\n";
for ( auto it = config->Settings.begin(); it != config->Settings.end(); ++it ){
std::cout << it->first << ":" << it->second << std::endl;
if (it->first == "CONSOLE" && it->second == "TRUE") {
jsConsole = true;
}
}
std::cout << std::endl;
#endif
renderer = std::make_unique<OpenGL>();
@ -176,8 +189,13 @@ int main(int argc, char *argv[]) { @@ -176,8 +189,13 @@ int main(int argc, char *argv[]) {
browser = std::make_unique<Browser>();
browser->addWindow();
if (!browser->windows.front().get()->window) {
std::cout << "main() - unable to add a window" << std::endl;
return 1;
}
if (jsConsole) {
std::cout << "turning on JS console" << std::endl;
browser->addJSDebuggerWindow();
}
//std::cout << "argc " << argc << std::endl;
if (argc > 1) {

886
src/parsers/scripting/javascript/JSParser.cpp

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save