Browse Source

Initial DragAndDrop support for Atomic Editor (OS X)

Josh Engebretson 10 years ago
parent
commit
bf4dc7d241

+ 22 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/assets/AssetImport.ts

@@ -0,0 +1,22 @@
+
+class AssetImport extends Atomic.ScriptObject {
+
+  constructor() {
+
+    super();
+
+    this.subscribeToEvent("DragAndDrop", (data) => this.handleDropFile(data));
+
+  }
+
+  handleDropFile(data):void {
+
+    print("Dropped: ", data.fileName);
+
+  }
+
+
+}
+
+
+export = AssetImport;

+ 4 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/editor/Editor.ts

@@ -1,12 +1,14 @@
 
 import MainFrame = require("../ui/MainFrame");
 import UIEvents = require("../ui/UIEvents");
+import AssetImport = require("../assets/AssetImport");
 
 class Editor extends Atomic.ScriptObject {
 
     project: ToolCore.Project;
     view: Atomic.UIView;
     mainframe: MainFrame;
+    assetImport: AssetImport;
 
     static instance: Editor;
 
@@ -53,6 +55,8 @@ class Editor extends Atomic.ScriptObject {
 
         Editor.instance = this;
 
+        this.assetImport = new AssetImport();
+
         var graphics = Atomic.getGraphics();
 
         this.view = new Atomic.UIView();

+ 1 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/tsconfig.json

@@ -12,6 +12,7 @@
     ],
     "files": [
         "./AtomicWork.d.ts",
+        "./assets/AssetImport.ts",
         "./editor/Editor.ts",
         "./main.ts",
         "./ui/EditorStrings.ts",

+ 5 - 0
Source/Atomic/Graphics/OpenGL/OGLGraphics.cpp

@@ -327,6 +327,11 @@ void Graphics::RaiseWindow()
         SDL_RaiseWindow(impl_->window_);
 }
 
+void* Graphics::GetSDLWindow()
+{
+    return impl_->window_;
+}
+
 bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample)
 {
     PROFILE(SetScreenMode);

+ 2 - 0
Source/Atomic/Graphics/OpenGL/OGLGraphics.h

@@ -100,6 +100,8 @@ public:
     void CenterWindow();
     /// Bring the window to front with focus
     void RaiseWindow();
+    /// Get the SDL_Window as a void* to avoid having to include the graphics implementation
+    void* GetSDLWindow();
     /// Set screen mode. Return true if successful.
     bool SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample);
     /// Set screen resolution only. Return true if successful.

+ 43 - 0
Source/AtomicEditorWork/Application/AEDragAndDrop.cpp

@@ -0,0 +1,43 @@
+
+#include <Atomic/Graphics/Graphics.h>
+
+#include "AEDragAndDrop.h"
+
+#ifdef ATOMIC_PLATFORM_OSX
+#include "AEMacDragAndDrop.h"
+#endif
+
+namespace AtomicEditor
+{
+
+AEDragAndDrop::AEDragAndDrop(Context *context) : Object(context)
+{
+#ifdef ATOMIC_PLATFORM_OSX
+    InitDragAndDrop(this);
+#endif
+
+}
+
+void AEDragAndDrop::BeginDrag()
+{
+    dragFilenames_.Clear();
+}
+
+void AEDragAndDrop::AddDragFilename(const String& filename)
+{
+    dragFilenames_.Push(filename);
+}
+
+void AEDragAndDrop::ConcludeDrag()
+{
+    for (unsigned i = 0; i < dragFilenames_.Size(); i++)
+    {
+        VariantMap eventData;
+        eventData[DragAndDrop::P_FILENAME] = dragFilenames_[i];
+        SendEvent(E_DRAGANDDROP, eventData);
+    }
+
+    dragFilenames_.Clear();
+}
+
+}

+ 36 - 0
Source/AtomicEditorWork/Application/AEDragAndDrop.h

