Odilitime 5 years ago
parent
commit
512ff54ea3
  1. 28
      README.md
  2. 2
      src/graphics/components/AnimeComponent.cpp
  3. 4
      src/graphics/components/AnimeComponent.h
  4. 6
      src/graphics/components/BoxComponent.cpp
  5. 6
      src/graphics/components/BoxComponent.h
  6. 28
      src/graphics/components/Component.cpp
  7. 3
      src/graphics/components/Component.h
  8. 6
      src/graphics/components/TextComponent.cpp
  9. 8
      src/graphics/components/TextComponent.h
  10. 6
      src/graphics/opengl/Window.cpp
  11. 10
      src/graphics/text/TextRasterizer.cpp
  12. 2
      src/html/HTMLParser.cpp
  13. 4
      src/html/HTMLParser.h
  14. 2
      src/main.cpp

28
README.md

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
# Netrunner
is an implementation of a new web browser written in C++ utilizing OpenGL. This is a brand new engine.
is an implementation of a new web browser engine written in C++ utilizing OpenGL.
Status: You can give it a url and it'll download, parser, and render the text from the page
Status: You can give it a url and it'll download, parse, and render the text from the page
## Odilitime's vision
A modern web browser is a huge project. I'd like to see this broken into several composable pieces.
@ -32,14 +32,21 @@ I'd like to develop text-based structures for communication between each piece. @@ -32,14 +32,21 @@ I'd like to develop text-based structures for communication between each piece.
#### Void
`sudo xbps-install -S glew glfw harfbuzz-devel`
#### Gentoo
`sudo emerge freetype harfbuzz glew glfw`
## Binaries
### Linux
[2017-07-26 binary package](https://my.mixtape.moe/xqvpqc.tar.gz)
[2017-07-31 binary package](https://my.mixtape.moe/imatcb.tar.gz)
GyroNinja.net is temporarily offline. Working with registrar to bring it back online.
[nightly binary only (no font files)](https://gyroninja.net:1615/job/NetRunner/lastSuccessfulBuild/artifact/netrunner)
### OSX
[2017-07-27 binary package](https://my.mixtape.moe/gbludd.zip)
[2017-07-31 binary package](https://my.mixtape.moe/ywjanx.zip)
### Windows
[2017-07-31 binary package](https://my.mixtape.moe/hkpcyu.zip)
## Milestones
- Browse 4chan /g/ board
@ -64,6 +71,13 @@ I don't think one on here could ever say they know what their doing without bein @@ -64,6 +71,13 @@ I don't think one on here could ever say they know what their doing without bein
- OSX Dev, focused on clean up
- Repo: https://gitgud.io/odilitime/netrunner/
- Nubben
- contributed local file code
- repo: https://github.com/nubben/netrunner
- Tomleb
- contributed keyboard code
- RetroTech - Web / Sys Admin
- Created original website
- Helps manage archive of logos and threads
@ -102,6 +116,6 @@ We coordinate on [irc.rizon.net](https://www.rizon.net/chat) #/g/netrunner or [O @@ -102,6 +116,6 @@ We coordinate on [irc.rizon.net](https://www.rizon.net/chat) #/g/netrunner or [O
- element - our DOM tree classes
### Class Types
- Nodes DOM tree objects
- Elements Individual tag types
- Components (gameobjects) renderer entities
- Nodes: DOM tree objects
- Elements: Individual tag types
- Components: (gameobjects) renderer entities

2
src/graphics/components/AnimeComponent.cpp

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
#endif
#include <cmath>
AnimeComponent::AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int windowWidth, const int windowHeight) : BoxComponent(rawX, rawY, rawWidth, rawHeight, windowWidth, windowHeight){
AnimeComponent::AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) : BoxComponent(rawX, rawY, rawWidth, rawHeight, passedWindowWidth, passedWindowHeight){
x = rawX;
y = rawY;
width = rawWidth;

4
src/graphics/components/AnimeComponent.h

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
class AnimeComponent : public BoxComponent {
public:
AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int windowWidth, const int windowHeight);
AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
};
#endif
#endif

6
src/graphics/components/BoxComponent.cpp

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
#include <cmath>
#include <iostream>
BoxComponent::BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int windowWidth, const int windowHeight) {
BoxComponent::BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) {
x = rawX;
y = rawY;
width = rawWidth;
@ -115,7 +115,7 @@ void BoxComponent::resize() { @@ -115,7 +115,7 @@ void BoxComponent::resize() {
verticesDirty = true;
}
void BoxComponent::pointToViewport(float &rawX, float &rawY, const int windowWidth, const int windowHeight) const {
void BoxComponent::pointToViewport(float &rawX, float &rawY, const int passedWindowWidth, const int passedWindowHeight) const {
if (rawX < 0) {
rawX += windowWidth;
}
@ -132,7 +132,7 @@ void BoxComponent::pointToViewport(float &rawX, float &rawY, const int windowWid @@ -132,7 +132,7 @@ void BoxComponent::pointToViewport(float &rawX, float &rawY, const int windowWid
rawY = (rawY * 2) - 1;
}
void BoxComponent::distanceToViewport(float &rawX, float &rawY, const int windowWidth, const int windowHeight) const {
void BoxComponent::distanceToViewport(float &rawX, float &rawY, const int passedWindowWidth, const int passedWindowHeight) const {
if (std::abs(rawX) > 1) {
rawX /= windowWidth;
}

6
src/graphics/components/BoxComponent.h

@ -22,12 +22,12 @@ protected: @@ -22,12 +22,12 @@ protected:
GLuint elementBufferObject = 0;
GLuint texture = 0;
public:
BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int windowWidth, const int windowHeight);
BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
~BoxComponent();
void render();
void resize();
void pointToViewport(float &rawX, float &rawY, const int windowWidth, const int windowHeight) const ;
void distanceToViewport(float &rawX, float &rawY, const int windowWidth, const int windowHeight) const ;
void pointToViewport(float &rawX, float &rawY, const int passedWindowWidth, const int passedWindowHeight) const ;
void distanceToViewport(float &rawX, float &rawY, const int passedWindowWidth, const int passedWindowHeight) const ;
};
#endif

28
src/graphics/components/Component.cpp

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#include "Component.h"
#include <iostream>
#include <algorithm>
#include "TextComponent.h"
Component::~Component() {
}
@ -38,16 +39,31 @@ void Component::layout() { @@ -38,16 +39,31 @@ void Component::layout() {
// reset position
x = 0;
y = 0;
/*
TextComponent *textComponent = dynamic_cast<TextComponent*>(this);
if (textComponent) {
std::cout << "Component::layout[" << textComponent->text << "]" << std::endl;
}
*/
// if we're a child, get our parents position
if (parent) {
//std::cout << "Component::layout - copying position from parent: " << (int)parent->x << "x" << (int)parent->y << std::endl;
x = parent->x;
y = parent->y;
// if we have sibilings see if they're inline or block
if (parent->children.size()) {
//std::cout << "Component::layout - parent children: " << parent->children.size() << std::endl;
if (previous) {
/*
TextComponent *prevTextComponent = dynamic_cast<TextComponent*>(previous.get());
if (prevTextComponent) {
std::cout << "Component::layout - previous [" << prevTextComponent->text << "] ending at: " << (int)prevTextComponent->endingX << "x" << (int)prevTextComponent->endingY << "" << std::endl;
}
*/
//std::cout << "Component::layout - previous at: " << (int)previous->x << "x" << (int)previous->y << " size: " << (int)previous->width << "x" << (int)previous->height << " ending at: " << (int)previous->endingX << "x" << (int)previous->endingY << std::endl;
// 2nd or last
if (previous->isInline) {
// last was inline
@ -55,6 +71,12 @@ void Component::layout() { @@ -55,6 +71,12 @@ void Component::layout() {
x = previous->x + previous->width;
y = previous->y; // keep on same line
//std::cout << "Component::layout - inLine (" << (int)previous->width << " wide) inLine" << std::endl;
if (x >= windowWidth) {
//std::cout << "Component::layout - inline inline wrapping because x: " << (int)x << " window: " << windowWidth << std::endl;
x = previous->endingX;
//std::cout << "Component::layout - p.y: " << (int)previous->y << " p.ey: " << previous->endingY << " p.h" << (int)previous->height << std::endl;
y = previous->y - previous->height + previous->endingY;
}
} else {
// we're block
y = previous->y - previous->height;
@ -67,6 +89,7 @@ void Component::layout() { @@ -67,6 +89,7 @@ void Component::layout() {
}
// really only inline but can't hurt block AFAICT
if (x >= windowWidth) {
//std::cout << "Component::layout - wrapping because x: " << (int)x << " window: " << windowWidth << std::endl;
x = 0;
y -= previous->height; // how far down do we need to wrap?, the previous height?
}
@ -131,7 +154,10 @@ void Component::updateParentSize() { @@ -131,7 +154,10 @@ void Component::updateParentSize() {
// back up current size
unsigned int lastParentWidth = parent->width;
unsigned int lastParentHeight = parent->height;
parent->endingX = endingX;
parent->endingY = endingY;
// find max width of all siblings
unsigned int maxWidth = width; // float?
unsigned int heightAccum = 0;

3
src/graphics/components/Component.h

@ -54,6 +54,9 @@ public: @@ -54,6 +54,9 @@ public:
// current placement on screen
float x = 0.0f;
float y = 0.0f;
// text flow (needed here because parent elements of textnode need to pass this info)
int endingX = 0;
int endingY = 0;
// height/width on screen
float height = 0.0f;
float width = 0.0f;

6
src/graphics/components/TextComponent.cpp

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
extern TextRasterizerCache *rasterizerCache;
TextComponent::TextComponent(const std::string &rawText, const int rawX, const int rawY, const unsigned int size, const bool bolded, const unsigned int hexColor, const int windowWidth, const int windowHeight) {
TextComponent::TextComponent(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) {
//const std::clock_t begin = clock();
text = rawText;
//x = rawX;
@ -92,7 +92,7 @@ inline void setVerticesColor(std::unique_ptr<float[]> &vertices, int p, unsigned @@ -92,7 +92,7 @@ inline void setVerticesColor(std::unique_ptr<float[]> &vertices, int p, unsigned
vertices[static_cast<size_t>(posMac(p) + 6)] = (static_cast<float>((color >> 0) & 0xFF)) / 255;
}
void TextComponent::rasterize(const int rawX, const int rawY, const int windowWidth, const int windowHeight) {
void TextComponent::rasterize(const int rawX, const int rawY, const int passedWindowWidth, const int passedWindowHeight) {
//const std::clock_t begin = clock();
const std::shared_ptr<TextRasterizer> textRasterizer=rasterizerCache->loadFont(fontSize, bold);
unsigned int glyphCount;
@ -227,7 +227,7 @@ void TextComponent::resize() { @@ -227,7 +227,7 @@ void TextComponent::resize() {
verticesDirty = true;
}
void TextComponent::pointToViewport(float &rawX, float &rawY, const int windowWidth, const int windowHeight) const {
void TextComponent::pointToViewport(float &rawX, float &rawY, const int passedWindowWidth, const int passedWindowHeight) const {
rawX = ((rawX / windowWidth) * 2) - 1;
rawY = ((rawY / windowHeight) * 2) - 1;
}

8
src/graphics/components/TextComponent.h

@ -24,17 +24,15 @@ private: @@ -24,17 +24,15 @@ private:
std::vector<GLuint> vertexBufferObjects;
GLuint elementBufferObject;
std::vector<GLuint> textures;
int endingX = 0;
int endingY = 0;
public:
std::string text;
TextComponent(const std::string &rawText, const int rawX, const int rawY, const unsigned int size, const bool bolded, const unsigned int hexColor, const int windowWidth, const int windowHeight);
TextComponent(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);
~TextComponent();
void rasterize(const int rawX, const int rawY, const int windowWidth, const int windowHeight);
void rasterize(const int rawX, const int rawY, const int passedWindowWidth, const int passedWindowHeight);
void render();
void resize();
void pointToViewport(float &rawX, float &rawY, const int windowWidth, const int windowHeight) const;
void pointToViewport(float &rawX, float &rawY, const int passedWindowWidth, const int passedWindowHeight) const;
void sanitize(std::string &str);
// backgroundColor

6
src/graphics/opengl/Window.cpp

@ -110,7 +110,7 @@ bool Window::initGLFW() { @@ -110,7 +110,7 @@ bool Window::initGLFW() {
if (thiz->transformMatrix[13]>std::max((thiz->rootComponent->height)/(thiz->windowHeight)*2.0f, 2.0f)) {
thiz->transformMatrix[13]=std::max((thiz->rootComponent->height)/(thiz->windowHeight)*2.0f, 2.0f);
}
//std::cout << "scroll y is at " << thiz->transformMatrix[13] << "/" << (int)(thiz->transformMatrix[13]*10000) << std::endl;
//std::cout << "scroll y is at " << thiz->transformMatrix[13] << "/" << static_cast<int>((thiz->transformMatrix[13]*10000) << std::endl;
thiz->transformMatrixDirty = true;
});
glfwSetMouseButtonCallback(window, [](GLFWwindow *win, int button, int action, int mods) {
@ -350,10 +350,10 @@ void Window::printComponentTree(const std::shared_ptr<Component> &component, int @@ -350,10 +350,10 @@ void Window::printComponentTree(const std::shared_ptr<Component> &component, int
}
TextComponent *textComponent = dynamic_cast<TextComponent*>(component.get());
if (textComponent) {
std::cout << std::fixed << "X: " << (int)textComponent->x << " Y: " << (int)textComponent->y << " WIDTH: " << (int)textComponent->width << " HEIGHT: " << (int)textComponent->height << " INLINE: " << textComponent->isInline << " TEXT: " << textComponent->text << std::endl;
std::cout << std::fixed << "X: " << static_cast<int>(textComponent->x) << " Y: " << static_cast<int>(textComponent->y) << " WIDTH: " << static_cast<int>(textComponent->width) << " HEIGHT: " << static_cast<int>(textComponent->height) << " INLINE: " << textComponent->isInline << " TEXT: " << textComponent->text << std::endl;
}
else {
std::cout << std::fixed << "X: " << (int)component->x << " Y: " << (int)component->y << " WIDTH: " << (int)component->width << " HEIGHT: " << (int)component->height << " INLINE: " << component->isInline << std::endl;
std::cout << std::fixed << "X: " << static_cast<int>(component->x) << " Y: " << static_cast<int>(component->y) << " WIDTH: " << static_cast<int>(component->width) << " HEIGHT: " << static_cast<int>(component->height) << " INLINE: " << component->isInline << std::endl;
}
for (std::shared_ptr<Component> child : component->children) {
printComponentTree(child, depth + 1);

10
src/graphics/text/TextRasterizer.cpp

@ -191,6 +191,8 @@ std::unique_ptr<Glyph[]> TextRasterizer::rasterize(const std::string &text, cons @@ -191,6 +191,8 @@ std::unique_ptr<Glyph[]> TextRasterizer::rasterize(const std::string &text, cons
//std::cout << "starting at: " << x << std::endl;
cx = wrapped ? x : 0; // reset
cy = 0;
//int miny0 = 99;
int maxy0 = 0;
for (unsigned int i = 0; i < glyphCount; i++) {
if (FT_Load_Glyph(*face, glyphInfo[i].codepoint, FT_LOAD_DEFAULT)) {
std::cout << "Could not load glyph" << std::endl;
@ -209,6 +211,9 @@ std::unique_ptr<Glyph[]> TextRasterizer::rasterize(const std::string &text, cons @@ -209,6 +211,9 @@ std::unique_ptr<Glyph[]> TextRasterizer::rasterize(const std::string &text, cons
const float yo = static_cast<float>(glyphPos[i].y_offset) / 64;
int y0 = static_cast<int>(floor(yo + slot->bitmap_top));
//miny0 = std::min(y0, miny0);
maxy0 = std::max(y0, maxy0);
int bump = y0max - y0; // Y adjust for this glyph
const float xa = static_cast<float>(glyphPos[i].x_advance) / 64;
// if this char is too width for this line, advance to next line
@ -239,7 +244,10 @@ std::unique_ptr<Glyph[]> TextRasterizer::rasterize(const std::string &text, cons @@ -239,7 +244,10 @@ std::unique_ptr<Glyph[]> TextRasterizer::rasterize(const std::string &text, cons
//std::cout << "final size: " << (int)width << "x" << (int)height << std::endl;
//std::cout << "at: " << (int)line->x0 << "x" << (int)line->y0 << " to: " << (int)line->x1 << "x" << (int)line->y1 <<std::endl;
endingX = cx; // maybe should be one xa less?
endingY = cy + std::ceil(1.2f * fontSize); // definitely should be one lineheight higher
//std::ceil(0.5 * 1.2f * fontSize)+2
endingY = cy + maxy0; // definitely should be one lineheight higher
//std::cout << "miny0: " << miny0 << " maxy0: " << maxy0 << " fontsize:" << fontSize << std::endl;
//endingY += 2;
// report a single glyph (since this one "glyph" represents the entire block of text)
glyphCount = 1;

2
src/html/HTMLParser.cpp

@ -4,8 +4,6 @@ @@ -4,8 +4,6 @@
#include <iostream>
#include <memory>
void printNode(const std::shared_ptr<Node> node, const int indent);
void printNode(const std::shared_ptr<Node> node, const int indent) {
for (int i = 0; i < indent; i++) {
std::cout << '\t';

4
src/html/HTMLParser.h

@ -5,10 +5,12 @@ @@ -5,10 +5,12 @@
#include "TagNode.h"
#include <string>
void printNode(const std::shared_ptr<Node> node, const int indent);
class HTMLParser {
public:
std::shared_ptr<Node> parse(const std::string &html) const;
void parseTag(const std::string &element, TagNode &tagNode) const;
};
#endif
#endif

2
src/main.cpp

@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) {
return 1;
}
const HTMLParser parser;
HTMLParser parser;
const std::clock_t begin = clock();
std::shared_ptr<Node> rootNode = parser.parse(res.raw);
const std::clock_t end = clock();

Loading…
Cancel
Save