Page 1 of 1

translate code

Posted: Fri Jan 03, 2014 5:06 am
by spacebuddy
Can anyone help me translate this code to PB. This is for WebGadget to turn on WebGL.

WebPreferences *p = [webView preferences];
if ([p respondsToSelector:@selector(setWebGLEnabled:)]) {
[p setWebGLEnabled:YES];
}

Thanks :D

Re: translate code

Posted: Fri Jan 03, 2014 7:16 am
by wilbert

Code: Select all

ImportC ""
  sel_registerName(str.p-ascii)
EndImport

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
  
  pref = CocoaMessage(0, GadgetID(0), "preferences")
  If CocoaMessage(0, pref, "respondsToSelector:", sel_registerName("setWebGLEnabled:"))
    CocoaMessage(0, pref, "setWebGLEnabled:", #YES)
  EndIf
  
  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf

Re: translate code

Posted: Fri Jan 03, 2014 8:07 am
by spacebuddy
Thanks Wilbert :D

Re: translate code

Posted: Fri Jan 03, 2014 7:36 pm
by Shardik
The Objective-C example code posted by spacebuddy was copied from a posting on stackoverflow.com:
http://stackoverflow.com/questions/1365 ... -on-webkit

This posting also contains the following valuable information from its author Kevin Reid:

Code: Select all

Once you have a WebView, there is an undocumented method which can enable WebGL:

WebPreferences *p = [webView preferences];
if ([p respondsToSelector:@selector(setWebGLEnabled:)]) {
    [p setWebGLEnabled:YES];
}

In this example I have protected it with respondsToSelector: to ensure the code will not abort if later versions remove this specific option.

Note that I understand that an application containing code using undocumented interfaces may be rejected if submitted to Apple's Mac App Store.

Re: translate code

Posted: Sat Jan 04, 2014 1:34 am
by spacebuddy
Yeah, not for Mac App store. I use for my own browser built in PB :D