Module: SnapUrl::Camera

Defined in:
lib/core/camera.rb

Defined Under Namespace

Classes: AppDelegate, LoadDelegate

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :browser               => {:width => 800.0, :height => 600.0},
  :clip                  => {:width => 200.0, :height => 150.0},
  :snapFormat            => [:fullsize, :thumbnail, :clip],
  :scaleFactor           => 0.25,
  :filename              => '',
  :datestampInFilename?  => false,
  :timestampInFilename?  => false,
  :sizeInFilename?       => false,
  :snapFormatInFilename? => false,
  :useHashForFilename?   => false,
  :outputDirectory       => Dir.pwd,
  :verbose?              => false
}

Class Method Summary collapse

Class Method Details

.snap(urls, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/core/camera.rb', line 28

def Camera::snap(urls, options = {})
  # create context
  OSX::NSApplication.sharedApplication

  # create an app delegate
  delegate = AppDelegate.alloc.init
  OSX::NSApp.setDelegate(delegate)

  # create a webview object
  rect    = OSX::NSMakeRect(-16000, -16000, 100, 100)
  webview = OSX::WebView.alloc.initWithFrame(rect)
  webview.setMediaStyle('screen')
  webview.mainFrame.frameView.setAllowsScrolling(false)

  # make sure we don't save any of the prefs that we change.
  webview.preferences.setAutosaves(false)
  webview.preferences.setShouldPrintBackgrounds(true)
  webview.preferences.setJavaScriptCanOpenWindowsAutomatically(false)
  webview.preferences.setAllowsAnimatedImages(false)

  # create a window and set view
  win = OSX::NSWindow.alloc
  win.initWithContentRect_styleMask_backing_defer(rect, OSX::NSBorderlessWindowMask, OSX::NSBackingStoreBuffered, false)
  win.setContentView(webview)

  # create load delegate
  loader         = LoadDelegate.alloc.init
  loader.urls    = urls
  loader.options = DEFAULT_OPTIONS.merge(options)
  webview.setFrameLoadDelegate(loader)

  # now run
  OSX::NSApp.run
end