@@ -0,0 +1,36 @@
+
+#pragma once
+
+#include <Atomic/Core/Object.h>
+
+using namespace Atomic;
+
+namespace AtomicEditor
+{
+
+/// A file was drag-dropped into the application window.
+EVENT(E_DRAGANDDROP, DragAndDrop)
+{
+    PARAM(P_FILENAME, FileName);            // String
+}
+
+class AEDragAndDrop : public Object
+{
+
+    OBJECT(AEDragAndDrop);
+
+public:
+    /// Construct.
+    AEDragAndDrop(Context* context);
+
+    void BeginDrag();
+    void AddDragFilename(const String& filename);
+    void ConcludeDrag();
+
+private:
+
+    Vector<String> dragFilenames_;
+
+};
+
+}

+ 4 - 1
Source/AtomicEditorWork/Application/AEEditorApp.cpp

@@ -7,6 +7,7 @@
 #include <Atomic/IO/FileSystem.h>
 #include <Atomic/Input/Input.h>
 #include <Atomic/Resource/ResourceCache.h>
+#include <Atomic/Graphics/Graphics.h>
 
 #include <Atomic/UI/UI.h>
 
@@ -15,6 +16,7 @@
 #include <ToolCore/ToolSystem.h>
 #include <ToolCore/ToolEnvironment.h>
 
+#include "AEDragAndDrop.h"
 #include "AEEditorApp.h"
 
 // Move me
