All pastes #805853 Raw Edit

Meins

public text v1 · immutable
·published 2007-12-04 18:47 UTC
rendered paste body
#!/usr/bin/env ruby
 
require 'optparse'
require 'osx/cocoa'
 
class Processor < OSX::NSObject
  include OSX
  attr_accessor :options, :text_view
 
  def initialize
    rect = [-16000, -16000, 5000, 5000]
    # rect = [100,100,1000,100]
    win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(rect, NSBorderlessWindowMask, 2, 0)
    win.setOpaque(0)
 
    @text_view = NSTextView.alloc.initWithFrame([0,0,0,0])
    @text_view.setHorizontallyResizable(true)
   
    @text_view.setTextColor(NSColor.redColor)
    @text_view.setFont(NSFont.fontWithName_size('Arial', 28.0))
    # @text_view.setDrawsBackground(false)
    @text_view.setBackgroundColor(NSColor.redColor)
   
    @text_view.setString("Hello World!")
   
    @text_view.sizeToFit
    puts @text_view.frame.width
 
    win.setContentView(@text_view)
    win.display
    win.orderFrontRegardless
  end
 
  def applicationDidFinishLaunching(notification)
    capture_and_save(@text_view, "test.png")
  end
 
  def capture_and_save(view, file)
    view.lockFocus
      bitmap = NSBitmapImageRep.alloc.initWithFocusedViewRect(view.bounds)
    view.unlockFocus
 
    bitmap.representationUsingType_properties(NSPNGFileType, nil).writeToFile_atomically(file, true)
   
    NSApplication.sharedApplication.terminate(nil)
  end
end
 
app = OSX::NSApplication.sharedApplication
app.setDelegate(Processor.alloc.init)
app.run