rubysketch 0.2.7 → 0.3.0

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
 
@@ -21,7 +22,7 @@ module RubySketch
21
22
  end
22
23
 
23
24
  def start (&block)
24
- @canvas_painter.paint do |_|
25
+ draw_canvas do
25
26
  block.call if block
26
27
  on_setup
27
28
  end
@@ -41,9 +42,7 @@ module RubySketch
41
42
  end
42
43
 
43
44
  def on_draw (e)
44
- @canvas_painter.paint do |_|
45
- call_block @draw, e
46
- end
45
+ draw_canvas {call_block @draw, e}
47
46
  e.painter.image @canvas
48
47
  end
49
48
 
@@ -98,6 +97,23 @@ module RubySketch
98
97
  to.font = from.font
99
98
  end
100
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
+
101
117
  def call_block (block, event, *args)
102
118
  @events.push event
103
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.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-16 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard