Skip to content

Commit

Permalink
Merge branch 'develop' into feature/package
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 4, 2019
2 parents 69544d0 + 5a7213f commit 7d54282
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
5 changes: 4 additions & 1 deletion canvas/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Image struct {

// one of the following sources will provide our image data
File string // Load the image from a file
Resource fyne.Resource // Load the image from an in-memory resource
PixelColor func(x, y, w, h int) color.Color // Render the image from code
PixelAspect float32 // Set an aspect ratio for pixel based images

Expand Down Expand Up @@ -79,7 +80,9 @@ func NewImageFromFile(file string) *Image {
// Images returned from this method will scale to fit the canvas object.
// The method for scaling can be set using the Fill field.
func NewImageFromResource(res fyne.Resource) *Image {
return NewImageFromFile(res.CachePath())
return &Image{
Resource: res,
}
}

// NewImageFromImage returns a new Image instance that is rendered from the Go
Expand Down
11 changes: 9 additions & 2 deletions driver/efl/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ func (c *eflCanvas) loadImage(img *canvas.Image, obj *C.Evas_Object) {
size := img.Size()

C.evas_object_image_load_size_set(obj, C.int(scaleInt(c, size.Width)), C.int(scaleInt(c, size.Height)))
cstr := C.CString(img.File)

var file string
if img.Resource != nil {
file = img.Resource.CachePath()
} else {
file = img.File
}
cstr := C.CString(file)
C.evas_object_image_file_set(obj, cstr, nil)
C.free(unsafe.Pointer(cstr))
}
Expand Down Expand Up @@ -302,7 +309,7 @@ func (c *eflCanvas) refreshObject(o, o2 fyne.CanvasObject) {
alpha := C.int(float64(255) * co.Alpha())
C.evas_object_color_set(obj, alpha, alpha, alpha, alpha) // premul ffffff*alpha

if co.File != "" {
if co.File != "" || co.Resource != nil {
c.loadImage(co, obj)
}
if co.PixelColor != nil {
Expand Down
21 changes: 16 additions & 5 deletions driver/gl/gl.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package gl

import (
"bytes"
"fmt"
"image"
"image/draw"
_ "image/jpeg" // avoid users having to import when using image widget
_ "image/png" // avoid the same for PNG images
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -144,11 +146,21 @@ func (c *glCanvas) newGlImageTexture(obj fyne.CanvasObject) uint32 {
return 0
}

if img.File != "" {
if strings.ToLower(filepath.Ext(img.File)) == ".svg" {
icon, err := oksvg.ReadIcon(img.File)
if img.File != "" || img.Resource != nil {
var file io.Reader
var name string
if img.Resource != nil {
name = img.Resource.Name()
file = bytes.NewReader(img.Resource.Content())
} else {
name = img.File
file, _ = os.Open(img.File)
}

if strings.ToLower(filepath.Ext(name)) == ".svg" {
icon, err := oksvg.ReadIconStream(file)
if err != nil {
log.Println("SVG Load error:", err, img.File)
log.Println("SVG Load error:", err)

return 0
}
Expand All @@ -169,7 +181,6 @@ func (c *glCanvas) newGlImageTexture(obj fyne.CanvasObject) uint32 {

icon.Draw(raster, img.Alpha())
} else {
file, _ := os.Open(img.File)
pixels, _, err := image.Decode(file)

if err != nil {
Expand Down
28 changes: 19 additions & 9 deletions vendor/github.com/srwiley/oksvg/svgd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion widget/widget.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package widget defines the UI widgets within the Fyne toolkit
package widget
package widget // import "fyne.io/fyne/widget"

import (
"fyne.io/fyne"
Expand Down

0 comments on commit 7d54282

Please sign in to comment.