Browse Source

textureTransformMatrix, scrollDocument() refactor, remove unused createComponentTree(), keyup case fix

master
Odilitime 5 years ago
parent
commit
712a74b6cc
  1. 111
      src/graphics/opengl/Window.cpp
  2. 9
      src/graphics/opengl/Window.h

111
src/graphics/opengl/Window.cpp

@ -199,7 +199,7 @@ bool Window::init() { @@ -199,7 +199,7 @@ bool Window::init() {
std::shared_ptr<InputComponent> navAddressBar = std::make_unique<InputComponent>(192.0f, windowHeight - 48.0f, windowWidth - 384.0f, 24.0f, windowWidth, windowHeight);
// add it to our components
navAddressBar->x = 192.0f;
navAddressBar->y = windowHeight-48.0f;
navAddressBar->y = windowHeight - 48.0f;
navAddressBar->uiControl.x = { 0, 192 }; // 192px
navAddressBar->uiControl.y = { 100, -48 }; // top - 48px
navAddressBar->uiControl.w = { 100, -384 }; // w - 384px
@ -367,7 +367,7 @@ bool Window::initGLFW() { @@ -367,7 +367,7 @@ bool Window::initGLFW() {
//std::cout << "scroll - hovering over a component" << std::endl;
if (thiz->hoverComponent->onWheel) {
//std::cout << "scroll - hovering over a scrollabel component" << std::endl;
thiz->hoverComponent->onWheel(xOffset * 100, yOffset * 100);
thiz->hoverComponent->onWheel(xOffset * 10, yOffset * 10);
}
}
@ -470,8 +470,8 @@ bool Window::initGLFW() { @@ -470,8 +470,8 @@ bool Window::initGLFW() {
p_tabComponent->onKeyPress(key, scancode, action, mods);
}
if (action == 0) {
if (p_tabComponent->onKeyup) {
p_tabComponent->onKeyup(key, scancode, action, mods);
if (p_tabComponent->onKeyUp) {
p_tabComponent->onKeyUp(key, scancode, action, mods);
}
}
}
@ -481,8 +481,8 @@ bool Window::initGLFW() { @@ -481,8 +481,8 @@ bool Window::initGLFW() {
DocumentComponent *docComponent = dynamic_cast<DocumentComponent*>(thiz->focusedComponent.get());
if (docComponent) {
if (action == 0) {
if (docComponent->onKeyup) {
docComponent->onKeyup(key, scancode, action, mods);
if (docComponent->onKeyUp) {
docComponent->onKeyUp(key, scancode, action, mods);
}
}
return;
@ -580,58 +580,33 @@ bool Window::initGLFW() { @@ -580,58 +580,33 @@ bool Window::initGLFW() {
Component::printComponentTree(thiz->rootComponent, 0);
printf("\n\n");
}
// basically ignored over tabbed or doc component
/*
int yOffsetScroll = 1;
if (key == GLFW_KEY_PAGE_UP && (action == GLFW_PRESS || action == GLFW_REPEAT)) {
TabbedComponent *p_TabComponent = dynamic_cast<TabbedComponent*>(thiz->tabComponent.get());
if (p_TabComponent) {
DocumentComponent *p_DocComponent = dynamic_cast<DocumentComponent*>(p_TabComponent->documentComponent.get());
if (p_DocComponent) {
p_DocComponent->transformMatrix[13] += -yOffsetScroll * 0.1;
p_DocComponent->transformMatrixDirty = true;
thiz->renderDirty = true;
}
}
std::cout << "PgUp is/was pressed. Scrolling down." << std::endl;
thiz->scrollDocument(-yOffsetScroll*0.1);
}
if (key == GLFW_KEY_PAGE_DOWN && (action == GLFW_PRESS || action == GLFW_REPEAT)) {
TabbedComponent *p_TabComponent = dynamic_cast<TabbedComponent*>(thiz->tabComponent.get());
if (p_TabComponent) {
DocumentComponent *p_DocComponent = dynamic_cast<DocumentComponent*>(p_TabComponent->documentComponent.get());
if (p_DocComponent) {
p_DocComponent->transformMatrix[13] += yOffsetScroll * 0.1;
p_DocComponent->transformMatrixDirty = true;
thiz->renderDirty = true;
}
}
std::cout << "PgDn is/was pressed. Scrolling up." << std::endl;
thiz->scrollDocument(yOffsetScroll*0.1);
}
// FIXME Scrolling with this can scroll past boundary whereas the same doesn't happen with
// scrolling wheel
if (key == GLFW_KEY_J && (action == GLFW_PRESS || action == GLFW_REPEAT)) {
std::cout << "J is/was pressed. Scrolling down." << std::endl;
TabbedComponent *p_TabComponent = dynamic_cast<TabbedComponent*>(thiz->tabComponent.get());
if (p_TabComponent) {
DocumentComponent *p_DocComponent = dynamic_cast<DocumentComponent*>(p_TabComponent->documentComponent.get());
if (p_DocComponent) {
p_DocComponent->transformMatrix[13] += yOffsetScroll * 0.1;
p_DocComponent->transformMatrixDirty = true;
thiz->renderDirty = true;
}
}
thiz->scrollDocument(-yOffsetScroll*0.1);
}
// FIXME Scrolling with this can scroll past boundary whereas the same doesn't happen with
// scrolling wheel
if (key == GLFW_KEY_K && (action == GLFW_PRESS || action == GLFW_REPEAT)) {
std::cout << "K is/was pressed. Scrolling up." << std::endl;
TabbedComponent *p_TabComponent = dynamic_cast<TabbedComponent*>(thiz->tabComponent.get());
if (p_TabComponent) {
DocumentComponent *p_DocComponent = dynamic_cast<DocumentComponent*>(p_TabComponent->documentComponent.get());
if (p_DocComponent) {
p_DocComponent->transformMatrix[13] += -yOffsetScroll * 0.1;
p_DocComponent->transformMatrixDirty = true;
thiz->renderDirty = true;
}
}
thiz->scrollDocument(yOffsetScroll*0.1);
}
*/
});
glfwMakeContextCurrent(window);
@ -679,6 +654,24 @@ void Window::onResize(int passedWidth, int passedHeight) { @@ -679,6 +654,24 @@ void Window::onResize(int passedWidth, int passedHeight) {
this->delayResize = 1;
}
void Window::scrollDocument(int y) {
TabbedComponent *p_TabComponent = dynamic_cast<TabbedComponent*>(this->tabComponent.get());
if (p_TabComponent) {
DocumentComponent *p_DocComponent = dynamic_cast<DocumentComponent*>(p_TabComponent->documentComponent.get());
if (p_DocComponent) {
p_DocComponent->transformMatrix[13] += y;
p_DocComponent->textureTransformMatrix[13] += y;
p_DocComponent->transformMatrixDirty = true;
this->renderDirty = true;
this->transformMatrixDirty = true;
} else {
std::cout << "Window::scrollDocument - no docComponent" << std::endl;
}
} else {
std::cout << "Window::scrollDocument - no tabComponent" << std::endl;
}
}
void Window::resize() {
//std::cout << "Window::resize" << std::endl;
@ -741,6 +734,23 @@ void Window::render() { @@ -741,6 +734,23 @@ void Window::render() {
std::cout << "window::render - glUseProgram - not ok: " << glErr << std::endl;
}
if (transformMatrixDirty) {
//const std::clock_t begin = clock();
GLint transformLocation = textureShader->uniform("transform");
glUniformMatrix4fv(transformLocation, 1, GL_FALSE, textureTransformMatrix);
glErr=glGetError();
if(glErr != GL_NO_ERROR) {
std::cout << "window::render - glUniformMatrix4fv - not ok: " << glErr << std::endl;
}
// didn't change much (could be we didnt' select the textureProgram first)
//GLint transformLocation2 = glGetUniformLocation(textureProgram, "transform");
//glUniformMatrix4fv(transformLocation2, 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;
}
// draw anime 1st, tabbed components 2nd
// then box shit
// text last
@ -748,7 +758,15 @@ void Window::render() { @@ -748,7 +758,15 @@ void Window::render() {
renderComponentType("tab", rootComponent);
textureShader->bind();
// reset it our textureTransformationMatrix
GLint transformLocation = textureShader->uniform("transform");
glUniformMatrix4fv(transformLocation, 1, GL_FALSE, textureTransformMatrix);
glErr=glGetError();
if(glErr != GL_NO_ERROR) {
std::cout << "window::render - glUniformMatrix4fv - not ok: " << glErr << std::endl;
}
//GLint transformLocation = glGetUniformLocation(textureProgram, "transform");
//glUniformMatrix4fv(transformLocation, 1, GL_FALSE, transformMatrix);
renderComponentType("box", rootComponent);
@ -792,6 +810,13 @@ void Window::render() { @@ -792,6 +810,13 @@ void Window::render() {
renderComponentType("anime", rootComponent);
renderComponentType("tab", rootComponent);
textureShader->bind();
// reset it our textureTransformationMatrix
glUniformMatrix4fv(transformLocation, 1, GL_FALSE, textureTransformMatrix);
glErr=glGetError();
if(glErr != GL_NO_ERROR) {
std::cout << "window::render - glUniformMatrix4fv - not ok: " << glErr << std::endl;
}
renderComponentType("box", rootComponent);
renderComponentType("input", rootComponent);
// it's quick but done on scroll
@ -829,6 +854,7 @@ void Window::setDOM(const std::shared_ptr<Node> rootNode) { @@ -829,6 +854,7 @@ void Window::setDOM(const std::shared_ptr<Node> rootNode) {
}
*/
/*
void Window::createComponentTree(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent) {
std::shared_ptr<Component> component = componentBuilder.build(node, parentComponent, shared_from_this());
@ -857,6 +883,7 @@ void Window::createComponentTree(const std::shared_ptr<Node> node, const std::sh @@ -857,6 +883,7 @@ void Window::createComponentTree(const std::shared_ptr<Node> node, const std::sh
// update parents, creation brings them up to date
//updateComponentSize(component);
}
*/
void Window::renderComponentType(std::string str, std::shared_ptr<Component> component) {
if (!component) {

9
src/graphics/opengl/Window.h

@ -26,12 +26,13 @@ public: @@ -26,12 +26,13 @@ public:
void render();
void setDOM(const std::shared_ptr<Node> rootNode);
void createComponentTree(const std::shared_ptr<Node> rootNode, const std::shared_ptr<Component> &parentComponent);
//void createComponentTree(const std::shared_ptr<Node> rootNode, const std::shared_ptr<Component> &parentComponent);
void renderComponentType(std::string str, std::shared_ptr<Component> component);
void onResize(int passedWidth, int passedHeight);
void checkForResize();
void resize();
void scrollDocument(int y);
void resizeComponentTree(const std::shared_ptr<Component> &component, const int windowWidth, const int windowHeight);
std::shared_ptr<Component> searchComponentTree(const std::shared_ptr<Component> &component, const int x, const int y);
@ -40,6 +41,12 @@ public: @@ -40,6 +41,12 @@ public:
// properties
int maxTextureSize = 0;
float textureTransformMatrix[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
float transformMatrix[16] = {
1, 0, 0, 0,
0, 1, 0, 0,

Loading…
Cancel
Save