Browse Source

Editor Work

Josh Engebretson 10 years ago
parent
commit
427f30090d

+ 61 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/javascript/ui/editorStrings.js

@@ -0,0 +1,61 @@
+
+
+
+exports.RevealInFinder = 0;
+exports.ShortcutUndo = 1;
+exports.ShortcutRedo = 2;
+exports.ShortcutCut = 3;
+exports.ShortcutCopy = 4;
+exports.ShortcutPaste = 5;
+exports.ShortcutSelectAll = 6;
+exports.ShortcutFind = 7;
+exports.ShortcutFindNext = 8;
+exports.ShortcutFindPrev = 9;
+exports.ShortcutBeautify = 10;
+exports.ShortcutCloseFile = 11;
+exports.ShortcutSaveFile = 12;
+exports.ShortcutPlay = 13;
+exports.ShortcutBuild = 14;
+exports.ShortcutBuildSettings = 15;
+
+exports.str = function(value) {
+
+  var string = strings[value];
+
+  if (typeof string === 'undefined') {
+      return "";
+  }
+
+  return string;
+}
+
+var strings = {};
+
+var shortcutKey = "⌘";
+
+strings[exports.RevealInFinder] = "Reveal in Finder";
+
+// Mac
+strings[exports.ShortcutRedo] ="⇧⌘Z";
+strings[exports.ShortcutFindNext] = "⌘G";
+strings[exports.ShortcutFindPrev] = "⇧⌘G";
+strings[exports.ShortcutBuildSettings] = "⇧⌘B";
+
+
+// General
+strings[exports.ShortcutUndo] = shortcutKey + "Z";
+
+strings[exports.ShortcutCut] = shortcutKey + "X";
+strings[exports.ShortcutCopy] = shortcutKey + "C";
+strings[exports.ShortcutPaste] = shortcutKey + "V";
+strings[exports.ShortcutSelectAll] = shortcutKey + "A";
+strings[exports.ShortcutFind] = shortcutKey + "F";
+
+strings[exports.ShortcutBeautify] = shortcutKey + "I";
+
+strings[exports.ShortcutSaveFile] = shortcutKey + "S";
+strings[exports.ShortcutCloseFile] = shortcutKey + "W";
+
+strings[exports.ShortcutPlay] = shortcutKey + "P";
+
+strings[exports.ShortcutBuild] = shortcutKey +"B";

+ 99 - 7
Data/AtomicEditor/Resources/EditorData/AtomicEditor/javascript/ui/mainframe.js

@@ -1,6 +1,11 @@
+var graphics = Atomic.getGraphics();
+
 var UI = Atomic.UI;
 var UI = Atomic.UI;
 var UIWidget = Atomic.UIWidget;
 var UIWidget = Atomic.UIWidget;
-var graphics = Atomic.getGraphics();
+var UIMenuWindow = Atomic.UIMenuWindow;
+
+var editorStrings = require("./editorStrings");
+var utils = require("./utils");
 
 
 var view = new Atomic.UIView();
 var view = new Atomic.UIView();
 
 
@@ -8,6 +13,8 @@ var mainframe = new UIWidget();
 
 
 mainframe.setSize(graphics.width, graphics.height);
 mainframe.setSize(graphics.width, graphics.height);
 
 
