22
33class RubyDraw < Processing ::App
44
5- require_relative 'main/string_object'
6- require_relative 'main/lines'
7- require_relative 'main/cursor'
8- require_relative 'main/parse'
9- require_relative 'main/description_list'
10- require_relative 'main/editor'
11- require_relative 'main/canvas'
12- require_relative 'main/watch'
5+ require_relative 'main/string_object'
6+ require_relative 'main/lines'
7+ require_relative 'main/cursor'
8+ require_relative 'main/parse'
9+ require_relative 'main/description_list'
10+ require_relative 'main/editor'
11+ require_relative 'main/canvas'
12+ require_relative 'main/watch'
1313
14- def setup
15- $width = 700
16- $height = 600
17- $editor_left_margin = 10
18- $editor_right_margin = 15
19- $editor_top_margin = 15
20- $start_of_editor_text = $width/2
21- $line_height = 13
22- $line_space = 2
14+ attr_reader :editor_left_margin , :editor_right_margin , :editor_top_margin , :start_of_editor_text , :line_height , :line_space , :pressed , :initial_arg_value
2315
16+ def setup
17+ size 700 , 600 # access with $app.width
18+ @editor_left_margin = 10
19+ @editor_right_margin = 15
20+ @editor_top_margin = 15
21+ @start_of_editor_text = 350
22+ @line_height = 13
23+ @line_space = 2
24+ @pressed = false #check if mouse pressed
2425
25- size 700 , 600 # needs to be hardcoded
2626 @lines = Lines . new
2727 @cursor = Cursor . new ( @lines )
2828 @parser = Parse . new ( @lines , @cursor )
@@ -39,23 +39,24 @@ def draw
3939 background 55
4040 @canvas . draw_canvas
4141 fill color 304 , 353 , 300
42- rect ( $width/2 ) -10 , 0 , ( $width/2 ) +10 , height
42+ rect ( $app . width /2 ) -10 , 0 , ( $app . width /2 ) +10 , height
4343 fill color 104 , 153 , 0
4444 @editor . draw_content
4545
4646
47- text "this is a DEMO app" , $width/2 , $height-40
48- text "write 'rect 20 20 200 200' and drag the values..." , $width/2 , $height-20
47+ text "this is a DEMO app" , $app . width /2 , $app . height -40
48+ text "write 'rect 20 20 200 200' and drag the values..." , $app . width /2 , $app . height -20
4949
5050 fill color 14 , 13 , 0
51- @cursor . draw_line
51+ @cursor . draw_line #we need a line marking the text position
5252 fill color 104 , 153 , 0
5353
5454 if mouse_pressed?
55+ sleep ( 0.2 ) #needed because of unintented param change line selection
5556 loop
5657 @watcher . check_param ( mouse_x , mouse_y )
5758 else
58- $ pressed = false
59+ @ pressed = false
5960 no_loop
6061 end
6162
@@ -73,8 +74,8 @@ def mouse_moved
7374
7475
7576 def mouse_pressed
76- $ pressed = [ mouse_x , mouse_y ]
77- $ initial_arg_value = @watcher . get_param ( mouse_x , mouse_y ) #get the initial value from watcher
77+ @ pressed = [ mouse_x , mouse_y ]
78+ @ initial_arg_value = @watcher . get_param ( mouse_x , mouse_y ) #get the initial value from watcher
7879 @cursor . set_position ( mouse_x , mouse_y )
7980 redraw
8081 end
0 commit comments