Object.merge(options, defaults, false, false);
return Object.merge(new UI._Group, options);
};
-
+
+
+ // UICustom
+ UI.Custom = function(options) {
+ options = options || {};
+ var defaults = {
+ docking: UI.DOCKING_TOP | UI.DOCKING_LEFT | UI.DOCKING_RIGHT
+ };
+ Object.merge(options, defaults, false, false);
+
+ return (function (obj) {
+ obj._processinput = function() {
+ obj.processinput.call(obj);
+ }
+ obj._update = function() {
+ obj.update.call(obj);
+ }
+ obj._draw = function() {
+ obj.draw.call(obj);
+ }
+ return obj;
+ })(Object.merge(new UI._Custom, options));
+
+ };
+
// PlayerFunctions
Player.myself = function(){
--- /dev/null
+//
+// UICustom.cpp
+//
+
+/**
+* @module global
+* @submodule UI
+ */
+
+/**
+ * @class Custom
+ * @namespace UI
+ * @extends UI.Base
+ */
+
+#include "UICustom.hpp"
+#include "../ScriptEnvironment.hpp"
+#include "../../common/Logger.hpp"
+
+UICustom::UICustom()
+{
+}
+
+UICustom::~UICustom()
+{
+}
+
+Handle<Value> UICustom::Property_processinput(Local<String> property, const AccessorInfo &info)
+{
+ assert(info.This()->InternalFieldCount() > 0);
+ auto self = std::dynamic_pointer_cast<UICustom>(
+ *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+ );
+ assert(self);
+ return self->processinput_;
+}
+
+void UICustom::Property_set_processinput(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ assert(info.This()->InternalFieldCount() > 0);
+ auto self = std::dynamic_pointer_cast<UICustom>(
+ *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+ );
+ assert(self);
+
+ self->processinput_ = Persistent<Function>::New(value.As<Function>());
+}
+
+Handle<Value> UICustom::Property_update(Local<String> property, const AccessorInfo &info)
+{
+ assert(info.This()->InternalFieldCount() > 0);
+ auto self = std::dynamic_pointer_cast<UICustom>(
+ *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+ );
+ assert(self);
+ return self->update_;
+}
+
+void UICustom::Property_set_update(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ assert(info.This()->InternalFieldCount() > 0);
+ auto self = std::dynamic_pointer_cast<UICustom>(
+ *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+ );
+ assert(self);
+
+ self->update_ = Persistent<Function>::New(value.As<Function>());
+}
+
+Handle<Value> UICustom::Property_draw(Local<String> property, const AccessorInfo &info)
+{
+ assert(info.This()->InternalFieldCount() > 0);
+ auto self = std::dynamic_pointer_cast<UICustom>(
+ *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+ );
+ assert(self);
+ return self->draw_;
+}
+
+void UICustom::Property_set_draw(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ assert(info.This()->InternalFieldCount() > 0);
+ auto self = std::dynamic_pointer_cast<UICustom>(
+ *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+ );
+ assert(self);
+
+ self->draw_ = Persistent<Function>::New(value.As<Function>());
+}
+
+void UICustom::DefineInstanceTemplate(Handle<ObjectTemplate>* object)
+{
+ UIBase::DefineInstanceTemplate(object);
+
+ SetProperty(object, "_processinput", Property_processinput, Property_set_processinput);
+ SetProperty(object, "_update", Property_update, Property_set_update);
+ SetProperty(object, "_draw", Property_draw, Property_set_draw);
+
+ SetFunction(object, "drawLine", Function_drawLine);
+}
+
+void UICustom::ProcessInput(InputManager* input)
+{
+ if (!visible_) {
+ return;
+ }
+ if (!processinput_.IsEmpty()) {
+ processinput_->Call(Context::GetCurrent()->Global(), 0, nullptr);
+ }
+}
+
+void UICustom::Update()
+{
+ if (!visible_) {
+ return;
+ }
+
+ if (!update_.IsEmpty()) {
+ update_->Call(Context::GetCurrent()->Global(), 0, nullptr);
+ }
+}
+
+void UICustom::Draw()
+{
+ if (!visible_) {
+ return;
+ }
+
+ if (!draw_.IsEmpty()) {
+ draw_->Call(Context::GetCurrent()->Global(), 0, nullptr);
+ }
+}
+
+Handle<Value> UICustom::Function_drawLine(const Arguments& args)
+{
+ assert(args.This()->InternalFieldCount() > 0);
+ auto self = std::dynamic_pointer_cast<UICustom>(
+ *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+ );
+ assert(self);
+
+ DrawLine(100, 100, 200, 200, GetColor(255,255,255));
+
+ return Undefined();
+}
+
--- /dev/null
+//
+// UICustom.hpp
+//
+
+#pragma once
+
+#include "UIBase.hpp"
+
+class UICustom : public UIBase {
+ public:
+ UICustom();
+ ~UICustom();
+ void ProcessInput(InputManager* input);
+ void Update();
+ void Draw();
+
+ public:
+ static void DefineInstanceTemplate(Handle<ObjectTemplate>* object);
+
+ private:
+ Persistent<Function> processinput_, update_, draw_;
+
+ static Handle<Value> Property_processinput(Local<String> property, const AccessorInfo &info);
+ static void Property_set_processinput(Local<String> property, Local<Value> value, const AccessorInfo& info);
+ static Handle<Value> Property_update(Local<String> property, const AccessorInfo &info);
+ static void Property_set_update(Local<String> property, Local<Value> value, const AccessorInfo& info);
+ static Handle<Value> Property_draw(Local<String> property, const AccessorInfo &info);
+ static void Property_set_draw(Local<String> property, Local<Value> value, const AccessorInfo& info);
+
+ private:
+ static Handle<Value> Function_drawLine(const Arguments& args);
+
+};
+
+typedef std::shared_ptr<UICustom> UICustomPtr;
\ No newline at end of file