+mainframe.load("AtomicEditor/editor/ui/mainframe.tb.txt");
+
 // Subscribe to graphics subsystems screen mode switching
 // Subscribe to graphics subsystems screen mode switching
 mainframe.subscribeToEvent(graphics, "ScreenMode", function(data) {
 mainframe.subscribeToEvent(graphics, "ScreenMode", function(data) {
 
 
@@ -15,19 +22,104 @@ mainframe.subscribeToEvent(graphics, "ScreenMode", function(data) {
 
 
 });
 });
 
 
-mainframe.subscribeToEvent("WidgetLoaded", function(data) {
+mainframe.subscribeToEvent(mainframe, "WidgetEvent", function(data) {
 
 
-  print("Widget Loaded", data.widget == mainframe);
+  if (data.type == UI.EVENT_TYPE_CLICK) {
 
 
-});
+    var target = data.target;
+
+    if (target.id == "menu atomic editor") {
 
 
-mainframe.subscribeToEvent("BeginFrame", function(data) {
+      print ("CLICK! ", target.id);
 
 
-  print("Update", data.frameNumber);
+      var menu = new UIMenuWindow(target, "atomic editor popup");
+      menu.show(mainframe.menuAtomicEditorSource);
+      return true; // handled
+
+    } else if (target.id == "menu edit") {
+
+      print ("CLICK! ", target.id);
+
+      var menu = new UIMenuWindow(target, "edit popup");
+      menu.show(mainframe.menuEditSource);
+      return true; // handled
+    }
+
+  }
 
 
 });
 });
 
 
+initializeMenuSources();
+
+function initializeMenuSources() {
+
+  //var src = mainframe.menuAtomicEditorSource = new UIMenuItemSource();
+
+  var aboutItems = {
+    "About Atomic Editor": "about atomic editor",
+    "-" : null,
+    "Manage License" : "manage license",
+    "-" : null,
+    "Check for Updates" : "check update",
+    "-" : null,
+    "Quit" : "quit"
+
+  };
+
+  var editItems = {
+
+    "Undo" : ["edit undo", editorStrings.ShortcutUndo],
+    "Redo" : ["edit redo", editorStrings.ShortcutRedo],
+    "-" : null,
+    "Cut" : ["edit cut", editorStrings.ShortcutCut],
+    "Copy" : ["edit copy", editorStrings.ShortcutCopy],
+    "Paste" : ["edit paste", editorStrings.ShortcutPaste],
+    "Select All" : ["edit select all", editorStrings.ShortcutSelectAll],
+    "-" : null,
+    "Find" : ["edit find", editorStrings.ShortcutFind],
+    "Find Next" : ["edit find next", editorStrings.ShortcutFindNext],
+    "Find Prev" : ["edit find prev", editorStrings.ShortcutFindPrev],
+    "-" : null,
+    "Format Code" : ["edit format code", editorStrings.ShortcutBeautify],
+    "-" : null,
+    "Play" : ["edit play", editorStrings.ShortcutPlay]
+  };
+
+  mainframe.menuAtomicEditorSource = utils.createMenuItemSource(aboutItems);
+  mainframe.menuEditSource = utils.createMenuItemSource(editItems);
+
+
+
+
+  /*
+
+  menuFileSource.AddItem(new MenubarItem("New Project", TBIDC("new project")));
+  menuFileSource.AddItem(new MenubarItem("Open Project", TBIDC("open project")));
+  menuFileSource.AddItem(new MenubarItem("Save Project", TBIDC("save project")));
+  menuFileSource.AddItem(new MenubarItem("-"));
+  menuFileSource.AddItem(new MenubarItem("Close Project", TBIDC("close project")));
+  menuFileSource.AddItem(new MenubarItem("-"));
+  menuFileSource.AddItem(new MenubarItem("Save File", TBIDC("save file"), EDITOR_STRING(ShortcutSaveFile)));
+  menuFileSource.AddItem(new MenubarItem("Close File", TBIDC("close file"), EDITOR_STRING(ShortcutCloseFile)));
+
+  menuBuildSource.AddItem(new MenubarItem("Build", TBIDC("project_build"), EDITOR_STRING(ShortcutBuild)));
+  menuBuildSource.AddItem(new MenubarItem("-"));
+  menuBuildSource.AddItem(new MenubarItem("Build Settings", TBIDC("project_build_settings"), EDITOR_STRING(ShortcutBuildSettings)));
+
+  menuToolsSource.AddItem(new MenubarItem("Tiled Map Editor", TBIDC("tools tiled")));
+
+
+  menuHelpSource.AddItem(new MenubarItem("API Documentation", TBIDC("help_api")));
+  menuHelpSource.AddItem(new MenubarItem("-"));
+  menuHelpSource.AddItem(new MenubarItem("Forums", TBIDC("help_forums")));
+  menuHelpSource.AddItem(new MenubarItem("-"));
+  menuHelpSource.AddItem(new MenubarItem("Atomic Game Engine on GitHub", TBIDC("help_github")));
+
+  menuDeveloperSource.AddItem(new MenubarItem("Set 1920x1080 Resolution", TBIDC("developer_resolution")));
+  */
+
+
+}
 
 
-mainframe.load("AtomicEditor/editor/ui/mainframe.tb.txt");
 
 
 view.addChild(mainframe);
 view.addChild(mainframe);

+ 37 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/javascript/ui/utils.js

@@ -0,0 +1,37 @@
+
+var editorStrings = require("./editorStrings");
+
+var UIMenuItemSource = Atomic.UIMenuItemSource;
+var UIMenuItem = Atomic.UIMenuItem;
+
+exports.createMenuItemSource = function(items) {
+
+  var src = new UIMenuItemSource();
+
+  for (var key in items) {
+    if (items.hasOwnProperty(key)) {
+
+      var value = items[key];
+
+      if (typeof value === 'string') {
+
+        src.addItem(new UIMenuItem(key, value));
+
+      } else if (value == null) {
+
+        src.addItem(new UIMenuItem(key));
+
+      } else if (typeof value === 'object' && value.length == 2) {
+
+        src.addItem(new UIMenuItem(key, value[0], editorStrings.str(value[1])));
+
+      }
+
+
+    }
+
+  }
+
+  return src;
+
+}

+ 2 - 2
Source/Atomic/UI/UIEvents.h

@@ -40,7 +40,7 @@ EVENT(E_WIDGETEVENT, WidgetEvent)
     PARAM(P_KEY, Key);                   // int
     PARAM(P_KEY, Key);                   // int
     PARAM(P_SPECIALKEY, SpecialKey);     // enum SPECIAL_KEY
     PARAM(P_SPECIALKEY, SpecialKey);     // enum SPECIAL_KEY
     PARAM(P_MODIFIERKEYS, ModifierKeys); // enum MODIFIER_KEYS
     PARAM(P_MODIFIERKEYS, ModifierKeys); // enum MODIFIER_KEYS
-    PARAM(P_REFID, RefID);                     // unsigned (TBID)
+    PARAM(P_REFID, RefID);               // string (TBID)
     PARAM(P_TOUCH, Touch);               // bool
     PARAM(P_TOUCH, Touch);               // bool
 
 
     // EventHandled can be set by event receivers to stop event bubble
     // EventHandled can be set by event receivers to stop event bubble
@@ -61,7 +61,7 @@ EVENT(E_WIDGETDELETED, WidgetDeleted)
 EVENT(E_POPUPMENUSELECT, PopupMenuSelect)
 EVENT(E_POPUPMENUSELECT, PopupMenuSelect)
 {
 {
     PARAM(P_BUTTON, Button);             // UIButton that created popup
     PARAM(P_BUTTON, Button);             // UIButton that created popup
-    PARAM(P_REFID, RefID);             // unsigned tbid
+    PARAM(P_REFID, RefID);             // string tbid
 }
 }
 
 
 
 

+ 1 - 1
Source/Atomic/UI/UIMenuWindow.h

@@ -26,7 +26,7 @@ protected:
 
 
 private:
 private:
 
 
-    tb::TBGenericStringItemSource* source_;
+    tb::TBSelectItemSource* source_;
 
 
 };
 };
 
 

