glimmer-dsl-gtk 0.0.6 → 0.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3230b55893dbd6faaa1a5ba29d191e0f55586d6d6147e5274286162d02d972c
4
- data.tar.gz: ac79a95afc0e0f3cbaf37d501477beace1a810bdfdf82eb10d53d79094d2dedf
3
+ metadata.gz: c811aaa03169f5bb7754c7c07721bea6c1084d652878d55c75a9aa28f0fa6e56
4
+ data.tar.gz: 5c4ef408d97778f9defaa1f2fdd0df2f83e2d218fa0147317f8d3a68f69205f4
5
5
  SHA512:
6
- metadata.gz: 8258cdcf3a83e552a8b24b4ed1d431b1c79414f5ff8c0f4a17779e40b95bd648c8470ca8fa54fcaf7622e34a534828cb137c543d9217ae83df5f969a0636beca
7
- data.tar.gz: f01a32a3d485115028622c4235997c4018c369bf350fa23efbe6877a508afd047147c2f5a134e83367af007762d894f753ed2c3afb4bc2baddb7819ea42a7220
6
+ metadata.gz: 95e9f024283b4cb606f766f5230436d0caef9b55733ad7347cb45f3ef10e1d7d9555d375b177fe0d5d08091414572804f20b3ba9856f7946df7ccfc894b3428b
7
+ data.tar.gz: 0f381c56c69281dcd1bb9e6ec0391f58f101169da99e1c72ef14193425c7c3728b51cdd1b13169ac418d38ea3197c8adcc2c486b9586cd09aff4e07af2f86315
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.7
4
+
5
+ - samples/cairo/text.rb
6
+ - Support for `path` nested `show_text`, `text_path`, `show_glyphs`, `glyph_path`, `new_sub_path` operations
7
+
3
8
  ## 0.0.6
4
9
 
5
10
  - samples/cairo/clip_image.rb
@@ -18,6 +23,7 @@
18
23
  - Support declarative `fill`/`paint` of `image, x, y` in cairo graphics
19
24
  - Support declarative transforms on cairo graphics shapes: `translate`, `scale`, `rotate`
20
25
  - Support applying transform on `drawing_area` `paint`
26
+ - Support for `path` nested `rectangle`, `rounded_rectangle`, and `arc_negative` operations
21
27
 
22
28
  ## 0.0.5
