7 #include <unordered_set>
46 using std::make_unique;
49 using std::unique_ptr;
50 using std::unordered_set;
96 const string& backgroundImage,
98 const GUIColor& backgroundImageEffectColorMul,
99 const GUIColor& backgroundImageEffectColorAdd,
104 const string& tooltip)
134 vector<string> elementNodeDependencies;
141 vector<string> effectsToRemove;
142 for (
const auto& [effectId, effect]:
effects) {
143 effectsToRemove.push_back(effectId);
145 for (
const auto& effectToRemoveId: effectsToRemove) {
151 string hierarchicalId;
153 while (_parentNode !=
nullptr) {
154 hierarchicalId = _parentNode->
id +
"." + hierarchicalId;
155 _parentNode = _parentNode->parentNode;
157 hierarchicalId = hierarchicalId +
id;
158 return hierarchicalId;
248 return static_cast<int>((parentValue / 100.0 * value));
290 if (constraint.empty() ==
true || constraint.length() == 0) {
291 return defaultConstraintsType;
293 if (constraint.compare(
"auto") == 0) {
296 if (constraint.compare(
"*") == 0) {
299 if (StringTools::endsWith(constraint,
"%")) {
308 if (constraint.empty() ==
true || constraint.length() == 0) {
309 return defaultConstraintsValue;
311 if (constraint.compare(
"auto") == 0) {
314 if (constraint.compare(
"*") == 0) {
317 if (StringTools::endsWith(constraint,
"%")) {
318 return (Integer::parse(constraint.substr(0, constraint.length() - 1)));
320 return (Integer::parse(constraint));
326 if (value.empty() ==
true || value.length() == 0) {
329 return (Integer::parse(value));
335 if (color.empty() ==
true || color.length() == 0) {
347 GUINode_Border GUINode::createBorder(
const string& allBorder,
const string& left,
const string& top,
const string& right,
const string& bottom,
const string& allBorderColor,
const string& leftColor,
const string& topColor,
const string& rightColor,
const string& bottomColor)
402 for (
auto i = 0; i < conditions.size(); i++) {
403 auto c = conditions[i];
412 if (arguments == 0 && c ==
',') {
413 guiNodeConditions.
add(StringTools::trim(condition));
419 if (condition.empty() ==
false) {
420 guiNodeConditions.
add(StringTools::trim(condition));
423 return guiNodeConditions;
431 if (
showOn.empty() ==
true &&
hideOn.empty() ==
true)
return true;
433 for (
auto i = 0; i <
showOn.size(); i++) {
438 for (
auto i = 0; i <
hideOn.size(); i++) {
448 vector<string> arguments;
449 for (
auto i = 0; i <
hideOn.size(); i++) {
450 auto conditionTerm =
hideOn[i];
452 if (
cfCall(elementNode,
function, arguments) ==
true)
return false;
454 for (
auto i = 0; i <
showOn.size(); i++) {
456 if (
cfCall(elementNode,
function, arguments) ==
true)
return true;
459 return showOn.empty() ==
true;
482 vector<Action*> actions;
483 vector<GUIEffect*> activeEffects;
484 for (
const auto& [effectId, effect]:
effects) {
485 if (effect->isActive() ==
true) {
486 if (effect->update(guiRenderer) ==
true && effect->getAction() !=
nullptr) {
487 actions.push_back(effect->getAction());
489 activeEffects.push_back(effect);
493 for (
auto action: actions) action->performAction();
494 if (activeEffects.empty() ==
true) {
495 auto defaultEffect =
getEffect(
"tdme.xmleffect.default");
496 if (defaultEffect !=
nullptr) {
497 defaultEffect->start();
498 activeEffects.push_back(defaultEffect);
542 ((left) / (screenWidth / 2.0f)) - 1.0f,
543 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
550 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
551 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
558 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
559 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
566 ((left) / (screenWidth / 2.0f)) - 1.0f,
567 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
582 if (scale9Grid.
left == 0 &&
583 scale9Grid.
right == 0 &&
584 scale9Grid.
top == 0 &&
591 ((left) / (screenWidth / 2.0f)) - 1.0f,
592 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
593 1.0f, 1.0f, 1.0f, 1.0f,
596 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
597 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
598 1.0f, 1.0f, 1.0f, 1.0f,
601 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
602 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
603 1.0f, 1.0f, 1.0f, 1.0f,
606 ((left) / (screenWidth / 2.0f)) - 1.0f,
607 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
608 1.0f, 1.0f, 1.0f, 1.0f,
616 if (scale9Grid.
top == 0 && scale9Grid.
bottom == 0) {
621 if (scale9Grid.
left == 0 && scale9Grid.
right == 0) {
636 scaledScale9Grid.
left =
static_cast<int>(scale9Grid.
left * scaleX);
637 scaledScale9Grid.
right =
static_cast<int>(scale9Grid.
right * scaleX);
638 scaledScale9Grid.
top =
static_cast<int>(scale9Grid.
top * scaleY);
639 scaledScale9Grid.
bottom =
static_cast<int>(scale9Grid.
bottom * scaleY);
642 float imageScreenScale9Left = imageScreenLeft + scaledScale9Grid.
left;
643 float imageScreenScale9Top = imageScreenTop + scaledScale9Grid.
top;
646 float imageScreenScale9Right = imageScreenLeft + imageScreenWidth - scaledScale9Grid.
right;
647 float imageScreenScale9Bottom = imageScreenTop + imageScreenHeight - scaledScale9Grid.
bottom;
651 if (scaledScale9Grid.
left > 0 && scaledScale9Grid.
top > 0) {
652 float left = imageScreenLeft;
653 float top = imageScreenTop;
654 float width = scaledScale9Grid.
left;
655 float height = scaledScale9Grid.
top;
657 ((left) / (screenWidth / 2.0f)) - 1.0f,
658 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
659 1.0f, 1.0f, 1.0f, 1.0f,
662 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
663 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
664 1.0f, 1.0f, 1.0f, 1.0f,
665 1.0f / imageTextureWidth * scale9Grid.
left,
667 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
668 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
669 1.0f, 1.0f, 1.0f, 1.0f,
670 1.0f / imageTextureWidth * scale9Grid.
left,
671 1.0f / imageTextureHeight * scale9Grid.
top,
672 ((left) / (screenWidth / 2.0f)) - 1.0f,
673 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
674 1.0f, 1.0f, 1.0f, 1.0f,
676 1.0f / imageTextureHeight * scale9Grid.
top
680 if (scaledScale9Grid.
top > 0) {
681 float left = imageScreenScale9Left;
682 float top = imageScreenTop;
683 float width = imageScreenWidth - scaledScale9Grid.
left - scaledScale9Grid.
right;
684 float height = scaledScale9Grid.
top;
686 ((left) / (screenWidth / 2.0f)) - 1.0f,
687 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
688 1.0f, 1.0f, 1.0f, 1.0f,
689 1.0f / imageTextureWidth * scale9Grid.
left,
691 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
692 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
693 1.0f, 1.0f, 1.0f, 1.0f,
694 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
696 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
697 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
698 1.0f, 1.0f, 1.0f, 1.0f,
699 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
700 1.0f / imageTextureHeight * scale9Grid.
top,
701 ((left) / (screenWidth / 2.0f)) - 1.0f,
702 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
703 1.0f, 1.0f, 1.0f, 1.0f,
704 1.0f / imageTextureWidth * scale9Grid.
left,
705 1.0f / imageTextureHeight * scale9Grid.
top
709 if (scaledScale9Grid.
right > 0 && scaledScale9Grid.
top > 0) {
710 float left = imageScreenScale9Right;
711 float top = imageScreenTop;
712 float width = scaledScale9Grid.
right;
713 float height = scaledScale9Grid.
top;
715 ((left) / (screenWidth / 2.0f)) - 1.0f,
716 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
717 1.0f, 1.0f, 1.0f, 1.0f,
718 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
720 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
721 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
722 1.0f, 1.0f, 1.0f, 1.0f,
725 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
726 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
727 1.0f, 1.0f, 1.0f, 1.0f,
729 1.0f / imageTextureHeight * scale9Grid.
top,
730 ((left) / (screenWidth / 2.0f)) - 1.0f,
731 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
732 1.0f, 1.0f, 1.0f, 1.0f,
733 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
734 1.0f / imageTextureHeight * scale9Grid.
top
738 if (scaledScale9Grid.
right > 0 && scaledScale9Grid.
bottom > 0) {
739 float left = imageScreenScale9Right;
740 float top = imageScreenScale9Bottom;
741 float width = scaledScale9Grid.
right;
742 float height = scaledScale9Grid.
bottom;
744 ((left) / (screenWidth / 2.0f)) - 1.0f,
745 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
746 1.0f, 1.0f, 1.0f, 1.0f,
747 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
748 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
749 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
750 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
751 1.0f, 1.0f, 1.0f, 1.0f,
753 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
754 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
755 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
756 1.0f, 1.0f, 1.0f, 1.0f,
759 ((left) / (screenWidth / 2.0f)) - 1.0f,
760 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
761 1.0f, 1.0f, 1.0f, 1.0f,
762 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
767 if (scaledScale9Grid.
bottom > 0) {
768 float left = imageScreenScale9Left;
769 float top = imageScreenScale9Bottom;
770 float width = imageScreenWidth - scaledScale9Grid.
left - scaledScale9Grid.
right;
771 float height = scaledScale9Grid.
bottom;
773 ((left) / (screenWidth / 2.0f)) - 1.0f,
774 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
775 1.0f, 1.0f, 1.0f, 1.0f,
776 1.0f / imageTextureWidth * scale9Grid.
left,
777 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
778 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
779 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
780 1.0f, 1.0f, 1.0f, 1.0f,
781 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
782 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
783 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
784 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
785 1.0f, 1.0f, 1.0f, 1.0f,
786 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
788 ((left) / (screenWidth / 2.0f)) - 1.0f,
789 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
790 1.0f, 1.0f, 1.0f, 1.0f,
791 1.0f / imageTextureWidth * scale9Grid.
left,
796 if (scaledScale9Grid.
left > 0 && scaledScale9Grid.
bottom > 0) {
797 float left = imageScreenLeft;
798 float top = imageScreenScale9Bottom;
799 float width = scaledScale9Grid.
left;
800 float height = scaledScale9Grid.
bottom;
802 ((left) / (screenWidth / 2.0f)) - 1.0f,
803 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
804 1.0f, 1.0f, 1.0f, 1.0f,
806 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
807 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
808 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
809 1.0f, 1.0f, 1.0f, 1.0f,
810 1.0f / imageTextureWidth * scale9Grid.
left,
811 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
812 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
813 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
814 1.0f, 1.0f, 1.0f, 1.0f,
815 1.0f / imageTextureWidth * scale9Grid.
left,
817 ((left) / (screenWidth / 2.0f)) - 1.0f,
818 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
819 1.0f, 1.0f, 1.0f, 1.0f,
825 if (scaledScale9Grid.
left > 0) {
826 float left = imageScreenLeft;
827 float top = imageScreenScale9Top;
828 float width = scaledScale9Grid.
left;
829 float height = imageScreenHeight - scaledScale9Grid.
top - scaledScale9Grid.
bottom;
831 ((left) / (screenWidth / 2.0f)) - 1.0f,
832 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
833 1.0f, 1.0f, 1.0f, 1.0f,
835 1.0f / imageTextureHeight * scale9Grid.
top,
836 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
837 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
838 1.0f, 1.0f, 1.0f, 1.0f,
839 1.0f / imageTextureWidth * scale9Grid.
left,
840 1.0f / imageTextureHeight * scale9Grid.
top,
841 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
842 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
843 1.0f, 1.0f, 1.0f, 1.0f,
844 1.0f / imageTextureWidth * scale9Grid.
left,
845 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
846 ((left) / (screenWidth / 2.0f)) - 1.0f,
847 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
848 1.0f, 1.0f, 1.0f, 1.0f,
850 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom)
854 if (scaledScale9Grid.
right > 0) {
855 float left = imageScreenScale9Right;
856 float top = imageScreenScale9Top;
857 float width = scaledScale9Grid.
right;
858 float height = imageScreenHeight - scaledScale9Grid.
top - scaledScale9Grid.
bottom;
860 ((left) / (screenWidth / 2.0f)) - 1.0f,
861 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
862 1.0f, 1.0f, 1.0f, 1.0f,
863 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
864 1.0f / imageTextureHeight * scale9Grid.
top,
865 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
866 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
867 1.0f, 1.0f, 1.0f, 1.0f,
869 1.0f / imageTextureHeight * scale9Grid.
top,
870 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
871 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
872 1.0f, 1.0f, 1.0f, 1.0f,
874 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
875 ((left) / (screenWidth / 2.0f)) - 1.0f,
876 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
877 1.0f, 1.0f, 1.0f, 1.0f,
878 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
879 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom)
884 float left = imageScreenScale9Left;
885 float top = imageScreenScale9Top;
886 float width = imageScreenWidth - scaledScale9Grid.
left - scaledScale9Grid.
right;
887 float height = imageScreenHeight - scaledScale9Grid.
top - scaledScale9Grid.
bottom;
889 ((left) / (screenWidth / 2.0f)) - 1.0f,
890 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
891 1.0f, 1.0f, 1.0f, 1.0f,
892 1.0f / imageTextureWidth * scale9Grid.
left,
893 1.0f / imageTextureHeight * scale9Grid.
top,
894 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
895 ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f,
896 1.0f, 1.0f, 1.0f, 1.0f,
897 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
898 1.0f / imageTextureHeight * scale9Grid.
top,
899 ((left + width) / (screenWidth / 2.0f)) - 1.0f,
900 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
901 1.0f, 1.0f, 1.0f, 1.0f,
902 1.0f / imageTextureWidth * (imageTextureWidth - scale9Grid.
right),
903 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom),
904 ((left) / (screenWidth / 2.0f)) - 1.0f,
905 ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f,
906 1.0f, 1.0f, 1.0f, 1.0f,
907 1.0f / imageTextureWidth * scale9Grid.
left,
908 1.0f / imageTextureHeight * (imageTextureHeight - scale9Grid.
bottom)
922 guiRenderer->
addQuad(((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 0.0f, ((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 0.0f);
930 guiRenderer->
addQuad(((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 0.0f, ((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 0.0f);
938 guiRenderer->
addQuad(((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 0.0f, ((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 0.0f);
946 guiRenderer->
addQuad(((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 1.0f, ((left + width) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 1.0f, 0.0f, ((left) / (screenWidth / 2.0f)) - 1.0f, ((screenHeight - top - height) / (screenHeight / 2.0f)) - 1.0f, borderColor[0], borderColor[1], borderColor[2], borderColor[3], 0.0f, 0.0f);
953 auto childrenRenderOffSetX = 0.0f;
959 return childrenRenderOffSetX;
963 auto childrenRenderOffSetY = 0.0f;
969 return childrenRenderOffSetY;
974 auto eventXScreen =
event->getX();
975 auto eventYScreen =
event->getY();
983 position[0] =
static_cast<int>((eventX - left));
984 }
else if (eventX > right) {
985 position[0] =
static_cast<int>((eventX - right));
990 position[1] =
static_cast<int>((eventY - top));
991 }
else if (eventY > bottom) {
992 position[1] =
static_cast<int>((eventY - bottom));
999 auto eventXScreen =
event->getX();
1000 auto eventYScreen =
event->getY();
1007 position[0] = Math::clamp(
static_cast<int>(eventX), left, right) - left;
1008 position[1] = Math::clamp(
static_cast<int>(eventY), top, bottom) - top;
1014 while (node !=
nullptr && node->controller ==
nullptr) {
1052 this->controller = unique_ptr<GUINodeController>(
controller);
1059 while (
true ==
true) {
1060 if (scrollXParentNode == toNode || scrollXParentNode ==
nullptr)
1066 scrollXParentNode = scrollXParentNode->
parentNode;
1068 if (
computedConstraints.
left < scrollXParentNode->getChildrenRenderOffsetX() + scrollXParentNode->computedConstraints.left) {
1074 scrollXParentNode->_scrollToNodeX(toNode);
1081 while (
true ==
true) {
1082 if (scrollYParentNode == toNode || scrollYParentNode ==
nullptr)
return;
1084 scrollYParentNode = scrollYParentNode->
parentNode;
1085 if (scrollYParentNode ==
nullptr)
return;
1087 if (
computedConstraints.
top < scrollYParentNode->getChildrenRenderOffsetY() + scrollYParentNode->computedConstraints.top) {
1093 scrollYParentNode->_scrollToNodeY(toNode);
1105 string indentString;
1106 for (
auto i = 0; i < indent; i++) indentString+=
" ";
1123 ": conditions met: " +
1126 (
dynamic_cast<GUIParentNode*
>(node) !=
nullptr?
"; child count: " + to_string(
dynamic_cast<GUIParentNode*
>(node)->subNodes.size()):
"") +
1127 (node->
getController() !=
nullptr?
"; controller attached":
"; no controller")
1129 if (
dynamic_cast<GUIParentNode*
>(node) !=
nullptr && (depth == 0 || depthIdx + 1 < depth)) {
1130 auto parentNode = required_dynamic_cast<GUIParentNode*>(node);
1132 dumpNode(subNode, depth, indent + 1, depthIdx + 1);
1138 string indentString;
1139 for (
auto i = 0; i < indent; i++) indentString+=
" ";
1156 ": conditions met: " +
1159 (
dynamic_cast<GUIParentNode*
>(node) !=
nullptr?
"; child count: " + to_string(
dynamic_cast<GUIParentNode*
>(node)->subNodes.size()):
"")
1170 vector<string> arguments;
1171 for (
auto i = 0; i <
hideOn.size(); i++) {
1172 auto conditionTerm =
hideOn[i];
1176 for (
auto i = 0; i <
showOn.size(); i++) {
1184 auto leftParenthesis = term.find(
'(');
1185 auto rightParenthesis = term.find_last_of(
')');
1186 function =
"hasCondition";
1187 if (leftParenthesis != string::npos && rightParenthesis != string::npos && leftParenthesis < rightParenthesis) {
1188 function = StringTools::trim(StringTools::substring(term, 0, leftParenthesis));
1191 auto argumentStartIdx = leftParenthesis != string::npos?leftParenthesis + 1:0;
1192 auto argumentEndIdx = rightParenthesis != string::npos?rightParenthesis:term.size();
1194 auto doubleQuote =
false;
1196 for (
auto i = argumentStartIdx; i < argumentEndIdx; i++) {
1200 if (quote ==
true) {
1202 arguments.push_back(StringTools::trim(argument));
1208 if (doubleQuote ==
true) {
1209 doubleQuote =
false;
1210 arguments.push_back(argument);
1214 if (quote ==
false && doubleQuote ==
false && c ==
',') {
1215 arguments.push_back(StringTools::trim(argument));
1221 if (argument.empty() ==
false) {
1222 arguments.push_back(StringTools::trim(argument));
1228 if (
function ==
"empty") {
1231 if (
function ==
"notEmpty") {
1232 return cfEmpty(arguments) ==
false;
1234 if (
function ==
"hasCondition") {
1237 Console::println(
"GUINode::cfCall(): Unknown function: " +
function +
": returning false");
1243 if (
function ==
"empty") {
1246 if (
function ==
"notEmpty") {
1249 if (
function ==
"hasCondition") {
1252 Console::println(
"GUINode::cfCallDetermineElementNodeDependencies(): Unknown function: " +
function +
": returning false");
1259 for (
const auto& argument: arguments) {
1260 string elementNodeId;
1261 auto condition = argument;
1262 if (condition.find(
'.') != -1) {
1268 if (elementNodeToCheck ==
nullptr) {
1269 Console::println(
"GUINode::checkConditions(): element node '" + elementNodeId +
"': not found");
1272 if (elementNodeToCheck->activeConditions.has(condition) ==
true)
return true;
1279 for (
const auto& argument: arguments) {
1280 string elementNodeId;
1281 auto condition = argument;
1282 if (condition.find(
'.') != string::npos) {
1287 if (elementNodeId.empty() ==
false) {
1288 elementNodeDependencies.push_back(elementNodeId);
1294 for (
const auto& argument: arguments) {
1295 if (argument ==
"false" ||
1297 argument ==
"0.0" ||
1298 argument ==
"\"\"" ||
1299 argument ==
"''")
return true;
1310 if (backgroundImage.length() > 0) {
1325 auto effectIt =
effects.find(
id);
1326 if (effectIt ==
effects.end())
return nullptr;
1327 return effectIt->second;
1332 auto effectIt =
effects.find(
id);
1333 if (effectIt ==
effects.end())
return;
1334 delete effectIt->second;
1346 auto defaultEffect =
getEffect(
"tdme.xmleffect.default");
1349 auto haveInEffect =
false;
1350 auto issuedOutEffect =
false;
1353 for (
const auto& condition: conditions) {
1355 auto effect =
getEffect(
"tdme.xmleffect.in.color.on." + condition);
1356 if (effect !=
nullptr && effect->isActive() ==
false) {
1357 haveInEffect =
true;
1362 auto effect =
getEffect(
"tdme.xmleffect.in.position.on." + condition);
1363 if (effect !=
nullptr && effect->isActive() ==
false) {
1364 haveInEffect =
true;
1369 if (haveInEffect ==
true) {
1370 if (defaultEffect !=
nullptr) defaultEffect->stop();
1371 for (
const auto& [effectId, effect]:
effects) {
1372 if (StringTools::startsWith(effectId,
"tdme.xmleffect.out.") ==
true && effect->isActive() ==
true) {
1378 if (find(conditions.begin(), conditions.end(), condition) != conditions.end())
continue;
1380 auto effect =
getEffect(
"tdme.xmleffect.out.color.on." + condition);
1381 if (effect !=
nullptr && effect->isActive() ==
false) {
1382 issuedOutEffect =
true;
1388 auto effect =
getEffect(
"tdme.xmleffect.out.position.on." + condition);
1389 if (effect !=
nullptr && effect->isActive() ==
false) {
1390 issuedOutEffect =
true;
1396 if (issuedOutEffect ==
true) {
1397 if (defaultEffect !=
nullptr && defaultEffect->isActive() ==
true) defaultEffect->stop();
1398 for (
const auto& [effectId, effect]:
effects) {
1399 if (StringTools::startsWith(effectId,
"tdme.xmleffect.in.") ==
true && effect->isActive() ==
true) {
1408 auto haveColorEffect =
false;
1409 auto havePositionEffect =
false;
1410 for (
const auto& [effectId, effect]:
effects) {
1411 if (effect->isActive() ==
true) {
1412 switch (effect->getType()) {
1413 case GUIEffect::EFFECTTYPE_COLOR:
1414 haveColorEffect =
true;
1416 case GUIEffect::EFFECTTYPE_POSITION:
1417 havePositionEffect =
true;
1419 case GUIEffect::EFFECTTYPE_NONE:
1424 if (haveColorEffect ==
false || havePositionEffect ==
false) {
1425 if (defaultEffect !=
nullptr) {
1426 switch (defaultEffect->getType()) {
1427 case GUIEffect::EFFECTTYPE_COLOR:
1428 haveColorEffect =
true;
1430 case GUIEffect::EFFECTTYPE_POSITION:
1431 havePositionEffect =
true;
1433 case GUIEffect::EFFECTTYPE_NONE:
1438 if (haveColorEffect ==
false) {
1439 GUIColorEffect::resetEffectState(
effectState.get());
1442 if (havePositionEffect ==
false) {
1443 GUIPositionEffect::resetEffectState(
effectState.get());
1446 if (defaultEffect !=
nullptr && haveColorEffect ==
false && havePositionEffect ==
false) {
1447 defaultEffect->start();
1456 for (
const auto& [effectId, effect]:
effects) {
1457 if (effect->isActive() ==
true) {
bool equals(const Color4 &color, float tolerance=Math::EPSILON) const
Compares this color with given color.
const array< float, 4 > & getArray() const
uint16_t getWidth() const
const string & getId() const
uint16_t getHeight() const
static STATIC_DLL_IMPEXT GUIColor GUICOLOR_BLACK
static STATIC_DLL_IMPEXT GUIColor GUICOLOR_TRANSPARENT
static STATIC_DLL_IMPEXT string CONDITION_ALWAYS
GUI element node conditions.
bool add(const string &condition)
Add a condition.
vector< string > conditions
GUI node controller base class.
virtual void dispose()=0
Dispose controller.
GUI node horizontal alignment enum.
static STATIC_DLL_IMPEXT GUINode_AlignmentHorizontal * RIGHT
static GUINode_AlignmentHorizontal * valueOf(const string &name)
Returns enum object given by name.
static STATIC_DLL_IMPEXT GUINode_AlignmentHorizontal * CENTER
static STATIC_DLL_IMPEXT GUINode_AlignmentHorizontal * LEFT
GUI node vertical alignment enum.
static STATIC_DLL_IMPEXT GUINode_AlignmentVertical * BOTTOM
static GUINode_AlignmentVertical * valueOf(const string &name)
Returns enum object given by name.
static STATIC_DLL_IMPEXT GUINode_AlignmentVertical * CENTER
static STATIC_DLL_IMPEXT GUINode_AlignmentVertical * TOP
static STATIC_DLL_IMPEXT GUINode_Flow * FLOATING
static GUINode_Flow * valueOf(const string &name)
Returns enum object given by name.
GUI node requested constraints requested constraints type enum.
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * PERCENT
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * TABLECELL
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * STAR
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * NONE
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * PIXEL
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * AUTO
void cfCallDetermineElementNodeDependencies(const string &function, const vector< string > &arguments, vector< string > &elementNodeDependencies)
Determine element node dependencies - Call condition function with arguments.
bool cfCall(GUIElementNode *elementNode, const string &function, const vector< string > &arguments)
Call condition function with arguments.
virtual int getContentHeight()=0
static GUINode_RequestedConstraints_RequestedConstraintsType * getRequestedConstraintsType(const string &constraint, GUINode_RequestedConstraints_RequestedConstraintsType *defaultConstraintsType)
Get requested constraints type.
GUIColor backgroundImageEffectColorMul
float computeParentChildrenRenderOffsetXTotal()
virtual void determineMouseEventNodes(GUIMouseEvent *event, bool floatingNode, unordered_set< string > &eventNodeIds, unordered_set< string > &eventFloatingNodeIds, int flags=DETERMINEMOUSEEVENTNODES_FLAG_NONE)
Determine mouse event nodes.
static GUINode_Alignments createAlignments(const string &horizontal, const string &vertical)
Create alignments.
void scrollToNodeY(GUIParentNode *toNode=nullptr)
Scroll to node Y.
void scrollToNodeX(GUIParentNode *toNode=nullptr)
Scroll to node X.
void onSetConditions(const vector< string > &conditions)
On set condition.
virtual int getContentWidth()=0
void addEffect(const string &id, GUIEffect *effect)
Add effect, effect already registered with the is will be removed.
virtual void setLeft(int left)
Set computed left.
virtual void layoutOnDemand()
Layout on demand.
GUINode_Scale9Grid backgroundImageScale9Grid
virtual void determineNodesByCoordinate(const Vector2 &coordinate, unordered_set< string > &nodeIds)
Determine nodes by coordinate.
bool cfHasCondition(GUIElementNode *elementNode, const vector< string > &arguments)
Condition function: has condition.
virtual ~GUINode()
Destructor.
vector< string > lastConditions
void _scrollToNodeX(GUIParentNode *toNode=nullptr)
Scroll to node X.
void cfDetermineElementNodeDependencies(vector< string > &elementNodeDependencies)
Determine element node dependencies.
static GUIColor getRequestedColor(const string &color, const GUIColor &defaultColor)
Get color.
virtual void render(GUIRenderer *guiRenderer)
Render.
static int getRequestedPixelValue(const string &value, int defaultValue)
Get requested pixel value.
void cfParse(const string &term, string &function, vector< string > &arguments)
Parse condition function term.
static constexpr int DETERMINEMOUSEEVENTNODES_FLAG_TOOLTIP
GUIColor backgroundImageEffectColorAdd
virtual void computeContentAlignment()
Do content alignment.
unique_ptr< GUINodeController > controller
GUIParentNode * parentNode
void _scrollToNodeY(GUIParentNode *toNode=nullptr)
Scroll to node Y.
virtual const string getNodeType()=0
static void dumpNode(GUINode *node, int depth=0, int indent=0, int depthIdx=0)
Dump node.
virtual void undoEffects(GUIRenderer *guiRenderer)
Undo effects.
virtual bool isContentNode()=0
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &nodeCoordinate)
Is event belonging to node.
Texture * backgroundTexture
bool haveActiveOutEffect()
Determine if we have a out effect active.
GUINode_ComputedConstraints computedConstraints
void cfHasConditionDetermineElementNodeDependencies(const vector< string > &arguments, vector< string > &elementNodeDependencies)
Determine element node dependencies - Condition function: has condition.
unordered_map< string, GUIEffect * > effects
virtual void setTop(int top)
Set computed top.
virtual void setConditionsMet()
Set conditions met for this node and its subnodes.
GUINodeController * getController()
GUIScreenNode * screenNode
const string getHierarchicalId()
virtual int getAutoWidth()
int layoutConstraintPixel(GUINode_RequestedConstraints_RequestedConstraintsType *type, int autoValue, int parentValue, int value)
Layout constraint.
GUINode_RequestedConstraints requestedConstraints
float computeParentChildrenRenderOffsetYTotal()
bool shouldRender()
Returns if to render.
GUIParentNode * getParentControllerNode()
virtual void dispose()
Dispose node.
bool cfEmpty(const vector< string > &arguments)
Condition function: empty.
void removeEffect(const string &id)
Remove effect.
void setBackgroundImage(const string &backgroundImage)
Set background image.
static GUINode_RequestedConstraints createRequestedConstraints(const string &left, const string &top, const string &width, const string &height, int factor)
Create requested constraints.
virtual void applyEffects(GUIRenderer *guiRenderer)
Apply effects.
GUINode_Alignments alignments
static void dumpParentNodes(GUINode *node, int indent=0)
Dump parent nodes.
bool isCoordinateBelongingToNode(const Vector2 &coordinate, Vector2 &nodeCoordinate)
Is coordinate belonging to node.
void setController(GUINodeController *controller)
Set up node controller.
bool checkConditions()
Check if conditions are met.
GUIEffect * getEffect(const string &id)
Get effect.
unique_ptr< GUIEffectState > effectState
static GUINode_Border createBorder(const string &allBorder, const string &left, const string &top, const string &right, const string &bottom, const string &allBorderColor, const string &leftColor, const string &topColor, const string &rightColor, const string &bottomColor)
Create border.
void getEventNodePosition(GUIMouseEvent *event, Vector2 &position)
Get event position clamped to node constraints TODO: use Vector2 instead of array<float,...
virtual void layout()
Layout.
static GUINodeConditions createConditions(const string &conditions)
Create conditions.
static GUINode_Padding createPadding(const string &allPadding, const string &left, const string &top, const string &right, const string &bottom)
Create padding.
static GUINode_Scale9Grid createScale9Grid(const string &all, const string &left, const string &top, const string &right, const string &bottom)
Create scale 9 grid.
void getEventOffNodeRelativePosition(GUIMouseEvent *event, Vector2 &position)
Get event off node relative position TODO: use Vector2 instead of array<float, 2>
virtual int getAutoHeight()
static int getRequestedConstraintsValue(const string &constraint, int defaultConstraintsValue)
Get requested constraints value.
static GUINode_Flow * createFlow(const string &flow)
Create flow.
GUI parent node overflow enum.
static STATIC_DLL_IMPEXT GUIParentNode_Overflow * SCROLL
GUI parent node base class thats supporting child nodes.
void setChildrenRenderOffsetX(float childrenRenderOffSetX)
Set children render offset x.
float getChildrenRenderOffsetX()
float getChildrenRenderOffsetY()
vector< GUINode * > subNodes
void setChildrenRenderOffsetY(float childrenRenderOffSetY)
Set children render offset y.
GUI screen node that represents a screen that can be rendered via GUI system.
void scrollToNodeX(const string &node, const string &toNode)
Register deferred scroll to node X.
void scrollToNodeY(const string &node, const string &toNode)
Register deferred scroll to node Y.
void removeTickNode(GUINode *node)
Remove tick node.
Texture * getImage(const string &fileName)
Get image.
void forceLayout(GUINode *node)
Force layout node content (e.g.
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
void addNodeElementNodeDependency(const string &elementNodeId, const string &nodeId)
Add node to element node dependency.
void bindTexture(int32_t textureId)
Bind texture.
void setEffectColorAdd(const GUIColor &color)
Set effect color add.
void popEffects()
Pop effects.
void setEffectColorMul(const GUIColor &color)
Set effect color mul.
void pushEffects(const vector< GUIEffect * > &effects)
Push effects @oaran effects effects.
void addQuad(float x1, float y1, float colorR1, float colorG1, float colorB1, float colorA1, float tu1, float tv1, float x2, float y2, float colorR2, float colorG2, float colorB2, float colorA2, float tu2, float tv2, float x3, float y3, float colorR3, float colorG3, float colorB3, float colorA3, float tu3, float tv3, float x4, float y4, float colorR4, float colorG4, float colorB4, float colorA4, float tu4, float tv4, bool solidColor=false, bool rotated=false)
Add quad Note: quad vertices order 1 2 +-—+ | | | | +-—+ 4 3.
Vector2 class representing vector2 mathematical structure and operations with x, y components.
const string & getName() const
bool equals(Enum *enumObject) const
Compare enum with another enum.
const string & nextToken()
void tokenize(const string &str, const string &delimiters, bool emptyTokens=false)
Tokenize.
GUINode_AlignmentVertical * vertical
GUINode_AlignmentHorizontal * horizontal
GUI node computed constraints.
GUI node requested constraints entity.
GUINode_RequestedConstraints_RequestedConstraintsType * topType
GUINode_RequestedConstraints_RequestedConstraintsType * widthType
GUINode_RequestedConstraints_RequestedConstraintsType * leftType
GUINode_RequestedConstraints_RequestedConstraintsType * heightType
GUI node scale 9 grid entity.