+ 214 - 0
Source/Atomic/UI/UIMenubar.cpp

@@ -0,0 +1,214 @@
+
+#include <TurboBadger/tb_menu_window.h>
+#include <TurboBadger/tb_select.h>
+
+#include "UIMenubar.h"
+
+using namespace tb;
+
+namespace tb {
+
+
+// THIS MUST MATCH TBSimpleLayoutItemWidget in tb_select_item.cpp
+class TBSimpleLayoutItemWidget : public TBLayout, private TBWidgetListener
+{
+public:
+    TBSimpleLayoutItemWidget(TBID image, TBSelectItemSource *source, const char *str);
+    ~TBSimpleLayoutItemWidget();
+    virtual bool OnEvent(const TBWidgetEvent &ev);
+private:
+    TBSelectItemSource *m_source;
+    TBTextField m_textfield;
+    TBSkinImage m_image;
+    TBSkinImage m_image_arrow;
+    TBMenuWindow *m_menu; ///< Points to the submenu window if opened
+    virtual void OnWidgetDelete(TBWidget *widget);
+    void OpenSubMenu();
+    void CloseSubMenu();
+};
+
+}
+
+namespace Atomic
+{
+
+
+class MenubarItem : public TBGenericStringItem
+{
+public:
+    MenubarItem(const char *str, const TBID &id = TBID((uint32)0), const String& shortcut = String::EMPTY)
+        : TBGenericStringItem(str, id), shortcut_(shortcut)
+    {
+
+    }
+
+    MenubarItem(const char *str, TBSelectItemSource *sub_source) : TBGenericStringItem(str, sub_source) {}
+
+    String shortcut_;
+
+};
+
+class MenubarItemSource : public TBSelectItemSourceList<MenubarItem>
+{
+public:
+    virtual bool Filter(int index, const char *filter);
+    virtual TBWidget *CreateItemWidget(int index, TBSelectItemViewer *viewer);
+};
+
+class MenubarItemWidget : public TBLayout
+{
+public:
+    MenubarItemWidget(MenubarItem *item, MenubarItemSource *source, TBSelectItemViewer *source_viewer, int index);
+    virtual bool OnEvent(const TBWidgetEvent &ev);
+private:
+    MenubarItemSource *m_source;
+    TBSelectItemViewer *m_source_viewer;
+    int m_index;
+};
+
+// UI IMPLEMENTATION
+
+UIMenuItem::UIMenuItem(Context* context, const String& str, const String& id, const String& shortcut):
+    UISelectItem(context, str, id),
+    shortcut_(shortcut)
+{
+
+}
+
+UIMenuItem::~UIMenuItem()
+{
+
+}
+
+tb::TBGenericStringItem* UIMenuItem::GetTBItem()
+{
+    MenubarItem* item;
+
+    if (!subSource_)
+    {
+         item = new MenubarItem(str_.CString(), id_, shortcut_);
+    }
+    else
+    {
+        item = new MenubarItem(str_.CString(), subSource_->GetTBItemSource());
+    }
+
+    return item;
+
+}
+
+tb::TBSelectItemSource* UIMenuItemSource::GetTBItemSource()
+{
+    // caller's responsibility to clean up
+    MenubarItemSource* src = new MenubarItemSource();
+
+    for (List<SharedPtr<UISelectItem> >::Iterator itr = items_.Begin(); itr != items_.End(); itr++)
+    {
+        MenubarItem* tbitem = (MenubarItem*) (*itr)->GetTBItem();
+        src->AddItem(tbitem);
+    }
+
+    return src;
+}
+
+UIMenuItemSource::UIMenuItemSource(Context* context) : UISelectItemSource(context)
+{
+
+}
+
+UIMenuItemSource::~UIMenuItemSource()
+{
+
+}
+
+// WIDGET IMPLEMENTATION
+
+MenubarItemWidget::MenubarItemWidget(MenubarItem *item, MenubarItemSource *source,
+                                     TBSelectItemViewer *source_viewer, int index)
+    : m_source(source)
+    , m_source_viewer(source_viewer)
+    , m_index(index)
+{
+    SetSkinBg(TBIDC("TBSelectItem"));
+    SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
+    SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
+    SetPaintOverflowFadeout(false);
+
+    TBWidget* root = GetContentRoot();
+
+    TBFontDescription fd;
+    fd.SetID(TBIDC("Vera"));
+    fd.SetSize(12);
+
+    TBTextField* text = new TBTextField();
+    text->SetIgnoreInput(true);
+    text->SetText(item->str);
+    text->SetFontDescription(fd);
+    root->AddChild(text);
+
+    if (item->shortcut_.Length())
+    {
+        TBWidget* spacer = new TBWidget();
+        spacer->SetIgnoreInput(true);
+        spacer->SetGravity(WIDGET_GRAVITY_LEFT_RIGHT);
+        root->AddChild(spacer);
+
+        TBTextField* shortcut = new TBTextField();
+        shortcut->SetIgnoreInput(true);
+        shortcut->SetText(item->shortcut_.CString());
+        shortcut->SetFontDescription(fd);
+        shortcut->SetGravity(WIDGET_GRAVITY_RIGHT);
+        root->AddChild(shortcut);
+    }
+
+}
+
+bool MenubarItemWidget::OnEvent(const TBWidgetEvent &ev)
+{
+    if (m_source && ev.type == EVENT_TYPE_CLICK && ev.target == this)
+    {
+        return false;
+    }
+
+    return false;
+}
+
+bool MenubarItemSource::Filter(int index, const char *filter)
+{
+    return true;
+}
+
+TBWidget *MenubarItemSource::CreateItemWidget(int index, TBSelectItemViewer *viewer)
+{
+    const char *string = GetItemString(index);
+
+    TBSelectItemSource *sub_source = GetItemSubSource(index);
+    TBID image = GetItemImage(index);
+
+    if (sub_source || image)
+    {
+        if (TBSimpleLayoutItemWidget *itemwidget = new TBSimpleLayoutItemWidget(image, sub_source, string))
+        {
+            itemwidget->SetID(GetItem(index)->id);
+            return itemwidget;
+        }
+    }
+    else if (string && *string == '-')
+    {
+        if (TBSeparator *separator = new TBSeparator)
+        {
+            separator->SetGravity(WIDGET_GRAVITY_ALL);
+            separator->SetSkinBg(TBIDC("AESeparator"));
+            return separator;
+        }
+    }
+    else if (TBLayout *layout = new MenubarItemWidget(GetItem(index), this, viewer, index))
+    {
+        layout->SetID(GetItem(index)->id);
+        return layout;
+    }
+
+    return NULL;
+}
+
+}

