|
|
@@ -30,6 +30,7 @@
|
|
|
#include <Rocket/Debugger.h>
|
|
|
#include <Input.h>
|
|
|
#include <Shell.h>
|
|
|
+#include <Rocket/Core/TransformPrimitive.h>
|
|
|
|
|
|
#include <cmath>
|
|
|
#include <sstream>
|
|
|
@@ -39,26 +40,35 @@ class DemoWindow
|
|
|
public:
|
|
|
DemoWindow(const Rocket::Core::String &title, const Rocket::Core::Vector2f &position, Rocket::Core::Context *context)
|
|
|
{
|
|
|
+ using namespace Rocket::Core;
|
|
|
document = context->LoadDocument("basic/animation/data/animation.rml");
|
|
|
if (document != NULL)
|
|
|
{
|
|
|
document->GetElementById("title")->SetInnerRML(title);
|
|
|
- document->SetProperty("left", Rocket::Core::Property(position.x, Rocket::Core::Property::PX));
|
|
|
- document->SetProperty("top", Rocket::Core::Property(position.y, Rocket::Core::Property::PX));
|
|
|
+ document->SetProperty("left", Property(position.x, Property::PX));
|
|
|
+ document->SetProperty("top", Property(position.y, Property::PX));
|
|
|
+ document->Animate("opacity", Property(0.6f, Property::NUMBER), 0.5f, -1, true);
|
|
|
|
|
|
auto el = document->GetElementById("high_score");
|
|
|
- el->Animate("margin-left", Rocket::Core::Property(0.f, Rocket::Core::Property::PX), 0.3f, 10, true);
|
|
|
- el->Animate("margin-left", Rocket::Core::Property(100.f, Rocket::Core::Property::PX), 0.6f);
|
|
|
+ el->Animate("margin-left", Property(0.f, Property::PX), 0.3f, 10, true);
|
|
|
+ el->Animate("margin-left", Property(100.f, Property::PX), 0.6f);
|
|
|
|
|
|
el = document->GetElementById("exit");
|
|
|
- el->Animate("margin-left", Rocket::Core::Property(100.f, Rocket::Core::Property::PX), 8.0f, -1, true);
|
|
|
+ el->Animate("margin-left", Property(100.f, Property::PX), 8.0f, -1, true);
|
|
|
+
|
|
|
+ el = document->GetElementById("start_game");
|
|
|
+ auto transform = new Transform;
|
|
|
+ auto value = Transforms::NumericValue(370.f, Property::DEG);
|
|
|
+ transform->AddPrimitive(Transforms::Rotate2D{ &value });
|
|
|
+ TransformRef tref{ transform };
|
|
|
+ el->Animate("transform", Property(tref, Property::TRANSFORM), 0.8f, -1, false);
|
|
|
|
|
|
el = document->GetElementById("help");
|
|
|
- el->Animate("image-color", Rocket::Core::Property(Rocket::Core::Colourb(128, 255, 255, 255), Rocket::Core::Property::COLOUR), 0.3f, -1, false);
|
|
|
- el->Animate("image-color", Rocket::Core::Property(Rocket::Core::Colourb(128, 128, 255, 255), Rocket::Core::Property::COLOUR), 0.3f);
|
|
|
- el->Animate("image-color", Rocket::Core::Property(Rocket::Core::Colourb(0, 128, 128, 255), Rocket::Core::Property::COLOUR), 0.3f);
|
|
|
- el->Animate("image-color", Rocket::Core::Property(Rocket::Core::Colourb(64, 128, 255, 0), Rocket::Core::Property::COLOUR), 0.9f);
|
|
|
- el->Animate("image-color", Rocket::Core::Property(Rocket::Core::Colourb(255, 255, 255, 255), Rocket::Core::Property::COLOUR), 0.3f);
|
|
|
+ el->Animate("image-color", Property(Colourb(128, 255, 255, 255), Property::COLOUR), 0.3f, -1, false);
|
|
|
+ el->Animate("image-color", Property(Colourb(128, 128, 255, 255), Property::COLOUR), 0.3f);
|
|
|
+ el->Animate("image-color", Property(Colourb(0, 128, 128, 255), Property::COLOUR), 0.3f);
|
|
|
+ el->Animate("image-color", Property(Colourb(64, 128, 255, 0), Property::COLOUR), 0.9f);
|
|
|
+ el->Animate("image-color", Property(Colourb(255, 255, 255, 255), Property::COLOUR), 0.3f);
|
|
|
|
|
|
document->Show();
|
|
|
}
|
|
|
@@ -86,13 +96,21 @@ Rocket::Core::Context* context = NULL;
|
|
|
ShellRenderInterfaceExtensions *shell_renderer;
|
|
|
DemoWindow* window = NULL;
|
|
|
|
|
|
+bool pause_loop = false;
|
|
|
+bool single_loop = false;
|
|
|
+
|
|
|
void GameLoop()
|
|
|
{
|
|
|
- context->Update();
|
|
|
+ if(!pause_loop || single_loop)
|
|
|
+ {
|
|
|
+ context->Update();
|
|
|
|
|
|
- shell_renderer->PrepareRenderBuffer();
|
|
|
- context->Render();
|
|
|
- shell_renderer->PresentRenderBuffer();
|
|
|
+ shell_renderer->PrepareRenderBuffer();
|
|
|
+ context->Render();
|
|
|
+ shell_renderer->PresentRenderBuffer();
|
|
|
+
|
|
|
+ single_loop = false;
|
|
|
+ }
|
|
|
|
|
|
//auto el = window->GetDocument()->GetElementById("exit");
|
|
|
//auto f = el->GetProperty<int>("margin-left");
|
|
|
@@ -103,6 +121,64 @@ void GameLoop()
|
|
|
// Rocket::Core::Log::Message(Rocket::Core::Log::LT_INFO, "Animation f = %d, df = %d", f, df);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+class Event : public Rocket::Core::EventListener
|
|
|
+{
|
|
|
+public:
|
|
|
+ Event(const Rocket::Core::String& value) : value(value) {}
|
|
|
+
|
|
|
+ void ProcessEvent(Rocket::Core::Event& event) override
|
|
|
+ {
|
|
|
+ if(value == "exit")
|
|
|
+ Shell::RequestExit();
|
|
|
+
|
|
|
+ if (event == "keydown" ||
|
|
|
+ event == "keyup")
|
|
|
+ {
|
|
|
+ bool key_down = event == "keydown";
|
|
|
+ Rocket::Core::Input::KeyIdentifier key_identifier = (Rocket::Core::Input::KeyIdentifier) event.GetParameter< int >("key_identifier", 0);
|
|
|
+
|
|
|
+ if (key_identifier == Rocket::Core::Input::KI_SPACE && key_down)
|
|
|
+ {
|
|
|
+ pause_loop = !pause_loop;
|
|
|
+ }
|
|
|
+ else if (key_identifier == Rocket::Core::Input::KI_RETURN && key_down)
|
|
|
+ {
|
|
|
+ pause_loop = true;
|
|
|
+ single_loop = true;
|
|
|
+ }
|
|
|
+ else if (key_identifier == Rocket::Core::Input::KI_ESCAPE)
|
|
|
+ {
|
|
|
+ Shell::RequestExit();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void OnDetach(Rocket::Core::Element* element) override { delete this; }
|
|
|
+
|
|
|
+private:
|
|
|
+ Rocket::Core::String value;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+class EventInstancer : public Rocket::Core::EventListenerInstancer
|
|
|
+{
|
|
|
+public:
|
|
|
+
|
|
|
+ /// Instances a new event handle for Invaders.
|
|
|
+ Rocket::Core::EventListener* InstanceEventListener(const Rocket::Core::String& value, Rocket::Core::Element* element) override
|
|
|
+ {
|
|
|
+ return new Event(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Destroys the instancer.
|
|
|
+ void Release() override { delete this; }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
#if defined ROCKET_PLATFORM_WIN32
|
|
|
#include <windows.h>
|
|
|
int APIENTRY WinMain(HINSTANCE ROCKET_UNUSED_PARAMETER(instance_handle), HINSTANCE ROCKET_UNUSED_PARAMETER(previous_instance_handle), char* ROCKET_UNUSED_PARAMETER(command_line), int ROCKET_UNUSED_PARAMETER(command_show))
|
|
|
@@ -154,9 +230,16 @@ int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv)
|
|
|
Input::SetContext(context);
|
|
|
shell_renderer->SetContext(context);
|
|
|
|
|
|
+
|
|
|
+ EventInstancer* event_instancer = new EventInstancer();
|
|
|
+ Rocket::Core::Factory::RegisterEventListenerInstancer(event_instancer);
|
|
|
+ event_instancer->RemoveReference();
|
|
|
+
|
|
|
Shell::LoadFonts("assets/");
|
|
|
|
|
|
window = new DemoWindow("Animation sample", Rocket::Core::Vector2f(81, 200), context);
|
|
|
+ window->GetDocument()->AddEventListener("keydown", new Event("hello"));
|
|
|
+ window->GetDocument()->AddEventListener("keyup", new Event("hello"));
|
|
|
|
|
|
|
|
|
Shell::EventLoop(GameLoop);
|