git.s-ol.nu alive / 070abf5
love: add text shape, line-width modifier s-ol 4 months ago
1 changed file(s) with 55 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
0 import Constant, Op, PureOp, Input, T, Array, any from require 'alv.base'
0 import Constant, Op, PureOp, Input, Error, T, Array, any from require 'alv.base'
11
22 unpack or= table.unpack
33
9292 @out\set ->
9393 love.graphics.rectangle mode, x, y, w, h
9494
95 text = Constant.meta
96 meta:
97 name: 'text'
98 summary: "create a text shape."
99 examples: { '(love/text str [align] [font])' }
100 description: "
101 Create a shape that draws the text `str` with font `font` (or the default font).
102 `align` should be on of the following strings:
103 - `center` (the default)
104 - `left`
105 - `right`"
106
107
108 value: class extends PureOp
109 pattern: any.str + -any.str + -any['love/font']
110 type: T['love/shape']
111
112 tick: =>
113 { text, align, font } = @unwrap_all!
114
115 wm = switch align or 'center'
116 when 'left' then 0
117 when 'center' then -0.5
118 when 'right' then -1
119 else
120 error Error 'argument', "unknown text alignment '#{align}'"
121
122 @out\set ->
123 font or= love.graphics.getFont!
124 width = font\getWidth text
125 height = font\getHeight!
126 love.graphics.print text, font, width*wm, -height/2
127
95128 color = Constant.meta
96129 meta:
97130 name: 'color'
109142 @out\set ->
110143 love.graphics.setColor r, g, b, a
111144 shape!
112 love.graphics.setColor 255, 255, 255
145 love.graphics.setColor 1, 1, 1
146
147 line_width = Constant.meta
148 meta:
149 name: 'line-width'
150 summary: "set line-width of a shape."
151 examples: { '(love/line-width width shape)' }
152
153 value: class extends PureOp
154 pattern: any.num + any['love/shape']
155 type: T['love/shape']
156
157 tick: =>
158 { width, shape } = @unwrap_all!
159
160 @out\set ->
161 love.graphics.setLineWidth width
162 shape!
163 love.graphics.setLineWidth 1
113164
114165 translate = Constant.meta
115166 meta:
252303 :draw
253304
254305 'no-shape': no_shape
255 :circle, :ellipse, :line, :rectangle
306 :circle, :ellipse, :line, :rectangle, :text
256307
257308 :translate, :rotate, :scale, :shear
258 :color
309 :color, 'line-width': line_width
259310
260311 'mouse-pos': mouse_pos