Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -qq pkg-config libwayland-dev libx11-dev libx11-xcb-dev libxkbcommon-dev libxkbcommon-x11-dev libgles2-mesa-dev libegl1-mesa-dev libffi-dev libxcursor-dev
sudo apt-get install -qq gcc pkg-config libwayland-dev libx11-dev libx11-xcb-dev libxkbcommon-x11-dev libgles2-mesa-dev libegl1-mesa-dev libffi-dev libxcursor-dev libvulkan-dev xvfb xdotool
# start a virtual frame buffer
Xvfb :99 -screen 0 1920x1024x24 &

Expand Down
6 changes: 3 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"image/color"
"log"

"gioui.org/text"
"gioui.org/font"
)

// Push saves the current drawing style settings and transformations.
Expand Down Expand Up @@ -55,7 +55,7 @@ func Fill(c color.Color) {
}

// LoadFonts sets the fonts collection to use for text.
func LoadFonts(fnt []text.FontFace) {
func LoadFonts(fnt []font.FontFace) {
gproc.LoadFonts(fnt)
}

Expand All @@ -65,7 +65,7 @@ func TextSize(size float64) {
}

// TextFont sets the text font.
func TextFont(fnt text.Font) {
func TextFont(fnt font.Font) {
gproc.TextFont(fnt)
}

Expand Down
48 changes: 26 additions & 22 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"image/color"

"gioui.org/f32"
"gioui.org/font"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/text"
"gioui.org/x/stroke"
)

// stackOps holds a stack of Gio operations and state.
Expand All @@ -35,61 +36,64 @@ type context struct {

tau float32 // Catmull-Rom tension, used for Curve.

state op.StateOp
state op.TransformStack
}

type strokeStyle struct {
color color.Color
style clip.StrokeStyle
style struct {
cap stroke.StrokeCap
join stroke.StrokeJoin
dashes stroke.Dashes
width float32
}
}

type textStyle struct {
color color.Color
align text.Alignment
size float32
font text.Font
font font.Font
}

func (stk *stackOps) cur() *context {
return &stk.ctx[len(stk.ctx)-1]
}

func (stk *stackOps) save() {
func (stk *stackOps) push() {
stk.ctx = append(stk.ctx, *stk.cur())
stk.cur().state = op.Save(stk.ops)
stk.cur().state = op.TransformOp{}.Push(stk.ops)
}

func (stk *stackOps) load() {
stk.cur().state.Load()
func (stk *stackOps) pop() {
stk.cur().state.Pop()
stk.ctx = stk.ctx[:len(stk.ctx)-1]
}

func (stk *stackOps) rotate(angle float64) {
ops := stk.ops
aff := f32.Affine2D{}.Rotate(f32.Pt(0, 0), float32(-angle))
op.Affine(aff).Add(ops)
op.Affine(f32.Affine2D{}.Rotate(
f32.Pt(0, 0), float32(-angle),
)).Add(stk.ops)
}

func (stk *stackOps) scale(x, y float64) {
ops := stk.ops
aff := f32.Affine2D{}.Scale(
op.Affine(f32.Affine2D{}.Scale(
f32.Pt(0, 0),
f32.Pt(float32(x), float32(y)),
)
op.Affine(aff).Add(ops)
)).Add(stk.ops)
}

func (stk *stackOps) translate(x, y float64) {
op.Offset(f32.Pt(float32(x), float32(y))).Add(stk.ops)
op.Affine(f32.Affine2D{}.Offset(
f32.Pt(float32(x), float32(y)),
)).Add(stk.ops)
}

func (stk *stackOps) shear(x, y float64) {
ops := stk.ops
aff := f32.Affine2D{}.Shear(
op.Affine(f32.Affine2D{}.Shear(
f32.Pt(0, 0),
float32(x), float32(y),
)
op.Affine(aff).Add(ops)
)).Add(stk.ops)
}

func (stk *stackOps) matrix(aff f32.Affine2D) {
Expand All @@ -98,12 +102,12 @@ func (stk *stackOps) matrix(aff f32.Affine2D) {

// Push saves the current drawing style settings and transformations.
func (p *Proc) Push() {
p.stk.save()
p.stk.push()
}

// Pop restores the previous drawing style settings and transformations.
func (p *Proc) Pop() {
p.stk.load()
p.stk.pop()
}

// Rotate rotates the graphical context by angle radians.
Expand Down
8 changes: 4 additions & 4 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"math"
"testing"

"gioui.org/font"
"gioui.org/font/gofont"
"gioui.org/font/opentype"
"gioui.org/text"
"github.com/go-fonts/latin-modern/lmroman12regular"
)

Expand All @@ -28,8 +28,8 @@ func TestPushPop(t *testing.T) {
if err != nil {
panic(fmt.Errorf("failed to parse font: %+v", err))
}
fonts = append(fonts, text.FontFace{
Font: text.Font{
fonts = append(fonts, font.FontFace{
Font: font.Font{
Typeface: "Latin-Modern",
},
Face: face,
Expand All @@ -54,7 +54,7 @@ func TestPushPop(t *testing.T) {
Fill(color.RGBA{R: 255, A: 255})
Pop()
}
TextFont(text.Font{Typeface: "Latin-Modern"})
TextFont(font.Font{Typeface: "Latin-Modern"})
TextSize(20)
Stroke(color.RGBA{R: 255, A: 255})
Rect(20, 20, 160, 160)
Expand Down
10 changes: 5 additions & 5 deletions example/hello/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"image/color"
"math"

"gioui.org/font"
"gioui.org/font/gofont"
"gioui.org/font/opentype"
"gioui.org/text"
"github.com/go-fonts/latin-modern/lmroman12regular"
"github.com/go-p5/p5"
)
Expand Down Expand Up @@ -48,11 +48,11 @@ func draw() {
p5.TextSize(24)
p5.Text("Hello, World!", 10, 250)

p5.TextFont(text.Font{Typeface: "Latin-Modern"})
p5.TextFont(font.Font{Typeface: "Latin-Modern"})
p5.TextSize(24)
p5.Text("Hello, World!", 10, 300)

p5.TextFont(text.Font{})
p5.TextFont(font.Font{})
p5.TextSize(24)
p5.Text("Hello, World!", 10, 350)

Expand All @@ -66,8 +66,8 @@ func loadFonts() {
if err != nil {
panic(fmt.Errorf("failed to parse font: %+v", err))
}
fonts = append(fonts, text.FontFace{
Font: text.Font{
fonts = append(fonts, font.FontFace{
Font: font.Font{
Typeface: "Latin-Modern",
},
Face: face,
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module github.com/go-p5/p5
go 1.19

require (
gioui.org v0.0.0-20210729070555-8cec7e04eb71
gioui.org v0.0.0-20230427133431-816bda7ac7bd
gioui.org/x v0.0.0-20230426160849-752f112c7a59
github.com/andybalholm/stroke v0.0.0-20221221101821-bd29b49d73f0
github.com/campoy/embedmd v1.0.0
github.com/go-fonts/latin-modern v0.3.0
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
Expand All @@ -14,10 +16,12 @@ require (
)

require (
gioui.org/cpu v0.0.0-20210727122813-41509bcd3462 // indirect
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect
gioui.org/shader v1.0.6 // indirect
github.com/go-fonts/liberation v0.3.0 // indirect
github.com/go-latex/latex v0.0.0-20230307184459-12ec69307ad9 // indirect
github.com/go-pdf/fpdf v0.8.0 // indirect
github.com/go-text/typesetting v0.0.0-20230413204129-b4f0492bf7ae // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp/shiny v0.0.0-20230425010034-47ecfdc1ba53 // indirect
golang.org/x/mod v0.10.0 // indirect
Expand Down
Loading