nyle 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42ab8fbeb3f524b4e03c3007e5021196296a4492e62ba78ae2b5a596dcb02a46
4
- data.tar.gz: 365227d4c2aaf246b5ed0f17cc928b179c533cf90f258fd4533106e91701bd66
3
+ metadata.gz: 693c8de3045e3e2da3cf72a117fff8a29cad2e0952626e9af1dfe11f2d23576d
4
+ data.tar.gz: de724f1bf413b8dce0c3ae243ad108119179872905fbd975f5d175cd9db41f4e
5
5
  SHA512:
6
- metadata.gz: 330e8bac463e481d5066c9313ca6ea94cde526727ec88b9e21f1e9bf27259dab1862dfc60bfd32714591e2ac0c2c3887a46c16262e3c6279bcc46bbd6cc5775a
7
- data.tar.gz: 1b98f3ef0709b13780a335109c5e880a1c371c3993598585ff82845f8e66b966a4365809fd0427cb1cc647db7e444d3d8d7bbe44f1d42452b880a0e38f8d8d60
6
+ metadata.gz: 530eec7b56aa8713b663a770d9adc2f62dc1655b0286820d829598728fe132957d050044f9e21b3b2aaca1f041fc1bbd39e3eb8364f58698a61e18b9fd8d6afe
7
+ data.tar.gz: a83a81cb91efe31be12b009010b470cf722db8f109fe7fefe0a590153a66d1791ec562f09a04ae3f58f19abcf7b5e8e782cedd60d187b6543fe3cdc2cdfa4ee8
data/.gitignore CHANGED
@@ -1,8 +1,10 @@
1
1
  desktop.ini
2
2
  *.gem
3
3
  bin/
