Browse Source

new build prototype (includes doc component), button support, remove some dead code

master
Odilitime 5 years ago
parent
commit
6da36658f5
  1. 70
      src/graphics/components/ComponentBuilder.cpp

70
src/graphics/components/ComponentBuilder.cpp

@ -10,6 +10,10 @@ @@ -10,6 +10,10 @@
#include "../elements/DIVElement.h"
#include "../elements/STRONGElement.h"
#include "../elements/INPUTElement.h"
#include "../elements/BUTTONElement.h"
#include "InputComponent.h"
#include "ButtonComponent.h"
// fwd decl
std::shared_ptr<Component> searchComponentTree(const std::shared_ptr<Component> &component, const int passedX, const int passedY);
@ -28,11 +32,12 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder @@ -28,11 +32,12 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder
{"br", std::make_shared<DIVElement>()},
{"strong", std::make_shared<STRONGElement>()},
{"input", std::make_shared<INPUTElement>()},
{"button", std::make_shared<BUTTONElement>()},
{"b", std::make_shared<STRONGElement>()},
{"i", std::make_shared<SPANElement>()}
};
std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent, const std::shared_ptr<Window> win) {
std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent, const std::shared_ptr<Window> win, DocumentComponent *docComponent) {
std::shared_ptr<Component> component;
std::string tag;
if (node == nullptr) {
@ -69,6 +74,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -69,6 +74,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
ElementRenderRequest request;
request.node = node;
request.parentComponent = parentComponent;
request.docComponent = docComponent;
component = element->renderer(request); // doesn't always make a component
} else {
//std::cout << "Unknown tag: " << tag << std::endl;
@ -81,6 +87,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -81,6 +87,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
TextComponent *textComponent = dynamic_cast<TextComponent*>(component.get());
if (textComponent) {
//std::cout << "compositing [" << textComponent->text << "]" << std::endl;
// FIXME: put in textcomponent
if (!textComponent->onMousedown) {
textComponent->onMousedown = [textComponent, win](int x, int y) {
if (win->selectionList.size()) {
@ -137,6 +144,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -137,6 +144,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
}
}
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component.get());
ButtonComponent *buttonComponent = dynamic_cast<ButtonComponent*>(component.get());
//if (inputComponent) {
// any input set up we need to do?
// boundToPage defaults to true for components, InputComponent doesn't have it overridded
@ -165,16 +173,19 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -165,16 +173,19 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
// figure out our position, size, texture
component->layout();
/*
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component.get());
if (inputComponent) {
std::cout << "ComponentBuilder::build - Just laid out input component" << std::endl;
}
*/
// not sure why only this component needs this but it fixes it
if (inputComponent) {
//std::cout << "ComponentBuilder::build - Just laid out input component" << std::endl;
//std::cout << "ComponentBuilder::build - inputComponent at " << (int)inputComponent->x << "," << (int)inputComponent->y << std::endl;
inputComponent->updateParentSize();
}
if (buttonComponent) {
//std::cout << "ComponentBuilder::build - buttonComponent at " << (int)buttonComponent->x << "," << (int)buttonComponent->y << std::endl;
// since win is set
buttonComponent->updateText();
buttonComponent->updateParentSize();
}
//std::cout << "post layout placed: " << (int)component->x << "x" << (int)component->y << " w/h: " << (int)component->width << "x" << (int)component->height << std::endl;
return component;
}
@ -185,19 +196,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -185,19 +196,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
#include "AnimeComponent.h"
std::string typeOfComponent(const std::shared_ptr<Component> &component) {
TabbedComponent *tabComponent = dynamic_cast<TabbedComponent*>(component.get());
if (tabComponent) return "tab";
DocumentComponent *docComponent = dynamic_cast<DocumentComponent*>(component.get());
if (docComponent) return "doc";
TextComponent *textComponent = dynamic_cast<TextComponent*>(component.get());
if (textComponent) return "text";
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component.get());
if (inputComponent) return "input";
AnimeComponent *animeComponent = dynamic_cast<AnimeComponent*>(component.get());
if (animeComponent) return "anime";
BoxComponent *boxComponent = dynamic_cast<BoxComponent*>(component.get());
if (boxComponent) return "box";
return "";
return typeOfComponent(component.get());
}
std::string typeOfComponent(Component *component) {
@ -209,6 +208,8 @@ std::string typeOfComponent(Component *component) { @@ -209,6 +208,8 @@ std::string typeOfComponent(Component *component) {
if (textComponent) return "text";
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component);
if (inputComponent) return "input";
ButtonComponent *buttonComponent = dynamic_cast<ButtonComponent*>(component);
if (buttonComponent) return "button";
AnimeComponent *animeComponent = dynamic_cast<AnimeComponent*>(component);
if (animeComponent) return "anime";
BoxComponent *boxComponent = dynamic_cast<BoxComponent*>(component);
@ -216,31 +217,18 @@ std::string typeOfComponent(Component *component) { @@ -216,31 +217,18 @@ std::string typeOfComponent(Component *component) {
return "";
}
// used for picking
// used for picking for text selection
std::shared_ptr<Component> searchComponentTree(const std::shared_ptr<Component> &component, const int passedX, const int passedY) {
if (component->children.empty()) {
//std::cout << "MultiComponent::searchComponentTree - component at " << static_cast<int>(component->x) << "," << static_cast<int>(component->y) << " size " << static_cast<int>(component->width) << "," << static_cast<int>(component->height) << std::endl;
/*
if (tabbed) {
//std::cout << "MultiComponent::searchComponentTree:Tabbed - y search: " << static_cast<int>(component->windowHeight - component->y - component->height) << "<" << static_cast<int>(passedY) << "<" << static_cast<int>(component->windowHeight - component->y) << std::endl;
if (component->windowHeight - component->y - component->height < passedY && component->windowHeight - component->y > passedY) {
//std::cout << "DocumentComponent::searchComponentTree:Tabbed - x search: " << static_cast<int>(component->x) << "<" << static_cast<int>(passedX) << "<" << static_cast<int>(component->x + component->width) << std::endl;
if (component->x < passedX && component->x + component->width > passedX) {
//std::cout << "MultiComponent::searchComponentTree:Tabbed - hit " << typeOfComponent(component) << std::endl;
return component;
}
}
} else {
*/
//std::cout << "MultiComponent::searchComponentTree - y search: " << static_cast<int>(-component->y) << "<" << static_cast<int>(passedY) << "<" << static_cast<int>(-component->y + component->height) << std::endl;
if (-component->y < passedY && -component->y + component->height > passedY) {
//std::cout << "DocumentComponent::searchComponentTree - x search: " << static_cast<int>(component->x) << "<" << static_cast<int>(passedX) << "<" << static_cast<int>(component->x + component->width) << std::endl;
if (component->x < passedX && component->x + component->width > passedX) {
//std::cout << "MultiComponent::searchComponentTree - hit " << typeOfComponent(component) << std::endl;
return component;
}
//std::cout << "MultiComponent::searchComponentTree - y search: " << static_cast<int>(-component->y) << "<" << static_cast<int>(passedY) << "<" << static_cast<int>(-component->y + component->height) << std::endl;
if (-component->y < passedY && -component->y + component->height > passedY) {
//std::cout << "DocumentComponent::searchComponentTree - x search: " << static_cast<int>(component->x) << "<" << static_cast<int>(passedX) << "<" << static_cast<int>(component->x + component->width) << std::endl;
if (component->x < passedX && component->x + component->width > passedX) {
//std::cout << "MultiComponent::searchComponentTree - hit " << typeOfComponent(component) << std::endl;
return component;
}
//}
}
}
else {
for (std::shared_ptr<Component> child : component->children) {

Loading…
Cancel
Save