Browse Source

only change x/y if boundToPage, useBoxShader support

pull/2/head
Odilitime 5 years ago
parent
commit
6963de426c
  1. 46
      src/graphics/components/Component.cpp

46
src/graphics/components/Component.cpp

@ -7,16 +7,16 @@ @@ -7,16 +7,16 @@
Component::~Component() {
}
// resize is where width/height can change within the confines of the window
void Component::resize(const int passedWindowWidth, const int passedWindowHeight) {
//std::cout << "Component::resize" << std::endl;
//std::cout << "Component::resize - doing nothing" << std::endl;
windowWidth = passedWindowWidth;
windowHeight = passedWindowHeight;
/*
if (boundToPage) {
} else {
*/
*/
// no vertices in component
/*
float vx = x;
@ -38,6 +38,18 @@ void Component::resize(const int passedWindowWidth, const int passedWindowHeight @@ -38,6 +38,18 @@ void Component::resize(const int passedWindowWidth, const int passedWindowHeight
verticesDirty = true;
*/
//}
// do we recurse down through children?
// well if a parent resizes, yea we should tell our children the window size has changed
// btw a layout already does this
// yea let's let layout handle this
/*
for (std::shared_ptr<Component> child : children) {
// update it's size
// maybe we should called wrap
child->resize(windowWidth, windowHeight);
}
*/
}
void Component::setParent(std::shared_ptr<Component> passedParent) {
@ -51,9 +63,20 @@ void Component::setParent(std::shared_ptr<Component> passedParent) { @@ -51,9 +63,20 @@ void Component::setParent(std::shared_ptr<Component> passedParent) {
parent = passedParent;
// update our position
x = passedParent->x;
y = passedParent->y - passedParent->height;
// probably could move this out of here
if (boundToPage) {
x = passedParent->x;
y = passedParent->y - passedParent->height;
}
//std::cout << "Component::setParent - placing at " << static_cast<int>(x) << "," << static_cast<int>(y) << std::endl;
if (passedParent) {
if (passedParent->children.size()) {
this->previous = passedParent->children.back();
}
// need to figure out how to make this work
//passedParent->children.push_back(std::make_shared<Component>(this));
}
// add new component as child to parent
//std::shared_ptr<Component> child=*new std::shared_ptr<Component>(this);
@ -63,6 +86,7 @@ void Component::setParent(std::shared_ptr<Component> passedParent) { @@ -63,6 +86,7 @@ void Component::setParent(std::shared_ptr<Component> passedParent) {
// window size is required because we need to know if our x is placed outside bounds
// our size is not required
// but all previous children sizes and positions are
// this function should be smart enough to read state, figure out what changes are actually needed and execute them
void Component::layout() {
// back up current position
//int lx = x;
@ -82,7 +106,7 @@ void Component::layout() { @@ -82,7 +106,7 @@ void Component::layout() {
*/
// if we're a child, get our parents position
if (parent) {
if (parent && boundToPage) {
//std::cout << "Component::layout - copying position from parent: " << (int)parent->x << "x" << (int)parent->y << std::endl;
x = parent->x;
@ -91,6 +115,7 @@ void Component::layout() { @@ -91,6 +115,7 @@ void Component::layout() {
if (parent->children.size()) {
//std::cout << "Component::layout - parent children: " << parent->children.size() << std::endl;
if (previous) {
//std::cout << "Component::layout - has previous " << std::endl;
/*
TextComponent *prevTextComponent = dynamic_cast<TextComponent*>(previous.get());
if (prevTextComponent) {
@ -153,6 +178,13 @@ void Component::layout() { @@ -153,6 +178,13 @@ void Component::layout() {
// if parent x or y changes or windowWindow changes, all children need to be adjust
//std::cout << "Component::layout - I have " << children.size() << " children affected by my moved" << std::endl;
for (std::shared_ptr<Component> child : children) {
// maybe it should be like this:
// hey new w/h
// update wras
// where do we update layout?
// So no, because this is a relayout, we don't know sf w/h has changes
// most component resize()s already update the w/h
// update new sizes
child->windowWidth = windowWidth;
child->windowHeight = windowHeight;
@ -322,7 +354,7 @@ bool Component::setTexture(GLuint textureNum, GLsizei w, GLsizei h, const unsign @@ -322,7 +354,7 @@ bool Component::setTexture(GLuint textureNum, GLsizei w, GLsizei h, const unsign
// converts 0-1 to screen
// but centered
void Component::pointToViewport(float &rawX, float &rawY) const {
if (boundToPage) {
if (useBoxShader) {
//std::cout << "Component::pointToViewport - notBoundToPage converting from " << static_cast<int>(rawX) << "," << static_cast<int>(rawY) << std::endl;
//std::cout << "BoundToPage using " << screenWidth << "x" << screenHeight << std::endl;
rawX = ((rawX / windowWidth) * 2) - 1;

Loading…
Cancel
Save