diff --git a/CHANGELOG.md b/CHANGELOG.md index 64f31d7..9e37a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Adding `Focus()` method to `Window` to focus the window via API. +- Restructure Pixel Project + - Converted `imdraw` and `text` packages to `extensions` + - moved all `*_test.go` files to `test` package + - moved `pixelgl` package to `backends/opengl` ## [v1.0.0](https://github.com/gopxl/pixel/v2/compare/v1.0.0...dev) - Multiple Window Management Framework diff --git a/README.md b/README.md index 1706c71..5a5479d 100644 --- a/README.md +++ b/README.md @@ -144,8 +144,7 @@ If you're using Windows and having trouble building Pixel, please check [this guide](https://github.com/gopxl/pixel/v2/wiki/Building-Pixel-on-Windows) on the [wiki](https://github.com/gopxl/pixel/v2/wiki). -[PixelGL](https://godoc.org/github.com/gopxl/pixel/v2/pixelgl) backend uses OpenGL to render -graphics. Because of that, OpenGL development libraries are needed for compilation. The dependencies +OpenGL development libraries are needed for compilation. The dependencies are same as for [GLFW](https://github.com/go-gl/glfw). The OpenGL version used is **OpenGL 3.3**. diff --git a/pixelgl/canvas.go b/backends/opengl/canvas.go similarity index 99% rename from pixelgl/canvas.go rename to backends/opengl/canvas.go index b1917fe..34d452c 100644 --- a/pixelgl/canvas.go +++ b/backends/opengl/canvas.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "fmt" diff --git a/pixelgl/doc.go b/backends/opengl/doc.go similarity index 55% rename from pixelgl/doc.go rename to backends/opengl/doc.go index c8acbbc..22003a1 100644 --- a/pixelgl/doc.go +++ b/backends/opengl/doc.go @@ -1,5 +1,5 @@ -// Package pixelgl implements efficient OpenGL targets and utilities for the Pixel game development +// Package opengl implements efficient OpenGL targets and utilities for the Pixel game development // library, specifically Window and Canvas. // // It also contains a few additional utilities to help extend Pixel with OpenGL graphical effects. -package pixelgl +package opengl diff --git a/pixelgl/glframe.go b/backends/opengl/glframe.go similarity index 99% rename from pixelgl/glframe.go rename to backends/opengl/glframe.go index 72c8c66..f943ea1 100644 --- a/pixelgl/glframe.go +++ b/backends/opengl/glframe.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "github.com/gopxl/glhf/v2" diff --git a/pixelgl/glpicture.go b/backends/opengl/glpicture.go similarity index 99% rename from pixelgl/glpicture.go rename to backends/opengl/glpicture.go index 635c587..3f16504 100644 --- a/pixelgl/glpicture.go +++ b/backends/opengl/glpicture.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "math" diff --git a/pixelgl/glshader.go b/backends/opengl/glshader.go similarity index 99% rename from pixelgl/glshader.go rename to backends/opengl/glshader.go index 97c4f84..48b3d0e 100644 --- a/pixelgl/glshader.go +++ b/backends/opengl/glshader.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "github.com/go-gl/mathgl/mgl32" diff --git a/pixelgl/gltriangles.go b/backends/opengl/gltriangles.go similarity index 99% rename from pixelgl/gltriangles.go rename to backends/opengl/gltriangles.go index dcf1921..7220d4a 100644 --- a/pixelgl/gltriangles.go +++ b/backends/opengl/gltriangles.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "fmt" diff --git a/pixelgl/input.go b/backends/opengl/input.go similarity index 99% rename from pixelgl/input.go rename to backends/opengl/input.go index 6f8f20e..73c1eb7 100644 --- a/pixelgl/input.go +++ b/backends/opengl/input.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "time" diff --git a/pixelgl/joystick.go b/backends/opengl/joystick.go similarity index 99% rename from pixelgl/joystick.go rename to backends/opengl/joystick.go index 25fd374..6a7d905 100644 --- a/pixelgl/joystick.go +++ b/backends/opengl/joystick.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "github.com/go-gl/glfw/v3.3/glfw" diff --git a/pixelgl/monitor.go b/backends/opengl/monitor.go similarity index 99% rename from pixelgl/monitor.go rename to backends/opengl/monitor.go index efb3e7f..8580bc6 100644 --- a/pixelgl/monitor.go +++ b/backends/opengl/monitor.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "github.com/go-gl/glfw/v3.3/glfw" diff --git a/pixelgl/run.go b/backends/opengl/run.go similarity index 98% rename from pixelgl/run.go rename to backends/opengl/run.go index a4cc1f4..a11cb99 100644 --- a/pixelgl/run.go +++ b/backends/opengl/run.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "github.com/go-gl/glfw/v3.3/glfw" diff --git a/pixelgl/util.go b/backends/opengl/util.go similarity index 94% rename from pixelgl/util.go rename to backends/opengl/util.go index 68c99fc..969b60c 100644 --- a/pixelgl/util.go +++ b/backends/opengl/util.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "math" diff --git a/pixelgl/window.go b/backends/opengl/window.go similarity index 99% rename from pixelgl/window.go rename to backends/opengl/window.go index 6763383..1ae636e 100644 --- a/pixelgl/window.go +++ b/backends/opengl/window.go @@ -1,4 +1,4 @@ -package pixelgl +package opengl import ( "fmt" diff --git a/backends/vulkan/.init b/backends/vulkan/.init new file mode 100644 index 0000000..e69de29 diff --git a/plugins/README.md b/ext/README.md similarity index 59% rename from plugins/README.md rename to ext/README.md index aea80bf..1cbcfab 100644 --- a/plugins/README.md +++ b/ext/README.md @@ -1,14 +1,16 @@ -# Plugins +# Extensions ## Introduction -Plugins are a way to extend the features and functionality of Pixel. They are the communities contribution +Extensions are a way to *extend* the features and functionality of Pixel. They are the communities contribution to pushing Pixel to the next level. -## Plugin List +## Extension List -* [gameloop](gameloop/README.md) - A plugin that allows you to run a game loop in Pixel. +* [gameloop](gameloop/README.md) - An extension that allows you to run a game loop in Pixel. +* [imdraw](imdraw/README.md) - An extension that allows you to draw primitives in Pixel. +* [text](text/README.md) - An extension that allows you to draw text in Pixel. ## Creating a Plugin diff --git a/plugins/gameloop/README.md b/ext/gameloop/README.md similarity index 93% rename from plugins/gameloop/README.md rename to ext/gameloop/README.md index 0130898..fc4c93f 100644 --- a/plugins/gameloop/README.md +++ b/ext/gameloop/README.md @@ -6,7 +6,7 @@ Defines an `EasyWindow` interface with the following methods ```go type EasyWindow interface { - Win() *pixelgl.Window // get underlying GLFW window + Win() *opengl.Window // get underlying GLFW window Setup() error // setup window Update() error // update window Draw() error // draw to window @@ -38,7 +38,7 @@ window1 := MyNewWindow() // assume MyNewWindow implements EasyWindow interface window2 := MyOtherWindow() // assume MyOtherWindow implements EasyWindow interface manager := NewWindowManager() -manager.InsertWindows([]pixelgl.EasyWindow{ +manager.InsertWindows([]opengl.EasyWindow{ window1, window2, }) diff --git a/plugins/gameloop/gameloop.go b/ext/gameloop/gameloop.go similarity index 89% rename from plugins/gameloop/gameloop.go rename to ext/gameloop/gameloop.go index a1fc33e..49bd3e8 100644 --- a/plugins/gameloop/gameloop.go +++ b/ext/gameloop/gameloop.go @@ -4,14 +4,14 @@ import ( "errors" "time" - "github.com/gopxl/pixel/v2/pixelgl" + "github.com/gopxl/pixel/v2/backends/opengl" ) type EasyWindow interface { - Win() *pixelgl.Window // get underlying GLFW window - Setup() error // setup window - Update() error // update window - Draw() error // draw to window + Win() *opengl.Window // get underlying GLFW window + Setup() error // setup window + Update() error // update window + Draw() error // draw to window } type WindowManager struct { diff --git a/ext/imdraw/README.md b/ext/imdraw/README.md new file mode 100644 index 0000000..4672399 --- /dev/null +++ b/ext/imdraw/README.md @@ -0,0 +1,39 @@ +# IMDraw + +
+ IMDraw is an immediate-mode-like shape drawer and BasicTarget. IMDraw supports TrianglesPosition, + TrianglesColor, TrianglesPicture and PictureColor. + + IMDraw, other than a regular BasicTarget, is used to draw shapes. To draw shapes, you first need + to Push some points to IMDraw: +```go + imd := pixel.NewIMDraw(pic) use nil pic if you only want to draw primitive shapes + imd.Push(pixel.V(100, 100)) + imd.Push(pixel.V(500, 100)) +``` + Once you have Pushed some points, you can use them to draw a shape, such as a line: + + `imd.Line(20) //draws a 20 units thick line`` + + Set exported fields to change properties of Pushed points: + +```go + imd.Color = pixel.RGB(1, 0, 0) + imd.Push(pixel.V(200, 200)) + imd.Circle(400, 0) +``` + Here is the list of all available point properties (need to be set before Pushing a point): + - Color - applies to all + - Picture - coordinates, only applies to filled polygons + - Intensity - picture intensity, only applies to filled polygons + - Precision - curve drawing precision, only applies to circles and ellipses + - EndShape - shape of the end of a line, only applies to lines and outlines + + And here's the list of all shapes that can be drawn (all, except for line, can be filled or + outlined): + - Line + - Polygon + - Circle + - Circle arc + - Ellipse + - Ellipse arc \ No newline at end of file diff --git a/imdraw/imdraw.go b/ext/imdraw/imdraw.go similarity index 100% rename from imdraw/imdraw.go rename to ext/imdraw/imdraw.go diff --git a/imdraw/imdraw_test.go b/ext/imdraw/imdraw_test.go similarity index 97% rename from imdraw/imdraw_test.go rename to ext/imdraw/imdraw_test.go index 1d38436..47dc436 100644 --- a/imdraw/imdraw_test.go +++ b/ext/imdraw/imdraw_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/gopxl/pixel/v2" - "github.com/gopxl/pixel/v2/imdraw" + "github.com/gopxl/pixel/v2/ext/imdraw" ) func BenchmarkPush(b *testing.B) { diff --git a/text/atlas.go b/ext/text/atlas.go similarity index 100% rename from text/atlas.go rename to ext/text/atlas.go diff --git a/text/atlas_test.go b/ext/text/atlas_test.go similarity index 93% rename from text/atlas_test.go rename to ext/text/atlas_test.go index 95daa6d..97746c3 100644 --- a/text/atlas_test.go +++ b/ext/text/atlas_test.go @@ -3,7 +3,7 @@ package text_test import ( "testing" - "github.com/gopxl/pixel/v2/text" + "github.com/gopxl/pixel/v2/ext/text" "golang.org/x/image/font/inconsolata" ) diff --git a/text/doc.go b/ext/text/doc.go similarity index 100% rename from text/doc.go rename to ext/text/doc.go diff --git a/text/text.go b/ext/text/text.go similarity index 100% rename from text/text.go rename to ext/text/text.go diff --git a/text/text_test.go b/ext/text/text_test.go similarity index 97% rename from text/text_test.go rename to ext/text/text_test.go index 3d53d83..1bb54bd 100644 --- a/text/text_test.go +++ b/ext/text/text_test.go @@ -9,9 +9,9 @@ import ( "golang.org/x/image/font/basicfont" "golang.org/x/image/font/gofont/goregular" - "github.com/gopxl/pixel/v2" - "github.com/gopxl/pixel/v2/text" "github.com/golang/freetype/truetype" + "github.com/gopxl/pixel/v2" + "github.com/gopxl/pixel/v2/ext/text" ) func TestClear(t *testing.T) { diff --git a/go.sum b/go.sum index 8268bc1..b86c224 100644 --- a/go.sum +++ b/go.sum @@ -8,14 +8,8 @@ github.com/go-gl/mathgl v1.1.0 h1:0lzZ+rntPX3/oGrDzYGdowSLC2ky8Osirvf5uAwfIEA= github.com/go-gl/mathgl v1.1.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= -github.com/gopxl/glhf/v2 v2.0.0-20231010004459-fc58b4a8f7d0 h1:QCfBCpS1GprFdtyKyswadqpVLk068vOe4AasenQVvU0= -github.com/gopxl/glhf/v2 v2.0.0-20231010004459-fc58b4a8f7d0/go.mod h1:2TW8DIqHAPiQhv6EAXThEA/fgl+Ky8Lgd3XevyJqmSY= -github.com/gopxl/glhf/v2 v2.0.0-20231011010357-90c5b7c2543d h1:DK2rpfmPeqdYlvdypfE5B7PTwkkKAAlCvzoBNZuwxWc= -github.com/gopxl/glhf/v2 v2.0.0-20231011010357-90c5b7c2543d/go.mod h1:InKwj5OoVdOAkpzsS0ILwpB+RrWBLw1i7aFefiGmrp8= github.com/gopxl/glhf/v2 v2.0.0 h1:SJtNy+TXuTBRjMersNx722VDJ0XHIooMH2+7+99LPIc= github.com/gopxl/glhf/v2 v2.0.0/go.mod h1:InKwj5OoVdOAkpzsS0ILwpB+RrWBLw1i7aFefiGmrp8= -github.com/gopxl/mainthread/v2 v2.0.0-20231010001939-73dfba06ae92 h1:+17VMm30TmRoIlA/S29R29A7Sqbak/6OLKjq6iX/I7U= -github.com/gopxl/mainthread/v2 v2.0.0-20231010001939-73dfba06ae92/go.mod h1:/uFQhUiSP53SSU/RQ5w0FFkljRArJlaQkDPza3zE2V8= github.com/gopxl/mainthread/v2 v2.0.0 h1:jRbeWFzX6/UyhRab00xS3xIVYywBgc0DgwPgwS6EVYw= github.com/gopxl/mainthread/v2 v2.0.0/go.mod h1:/uFQhUiSP53SSU/RQ5w0FFkljRArJlaQkDPza3zE2V8= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/circle_test.go b/tests/circle_test.go similarity index 100% rename from circle_test.go rename to tests/circle_test.go diff --git a/color_test.go b/tests/color_test.go similarity index 100% rename from color_test.go rename to tests/color_test.go diff --git a/data_test.go b/tests/data_test.go similarity index 100% rename from data_test.go rename to tests/data_test.go diff --git a/drawer_test.go b/tests/drawer_test.go similarity index 100% rename from drawer_test.go rename to tests/drawer_test.go diff --git a/geometry_test.go b/tests/geometry_test.go similarity index 100% rename from geometry_test.go rename to tests/geometry_test.go diff --git a/line_test.go b/tests/line_test.go similarity index 100% rename from line_test.go rename to tests/line_test.go diff --git a/math_test.go b/tests/math_test.go similarity index 76% rename from math_test.go rename to tests/math_test.go index ad828c1..fe11c22 100644 --- a/math_test.go +++ b/tests/math_test.go @@ -1,7 +1,6 @@ package pixel_test import ( - "fmt" "math" "testing" @@ -10,10 +9,11 @@ import ( // closeEnough will shift the decimal point by the accuracy required, truncates the results and compares them. // Effectively this compares two floats to a given decimal point. -// Example: -// closeEnough(100.125342432, 100.125, 2) == true -// closeEnough(math.Pi, 3.14, 2) == true -// closeEnough(0.1234, 0.1245, 3) == false +// +// Example: +// closeEnough(100.125342432, 100.125, 2) == true +// closeEnough(math.Pi, 3.14, 2) == true +// closeEnough(0.1234, 0.1245, 3) == false func closeEnough(got, expected float64, decimalAccuracy int) bool { gotShifted := got * math.Pow10(decimalAccuracy) expectedShifted := expected * math.Pow10(decimalAccuracy) @@ -40,7 +40,7 @@ func TestClamp(t *testing.T) { for _, tc := range tests { result := pixel.Clamp(tc.number, tc.min, tc.max) if result != tc.expected { - t.Error(fmt.Sprintf("Clamping %v with min %v and max %v should have given %v, but gave %v", tc.number, tc.min, tc.max, tc.expected, result)) + t.Errorf("Clamping %v with min %v and max %v should have given %v, but gave %v", tc.number, tc.min, tc.max, tc.expected, result) } } } diff --git a/matrix_test.go b/tests/matrix_test.go similarity index 100% rename from matrix_test.go rename to tests/matrix_test.go diff --git a/pixel_test.go b/tests/pixel_test.go similarity index 95% rename from pixel_test.go rename to tests/pixel_test.go index eac12cb..faceb67 100644 --- a/pixel_test.go +++ b/tests/pixel_test.go @@ -9,7 +9,7 @@ import ( _ "image/png" "github.com/gopxl/pixel/v2" - "github.com/gopxl/pixel/v2/pixelgl" + "github.com/gopxl/pixel/v2/backends/opengl" ) // onePixelImage is the byte representation of a 1x1 solid white png file @@ -39,7 +39,7 @@ var onePixelImage = []byte{ } func TestMain(m *testing.M) { - pixelgl.Run(func() { + opengl.Run(func() { os.Exit(m.Run()) }) } @@ -53,13 +53,13 @@ func TestSprite_Draw(t *testing.T) { sprite := pixel.NewSprite(pic, pic.Bounds()) - cfg := pixelgl.WindowConfig{ + cfg := opengl.WindowConfig{ Title: "testing", Bounds: pixel.R(0, 0, 150, 150), Invisible: true, } - win, err := pixelgl.NewWindow(cfg) + win, err := opengl.NewWindow(cfg) if err != nil { t.Fatalf("Could not create window: %v", err) } diff --git a/rectangle_test.go b/tests/rectangle_test.go similarity index 100% rename from rectangle_test.go rename to tests/rectangle_test.go diff --git a/vector_test.go b/tests/vector_test.go similarity index 83% rename from vector_test.go rename to tests/vector_test.go index 3a30920..1425f56 100644 --- a/vector_test.go +++ b/tests/vector_test.go @@ -1,7 +1,6 @@ package pixel_test import ( - "fmt" "testing" "github.com/gopxl/pixel/v2" @@ -21,7 +20,7 @@ func TestFloor(t *testing.T) { for _, tc := range tests { result := tc.input.Floor() if result != tc.expected { - t.Error(fmt.Sprintf("Expected %v but got %v", tc.expected, result)) + t.Errorf("Expected %v but got %v", tc.expected, result) } } }