@@ -40,6 +42,8 @@ AEEditorApp::AEEditorApp(Context* context) :
 
 void AEEditorApp::Start()
 {
+    context_->RegisterSubsystem(new AEDragAndDrop(context_));
+
     Input* input = GetSubsystem<Input>();
     input->SetMouseVisible(true);
 
@@ -90,7 +94,6 @@ void AEEditorApp::Setup()
     ToolSystem* system = new ToolSystem(context_);
     context_->RegisterSubsystem(system);
 
-
 #ifdef ATOMIC_DEV_BUILD
 
     if (!env->InitFromJSON())

+ 11 - 0
Source/AtomicEditorWork/Application/AEMacDragAndDrop.h

@@ -0,0 +1,11 @@
+#pragma once
+
+namespace AtomicEditor
+{
+
+class AEDragAndDrop;
+void InitDragAndDrop(AEDragAndDrop* dragAndDrop);
+
+}
+
+

+ 93 - 0
Source/AtomicEditorWork/Application/AEMacDragAndDrop.mm

@@ -0,0 +1,93 @@
+
+#include <stdio.h>
+
+#include <ThirdParty/SDL/include/SDL.h>
+#include <ThirdParty/SDL/include/SDL_syswm.h>
+
+#include <Atomic/Graphics/Graphics.h>
+
+#include "AEDragAndDrop.h"
+
+static WeakPtr<AtomicEditor::AEDragAndDrop> dragAndDrop_;
+
+@interface NSWindow (NSWindowWithDragAndDrop)
+
+    -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
+    -(NSDragOperation)draggingUpdated:(id)sender;
+    -(BOOL)prepareForDragOperation:(id)sender;
+    -(BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
+    -(void)concludeDragOperation:(id <NSDraggingInfo>)sender;
+
+@end
+
+@implementation NSWindow (NSWindowWithDragAndDrop)
+
+-(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
+{
+    dragAndDrop_->BeginDrag();
+    return NSDragOperationGeneric;
+}
+
+-(NSDragOperation)draggingUpdated:(id)sender
+{
+    return NSDragOperationGeneric;
+}
+
+-(BOOL)prepareForDragOperation:(id)sender
+{
+    return YES;
+}
+
+-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{
+    return YES;
+}
+
+-(void)concludeDragOperation:(id <NSDraggingInfo>)sender
+{
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSString *type = [pboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];
+    if (type)
+    {
+        if ([type isEqualToString:NSFilenamesPboardType])
+        {
+            NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
+            unsigned i = [filenames count];
+            NSMutableArray *goodFiles = [NSMutableArray array];
+            NSFileManager *fm = [NSFileManager defaultManager];
+            BOOL isDir;
+            while (i-- > 0)
+            {
+                NSString *filename = [filenames objectAtIndex:i];
+                dragAndDrop_->AddDragFilename([filename UTF8String]);
+            }
+
+            dragAndDrop_->ConcludeDrag();
+        }
+    }
+}
+
+@end
+
+namespace AtomicEditor
+{
+
+void InitDragAndDrop(AEDragAndDrop *dragAndDrop)
+{
+    dragAndDrop_ = dragAndDrop;
+
+    SDL_Window* window = (SDL_Window*) dragAndDrop->GetSubsystem<Graphics>()->GetSDLWindow();
+
+    SDL_SysWMinfo info;
+    SDL_VERSION(&info.version);
+
+    if(SDL_GetWindowWMInfo(window, &info)) {
+
+        NSWindow* window = info.info.cocoa.window;
+        [window registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
+    }
+
+}
+
+}
+

+ 4 - 0
Source/AtomicEditorWork/CMakeLists.txt

@@ -23,6 +23,10 @@ file (GLOB JAVASCRIPT_BINDINGS_SOURCE ${CMAKE_SOURCE_DIR}/Build/Source/Generated
 set (SOURCE_FILES ${SOURCE_FILES} ${JAVASCRIPT_BINDINGS_SOURCE})
 
 if (APPLE)
+
+    file (GLOB_RECURSE OBJC_FILES *.mm *.h)
+    set (SOURCE_FILES ${SOURCE_FILES} ${OBJC_FILES})
+
     set (EXE_TYPE MACOSX_BUNDLE)
 
     #ICNS

+ 4 - 3
Source/AtomicJS/Packages/ToolCore/ToolCore.json

@@ -1,7 +1,8 @@
 {
 	"name" : "ToolCore",
-	"sources" : ["Source/ToolCore", "Source/ToolCore/Project", "Source/ToolCore/Platform", "Source/ToolCore/Command"],
+	"sources" : ["Source/ToolCore", "Source/ToolCore/Project", "Source/ToolCore/Platform", "Source/ToolCore/Command",
+							 "Source/ToolCore/Import"],
 	"classes" : ["ToolEnvironment", "ToolSystem", "Project", "ProjectFile", "Platform", "PlatformMac", "PlatformWeb",
-							 "PlatformWindows",
-							"Command", "PlayCmd"]
+							 "PlatformWindows", "Command", "PlayCmd", "OpenAssetImporter"]
+
 }

+ 4 - 4
Source/ToolCore/Command/ImportCmd.cpp

@@ -67,7 +67,6 @@ void ImportCmd::Run()
             return;
         }
 
-
         LOGRAWF("Importing JSON: %s", assetFilename_.CString());
 
         SharedPtr<JSONSceneImporter> jimporter;
@@ -82,9 +81,10 @@ void ImportCmd::Run()
     else
     {
         SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
-
-        importer->SetVerboseLog(true);
-        importer->Load(assetFilename_);
+        if (importer->Load(assetFilename_))
+        {
+            importer->ExportModel("/Users/josh/Desktop/ExportedModel.mdl");
+        }
 
     }
 

+ 7 - 1
Source/ToolCore/Import/OpenAssetImporter.cpp

@@ -84,6 +84,12 @@ OpenAssetImporter::OpenAssetImporter(Context* context) : Object(context) ,
 
 }
 
+OpenAssetImporter::~OpenAssetImporter()
+{
+    if (scene_)
+        aiReleaseImport(scene_);
+}
+
 bool OpenAssetImporter::Load(const String &assetPath)
 {
     if (verboseLog_)
@@ -101,7 +107,7 @@ bool OpenAssetImporter::Load(const String &assetPath)
 
     rootNode_ = scene_->mRootNode;
 
-    DumpNodes(rootNode_, 0);
+    // DumpNodes(rootNode_, 0);
 
     return true;
 

+ 1 - 1
Source/ToolCore/Import/OpenAssetImporter.h

@@ -42,7 +42,7 @@ class OpenAssetImporter : public Object
 public:
 
     OpenAssetImporter(Context* context);
-    virtual ~OpenAssetImporter() {}
+    virtual ~OpenAssetImporter();
 
     bool Load(const String& assetPath);