forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fyne-io#1130 from andydotxyz/software_circle
Add a simple circle renderer to software painter
- Loading branch information
Showing
39 changed files
with
77 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package painter | ||
|
||
import ( | ||
"image" | ||
"math" | ||
|
||
"fyne.io/fyne/canvas" | ||
|
||
"github.com/srwiley/rasterx" | ||
"golang.org/x/image/math/fixed" | ||
) | ||
|
||
// DrawCircle rasterizes the given circle object into an image. | ||
// The bounds of the output image will be increased by vectorPad to allow for stroke overflow at the edges. | ||
// The scale function is used to understand how many pixels are required per unit of size. | ||
func DrawCircle(circle *canvas.Circle, vectorPad int, scale func(float32) int) *image.RGBA { | ||
radius := float32(math.Min(float64(circle.Size().Width), float64(circle.Size().Height)) / 2) | ||
|
||
width := scale(float32(circle.Size().Width + vectorPad*2)) | ||
height := scale(float32(circle.Size().Height + vectorPad*2)) | ||
stroke := scale(circle.StrokeWidth) | ||
|
||
raw := image.NewRGBA(image.Rect(0, 0, width, height)) | ||
scanner := rasterx.NewScannerGV(circle.Size().Width, circle.Size().Height, raw, raw.Bounds()) | ||
|
||
if circle.FillColor != nil { | ||
filler := rasterx.NewFiller(width, height, scanner) | ||
filler.SetColor(circle.FillColor) | ||
rasterx.AddCircle(float64(width/2), float64(height/2), float64(scale(radius)), filler) | ||
filler.Draw() | ||
} | ||
|
||
dasher := rasterx.NewDasher(width, height, scanner) | ||
dasher.SetColor(circle.StrokeColor) | ||
dasher.SetStroke(fixed.Int26_6(float64(stroke)*64), 0, nil, nil, nil, 0, nil, 0) | ||
rasterx.AddCircle(float64(width/2), float64(height/2), float64(scale(radius)), dasher) | ||
dasher.Draw() | ||
|
||
return raw | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+193 Bytes
(110%)
widget/testdata/radio/layout_multiple_horizontal_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+179 Bytes
(110%)
widget/testdata/radio/layout_multiple_selected_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+189 Bytes
(110%)
widget/testdata/radio/layout_multiple_selected_horizontal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+196 Bytes
(110%)
widget/testdata/radio/layout_multiple_selected_horizontal_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+131 Bytes
(110%)
widget/testdata/radio/layout_single_horizontal_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+128 Bytes
(110%)
widget/testdata/radio/layout_single_selected_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+132 Bytes
(110%)
widget/testdata/radio/layout_single_selected_horizontal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+128 Bytes
(110%)
widget/testdata/radio/layout_single_selected_horizontal_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+629 Bytes
(150%)
widget/testdata/tabcontainer/desktop/layout_bottom_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+637 Bytes
(140%)
widget/testdata/tabcontainer/desktop/layout_bottom_icon_and_text.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+631 Bytes
(150%)
widget/testdata/tabcontainer/desktop/layout_bottom_text.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+538 Bytes
(130%)
widget/testdata/tabcontainer/desktop/layout_leading_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+529 Bytes
(130%)
widget/testdata/tabcontainer/desktop/layout_leading_icon_and_text.png
Oops, something went wrong.
Binary file modified
BIN
+548 Bytes
(140%)
widget/testdata/tabcontainer/desktop/layout_leading_text.png
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
+635 Bytes
(140%)
widget/testdata/tabcontainer/desktop/layout_top_icon_and_text.png
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
+540 Bytes
(130%)
widget/testdata/tabcontainer/desktop/layout_trailing_icon.png
Oops, something went wrong.
Binary file modified
BIN
+551 Bytes
(130%)
widget/testdata/tabcontainer/desktop/layout_trailing_icon_and_text.png
Oops, something went wrong.
Binary file modified
BIN
+562 Bytes
(140%)
widget/testdata/tabcontainer/desktop/layout_trailing_text.png
Oops, something went wrong.