+ 44 - 0
Source/Atomic/UI/UIMenubar.h

@@ -0,0 +1,44 @@
+
+#pragma once
+
+#include "UISelectItem.h"
+
+namespace Atomic
+{
+
+class UIMenuItemSource;
+
+class UIMenuItem : public UISelectItem
+{
+    OBJECT(UIMenuItem)
+
+public:
+
+    UIMenuItem(Context* context, const String& str = String::EMPTY, const String& id = String::EMPTY, const String& shortcut = String::EMPTY);
+    virtual ~UIMenuItem();
+
+    tb::TBGenericStringItem* GetTBItem();
+
+private:
+
+    String shortcut_;
+
+};
+
+class UIMenuItemSource : public UISelectItemSource
+{
+    OBJECT(UIMenuItemSource)
+
+public:
+
+    UIMenuItemSource(Context* context);
+    virtual ~UIMenuItemSource();
+
+    // caller's responsibility to clean up
+    tb::TBSelectItemSource *GetTBItemSource();
+
+private:
+
+};
+
+}

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

@@ -63,7 +63,7 @@ UISelectItemSource::~UISelectItemSource()
 
 
 }
 }
 
 
-tb::TBGenericStringItemSource* UISelectItemSource::GetTBItemSource()
+TBSelectItemSource *UISelectItemSource::GetTBItemSource()
 {
 {
     // caller's responsibility to clean up
     // caller's responsibility to clean up
     TBGenericStringItemSource* src = new TBGenericStringItemSource();
     TBGenericStringItemSource* src = new TBGenericStringItemSource();

+ 4 - 4
Source/Atomic/UI/UISelectItem.h

@@ -26,9 +26,9 @@ public:
     void SetSkinImage(const String& skinImage);
     void SetSkinImage(const String& skinImage);
     void SetSubSource(UISelectItemSource *subSource);
     void SetSubSource(UISelectItemSource *subSource);
 
 
-    tb::TBGenericStringItem* GetTBItem();
+    virtual tb::TBGenericStringItem* GetTBItem();
 
 
-private:
+protected:
 
 
     String str_;
     String str_;
 
 
@@ -53,9 +53,9 @@ public:
     void AddItem(UISelectItem* item) { items_.Push(SharedPtr<UISelectItem>(item)); }
     void AddItem(UISelectItem* item) { items_.Push(SharedPtr<UISelectItem>(item)); }
 
 
     // caller's responsibility to clean up
     // caller's responsibility to clean up
-    tb::TBGenericStringItemSource* GetTBItemSource();
+    virtual tb::TBSelectItemSource* GetTBItemSource();
 
 
-private:
+protected:
 
 
     List<SharedPtr<UISelectItem>> items_;
     List<SharedPtr<UISelectItem>> items_;
 
 

+ 9 - 2
Source/Atomic/UI/UIWidget.cpp

@@ -68,6 +68,11 @@ void UIWidget::SetWidget(tb::TBWidget* widget)
 
 
 void UIWidget::ConvertEvent(UIWidget *handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data)
 void UIWidget::ConvertEvent(UIWidget *handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data)
 {
 {
+    UI* ui = GetSubsystem<UI>();
+    String id;
+
+    ui->GetTBIDString(ev.ref_id, id);
+
     using namespace WidgetEvent;
     using namespace WidgetEvent;
     data[P_HANDLER] = handler;
     data[P_HANDLER] = handler;
     data[P_TARGET] = target;
     data[P_TARGET] = target;
@@ -80,7 +85,7 @@ void UIWidget::ConvertEvent(UIWidget *handler, UIWidget* target, const tb::TBWid
     data[P_KEY] = ev.key;
     data[P_KEY] = ev.key;
     data[P_SPECIALKEY] = (unsigned) ev.special_key;
     data[P_SPECIALKEY] = (unsigned) ev.special_key;
     data[P_MODIFIERKEYS] = (unsigned) ev.modifierkeys;
     data[P_MODIFIERKEYS] = (unsigned) ev.modifierkeys;
-    data[P_REFID] = (unsigned) ev.ref_id;
+    data[P_REFID] = id;
     data[P_TOUCH] = (unsigned) ev.touch;
     data[P_TOUCH] = (unsigned) ev.touch;
 }
 }
 
 
@@ -366,7 +371,9 @@ bool UIWidget::OnEvent(const tb::TBWidgetEvent &ev)
             {
             {
                 VariantMap eventData;
                 VariantMap eventData;
                 eventData[PopupMenuSelect::P_BUTTON] = this;
                 eventData[PopupMenuSelect::P_BUTTON] = this;
-                eventData[PopupMenuSelect::P_REFID] = (unsigned) ev.ref_id;
+                String id;
+                ui->GetTBIDString(ev.ref_id, id);
+                eventData[PopupMenuSelect::P_REFID] = id;
                 SendEvent(E_POPUPMENUSELECT, eventData);
                 SendEvent(E_POPUPMENUSELECT, eventData);
             }
             }
 
 

+ 0 - 3
Source/AtomicEditor/Source/UI/UIMenubar.h

@@ -14,9 +14,6 @@ using namespace Atomic;
 namespace AtomicEditor
 namespace AtomicEditor
 {
 {
 
 
-class ListViewItemSource;
-class ListViewItemWidget;
-
 class MenubarItem : public TBGenericStringItem
 class MenubarItem : public TBGenericStringItem
 {
 {
 public:
 public:

+ 1 - 1
Source/AtomicJS/JSBind/modules/UI.json

@@ -4,7 +4,7 @@
 	"includes" : ["<Atomic/Graphics/Material.h>", "<Atomic/Scene/Node.h>", "<Atomic/Scene/Scene.h>", "<Atomic/Graphics/Texture2D.h>"],
 	"includes" : ["<Atomic/Graphics/Material.h>", "<Atomic/Scene/Node.h>", "<Atomic/Scene/Scene.h>", "<Atomic/Graphics/Texture2D.h>"],
 	"classes" : ["UIWidget", "UILayout", "UIView", "UIWindow", "UIButton", "UITextField",
 	"classes" : ["UIWidget", "UILayout", "UIView", "UIWindow", "UIButton", "UITextField",
 								"UISelectItem", "UISelectItemSource", "UIMenuWindow", "UIEditField",
 								"UISelectItem", "UISelectItemSource", "UIMenuWindow", "UIEditField",
-								"UIImageWidget", "UIClickLabel", "UICheckBox"],
+								"UIImageWidget", "UIClickLabel", "UICheckBox", "UIMenuItem", "UIMenuItemSource"],
 	"overloads" : {
 	"overloads" : {
 	}
 	}
 }
 }

+ 2 - 2
Source/AtomicJS/Javascript/JSCore.cpp

@@ -68,7 +68,7 @@ static int Object_SubscribeToEvent(duk_context* ctx)
         duk_throw(ctx);
         duk_throw(ctx);
     }
     }
 
 
-    duk_push_this(ctx); // stack 2
+    duk_push_this(ctx);
 
 
     // event receiver
     // event receiver
     Object* object = js_to_class_instance<Object>(ctx, -1, 0);
     Object* object = js_to_class_instance<Object>(ctx, -1, 0);
@@ -101,7 +101,7 @@ static int Object_SubscribeToEvent(duk_context* ctx)
         // dup so when we set the helper is left on stack
         // dup so when we set the helper is left on stack
         duk_dup_top(ctx);
         duk_dup_top(ctx);
 
 
-        duk_put_prop_string(ctx, 2, "__eventHelper");
+        duk_put_prop_string(ctx, -3, "__eventHelper");
     }
     }
 
 
     JSEventHelper* helper = js_to_class_instance<JSEventHelper>(ctx, -1, 0);
     JSEventHelper* helper = js_to_class_instance<JSEventHelper>(ctx, -1, 0);

+ 19 - 1
Source/AtomicJS/Javascript/JSEventHelper.cpp

@@ -1,4 +1,6 @@
 
 
+#include <Atomic/UI/UIEvents.h>
+
 #include "JSVM.h"
 #include "JSVM.h"
 #include "JSEventHelper.h"
 #include "JSEventHelper.h"
 
 
@@ -13,7 +15,7 @@ JSEventHelper::JSEventHelper(Context* context) :
 
 
 JSEventHelper::~JSEventHelper()
 JSEventHelper::~JSEventHelper()
 {
 {
-
+    LOGINFO("Boom");
 }
 }
 
 
 void JSEventHelper::AddEventHandler(StringHash eventType)
 void JSEventHelper::AddEventHandler(StringHash eventType)
@@ -44,6 +46,7 @@ void JSEventHelper::HandleEvent(StringHash eventType, VariantMap& eventData)
     if (duk_is_function(ctx, -1))
     if (duk_is_function(ctx, -1))
     {
     {
         currentData_ = (const VariantMap&) eventData;
         currentData_ = (const VariantMap&) eventData;
+
         // pass in event helper proxy
         // pass in event helper proxy
         duk_get_prop_string(ctx, -3, "__eventHelperProxy");
         duk_get_prop_string(ctx, -3, "__eventHelperProxy");
         assert(duk_is_object(ctx, -1));
         assert(duk_is_object(ctx, -1));
@@ -52,6 +55,21 @@ void JSEventHelper::HandleEvent(StringHash eventType, VariantMap& eventData)
         {
         {
             vm->SendJSErrorEvent();
             vm->SendJSErrorEvent();
         }
         }
+        else
+        {
+            // For widget events, need to check return value
+            // and set whether handled
+            if (eventType == E_WIDGETEVENT)
+            {
+                if (duk_is_boolean(ctx, -1))
+                {
+                    if (duk_to_boolean(ctx, -1))
+                    {
+                        eventData[WidgetEvent::P_HANDLED] = true;
+                    }
+                }
+            }
+        }
     }
     }
 
 
     duk_set_top(ctx, top);
     duk_set_top(ctx, top);

+ 4 - 7
Source/AtomicJS/Javascript/JSUI.cpp

@@ -193,9 +193,8 @@ void JSUI::HandlePopupMenuSelect(StringHash eventType, VariantMap& eventData)
         return;
         return;
     }
     }
 
 
