Browse Source

Various updates

Josh Engebretson 11 years ago
parent
commit
70839597e7

+ 15 - 0
Bin/CoreData/AtomicModules/AtomicGame.js

@@ -8,6 +8,7 @@ function Game() {
 	this.renderer = Atomic.GetRenderer();
 	this.graphics = Atomic.GetGraphics();
 	this.input = Atomic.GetInput();
+    this.ui = Atomic.GetUI();
 
     if (Atomic.platform == "Android") {
         this.renderer.reuseShadowMaps = false;
@@ -74,6 +75,12 @@ Game.prototype.createScene2D = function() {
     if (Atomic.editor) {
         var _viewport = Atomic.editor.viewport;
         viewport.rect = [_viewport.left, _viewport.top, _viewport.right, _viewport.bottom];
+
+        var width = (_viewport.right - 8) - _viewport.left;
+        var height = _viewport.bottom - _viewport.top;
+
+        this.ui.getRoot().setPosition(_viewport.left, _viewport.top);
+        this.ui.getRoot().setSize(width, height);        
     }
 
     this.renderer.setViewport(0, viewport);
@@ -100,8 +107,16 @@ Game.prototype.createScene3D = function() {
     var viewport = new Atomic.Viewport(scene, camera);
 
     if (Atomic.editor) {
+
         var _viewport = Atomic.editor.viewport;
         viewport.rect = [_viewport.left, _viewport.top, _viewport.right - 8, _viewport.bottom];
+
+        var width = (_viewport.right - 8) - _viewport.left;
+        var height = _viewport.bottom - _viewport.top;
+
+        this.ui.getRoot().setPosition(_viewport.left + width/2, _viewport.top + height/2);
+        this.ui.getRoot().setSize(width, height);        
+
     }
 
     this.renderer.setViewport(0, viewport);

+ 10 - 0
Source/Atomic/Javascript/JSAtomic.cpp

@@ -110,6 +110,13 @@ static int js_atomic_GetGraphics(duk_context* ctx)
     return 1;
 }
 
+static int js_atomic_GetUI(duk_context* ctx)
+{
+    JSVM* vm = JSVM::GetJSVM(ctx);
+    js_push_class_object_instance(ctx, vm->GetSubsystem<UI>());
+    return 1;
+}
+
 static int js_atomic_GetInput(duk_context* ctx)
 {
     JSVM* vm = JSVM::GetJSVM(ctx);
@@ -239,6 +246,9 @@ void jsapi_init_atomic(JSVM* vm)
     duk_push_c_function(ctx, js_atomic_GetInput, 0);
     duk_put_prop_string(ctx, -2, "GetInput");
 
+    duk_push_c_function(ctx, js_atomic_GetUI, 0);
+    duk_put_prop_string(ctx, -2, "GetUI");
+
     duk_push_c_function(ctx, js_atomic_destroy, 1);
     duk_put_prop_string(ctx, -2, "destroy");
 

+ 24 - 13
Source/Atomic/Javascript/JSComponent.cpp

@@ -24,6 +24,9 @@
 #include "../Javascript/JSComponent.h"
 #include "../Javascript/JSAPI.h"
 
+#include "../UI/UIEvents.h"
+#include "../UI/UIElement.h"
+
 namespace Atomic
 {
 
@@ -436,7 +439,27 @@ void JSComponent::HandleScriptEvent(StringHash eventType, VariantMap& eventData)
         duk_context* ctx = vm_->GetJSContext();
         JS_HEAP_PTR function = scriptEventFunctions_[eventType];
 
-        if (eventType == E_PHYSICSBEGINCONTACT2D || E_PHYSICSENDCONTACT2D)
+        if (eventType == E_UIMOUSECLICK)
+        {
+            UIElement* clicked = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr());
+            if (clicked)
+            {
+                duk_push_heapptr(ctx, function);
+                js_push_class_object_instance(ctx, clicked);
+
+                if (duk_pcall(ctx, 1) != 0)
+                {
+                    vm_->SendJSErrorEvent();
+                }
+
+                duk_pop(ctx);
+
+            }
+
+
+        }
+
+        else if (eventType == E_PHYSICSBEGINCONTACT2D || E_PHYSICSENDCONTACT2D)
         {
             using namespace PhysicsBeginContact2D;
             PhysicsWorld2D* world = static_cast<PhysicsWorld2D*>(eventData[P_WORLD].GetPtr());
@@ -499,18 +522,6 @@ void JSComponent::HandleScriptEvent(StringHash eventType, VariantMap& eventData)
         }
     }
 
-    /*
-    asIScriptFunction* method = static_cast<asIScriptFunction*>(GetEventHandler()->GetUserData());
-
-    VariantVector parameters;
-    if (method->GetParamCount() > 0)
-    {
-        parameters.Push(Variant((void*)&eventType));
-        parameters.Push(Variant((void*)&eventData));
-    }
-
-    scriptFile_->Execute(scriptObject_, method, parameters);
-    */
 }
 
 

+ 2 - 2
Source/Atomic/Javascript/JSVM.cpp

@@ -398,7 +398,7 @@ void JSVM::SendJSErrorEvent()
 
 }
 
-bool JSVM::ExecuteMain()
+bool JSVM::ExecuteMain(const String &mainPath)
 {
     SharedPtr<JSFile> jsFile;
     jsFile = GetSubsystem<ResourceCache>()->GetResource<JSFile>("Scripts/main.js");
@@ -418,7 +418,7 @@ bool JSVM::ExecuteMain()
 
     source += "}\n return __main_function;\n});";
 
-    duk_push_string(jsContext_, "Main.js");
+    duk_push_string(jsContext_, mainPath.CString());
 
     if (duk_eval_raw(jsContext_, source.CString(), source.Length(),
                      DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE) != 0)

+ 1 - 1
Source/Atomic/Javascript/JSVM.h

@@ -25,7 +25,7 @@ public:
     /// Destruct.
     virtual ~JSVM();
 
-    bool ExecuteMain();
+    bool ExecuteMain(const String& mainPath);
 
     bool ExecuteFile(JSFile* jsfile);
 

+ 2 - 1
Source/Atomic/UI/UI.cpp

@@ -401,7 +401,8 @@ void UI::RenderUpdate()
     batches_.Clear();
     vertexData_.Clear();
     const IntVector2& rootSize = rootElement_->GetSize();
-    IntRect currentScissor = IntRect(0, 0, rootSize.x_, rootSize.y_);
+    const IntVector2& rootPosition = rootElement_->GetPosition();
+    IntRect currentScissor = IntRect(rootPosition.x_, rootPosition.y_, rootPosition.x_ + rootSize.x_, rootPosition.y_ + rootSize.y_);
     GetBatches(rootElement_, currentScissor);
 
     // Save the batch size of the non-modal batches for later use

+ 7 - 0
Source/ThirdParty/TurboBadger/tb_style_edit.cpp

@@ -1834,6 +1834,10 @@ bool TBStyleEdit::KeyDown(int key, SPECIAL_KEY special_key, MODIFIER_KEYS modifi
                 if (block == selection.stop.block)
                     break;
             }
+
+            if (text_change_listener)
+                text_change_listener->OnChange(this);
+
         }
     }
     else if (!packed.read_only && (modifierkeys & TB_SHIFT) && (special_key == TB_KEY_TAB && packed.multiline_on))
@@ -1896,6 +1900,9 @@ bool TBStyleEdit::KeyDown(int key, SPECIAL_KEY special_key, MODIFIER_KEYS modifi
                 if (block == selection.stop.block)
                     break;
             }
+            if (text_change_listener)
+                text_change_listener->OnChange(this);
+
         }
     }
     else if (!packed.read_only && (special_key == TB_KEY_ENTER && packed.multiline_on) && !(ctrlOrSuper))