translate code

Mac OSX specific forum
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

translate code

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: translate code

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Re: translate code

Post by spacebuddy »

Thanks Wilbert :D
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: translate code

Post 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.
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Re: translate code

Post by spacebuddy »

Yeah, not for Mac App store. I use for my own browser built in PB :D
Post Reply