8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CCWebViewをCocos2d-x 3.2へ対応

Last updated at Posted at 2014-07-27

GreePlatformSDKCocos2dxのWebViewを導入後の3.2対応させる為の、ソース等の変更箇所です。

##iOS対応

--- a/webview_plugin/webview_plugin/include/CCWebView.h	2014-07-25 00:35:00.000000000 +0900
+++ b/webview_plugin/webview_plugin/include/CCWebView.h	2014-07-26 20:35:06.000000000 +0900
@@ -1,9 +1,7 @@
 #ifndef __CC_WEBVIEW_H__
 #define __CC_WEBVIEW_H__
 
-#include "CCStdC.h"
-#include "cocoa/CCString.h"
-#include "cocoa/CCDictionary.h"
+#include "cocos2d.h"
 
 #define USING_NS_CC_WEBVIEW  using namespace cocos2d::webview_plugin
 
@@ -23,10 +21,10 @@
 
 class CCWebViewDelegate {
 	public:
-		virtual void callbackFromJS(CCWebView* webview, CCString* message){};
+    virtual void callbackFromJS(CCWebView* webview, std::string message){};
 };
 
-class CCWebView : public CCObject {
+    class CCWebView : public cocos2d::Ref {
 	public:
 		static CCWebView* create();
 		void loadUrl(const char* url);

--- a/webview_plugin/webview_plugin/ios/CCWebView.mm	2014-07-25 00:35:00.000000000 +0900
+++ b/webview_plugin/webview_plugin/ios/CCWebView.mm	2014-07-26 21:44:11.000000000 +0900
@@ -1,6 +1,6 @@
 #import "CCWebView.h"
 
-#import "EAGLView.h"
+#import "CCEAGLView.h"
 
 @interface WebViewDelegate : NSObject<UIWebViewDelegate>
 {
@@ -42,7 +42,7 @@
 
 CCWebView* CCWebView::create(){
     CCWebView *webview = NULL;
-    UIView *view = [EAGLView sharedEGLView];
+    UIView *view = (UIView *)Director::getInstance()->getOpenGLView()->getEAGLView();
     UIWebView *uiView = [[UIWebView alloc] init];
     UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
     if(UIInterfaceOrientationIsPortrait(orientation)){
@@ -58,9 +58,11 @@
 }
 
 void CCWebView::setRect(int x, int y, int w, int h){
-    UIView *view = [EAGLView sharedEGLView];
+    UIView *view = (UIView *)Director::getInstance()->getOpenGLView()->getEAGLView();
     CGRect frame = view.frame;
     CGFloat scale = view.contentScaleFactor;
+    frame.origin.x = x / scale;
+    frame.origin.y = y / scale;
     frame.size.width = w / scale;
     frame.size.height = h / scale;
     UIWebView *uiView = (UIWebView*)mWebView;
@@ -97,8 +99,7 @@
 void CCWebView::handleCalledFromJS(const char *message){
     CCWebViewDelegate *delegate = CCWebView::getWebViewDelegate();
     if(delegate != NULL){
-        CCString *str = new CCString(message);
-        str->autorelease();
+        std::string str = message;
         delegate->callbackFromJS(this, str);
     }
 }

##Android対応

--- a/webview_plugin/webview_plugin/android/CCWebView.cpp	2014-07-25 00:35:00.000000000 +0900
+++ b/webview_plugin/webview_plugin/android/CCWebView.cpp	2014-07-26 22:45:04.000000000 +0900
@@ -55,8 +55,7 @@
 void CCWebView::handleCalledFromJS(const char *message){
 	CCWebViewDelegate *delegate = CCWebView::getWebViewDelegate();
 	if(delegate != NULL){
-		CCString *str = new CCString(message);
-		str->autorelease();
+		std::string str = message;
 		delegate->callbackFromJS(this, str);
 	}
 }

--- a/cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java	2014-07-11 16:02:08.000000000 +0900
+++ b/cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java	2014-07-27 10:36:07.000000000 +0900
@@ -30,6 +30,8 @@
 import java.util.Set;
 import java.lang.Runnable;
 
+import org.cocos2dx.lib.gree.webview.Cocos2dxWebView;
+
 import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -92,6 +94,7 @@
     
             Cocos2dxBitmap.setContext(activity);
             Cocos2dxETCLoader.setContext(activity);
+            Cocos2dxWebView.setContext(activity);
             sActivity = activity;
 
             sInited = true;

--- a/webview_plugin/webview_plugin/android/Android.mk	2014-07-25 00:35:00.000000000 +0900
+++ b/webview_plugin/webview_plugin/android/Android.mk	2014-07-26 22:31:37.000000000 +0900
@@ -14,13 +14,12 @@
 
 LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include
 
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../cocos2dx \
-							$(LOCAL_PATH)/../../cocos2dx/include \
-							$(LOCAL_PATH)/../../cocos2dx/platform/android \
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../cocos \
+							$(LOCAL_PATH)/../../../cocos/platform/android \
 							$(LOCAL_PATH)/../include \
 							$(LOCAL_PATH)/ \
 							$(LOCAL_PATH)/jni
                     
 include $(BUILD_STATIC_LIBRARY)
 
-$(call import-module,cocos2dx)
+# $(call import-module,cocos2dx)

--- a/jni/Android.mk	2014-07-23 00:51:15.000000000 +0900
+++ b/jni/Android.mk	2014-07-26 23:22:17.000000000 +0900
@@ -18,6 +18,7 @@
 
 LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
 LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
+LOCAL_WHOLE_STATIC_LIBRARIES += cocos_webview_plugin_static
 
 # LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
 # LOCAL_WHOLE_STATIC_LIBRARIES += cocosbuilder_static
@@ -31,6 +32,7 @@
 
 $(call import-module,.)
 $(call import-module,audio/android)
+$(call import-module,webview_plugin/webview_plugin/android)
 
 # $(call import-module,Box2D)
 # $(call import-module,editor-support/cocosbuilder)
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?