rubysketch 0.2.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,9 @@ module RubySketch
3
3
 
4
4
  class Window < Reflex::Window
5
5
 
6
- attr_accessor :setup, :update, :draw, :key, :motion, :resize,
7
- :pointer_down, :pointer_up, :pointer_move, :pointer_drag
6
+ attr_accessor :setup, :update, :draw, :before_draw, :after_draw, :resize,
7
+ :pointer_down, :pointer_up, :pointer_move, :pointer_drag,
8
+ :key, :motion
8
9
 
9
10
  attr_accessor :auto_resize
10
11
 
@@ -17,13 +18,11 @@ module RubySketch
17
18
 
18
19
  reset_canvas 1, 1
19
20
 
20
- super *args, size: [width, height] do |_|
21
- start &block if block
22
- end
21
+ super *args, size: [width, height], &block
23
22
  end
24
23
 
25
24
  def start (&block)
26
- @canvas_painter.paint do |_|
25
+ draw_canvas do
27
26
  block.call if block
28
27
  on_setup
29
28
  end
@@ -43,14 +42,12 @@ module RubySketch
43
42
  end
44
43
 
45
44
  def on_draw (e)
46
- @canvas_painter.paint do |painter|
47
- call_block @draw, e, painter
48
- end
45
+ draw_canvas {call_block @draw, e} if @draw
49
46
  e.painter.image @canvas
50
47
  end
51
48
 
52
49
  def on_key (e)
53
- call_block @key, e
50
+ draw_canvas {call_block @key, e} if @key
54
51
  end
55
52
 
56
53
  def on_pointer (e)
@@ -59,16 +56,16 @@ module RubySketch
59
56
  when :up then @pointer_up
60
57
  when :move then e.drag? ? @pointer_drag : @pointer_move
61
58
  end
62
- call_block block, e if block
59
+ draw_canvas {call_block block, e} if block
63
60
  end
64
61
 
65
62
  def on_motion (e)
66
- call_block @motion, e
63
+ draw_canvas {call_block @motion, e} if @motion
67
64
  end
68
65
 
69
66
  def on_resize (e)
70
67
  reset_canvas e.width, e.height if @auto_resize
71
- call_block @resize, e
68
+ draw_canvas {call_block @resize, e} if @resize
72
69
  end
73
70
 
74
71
  private
@@ -80,7 +77,7 @@ module RubySketch
80
77
  old_canvas = @canvas
81
78
  old_painter = @canvas_painter
82
79
 
83
- cs = old_canvas&.color_space || Rays::ColorSpace::RGBA
80
+ cs = old_canvas&.color_space || Rays::RGBA
84
81
  @canvas = Rays::Image.new width, height, cs, painter.pixel_density
85
82
  @canvas_painter = @canvas.painter
86
83
 
@@ -94,9 +91,29 @@ module RubySketch
94
91
  to.fill = from.fill
95
92
  to.stroke = from.stroke
96
93
  to.stroke_width = from.stroke_width
94
+ to.stroke_cap = from.stroke_cap
95
+ to.stroke_join = from.stroke_join
96
+ to.miter_limit = from.miter_limit
97
97
  to.font = from.font
98
98
  end
99
99
 
100
+ def draw_canvas (&block)
101
+ begin_draw
102
+ block.call
103
+ ensure
104
+ end_draw
105
+ end
106
+
107
+ def begin_draw ()
108
+ @canvas_painter.__send__ :begin_paint
109
+ @before_draw&.call
110
+ end
111
+
112
+ def end_draw ()
113
+ @after_draw&.call
114
+ @canvas_painter.__send__ :end_paint
115
+ end
116
+
100
117
  def call_block (block, event, *args)
101
118
  @events.push event
102
119
  block.call event, *args if block && !@error
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-28 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -103,6 +103,7 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
105
  - ".yardopts"
106
+ - ChangeLog.md
106
107
  - LICENSE
107
108
  - README.md
108
109
  - Rakefile
@@ -117,7 +118,6 @@ files:
117
118
  - lib/rubysketch/glsl.rb
118
119
  - lib/rubysketch/module.rb
119
120
  - lib/rubysketch/processing.rb
120
- - lib/rubysketch/starter.rb
121
121
  - lib/rubysketch/window.rb
122
122
  - rubysketch.gemspec
123
123
  homepage: https://github.com/xord/rubysketch
@@ -1,67 +0,0 @@
1
- module RubySketch
2
-
3
-
4
- extend module Functions
5
-
6
- def start (context, start_at_exit: false, &block)
7
- window = Window.new do
8
- context.instance_eval &block if block
9
- end
10
-
11
- context.on_start__ window
12
-
13
- start = proc do
14
- Reflex.start {window.show}
15
- end
16
-
17
- if start_at_exit
18
- at_exit {start.call unless $!}
19
- else
20
- start.call
21
- end
22
-
23
- window
24
- end
25
-
26
- private
27
-
28
- def start_on_object_at_exit (object, context)
29
- klass = context.class
30
- methods = klass.instance_methods(false)
31
- .reject {|name| name =~ /__$/}
32
- consts = klass.constants
33
- .reject {|name| name =~ /__$/}
34
- .each_with_object({}) {|name, h| h[name] = klass.const_get name}
35
-
36
- object.class.class_eval do
37
- methods.each do |name|
38
- define_method name do |*args, &block|
39
- context.__send__ name, *args, &block
40
- end
41
- end
42
- consts.each do |(name, value)|
43
- const_set name, value
44
- end
45
- end
46
-
47
- window = start context, start_at_exit: true
48
-
49
- window.canvas_painter.__send__ :begin_paint
50
- at_exit {window.canvas_painter.__send__ :end_paint}
51
- end
52
-
53
- self
54
-
55
- end# Functions
56
-
57
-
58
- module Starter
59
-
60
- def start (*args, &block)
61
- RubySketch.start self.new(*args), start_at_exit: true, &block
62
- end
63
-
64
- end# Starter
65
-
66
-
67
- end# RubySketch