minigl 1.3.10 → 2.0.0

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.
data/lib/minigl/text.rb CHANGED
@@ -1,4 +1,4 @@
1
- module AGL
1
+ module MiniGL
2
2
  # This class provides methods for easily drawing one or multiple lines of
3
3
  # text, with control over the text alignment and coloring.
4
4
  class TextHelper
@@ -8,7 +8,7 @@ module AGL
8
8
  # [font] A <code>Gosu::Font</code> that will be used to draw the text.
9
9
  # [line_spacing] When drawing multiple lines, the distance, in pixels,
10
10
  # between each line.
11
- def initialize font, line_spacing = 0
11
+ def initialize(font, line_spacing = 0)
12
12
  @font = font
13
13
  @line_spacing = line_spacing
14
14
  end
@@ -27,11 +27,24 @@ module AGL
27
27
  # [mode] The alignment of the text. Valid values are +:left+, +:right+ and
28
28
  # +:center+.
29
29
  # [color] The color of the text, in hexadecimal RRGGBB format.
30
+ # [effect] Effect to add to the text. It can be either +nil+, for no effect,
31
+ # +:border+ for bordered text, or +:shadow+ for shadowed text (the
32
+ # shadow is always placed below and to the right of the text).
33
+ # [effect_color] Color of the effect, if any.
34
+ # [effect_size] Size of the effect, if any. In the case of +:border+, this
35
+ # will be the width of the border (the border will only look
36
+ # good when +effect_size+ is relatively small, compared to the
37
+ # size of the font); in the case of +:shadow+, it will be the
38
+ # distance between the text and the shadow.
39
+ # [effect_alpha] Opacity of the effect, if any. For shadows, it is usual to
40
+ # provide less than 255.
30
41
  # [alpha] The opacity of the text. Valid values vary from 0 (fully
31
42
  # transparent) to 255 (fully opaque).
32
43
  # [z_index] The z-order to draw the object. Objects with larger z-orders
33
44
  # will be drawn on top of the ones with smaller z-orders.
34
- def write_line text, x, y, mode = :left, color = 0, alpha = 0xff, z_index = 0
45
+ def write_line(text, x, y, mode = :left, color = 0,
46
+ effect = nil, effect_color = 0, effect_size = 1, effect_alpha = 0xff,
47
+ alpha = 0xff, z_index = 0)
35
48
  color = (alpha << 24) | color
36
49
  rel =
37
50
  case mode
@@ -40,6 +53,21 @@ module AGL
40
53
  when :right then 1
41
54
  else 0
42
55
  end
56
+ if effect
57
+ effect_color = (effect_alpha << 24) | effect_color
58
+ if effect == :border
59
+ @font.draw_rel text, x - effect_size, y - effect_size, z_index, rel, 0, 1, 1, effect_color
60
+ @font.draw_rel text, x, y - effect_size, z_index, rel, 0, 1, 1, effect_color
61
+ @font.draw_rel text, x + effect_size, y - effect_size, z_index, rel, 0, 1, 1, effect_color
62
+ @font.draw_rel text, x + effect_size, y, z_index, rel, 0, 1, 1, effect_color
63
+ @font.draw_rel text, x + effect_size, y + effect_size, z_index, rel, 0, 1, 1, effect_color
64
+ @font.draw_rel text, x, y + effect_size, z_index, rel, 0, 1, 1, effect_color
65
+ @font.draw_rel text, x - effect_size, y + effect_size, z_index, rel, 0, 1, 1, effect_color
66
+ @font.draw_rel text, x - effect_size, y, z_index, rel, 0, 1, 1, effect_color
67
+ elsif effect == :shadow
68
+ @font.draw_rel text, x + effect_size, y + effect_size, z_index, rel, 0, 1, 1, effect_color
69
+ end
70
+ end
43
71
  @font.draw_rel text, x, y, z_index, rel, 0, 1, 1, color
44
72
  end
45
73
 
@@ -62,7 +90,7 @@ module AGL
62
90
  # transparent) to 255 (fully opaque).
63
91
  # [z_index] The z-order to draw the object. Objects with larger z-orders
64
92
  # will be drawn on top of the ones with smaller z-orders.
65
- def write_breaking text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0
93
+ def write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0)
66
94
  color = (alpha << 24) | color
67
95
  text.split("\n").each do |p|
68
96
  if mode == :justified
