#include #if UF_USE_ULTRALIGHT #include "behavior.h" #include "../gui.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include UF_BEHAVIOR_REGISTER_CPP(ext::GuiHtmlBehavior) UF_BEHAVIOR_TRAITS_CPP(ext::GuiHtmlBehavior, ticks = true, renders = false, multithread = false) #define this ((uf::Object*) &self) void ext::GuiHtmlBehavior::initialize( uf::Object& self ) { #if UF_USE_ULTRALIGHT auto& page = this->getComponent(); auto& metadata = this->getComponent(); pod::Vector2ui size = { 1, 1 }; if ( ext::json::isArray( metadata["size"] ) ) { size = { metadata["size"][0].as(), metadata["size"][1].as(), }; } else { size = ext::gui::size.current; } if ( size.x <= 0 && size.y <= 0 ) { size = uf::vector::decode( ext::config["window"]["size"], pod::Vector2ui{} ); } page = ext::ultralight::create( page, metadata["html"].as(), size); uf::stl::string onLoad = this->formatHookName("html:Load.%UID%"); if ( metadata["wait for load"].as() ) { ext::ultralight::on(page, "load", onLoad); this->addHook( onLoad, [&](ext::json::Value& json){ auto image = ext::ultralight::capture( page ); this->as().load( image ); }); } else { auto image = ext::ultralight::capture( page ); this->as().load( image ); } this->addHook( "window:Resized", [&](ext::json::Value& json){ if ( !this->hasComponent() ) return; pod::Vector2ui size = uf::vector::decode( json["window"]["size"], pod::Vector2ui{} ); metadata["size"][0] = size.x; metadata["size"][1] = size.y; ext::ultralight::resize( page, size ); }); this->addHook( "window:Key", [&](ext::json::Value& json){ if ( json["type"].as() == "window:Text.Entered" ) return; if ( metadata["ignore inputs"].as() ) return; ext::ultralight::input( page, json ); }); this->addHook( "window:Text.Entered", [&](ext::json::Value& json){ if ( metadata["ignore inputs"].as() ) return; ext::ultralight::input( page, json ); }); this->addHook( "window:Mouse.Wheel", [&](ext::json::Value& json){ if ( metadata["ignore inputs"].as() ) return; ext::ultralight::input( page, json ); }); this->addHook( "gui:Mouse.Clicked.%UID%", [&](ext::json::Value& json){ if ( metadata["ignore inputs"].as() ) return; ext::ultralight::input( page, json ); }); this->addHook( "gui:Mouse.Moved.%UID%", [&](ext::json::Value& json){ if ( metadata["ignore inputs"].as() ) return; ext::ultralight::input( page, json ); }); #endif } void ext::GuiHtmlBehavior::tick( uf::Object& self ) { #if UF_USE_ULTRALIGHT auto& metadata = this->getComponent(); auto& page = this->getComponent(); bool should = metadata["update"].as() || page.pending; if ( !this->hasComponent() || !should ) return; auto& graphic = this->getComponent(); auto& texture = graphic.material.textures.front(); auto image = ext::ultralight::capture( page ); texture.update( image ); // page.pending = false; #endif } void ext::GuiHtmlBehavior::render( uf::Object& self ){} void ext::GuiHtmlBehavior::destroy( uf::Object& self ){} void ext::GuiHtmlBehavior::Metadata::serializer( uf::Object& self, uf::Serializer& serializer ){} void ext::GuiHtmlBehavior::Metadata::deserializer( uf::Object& self, uf::Serializer& serializer ){} #undef this #endif