rubysketch 0.3.1 → 0.3.2
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 +4 -4
- data/ChangeLog.md +8 -0
- data/VERSION +1 -1
- data/lib/rubysketch/processing.rb +73 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83aecf951db1320693714768446ccc95aa0a87f23012e02fff31b032c88be3c6
|
4
|
+
data.tar.gz: 6d1f67cbe65c15468cb606666acceacf19f56bf8c83dd1abae2a1b21d7daf94b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9946ba3029ce56a90042daa9be9e6c2f74f5d7ef7d318b5263b10c03ca35c26f5f7e67c61e6f78bd90f4224c267f732dcb937d86030adbe2b0ac51350a225f6e
|
7
|
+
data.tar.gz: 627eb17aa1e83da474f9ab9457b449b278ecf95d84956f98b82d3185c6bc87fa9b5788ad65c1144f80364171b14a4f7322d86a42066925ccbca8f2e19ff46cc3
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# RubySketch ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [0.3.2] - 2020-07-22
|
5
|
+
|
6
|
+
- text() draws to the baseline by default
|
7
|
+
- add textWidth(), textAscent(), textDescent() and textAlign()
|
8
|
+
- change initial color for fill() and stroke()
|
9
|
+
- change initial background color to grayscale 0.8
|
10
|
+
|
11
|
+
|
4
12
|
## [0.3.1] - 2020-07-17
|
5
13
|
|
6
14
|
- add touchStarted(), touchEnded(), touchMoved() and touches()
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -211,7 +211,7 @@ module RubySketch
|
|
211
211
|
#
|
212
212
|
CORNERS = :CORNERS
|
213
213
|
|
214
|
-
# Mode for rectMode(), ellipseMode() and
|
214
|
+
# Mode for rectMode(), ellipseMode(), imageMode() and textAlign().
|
215
215
|
#
|
216
216
|
CENTER = :CENTER
|
217
217
|
|
@@ -219,6 +219,21 @@ module RubySketch
|
|
219
219
|
#
|
220
220
|
RADIUS = :RADIUS
|
221
221
|
|
222
|
+
# Mode for textAlign().
|
223
|
+
LEFT = :LEFT
|
224
|
+
|
225
|
+
# Mode for textAlign().
|
226
|
+
RIGHT = :RIGHT
|
227
|
+
|
228
|
+
# Mode for textAlign().
|
229
|
+
TOP = :TOP
|
230
|
+
|
231
|
+
# Mode for textAlign().
|
232
|
+
BOTTOM = :BOTTOM
|
233
|
+
|
234
|
+
# Mode for textAlign().
|
235
|
+
BASELINE = :BASELINE
|
236
|
+
|
222
237
|
# Mode for strokeCap().
|
223
238
|
#
|
224
239
|
BUTT = :butt
|
@@ -235,7 +250,10 @@ module RubySketch
|
|
235
250
|
#
|
236
251
|
SQUARE = :square
|
237
252
|
|
238
|
-
def setup__ ()
|
253
|
+
def setup__ (painter)
|
254
|
+
@painter__ = painter
|
255
|
+
@painter__.miter_limit = 10
|
256
|
+
|
239
257
|
@drawing = false
|
240
258
|
@hsbColor__ = false
|
241
259
|
@colorMaxes__ = [1.0] * 4
|
@@ -243,6 +261,8 @@ module RubySketch
|
|
243
261
|
@rectMode__ = nil
|
244
262
|
@ellipseMode__ = nil
|
245
263
|
@imageMode__ = nil
|
264
|
+
@textAlignH__ = nil
|
265
|
+
@textAlignV__ = nil
|
246
266
|
@matrixStack__ = []
|
247
267
|
@styleStack__ = []
|
248
268
|
|
@@ -251,6 +271,10 @@ module RubySketch
|
|
251
271
|
rectMode CORNER
|
252
272
|
ellipseMode CENTER
|
253
273
|
imageMode CORNER
|
274
|
+
textAlign LEFT
|
275
|
+
|
276
|
+
fill 255
|
277
|
+
stroke 0
|
254
278
|
end
|
255
279
|
|
256
280
|
def beginDraw ()
|
@@ -288,10 +312,11 @@ module RubySketch
|
|
288
312
|
# @return [nil] nil
|
289
313
|
#
|
290
314
|
def colorMode (mode, *maxes)
|
315
|
+
mode = mode.upcase.to_sym
|
291
316
|
raise ArgumentError, "invalid color mode: #{mode}" unless [RGB, HSB].include?(mode)
|
292
317
|
raise ArgumentError unless [0, 1, 3, 4].include?(maxes.size)
|
293
318
|
|
294
|
-
@hsbColor__ = mode
|
319
|
+
@hsbColor__ = mode == HSB
|
295
320
|
case maxes.size
|
296
321
|
when 1 then @colorMaxes__ = [maxes.first.to_f] * 4
|
297
322
|
when 3, 4 then @colorMaxes__[0...maxes.size] = maxes.map &:to_f
|
@@ -335,7 +360,7 @@ module RubySketch
|
|
335
360
|
# @return [nil] nil
|
336
361
|
#
|
337
362
|
def angleMode (mode)
|
338
|
-
@angleScale__ = case mode
|
363
|
+
@angleScale__ = case mode.upcase.to_sym
|
339
364
|
when RADIANS then Utility::RAD2DEG__
|
340
365
|
when DEGREES then 1.0
|
341
366
|
else raise ArgumentError, "invalid angle mode: #{mode}"
|
@@ -523,6 +548,23 @@ module RubySketch
|
|
523
548
|
nil
|
524
549
|
end
|
525
550
|
|
551
|
+
def textWidth (str)
|
552
|
+
@painter__.font.width str
|
553
|
+
end
|
554
|
+
|
555
|
+
def textAscent ()
|
556
|
+
@painter__.font.ascent
|
557
|
+
end
|
558
|
+
|
559
|
+
def textDescent ()
|
560
|
+
@painter__.font.descent
|
561
|
+
end
|
562
|
+
|
563
|
+
def textAlign (horizontal, vertical = BASELINE)
|
564
|
+
@textAlignH__ = horizontal
|
565
|
+
@textAlignV__ = vertical
|
566
|
+
end
|
567
|
+
|
526
568
|
# @private
|
527
569
|
def setFont__ (name, size)
|
528
570
|
size = 256 if size && size > 256
|
@@ -758,15 +800,35 @@ module RubySketch
|
|
758
800
|
#
|
759
801
|
# @overload text(str)
|
760
802
|
# @overload text(str, x, y)
|
803
|
+
# @overload text(str, a, b, c, d)
|
761
804
|
#
|
762
805
|
# @param str [String] text to draw
|
763
806
|
# @param x [Numeric] horizontal position of the text
|
764
807
|
# @param y [Numeric] vertical position of the text
|
808
|
+
# @param a [Numeric] equivalent to parameters of the rect(), see rectMode()
|
809
|
+
# @param b [Numeric] equivalent to parameters of the rect(), see rectMode()
|
810
|
+
# @param c [Numeric] equivalent to parameters of the rect(), see rectMode()
|
811
|
+
# @param d [Numeric] equivalent to parameters of the rect(), see rectMode()
|
765
812
|
#
|
766
813
|
# @return [nil] nil
|
767
814
|
#
|
768
|
-
def text (str, x, y)
|
815
|
+
def text (str, x, y, x2 = nil, y2 = nil)
|
769
816
|
assertDrawing__
|
817
|
+
if x2
|
818
|
+
raise ArgumentError, "missing y2 parameter" unless y2
|
819
|
+
x, y, w, h = toXYWH__ @rectMode__, x, y, x2, y2
|
820
|
+
case @textAlignH__
|
821
|
+
when RIGHT then x += w - @painter__.font.width(str)
|
822
|
+
when CENTER then x += (w - @painter__.font.width(str)) / 2
|
823
|
+
end
|
824
|
+
case @textAlignV__
|
825
|
+
when BOTTOM then y += h - @painter__.font.height
|
826
|
+
when CENTER then y += (h - @painter__.font.height) / 2
|
827
|
+
else
|
828
|
+
end
|
829
|
+
else
|
830
|
+
y -= @painter__.font.ascent
|
831
|
+
end
|
770
832
|
@painter__.text str, x, y
|
771
833
|
nil
|
772
834
|
end
|
@@ -982,9 +1044,8 @@ module RubySketch
|
|
982
1044
|
include GraphicsContext
|
983
1045
|
|
984
1046
|
def initialize (width, height)
|
985
|
-
|
986
|
-
@image__
|
987
|
-
@painter__ = @image__.painter
|
1047
|
+
@image__ = Rays::Image.new width, height
|
1048
|
+
setup__ @image__.painter
|
988
1049
|
end
|
989
1050
|
|
990
1051
|
def beginDraw ()
|
@@ -1288,7 +1349,10 @@ module RubySketch
|
|
1288
1349
|
|
1289
1350
|
# @private
|
1290
1351
|
def setup__ (window)
|
1291
|
-
|
1352
|
+
@window__ = window
|
1353
|
+
@image__ = @window__.canvas
|
1354
|
+
super @window__.canvas_painter.paint {background 0.8}
|
1355
|
+
|
1292
1356
|
@loop__ = true
|
1293
1357
|
@redraw__ = false
|
1294
1358
|
@frameCount__ = 0
|
@@ -1297,12 +1361,6 @@ module RubySketch
|
|
1297
1361
|
@mousePressed__ = false
|
1298
1362
|
@touches__ = []
|
1299
1363
|
|
1300
|
-
@window__ = window
|
1301
|
-
@image__ = @window__.canvas
|
1302
|
-
@painter__ = @window__.canvas_painter
|
1303
|
-
|
1304
|
-
@painter__.miter_limit = 10
|
1305
|
-
|
1306
1364
|
@window__.before_draw = proc {beginDraw}
|
1307
1365
|
@window__.after_draw = proc {endDraw}
|
1308
1366
|
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|