Skip to content

Commit

Permalink
Merge pull request #64 from duysqubix/subtask/#63/refactor-project
Browse files Browse the repository at this point in the history
refactoring project
  • Loading branch information
duysqubix authored Oct 12, 2023
2 parents cd1c4d2 + 8458582 commit f7b21bf
Show file tree
Hide file tree
Showing 38 changed files with 85 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/canvas.go → backends/opengl/canvas.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions pixelgl/doc.go → backends/opengl/doc.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pixelgl/glframe.go → backends/opengl/glframe.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"github.com/gopxl/glhf/v2"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/glpicture.go → backends/opengl/glpicture.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"math"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/glshader.go → backends/opengl/glshader.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"github.com/go-gl/mathgl/mgl32"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/gltriangles.go → backends/opengl/gltriangles.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/input.go → backends/opengl/input.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/joystick.go → backends/opengl/joystick.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"github.com/go-gl/glfw/v3.3/glfw"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/monitor.go → backends/opengl/monitor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"github.com/go-gl/glfw/v3.3/glfw"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/run.go → backends/opengl/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"github.com/go-gl/glfw/v3.3/glfw"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/util.go → backends/opengl/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"math"
Expand Down
2 changes: 1 addition & 1 deletion pixelgl/window.go → backends/opengl/window.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixelgl
package opengl

import (
"fmt"
Expand Down
Empty file added backends/vulkan/.init
Empty file.
10 changes: 6 additions & 4 deletions plugins/README.md → ext/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugins/gameloop/README.md → ext/gameloop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
Expand Down
10 changes: 5 additions & 5 deletions plugins/gameloop/gameloop.go → ext/gameloop/gameloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions ext/imdraw/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# IMDraw

<hr>
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
File renamed without changes.
2 changes: 1 addition & 1 deletion imdraw/imdraw_test.go → ext/imdraw/imdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion text/atlas_test.go → ext/text/atlas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions text/text_test.go → ext/text/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions math_test.go → tests/math_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pixel_test

import (
"fmt"
"math"
"testing"

Expand All @@ -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)
Expand All @@ -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)
}
}
}
File renamed without changes.
8 changes: 4 additions & 4 deletions pixel_test.go → tests/pixel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,7 +39,7 @@ var onePixelImage = []byte{
}

func TestMain(m *testing.M) {
pixelgl.Run(func() {
opengl.Run(func() {
os.Exit(m.Run())
})
}
Expand All @@ -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)
}
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions vector_test.go → tests/vector_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pixel_test

import (
"fmt"
"testing"

"github.com/gopxl/pixel/v2"
Expand All @@ -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)
}
}
}

0 comments on commit f7b21bf

Please sign in to comment.