23
29
 
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for GTK 0.0.6
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for GTK 0.0.7
2
2
  ## Ruby-GNOME Desktop Development GUI Library
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-gtk.svg)](http://badge.fury.io/rb/glimmer-dsl-gtk)
4
4
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
5
 
6
- [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [GTK](https://www.gtk.org/) enables building desktop applications with [Ruby-GNOME](https://github.com/ruby-gnome/ruby-gnome).
6
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [GTK](https://www.gtk.org/) enables building desktop applications with [Ruby-GNOME](https://github.com/ruby-gnome/ruby-gnome) (including [Cairo graphics](#declarative-cairo-graphics)).
7
7
 
8
8
  [GTK](https://www.gtk.org/) (aka GIMP-Toolkit or [incorrectly] GNOME-Toolkit) is the premiere desktop GUI toolkit on [Linux](https://www.gtk.org/docs/installations/linux/), which also runs on [Mac](https://www.gtk.org/docs/installations/macos/) ([Quartz GTK+](https://wiki.gnome.org/Projects/GTK/OSX)) and [Windows](https://www.gtk.org/docs/installations/windows).
9
9
 
@@ -80,7 +80,7 @@ gem install glimmer-dsl-gtk
80
80
 
81
81
  Add the following to `Gemfile`:
82
82
  ```
83
- gem 'glimmer-dsl-gtk', '~> 0.0.6'
83
+ gem 'glimmer-dsl-gtk', '~> 0.0.7'
84
84
  ```
85
85
 
86
86
  And, then run:
@@ -820,6 +820,61 @@ window {
820
820
 
821
821
  ![Set line join](/screenshots/glimmer-dsl-gtk-mac-cairo-set-line-join.png)
822
822
 
823
+ ### Text
824
+
825
+ [samples/cairo/text.rb](/samples/cairo/text.rb)
826
+
827
+ ```ruby
828
+ require 'glimmer-dsl-gtk'
829
+
830
+ include Glimmer
831
+
832
+ window {
833
+ title 'Text'
834
+ default_size 256, 256
835
+
836
+ drawing_area {
837
+ paint 242.25, 242.25, 242.25
838
+
839
+ font_family = OS.linux? ? 'Sans' : (OS.mac? ? 'Helvetica' : 'Arial')
840
+
841
+ # The main code
842
+ path {
843
+ move_to 10.0, 135.0
844
+ show_text 'Hello'
845
+
846
+ font_face font_family, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD
847
+ font_size 90.0
848
+ line_width 2.56
849
+ fill 0, 0, 0
850
+ stroke 0, 0, 0
851
+ }
852
+
853
+ path {
854
+ move_to 70.0, 165.0
855
+ text_path 'void'
856
+
857
+ font_face font_family, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD
858
+ font_size 90.0
859
+ line_width 2.56
860
+ fill 127.5, 127.5, 255
861
+ stroke 0, 0, 0
862
+ }
863
+
864
+ # draw helping lines
865
+ path {
866
+ arc 10.0, 135.0, 5.12, 0, 2*Math::PI
867
+ close_path
868
+ arc 70.0, 165.0, 5.12, 0, 2*Math::PI
869
+
870
+ fill 255, 51, 51, 0.6
871
+ }
872
+ }
873
+ }.show
874
+ ```
875
+
876
+ ![Text](/screenshots/glimmer-dsl-gtk-mac-cairo-text.png)
877
+
823
878
  ## Girb (Glimmer IRB)
824
879
 
825
880
  You can run the `girb` command (`bin/girb` if you cloned the project locally):
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
Binary file
@@ -93,6 +93,12 @@ module Glimmer
93
93
  cairo_context.set_matrix(previous_matrix)
94
94
  end
95
95
 
96
+ # TODO look into a way to generalize the declaration of the methods below (or perform code reuse)
97
+
98
+ def new_sub_path(*args)
99
+ @drawing_operations << [:new_sub_path, args]
100
+ end
101
+
96
102
  def arc(*args)
97
103
  @drawing_operations << [:arc, args]
98
104
  end
@@ -109,6 +115,22 @@ module Glimmer
109
115
  @drawing_operations << [:rounded_rectangle, args]
110
116
  end
111
117
 
118
+ def text_path(*args)
119
+ @drawing_operations << [:text_path, args]
120
+ end
121
+
122
+ def show_text(*args)
123
+ @drawing_operations << [:show_text, args]
124
+ end
125
+
126
+ def glyph_path(*args)
127
+ @drawing_operations << [:text_path, args]
128
+ end
129
+
130
+ def show_glyphs(*args)
131
+ @drawing_operations << [:show_text, args]
132
+ end
133
+
112
134
  def move_to(*args)
113
135
  @drawing_operations << [:move_to, args]
114
136
  end
@@ -125,12 +125,13 @@ module Glimmer
125
125
  prepend Transformable
126
126
 
127
127
  SHAPE_FILL_PROPERTIES = [:fill_rule]
128
- SHAPE_STROKE_PROPERTIES = [:dash, :font_face, :font_matrix, :font_options, :font_size, :line_cap, :line_join, :line_width, :miter_limit, :scaled_font]
128
+ SHAPE_STROKE_PROPERTIES = [:dash, :line_cap, :line_join, :line_width, :miter_limit, :scaled_font]
129
129
  SHAPE_GENERAL_PROPERTIES = [:matrix, :operator, :tolerance]
130
+ SHAPE_FONT_PROPERTIES = [:font_face, :font_matrix, :font_options, :font_size]
130
131
 
131
132
  attr_reader :parent, :args, :keyword, :block
132
133
  attr_accessor :fill, :stroke, :clip
133
- attr_accessor *(SHAPE_FILL_PROPERTIES + SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES)
134
+ attr_accessor *(SHAPE_FILL_PROPERTIES + SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES + SHAPE_FONT_PROPERTIES)
134
135
  # TODO consider automatically setting attribute accessors by looking up set_xyz methods on cairo context
135
136
 
136
137
  def initialize(keyword, parent, args, &block)
@@ -162,16 +163,19 @@ module Glimmer
162
163
  # Subclasses must either implement draw_shape hook method or override this method directly
163
164
  def draw(drawing_area_widget, cairo_context)
164
165
  if fill
166
+ draw_font(drawing_area_widget, cairo_context)
165
167
  draw_shape(drawing_area_widget, cairo_context)
166
168
  draw_fill(drawing_area_widget, cairo_context)
167
169
  end
168
170
 
169
171
  if stroke
172
+ draw_font(drawing_area_widget, cairo_context)
170
173
  draw_shape(drawing_area_widget, cairo_context)
171
174
  draw_stroke(drawing_area_widget, cairo_context)
172
175
  end
173
176
 
174
177
  if clip
178
+ draw_font(drawing_area_widget, cairo_context)
175
179
  draw_shape(drawing_area_widget, cairo_context)
176
180
  draw_clip(drawing_area_widget, cairo_context)
177
181
  end
@@ -194,19 +198,25 @@ module Glimmer
194
198
  previous_matrix = cairo_context.matrix
195
199
  apply_transforms(cairo_context, target: :fill)
196
200
  self.class.set_source_dynamically(cairo_context, fill)
197
- (SHAPE_FILL_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
198
- cairo_context.send("set_#{property}", *send(property)) if send(property)
201
+ (SHAPE_GENERAL_PROPERTIES + SHAPE_FILL_PROPERTIES).each do |property|
202
+ apply_property(cairo_context, property)
199
203
  end
200
204
  cairo_context.fill
201
205
  cairo_context.set_matrix(previous_matrix)
202
206
  end
203
207
 
208
+ def draw_font(drawing_area_widget, cairo_context)
209
+ SHAPE_FONT_PROPERTIES.each do |property|
210
+ apply_property(cairo_context, property)
211
+ end
212
+ end
213
+
204
214
  def draw_stroke(drawing_area_widget, cairo_context)
205
215
  previous_matrix = cairo_context.matrix
206
216
  apply_transforms(cairo_context, target: :stroke)
207
217
  self.class.set_source_dynamically(cairo_context, stroke)
208
- (SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
209
- cairo_context.send("set_#{property}", *send(property)) if send(property)
218
+ (SHAPE_GENERAL_PROPERTIES + SHAPE_STROKE_PROPERTIES).each do |property|
219
+ apply_property(cairo_context, property)
210
220
  end
211
221
  cairo_context.stroke
212
222
  cairo_context.set_matrix(previous_matrix)
@@ -216,12 +226,22 @@ module Glimmer
216
226
  previous_matrix = cairo_context.matrix
217
227
  apply_transforms(cairo_context, target: :clip)
218
228
  SHAPE_GENERAL_PROPERTIES.each do |property|
219
- cairo_context.send("set_#{property}", *send(property)) if send(property)
229
+ apply_property(cairo_context, property)
220
230
  end
221
231
  cairo_context.clip
222
232
  cairo_context.set_matrix(previous_matrix)
223
233
  end
224
234
 
235
+ def apply_property(cairo_context, property)
236
+ if send(property)
237
+ if property == :font_face
238
+ cairo_context.send("select_#{property}", *send(property))
239
+ else
240
+ cairo_context.send("set_#{property}", *send(property))
241
+ end
242
+ end
243
+ end
244
+
225
245
  def respond_to?(method_name, include_private = false, &block)
226
246
  method_name = method_name.to_s
227
247
  (method_name.start_with?('set_') && super("#{method_name.sub('set_', '')}=", include_private)) ||
@@ -0,0 +1,46 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Text'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ font_family = OS.linux? ? 'Sans' : (OS.mac? ? 'Helvetica' : 'Arial')
13
+
14
+ # The main code
15
+ path {
16
+ move_to 10.0, 135.0
17
+ show_text 'Hello'
18
+
19
+ font_face font_family, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD
20
+ font_size 90.0
21
+ line_width 2.56
22
+ fill 0, 0, 0
23
+ stroke 0, 0, 0
24
+ }
25
+
26
+ path {
27
+ move_to 70.0, 165.0
28
+ text_path 'void'
29
+
30
+ font_face font_family, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD
31
+ font_size 90.0
32
+ line_width 2.56
33
+ fill 127.5, 127.5, 255
34
+ stroke 0, 0, 0
35
+ }
36
+
37
+ # draw helping lines
38
+ path {
39
+ arc 10.0, 135.0, 5.12, 0, 2*Math::PI
40
+ close_path
41
+ arc 70.0, 165.0, 5.12, 0, 2*Math::PI
42
+
43
+ fill 255, 51, 51, 0.6
44
+ }
45
+ }
46
+ }.show
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-gtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -142,7 +142,8 @@ dependencies:
142
142
  - - ">"
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
- description: Glimmer DSL for GTK - Ruby-GNOME Desktop Development GUI Library
145
+ description: Glimmer DSL for GTK - Ruby-GNOME Desktop Development GUI Library - Supports
146
+ all GTK widgets and Cairo graphics
146
147
  email: andy.am@gmail.com
147
148
  executables:
148
149
  - girb
@@ -202,6 +203,7 @@ files:
202
203
  - samples/cairo/rounded_rectangle.rb
203
204
  - samples/cairo/set_line_cap.rb
204
205
  - samples/cairo/set_line_join.rb
206
+ - samples/cairo/text.rb
205
207
  - samples/elaborate/tetris.rb
206
208
  - samples/elaborate/tetris/model/block.rb
207
209
  - samples/elaborate/tetris/model/game.rb