Skip to content
Snippets Groups Projects
Commit 3562de1b authored by Odilitime's avatar Odilitime
Browse files

transformMatrix scroll, onWheel scroll fixes, setDOM reset scrool position

parent dcbec2a9
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f
std::cout << "DocumentComponent::DocumentComponent - height was less than zero" << std::endl;
height = 0;
}
//std::cout << "DocumentComponent::DocumentComponent - our size" << static_cast<int>(width) << "x" << static_cast<int>(height) << std::endl;
onMousemove=[this](int passedX, int passedY) {
// set hover component
......@@ -36,7 +37,8 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f
lx = passedX;
ly = passedY;
//std::cout << "DocumentComponent::DocumentComponent:onMousemove - size " << this->windowWidth << "," << this->windowHeight << std::endl;
this->hoverComponent = this->searchComponentTree(this->rootComponent, passedX, passedY);
//std::cout << "DocumentComponent::DocumentComponent:onMousemove - at " << passedX << "," << passedY << " scroll: " << (int)(((this->transformMatrix[13] / 2) - 1) * this->windowHeight) << std::endl;
this->hoverComponent = this->searchComponentTree(this->rootComponent, passedX, passedY + (((this->transformMatrix[13] / 2) - 1) * this->windowHeight));
if (this->hoverComponent) {
//std::cout << "DocumentComponent::DocumentComponent:onMousemove - hovering over " << typeOfComponent(this->hoverComponent) << " component" << std::endl;
if (this->hoverComponent->onMousemove) {
......@@ -55,7 +57,7 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f
onWheel=[this](int passedX, int passedY) {
//std::cout << "DocumentComponent::DocumentComponent:::onWheel - scroll yDelta: " << y << std::endl;
//Component::printComponentTree(rootComponent, 0);
double pY = passedY / 10;
double pY = passedY / 10.0;
this->scrollY -= pY;
if (this->scrollY < 0) {
this->scrollY = 0;
......@@ -67,6 +69,22 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f
//std::cout << "root.y: " << static_cast<int>(rootComponent->y) << std::endl;
//std::cout << "windowSize: " << windowWidth << "," << windowHeight << std::endl;
// new system
//std::cout << "DocumentComponent::DocumentComponent:::onWheel - old position: " << this->transformMatrix[13] << " adjustment:" << (-pY*0.1) << std::endl;
this->transformMatrix[13] += -pY * 0.01;
// 2.0 is one screen height
// we draw from 0 downwards (y+), so can't scroll past our starting draw point
if (this->transformMatrix[13] < 2) {
this->transformMatrix[13] = 2;
}
// calculate scroll max by calculating how many screens are in the rootComponent's Height
if (this->transformMatrix[13] > std::max( (this->rootComponent->height - this->rootComponent->y) / this->windowHeight * 2.0f, 2.0f)) {
this->transformMatrix[13] = std::max( (this->rootComponent->height - this->rootComponent->y) / this->windowHeight * 2.0f, 2.0f);
}
this->transformMatrixDirty = true;
/*
// adjust root position
rootComponent->y = this->y + this->scrollY;
//std::cout << "now root.y: " << static_cast<int>(rootComponent->y) << std::endl;
......@@ -84,6 +102,7 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f
// should we mark win->renderDirty = true?
const std::clock_t end = clock();
std::cout << "Scrolled document in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
*/
//rootComponent->y = this->y - this->scrollY;
//std::cout << "after root.y: " << static_cast<int>(rootComponent->y) << std::endl;
......@@ -212,7 +231,10 @@ void DocumentComponent::setDOM(const std::shared_ptr<Node> rootNode) {
if (domRootNode) {
deleteNode(domRootNode);
}
// reset scroll position ?
// reset scroll position
transformMatrix[13] = 2;
transformMatrixDirty = true;
// new root component
rootComponent = std::make_shared<Component>();
......@@ -236,7 +258,28 @@ void DocumentComponent::render() {
domDirty = false;
//std::cout << "root Height: " << static_cast<int>(rootComponent->height) << " window Height: " << windowHeight << " y " << static_cast<int>(this->y) << std::endl;
scrollHeight = std::max(0, static_cast<int>(rootComponent->height - (windowHeight + (this->y * 2))));
// recalculate scroll max by calculating how many screens are in the rootComponent's Height
if (transformMatrix[13]>std::max((rootComponent->height)/(windowHeight)*2.0f, 2.0f)) {
transformMatrix[13]=std::max((rootComponent->height)/(windowHeight)*2.0f, 2.0f);
transformMatrixDirty = true;
}
}
// we have to do this each time
// because window resets it
//if (transformMatrixDirty) {
//const std::clock_t begin = clock();
GLint transformLocation = glGetUniformLocation(win->fontProgram, "transform");
glUniformMatrix4fv(transformLocation, 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;
GLint transformLocation2 = glGetUniformLocation(win->textureProgram, "transform");
glUniformMatrix4fv(transformLocation2, 1, GL_FALSE, transformMatrix);
transformMatrixDirty = false;
//}
//std::cout << "DocumentComponent::render - renderDirty" << std::endl;
glUseProgram(win->textureProgram);
renderBoxComponents(rootComponent);
......
......@@ -11,6 +11,7 @@
#include "MultiComponent.h"
// document is scrollable until multicomponent
class DocumentComponent : public MultiComponent {
public:
DocumentComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
......@@ -25,6 +26,14 @@ public:
bool domDirty = false;
int scrollY = 0;
int scrollHeight = 0;
float transformMatrix[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
bool transformMatrixDirty = true;
};
//bool setWindowContent(URL const& url);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment