move gogame to github as third part
@ -1,36 +0,0 @@
|
|||||||
package color
|
|
||||||
|
|
||||||
//import "github.com/veandco/go-sdl2/sdl"
|
|
||||||
|
|
||||||
|
|
||||||
type Color struct {
|
|
||||||
R uint32
|
|
||||||
G uint32
|
|
||||||
B uint32
|
|
||||||
A uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Color) ToHex() int {
|
|
||||||
return int( c.A<< 24 | c.R << 16 | c.G << 8 | c.B )
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Color) ToBytes() []byte {
|
|
||||||
bytes := make([]byte,4)
|
|
||||||
bytes[0] = byte(c.R)
|
|
||||||
bytes[1] = byte(c.G)
|
|
||||||
bytes[2] = byte(c.B)
|
|
||||||
bytes[3] = byte(c.A)
|
|
||||||
return bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Color) RGBA() (r, g, b, a uint32) {
|
|
||||||
r = uint32(c.R)
|
|
||||||
r |= r << 8
|
|
||||||
g = uint32(c.G)
|
|
||||||
g |= g << 8
|
|
||||||
b = uint32(c.B)
|
|
||||||
b |= b << 8
|
|
||||||
a = uint32(c.A)
|
|
||||||
a |= a << 8
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package color
|
|
||||||
|
|
||||||
// > go test color.go color_test.go -v
|
|
||||||
// Or
|
|
||||||
// > go test -v
|
|
||||||
// to test all test files
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestColor(t *testing.T) {
|
|
||||||
c := &Color{244,124,244,0}
|
|
||||||
t.Logf("%x", c.ToHex())
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
package display
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"../../gogame"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Inited = false
|
|
||||||
var window *sdl.Window
|
|
||||||
|
|
||||||
func AssertInited() {
|
|
||||||
if Inited == false {
|
|
||||||
panic("run gogame.DisplayInit first")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Init() bool {
|
|
||||||
sdl.Do(func() {
|
|
||||||
|
|
||||||
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
Inited = true
|
|
||||||
})
|
|
||||||
|
|
||||||
return Inited
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func SetMode(w,h,flags,depth int32) *sdl.Surface {
|
|
||||||
var err error
|
|
||||||
var surface *sdl.Surface
|
|
||||||
AssertInited()
|
|
||||||
|
|
||||||
sdl.Do(func() {
|
|
||||||
window, err = sdl.CreateWindow("gogame", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
|
|
||||||
w, h, uint32( gogame.SHOWN | flags))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
surface,err = window.GetSurface()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return surface
|
|
||||||
}
|
|
||||||
|
|
||||||
func Flip() {
|
|
||||||
sdl.Do(func() {
|
|
||||||
|
|
||||||
if window != nil {
|
|
||||||
window.UpdateSurface()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package draw
|
|
||||||
|
|
||||||
|
|
||||||
const (
|
|
||||||
LEFT_EDGE=0x1
|
|
||||||
RIGHT_EDGE=0x2
|
|
||||||
BOTTOM_EDGE=0x4
|
|
||||||
TOP_EDGE=0x8
|
|
||||||
)
|
|
||||||
|
|
||||||
@ -1,96 +0,0 @@
|
|||||||
package draw
|
|
||||||
|
|
||||||
import (
|
|
||||||
// "fmt"
|
|
||||||
// "math"
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"github.com/veandco/go-sdl2/gfx"
|
|
||||||
|
|
||||||
"../color"
|
|
||||||
"../rect"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func _aa_render_region(image *sdl.Renderer, _rect *sdl.Rect, col color.Color, rad int) {
|
|
||||||
corners := rect.Inflate(_rect,-2*rad-1, -2*rad-1)
|
|
||||||
topleft := []int{ int(corners.X),int(corners.Y)}
|
|
||||||
topright := []int{int(corners.X+corners.W-1), int(corners.Y)}
|
|
||||||
bottomleft := []int{int(corners.X), int(corners.Y+corners.H-1)}
|
|
||||||
bottomright := []int{int(corners.X+corners.W -1), int(corners.Y+corners.H-1)}
|
|
||||||
|
|
||||||
attributes :=[][]int{topleft, topright, bottomleft, bottomright }
|
|
||||||
|
|
||||||
r,g,b,a := col.RGBA()
|
|
||||||
|
|
||||||
image.SetDrawColor( uint8(r),uint8(g),uint8(b),uint8(a) )
|
|
||||||
|
|
||||||
|
|
||||||
for i:=0; i< len(attributes);i++ {
|
|
||||||
x,y := attributes[i][0],attributes[i][1]
|
|
||||||
|
|
||||||
gfx.AACircleRGBA(image,int32(x),int32(y),int32(rad),uint8(r),uint8(g),uint8(b),uint8(a))
|
|
||||||
gfx.FilledCircleRGBA(image,int32(x),int32(y), int32(rad),uint8(r),uint8(g),uint8(b),uint8(a))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
r1 := rect.Inflate(_rect,-2*rad,0)
|
|
||||||
r2 := rect.Inflate(_rect,0,-2*rad)
|
|
||||||
|
|
||||||
image.FillRect( &r1 ) // main body except four circles in corners
|
|
||||||
image.FillRect( &r2 ) // fix gap between circles of up and down vertical
|
|
||||||
}
|
|
||||||
|
|
||||||
//alpha of color should be 255
|
|
||||||
func AARoundRect(surf *sdl.Surface,_rect *sdl.Rect,col color.Color,rad,border int, inside color.Color) {
|
|
||||||
|
|
||||||
image,_ := sdl.CreateSoftwareRenderer(surf)
|
|
||||||
|
|
||||||
/*
|
|
||||||
image.SetDrawColor(233,100,200,0)
|
|
||||||
image.DrawLine(10,20,100,200)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// image.Clear()
|
|
||||||
_aa_render_region(image,_rect,col,rad)
|
|
||||||
if border > 0 {
|
|
||||||
rect.InflateIp(_rect,-2*border,-2*border)
|
|
||||||
_aa_render_region(image,_rect,inside,rad)
|
|
||||||
}
|
|
||||||
|
|
||||||
//image.Present()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Point(surf *sdl.Surface, c color.Color, x,y int) {
|
|
||||||
pixels := surf.Pixels()
|
|
||||||
bytes_per_pixel := surf.BytesPerPixel()
|
|
||||||
|
|
||||||
addr := y * int(surf.Pitch) + x*bytes_per_pixel // 1 2 3 4
|
|
||||||
|
|
||||||
color_bytes := c.ToBytes()
|
|
||||||
|
|
||||||
surf.Lock()
|
|
||||||
|
|
||||||
if bytes_per_pixel == 1 {
|
|
||||||
pixels[addr] = color_bytes[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_per_pixel == 2 {
|
|
||||||
for i :=0; i < bytes_per_pixel; i++ {
|
|
||||||
pixels[addr+i] = color_bytes[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_per_pixel == 3 {
|
|
||||||
for i :=0; i < bytes_per_pixel; i++ {
|
|
||||||
pixels[addr+i] = color_bytes[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_per_pixel == 4 {
|
|
||||||
for i :=0; i < bytes_per_pixel; i++ {
|
|
||||||
pixels[addr+i] = color_bytes[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
surf.Unlock()
|
|
||||||
}
|
|
||||||
@ -1,542 +0,0 @@
|
|||||||
package draw
|
|
||||||
|
|
||||||
import (
|
|
||||||
// "fmt"
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"../color"
|
|
||||||
"../rect"
|
|
||||||
)
|
|
||||||
|
|
||||||
//closed true => an additional line segment is drawn between the first and last points.
|
|
||||||
//pointlist should be [][2]
|
|
||||||
func Lines(surf *sdl.Surface, col color.Color,closed bool, pointlist [][]int,width int) sdl.Rect {
|
|
||||||
length := len(pointlist)
|
|
||||||
if length < 2 {
|
|
||||||
panic("draw lines at least contains more than 1 points pair")
|
|
||||||
}
|
|
||||||
pts := make([]int,4)
|
|
||||||
|
|
||||||
if len(pointlist[0]) < 2 {
|
|
||||||
panic("start points should be more than 1 at least")
|
|
||||||
}
|
|
||||||
|
|
||||||
x := pointlist[0][0]
|
|
||||||
y := pointlist[0][1]
|
|
||||||
|
|
||||||
startx := x
|
|
||||||
pts[0] = x
|
|
||||||
left := x
|
|
||||||
right := x
|
|
||||||
|
|
||||||
starty := y
|
|
||||||
pts[1] = y
|
|
||||||
top := y
|
|
||||||
bottom := y
|
|
||||||
|
|
||||||
if width < 1 {
|
|
||||||
return rect.Rect(x,y,0,0)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := surf.Lock()
|
|
||||||
if err != nil {
|
|
||||||
return rect.Rect(0,0,0,0)
|
|
||||||
}
|
|
||||||
|
|
||||||
drawn := 1
|
|
||||||
for loop := 1; loop < length; loop++ {
|
|
||||||
item := pointlist[loop]
|
|
||||||
if len(item) < 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
x = item[0]
|
|
||||||
y = item[1]
|
|
||||||
drawn += 1
|
|
||||||
pts[0] = startx
|
|
||||||
pts[1] = starty
|
|
||||||
startx = x
|
|
||||||
starty = y
|
|
||||||
pts[2] = x
|
|
||||||
pts[3] = y
|
|
||||||
if clip_and_draw_line_width(surf, &surf.ClipRect, col, width, pts) > 0 {
|
|
||||||
left = min(min(pts[0],pts[2]),left)
|
|
||||||
top = min(min(pts[1],pts[3]),top)
|
|
||||||
right = max(max(pts[0],pts[2]),right)
|
|
||||||
bottom = max(max(pts[1],pts[3]),bottom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if closed == true && drawn > 2 {
|
|
||||||
item := pointlist[0]
|
|
||||||
x = item[0]
|
|
||||||
y = item[1]
|
|
||||||
|
|
||||||
pts[0] = startx
|
|
||||||
pts[1] = starty
|
|
||||||
pts[2] = x
|
|
||||||
pts[3] = y
|
|
||||||
clip_and_draw_line_width(surf, &surf.ClipRect, col, width, pts)
|
|
||||||
}
|
|
||||||
surf.Unlock()
|
|
||||||
|
|
||||||
return rect.Rect(left,top,right-left+1, bottom-top+1)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func Line(surf *sdl.Surface, col color.Color,x1,y1,x2,y2 ,width int) sdl.Rect {
|
|
||||||
pts := make([]int,4)
|
|
||||||
pts[0] = x1
|
|
||||||
pts[1] = y1
|
|
||||||
pts[2] = x2
|
|
||||||
pts[3] = y2
|
|
||||||
|
|
||||||
if width < 1 {
|
|
||||||
return rect.Rect(x1,y1,0,0)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := surf.Lock()
|
|
||||||
if err != nil {
|
|
||||||
return rect.Rect(0,0,0,0)
|
|
||||||
}
|
|
||||||
anydraw := clip_and_draw_line_width(surf,&surf.ClipRect, col, width,pts)
|
|
||||||
surf.Unlock()
|
|
||||||
if anydraw == 0 {
|
|
||||||
return rect.Rect(x1,y1,0,0)
|
|
||||||
}
|
|
||||||
rleft := 0
|
|
||||||
rtop := 0
|
|
||||||
|
|
||||||
if x1 < x2 {
|
|
||||||
rleft = x1
|
|
||||||
}else {
|
|
||||||
rleft = x2
|
|
||||||
}
|
|
||||||
|
|
||||||
if y1 < y2 {
|
|
||||||
rtop = y1
|
|
||||||
}else {
|
|
||||||
rtop = y2
|
|
||||||
}
|
|
||||||
|
|
||||||
dx := abs(x1-x2)
|
|
||||||
dy := abs(y1-y2)
|
|
||||||
|
|
||||||
rwidth := 0
|
|
||||||
rheight := 0
|
|
||||||
if dx > dy {
|
|
||||||
rwidth = dx +1
|
|
||||||
rheight = dy + width
|
|
||||||
}else {
|
|
||||||
rwidth = dx + width
|
|
||||||
rheight = dy + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return rect.Rect(rleft,rtop,rwidth,rheight)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func clip_and_draw_line(surf *sdl.Surface, rect *sdl.Rect, col color.Color, pts []int) int {
|
|
||||||
|
|
||||||
if clipline(pts, int(rect.X),int(rect.Y),int(rect.X+ rect.W-1), int(rect.Y+rect.H-1) ) == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if pts[1] == pts[3] {
|
|
||||||
drawhorzline(surf, col, pts[0],pts[1],pts[2])
|
|
||||||
}else if pts[0] == pts[2] {
|
|
||||||
drawvertline(surf,col, pts[0],pts[1],pts[3])
|
|
||||||
}else {
|
|
||||||
drawline(surf, col, pts[0],pts[1],pts[2],pts[3])
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func clip_and_draw_line_width(surf *sdl.Surface,rect *sdl.Rect,col color.Color, width int, pts []int) int {
|
|
||||||
loop := 0
|
|
||||||
xinc :=0
|
|
||||||
yinc :=0
|
|
||||||
newpts :=make([]int,4)
|
|
||||||
range_ := make([]int,4)
|
|
||||||
anydraw := 0
|
|
||||||
if abs(pts[0]-pts[2]) > abs(pts[1]-pts[3]) {
|
|
||||||
yinc = 1
|
|
||||||
}else{
|
|
||||||
xinc = 1
|
|
||||||
}
|
|
||||||
copy(newpts, pts)
|
|
||||||
if clip_and_draw_line(surf,rect,col, newpts) > 0 {
|
|
||||||
anydraw = 1
|
|
||||||
copy(range_,newpts)
|
|
||||||
}else {
|
|
||||||
range_[0] = 10000
|
|
||||||
range_[1] = 10000
|
|
||||||
range_[2] = -10000
|
|
||||||
range_[3] = -10000
|
|
||||||
}
|
|
||||||
|
|
||||||
for loop = 1; loop < width; loop +=2 {
|
|
||||||
newpts[0] = pts[0] + xinc*(loop/2+1)
|
|
||||||
newpts[1] = pts[1] + yinc*(loop/2+1)
|
|
||||||
newpts[2] = pts[2] + xinc*(loop/2+1)
|
|
||||||
newpts[3] = pts[3] + yinc*(loop/2+1)
|
|
||||||
if clip_and_draw_line(surf,rect,col,newpts) > 0 {
|
|
||||||
anydraw = 1
|
|
||||||
range_[0] = min(newpts[0],range_[0])
|
|
||||||
range_[1] = min(newpts[1],range_[1])
|
|
||||||
range_[2] = max(newpts[2],range_[2])
|
|
||||||
range_[3] = max(newpts[3],range_[3])
|
|
||||||
}
|
|
||||||
if (loop + 1) < width {
|
|
||||||
newpts[0] = pts[0] - xinc*(loop/2+1)
|
|
||||||
newpts[1] = pts[1] - yinc*(loop/2+1)
|
|
||||||
newpts[2] = pts[2] - xinc*(loop/2+1)
|
|
||||||
newpts[3] = pts[3] - yinc*(loop/2+1)
|
|
||||||
if clip_and_draw_line(surf,rect,col, newpts) > 0 {
|
|
||||||
anydraw = 1
|
|
||||||
range_[0] = min(newpts[0],range_[0])
|
|
||||||
range_[1] = min(newpts[1],range_[1])
|
|
||||||
range_[2] = max(newpts[2],range_[2])
|
|
||||||
range_[3] = max(newpts[3],range_[3])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if anydraw > 0 {
|
|
||||||
copy(pts,range_)
|
|
||||||
}
|
|
||||||
return anydraw
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func encode(x,y,left,top,right,bottom int) int {
|
|
||||||
code := 0
|
|
||||||
if (x < left ) {
|
|
||||||
code |= LEFT_EDGE
|
|
||||||
}
|
|
||||||
if (x > right) {
|
|
||||||
code |= RIGHT_EDGE
|
|
||||||
}
|
|
||||||
if (y < top) {
|
|
||||||
code |= TOP_EDGE
|
|
||||||
}
|
|
||||||
if (y > bottom) {
|
|
||||||
code |= BOTTOM_EDGE
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
|
|
||||||
func inside(a int) bool {
|
|
||||||
if a > 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func accept(a,b int) bool {
|
|
||||||
ret := a | b
|
|
||||||
if ret > 0 {
|
|
||||||
return false
|
|
||||||
}else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func reject(a,b int) bool {
|
|
||||||
ret := a & b
|
|
||||||
if ret > 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func clipline(pts []int, left,top,right,bottom int) int {
|
|
||||||
|
|
||||||
x1 := pts[0]
|
|
||||||
y1 := pts[1]
|
|
||||||
x2 := pts[2]
|
|
||||||
y2 := pts[3]
|
|
||||||
|
|
||||||
var code1 int
|
|
||||||
var code2 int
|
|
||||||
draw := 0
|
|
||||||
var swaptmp int
|
|
||||||
var m float64 /*slope*/
|
|
||||||
|
|
||||||
for true {
|
|
||||||
code1 = encode(x1,y1,left,top,right,bottom)
|
|
||||||
code2 = encode(x2,y2,left,top,right,bottom)
|
|
||||||
if ( accept(code1,code2) ) {
|
|
||||||
draw = 1
|
|
||||||
break
|
|
||||||
} else if ( reject(code1,code2 ) ) {
|
|
||||||
break
|
|
||||||
}else {
|
|
||||||
if inside(code1) {
|
|
||||||
swaptmp = x2
|
|
||||||
x2 = x1
|
|
||||||
x1 = swaptmp
|
|
||||||
swaptmp = y2
|
|
||||||
y2 = y1
|
|
||||||
y1 = swaptmp
|
|
||||||
swaptmp = code2
|
|
||||||
code2 = code1
|
|
||||||
code1 = swaptmp
|
|
||||||
}
|
|
||||||
if x2 != x1 {
|
|
||||||
m = float64(y2 - y1) / float64(x2-x1)
|
|
||||||
}else {
|
|
||||||
m = 1.0
|
|
||||||
}
|
|
||||||
if (code1 & LEFT_EDGE) > 0 {
|
|
||||||
y1 += int(float64(left-x1)*m)
|
|
||||||
x1 = left
|
|
||||||
}else if (code1 & RIGHT_EDGE) > 0 {
|
|
||||||
y1 += int(float64(right-x1)*m)
|
|
||||||
x1 = right
|
|
||||||
}else if (code1 & BOTTOM_EDGE) > 0 {
|
|
||||||
if x2 != x1 {
|
|
||||||
x1 += int(float64(bottom-y1) / m)
|
|
||||||
}
|
|
||||||
y1 = bottom
|
|
||||||
}else if (code1 & TOP_EDGE) > 0 {
|
|
||||||
if x2 != x1 {
|
|
||||||
x1 += int( float64(top-y1) / m)
|
|
||||||
}
|
|
||||||
y1 = top
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if draw > 0 {
|
|
||||||
pts[0] = x1
|
|
||||||
pts[1] = y1
|
|
||||||
pts[2] = x2
|
|
||||||
pts[3] = y2
|
|
||||||
}
|
|
||||||
|
|
||||||
return draw
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawline(surf *sdl.Surface, col color.Color, x1,y1,x2,y2 int) {
|
|
||||||
deltax := x2 - x1
|
|
||||||
deltay := y2 - y1
|
|
||||||
|
|
||||||
signx := 0
|
|
||||||
signy := 0
|
|
||||||
|
|
||||||
if deltax < 0 {
|
|
||||||
signx = -1
|
|
||||||
}else {
|
|
||||||
signx = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if deltay < 0 {
|
|
||||||
signy = -1
|
|
||||||
}else {
|
|
||||||
signy = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
deltax = signx * deltax + 1
|
|
||||||
deltay = signy * deltay + 1
|
|
||||||
|
|
||||||
bytes_per_pixel := surf.BytesPerPixel()
|
|
||||||
|
|
||||||
pixx := int(bytes_per_pixel)
|
|
||||||
pixy := int(surf.Pitch)
|
|
||||||
|
|
||||||
addr := pixy* y1 + x1 * bytes_per_pixel
|
|
||||||
|
|
||||||
pixx *= int(signx)
|
|
||||||
pixy *= int(signy)
|
|
||||||
|
|
||||||
swaptmp := 0
|
|
||||||
if deltax < deltay {
|
|
||||||
swaptmp = deltax
|
|
||||||
deltax = deltay
|
|
||||||
deltay = swaptmp
|
|
||||||
swaptmp = pixx
|
|
||||||
pixx = pixy
|
|
||||||
pixy = swaptmp
|
|
||||||
}
|
|
||||||
|
|
||||||
x := 0
|
|
||||||
y := 0
|
|
||||||
|
|
||||||
color_bytes := col.ToBytes()
|
|
||||||
pixels := surf.Pixels()
|
|
||||||
|
|
||||||
switch bytes_per_pixel {
|
|
||||||
case 1:
|
|
||||||
for ; x < deltax; x++ {
|
|
||||||
pixels[addr] = color_bytes[0]
|
|
||||||
y += deltay
|
|
||||||
if y >= deltax {
|
|
||||||
y -= deltax
|
|
||||||
addr += pixy
|
|
||||||
}
|
|
||||||
addr +=pixx
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
for ; x < deltax;x++ {
|
|
||||||
pixels[addr] = color_bytes[0]
|
|
||||||
pixels[addr+1] = color_bytes[1]
|
|
||||||
y+= deltay
|
|
||||||
if y >= deltax {
|
|
||||||
y -= deltax
|
|
||||||
addr += pixy
|
|
||||||
}
|
|
||||||
|
|
||||||
addr+=pixx
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 3:
|
|
||||||
for ; x < deltax; x++ {
|
|
||||||
pixels[addr] = color_bytes[0]
|
|
||||||
pixels[addr+1] = color_bytes[1]
|
|
||||||
pixels[addr+2] = color_bytes[2]
|
|
||||||
y+=deltay
|
|
||||||
if y >= deltax {
|
|
||||||
y-=deltax
|
|
||||||
addr += pixy
|
|
||||||
}
|
|
||||||
addr+=pixx
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 4:
|
|
||||||
for ; x < deltax; x++ {
|
|
||||||
pixels[addr] = color_bytes[0]
|
|
||||||
pixels[addr+1] = color_bytes[1]
|
|
||||||
pixels[addr+2] = color_bytes[2]
|
|
||||||
pixels[addr+3] = color_bytes[3]
|
|
||||||
y+=deltay
|
|
||||||
if y >= deltax {
|
|
||||||
y-=deltax
|
|
||||||
addr += pixy
|
|
||||||
}
|
|
||||||
addr+=pixx
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawhorzline(surf *sdl.Surface, col color.Color, x1,y1,x2 int) {
|
|
||||||
if x1 == x2 {
|
|
||||||
pixel(surf,col,x1,y1)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes_per_pixel := surf.BytesPerPixel()
|
|
||||||
color_bytes := col.ToBytes()
|
|
||||||
pixels := surf.Pixels()
|
|
||||||
|
|
||||||
addr := int(surf.Pitch) * y1
|
|
||||||
end := 0
|
|
||||||
start := 0
|
|
||||||
if x1 < x2 {
|
|
||||||
end = addr + x2*bytes_per_pixel
|
|
||||||
start = addr+x1 *bytes_per_pixel
|
|
||||||
}else {
|
|
||||||
end = addr + x1 *bytes_per_pixel
|
|
||||||
start = addr + x2 * bytes_per_pixel
|
|
||||||
}
|
|
||||||
|
|
||||||
switch bytes_per_pixel {
|
|
||||||
case 1:
|
|
||||||
for ; start <=end; start++ {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
for ; start <= end; start+=2 {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
pixels[start+1] = color_bytes[1]
|
|
||||||
}
|
|
||||||
case 3:
|
|
||||||
for ; start <= end; start+=3 {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
pixels[start+1] = color_bytes[1]
|
|
||||||
pixels[start+2] = color_bytes[2]
|
|
||||||
}
|
|
||||||
case 4:
|
|
||||||
for ; start <= end; start +=4 {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
pixels[start+1] = color_bytes[1]
|
|
||||||
pixels[start+2] = color_bytes[2]
|
|
||||||
pixels[start+3] = color_bytes[3]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawhorzlineclip(surf *sdl.Surface, col color.Color, x1 , y1, x2 int ) {
|
|
||||||
if y1 < int(surf.ClipRect.Y) || y1 >= int( surf.ClipRect.Y + surf.ClipRect.H) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if x2 < x1 {
|
|
||||||
temp := x1
|
|
||||||
x1 = x2
|
|
||||||
x2 = temp
|
|
||||||
}
|
|
||||||
x1 = max(x1,int(surf.ClipRect.X))
|
|
||||||
x2 = min(x2,int(surf.ClipRect.X+surf.ClipRect.W-1))
|
|
||||||
if x2 < int(surf.ClipRect.X) || x1 >= int( surf.ClipRect.X + surf.ClipRect.W) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if x1 == x2 {
|
|
||||||
pixel(surf,col, x1,y1)
|
|
||||||
}else {
|
|
||||||
drawhorzline(surf,col,x1,y1,x2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawvertline(surf *sdl.Surface, col color.Color, x1,y1,y2 int) {
|
|
||||||
if y1 == y2 {
|
|
||||||
pixel(surf,col, x1,y1)
|
|
||||||
}
|
|
||||||
bytes_per_pixel := surf.BytesPerPixel()
|
|
||||||
color_bytes := col.ToBytes()
|
|
||||||
pixels := surf.Pixels()
|
|
||||||
pitch := int(surf.Pitch)
|
|
||||||
|
|
||||||
addr := x1 * bytes_per_pixel
|
|
||||||
end := 0
|
|
||||||
start := 0
|
|
||||||
if y1 < y2 {
|
|
||||||
end = addr + y2* pitch
|
|
||||||
start = addr + y1*pitch
|
|
||||||
}else {
|
|
||||||
end = addr + y1*pitch
|
|
||||||
start = addr + y2*pitch
|
|
||||||
}
|
|
||||||
|
|
||||||
switch bytes_per_pixel {
|
|
||||||
case 1:
|
|
||||||
for ; start <=end; start+=pitch {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
for ; start <= end; start+=pitch {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
pixels[start+1] = color_bytes[1]
|
|
||||||
}
|
|
||||||
case 3:
|
|
||||||
for ; start <= end; start+=pitch {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
pixels[start+1] = color_bytes[1]
|
|
||||||
pixels[start+2] = color_bytes[2]
|
|
||||||
}
|
|
||||||
case 4:
|
|
||||||
for ; start <= end; start +=pitch {
|
|
||||||
pixels[start] = color_bytes[0]
|
|
||||||
pixels[start+1] = color_bytes[1]
|
|
||||||
pixels[start+2] = color_bytes[2]
|
|
||||||
pixels[start+3] = color_bytes[3]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,164 +0,0 @@
|
|||||||
package draw
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
// "math"
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"../color"
|
|
||||||
"../rect"
|
|
||||||
"../qsort"
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
func draw_fillpoly(surf *sdl.Surface, vx []int, vy []int, numpoints int, col color.Color) {
|
|
||||||
|
|
||||||
miny:=0
|
|
||||||
maxy:=0
|
|
||||||
y:=0
|
|
||||||
x1:=0
|
|
||||||
y1:=0
|
|
||||||
x2:=0
|
|
||||||
y2:=0
|
|
||||||
ints := 0
|
|
||||||
ind1:=0
|
|
||||||
ind2:=0
|
|
||||||
|
|
||||||
polyints := make([]int,numpoints)
|
|
||||||
|
|
||||||
/* Determine Y maxima */
|
|
||||||
miny = vy[0]
|
|
||||||
maxy = vy[0]
|
|
||||||
for i:=1; i < numpoints; i++ {
|
|
||||||
miny = min(miny,vy[i])
|
|
||||||
maxy = max(maxy,vy[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Draw, scanning y */
|
|
||||||
for y=miny;y<=maxy;y++ {
|
|
||||||
ints = 0
|
|
||||||
for i:=0; i< numpoints;i++ {
|
|
||||||
if i == 0 {
|
|
||||||
ind1 = numpoints -1
|
|
||||||
ind2 = 0
|
|
||||||
}else {
|
|
||||||
ind1 = i-1
|
|
||||||
ind2 = i
|
|
||||||
}
|
|
||||||
|
|
||||||
y1 = vy[ind1]
|
|
||||||
y2 = vy[ind2]
|
|
||||||
if y1 < y2 {
|
|
||||||
x1 = vx[ind1]
|
|
||||||
x2 = vx[ind2]
|
|
||||||
}else if y1 > y2 {
|
|
||||||
y2 = vy[ind1]
|
|
||||||
y1 = vy[ind2]
|
|
||||||
x2 = vx[ind1]
|
|
||||||
x1 = vx[ind2]
|
|
||||||
}else if miny == maxy {
|
|
||||||
/* Special case: polygon only 1 pixel high. */
|
|
||||||
minx:= vx[0]
|
|
||||||
maxx:= vx[0]
|
|
||||||
|
|
||||||
for j:= 1; j < numpoints; j++ {
|
|
||||||
minx = min(minx,vx[j])
|
|
||||||
maxx = max(maxx,vx[j])
|
|
||||||
}
|
|
||||||
polyints[ints] = minx
|
|
||||||
ints+=1
|
|
||||||
polyints[ints] = maxx
|
|
||||||
ints+=1
|
|
||||||
break
|
|
||||||
}else {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( y >= y1) && (y < y2 ) {
|
|
||||||
fmt.Println("ints : ",ints)
|
|
||||||
polyints[ints] = (y-y1) * (x2-x1) / (y2-y1) + x1
|
|
||||||
ints+=1
|
|
||||||
|
|
||||||
}else if (y == maxy) && (y > y1) && (y <= y2) {
|
|
||||||
polyints[ints] = (y-y1) * (x2-x1) / (y2-y1) + x1
|
|
||||||
ints+=1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_polyints := make([]int, ints)
|
|
||||||
copy(new_polyints,polyints)
|
|
||||||
new_polyints = qsort.QuickSort(new_polyints)
|
|
||||||
|
|
||||||
for i:=0;i<ints;i+=2 {
|
|
||||||
drawhorzlineclip(surf, col, new_polyints[i], y, new_polyints[i+1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Polygon(surf *sdl.Surface, color color.Color, points [][]int, border_width int) sdl.Rect {
|
|
||||||
|
|
||||||
if border_width > 0 {
|
|
||||||
ret := Lines(surf, color, true,points,border_width)
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes_per_pixel := surf.BytesPerPixel()
|
|
||||||
if bytes_per_pixel <= 0 || bytes_per_pixel > 4 {
|
|
||||||
panic("unsupport bit depth for line draw")
|
|
||||||
}
|
|
||||||
|
|
||||||
length := len(points)
|
|
||||||
if length < 3 {
|
|
||||||
panic("points argument must contain more than 2 points")
|
|
||||||
}
|
|
||||||
|
|
||||||
item := points[0] // Needs sequence_get_item to fetch from sorted points list
|
|
||||||
if len(item) < 2 {
|
|
||||||
panic("points should be a pair of coordinators")
|
|
||||||
}
|
|
||||||
|
|
||||||
x := item[0]
|
|
||||||
y := item[1]
|
|
||||||
|
|
||||||
left := x
|
|
||||||
right := x
|
|
||||||
top := y
|
|
||||||
bottom := y
|
|
||||||
|
|
||||||
xlist := make([]int,length)
|
|
||||||
ylist := make([]int,length)
|
|
||||||
|
|
||||||
numpoints := 0
|
|
||||||
for loop := 0; loop < length; loop++ {
|
|
||||||
item = points[loop]
|
|
||||||
if len(item) < 2 {
|
|
||||||
panic("points should be a pair of coordinators")
|
|
||||||
}
|
|
||||||
x = item[0]
|
|
||||||
y = item[1]
|
|
||||||
|
|
||||||
xlist[numpoints] = x
|
|
||||||
ylist[numpoints] = y
|
|
||||||
numpoints+=1
|
|
||||||
|
|
||||||
left = min(x,left)
|
|
||||||
top = min(y,top)
|
|
||||||
right = max(x,right)
|
|
||||||
bottom = max(y,bottom)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := surf.Lock()
|
|
||||||
if err != nil {
|
|
||||||
return rect.Rect(0,0,0,0)
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_fillpoly(surf,xlist,ylist,numpoints,color)
|
|
||||||
|
|
||||||
surf.Unlock()
|
|
||||||
|
|
||||||
left = max(left,int(surf.ClipRect.X))
|
|
||||||
top = max(top, int(surf.ClipRect.Y))
|
|
||||||
right = min(right,int(surf.ClipRect.X + surf.ClipRect.W))
|
|
||||||
bottom = min(bottom, int(surf.ClipRect.Y + surf.ClipRect.H))
|
|
||||||
return rect.Rect(left,top,right-left+1, bottom-top+1)
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package draw
|
|
||||||
|
|
||||||
import (
|
|
||||||
// "math"
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"../color"
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
func Rect(surf *sdl.Surface,color color.Color, _rect *sdl.Rect, border_width int) {
|
|
||||||
l := int(_rect.X)
|
|
||||||
r := int(_rect.X + _rect.W - 1)
|
|
||||||
t := int(_rect.Y)
|
|
||||||
b := int(_rect.Y + _rect.H - 1)
|
|
||||||
|
|
||||||
points := [][]int{ []int{l,t}, []int{r,t}, []int{r,b},[]int{l,b} }
|
|
||||||
Polygon(surf, color, points, border_width)
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
package draw
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"../color"
|
|
||||||
)
|
|
||||||
|
|
||||||
func max(a, b int) int {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func min(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func abs(n int) int {
|
|
||||||
return int(math.Abs(float64(n)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func pixel(surf *sdl.Surface, c color.Color, x,y int) int {
|
|
||||||
pixels := surf.Pixels()
|
|
||||||
bytes_per_pixel := surf.BytesPerPixel()
|
|
||||||
|
|
||||||
addr := y * int(surf.Pitch) + x*bytes_per_pixel // 1 2 3 4
|
|
||||||
|
|
||||||
color_bytes := c.ToBytes()
|
|
||||||
|
|
||||||
if x < int(surf.ClipRect.X) || x >= int(surf.ClipRect.X + surf.ClipRect.W) ||
|
|
||||||
y < int(surf.ClipRect.Y) || y >= int(surf.ClipRect.Y + surf.ClipRect.H) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_per_pixel == 1 {
|
|
||||||
pixels[addr] = color_bytes[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_per_pixel == 2 {
|
|
||||||
for i :=0; i < bytes_per_pixel; i++ {
|
|
||||||
pixels[addr+i] = color_bytes[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_per_pixel == 3 {
|
|
||||||
for i :=0; i < bytes_per_pixel; i++ {
|
|
||||||
pixels[addr+i] = color_bytes[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_per_pixel == 4 {
|
|
||||||
for i :=0; i < bytes_per_pixel; i++ {
|
|
||||||
pixels[addr+i] = color_bytes[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
@ -1,313 +0,0 @@
|
|||||||
package event
|
|
||||||
|
|
||||||
import (
|
|
||||||
// "fmt"
|
|
||||||
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
NOEVENT = iota
|
|
||||||
QUIT
|
|
||||||
KEYDOWN
|
|
||||||
KEYUP
|
|
||||||
USEREVENT
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
var sdlKeyDict = map[int]string{
|
|
||||||
sdl.K_UNKNOWN:"",
|
|
||||||
sdl.K_RETURN:"Return",
|
|
||||||
sdl.K_ESCAPE:"Escape",
|
|
||||||
sdl.K_BACKSPACE:"Backspace",
|
|
||||||
sdl.K_TAB:"Tab",
|
|
||||||
sdl.K_SPACE:"Space",
|
|
||||||
sdl.K_EXCLAIM:"!",
|
|
||||||
sdl.K_QUOTEDBL:"\"",
|
|
||||||
sdl.K_HASH:"#",
|
|
||||||
sdl.K_PERCENT:"%",
|
|
||||||
sdl.K_DOLLAR:"$",
|
|
||||||
sdl.K_AMPERSAND:"&",
|
|
||||||
sdl.K_QUOTE:"'",
|
|
||||||
sdl.K_LEFTPAREN:"(",
|
|
||||||
sdl.K_RIGHTPAREN:")",
|
|
||||||
sdl.K_ASTERISK:"*",
|
|
||||||
sdl.K_PLUS:"+",
|
|
||||||
sdl.K_COMMA:",",
|
|
||||||
sdl.K_MINUS:"-",
|
|
||||||
sdl.K_PERIOD:".",
|
|
||||||
sdl.K_SLASH:"/",
|
|
||||||
sdl.K_0:"0",
|
|
||||||
sdl.K_1:"1",
|
|
||||||
sdl.K_2:"2",
|
|
||||||
sdl.K_3:"3",
|
|
||||||
sdl.K_4:"4",
|
|
||||||
sdl.K_5:"5",
|
|
||||||
sdl.K_6:"6",
|
|
||||||
sdl.K_7:"7",
|
|
||||||
sdl.K_8:"8",
|
|
||||||
sdl.K_9:"9",
|
|
||||||
sdl.K_COLON:":",
|
|
||||||
sdl.K_SEMICOLON:";",
|
|
||||||
sdl.K_LESS:"<",
|
|
||||||
sdl.K_EQUALS:"=",
|
|
||||||
sdl.K_GREATER:">",
|
|
||||||
sdl.K_QUESTION:"?",
|
|
||||||
sdl.K_AT:"@",
|
|
||||||
sdl.K_LEFTBRACKET:"[",
|
|
||||||
sdl.K_BACKSLASH:"\\",
|
|
||||||
sdl.K_RIGHTBRACKET:"]",
|
|
||||||
sdl.K_CARET:"^",
|
|
||||||
sdl.K_UNDERSCORE:"_",
|
|
||||||
sdl.K_BACKQUOTE:"`",
|
|
||||||
sdl.K_a:"A",
|
|
||||||
sdl.K_b:"B",
|
|
||||||
sdl.K_c:"C",
|
|
||||||
sdl.K_d:"D",
|
|
||||||
sdl.K_e:"E",
|
|
||||||
sdl.K_f:"F",
|
|
||||||
sdl.K_g:"G",
|
|
||||||
sdl.K_h:"H",
|
|
||||||
sdl.K_i:"I",
|
|
||||||
sdl.K_j:"J",
|
|
||||||
sdl.K_k:"K",
|
|
||||||
sdl.K_l:"L",
|
|
||||||
sdl.K_m:"M",
|
|
||||||
sdl.K_n:"N",
|
|
||||||
sdl.K_o:"O",
|
|
||||||
sdl.K_p:"P",
|
|
||||||
sdl.K_q:"Q",
|
|
||||||
sdl.K_r:"R",
|
|
||||||
sdl.K_s:"S",
|
|
||||||
sdl.K_t:"T",
|
|
||||||
sdl.K_u:"U",
|
|
||||||
sdl.K_v:"V",
|
|
||||||
sdl.K_w:"W",
|
|
||||||
sdl.K_x:"X",
|
|
||||||
sdl.K_y:"Y",
|
|
||||||
sdl.K_z:"Z",
|
|
||||||
sdl.K_CAPSLOCK:"CapsLock",
|
|
||||||
sdl.K_F1:"F1",
|
|
||||||
sdl.K_F2:"F2",
|
|
||||||
sdl.K_F3:"F3",
|
|
||||||
sdl.K_F4:"F4",
|
|
||||||
sdl.K_F5:"F5",
|
|
||||||
sdl.K_F6:"F6",
|
|
||||||
sdl.K_F7:"F7",
|
|
||||||
sdl.K_F8:"F8",
|
|
||||||
sdl.K_F9:"F9",
|
|
||||||
sdl.K_F10:"F10",
|
|
||||||
sdl.K_F11:"F11",
|
|
||||||
sdl.K_F12:"F12",
|
|
||||||
sdl.K_PRINTSCREEN:"PrintScreen",
|
|
||||||
sdl.K_SCROLLLOCK:"ScrollLock",
|
|
||||||
sdl.K_PAUSE:"Pause",
|
|
||||||
sdl.K_INSERT:"Insert",
|
|
||||||
sdl.K_HOME:"Home",
|
|
||||||
sdl.K_PAGEUP:"PageUp",
|
|
||||||
sdl.K_DELETE:"Delete",
|
|
||||||
sdl.K_END:"End",
|
|
||||||
sdl.K_PAGEDOWN:"PageDown",
|
|
||||||
sdl.K_RIGHT:"Right",
|
|
||||||
sdl.K_LEFT:"Left",
|
|
||||||
sdl.K_DOWN:"Down",
|
|
||||||
sdl.K_UP:"Up",
|
|
||||||
sdl.K_NUMLOCKCLEAR:"Numlock",
|
|
||||||
sdl.K_KP_DIVIDE:"Keypad /",
|
|
||||||
sdl.K_KP_MULTIPLY:"Keypad *",
|
|
||||||
sdl.K_KP_MINUS:"Keypad -",
|
|
||||||
sdl.K_KP_PLUS:"Keypad +",
|
|
||||||
sdl.K_KP_ENTER:"Keypad Enter",
|
|
||||||
sdl.K_KP_1:"Keypad 1",
|
|
||||||
sdl.K_KP_2:"Keypad 2",
|
|
||||||
sdl.K_KP_3:"Keypad 3",
|
|
||||||
sdl.K_KP_4:"Keypad 4",
|
|
||||||
sdl.K_KP_5:"Keypad 5",
|
|
||||||
sdl.K_KP_6:"Keypad 6",
|
|
||||||
sdl.K_KP_7:"Keypad 7",
|
|
||||||
sdl.K_KP_8:"Keypad 8",
|
|
||||||
sdl.K_KP_9:"Keypad 9",
|
|
||||||
sdl.K_KP_0:"Keypad 0",
|
|
||||||
sdl.K_KP_PERIOD:"Keypad .",
|
|
||||||
sdl.K_APPLICATION:"Application",
|
|
||||||
sdl.K_POWER:"Power",
|
|
||||||
sdl.K_KP_EQUALS:"Keypad =",
|
|
||||||
sdl.K_F13:"F13",
|
|
||||||
sdl.K_F14:"F14",
|
|
||||||
sdl.K_F15:"F15",
|
|
||||||
sdl.K_F16:"F16",
|
|
||||||
sdl.K_F17:"F17",
|
|
||||||
sdl.K_F18:"F18",
|
|
||||||
sdl.K_F19:"F19",
|
|
||||||
sdl.K_F20:"F20",
|
|
||||||
sdl.K_F21:"F21",
|
|
||||||
sdl.K_F22:"F22",
|
|
||||||
sdl.K_F23:"F23",
|
|
||||||
sdl.K_F24:"F24",
|
|
||||||
sdl.K_EXECUTE:"Execute",
|
|
||||||
sdl.K_HELP:"Help",
|
|
||||||
sdl.K_MENU:"Menu",
|
|
||||||
sdl.K_SELECT:"Select",
|
|
||||||
sdl.K_STOP:"Stop",
|
|
||||||
sdl.K_AGAIN:"Again",
|
|
||||||
sdl.K_UNDO:"Undo",
|
|
||||||
sdl.K_CUT:"Cut",
|
|
||||||
sdl.K_COPY:"Copy",
|
|
||||||
sdl.K_PASTE:"Paste",
|
|
||||||
sdl.K_FIND:"Find",
|
|
||||||
sdl.K_MUTE:"Mute",
|
|
||||||
sdl.K_VOLUMEUP:"VolumeUp",
|
|
||||||
sdl.K_VOLUMEDOWN:"VolumeDown",
|
|
||||||
sdl.K_KP_COMMA:"Keypad ,",
|
|
||||||
sdl.K_KP_EQUALSAS400:"Keypad = (AS400)",
|
|
||||||
sdl.K_ALTERASE:"AltErase",
|
|
||||||
sdl.K_SYSREQ:"SysReq",
|
|
||||||
sdl.K_CANCEL:"Cancel",
|
|
||||||
sdl.K_CLEAR:"Clear",
|
|
||||||
sdl.K_PRIOR:"Prior",
|
|
||||||
sdl.K_RETURN2:"Return",
|
|
||||||
sdl.K_SEPARATOR:"Separator",
|
|
||||||
sdl.K_OUT:"Out",
|
|
||||||
sdl.K_OPER:"Oper",
|
|
||||||
sdl.K_CLEARAGAIN:"Clear / Again",
|
|
||||||
sdl.K_CRSEL:"CrSel",
|
|
||||||
sdl.K_EXSEL:"ExSel",
|
|
||||||
sdl.K_KP_00:"Keypad 00",
|
|
||||||
sdl.K_KP_000:"Keypad 000",
|
|
||||||
sdl.K_THOUSANDSSEPARATOR:"ThousandsSeparator",
|
|
||||||
sdl.K_DECIMALSEPARATOR:"DecimalSeparator",
|
|
||||||
sdl.K_CURRENCYUNIT:"CurrencyUnit",
|
|
||||||
sdl.K_CURRENCYSUBUNIT:"CurrencySubUnit",
|
|
||||||
sdl.K_KP_LEFTPAREN:"Keypad (",
|
|
||||||
sdl.K_KP_RIGHTPAREN:"Keypad )",
|
|
||||||
sdl.K_KP_LEFTBRACE:"Keypad {",
|
|
||||||
sdl.K_KP_RIGHTBRACE:"Keypad }",
|
|
||||||
sdl.K_KP_TAB:"Keypad Tab",
|
|
||||||
sdl.K_KP_BACKSPACE:"Keypad Backspace",
|
|
||||||
sdl.K_KP_A:"Keypad A",
|
|
||||||
sdl.K_KP_B:"Keypad B",
|
|
||||||
sdl.K_KP_C:"Keypad C",
|
|
||||||
sdl.K_KP_D:"Keypad D",
|
|
||||||
sdl.K_KP_E:"Keypad E",
|
|
||||||
sdl.K_KP_F:"Keypad F",
|
|
||||||
sdl.K_KP_XOR:"Keypad XOR",
|
|
||||||
sdl.K_KP_POWER:"Keypad ^",
|
|
||||||
sdl.K_KP_PERCENT:"Keypad %",
|
|
||||||
sdl.K_KP_LESS:"Keypad <",
|
|
||||||
sdl.K_KP_GREATER:"Keypad >",
|
|
||||||
sdl.K_KP_AMPERSAND:"Keypad &",
|
|
||||||
sdl.K_KP_DBLAMPERSAND:"Keypad &&",
|
|
||||||
sdl.K_KP_VERTICALBAR:"Keypad |",
|
|
||||||
sdl.K_KP_DBLVERTICALBAR:"Keypad ||",
|
|
||||||
sdl.K_KP_COLON:"Keypad :",
|
|
||||||
sdl.K_KP_HASH:"Keypad #",
|
|
||||||
sdl.K_KP_SPACE:"Keypad Space",
|
|
||||||
sdl.K_KP_AT:"Keypad @",
|
|
||||||
sdl.K_KP_EXCLAM:"Keypad !",
|
|
||||||
sdl.K_KP_MEMSTORE:"Keypad MemStore",
|
|
||||||
sdl.K_KP_MEMRECALL:"Keypad MemRecall",
|
|
||||||
sdl.K_KP_MEMCLEAR:"Keypad MemClear",
|
|
||||||
sdl.K_KP_MEMADD:"Keypad MemAdd",
|
|
||||||
sdl.K_KP_MEMSUBTRACT:"Keypad MemSubtract",
|
|
||||||
sdl.K_KP_MEMMULTIPLY:"Keypad MemMultiply",
|
|
||||||
sdl.K_KP_MEMDIVIDE:"Keypad MemDivide",
|
|
||||||
sdl.K_KP_PLUSMINUS:"Keypad +/-",
|
|
||||||
sdl.K_KP_CLEAR:"Keypad Clear",
|
|
||||||
sdl.K_KP_CLEARENTRY:"Keypad ClearEntry",
|
|
||||||
sdl.K_KP_BINARY:"Keypad Binary",
|
|
||||||
sdl.K_KP_OCTAL:"Keypad Octal",
|
|
||||||
sdl.K_KP_DECIMAL:"Keypad Decimal",
|
|
||||||
sdl.K_KP_HEXADECIMAL:"Keypad Hexadecimal",
|
|
||||||
sdl.K_LCTRL:"Left Ctrl",
|
|
||||||
sdl.K_LSHIFT:"Left Shift",
|
|
||||||
sdl.K_LALT:"Left Alt",
|
|
||||||
sdl.K_LGUI:"Left GUI",
|
|
||||||
sdl.K_RCTRL:"Right Ctrl",
|
|
||||||
sdl.K_RSHIFT:"Right Shift",
|
|
||||||
sdl.K_RALT:"Right Alt",
|
|
||||||
sdl.K_RGUI:"Right GUI",
|
|
||||||
sdl.K_MODE:"ModeSwitch",
|
|
||||||
sdl.K_AUDIONEXT:"AudioNext",
|
|
||||||
sdl.K_AUDIOPREV:"AudioPrev",
|
|
||||||
sdl.K_AUDIOSTOP:"AudioStop",
|
|
||||||
sdl.K_AUDIOPLAY:"AudioPlay",
|
|
||||||
sdl.K_AUDIOMUTE:"AudioMute",
|
|
||||||
sdl.K_MEDIASELECT:"MediaSelect",
|
|
||||||
sdl.K_WWW:"WWW",
|
|
||||||
sdl.K_MAIL:"Mail",
|
|
||||||
sdl.K_CALCULATOR:"Calculator",
|
|
||||||
sdl.K_COMPUTER:"Computer",
|
|
||||||
sdl.K_AC_SEARCH:"AC Search",
|
|
||||||
sdl.K_AC_HOME:"AC Home",
|
|
||||||
sdl.K_AC_BACK:"AC Back",
|
|
||||||
sdl.K_AC_FORWARD:"AC Forward",
|
|
||||||
sdl.K_AC_STOP:"AC Stop",
|
|
||||||
sdl.K_AC_REFRESH:"AC Refresh",
|
|
||||||
sdl.K_AC_BOOKMARKS:"AC Bookmarks",
|
|
||||||
sdl.K_BRIGHTNESSDOWN:"BrightnessDown",
|
|
||||||
sdl.K_BRIGHTNESSUP:"BrightnessUp",
|
|
||||||
sdl.K_DISPLAYSWITCH:"DisplaySwitch",
|
|
||||||
sdl.K_KBDILLUMTOGGLE:"KBDIllumToggle",
|
|
||||||
sdl.K_KBDILLUMDOWN:"KBDIllumDown",
|
|
||||||
sdl.K_KBDILLUMUP:"KBDIllumUp",
|
|
||||||
sdl.K_EJECT:"Eject",
|
|
||||||
sdl.K_SLEEP:"Sleep",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type Event struct {
|
|
||||||
Type uint32
|
|
||||||
Data map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
func map_events( event sdl.Event) Event {
|
|
||||||
var ret Event
|
|
||||||
if event != nil {
|
|
||||||
switch t := event.(type) {
|
|
||||||
case *sdl.QuitEvent:
|
|
||||||
ret.Type = QUIT
|
|
||||||
case *sdl.KeyboardEvent:
|
|
||||||
if t.Type == sdl.KEYDOWN {
|
|
||||||
ret.Type = KEYDOWN
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.Type == sdl.KEYUP {
|
|
||||||
ret.Type = KEYUP
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.Data = make(map[string]string)
|
|
||||||
ret.Data["Repeat"]= strconv.Itoa( int(t.Repeat) )
|
|
||||||
ret.Data["Key"] = sdlKeyDict[ int(t.Keysym.Sym) ]
|
|
||||||
ret.Data["Mod"] = strconv.Itoa( int(t.Keysym.Mod) )
|
|
||||||
|
|
||||||
default:
|
|
||||||
// fmt.Printf("unknow type %T\n", t)
|
|
||||||
ret.Type = NOEVENT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func Poll() Event {
|
|
||||||
var ret Event
|
|
||||||
|
|
||||||
sdl.Do(func() {
|
|
||||||
event := sdl.PollEvent()
|
|
||||||
ret = map_events(event)
|
|
||||||
})
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func Wait() Event {
|
|
||||||
var ret Event
|
|
||||||
|
|
||||||
event := sdl.WaitEvent()
|
|
||||||
ret = map_events(event)
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
package gogame
|
|
||||||
|
|
||||||
import "github.com/veandco/go-sdl2/sdl"
|
|
||||||
|
|
||||||
const (
|
|
||||||
|
|
||||||
SHOWN = sdl.WINDOW_SHOWN
|
|
||||||
OPENGL = sdl.WINDOW_OPENGL
|
|
||||||
HIDDEN = sdl.WINDOW_HIDDEN
|
|
||||||
FULLSCREEN = sdl.WINDOW_FULLSCREEN
|
|
||||||
RESIZABLE = sdl.WINDOW_RESIZABLE
|
|
||||||
|
|
||||||
)
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package qsort
|
|
||||||
|
|
||||||
import "math/rand"
|
|
||||||
|
|
||||||
func QuickSort(slice []int) []int {
|
|
||||||
length := len(slice)
|
|
||||||
|
|
||||||
if length <= 1 {
|
|
||||||
sliceCopy := make([]int, length)
|
|
||||||
copy(sliceCopy, slice)
|
|
||||||
return sliceCopy
|
|
||||||
}
|
|
||||||
|
|
||||||
m := slice[rand.Intn(length)]
|
|
||||||
|
|
||||||
less := make([]int, 0, length)
|
|
||||||
middle := make([]int, 0, length)
|
|
||||||
more := make([]int, 0, length)
|
|
||||||
|
|
||||||
for _, item := range slice {
|
|
||||||
switch {
|
|
||||||
case item < m:
|
|
||||||
less = append(less, item)
|
|
||||||
case item == m:
|
|
||||||
middle = append(middle, item)
|
|
||||||
case item > m:
|
|
||||||
more = append(more, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
less, more = QuickSort(less), QuickSort(more)
|
|
||||||
|
|
||||||
less = append(less, middle...)
|
|
||||||
less = append(less, more...)
|
|
||||||
|
|
||||||
return less
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
package qsort
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var testData = []struct {
|
|
||||||
input []int
|
|
||||||
expectedOutput []int
|
|
||||||
}{
|
|
||||||
{[]int{}, []int{}},
|
|
||||||
{[]int{42}, []int{42}},
|
|
||||||
{[]int{42, 23}, []int{23, 42}},
|
|
||||||
{[]int{23, 42, 32, 64, 12, 4}, []int{4, 12, 23, 32, 42, 64}},
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestQuickSort(t *testing.T) {
|
|
||||||
for _, testCase := range testData {
|
|
||||||
actual := QuickSort(testCase.input)
|
|
||||||
expected := testCase.expectedOutput
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
|
||||||
t.Errorf("%v != %v\n", actual, expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package rect
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Rect(top ,left, width,height int) sdl.Rect {
|
|
||||||
return sdl.Rect{int32(top),int32(left),int32(width),int32(height)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func InflateIp(rect *sdl.Rect, x,y int) {
|
|
||||||
|
|
||||||
rect.X -= int32(x/2)
|
|
||||||
rect.Y -= int32(y/2)
|
|
||||||
rect.W += int32(x)
|
|
||||||
rect.H += int32(y)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func Inflate(rect *sdl.Rect, x,y int) sdl.Rect {
|
|
||||||
|
|
||||||
r := sdl.Rect{0,0,0,0}
|
|
||||||
|
|
||||||
r.X = rect.X - int32(x/2)
|
|
||||||
r.Y = rect.Y - int32(y/2)
|
|
||||||
r.W = rect.W + int32(x)
|
|
||||||
r.H = rect.H + int32(y)
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
package gogame
|
|
||||||
|
|
||||||
//import "github.com/veandco/go-sdl2/sdl"
|
|
||||||
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
package surface
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"../color"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func Fill(surface *sdl.Surface, col color.Color) {
|
|
||||||
|
|
||||||
rect := sdl.Rect{0,0,0,0}
|
|
||||||
|
|
||||||
rect.W = surface.W
|
|
||||||
rect.H = surface.H
|
|
||||||
|
|
||||||
FillRect(surface, &rect, uint32(col.ToHex()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FillRect(surface *sdl.Surface,rect *sdl.Rect, color uint32) {
|
|
||||||
|
|
||||||
sdl.Do(func() {
|
|
||||||
surface.FillRect(rect,color)
|
|
||||||
})
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a New Surface
|
|
||||||
func Surface(w,h int) *sdl.Surface {
|
|
||||||
//flags=0, depth=0, masks=None
|
|
||||||
Rmask := 0x000000ff
|
|
||||||
Gmask := 0x0000ff00
|
|
||||||
Bmask := 0x00ff0000
|
|
||||||
Amask := 0xff000000
|
|
||||||
|
|
||||||
flags := 0
|
|
||||||
depth := 32
|
|
||||||
|
|
||||||
surf,err := sdl.CreateRGBSurface(uint32(flags),int32(w),int32(h), int32(depth), uint32(Rmask), uint32(Gmask), uint32(Bmask), uint32(Amask))
|
|
||||||
if err != nil {
|
|
||||||
panic( fmt.Sprintf("sdl.CreateRGBSurface failed %s",sdl.GetError()))
|
|
||||||
}
|
|
||||||
|
|
||||||
return surf
|
|
||||||
}
|
|
||||||
3
skin/default/config.cfg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[Colors]
|
||||||
|
High = #33a6ff
|
||||||
|
White = #ffffff
|
||||||
BIN
skin/default/sys.go/gameshell/blank.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
skin/default/sys.go/gameshell/footbar_icons/footbar.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
skin/default/sys.go/gameshell/icons/_L.png
Normal file
|
After Width: | Height: | Size: 306 B |
BIN
skin/default/sys.go/gameshell/icons/_R.png
Normal file
|
After Width: | Height: | Size: 294 B |
BIN
skin/default/sys.go/gameshell/icons/about_bg.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
skin/default/sys.go/gameshell/icons/blueselector.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
skin/default/sys.go/gameshell/icons/done.png
Normal file
|
After Width: | Height: | Size: 198 B |
BIN
skin/default/sys.go/gameshell/icons/empty.png
Normal file
|
After Width: | Height: | Size: 875 B |
BIN
skin/default/sys.go/gameshell/icons/heart.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
skin/default/sys.go/gameshell/icons/icon_sd.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
skin/default/sys.go/gameshell/icons/light.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
skin/default/sys.go/gameshell/icons/lock.png
Normal file
|
After Width: | Height: | Size: 335 B |
BIN
skin/default/sys.go/gameshell/icons/needwifi_bg.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
skin/default/sys.go/gameshell/icons/online.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
skin/default/sys.go/gameshell/icons/rom_download.png
Normal file
|
After Width: | Height: | Size: 545 B |
BIN
skin/default/sys.go/gameshell/icons/roundcorners.png
Normal file
|
After Width: | Height: | Size: 286 B |
BIN
skin/default/sys.go/gameshell/icons/scale.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
skin/default/sys.go/gameshell/icons/star.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
skin/default/sys.go/gameshell/icons/sys.png
Normal file
|
After Width: | Height: | Size: 427 B |
BIN
skin/default/sys.go/gameshell/icons/vol.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
skin/default/sys.go/gameshell/titlebar_icons/battery_unknown.png
Normal file
|
After Width: | Height: | Size: 316 B |
BIN
skin/default/sys.go/gameshell/titlebar_icons/soundvolume.png
Normal file
|
After Width: | Height: | Size: 601 B |
BIN
skin/default/sys.go/gameshell/titlebar_icons/wifi.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
skin/default/sys.go/gameshell/titlebar_icons/withcharging.png
Normal file
|
After Width: | Height: | Size: 673 B |
|
After Width: | Height: | Size: 627 B |
BIN
skin/default/truetype/NotoSansCJK-Regular.ttf
Normal file
BIN
skin/default/truetype/NotoSansMono-Regular.ttf
Normal file
BIN
skin/default/truetype/VarelaRound-Regular.ttf
Normal file
BIN
skin/default/truetype/VeraMono.ttf
Normal file
39
test.go
@ -6,33 +6,52 @@ import (
|
|||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
|
|
||||||
//"./gogame"
|
//"github.com/cuu/gogame"
|
||||||
"./gogame/color"
|
"github.com/cuu/gogame/color"
|
||||||
"./gogame/display"
|
"github.com/cuu/gogame/display"
|
||||||
"./gogame/surface"
|
"github.com/cuu/gogame/surface"
|
||||||
"./gogame/event"
|
"github.com/cuu/gogame/event"
|
||||||
"./gogame/rect"
|
"github.com/cuu/gogame/rect"
|
||||||
"./gogame/draw"
|
"github.com/cuu/gogame/draw"
|
||||||
|
"github.com/cuu/gogame/image"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func run() int {
|
func run() int {
|
||||||
|
|
||||||
|
width := 320
|
||||||
|
height := 240
|
||||||
|
|
||||||
display.Init()
|
display.Init()
|
||||||
|
|
||||||
screen := display.SetMode(320,240,0,32)
|
screen := display.SetMode(int32(width),int32(height),0,32)
|
||||||
|
|
||||||
surface.Fill(screen, color.Color{0,0,0,0} )
|
surface.Fill(screen, color.Color{255,255,255,255} )
|
||||||
|
|
||||||
rect1 := rect.Rect(0,10, 12, 10)
|
rect1 := rect.Rect(0,10, 12, 10)
|
||||||
|
|
||||||
//surface.FillRect(screen,&rect, 0xffff0000)
|
//surface.FillRect(screen,&rect, 0xffff0000)
|
||||||
rect1.X = 12
|
rect1.X = 12
|
||||||
draw.Rect(screen,color.Color{129,235,234,0},&rect1,1)
|
draw.Rect(screen,color.Color{129,235,234,255},&rect1,1)
|
||||||
|
|
||||||
fmt.Println(screen.Pitch)
|
fmt.Println(screen.Pitch)
|
||||||
fmt.Println( screen.BytesPerPixel() )
|
fmt.Println( screen.BytesPerPixel() )
|
||||||
|
|
||||||
|
img_surf := image.Load("skin/default/sys.go/gameshell/icons/roundcorners.png")
|
||||||
|
|
||||||
|
|
||||||
|
fmt.Println("WxH: ", img_surf.W,img_surf.H)
|
||||||
|
|
||||||
|
portion := rect.Rect(0,0,10,10)
|
||||||
|
surface.Blit(screen,img_surf, draw.MidRect(5,5,10,10,width,height), &portion)
|
||||||
|
portion.Y = 10
|
||||||
|
surface.Blit(screen,img_surf, draw.MidRect(315,5,10,10,width,height), &portion)
|
||||||
|
portion.Y = 20
|
||||||
|
surface.Blit(screen,img_surf, draw.MidRect(5,235,10,10,width,height), &portion)
|
||||||
|
portion.Y = 30
|
||||||
|
surface.Blit(screen,img_surf, draw.MidRect(315,235,10,10,width,height), &portion)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for i:=1; i<319;i++ {
|
for i:=1; i<319;i++ {
|
||||||
draw.Point(screen, color.Color{255,44,255,0}, i,20)
|
draw.Point(screen, color.Color{255,44,255,0}, i,20)
|
||||||
|
|||||||