@@ -82,14 +110,14 @@ module AGL
82
110
 
83
111
  private
84
112
 
85
- def write_paragraph text, x, y, width, rel, color, z_index
86
- line = ""
113
+ def write_paragraph(text, x, y, width, rel, color, z_index)
114
+ line = ''
87
115
  line_width = 0
88
116
  text.split(' ').each do |word|
89
117
  w = @font.text_width word
90
118
  if line_width + w > width
91
119
  @font.draw_rel line.chop, x, y, z_index, rel, 0, 1, 1, color
92
- line = ""
120
+ line = ''
93
121
  line_width = 0
94
122
  y += @font.height + @line_spacing
95
123
  end
@@ -100,8 +128,8 @@ module AGL
100
128
  y + @font.height + @line_spacing
101
129
  end
102
130
 
103
- def write_paragraph_justified text, x, y, width, color, z_index
104
- space_width = @font.text_width " "
131
+ def write_paragraph_justified(text, x, y, width, color, z_index)
132
+ space_width = @font.text_width ' '
105
133
  spaces = [[]]
106
134
  line_index = 0
107
135
  new_x = x
Binary file
@@ -0,0 +1,73 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+ <svg
5
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
6
+ xmlns:cc="http://creativecommons.org/ns#"
7
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
+ xmlns:svg="http://www.w3.org/2000/svg"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
11
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
12
+ width="204"
13
+ height="24"
14
+ id="svg2"
15
+ version="1.1"
16
+ inkscape:version="0.48.4 r9939"
17
+ sodipodi:docname="barbg.svg"
18
+ inkscape:export-filename="/home/victor/Projects/TCC/minigl/test/data/img/barbg.png"
19
+ inkscape:export-xdpi="90"
20
+ inkscape:export-ydpi="90">
21
+ <defs
22
+ id="defs4" />
23
+ <sodipodi:namedview
24
+ id="base"
25
+ pagecolor="#ffffff"
26
+ bordercolor="#666666"
27
+ borderopacity="1.0"
28
+ inkscape:pageopacity="0.0"
29
+ inkscape:pageshadow="2"
30
+ inkscape:zoom="4"
31
+ inkscape:cx="127.40358"
32
+ inkscape:cy="-8.2431265"
33
+ inkscape:document-units="px"
34
+ inkscape:current-layer="layer1"
35
+ showgrid="false"
36
+ inkscape:window-width="1364"
37
+ inkscape:window-height="718"
38
+ inkscape:window-x="0"
39
+ inkscape:window-y="0"
40
+ inkscape:window-maximized="1" />
41
+ <metadata
42
+ id="metadata7">
43
+ <rdf:RDF>
44
+ <cc:Work
45
+ rdf:about="">
46
+ <dc:format>image/svg+xml</dc:format>
47
+ <dc:type
48
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
49
+ <dc:title></dc:title>
50
+ </cc:Work>
51
+ </rdf:RDF>
52
+ </metadata>
53
+ <g
54
+ inkscape:label="Layer 1"
55
+ inkscape:groupmode="layer"
56
+ id="layer1"
57
+ transform="translate(0,-1028.3622)">
58
+ <rect
59
+ style="fill:#ffffff;fill-opacity:1;stroke:none"
60
+ id="rect3753"
61
+ width="204"
62
+ height="24"
63
+ x="0"
64
+ y="1028.3622" />
65
+ <rect
66
+ style="fill:#ff0000;fill-opacity:1;stroke:none"
67
+ id="rect3755"
68
+ width="200"
69
+ height="20"
70
+ x="2"
71
+ y="1030.3622" />
72
+ </g>
73
+ </svg>
Binary file
@@ -0,0 +1,106 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+ <svg
5
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
6
+ xmlns:cc="http://creativecommons.org/ns#"
7
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
+ xmlns:svg="http://www.w3.org/2000/svg"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ xmlns:xlink="http://www.w3.org/1999/xlink"
11
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
12
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
13
+ width="20"
14
+ height="20"
15
+ id="svg2"
16
+ version="1.1"
17
+ inkscape:version="0.48.4 r9939"
18
+ sodipodi:docname="barfg.svg"
19
+ inkscape:export-filename="/home/victor/Projects/TCC/minigl/test/data/img/barfg.png"
20
+ inkscape:export-xdpi="90"
21
+ inkscape:export-ydpi="90">
22
+ <defs
23
+ id="defs4">
24
+ <linearGradient
25
+ id="linearGradient3778">
26
+ <stop
27
+ style="stop-color:#008000;stop-opacity:1;"
28
+ offset="0"
29
+ id="stop3780" />
30
+ <stop
31
+ id="stop3786"
32
+ offset="0.5"
33
+ style="stop-color:#00ff00;stop-opacity:1;" />
34
+ <stop
35
+ style="stop-color:#008000;stop-opacity:1;"
36
+ offset="1"
37
+ id="stop3782" />
38
+ </linearGradient>
39
+ <linearGradient
40
+ inkscape:collect="always"
41
+ xlink:href="#linearGradient3778"
42
+ id="linearGradient3784"
43
+ x1="0.51369864"
44
+ y1="1032.3622"
45
+ x2="0.52054793"
46
+ y2="1052.3965"
47
+ gradientUnits="userSpaceOnUse"
48
+ gradientTransform="scale(20,1)" />
49
+ </defs>
50
+ <sodipodi:namedview
51
+ id="base"
52
+ pagecolor="#ffffff"
53
+ bordercolor="#666666"
54
+ borderopacity="1.0"
55
+ inkscape:pageopacity="0.0"
56
+ inkscape:pageshadow="2"
57
+ inkscape:zoom="1"
58
+ inkscape:cx="10"
59
+ inkscape:cy="10"
60
+ inkscape:document-units="px"
61
+ inkscape:current-layer="layer1"
62
+ showgrid="false"
63
+ inkscape:window-width="1364"
64
+ inkscape:window-height="718"
65
+ inkscape:window-x="0"
66
+ inkscape:window-y="0"
67
+ inkscape:window-maximized="1" />
68
+ <metadata
69
+ id="metadata7">
70
+ <rdf:RDF>
71
+ <cc:Work
72
+ rdf:about="">
73
+ <dc:format>image/svg+xml</dc:format>
74
+ <dc:type
75
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
76
+ <dc:title />
77
+ </cc:Work>
78
+ </rdf:RDF>
79
+ </metadata>
80
+ <g
81
+ inkscape:label="Layer 1"
82
+ inkscape:groupmode="layer"
83
+ id="layer1"
84
+ transform="translate(0,-1032.3622)">
85
+ <rect
86
+ style="fill:url(#linearGradient3784);fill-opacity:1;stroke:none"
87
+ id="rect3776"
88
+ width="20"
89
+ height="20"
90
+ x="0"
91
+ y="1032.3622" />
92
+ <path
93
+ style="opacity:0.15;fill:#000000;fill-opacity:1;stroke:none"
94
+ d="M 0,0 0,10 10,0 z"
95
+ id="path3766"
96
+ inkscape:connector-curvature="0"
97
+ transform="translate(0,1032.3622)"
98
+ sodipodi:nodetypes="cccc" />
99
+ <path
100
+ sodipodi:nodetypes="ccccc"
101
+ inkscape:connector-curvature="0"
102
+ id="path3768"
103
+ d="m 10,1052.3622 10,-10 0,-10 -20,20 z"
104
+ style="opacity:0.15;fill:#000000;fill-opacity:1;stroke:none" />
105
+ </g>
106
+ </svg>
Binary file
@@ -0,0 +1,127 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+ <svg
5
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
6
+ xmlns:cc="http://creativecommons.org/ns#"
7
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
+ xmlns:svg="http://www.w3.org/2000/svg"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ xmlns:xlink="http://www.w3.org/1999/xlink"
11
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
12
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
13
+ width="10"
14
+ height="20"
15
+ id="svg2"
16
+ version="1.1"
17
+ inkscape:version="0.48.4 r9939"
18
+ sodipodi:docname="barfgl.svg"
19
+ inkscape:export-filename="/home/victor/Projects/TCC/minigl/test/data/img/barfgl.png"
20
+ inkscape:export-xdpi="90"
21
+ inkscape:export-ydpi="90">
22
+ <defs
23
+ id="defs4">
24
+ <linearGradient
25
+ id="linearGradient3770">
26
+ <stop
27
+ id="stop3772"
28
+ offset="0"
29
+ style="stop-color:#000000;stop-opacity:0.50196081;" />
30
+ <stop
31
+ style="stop-color:#000000;stop-opacity:0;"
32
+ offset="1"
33
+ id="stop3774" />
34
+ </linearGradient>
35
+ <linearGradient
36
+ id="linearGradient3778">
37
+ <stop
38
+ style="stop-color:#008000;stop-opacity:1;"
39
+ offset="0"
40
+ id="stop3780" />
41
+ <stop
42
+ id="stop3786"
43
+ offset="0.5"
44
+ style="stop-color:#00ff00;stop-opacity:1;" />
45
+ <stop
46
+ style="stop-color:#008000;stop-opacity:1;"
47
+ offset="1"
48
+ id="stop3782" />
49
+ </linearGradient>
50
+ <linearGradient
51
+ inkscape:collect="always"
52
+ xlink:href="#linearGradient3778"
53
+ id="linearGradient3784"
54
+ x1="0.51369864"
55
+ y1="1032.3622"
56
+ x2="0.52054793"
57
+ y2="1052.3965"
58
+ gradientUnits="userSpaceOnUse"
59
+ gradientTransform="scale(10,1)" />
60
+ <linearGradient
61
+ inkscape:collect="always"
62
+ xlink:href="#linearGradient3770"
63
+ id="linearGradient3768"
64
+ gradientUnits="userSpaceOnUse"
65
+ gradientTransform="scale(10,1)"
66
+ x1="3.6742588e-08"
67
+ y1="1042.328"
68
+ x2="0.99999994"
69
+ y2="1042.3281" />
70
+ </defs>
71
+ <sodipodi:namedview
72
+ id="base"
73
+ pagecolor="#ffffff"
74
+ bordercolor="#666666"
75
+ borderopacity="1.0"
76
+ inkscape:pageopacity="0.0"
77
+ inkscape:pageshadow="2"
78
+ inkscape:zoom="1"
79
+ inkscape:cx="15.856164"
80
+ inkscape:cy="10"
81
+ inkscape:document-units="px"
82
+ inkscape:current-layer="layer1"
83
+ showgrid="false"
84
+ inkscape:window-width="1364"
85
+ inkscape:window-height="718"
86
+ inkscape:window-x="0"
87
+ inkscape:window-y="0"
88
+ inkscape:window-maximized="1" />
89
+ <metadata
90
+ id="metadata7">
91
+ <rdf:RDF>
92
+ <cc:Work
93
+ rdf:about="">
94
+ <dc:format>image/svg+xml</dc:format>
95
+ <dc:type
96
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
97
+ <dc:title></dc:title>
98
+ </cc:Work>
99
+ </rdf:RDF>
100
+ </metadata>
101
+ <g
102
+ inkscape:label="Layer 1"
103
+ inkscape:groupmode="layer"
104
+ id="layer1"
105
+ transform="translate(0,-1032.3622)">
106
+ <rect
107
+ style="fill:url(#linearGradient3784);fill-opacity:1;stroke:none"
108
+ id="rect3776"
109
+ width="10"
110
+ height="20"
111
+ x="0"
112
+ y="1032.3622" />
113
+ <rect
114
+ y="1032.3622"
115
+ x="0"
116
+ height="20"
117
+ width="10"
118
+ id="rect3766"
119
+ style="fill:url(#linearGradient3768);fill-opacity:1;stroke:none" />
120
+ <path
121
+ sodipodi:nodetypes="ccccc"
122
+ inkscape:connector-curvature="0"
123
+ id="path3768"
124
+ d="m 0,1052.3622 10,-10 0,-10 -10,10 z"
125
+ style="opacity:0.15;fill:#000000;fill-opacity:1;stroke:none" />
126
+ </g>
127
+ </svg>
Binary file
@@ -0,0 +1,135 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+ <svg
5
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
6
+ xmlns:cc="http://creativecommons.org/ns#"
7
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
+ xmlns:svg="http://www.w3.org/2000/svg"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ xmlns:xlink="http://www.w3.org/1999/xlink"
11
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
12
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
13
+ width="10"
14
+ height="20"
15
+ id="svg2"
16
+ version="1.1"
17
+ inkscape:version="0.48.4 r9939"
18
+ sodipodi:docname="barfgr.svg"
19
+ inkscape:export-filename="/home/victor/Projects/TCC/minigl/test/data/img/barfgr.png"
20
+ inkscape:export-xdpi="90"
21
+ inkscape:export-ydpi="90">
22
+ <defs
23
+ id="defs4">
24
+ <linearGradient
25
+ id="linearGradient3770">
26
+ <stop
27
+ id="stop3772"
28
+ offset="0"
29
+ style="stop-color:#000000;stop-opacity:0.50196081;" />
30
+ <stop
31
+ style="stop-color:#000000;stop-opacity:0;"
32
+ offset="1"
33
+ id="stop3774" />
34
+ </linearGradient>
35
+ <linearGradient
36
+ id="linearGradient3778">
37
+ <stop
38
+ style="stop-color:#008000;stop-opacity:1;"
39
+ offset="0"
40
+ id="stop3780" />
41
+ <stop
42
+ id="stop3786"
43
+ offset="0.5"
44
+ style="stop-color:#00ff00;stop-opacity:1;" />
45
+ <stop
46
+ style="stop-color:#008000;stop-opacity:1;"
47
+ offset="1"
48
+ id="stop3782" />
49
+ </linearGradient>
50
+ <linearGradient
51
+ inkscape:collect="always"
52
+ xlink:href="#linearGradient3778"
53
+ id="linearGradient3784"
54
+ x1="0.51369864"
55
+ y1="1032.3622"
56
+ x2="0.52054793"
57
+ y2="1052.3965"
58
+ gradientUnits="userSpaceOnUse"
59
+ gradientTransform="scale(10,1)" />
60
+ <linearGradient
61
+ inkscape:collect="always"
62
+ xlink:href="#linearGradient3770"
63
+ id="linearGradient3768"
64
+ gradientUnits="userSpaceOnUse"
65
+ gradientTransform="matrix(10,0,0,1,-10,0)"
66
+ x1="3.6742588e-08"
67
+ y1="1042.328"
68
+ x2="0.99999994"
69
+ y2="1042.3281" />
70
+ </defs>
71
+ <sodipodi:namedview
72
+ id="base"
73
+ pagecolor="#ffffff"
74
+ bordercolor="#666666"
75
+ borderopacity="1.0"
76
+ inkscape:pageopacity="0.0"
77
+ inkscape:pageshadow="2"
78
+ inkscape:zoom="1"
79
+ inkscape:cx="-0.85616438"
80
+ inkscape:cy="10"
81
+ inkscape:document-units="px"
82
+ inkscape:current-layer="layer1"
83
+ showgrid="false"
84
+ inkscape:window-width="1364"
85
+ inkscape:window-height="718"
86
+ inkscape:window-x="0"
87
+ inkscape:window-y="0"
88
+ inkscape:window-maximized="1" />
89
+ <metadata
90
+ id="metadata7">
91
+ <rdf:RDF>
92
+ <cc:Work
93
+ rdf:about="">
94
+ <dc:format>image/svg+xml</dc:format>
95
+ <dc:type
96
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
97
+ <dc:title></dc:title>
98
+ </cc:Work>
99
+ </rdf:RDF>
100
+ </metadata>
101
+ <g
102
+ inkscape:label="Layer 1"
103
+ inkscape:groupmode="layer"
104
+ id="layer1"
105
+ transform="translate(0,-1032.3622)">
106
+ <rect
107
+ style="fill:url(#linearGradient3784);fill-opacity:1;stroke:none"
108
+ id="rect3776"
109
+ width="10"
110
+ height="20"
111
+ x="0"
112
+ y="1032.3622" />
113
+ <rect
114
+ y="1032.3622"
115
+ x="-10"
116
+ height="20"
117
+ width="10"
118
+ id="rect3766"
119
+ style="fill:url(#linearGradient3768);fill-opacity:1;stroke:none"
120
+ transform="scale(-1,1)" />
121
+ <path
122
+ style="opacity:0.15;fill:#000000;fill-opacity:1;stroke:none"
123
+ d="M 0,0 0,10 10,0 z"
124
+ id="path3797"
125
+ inkscape:connector-curvature="0"
126
+ transform="translate(0,1032.3622)"
127
+ sodipodi:nodetypes="cccc" />
128
+ <path
129
+ sodipodi:nodetypes="cccc"
130
+ inkscape:connector-curvature="0"
131
+ id="path3799"
132
+ d="m 10,1052.3622 0,-10 -10,10 z"
133
+ style="opacity:0.15;fill:#000000;fill-opacity:1;stroke:none" />
134
+ </g>
135
+ </svg>