Skip to content

Commit

Permalink
Merge branch 'master' into fast-lexer
Browse files Browse the repository at this point in the history
# Conflicts:
#	runtime/datatypes/string.reds
  • Loading branch information
dockimbel committed May 16, 2020
2 parents d862e74 + 172c5fb commit 83275f4
Show file tree
Hide file tree
Showing 12 changed files with 1,119 additions and 165 deletions.
2 changes: 2 additions & 0 deletions build/includes.r
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ write %build/bin/sources.r set-cache [
%handle.reds
%hash.reds
%image.reds
%image-utils.reds
%integer.reds
%issue.reds
%lit-path.reds
Expand Down Expand Up @@ -156,6 +157,7 @@ write %build/bin/sources.r set-cache [
%unset.reds
%url.reds
%vector.reds
%vector2d.reds
%word.reds
]
%platform/ [
Expand Down
189 changes: 128 additions & 61 deletions modules/view/backends/macOS/draw.reds
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ draw-begin: func [
]

ctx/raw: CGCtx
ctx/ctx-matrix: CGContextGetCTM CGCtx
ctx/matrix/a: F32_1
ctx/matrix/b: F32_0
ctx/matrix/c: F32_0
Expand Down Expand Up @@ -981,78 +982,119 @@ CG-draw-image: func [ ;@@ use CALayer to get very good performance?
width [integer!]
height [integer!]
/local
rc [NSRect!]
tx [float32!]
ty [float32!]
w [float32!]
h [float32!]
flip-x [float32!]
flip-y [float32!]
][
rc: make-rect x y width height
ty: rc/y + rc/h
either width < 0 [
w: as float32! 0 - width
flip-x: as float32! -1.0
][
w: as float32! width
flip-x: as float32! 1.0
]
tx: as float32! x
either height < 0 [
h: as float32! 0 - height
flip-y: as float32! 1.0
][
h: as float32! height
flip-y: as float32! -1.0
]
ty: as float32! y + height
;-- flip coords
;; drawing an image or PDF by calling Core Graphics functions directly,
;; we must flip the CTM.
;; http://stackoverflow.com/questions/506622/cgcontextdrawimage-draws-image-upside-down-when-passed-uiimage-cgimage
CGContextTranslateCTM dc as float32! 0.0 ty
CGContextScaleCTM dc as float32! 1.0 as float32! -1.0
CGContextTranslateCTM dc tx ty
CGContextScaleCTM dc flip-x flip-y

CGContextDrawImage dc rc/x as float32! 0.0 rc/w rc/h image
CGContextDrawImage dc as float32! 0.0 as float32! 0.0 w h image

;-- flip back
CGContextScaleCTM dc as float32! 1.0 as float32! -1.0
CGContextTranslateCTM dc as float32! 0.0 (as float32! 0.0) - ty
CGContextScaleCTM dc flip-x flip-y
CGContextTranslateCTM dc (as float32! 0.0) - tx (as float32! 0.0) - ty
]

OS-draw-image: func [
dc [draw-ctx!]
image [red-image!]
src [red-image!]
start [red-pair!]
end [red-pair!]
key-color [red-tuple!]
border? [logic!]
crop1 [red-pair!]
pattern [red-word!]
/local
img [integer!]
sub-img [integer!]
src.w [integer!]
src.h [integer!]
x [integer!]
y [integer!]
width [integer!]
height [integer!]
w [float32!]
h [float32!]
ww [float32!]
w [integer!]
h [integer!]
crop2 [red-pair!]
crop.x [integer!]
crop.y [integer!]
crop.w [integer!]
crop.h [integer!]
dst [red-image! value]
handle [integer!]
][
either null? start [x: 0 y: 0][x: start/x y: start/y]
case [
start = end [
width: IMAGE_WIDTH(image/size)
height: IMAGE_HEIGHT(image/size)
either any [
start + 2 = end
start + 3 = end
][
x: 0 y: 0 w: 0 h: 0
image/any-resize src dst crop1 start end :x :y :w :h
if dst/header = TYPE_NONE [exit]
handle: OS-image/to-cgimage dst
CG-draw-image dc/raw handle x y w h
OS-image/delete dst
][
src.w: IMAGE_WIDTH(src/size)
src.h: IMAGE_HEIGHT(src/size)
either null? start [x: 0 y: 0][x: start/x y: start/y]
unless null? crop1 [
crop2: crop1 + 1
crop.x: crop1/x
crop.y: crop1/y
crop.w: crop2/x
crop.h: crop2/y
if crop.x + crop.w > src.w [
crop.w: src.w - crop.x
]
if crop.y + crop.h > src.h [
crop.h: src.h - crop.y
]
]
start + 1 = end [ ;-- two control points
width: end/x - x
height: end/y - y
case [
start = end [
either null? crop1 [
w: src.w h: src.h
][
w: crop.w h: crop.h
]
]
start + 1 = end [
w: end/x - x
h: end/y - y
]
true [exit]
]
handle: OS-image/to-cgimage src
unless null? crop1 [
handle: CGImageCreateWithImageInRect handle
as float32! crop.x as float32! crop.y
as float32! crop.w as float32! crop.h
]
CG-draw-image dc/raw handle x y w h
unless null? crop1 [
CGImageRelease handle
]
start + 2 = end [0] ;@@ TBD three control points
true [0] ;@@ TBD four control points
]

img: OS-image/to-cgimage image
if crop1 <> null [
crop2: crop1 + 1
w: as float32! crop2/x
h: as float32! crop2/y
ww: w / h * (as float32! height)
width: as-integer ww
sub-img: CGImageCreateWithImageInRect
img
as float32! crop1/x
as float32! crop1/y
w
h
img: sub-img
]

CG-draw-image dc/raw img x y width height
if crop1 <> null [CGImageRelease img]
]

fill-gradient-region: func [
Expand Down Expand Up @@ -1337,10 +1379,19 @@ OS-matrix-scale: func [
dc [draw-ctx!]
pen [integer!]
sx [red-integer!]
sy [red-integer!]
center [red-pair!]
/local
sy [red-integer!]
][
sy: sx + 1
either pen = -1 [
if sx <> as red-integer! center [
_OS-matrix-translate dc/raw center/x center/y
]
CGContextScaleCTM dc/raw get-float32 sx get-float32 sy
if sx <> as red-integer! center [
_OS-matrix-translate dc/raw 0 - center/x 0 - center/y
]
][
dc/matrix: CGAffineTransformScale dc/matrix get-float32 sx get-float32 sy
]
Expand Down Expand Up @@ -1371,18 +1422,37 @@ OS-matrix-skew: func [
dc [draw-ctx!]
pen [integer!]
sx [red-integer!]
sy [red-integer!]
center [red-pair!]
/local
sy [red-integer!]
xv [float!]
yv [float!]
m [CGAffineTransform! value]
][
sy: sx + 1
xv: get-float sx
yv: either all [
sy <= center
TYPE_OF(sy) = TYPE_PAIR
][
get-float sy
][
0.0
]
m/a: as float32! 1.0
m/b: as float32! either sx = sy [0.0][tan degree-to-radians get-float sy TYPE_TANGENT]
m/c: as float32! tan degree-to-radians get-float sx TYPE_TANGENT
m/b: as float32! either yv = 0.0 [0.0][tan degree-to-radians yv TYPE_TANGENT]
m/c: as float32! tan degree-to-radians xv TYPE_TANGENT
m/d: as float32! 1.0
m/tx: as float32! 0.0
m/ty: as float32! 0.0
either pen = -1 [
if TYPE_OF(center) = TYPE_PAIR [
_OS-matrix-translate dc/raw center/x center/y
]
CGContextConcatCTM dc/raw m
if TYPE_OF(center) = TYPE_PAIR [
_OS-matrix-translate dc/raw 0 - center/x 0 - center/y
]
][
dc/matrix: CGAffineTransformConcat dc/matrix m
]
Expand All @@ -1402,7 +1472,7 @@ OS-matrix-transform: func [
center?: rotate <> center

_OS-matrix-translate dc/raw translate/x translate/y
OS-matrix-scale dc pen scale scale + 1
OS-matrix-scale dc pen scale center
OS-matrix-rotate dc pen rotate center
]

Expand Down Expand Up @@ -1431,22 +1501,19 @@ OS-matrix-pop: func [dc [draw-ctx!] state [draw-state!]][
]

OS-matrix-reset: func [
dc [draw-ctx!]
pen [integer!]
dc [draw-ctx!]
pen [integer!]
/local
m [CGAffineTransform! value]
ctx [handle!]
m [CGAffineTransform! value]
][
either dc/on-image? [
m: CGAffineTransformMake F32_1 F32_0 F32_0 as float32! -1.0 F32_0 dc/rect-y
][
m: CGAffineTransformMake F32_1 F32_0 F32_0 F32_1 as float32! 0.5 as float32! 0.5
]
CGContextSetCTM dc/raw m
ctx: dc/raw
CGContextSetCTM ctx dc/ctx-matrix
]

OS-matrix-invert: func [
dc [draw-ctx!]
pen [integer!]
dc [draw-ctx!]
pen [integer!]
/local
ctx [handle!]
m [CGAffineTransform! value]
Expand Down
Loading

0 comments on commit 83275f4

Please sign in to comment.