hotcocoa 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/bin/hotcocoa +31 -0
- data/lib/hotcocoa/application_builder.rb +320 -0
- data/lib/hotcocoa/attributed_string.rb +143 -0
- data/lib/hotcocoa/behaviors.rb +7 -0
- data/lib/hotcocoa/data_sources/combo_box_data_source.rb +44 -0
- data/lib/hotcocoa/data_sources/table_data_source.rb +18 -0
- data/lib/hotcocoa/delegate_builder.rb +85 -0
- data/lib/hotcocoa/graphics/canvas.rb +836 -0
- data/lib/hotcocoa/graphics/color.rb +781 -0
- data/lib/hotcocoa/graphics/elements/particle.rb +75 -0
- data/lib/hotcocoa/graphics/elements/rope.rb +99 -0
- data/lib/hotcocoa/graphics/elements/sandpainter.rb +71 -0
- data/lib/hotcocoa/graphics/gradient.rb +63 -0
- data/lib/hotcocoa/graphics/image.rb +488 -0
- data/lib/hotcocoa/graphics/path.rb +325 -0
- data/lib/hotcocoa/graphics/pdf.rb +71 -0
- data/lib/hotcocoa/graphics.rb +161 -0
- data/lib/hotcocoa/kernel_ext.rb +14 -0
- data/lib/hotcocoa/kvo_accessors.rb +48 -0
- data/lib/hotcocoa/layout_view.rb +448 -0
- data/lib/hotcocoa/mapper.rb +227 -0
- data/lib/hotcocoa/mapping_methods.rb +40 -0
- data/lib/hotcocoa/mappings/alert.rb +25 -0
- data/lib/hotcocoa/mappings/application.rb +112 -0
- data/lib/hotcocoa/mappings/array_controller.rb +87 -0
- data/lib/hotcocoa/mappings/box.rb +39 -0
- data/lib/hotcocoa/mappings/button.rb +92 -0
- data/lib/hotcocoa/mappings/collection_view.rb +44 -0
- data/lib/hotcocoa/mappings/color.rb +28 -0
- data/lib/hotcocoa/mappings/column.rb +21 -0
- data/lib/hotcocoa/mappings/combo_box.rb +24 -0
- data/lib/hotcocoa/mappings/control.rb +33 -0
- data/lib/hotcocoa/mappings/font.rb +44 -0
- data/lib/hotcocoa/mappings/gradient.rb +15 -0
- data/lib/hotcocoa/mappings/image.rb +15 -0
- data/lib/hotcocoa/mappings/image_view.rb +43 -0
- data/lib/hotcocoa/mappings/label.rb +25 -0
- data/lib/hotcocoa/mappings/layout_view.rb +9 -0
- data/lib/hotcocoa/mappings/menu.rb +71 -0
- data/lib/hotcocoa/mappings/menu_item.rb +47 -0
- data/lib/hotcocoa/mappings/movie.rb +13 -0
- data/lib/hotcocoa/mappings/movie_view.rb +27 -0
- data/lib/hotcocoa/mappings/notification.rb +17 -0
- data/lib/hotcocoa/mappings/popup.rb +110 -0
- data/lib/hotcocoa/mappings/progress_indicator.rb +68 -0
- data/lib/hotcocoa/mappings/scroll_view.rb +29 -0
- data/lib/hotcocoa/mappings/search_field.rb +9 -0
- data/lib/hotcocoa/mappings/secure_text_field.rb +17 -0
- data/lib/hotcocoa/mappings/segmented_control.rb +97 -0
- data/lib/hotcocoa/mappings/slider.rb +25 -0
- data/lib/hotcocoa/mappings/sort_descriptor.rb +13 -0
- data/lib/hotcocoa/mappings/sound.rb +9 -0
- data/lib/hotcocoa/mappings/speech_synthesizer.rb +25 -0
- data/lib/hotcocoa/mappings/split_view.rb +21 -0
- data/lib/hotcocoa/mappings/status_bar.rb +7 -0
- data/lib/hotcocoa/mappings/status_item.rb +9 -0
- data/lib/hotcocoa/mappings/table_view.rb +110 -0
- data/lib/hotcocoa/mappings/text_field.rb +41 -0
- data/lib/hotcocoa/mappings/text_view.rb +13 -0
- data/lib/hotcocoa/mappings/timer.rb +25 -0
- data/lib/hotcocoa/mappings/toolbar.rb +97 -0
- data/lib/hotcocoa/mappings/toolbar_item.rb +36 -0
- data/lib/hotcocoa/mappings/view.rb +67 -0
- data/lib/hotcocoa/mappings/web_view.rb +22 -0
- data/lib/hotcocoa/mappings/window.rb +118 -0
- data/lib/hotcocoa/mappings/xml_parser.rb +41 -0
- data/lib/hotcocoa/mappings.rb +109 -0
- data/lib/hotcocoa/mvc.rb +175 -0
- data/lib/hotcocoa/notification_listener.rb +62 -0
- data/lib/hotcocoa/object_ext.rb +22 -0
- data/lib/hotcocoa/plist.rb +45 -0
- data/lib/hotcocoa/standard_rake_tasks.rb +17 -0
- data/lib/hotcocoa/template.rb +27 -0
- data/lib/hotcocoa/virtual_file_system.rb +172 -0
- data/lib/hotcocoa.rb +26 -0
- data/template/Rakefile +5 -0
- data/template/config/build.yml +8 -0
- data/template/lib/application.rb +45 -0
- data/template/lib/menu.rb +32 -0
- data/template/resources/HotCocoa.icns +0 -0
- data/test/test_helper.rb +3 -0
- data/test/test_hotcocoa.rb +11 -0
- metadata +137 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
# Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
|
2
|
+
# interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
|
3
|
+
# With a few lines of easy-to-read code, you can write scripts to draw simple or complex
|
4
|
+
# shapes, lines, and patterns, process and filter images, create abstract art or visualize
|
5
|
+
# scientific data, and much more.
|
6
|
+
#
|
7
|
+
# Inspiration for this project was derived from Processing and NodeBox. These excellent
|
8
|
+
# graphics programming environments are more full-featured than RCG, but they are implemented
|
9
|
+
# in Java and Python, respectively. RCG was created to offer similar functionality using
|
10
|
+
# the Ruby programming language.
|
11
|
+
#
|
12
|
+
# Author:: James Reynolds (mailto:drtoast@drtoast.com)
|
13
|
+
# Copyright:: Copyright (c) 2008 James Reynolds
|
14
|
+
# License:: Distributes under the same terms as Ruby
|
15
|
+
|
16
|
+
module HotCocoa::Graphics
|
17
|
+
|
18
|
+
# wandering particle with brownian motion
|
19
|
+
class Particle
|
20
|
+
|
21
|
+
attr_accessor :acceleration, :points, :stroke, :velocity_x, :velocity_y, :x, :y
|
22
|
+
|
23
|
+
# initialize particle origin x,y coordinates (relative to the center)
|
24
|
+
def initialize (x, y, velocity_x=0.0, velocity_y=2.0)
|
25
|
+
@age = 0
|
26
|
+
@acceleration = 0.5
|
27
|
+
|
28
|
+
@x = x
|
29
|
+
@y = y
|
30
|
+
|
31
|
+
@previous_x = 0
|
32
|
+
@previous_y = 0
|
33
|
+
|
34
|
+
# initialize velocity
|
35
|
+
@velocity_x=velocity_x
|
36
|
+
@velocity_y=velocity_y
|
37
|
+
|
38
|
+
# append the point to the array
|
39
|
+
@points = [NSPoint.new(@x, @y)]
|
40
|
+
@stroke = Color.white
|
41
|
+
end
|
42
|
+
|
43
|
+
# move to a new position using brownian motion
|
44
|
+
def move
|
45
|
+
# save old x,y position
|
46
|
+
@previous_x=@x
|
47
|
+
@previous_y=@y
|
48
|
+
|
49
|
+
# move particle by velocity_x,velocity_y
|
50
|
+
@x += @velocity_x
|
51
|
+
@y += @velocity_y
|
52
|
+
|
53
|
+
# randomly increase/decrease direction
|
54
|
+
@velocity_x += random(-1.0, 1.0) * @acceleration
|
55
|
+
@velocity_y += random(-1.0, 1.0) * @acceleration
|
56
|
+
|
57
|
+
# draw a line from the old position to the new
|
58
|
+
#CANVAS.line(@previous_x,@previous_y,@x,@y);
|
59
|
+
@points.push(NSPoint.new(@x, @y))
|
60
|
+
|
61
|
+
# grow old
|
62
|
+
@age += 1
|
63
|
+
if @age>200
|
64
|
+
# die and be reborn
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def draw(canvas)
|
70
|
+
canvas.nofill
|
71
|
+
canvas.lines(@points)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
|
2
|
+
# interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
|
3
|
+
# With a few lines of easy-to-read code, you can write scripts to draw simple or complex
|
4
|
+
# shapes, lines, and patterns, process and filter images, create abstract art or visualize
|
5
|
+
# scientific data, and much more.
|
6
|
+
#
|
7
|
+
# Inspiration for this project was derived from Processing and NodeBox. These excellent
|
8
|
+
# graphics programming environments are more full-featured than RCG, but they are implemented
|
9
|
+
# in Java and Python, respectively. RCG was created to offer similar functionality using
|
10
|
+
# the Ruby programming language.
|
11
|
+
#
|
12
|
+
# Author:: James Reynolds (mailto:drtoast@drtoast.com)
|
13
|
+
# Copyright:: Copyright (c) 2008 James Reynolds
|
14
|
+
# License:: Distributes under the same terms as Ruby
|
15
|
+
|
16
|
+
module HotCocoa::Graphics
|
17
|
+
|
18
|
+
class Rope
|
19
|
+
|
20
|
+
attr_accessor :x0, :y0, :x1, :y1, :width, :fibers, :roundness, :strokewidth
|
21
|
+
|
22
|
+
def initialize(canvas, options={})
|
23
|
+
@canvas = canvas
|
24
|
+
@width = options[:width] || 200
|
25
|
+
@fibers = options[:fibers] || 200
|
26
|
+
@roundness = options[:roundness] || 1.0
|
27
|
+
@strokewidth = options[:strokewidth] || 0.4
|
28
|
+
end
|
29
|
+
|
30
|
+
def hair(hair_x0=@x0, hair_y0=@y0, hair_x1=@x1, hair_y1=@y1, hair_width=@width, hair_fibers=@fibers)
|
31
|
+
@canvas.push
|
32
|
+
@canvas.strokewidth(@strokewidth)
|
33
|
+
@canvas.autoclosepath(false)
|
34
|
+
@canvas.nofill
|
35
|
+
hair_x0 = choose(hair_x0)
|
36
|
+
hair_y0 = choose(hair_y0)
|
37
|
+
hair_x1 = choose(hair_x1)
|
38
|
+
hair_y1 = choose(hair_y1)
|
39
|
+
vx0 = random(-@canvas.width / 2, @canvas.width / 2) * @roundness
|
40
|
+
vy0 = random(-@canvas.height / 2, @canvas.height / 2) * @roundness
|
41
|
+
vx1 = random(-@canvas.width / 2, @canvas.width / 2) * @roundness
|
42
|
+
vy1 = random(-@canvas.height / 2, @canvas.height / 2) * @roundness
|
43
|
+
hair_fibers.times do |j|
|
44
|
+
#x0,y0,x1,y1 = [@x0.choose,@y0.choose,@x1.choose,@y1.choose]
|
45
|
+
@canvas.beginpath(hair_x0, hair_y0)
|
46
|
+
@canvas.curveto(
|
47
|
+
hair_x0 + vx0 + rand(hair_width), hair_y0 + vy0 + rand(hair_width), # control point 1
|
48
|
+
hair_x1 + vx1, hair_y1 + vy1, # control point 2
|
49
|
+
hair_x1, hair_y1 # end point
|
50
|
+
)
|
51
|
+
@canvas.endpath
|
52
|
+
end
|
53
|
+
@canvas.pop
|
54
|
+
end
|
55
|
+
|
56
|
+
def ribbon(ribbon_x0=@x0, ribbon_y0=@y0, ribbon_x1=@x1, ribbon_y1=@y1, ribbon_width=@width, ribbon_fibers=@fibers)
|
57
|
+
@canvas.push
|
58
|
+
@canvas.strokewidth(@strokewidth)
|
59
|
+
@canvas.autoclosepath(false)
|
60
|
+
@canvas.nofill
|
61
|
+
black = Color.black
|
62
|
+
white = Color.white
|
63
|
+
ribbon_x0 = choose(ribbon_x0)
|
64
|
+
ribbon_y0 = choose(ribbon_y0)
|
65
|
+
ribbon_x1 = choose(ribbon_x1)
|
66
|
+
ribbon_y1 = choose(ribbon_y1)
|
67
|
+
vx0 = random(-@canvas.width / 2, @canvas.width / 2) * @roundness
|
68
|
+
vy0 = random(-@canvas.height / 2, @canvas.height / 2) * @roundness
|
69
|
+
vx1 = random(-@canvas.width / 2, @canvas.width / 2) * @roundness
|
70
|
+
vy1 = random(-@canvas.height / 2, @canvas.height / 2) * @roundness
|
71
|
+
xwidth = rand(ribbon_width)
|
72
|
+
ywidth = rand(ribbon_width)
|
73
|
+
ribbon_fibers.times do |j|
|
74
|
+
#x0,y0,x1,y1 = [@x0.choose,@y0.choose,@x1.choose,@y1.choose]
|
75
|
+
xoffset = (j-1).to_f * xwidth / ribbon_fibers
|
76
|
+
yoffset = (j-1).to_f * ywidth / ribbon_fibers
|
77
|
+
cpx0 = ribbon_x0 + vx0 + xoffset
|
78
|
+
cpy0 = ribbon_y0 + vy0 + yoffset
|
79
|
+
cpx1 = ribbon_x1 + vx1
|
80
|
+
cpy1 = ribbon_y1 + vy1
|
81
|
+
# debug - show control points
|
82
|
+
# @canvas.fill(black)
|
83
|
+
# @canvas.oval(cpx0,cpy0,5,5,:center)
|
84
|
+
# @canvas.fill(white)
|
85
|
+
# @canvas.oval(cpx1,cpy1,5,5,:center)
|
86
|
+
# @canvas.nofill
|
87
|
+
|
88
|
+
@canvas.beginpath(x0, y0)
|
89
|
+
@canvas.curveto(
|
90
|
+
cpx0, cpy0, # control point 1
|
91
|
+
cpx1, cpy1, # control point 2
|
92
|
+
ribbon_x1, ribbon_y1 # end point
|
93
|
+
)
|
94
|
+
@canvas.endpath
|
95
|
+
end
|
96
|
+
@canvas.pop
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
|
2
|
+
# interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
|
3
|
+
# With a few lines of easy-to-read code, you can write scripts to draw simple or complex
|
4
|
+
# shapes, lines, and patterns, process and filter images, create abstract art or visualize
|
5
|
+
# scientific data, and much more.
|
6
|
+
#
|
7
|
+
# Inspiration for this project was derived from Processing and NodeBox. These excellent
|
8
|
+
# graphics programming environments are more full-featured than RCG, but they are implemented
|
9
|
+
# in Java and Python, respectively. RCG was created to offer similar functionality using
|
10
|
+
# the Ruby programming language.
|
11
|
+
#
|
12
|
+
# Author:: James Reynolds (mailto:drtoast@drtoast.com)
|
13
|
+
# Copyright:: Copyright (c) 2008 James Reynolds
|
14
|
+
# License:: Distributes under the same terms as Ruby
|
15
|
+
|
16
|
+
module HotCocoa::Graphics
|
17
|
+
|
18
|
+
# draw watercolor-like painted strokes (adapted from code by Jared Tarbell - complexification.net)
|
19
|
+
class SandPainter
|
20
|
+
|
21
|
+
attr_accessor :color, :grains, :grainsize, :maxalpha, :jitter, :huedrift, :saturationdrift, :brightnessdrift
|
22
|
+
|
23
|
+
def initialize(canvas, color=Color.red)
|
24
|
+
@canvas = canvas
|
25
|
+
@color = color
|
26
|
+
# set a random initial gain value
|
27
|
+
@gain = random(0.01, 0.1)
|
28
|
+
@grainsize = 6.0
|
29
|
+
@grains = 64
|
30
|
+
@maxalpha = 0.1
|
31
|
+
@jitter = 0
|
32
|
+
@huedrift = 0.2
|
33
|
+
@saturationdrift = 0.3
|
34
|
+
@brightnessdrift = 0.3
|
35
|
+
end
|
36
|
+
|
37
|
+
# render a line that fades out from ox,oy to x,y
|
38
|
+
def render(ox, oy, x, y)
|
39
|
+
@canvas.push
|
40
|
+
# modulate gain
|
41
|
+
@gain += random(-0.050, 0.050)
|
42
|
+
@gain = inrange(@gain, 0.0, 1.0)
|
43
|
+
# calculate grains by distance
|
44
|
+
#@grains = (sqrt((ox-x)*(ox-x)+(oy-y)*(oy-y))).to_i
|
45
|
+
|
46
|
+
# ramp from 0 to .015 for g = 0 to 1
|
47
|
+
w = @gain / (@grains-1)
|
48
|
+
|
49
|
+
#raycolor = @color.analog
|
50
|
+
#@color.drift(0.2,0.1,0.1)
|
51
|
+
@color.drift(huedrift, saturationdrift, brightnessdrift)
|
52
|
+
#for i in 0..@grains do ##RACK change to fixnum.times
|
53
|
+
(@grains + 1).times do |i|
|
54
|
+
# set alpha for this grain (ramp from maxalpha to 0.0 for i = 0 to 64)
|
55
|
+
a = @maxalpha - (i / @grains.to_f) * @maxalpha
|
56
|
+
fillcolor = @color.copy.a(a)
|
57
|
+
@canvas.fill(fillcolor)
|
58
|
+
#C.rect(ox+(x-ox)*sin(sin(i*w)),oy+(y-oy)*sin(sin(i*w)),1,1)
|
59
|
+
scaler = sin(sin(i * w)) # ramp sinusoidally from 0 to 1
|
60
|
+
x1 = ox + (x - ox) * scaler + random(-@jitter, @jitter)
|
61
|
+
y1 = oy + (y - oy) * scaler + random(-@jitter, @jitter)
|
62
|
+
#puts "#{scaler} #{w} #{i} #{a} => #{x1},#{y1} #{scaler}"
|
63
|
+
@canvas.oval(x1, y1, @grainsize, @grainsize, :center)
|
64
|
+
#C.oval(x,y,@grainsize,@grainsize,:center)
|
65
|
+
#C.oval(ox,oy,@grainsize,@grainsize,:center)
|
66
|
+
end
|
67
|
+
@canvas.pop
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Ruby Cocoa Graphics is a graphics library providing a simple object-oriented
|
2
|
+
# interface into the power of Mac OS X's Core Graphics and Core Image drawing libraries.
|
3
|
+
# With a few lines of easy-to-read code, you can write scripts to draw simple or complex
|
4
|
+
# shapes, lines, and patterns, process and filter images, create abstract art or visualize
|
5
|
+
# scientific data, and much more.
|
6
|
+
#
|
7
|
+
# Inspiration for this project was derived from Processing and NodeBox. These excellent
|
8
|
+
# graphics programming environments are more full-featured than RCG, but they are implemented
|
9
|
+
# in Java and Python, respectively. RCG was created to offer similar functionality using
|
10
|
+
# the Ruby programming language.
|
11
|
+
#
|
12
|
+
# Author:: James Reynolds (mailto:drtoast@drtoast.com)
|
13
|
+
# Copyright:: Copyright (c) 2008 James Reynolds
|
14
|
+
# License:: Distributes under the same terms as Ruby
|
15
|
+
|
16
|
+
module HotCocoa::Graphics
|
17
|
+
|
18
|
+
# draw a smooth gradient between any number of key colors
|
19
|
+
class Gradient
|
20
|
+
|
21
|
+
attr_reader :gradient, :drawpre, :drawpost
|
22
|
+
|
23
|
+
# create a new gradient from black to white
|
24
|
+
def initialize(*colors)
|
25
|
+
@colorspace = CGColorSpaceCreateWithName(KCGColorSpaceGenericRGB)
|
26
|
+
colors = colors[0] if colors[0].class == Array
|
27
|
+
set(colors)
|
28
|
+
pre(true)
|
29
|
+
post(true)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# create a gradient that evenly distributes the given colors
|
34
|
+
def set(colors)
|
35
|
+
colors ||= [Color.black, Color.white]
|
36
|
+
cgcolors = []
|
37
|
+
locations = []
|
38
|
+
increment = 1.0 / (colors.size - 1).to_f
|
39
|
+
i = 0
|
40
|
+
colors.each do |c|
|
41
|
+
cgcolor = CGColorCreate(@colorspace, [c.r, c.g, c.b, c.a])
|
42
|
+
cgcolors.push(cgcolor)
|
43
|
+
location = i * increment
|
44
|
+
locations.push(location)
|
45
|
+
i = i + 1
|
46
|
+
end
|
47
|
+
@gradient = CGGradientCreateWithColors(@colorspace, cgcolors, locations)
|
48
|
+
end
|
49
|
+
|
50
|
+
# extend gradient before start location? (true/false)
|
51
|
+
def pre(tf=nil)
|
52
|
+
@drawpre = (tf ? KCGGradientDrawsBeforeStartLocation : 0) unless tf.nil?
|
53
|
+
@drawpre
|
54
|
+
end
|
55
|
+
|
56
|
+
# extend gradient after end location? (true/false)
|
57
|
+
def post(tf=nil)
|
58
|
+
@drawpost = (tf ? KCGGradientDrawsAfterEndLocation : 0) unless tf.nil?
|
59
|
+
@drawpost
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|