Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • demetrius/netrunner
  • despair/netrunner
  • antpy/netrunner
  • dylanbaughercontact/netrunner
  • okn3/netrunner
  • geertiebear/netrunner
  • mechacrash/netrunner
  • vaartis/netrunner
  • flat/netrunner
9 results
Show changes
Showing
with 929 additions and 235 deletions
#include "StringUtils.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <algorithm>
/**
* get an extension from a filename
* @param fileName a filename string
* @return '' or a string with the found extension
*/
const std::string getFilenameExtension(std::string const& fileName) {
auto dotPos = fileName.find_last_of('.');
if (dotPos != std::string::npos && dotPos + 1 != std::string::npos) {
//std::cout << "StringUtils::getFilenameExtension - " << fileName.substr(dotPos + 1) << std::endl;
return fileName.substr(dotPos + 1);
}
return "";
}
/**
* get an document from a url
* @param url url string
* @return '' or a string with the found document
*/
const std::string getDocumentFromURL(const std::string &url) {
int slashes = 0;
for (unsigned int i = 0; i < url.length(); i++) {
if (url[i] == '/') {
slashes++;
if (slashes == 3) {
return url.substr(i, url.length() - i);
}
}
}
return "";
}
/**
* get host from a url
* @param url url string
* @return '' or a string with the found host
*/
const std::string getHostFromURL(const std::string &url) {
auto colonDoubleSlash = url.find("://");
if (colonDoubleSlash != std::string::npos) {
auto startPos = colonDoubleSlash + 3;
auto thirdSlash = url.find("/", startPos);
if (thirdSlash == std::string::npos) {
return url.substr(startPos);
}
return url.substr(startPos, thirdSlash - startPos);
}
return "";
}
/**
* get scheme from a url
* @param url url string
* @return '' or a string with the found protocol
*/
const std::string getSchemeFromURL(const std::string &url) {
auto colonDoubleSlash = url.find("://");
if (colonDoubleSlash != std::string::npos) {
return url.substr(0, colonDoubleSlash);
}
return "";
}
/**
* convert string to lowercase
* @param str string
* @return lowercased version of str
*/
const std::string toLowercase(const std::string &str) {
std::string returnString = "";
std::transform(str.begin(),
str.end(),
back_inserter(returnString),
tolower);
return returnString;
/*
std::string stringToLower(std::string s) {
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c){ return std::tolower(c); });
return s;
*/
}
This diff is collapsed.
#ifndef APP_H
#define APP_H
#include "../interfaces/graphical/renderers/glfw/Window.h"
#include "../interfaces/components/Component.h"
#include "../parsers/markup/Node.h"
//#include <GL/glew.h>
//#include <GLFW/glfw3.h>
//#include <memory>
#include <vector>
#include "../platform/tlsf.h"
//#include <algorithm>
void doOnClick(std::string type, Component *component, Window *win);
// this is the actually application that
// contains a list of windows
class App {
public:
std::shared_ptr<Node> loadTheme(std::string filename);
void destroyTheme();
// maybe applyTheme?
void rebuildTheme();
void transferTheme(std::string filename);
void NextTheme();
void createComponentTree(const std::shared_ptr<Node> node, std::shared_ptr<Component> &parentComponent, std::shared_ptr<Window> win);
void addJSDebuggerWindow();
void addWindow();
void render();
void loop();
//
// properties
//
std::shared_ptr<Node> uiRootNode;
std::vector<std::shared_ptr<Component>> layers;
bool jsEnable = false;
// because components take a shared_ptr for win, this has to be shared too
std::vector<std::shared_ptr<Window>> windows;
Window *activeWindow = nullptr;
size_t windowCounter = 0;
};
#endif
#include "browser.h"
#include "../../interfaces/components/TabbedComponent.h"
#include "../../parsers/markup/html/HTMLParser.h"
#include "../../interfaces/components/InputComponent.h"
#include "../../interfaces/components/ImageComponent.h"
#include "../../interfaces/components/TabbedComponent.h"
#include "../../interfaces/components/ButtonComponent.h"
Browser::Browser() {
/*
std::string ntrml, line;
std::ifstream myfile("browser.ntrml");
if (myfile.is_open()) {
while(getline(myfile, line)) {
ntrml += line;
}
myfile.close();
} else {
std::cout << "Couldnt read browser.ntrml" << std::endl;
}
NTRMLParser uiParser;
//std::cout << "Browser read [" << ntrml << "]" << std::endl;
*/
//this->uiRootNode = uiParser.parse(ntrml);
this->uiRootNode = this->loadTheme("browser.ntrml");
//printNode(this->uiRootNode, 0);
}
/*
void Browser::addWindow() {
App::addWindow();
}
*/
std::shared_ptr<DocumentComponent> Browser::getActiveDocumentComponent() {
if (!activeWindow) {
std::cout << "Browser::getActiveDocumentComponent - No active window" << std::endl;
return nullptr;
}
return this->activeWindow->getActiveDocumentComponent();
}
#ifndef BROWSER_H
#define BROWSER_H
#include "../app.h"
//#include "interfaces/graphical/renderers/glfw/Window.h"
//#include "interfaces/components/Component.h"
#include "../../interfaces/components/DocumentComponent.h"
//#include "interfaces/components/ComponentBuilder.h"
//#include "parsers/markup/Node.h"
//#include <GL/glew.h>
//#include <GLFW/glfw3.h>
//#include <memory>
//#include <vector>
//#include <algorithm>
//#include "networking/HTTPResponse.h"
//#include "URL.h"
//#include "interfaces/graphical/renderers/glfw/Window.h"
// separate window functions from browser functions
class Browser : public App {
private:
public:
Browser();
//void addWindow();
// does not sound very browser specific, I could see other apps needing this
// but not all apps would use a doc component
std::shared_ptr<DocumentComponent> getActiveDocumentComponent();
std::shared_ptr<Component> tabComponent = nullptr;
std::shared_ptr<Component> addressComponent = nullptr;
//URL currentURL;
};
//bool setWindowContent(URL const& url);
//void handleRequest(const HTTPResponse &response);
#endif
#include "Environment.h"
#include <vector>
#include "Path.h"
#include "../tools/Log.h"
std::string Environment::resourceDir = "";
void Environment::init() {
if (!resourceDir.empty())
return; // already initialized O_o
std::vector<std::string> paths = {
"res"
};
#ifndef _WIN32
// linux or osx
paths.push_back("/usr/share/netrunner/resources");
paths.push_back("/usr/local/share/netrunner/resources");
#else
paths.push_back(""); //TODO: place it somewhere for windows
#endif
for (std::string &path : paths) {
if (Path::directoryExists(path)) {
resourceDir = path;
logInfo() << "Found resource dir at " << path << "!" << std::endl;
break;
}
}
}
std::string Environment::getResourceDir() {
return resourceDir;
}
#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H
#include <string>
class Environment {
public:
static void init();
static std::string getResourceDir();
static void setResourceDir();
private:
static std::string resourceDir;
};
#endif
#include "Path.h"
#include <sys/stat.h>
bool Path::directoryExists(const std::string &path) {
struct stat sb;
if (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
return true;
}
return false;
}
std::string Path::fromUnixPath(const std::string &path) {
std::string returnPath(path);
#ifdef _WIN32
for (int i = 0; i < path.size(); i++)
if (path.at(i) == '/') returnPath.at(i) = '\\';
#endif
return returnPath;
}
#ifndef PATH_H
#define PATH_H
#include <string>
class Path {
public:
static bool directoryExists(const std::string &path);
static std::string fromUnixPath(const std::string &path);
};
#endif
#ifndef ANIMECOMPONENT_H
#define ANIMECOMPONENT_H
#include <GL/glew.h>
#include "BoxComponent.h"
class AnimeComponent : public BoxComponent {
public:
AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
unsigned char data[1024][1024][4];
};
#endif
#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;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#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());
if (textNode) {
return std::make_unique<TextComponent>(textNode->text, x, y, 24, true, 0x000000FF, windowWidth, windowHeight);
}
return nullptr;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.