@@ -2,12 +2,13 @@ package nanovgo
2
2
3
3
import (
4
4
"bytes"
5
- "github.com/shibukawa/nanovgo/fontstashmini"
6
5
"image"
7
6
_ "image/jpeg" // to read jpeg
8
7
_ "image/png" // to read png
9
8
"log"
10
9
"os"
10
+
11
+ "github.com/shibukawa/nanovgo/fontstashmini"
11
12
)
12
13
13
14
// Context is an entry point object to use NanoVGo API and created by NewContext() function.
@@ -116,12 +117,12 @@ type Context struct {
116
117
fringeWidth float32
117
118
devicePxRatio float32
118
119
fs * fontstashmini.FontStash
119
- fontImages []int
120
- fontImageIdx int
121
- drawCallCount int
122
- fillTriCount int
123
- strokeTriCount int
124
- textTriCount int
120
+ fontImages []int32
121
+ fontImageIdx int32
122
+ drawCallCount int32
123
+ fillTriCount int32
124
+ strokeTriCount int32
125
+ textTriCount int32
125
126
}
126
127
127
128
// Delete is called when tearing down NanoVGo context
@@ -144,7 +145,7 @@ func (c *Context) Delete() {
144
145
// For example, GLFW returns two dimension for an opened window: window size and
145
146
// frame buffer size. In that case you would set windowWidth/Height to the window size
146
147
// devicePixelRatio to: frameBufferWidth / windowWidth.
147
- func (c * Context ) BeginFrame (windowWidth , windowHeight int , devicePixelRatio float32 ) {
148
+ func (c * Context ) BeginFrame (windowWidth , windowHeight int32 , devicePixelRatio float32 ) {
148
149
c .states = c .states [:0 ]
149
150
c .Save ()
150
151
c .Reset ()
@@ -173,7 +174,7 @@ func (c *Context) EndFrame() {
173
174
}
174
175
iw , ih , _ := c .ImageSize (fontImage )
175
176
j := 0
176
- for i := 0 ; i < c .fontImageIdx ; i ++ {
177
+ for i := 0 ; int32 ( i ) < c .fontImageIdx ; i ++ {
177
178
nw , nh , _ := c .ImageSize (c .fontImages [i ])
178
179
if nw < iw || nh < ih {
179
180
c .DeleteImage (c .fontImages [i ])
@@ -369,7 +370,7 @@ func (c *Context) SetFillPaint(paint Paint) {
369
370
370
371
// CreateImage creates image by loading it from the disk from specified file name.
371
372
// Returns handle to the image.
372
- func (c * Context ) CreateImage (filePath string , flags ImageFlags ) int {
373
+ func (c * Context ) CreateImage (filePath string , flags ImageFlags ) int32 {
373
374
file , err := os .Open (filePath )
374
375
defer file .Close ()
375
376
if err != nil {
@@ -384,7 +385,7 @@ func (c *Context) CreateImage(filePath string, flags ImageFlags) int {
384
385
385
386
// CreateImageFromMemory creates image by loading it from the specified chunk of memory.
386
387
// Returns handle to the image.
387
- func (c * Context ) CreateImageFromMemory (flags ImageFlags , data []byte ) int {
388
+ func (c * Context ) CreateImageFromMemory (flags ImageFlags , data []byte ) int32 {
388
389
reader := bytes .NewReader (data )
389
390
img , _ , err := image .Decode (reader )
390
391
if err != nil {
@@ -395,30 +396,30 @@ func (c *Context) CreateImageFromMemory(flags ImageFlags, data []byte) int {
395
396
396
397
// CreateImageFromGoImage creates image by loading it from the specified image.Image object.
397
398
// Returns handle to the image.
398
- func (c * Context ) CreateImageFromGoImage (imageFlag ImageFlags , img image.Image ) int {
399
+ func (c * Context ) CreateImageFromGoImage (imageFlag ImageFlags , img image.Image ) int32 {
399
400
bounds := img .Bounds ()
400
401
size := bounds .Size ()
401
402
rgba , ok := img .(* image.RGBA )
402
403
if ok {
403
- return c .CreateImageRGBA (size .X , size .Y , imageFlag , rgba .Pix )
404
+ return c .CreateImageRGBA (int32 ( size .X ), int32 ( size .Y ) , imageFlag , rgba .Pix )
404
405
}
405
406
rgba = image .NewRGBA (bounds )
406
407
for x := 0 ; x < size .X ; x ++ {
407
408
for y := 0 ; y < size .Y ; y ++ {
408
409
rgba .Set (x , y , img .At (x , y ))
409
410
}
410
411
}
411
- return c .CreateImageRGBA (size .X , size .Y , imageFlag , rgba .Pix )
412
+ return c .CreateImageRGBA (int32 ( size .X ), int32 ( size .Y ) , imageFlag , rgba .Pix )
412
413
}
413
414
414
415
// CreateImageRGBA creates image from specified image data.
415
416
// Returns handle to the image.
416
- func (c * Context ) CreateImageRGBA (w , h int , imageFlags ImageFlags , data []byte ) int {
417
+ func (c * Context ) CreateImageRGBA (w , h int32 , imageFlags ImageFlags , data []byte ) int32 {
417
418
return c .params .renderCreateTexture (nvgTextureRGBA , w , h , imageFlags , data )
418
419
}
419
420
420
421
// UpdateImage updates image data specified by image handle.
421
- func (c * Context ) UpdateImage (img int , data []byte ) error {
422
+ func (c * Context ) UpdateImage (img int32 , data []byte ) error {
422
423
w , h , err := c .params .renderGetTextureSize (img )
423
424
if err != nil {
424
425
return err
@@ -427,12 +428,12 @@ func (c *Context) UpdateImage(img int, data []byte) error {
427
428
}
428
429
429
430
// ImageSize returns the dimensions of a created image.
430
- func (c * Context ) ImageSize (img int ) (int , int , error ) {
431
+ func (c * Context ) ImageSize (img int32 ) (int32 , int32 , error ) {
431
432
return c .params .renderGetTextureSize (img )
432
433
}
433
434
434
435
// DeleteImage deletes created image.
435
- func (c * Context ) DeleteImage (img int ) {
436
+ func (c * Context ) DeleteImage (img int32 ) {
436
437
c .params .renderDeleteTexture (img )
437
438
}
438
439
@@ -725,8 +726,8 @@ func (c *Context) Fill() {
725
726
// Count triangles
726
727
for i := 0 ; i < len (c .cache .paths ); i ++ {
727
728
path := & c .cache .paths [i ]
728
- c .fillTriCount += len (path .fills ) - 2
729
- c .strokeTriCount += len (path .strokes ) - 2
729
+ c .fillTriCount += int32 ( len (path .fills ) - 2 )
730
+ c .strokeTriCount += int32 ( len (path .strokes ) - 2 )
730
731
c .drawCallCount += 2
731
732
}
732
733
}
@@ -767,7 +768,7 @@ func (c *Context) Stroke() {
767
768
// Count triangles
768
769
for i := 0 ; i < len (c .cache .paths ); i ++ {
769
770
path := & c .cache .paths [i ]
770
- c .strokeTriCount += len (path .strokes ) - 2
771
+ c .strokeTriCount += int32 ( len (path .strokes ) - 2 )
771
772
c .drawCallCount += 2
772
773
}
773
774
}
@@ -1346,7 +1347,7 @@ func createInternal(params nvgParams) (*Context, error) {
1346
1347
context := & Context {
1347
1348
params : params ,
1348
1349
states : make ([]nvgState , 0 , nvgMaxStates ),
1349
- fontImages : make ([]int , nvgMaxFontImages ),
1350
+ fontImages : make ([]int32 , nvgMaxFontImages ),
1350
1351
commands : make ([]float32 , 0 , nvgInitCommandsSize ),
1351
1352
cache : nvgPathCache {
1352
1353
points : make ([]nvgPoint , 0 , nvgInitPointsSize ),
@@ -1499,10 +1500,10 @@ func (c *Context) flushTextTexture() {
1499
1500
// Update texture
1500
1501
if fontImage != 0 {
1501
1502
data , _ , _ := c .fs .GetTextureData ()
1502
- x := dirty [0 ]
1503
- y := dirty [1 ]
1504
- w := dirty [2 ] - x
1505
- h := dirty [3 ] - y
1503
+ x := int32 ( dirty [0 ])
1504
+ y := int32 ( dirty [1 ])
1505
+ w := int32 ( dirty [2 ]) - x
1506
+ h := int32 ( dirty [3 ]) - y
1506
1507
c .params .renderUpdateTexture (fontImage , x , y , w , h , data )
1507
1508
}
1508
1509
}
@@ -1513,7 +1514,7 @@ func (c *Context) allocTextAtlas() bool {
1513
1514
if c .fontImageIdx >= nvgMaxFontImages - 1 {
1514
1515
return false
1515
1516
}
1516
- var iw , ih int
1517
+ var iw , ih int32
1517
1518
// if next fontImage already have a texture
1518
1519
if c .fontImages [c .fontImageIdx + 1 ] != 0 {
1519
1520
iw , ih , _ = c .ImageSize (c .fontImages [c .fontImageIdx + 1 ])
@@ -1524,14 +1525,14 @@ func (c *Context) allocTextAtlas() bool {
1524
1525
} else {
1525
1526
iw *= 2
1526
1527
}
1527
- if iw > nvgMaxFontImageSize || ih > nvgMaxFontImageSize {
1528
- iw = nvgMaxFontImageSize
1529
- ih = nvgMaxFontImageSize
1528
+ if iw > int32 ( nvgMaxFontImageSize ) || ih > int32 ( nvgMaxFontImageSize ) {
1529
+ iw = int32 ( nvgMaxFontImageSize )
1530
+ ih = int32 ( nvgMaxFontImageSize )
1530
1531
}
1531
1532
c .fontImages [c .fontImageIdx + 1 ] = c .params .renderCreateTexture (nvgTextureALPHA , iw , ih , 0 , nil )
1532
1533
}
1533
1534
c .fontImageIdx ++
1534
- c .fs .ResetAtlas (iw , ih )
1535
+ c .fs .ResetAtlas (int ( iw ), int ( ih ) )
1535
1536
return true
1536
1537
}
1537
1538
@@ -1549,5 +1550,5 @@ func (c *Context) renderText(vertexes []nvgVertex) {
1549
1550
c .params .renderTriangleStrip (& paint , & state .scissor , vertexes )
1550
1551
1551
1552
c .drawCallCount ++
1552
- c .textTriCount += len (vertexes ) / 3
1553
+ c .textTriCount += int32 ( len (vertexes ) / 3 )
1553
1554
}
0 commit comments