Explorar el Código

Merge branch 'master' of github.com:ivansafrin/Polycode

Ivan Safrin hace 13 años
padre
commit
1e979de62f

+ 2 - 1
Core/Contents/Include/PolyTween.h

@@ -47,7 +47,7 @@ namespace Polycode {
 		* @param time The duration of the tween.
 		* @param repeat If true, this tween will repeat over and over.
 		*/
-		Tween(Number *target, int easeType, Number startVal, Number endVal, Number time, bool repeat=false);
+		Tween(Number *target, int easeType, Number startVal, Number endVal, Number time, bool repeat=false, bool deleteOnComplete=true);
 		~Tween();
 		
 		void handleEvent(Event *event);
@@ -95,6 +95,7 @@ namespace Polycode {
 		bool isComplete();
 		bool repeat;
 		
+		bool deleteOnComplete;
 		/*
 		* Set a speed multiplier for the tween
 		* @param speed Speed multiplier.

+ 4 - 2
Core/Contents/Source/PolyCocoaCore.mm

@@ -201,8 +201,10 @@ void CocoaCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, in
 //	}
 	if(fullScreen) {	
 		CGDisplaySwitchToMode (kCGDirectMainDisplay, CGDisplayBestModeForParameters (kCGDirectMainDisplay, 32, xRes, yRes, NULL) );						
-		[glView enterFullScreenMode:[NSScreen mainScreen] withOptions:[NSDictionary dictionaryWithObjectsAndKeys:
-																	   nil]];
+//		[glView enterFullScreenMode:[NSScreen mainScreen] withOptions:[NSDictionary dictionaryWithObjectsAndKeys: nil]];
+		[glView enterFullScreenMode:[[NSScreen screens] objectAtIndex:1] withOptions:[NSDictionary dictionaryWithObjectsAndKeys: nil]];
+
+
 		
 	}
 	

+ 3 - 1
Core/Contents/Source/PolyTexture.cpp

@@ -87,7 +87,9 @@ void Texture::setImageData(Image *data) {
 		break;
 	}
 
-
+	width = data->getWidth();
+	height = data->getHeight();
+	
 	if(this->textureData)
 		free(this->textureData);
 	this->textureData = (char*)malloc(width*height*pixelSize);

+ 2 - 1
Core/Contents/Source/PolyTween.cpp

@@ -31,7 +31,8 @@
 
 using namespace Polycode;
 
-Tween::	Tween(Number *target, int easeType, Number startVal, Number endVal, Number time, bool repeat) : EventDispatcher() {
+Tween::	Tween(Number *target, int easeType, Number startVal, Number endVal, Number time, bool repeat, bool deleteOnComplete) : EventDispatcher() {
+	this->deleteOnComplete = deleteOnComplete;
 	targetVal = target;
 	this->repeat = repeat;
 	this->easeType = easeType;

+ 5 - 1
Core/Contents/Source/PolyTweenManager.cpp

@@ -41,6 +41,9 @@ void TweenManager::removeTween(Tween *tween) {
 	for(int i=0;i<tweens.size();i++) {
 		if(tweens[i] == tween) {
 			tweens.erase(tweens.begin()+i);
+			if(tween->deleteOnComplete)
+				delete tween;
+			
 		}
 	}
 }
@@ -56,7 +59,8 @@ void TweenManager::Update() {
 				tween = tweens[i];
 				tweens.erase(tweens.begin()+i);
 				tween->doOnComplete();
-//				delete tween;
+				if(tween->deleteOnComplete)
+					delete tween;
 				return;
 			}
 		}

+ 74 - 1
Modules/Contents/Awesomium/PolycodeWebView.cpp

@@ -1,7 +1,7 @@
 
 #include "PolycodeWebView.h"
 
-PolycodeWebView::PolycodeWebView(unsigned int width, unsigned int height, String url) {
+PolycodeWebView::PolycodeWebView(unsigned int width, unsigned int height, String url) : Awesomium::WebViewListener(), EventDispatcher() {
 
 	this->width = width;
 	this->height = height;
@@ -13,16 +13,51 @@ PolycodeWebView::PolycodeWebView(unsigned int width, unsigned int height, String
 	webCore = new Awesomium::WebCore();
 	webView = webCore->createWebView(width, height);
 	
+	webView->setListener(this);
+	
+	webView->createObject(L"Polycode");
+	webView->setObjectCallback(L"Polycode", L"showNotice");
+	webView->setObjectCallback(L"Polycode", L"showGlowAreas");
+	
 	webView->loadURL(url.c_str());
 	webView->focus();
 }
 
+void PolycodeWebView::onCallback(Awesomium::WebView* caller, 
+							const std::wstring& objectName, 
+							const std::wstring& callbackName, 
+							const Awesomium::JSArguments& args) {
+
+	PolycodeWebViewEvent *event = new PolycodeWebViewEvent();
+	event->objectName = objectName;
+	event->callbackName = callbackName;
+	
+	for(int i=0; i < args.size(); i++) {
+		event->args.push_back(String(args[i].toString()));
+	}
+	
+	dispatchEvent(event, PolycodeWebViewEvent::CALLBACK_EVENT);
+}
+
+
+
+void PolycodeWebView::Resize(unsigned int width, unsigned int height) {
+	webView->resize(width, height);
+	this->width = width;
+	this->height = height;
+}
+
+
 PolycodeWebView::~PolycodeWebView() {
 	webView->destroy();
 	delete webCore;	
 	delete renderTexture;
 }
 
+void PolycodeWebView::loadURL(String url) {
+	webView->loadURL(url.c_str());
+}
+
 void PolycodeWebView::Update() {
 	webCore->update();
 	if(webView->isDirty()) {
@@ -40,6 +75,44 @@ void PolycodeWebView::Update() {
 	}
 }
 
+void PolycodeWebView::mouseMove(Number x, Number y) {
+	webView->injectMouseMove(x, y);
+}
+
+void PolycodeWebView::mouseDown(Number x, Number y) {
+	webView->injectMouseDown(Awesomium::LEFT_MOUSE_BTN);
+}
+
+void PolycodeWebView::mouseUp(Number x, Number y) {
+	webView->injectMouseUp(Awesomium::LEFT_MOUSE_BTN);
+}
+
+void PolycodeWebView::injectKey(int keyCode) {
+	Awesomium::WebKeyboardEvent keyEvent;
+
+	char* buf = new char[20];
+	keyEvent.virtualKeyCode = keyCode;
+	Awesomium::getKeyIdentifierFromVirtualKeyCode(keyEvent.virtualKeyCode, 
+												  &buf);
+	strcpy(keyEvent.keyIdentifier, buf);
+	delete[] buf;
+	
+	keyEvent.modifiers = 0;
+	keyEvent.nativeKeyCode = 0;
+	keyEvent.type = Awesomium::WebKeyboardEvent::TYPE_KEY_DOWN;
+
+	webView->injectKeyboardEvent(keyEvent);
+
+	keyEvent.type = Awesomium::WebKeyboardEvent::TYPE_KEY_UP;
+
+	webView->injectKeyboardEvent(keyEvent);
+}
+
+void PolycodeWebView::keyDown(PolyKEY key) {
+	injectKey(key);
+}
+
+
 Texture *PolycodeWebView::getRenderTexture() {
 	return renderTexture;
 }

+ 142 - 1
Modules/Contents/Awesomium/PolycodeWebView.h

@@ -4,13 +4,154 @@
 
 using namespace Polycode;
 
-class PolycodeWebView {
+class PolycodeWebViewEvent : public Event {
+	public:
+			PolycodeWebViewEvent() : Event() {}
+			
+			static const int CALLBACK_EVENT = 0;	
+			
+			String objectName;
+			String callbackName;
+			std::vector <String> args;
+
+};
+
+class PolycodeWebView : public Awesomium::WebViewListener, public EventDispatcher {
 	public:
 		PolycodeWebView(unsigned int width, unsigned int height, String url);
 		~PolycodeWebView();		
 		void Update();
 		
+		void loadURL(String url);
+		
+		void Resize(unsigned int width, unsigned int height);
+		
 		Texture *getRenderTexture();
+				
+		void mouseMove(Number x, Number y);
+		void mouseDown(Number x, Number y);
+		void mouseUp(Number x, Number y);
+		void keyDown(PolyKEY key);
+		
+		void injectKey(int keyCode);
+		
+	// ** The following methods are inherited from WebViewListener:
+
+	virtual void onBeginNavigation(Awesomium::WebView* caller, 
+								   const std::string& url, 
+								   const std::wstring& frameName) {}
+	
+	virtual void onBeginLoading(Awesomium::WebView* caller, 
+								const std::string& url, 
+								const std::wstring& frameName, 
+								int statusCode, const std::wstring& mimeType) {}
+	
+	virtual void onFinishLoading(Awesomium::WebView* caller) {}
+	
+	virtual void onCallback(Awesomium::WebView* caller, 
+							const std::wstring& objectName, 
+							const std::wstring& callbackName, 
+							const Awesomium::JSArguments& args);
+	
+	virtual void onReceiveTitle(Awesomium::WebView* caller, 
+								const std::wstring& title, 
+								const std::wstring& frameName) {}
+	
+	virtual void onChangeTooltip(Awesomium::WebView* caller, 
+								 const std::wstring& tooltip) {}
+	
+	virtual void onChangeCursor(Awesomium::WebView* caller, 
+								Awesomium::CursorType cursor) {}
+
+	virtual void onChangeKeyboardFocus(Awesomium::WebView* caller,
+									   bool isFocused) {}
+	
+	virtual void onChangeTargetURL(Awesomium::WebView* caller, 
+								   const std::string& url) {}
+	
+	virtual void onOpenExternalLink(Awesomium::WebView* caller, 
+									const std::string& url, 
+									const std::wstring& source) {}
+
+	virtual void onRequestDownload(Awesomium::WebView* caller,
+								   const std::string& url) {}
+	
+	virtual void onWebViewCrashed(Awesomium::WebView* caller) {}
+	
+	virtual void onPluginCrashed(Awesomium::WebView* caller, 
+								 const std::wstring& pluginName) {}
+	
+	virtual void onRequestMove(Awesomium::WebView* caller, int x, int y) {}
+	
+	virtual void onGetPageContents(Awesomium::WebView* caller, 
+								   const std::string& url, 
+								   const std::wstring& contents) {}
+	
+	virtual void onDOMReady(Awesomium::WebView* caller) {}
+
+	virtual void onRequestFileChooser(Awesomium::WebView* caller,
+										  bool selectMultipleFiles,
+										  const std::wstring& title,
+										  const std::wstring& defaultPath) {}
+
+	virtual void onGetScrollData(Awesomium::WebView* caller,
+								 int contentWidth,
+								 int contentHeight,
+								 int preferredWidth,
+								 int scrollX,
+								 int scrollY) {}
+
+	virtual void onJavascriptConsoleMessage(Awesomium::WebView* caller,
+											const std::wstring& message,
+											int lineNumber,
+											const std::wstring& source) {}
+
+	virtual void onGetFindResults(Awesomium::WebView* caller,
+                                      int requestID,
+                                      int numMatches,
+                                      const Awesomium::Rect& selection,
+                                      int curMatch,
+                                      bool finalUpdate) {}
+
+	virtual void onUpdateIME(Awesomium::WebView* caller,
+                                 Awesomium::IMEState imeState,
+                                 const Awesomium::Rect& caretRect) {}
+
+	virtual void onShowContextMenu(Awesomium::WebView* caller,
+                                   int mouseX,
+								   int mouseY,
+								   Awesomium::MediaType type,
+								   int mediaState,
+								   const std::string& linkURL,
+								   const std::string& srcURL,
+								   const std::string& pageURL,
+								   const std::string& frameURL,
+								   const std::wstring& selectionText,
+								   bool isEditable,
+								   int editFlags) {}
+
+	virtual void onRequestLogin(Awesomium::WebView* caller,
+                                   int requestID,
+								   const std::string& requestURL,
+								   bool isProxy,
+								   const std::wstring& hostAndPort,
+								   const std::wstring& scheme,
+								   const std::wstring& realm) {}
+
+	virtual void onChangeHistory(Awesomium::WebView* caller,
+									int backCount,
+									int forwardCount) {}
+
+	virtual void onFinishResize(Awesomium::WebView* caller,
+									int width,
+									int height) {}
+
+	virtual void onShowJavascriptDialog(Awesomium::WebView* caller,
+											int requestID,
+											int dialogFlags,
+											const std::wstring& message,
+											const std::wstring& defaultPrompt,
+											const std::string& frameURL) {}	
 		
 	protected: