@@ -52,38 +52,38 @@ Button.properties:
5252 imageMarginLeft
5353 image
5454
55- proc newButton * (w: Window , r: Rect ): Button =
55+ proc newButton * (gfx: GraphicsContext , r: Rect ): Button =
5656 result .new ()
57- result .init (w , r)
57+ result .init (gfx , r)
5858
59- proc newButton * (parent: View = nil , w: Window , position: Point = newPoint (0 , 0 ), size: Size = newSize (100 , 20 ), title: string = " Button" ): Button =
60- result = newButton (w , newRect (position.x, position.y, size.width, size.height))
59+ proc newButton * (parent: View = nil , gfx: GraphicsContext , position: Point = newPoint (0 , 0 ), size: Size = newSize (100 , 20 ), title: string = " Button" ): Button =
60+ result = newButton (gfx , newRect (position.x, position.y, size.width, size.height))
6161 result .title = title
6262 if not isNil (parent):
6363 parent.addSubview (result )
6464
65- proc newCheckbox * (w: Window , r: Rect ): Button =
66- result = newButton (w , r)
65+ proc newCheckbox * (gfx: GraphicsContext , r: Rect ): Button =
66+ result = newButton (gfx , r)
6767 result .style = bsCheckbox
6868 result .behavior = bbToggle
6969
70- proc newRadiobox * (w: Window , r: Rect ): Button =
71- result = newButton (w , r)
70+ proc newRadiobox * (gfx: GraphicsContext , r: Rect ): Button =
71+ result = newButton (gfx , r)
7272 result .style = bsRadiobox
7373 result .behavior = bbToggle
7474
75- proc newImageButton * (w: Window , r: Rect ): Button =
76- result = newButton (w , r)
75+ proc newImageButton * (gfx: GraphicsContext , r: Rect ): Button =
76+ result = newButton (gfx , r)
7777 result .style = bsImage
7878
79- proc newImageButton * (parent: View = nil , w: Window , position: Point = newPoint (0 , 0 ), size: Size = newSize (100 , 20 ), image: Image = nil ): Button =
80- result = newImageButton (w , newRect (position.x, position.y, size.width, size.height))
79+ proc newImageButton * (parent: View = nil , gfx: GraphicsContext , position: Point = newPoint (0 , 0 ), size: Size = newSize (100 , 20 ), image: Image = nil ): Button =
80+ result = newImageButton (gfx , newRect (position.x, position.y, size.width, size.height))
8181 result .image = image
8282 if not isNil (parent):
8383 parent.addSubview (result )
8484
85- method init * (b: Button , w: Window , frame: Rect ) =
86- procCall b.Control .init (w , frame)
85+ method init * (b: Button , gfx: GraphicsContext , frame: Rect ) =
86+ procCall b.Control .init (gfx , frame)
8787 b.state = bsUp
8888 b.enabled = true
8989 b.backgroundColor = whiteColor ()
@@ -93,22 +93,22 @@ method init*(b: Button, w: Window, frame: Rect) =
9393 b.imageMarginTop = 2
9494 b.imageMarginBottom = 2
9595
96- method init * (b: Checkbox , w: Window , frame: Rect ) =
97- procCall b.Button .init (w , frame)
96+ method init * (b: Checkbox , gfx: GraphicsContext , frame: Rect ) =
97+ procCall b.Button .init (gfx , frame)
9898 b.style = bsCheckbox
9999 b.behavior = bbToggle
100100
101- method init * (b: Radiobox , w: Window , frame: Rect ) =
102- procCall b.Button .init (w , frame)
101+ method init * (b: Radiobox , gfx: GraphicsContext , frame: Rect ) =
102+ procCall b.Button .init (gfx , frame)
103103 b.style = bsRadiobox
104104 b.behavior = bbToggle
105105
106106proc drawTitle (b: Button , xOffset: Coord ) =
107- template gfxCtx : untyped = b.window.gfxCtx
108- template fontCtx : untyped = b.window.gfxCtx .fontCtx
109- template gl : untyped = b.window.gfxCtx .gl
107+ template gfx : untyped = b.gfx
108+ template fontCtx : untyped = b.gfx .fontCtx
109+ template gl : untyped = b.gfx .gl
110110 if b.title.len != 0 :
111- gfxCtx .fillColor = if b.state == bsDown and b.style == bsRegular:
111+ gfx .fillColor = if b.state == bsDown and b.style == bsRegular:
112112 whiteColor ()
113113 else :
114114 blackColor ()
@@ -117,7 +117,7 @@ proc drawTitle(b: Button, xOffset: Coord) =
117117 var titleRect = b.bounds
118118 var pt = centerInRect (sizeOfString (fontCtx, gl, font, b.title), titleRect)
119119 if pt.x < xOffset: pt.x = xOffset
120- gfxCtx .drawText (font, pt, b.title)
120+ gfx .drawText (font, pt, b.title)
121121
122122var regularButtonComposition = newComposition """
123123uniform vec4 uStrokeColor;
@@ -136,7 +136,7 @@ void compose() {
136136"""
137137
138138proc drawRegularBezel (b: Button ) =
139- draw b.window.gfxCtx , regularButtonComposition, b.bounds:
139+ draw b.gfx , regularButtonComposition, b.bounds:
140140 if b.state == bsUp:
141141 setUniform (" uStrokeColor" , newGrayColor (0.78 ))
142142 setUniform (" uFillColorStart" , if b.enabled: b.backgroundColor else : grayColor ())
@@ -164,7 +164,7 @@ proc drawCheckboxStyle(b: Button, r: Rect) =
164164 let
165165 size = b.bounds.height
166166 bezelRect = newRect (0 , 0 , size, size)
167- c = b.window.gfxCtx
167+ c = b.gfx
168168
169169 if b.value != 0 :
170170 draw c, checkButtonComposition, bezelRect:
@@ -208,7 +208,7 @@ void compose() {
208208
209209proc drawRadioboxStyle (b: Button , r: Rect ) =
210210 let bezelRect = newRect (0 , 0 , b.bounds.height, b.bounds.height)
211- let c = b.window.gfxCtx
211+ template c : untyped = b.gfx
212212
213213 # Selected
214214 if b.value != 0 :
@@ -227,7 +227,7 @@ proc drawRadioboxStyle(b: Button, r: Rect) =
227227 b.drawTitle (bezelRect.width + 1 )
228228
229229proc drawImage (b: Button ) =
230- let c = b.window.gfxCtx
230+ template c : untyped = b.gfx
231231 let r = b.bounds
232232 if b.imageMarginLeft != 0 or b.imageMarginRight != 0 or
233233 b.imageMarginTop != 0 or b.imageMarginBottom != 0 :
0 commit comments