-    UI* ui = GetSubsystem<UI>();
     String id;
     String id;
-    ui->GetTBIDString(eventData[P_REFID].GetUInt(), id);
+    id = eventData[P_REFID].GetString();
 
 
     duk_push_string(ctx_, id.CString());
     duk_push_string(ctx_, id.CString());
     duk_insert(ctx_, -1);
     duk_insert(ctx_, -1);
@@ -214,8 +213,6 @@ void JSUI::HandlePopupMenuSelect(StringHash eventType, VariantMap& eventData)
 void JSUI::PushWidgetEventObject(VariantMap& eventData)
 void JSUI::PushWidgetEventObject(VariantMap& eventData)
 {
 {
 
 
-    UI* ui = GetSubsystem<UI>();
-
     using namespace WidgetEvent;
     using namespace WidgetEvent;
 
 
     // create the event object
     // create the event object
@@ -266,9 +263,7 @@ void JSUI::PushWidgetEventObject(VariantMap& eventData)
     duk_push_number(ctx_, (duk_double_t) eventData[P_MODIFIERKEYS].GetInt());
     duk_push_number(ctx_, (duk_double_t) eventData[P_MODIFIERKEYS].GetInt());
     duk_put_prop_string(ctx_, -2, "modifierKeys");
     duk_put_prop_string(ctx_, -2, "modifierKeys");
 
 
-    String id;
-    unsigned blah = eventData[P_REFID].GetUInt();
-    ui->GetTBIDString(eventData[P_REFID].GetUInt(), id);
+    String id = eventData[P_REFID].GetString();
     duk_push_string(ctx_, id.CString() );
     duk_push_string(ctx_, id.CString() );
     duk_put_prop_string(ctx_, -2, "refID");
     duk_put_prop_string(ctx_, -2, "refID");
 
 
@@ -281,6 +276,8 @@ void JSUI::HandleWidgetEvent(StringHash eventType, VariantMap& eventData)
 {
 {
     using namespace WidgetEvent;
     using namespace WidgetEvent;
 
 
+    return;
+
     UIWidget* handler = static_cast<UIWidget*>(eventData[P_HANDLER].GetPtr());
     UIWidget* handler = static_cast<UIWidget*>(eventData[P_HANDLER].GetPtr());
     UIWidget* target = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
     UIWidget* target = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
 
 

+ 34 - 0
Source/AtomicJS/Javascript/JSUIAPI.cpp

@@ -269,6 +269,40 @@ void jsapi_init_ui(JSVM* vm)
     duk_push_number(ctx, (double) tb::WIDGET_STATE_ALL);
     duk_push_number(ctx, (double) tb::WIDGET_STATE_ALL);
     duk_put_prop_string(ctx, -2, "WIDGET_STATE_ALL");
     duk_put_prop_string(ctx, -2, "WIDGET_STATE_ALL");
 
 
+    // Events
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_CLICK);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_CLICK");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_LONG_CLICK);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_LONG_CLICK");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_POINTER_DOWN);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_POINTER_DOWN");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_POINTER_UP);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_POINTER_UP");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_POINTER_MOVE);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_POINTER_MOVE");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_RIGHT_POINTER_DOWN);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_RIGHT_POINTER_DOWN");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_RIGHT_POINTER_UP);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_RIGHT_POINTER_UP");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_WHEEL);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_WHEEL");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_CHANGED);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_CHANGED");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_KEY_DOWN);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_KEY_DOWN");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_KEY_UP);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_KEY_UP");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_SHORTCUT);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_SHORTCUT");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_CONTEXT_MENU);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_CONTEXT_MENU");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_FILE_DROP);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_FILE_DROP");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_TAB_CHANGED);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_TAB_CHANGED");
+    duk_push_number(ctx, (double) tb::EVENT_TYPE_CUSTOM);
+    duk_put_prop_string(ctx, -2, "EVENT_TYPE_CUSTOM");
+
     duk_put_prop_string(ctx, -2, "UI");
     duk_put_prop_string(ctx, -2, "UI");
 
 
     duk_pop(ctx);
     duk_pop(ctx);