4
+ pkg/
4
5
  doc/*.docx
5
6
  samples/.bundle/
6
7
  samples/Gemfile
7
8
  samples/Gemfile.lock
8
- samples/readme_torun.txt
9
+ samples/sketch.png
10
+ samples/t_*.rb
@@ -0,0 +1,71 @@
1
+
2
+ ### 0.6.0 (2018/12/01)
3
+ #### New features
4
+ * add `Nyle.pixel` method
5
+ * add `Nyle.pixel?` method
6
+ * add `Nyle.save` method
7
+ * enhance `Nyle::Frame#set_current` to use container widget of GTK3
8
+
9
+ #### Bug fixes, etc.
10
+ * add defintion of key names
11
+ * define constant of mouse buttons
12
+ * move key/mouse state process to :draw signal handler in `Nyle::Screen`
13
+
14
+ #### Reference manual
15
+ * revise
16
+
17
+ #### Samples
18
+ * use `MOUSE_L` `MOUSE_R`
19
+ * add `nyle_click.rb`
20
+ * add `nyle_clock.rb`
21
+ * add `nyle_flight.rb`
22
+ * add `nyle_pixel.rb`
23
+ * add `nyle_sugar.rb`
24
+
25
+
26
+ ### 0.5.2 (2018/11/11)
27
+ #### New features
28
+ * release as RubyGems
29
+ * add `Nyle.draw_shape` method
30
+ * add `a`(alpha value) option in `Nyle.draw_*`
31
+ * add `Nyle::Scneen#suspend` method and `Nyle::Scneen#resume` method
32
+ * give `?` letter to method which returns true ot false
33
+
34
+
35
+ ### 0.4.0 (2018/11/04)
36
+ #### New features
37
+
38
+ * add `Nyle.load_image_tiles` method
39
+ * add `Nyle.screen_width` method
40
+ * add `Nyle.screen_height` method
41
+ * add `cw` and `ch` option in `Nyle.load_image` method
42
+
43
+ #### Bug fixes, etc.
44
+ * delete `set_default_size` (using gtk3-3.3.0)
45
+
46
+ #### Samples
47
+ * adjust calling `Nyle.load_image` method at `initialize`
48
+
49
+
50
+ ### 0.3.0 (2018/11/02)
51
+ #### Bug fixes, etc.
52
+
53
+ * change `_set_cr(widget.window.create_cairo_context)` to `_set_cr(cairo_context)`
54
+ (`Class Nyle::Screen` `signal_connect(:draw)`)
55
+ * change `set_default_size` to `set_size_request` (except on Windows)
56
+ (`Class Nyle::frame` `initialize`)
57
+ * add `Nyle.os` (for internal)
58
+ * delete `NYLE_SCALE` environment variable
59
+
60
+
61
+ ### 0.2.0 (2018/11/01)
62
+ * Bug fixes, etc.
63
+
64
+
65
+ ### 0.1.0 (2018/10/28)
66
+ * release
67
+
68
+
69
+ ### 0.0.1 (2018/09/16)
70
+ * trial release
71
+
data/README.md CHANGED
@@ -5,7 +5,6 @@
5
5
  ## Requirements
6
6
 
7
7
  * Ruby/GTK3
8
- * rsvg2 (for Windows only)
9
8
 
10
9
  ## Installation
11
10
 
@@ -13,11 +12,6 @@ Install it yourself as:
13
12
 
14
13
  $ gem install nyle
15
14
 
16
- Or for Windows
17
-
18
- $ gem install nyle
19
- $ gem rsvg2
20
-
21
15
  ## Usage
22
16
 
23
17
  ```ruby
@@ -30,7 +24,7 @@ Reference manual: https://github.com/spoolkitamura/nyle/tree/master/doc/Nyle_ref
30
24
 
31
25
  ## Samples
32
26
 
33
- Reference manual: https://github.com/spoolkitamura/nyle/tree/master/samples
27
+ Sample programs: https://github.com/spoolkitamura/nyle/tree/master/samples
34
28
 
35
29
  ## License
36
30
 
Binary file
@@ -15,6 +15,15 @@ require 'nyle/version'
15
15
  require 'nyle/frame'
16
16
  require 'nyle/screen'
17
17
 
18
+ Gdk::Keyval.constants.each do |c|
19
+ #puts "#{c} #{Gdk::Keyval.const_get(c)}"
20
+ eval("#{c} = #{Gdk::Keyval.const_get(c)}") # key name definication to omit 'Gdk::Keyval::'
21
+ end
22
+
23
+ MOUSE_L = 1
24
+ MOUSE_M = 2
25
+ MOUSE_R = 3
26
+
18
27
  module Nyle
19
28
  class Error < StandardError; end
20
29
 
@@ -133,6 +142,13 @@ module Nyle
133
142
  module_function def mask_shift? ; Nyle.module_eval{ @__mask_shift } ; end
134
143
  module_function def os ; Nyle.module_eval{ @__os } ; end
135
144
 
145
+ module_function def save
146
+ cr = Nyle.module_eval{ @__cr }
147
+ cr.save do
148
+ yield
149
+ end
150
+ end
151
+
136
152
  module_function def draw_line(x1, y1, x2, y2, weight: 2, cap: :BUTT, color: :BLACK, a: 1.0)
137
153
  cr = Nyle.module_eval{ @__cr }
138
154
  cr.save do
@@ -295,6 +311,32 @@ module Nyle
295
311
  cr.target.write_to_png(filename)
296
312
  end
297
313
 
314
+ module INNER
315
+ # for Nyle.pixel* methods
316
+ class << self
317
+ private def _pixel(x, y)
318
+ cr = Nyle.module_eval{ @__cr }
319
+ surface = cr.target
320
+ address = surface.width * (y * 4) + (x * 4)
321
+ color = surface.data.byteslice(address, 4).unpack("H*").first.upcase # e.g. '\xcc\x77\x00\xff -> ['cc7700ff'] -> 'CC7700FF'
322
+ color = '#' +
323
+ color.slice(4, 2) +
324
+ color.slice(2, 2) +
325
+ color.slice(0, 2) +
326
+ color.slice(6, 2) # BBGGRRAA -> #RRGGBBAA
327
+ end
328
+ end
329
+ end
330
+
331
+ module_function def pixel(x, y)
332
+ Nyle::INNER.module_eval{ _pixel(x, y) }
333
+ end
334
+
335
+ module_function def pixel?(x, y, color)
336
+ c = Nyle::INNER.module_eval{ _pixel(x, y) }
337
+ return (c == Cairo::Color.parse(color).to_s ? true : false)
338
+ end
339
+
298
340
  module_function def translate(tx, ty)
299
341
  cr = Nyle.module_eval{ @__cr }
300
342
  cr.translate(tx, ty)
@@ -24,10 +24,6 @@ module Nyle
24
24
  @interval_time = 15 if @interval_time < 5 or @interval_time > 60
25
25
  GLib::Timeout.add(@interval_time) do
26
26
  if @current_screen
27
- Nyle.module_eval {
28
- _update_mouse_state
29
- _update_key_state
30
- }
31
27
  update
32
28
  @current_screen.queue_draw unless @current_screen.destroyed?
33
29
  end
@@ -80,10 +76,25 @@ module Nyle
80
76
  _set_current(screen)
81
77
  end
82
78
 
83
- private def _set_current(screen)
84
- self.remove(@current_screen) if @current_screen
85
- @current_screen = screen
86
- self.add(@current_screen)
79
+ private def _set_current(widget)
80
+ if widget.is_a?(Nyle::Screen)
81
+ self.remove(@current_screen) if @current_screen
82
+ @current_screen = widget
83
+ self.add(@current_screen) # add instance which is kind of Nyle::Screen
84
+ else
85
+ screen = nil
86
+ widget.each do |child|
87
+ if child.is_a?(Nyle::Screen)
88
+ screen = child # get instance which is kind of Nyle::Screen from container
89
+ break
90
+ end
91
+ end
92
+ if screen
93
+ self.remove(@current_screen) if @current_screen
94
+ @current_screen = screen
95
+ self.add(widget) # add container
96
+ end
97
+ end
87
98
  w = @current_screen.width
88
99
  h = @current_screen.height
89
100
  Nyle.module_eval {
@@ -13,7 +13,6 @@ module Nyle
13
13
 
14
14
  # Screen
15
15
  class Screen < Gtk::DrawingArea
16
- include Gdk::Keyval # Include key definication to omit 'Gdk::Keyval::' for subclass
17
16
  attr_reader :width, :height, :status
18
17
  def initialize(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, bgcolor: :WHITE, trace: false)
19
18
  super()
@@ -24,25 +23,20 @@ module Nyle
24
23
  @running_count = 0
25
24
  @status = nil
26
25
 
26
+ @fill_done = false
27
+
27
28
  # Draw to 'CairoContext' of ImageSurface once, and copy to 'CairoContext' of DrawingArea
28
- if @trace
29
- # specified color background
30
- # [WARN] Segmentation Fault happen after a while
31
- #data = sprintf("%02X%02X%02X%02X", Cairo::Color.parse(@bgcolor).b * 255,
32
- # Cairo::Color.parse(@bgcolor).g * 255,
33
- # Cairo::Color.parse(@bgcolor).r * 255, 255) # Hex (e.g. CC7700FF; b=CC, g=77, r=00, a=FF)
34
- #data = [data].pack("H*") # Pack as binary (e.g. \xCC\x77\x00\xFF)
35
- #@canvas = Cairo::ImageSurface.new(data * @width * @height, :ARGB32, @width, @height, @width * 4)
36
- @canvas = Cairo::ImageSurface.new(@width, @height)
37
- else
38
- # transparent background
39
- @canvas = Cairo::ImageSurface.new(@width, @height)
40
- end
29
+ @canvas = Cairo::ImageSurface.new(@width, @height)
30
+
41
31
  self.signal_connect(:configure_event) do |widget, event|
42
32
  ; # For resizing and so on
43
33
  end
44
34
 
45
35
  self.signal_connect(:draw) do |widget, cairo_context|
36
+ Nyle.module_eval {
37
+ _update_mouse_state
38
+ _update_key_state
39
+ }
46
40
  # Draw to 'CairoContext' of ImageSurface
47
41
  Cairo::Context.new(@canvas) do |cr|
48
42
  Nyle.module_eval {
@@ -51,6 +45,12 @@ module Nyle
51
45
  unless @trace # If not trace, fill screen each time
52
46
  Nyle.cr.set_source_color(@bgcolor)
53
47
  Nyle.cr.paint
48
+ else
49
+ unless @fill_done
50
+ Nyle.cr.set_source_color(@bgcolor) # fill once
51
+ Nyle.cr.paint
52
+ @fill_done = true
53
+ end
54
54
  end
55
55
  update
56
56
  draw
@@ -73,7 +73,7 @@ module Nyle
73
73
  # Signal handler for mouse position
74
74
  self.signal_connect(:motion_notify_event) do |widget, event|
75
75
  Nyle.module_eval {
76
- _set_mouse_pos(event.x, event.y)
76
+ _set_mouse_pos(event.x.to_i, event.y.to_i)
77
77
  }
78
78
  false
79
79
  end
@@ -83,11 +83,6 @@ module Nyle
83
83
  def show_all(title = DEFAULT_TITLE)
84
84
  f = Nyle::Frame.new(@width, @height, {title: title})
85
85
  f.set_current(self)
86
-
87
- # Workaround for Segmentation Fault when ImageSureface instance create by using RGBA32 data at Screen.initialize
88
- f.override_background_color(:normal, Gdk::RGBA::new(Cairo::Color.parse(@bgcolor).r,
89
- Cairo::Color.parse(@bgcolor).g,
90
- Cairo::Color.parse(@bgcolor).b, 1.0))
91
86
  f.show_all
92
87
  f
93
88
  end
@@ -1,3 +1,3 @@
1
1
  module Nyle
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Koki Kitamura"]
10
10
  spec.email = ["spool.kitamura@nifty.ne.jp"]
11
11
 
12
- spec.summary = %q{minimal graphics framework using Ruby/GTK3 with Cairo}
13
- spec.description = %q{'Nyle' is a minimal graphics framework using Ruby/GTK3 with Cairo}
12
+ spec.summary = %q{minimal graphics framework using Ruby/GTK3 and Cairo}
13
+ spec.description = %q{'Nyle' is a minimal graphics framework using Ruby/GTK3 and Cairo}
14
14
  spec.homepage = "https://github.com/spoolkitamura/nyle"
15
15
  spec.license = "MIT"
16
16
 
@@ -32,7 +32,7 @@ class Screen < Nyle::Screen
32
32
  Nyle.draw_rect(540, 200, 60, 30, {color: :ORANGE, fill: true, round: 5, a: 0.6})
33
33
 
34
34
  Nyle.draw_rect( 45, 250, 50, 30, {weight: 3, color: :GOLD})
35
- Nyle.cr.save do
35
+ Nyle.save do
36
36
  for i in (1..5) do
37
37
  # rectangle (coordinate transformation)
38
38
  Nyle.rotate(Math::PI / 80)
@@ -55,7 +55,7 @@ class Screen < Nyle::Screen
55
55
  puts "[ctrl] + [shift]" if Nyle.mask_control? and Nyle.mask_shift?
56
56
 
57
57
  # mouse status
58
- for k in (1..3)
58
+ [MOUSE_L, MOUSE_M, MOUSE_R].each do |k|
59
59
  puts "Nyle.mouse_press?(#{k})" if Nyle.mouse_press?(k)
60
60
  end
61
61
 
@@ -33,7 +33,7 @@ class Screen < Nyle::Screen
33
33
  draw_rect(540, 200, 60, 30, {color: :ORANGE, fill: true, round: 5, a: 0.6})
34
34
 
35
35
  draw_rect( 45, 250, 50, 30, {weight: 3, color: :GOLD})
36
- cr.save do
36
+ save do
37
37
  for i in (1..5) do
38
38
  # rectangle (coordinate transformation)
39
39
  rotate(Math::PI / 80)
@@ -56,7 +56,7 @@ class Screen < Nyle::Screen
56
56
  puts "[ctrl] + [shift]" if mask_control? and mask_shift?
57
57
 
58
58
  # mouse status
59
- for k in (1..3)
59
+ [MOUSE_L, MOUSE_M, MOUSE_R].each do |k|
60
60
  puts "mouse_press?(#{k})" if mouse_press?(k)
61
61
  end
62
62
 
@@ -97,10 +97,10 @@ class Ball
97
97
  @x = x
98
98
  @y = y
99
99
  @r = 10
100
- @dx = 4
101
- @dy = -4
100
+ @dx = 5
101
+ @dy = -5
102
102
  end
103
-
103
+
104
104
  def update(walls, blocks, paddle)
105
105
  @x +=@dx
106
106
  if _atari_array?(walls) or _atari?(paddle)
@@ -0,0 +1,34 @@
1
+
2
+ require 'nyle'
3
+
4
+ class Screen < Nyle::Screen
5
+ def initialize
6
+ super
7
+ @image1 = Nyle.load_image("./image/n_f_strawberry.png")
8
+ calc_xy
9
+ end
10
+
11
+ def draw
12
+ Nyle.draw_image(@x, @y, @image1)
13
+ calc_xy if clicked?
14
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
15
+ end
16
+
17
+ def calc_xy
18
+ @x = rand(Nyle.screen_width - @image1.width)
19
+ @y = rand(Nyle.screen_height - @image1.height)
20
+ end
21
+
22
+ def clicked?
23
+ Nyle.mouse_press?(MOUSE_L) and
24
+ Nyle.mouse_x >= @x and
25
+ Nyle.mouse_x <= @x + @image1.width and
26
+ Nyle.mouse_y >= @y and
27
+ Nyle.mouse_y <= @y + @image1.height
28
+ end
29
+ end
30
+
31
+
32
+ Screen.new.show_all
33
+ Gtk.main
34
+
@@ -0,0 +1,57 @@
1
+
2
+ require 'nyle'
3
+
4
+ class Screen < Nyle::Screen
5
+ def initialize
6
+ super(240, 240, {bgcolor: :FOREST_GREEN})
7
+ @radius = 0.42
8
+ end
9
+
10
+ def draw
11
+ Nyle.scale(Nyle.screen_width, Nyle.screen_height);
12
+ Nyle.translate(0.5, 0.5);
13
+
14
+ Nyle.draw_circle(0, 0, @radius, {color: :WHITE, fill: true})
15
+ Nyle.draw_circle(0, 0, @radius, {weight: 0.05})
16
+
17
+ # clock ticks
18
+ for i in (0...12) do
19
+ inset = (i % 3 == 0 ? 0.05 : 0.03)
20
+ Nyle.draw_line((@radius - inset) * Math::cos(i * Math::PI / 6),
21
+ (@radius - inset) * Math::sin(i * Math::PI / 6),
22
+ (@radius) * Math::cos(i * Math::PI / 6),
23
+ (@radius) * Math::sin(i * Math::PI / 6), {cap: :ROUND, weight: inset})
24
+ end
25
+
26
+ # store the current time
27
+ tm = Time.now
28
+ # puts "#{tm.hour} #{tm.min} #{tm.sec}"
29
+
30
+ # compute the angles of the indicators of our clock
31
+ hours = tm.hour * Math::PI / 6;
32
+ minutes = tm.min * Math::PI / 30;
33
+ seconds = tm.sec * Math::PI / 30;
34
+
35
+ # draw the hours hand
36
+ Nyle.draw_line(0, 0, Math::sin(hours + minutes / 12) * (@radius * 0.5),
37
+ -Math::cos(hours + minutes / 12) * (@radius * 0.5), {cap: :ROUND, color: :FOREST_GREEN, weight: 0.05})
38
+
39
+ # draw the minutes hand
40
+ Nyle.draw_line(0, 0, Math::sin(minutes + seconds / 60) * (@radius * 0.8),
41
+ -Math::cos(minutes + seconds / 60) * (@radius * 0.8), {cap: :ROUND, color: :BLUE, weight: 0.05})
42
+
43
+ # draw the seconds hand
44
+ Nyle.draw_line(0, 0, Math::sin(seconds) * (@radius * 0.9),
45
+ -Math::cos(seconds) * (@radius * 0.9), {cap: :ROUND, color: :RED, weight: 0.05 / 3})
46
+
47
+ # draw a little dot in the middle
48
+ Nyle.draw_circle(0, 0, 0.05 / 2, {fill: true})
49
+
50
+ Nyle.quit if Nyle.key_press?(KEY_Escape)
51
+ end
52
+ end
53
+
54
+
55
+ Screen.new.show_all
56
+ Gtk.main
57
+