test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package main
  2. import (
  3. "os"
  4. "fmt"
  5. "github.com/veandco/go-sdl2/sdl"
  6. //"github.com/cuu/gogame"
  7. "github.com/cuu/gogame/color"
  8. "github.com/cuu/gogame/display"
  9. "github.com/cuu/gogame/surface"
  10. "github.com/cuu/gogame/event"
  11. "github.com/cuu/gogame/rect"
  12. "github.com/cuu/gogame/draw"
  13. "github.com/cuu/gogame/image"
  14. "github.com/cuu/gogame/font"
  15. "github.com/cuu/gogame/time"
  16. )
  17. func run() int {
  18. width := 320
  19. height := 240
  20. display.Init()
  21. screen := display.SetMode(int32(width),int32(height),0,32)
  22. surface.Fill(screen, &color.Color{255,255,255,255} )
  23. rect1 := rect.Rect(0,10, 12, 10)
  24. //surface.FillRect(screen,&rect, 0xffff0000)
  25. rect1.X = 12
  26. draw.Rect(screen,&color.Color{129,235,234,255},&rect1,1)
  27. fmt.Println(screen.Pitch)
  28. fmt.Println( screen.BytesPerPixel() )
  29. img_surf := image.Load("skin/default/sys.go/gameshell/icons/roundcorners.png")
  30. fmt.Println("WxH: ", img_surf.W,img_surf.H)
  31. portion := rect.Rect(0,0,10,10)
  32. surface.Blit(screen,img_surf, draw.MidRect(5,5,10,10,width,height), &portion)
  33. portion.Y = 10
  34. surface.Blit(screen,img_surf, draw.MidRect(315,5,10,10,width,height), &portion)
  35. portion.Y = 20
  36. surface.Blit(screen,img_surf, draw.MidRect(5,235,10,10,width,height), &portion)
  37. portion.Y = 30
  38. surface.Blit(screen,img_surf, draw.MidRect(315,235,10,10,width,height), &portion)
  39. /*
  40. for i:=1; i<319;i++ {
  41. draw.Point(screen, color.Color{255,44,255,0}, i,20)
  42. }
  43. */
  44. draw.Line(screen,&color.Color{255,44,255,255}, 0,100, 320,100,3)
  45. draw.Line(screen,&color.Color{255,44,255,255}, 10, 0, 10,250,4)
  46. rect2 := rect.Rect(3,120,200,30)
  47. draw.AARoundRect(screen,&rect2,&color.Color{0,213,222,255},10,0, &color.Color{0,213,222,255})
  48. font.Init()
  49. font_path := "skin/default/truetype/NotoSansCJK-Regular.ttf"
  50. notocjk15 := font.Font(font_path,15)
  51. fmt.Println( font.LineSize( notocjk15 ))
  52. my_text := font.Render(notocjk15,"Test ㆑ ㆒ ㆓ ㆔ ㆕ ㆖ 豈 更 車 賈 滑 串 句 龜 龜 契 金 ",true, &color.Color{234,123,12,255},nil)
  53. surface.Blit(screen,my_text,draw.MidRect(width/2,100,surface.GetWidth(my_text),surface.GetHeight(my_text),width,height),nil)
  54. my_text2 := font.Render(notocjk15,"Test ㆑ ㆒ ㆓ ㆔ ㆕ ㆖ 豈 更 車 賈 滑 串 句 龜 龜 契 金 ",true, &color.Color{234,123,12,255},&color.Color{0,0,111,255})
  55. surface.Blit(screen,my_text2,draw.MidRect(width/2,100+font.LineSize(notocjk15),surface.GetWidth(my_text),surface.GetHeight(my_text),width,height),nil)
  56. display.Flip()
  57. running := true
  58. for running {
  59. ev := event.Wait()
  60. if ev.Type == event.QUIT {
  61. running = false
  62. break
  63. }
  64. if ev.Type == event.USEREVENT {
  65. fmt.Println(ev.Data["Msg"])
  66. }
  67. if ev.Type == event.KEYDOWN {
  68. fmt.Println(ev)
  69. if ev.Data["Key"] == "Q" {
  70. return 0
  71. }
  72. if ev.Data["Key"] == "Escape" {
  73. return 0
  74. }
  75. if ev.Data["Key"] == "T" {
  76. time.Delay(1000)
  77. }
  78. if ev.Data["Key"] == "P" {
  79. event.Post(event.RUNEVT,"GODEBUG=cgocheck=0 sucks") // just id and string, simpify the stuff
  80. }
  81. }
  82. }
  83. return 0
  84. }
  85. func main() {
  86. var exitcode int
  87. os.Setenv("SDL_VIDEO_CENTERED","1")
  88. os.Setenv("GODEBUG", "cgocheck=0")
  89. sdl.Main(func() {
  90. exitcode = run()
  91. })
  92. os.Exit(exitcode)
  93. }