├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── bird.go
├── go.mod
├── go.sum
├── main.go
├── pipes.go
├── res
├── fonts
│ └── Flappy.ttf
└── imgs
│ ├── background.png
│ ├── bird_frame_1.png
│ ├── bird_frame_2.png
│ ├── bird_frame_3.png
│ ├── bird_frame_4.png
│ └── pipe.png
├── scene.go
└── vendor
├── github.com
└── veandco
│ └── go-sdl2
│ ├── CONTRIBUTORS.md
│ ├── LICENSE
│ ├── img
│ ├── sdl_image.go
│ ├── sdl_image_cgo.go
│ ├── sdl_image_cgo_static.go
│ └── sdl_image_wrapper.h
│ ├── sdl
│ ├── TODO.md
│ ├── audio.go
│ ├── blendmode.go
│ ├── clipboard.go
│ ├── cpuinfo.go
│ ├── endian.go
│ ├── error.go
│ ├── events.c
│ ├── events.go
│ ├── events.h
│ ├── filesystem.go
│ ├── gamecontroller.go
│ ├── gesture.go
│ ├── haptic.go
│ ├── helpers.go
│ ├── hints.c
│ ├── hints.go
│ ├── hints.h
│ ├── joystick.go
│ ├── keyboard.go
│ ├── keycode.go
│ ├── loadso.go
│ ├── log.c
│ ├── log.go
│ ├── log.h
│ ├── mouse.go
│ ├── mutex.go
│ ├── pixels.go
│ ├── power.go
│ ├── rect.go
│ ├── render.go
│ ├── rwops.go
│ ├── scancode.go
│ ├── sdl.go
│ ├── sdl_cgo.go
│ ├── sdl_cgo_static.go
│ ├── sdl_wrapper.h
│ ├── surface.go
│ ├── sysrender.go
│ ├── system_android.go
│ ├── syswm.go
│ ├── timer.go
│ ├── touch.go
│ ├── version.go
│ └── video.go
│ └── ttf
│ ├── sdl_ttf.go
│ ├── sdl_ttf_cgo.go
│ ├── sdl_ttf_cgo_static.go
│ └── sdl_ttf_wrapper.h
└── modules.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | **/.DS_Store
2 | flappy-gopher
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution,
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Flappy Gopher
2 |
3 | Flappy Gopher is a clone of the famous Flappy Bird game developed in Go with
4 | bindings for SDL2.
5 |
6 | ## Recordings
7 |
8 | You can learn more about the game and how it was implemented watching the three
9 | episodes dedicated to it.
10 |
11 |
17 |
18 |
24 |
25 |
31 |
32 | ## Installation
33 |
34 | You need to install first SDL2 and the SDL2 bindings for Go. To do so follow the instructions [here](https://github.com/veandco/go-sdl2).
35 | It is quite easy to install on basically any platform.
36 |
37 | You will also need to install [pkg-config](https://en.wikipedia.org/wiki/Pkg-config).
38 |
39 | After that you should be able to simply run:
40 |
41 | go get github.com/campoy/flappy-gopher
42 |
43 | And run the binary generated in `$GOPATH/bin`.
44 |
45 | ## Images, fonts, and licenses
46 |
47 | All the images used in this game are CC0 and obtained from [Clipart](https://openclipart.org/tags/flapping).
48 | You can find atlernative birds in there, so you can mod the game!
49 |
50 | The fonts are copied from https://github.com/deano2390/OpenFlappyBird.
51 |
52 | This project is licensed under Apache v2 license. Read more in the [LICENSE](LICENSE) file.
53 |
54 | ### Disclaimer
55 |
56 | This is not an official Google product (experimental or otherwise), it is just
57 | code that happens to be owned by Google.
--------------------------------------------------------------------------------
/bird.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to writing, software distributed
8 | // under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
9 | // CONDITIONS OF ANY KIND, either express or implied.
10 | //
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package main
15 |
16 | import (
17 | "fmt"
18 | "sync"
19 |
20 | "github.com/veandco/go-sdl2/sdl"
21 | img "github.com/veandco/go-sdl2/img"
22 | )
23 |
24 | const (
25 | gravity = 0.1
26 | jumpSpeed = 5
27 | )
28 |
29 | type bird struct {
30 | mu sync.RWMutex
31 |
32 | time int
33 | textures []*sdl.Texture
34 |
35 | x, y int32
36 | w, h int32
37 | speed float64
38 | dead bool
39 | }
40 |
41 | func newBird(r *sdl.Renderer) (*bird, error) {
42 | var textures []*sdl.Texture
43 | for i := 1; i <= 4; i++ {
44 | path := fmt.Sprintf("res/imgs/bird_frame_%d.png", i)
45 | texture, err := img.LoadTexture(r, path)
46 | if err != nil {
47 | return nil, fmt.Errorf("could not load background image: %v", err)
48 | }
49 | textures = append(textures, texture)
50 | }
51 | return &bird{textures: textures, x: 10, y: 300, w: 50, h: 43}, nil
52 | }
53 |
54 | func (b *bird) update() {
55 | b.mu.Lock()
56 | defer b.mu.Unlock()
57 |
58 | b.time++
59 | b.y -= int32(b.speed)
60 | if b.y < 0 {
61 | b.dead = true
62 | }
63 | b.speed += gravity
64 | }
65 |
66 | func (b *bird) paint(r *sdl.Renderer) error {
67 | b.mu.RLock()
68 | defer b.mu.RUnlock()
69 |
70 | rect := &sdl.Rect{X: 10, Y: 600 - b.y - b.h/2, W: b.w, H: b.h}
71 |
72 | i := b.time / 10 % len(b.textures)
73 | if err := r.Copy(b.textures[i], nil, rect); err != nil {
74 | return fmt.Errorf("could not copy background: %v", err)
75 | }
76 | return nil
77 | }
78 |
79 | func (b *bird) restart() {
80 | b.mu.Lock()
81 | defer b.mu.Unlock()
82 |
83 | b.y = 300
84 | b.speed = 0
85 | b.dead = false
86 | }
87 |
88 | func (b *bird) destroy() {
89 | b.mu.Lock()
90 | defer b.mu.Unlock()
91 |
92 | for _, t := range b.textures {
93 | t.Destroy()
94 | }
95 | }
96 |
97 | func (b *bird) isDead() bool {
98 | b.mu.RLock()
99 | defer b.mu.RUnlock()
100 | return b.dead
101 | }
102 |
103 | func (b *bird) jump() {
104 | b.mu.Lock()
105 | defer b.mu.Unlock()
106 |
107 | b.speed = -jumpSpeed
108 | }
109 |
110 | func (b *bird) touch(p *pipe) {
111 | b.mu.Lock()
112 | defer b.mu.Unlock()
113 |
114 | if p.x > b.x+b.w { // too far right
115 | return
116 | }
117 | if p.x+p.w < b.x { // too far left
118 | return
119 | }
120 | if !p.inverted && p.h < b.y-b.h/2 { // pipe is too low
121 | return
122 | }
123 | if p.inverted && 600-p.h > b.y+b.h/2 { // inverted pipe is too high
124 | return
125 | }
126 |
127 | b.dead = true
128 | }
129 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/campoy/flappy-gopher
2 |
3 | go 1.12
4 |
5 | require github.com/veandco/go-sdl2 v0.3.0
6 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/veandco/go-sdl2 v0.3.0 h1:IWYkHMp8V3v37NsKjszln8FFnX2+ab0538J371t+rss=
2 | github.com/veandco/go-sdl2 v0.3.0/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg=
3 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to writing, software distributed
8 | // under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
9 | // CONDITIONS OF ANY KIND, either express or implied.
10 | //
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package main
15 |
16 | import (
17 | "fmt"
18 | "os"
19 | "runtime"
20 | "time"
21 |
22 | "github.com/veandco/go-sdl2/sdl"
23 | ttf "github.com/veandco/go-sdl2/ttf"
24 | )
25 |
26 | func main() {
27 | if err := run(); err != nil {
28 | fmt.Fprintf(os.Stderr, "%v", err)
29 | os.Exit(2)
30 | }
31 | }
32 |
33 | func run() error {
34 | err := sdl.Init(sdl.INIT_EVERYTHING)
35 | if err != nil {
36 | return fmt.Errorf("could not initialize SDL: %v", err)
37 | }
38 | defer sdl.Quit()
39 |
40 | if err := ttf.Init(); err != nil {
41 | return fmt.Errorf("could not initialize TTF: %v", err)
42 | }
43 | defer ttf.Quit()
44 |
45 | w, r, err := sdl.CreateWindowAndRenderer(800, 600, sdl.WINDOW_SHOWN)
46 | if err != nil {
47 | return fmt.Errorf("could not create window: %v", err)
48 | }
49 | defer w.Destroy()
50 |
51 | if err := drawTitle(r, "Flappy Gopher"); err != nil {
52 | return fmt.Errorf("could not draw title: %v", err)
53 | }
54 |
55 | time.Sleep(1 * time.Second)
56 |
57 | s, err := newScene(r)
58 | if err != nil {
59 | return fmt.Errorf("could not create scene: %v", err)
60 | }
61 | defer s.destroy()
62 |
63 | events := make(chan sdl.Event)
64 | errc := s.run(events, r)
65 |
66 | runtime.LockOSThread()
67 | for {
68 | select {
69 | case events <- sdl.WaitEvent():
70 | case err := <-errc:
71 | return err
72 | }
73 | }
74 | }
75 |
76 | func drawTitle(r *sdl.Renderer, text string) error {
77 | r.Clear()
78 |
79 | f, err := ttf.OpenFont("res/fonts/Flappy.ttf", 20)
80 | if err != nil {
81 | return fmt.Errorf("could not load font: %v", err)
82 | }
83 | defer f.Close()
84 |
85 | c := sdl.Color{R: 255, G: 100, B: 0, A: 255}
86 | s, err := f.RenderUTF8Solid(text, c)
87 | if err != nil {
88 | return fmt.Errorf("could not render title: %v", err)
89 | }
90 | defer s.Free()
91 |
92 | t, err := r.CreateTextureFromSurface(s)
93 | if err != nil {
94 | return fmt.Errorf("could not create texture: %v", err)
95 | }
96 | defer t.Destroy()
97 |
98 | if err := r.Copy(t, nil, nil); err != nil {
99 | return fmt.Errorf("could not copy texture: %v", err)
100 | }
101 |
102 | r.Present()
103 |
104 | return nil
105 | }
106 |
--------------------------------------------------------------------------------
/pipes.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to writing, software distributed
8 | // under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
9 | // CONDITIONS OF ANY KIND, either express or implied.
10 | //
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package main
15 |
16 | import (
17 | "fmt"
18 | "math/rand"
19 | "sync"
20 | "time"
21 |
22 | "github.com/veandco/go-sdl2/sdl"
23 | img "github.com/veandco/go-sdl2/img"
24 | )
25 |
26 | type pipes struct {
27 | mu sync.RWMutex
28 |
29 | texture *sdl.Texture
30 | speed int32
31 |
32 | pipes []*pipe
33 | }
34 |
35 | func newPipes(r *sdl.Renderer) (*pipes, error) {
36 | texture, err := img.LoadTexture(r, "res/imgs/pipe.png")
37 | if err != nil {
38 | return nil, fmt.Errorf("could not load pipe image: %v", err)
39 | }
40 |
41 | ps := &pipes{
42 | texture: texture,
43 | speed: 2,
44 | }
45 |
46 | go func() {
47 | for {
48 | ps.mu.Lock()
49 | ps.pipes = append(ps.pipes, newPipe())
50 | ps.mu.Unlock()
51 | time.Sleep(time.Second)
52 | }
53 | }()
54 |
55 | return ps, nil
56 | }
57 |
58 | func (ps *pipes) paint(r *sdl.Renderer) error {
59 | ps.mu.RLock()
60 | defer ps.mu.RUnlock()
61 |
62 | for _, p := range ps.pipes {
63 | if err := p.paint(r, ps.texture); err != nil {
64 | return err
65 | }
66 | }
67 | return nil
68 | }
69 |
70 | func (ps *pipes) touch(b *bird) {
71 | ps.mu.RLock()
72 | defer ps.mu.RUnlock()
73 | for _, p := range ps.pipes {
74 | p.touch(b)
75 | }
76 | }
77 |
78 | func (ps *pipes) restart() {
79 | ps.mu.Lock()
80 | defer ps.mu.Unlock()
81 |
82 | ps.pipes = nil
83 | }
84 |
85 | func (ps *pipes) update() {
86 | ps.mu.Lock()
87 | defer ps.mu.Unlock()
88 |
89 | var rem []*pipe
90 | for _, p := range ps.pipes {
91 | p.mu.Lock()
92 | p.x -= ps.speed
93 | p.mu.Unlock()
94 | if p.x+p.w > 0 {
95 | rem = append(rem, p)
96 | }
97 | }
98 | ps.pipes = rem
99 | }
100 |
101 | func (ps *pipes) destroy() {
102 | ps.mu.Lock()
103 | defer ps.mu.Unlock()
104 |
105 | ps.texture.Destroy()
106 | }
107 |
108 | type pipe struct {
109 | mu sync.RWMutex
110 |
111 | x int32
112 | h int32
113 | w int32
114 | inverted bool
115 | }
116 |
117 | func newPipe() *pipe {
118 | return &pipe{
119 | x: 800,
120 | h: 100 + int32(rand.Intn(300)),
121 | w: 50,
122 | inverted: rand.Float32() > 0.5,
123 | }
124 | }
125 |
126 | func (p *pipe) touch(b *bird) {
127 | p.mu.RLock()
128 | defer p.mu.RUnlock()
129 | b.touch(p)
130 | }
131 |
132 | func (p *pipe) paint(r *sdl.Renderer, texture *sdl.Texture) error {
133 | p.mu.RLock()
134 | defer p.mu.RUnlock()
135 |
136 | rect := &sdl.Rect{X: p.x, Y: 600 - p.h, W: p.w, H: p.h}
137 | flip := sdl.FLIP_NONE
138 | if p.inverted {
139 | rect.Y = 0
140 | flip = sdl.FLIP_VERTICAL
141 | }
142 |
143 | if err := r.CopyEx(texture, nil, rect, 0, nil, flip); err != nil {
144 | return fmt.Errorf("could not copy background: %v", err)
145 | }
146 |
147 | return nil
148 | }
149 |
--------------------------------------------------------------------------------
/res/fonts/Flappy.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/campoy/flappy-gopher/5f88ba929239e4e1787a51cf098d69d1289a280a/res/fonts/Flappy.ttf
--------------------------------------------------------------------------------
/res/imgs/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/campoy/flappy-gopher/5f88ba929239e4e1787a51cf098d69d1289a280a/res/imgs/background.png
--------------------------------------------------------------------------------
/res/imgs/bird_frame_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/campoy/flappy-gopher/5f88ba929239e4e1787a51cf098d69d1289a280a/res/imgs/bird_frame_1.png
--------------------------------------------------------------------------------
/res/imgs/bird_frame_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/campoy/flappy-gopher/5f88ba929239e4e1787a51cf098d69d1289a280a/res/imgs/bird_frame_2.png
--------------------------------------------------------------------------------
/res/imgs/bird_frame_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/campoy/flappy-gopher/5f88ba929239e4e1787a51cf098d69d1289a280a/res/imgs/bird_frame_3.png
--------------------------------------------------------------------------------
/res/imgs/bird_frame_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/campoy/flappy-gopher/5f88ba929239e4e1787a51cf098d69d1289a280a/res/imgs/bird_frame_4.png
--------------------------------------------------------------------------------
/res/imgs/pipe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/campoy/flappy-gopher/5f88ba929239e4e1787a51cf098d69d1289a280a/res/imgs/pipe.png
--------------------------------------------------------------------------------
/scene.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to writing, software distributed
8 | // under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
9 | // CONDITIONS OF ANY KIND, either express or implied.
10 | //
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package main
15 |
16 | import (
17 | "fmt"
18 | "log"
19 | "time"
20 |
21 | "github.com/veandco/go-sdl2/sdl"
22 | img "github.com/veandco/go-sdl2/img"
23 | )
24 |
25 | type scene struct {
26 | bg *sdl.Texture
27 | bird *bird
28 | pipes *pipes
29 | }
30 |
31 | func newScene(r *sdl.Renderer) (*scene, error) {
32 | bg, err := img.LoadTexture(r, "res/imgs/background.png")
33 | if err != nil {
34 | return nil, fmt.Errorf("could not load background image: %v", err)
35 | }
36 |
37 | b, err := newBird(r)
38 | if err != nil {
39 | return nil, err
40 | }
41 |
42 | ps, err := newPipes(r)
43 | if err != nil {
44 | return nil, err
45 | }
46 |
47 | return &scene{bg: bg, bird: b, pipes: ps}, nil
48 | }
49 |
50 | func (s *scene) run(events <-chan sdl.Event, r *sdl.Renderer) <-chan error {
51 | errc := make(chan error)
52 |
53 | go func() {
54 | defer close(errc)
55 | tick := time.Tick(10 * time.Millisecond)
56 | for {
57 | select {
58 | case e := <-events:
59 | if done := s.handleEvent(e); done {
60 | return
61 | }
62 | case <-tick:
63 | s.update()
64 |
65 | if s.bird.isDead() {
66 | drawTitle(r, "Game Over")
67 | time.Sleep(time.Second)
68 | s.restart()
69 | }
70 |
71 | if err := s.paint(r); err != nil {
72 | errc <- err
73 | }
74 | }
75 | }
76 | }()
77 |
78 | return errc
79 | }
80 |
81 | func (s *scene) handleEvent(event sdl.Event) bool {
82 | switch event.(type) {
83 | case *sdl.QuitEvent:
84 | return true
85 | case *sdl.MouseButtonEvent:
86 | s.bird.jump()
87 | case *sdl.MouseMotionEvent, *sdl.WindowEvent, *sdl.TouchFingerEvent, *sdl.CommonEvent:
88 | default:
89 | log.Printf("unknown event %T", event)
90 | }
91 | return false
92 | }
93 |
94 | func (s *scene) update() {
95 | s.bird.update()
96 | s.pipes.update()
97 | s.pipes.touch(s.bird)
98 | }
99 |
100 | func (s *scene) restart() {
101 | s.bird.restart()
102 | s.pipes.restart()
103 | }
104 |
105 | func (s *scene) paint(r *sdl.Renderer) error {
106 | r.Clear()
107 | if err := r.Copy(s.bg, nil, nil); err != nil {
108 | return fmt.Errorf("could not copy background: %v", err)
109 | }
110 | if err := s.bird.paint(r); err != nil {
111 | return err
112 | }
113 | if err := s.pipes.paint(r); err != nil {
114 | return err
115 | }
116 | r.Present()
117 | return nil
118 | }
119 |
120 | func (s *scene) destroy() {
121 | s.bg.Destroy()
122 | s.bird.destroy()
123 | s.pipes.destroy()
124 | }
125 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/CONTRIBUTORS.md:
--------------------------------------------------------------------------------
1 | Contributors
2 | ============
3 | Here's the list of contributors with their respective Github URLs.
4 | * [Jacky Boen](https://github.com/jackyb)
5 | * [HardWareGuy](https://github.com/HardWareGuy)
6 | * [akovaski](https://github.com/akovaski)
7 | * [Jeromy Johnson](https://github.com/whyrusleeping)
8 | * [Cai Lei](https://github.com/ccll)
9 | * [Arne Döring](https://github.com/krux02)
10 | * [Marcus von Appen](https://github.com/marcusva)
11 | * [Tom Murray](https://github.com/TomMurray)
12 | * [Ian Davis](https://github.com/iand)
13 | * [hschendel](https://github.com/hschendel)
14 | * [Ingo Oeser](https://github.com/nightlyone)
15 | * [nlordell](https://github.com/nlordell)
16 | * [Ben Davies](https://github.com/JalfResi)
17 | * [Bastien Dejean](https://github.com/baskerville)
18 | * [Pirmin Tapken](https://github.com/PirminTapken)
19 | * [Robert Lillack](https://github.com/roblillack)
20 | * [Marcell Jusztin](https://github.com/morcmarc)
21 | * [Stan Schwertly](https://github.com/Stantheman)
22 | * [Michael Vetter](https://github.com/jubalh)
23 | * [Tom Fogal](https://github.com/tfogal)
24 | * [Philipp Meinen](https://github.com/PhiCode)
25 | * [Thomas McGrew](https://github.com/mcgrew)
26 | * [Geoff Catlin](https://github.com/gcatlin)
27 | * [Schobers](https://github.com/Schobers)
28 | * [Jan Tuitman](https://github.com/jantuitman)
29 | * [Nick Powell](https://github.com/THUNDERGROOVE)
30 | * [Steven R. Wiley](https://github.com/srwiley)
31 | * [Franco Lazzarino](https://github.com/flazz)
32 | * [Jason Alan Palmer](https://github.com/jalan)
33 | * [Seuk Won Kang](https://github.com/kasworld)
34 | * [Brandon Mulcahy](https://github.com/jangler)
35 | * [Tim Anema](https://github.com/tanema)
36 | * [Tyler Compton](https://github.com/velovix)
37 | * [Nicolas Hess](https://github.com/n0dev)
38 | * [Stephen Noonan](https://github.com/tycho)
39 | * [Guilherme Freitas Nemeth](https://github.com/glhrmfrts)
40 | * [Charney Kaye](https://github.com/charneykaye)
41 | * [Lars Scheme](https://github.com/gonutz)
42 | * [Emil Laine](https://github.com/emlai)
43 | * [Sergey Parshukov](https://github.com/jBugman)
44 | * [Casey DeLorme](https://github.com/cdelorme)
45 | * [Andreas T. Jonsson](https://github.com/andreas-jonsson)
46 | * [Milan Nikolic](https://github.com/gen2brain)
47 | * [Mike Gerow](https://github.com/gerow)
48 | * [Lilis Iskandar](https://github.com/veeableful)
49 | * [tfriedel6](https://github.com/tfriedel6)
50 | * [Eric Bronner](https://github.com/MoonWatcher582)
51 | * [Julien Castelain](https://github.com/julien)
52 | * [Robert Wallis](https://github.com/robert-wallis)
53 | * [Chae-Young Song](https://github.com/chaeyoungsong)
54 | * [Robert Wallis](https://github.com/robert-wallis)
55 | * [Lennart Buhl](https://github.com/r41d)
56 | * [Giovanni Bajo](https://github.com/rasky)
57 | * [Laurent Vaucher](https://github.com/slowfrog)
58 | * [Mike](https://github.com/barbeque)
59 | * [Tomas Virgl](https://github.com/tvi)
60 | * [Aye Aye Maung](https://github.com/ZeroXLR)
61 | * [Anton Malashin](https://github.com/malashin)
62 | * [John Perkins](https://github.com/mpath)
63 |
64 | _if anyone is missing, let me know!.. or you can add yourself in :)_
65 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, Go-SDL2 Authors
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright
10 | notice, this list of conditions and the following disclaimer in the
11 | documentation and/or other materials provided with the distribution.
12 | * Neither the name of Go-SDL2 nor the names of its contributors may be
13 | used to endorse or promote products derived from this software without specific
14 | prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/img/sdl_image.go:
--------------------------------------------------------------------------------
1 | // Package img is a simple library to load images of various formats as SDL surfaces.
2 | package img
3 |
4 | //#include
5 | //#include "sdl_image_wrapper.h"
6 | import "C"
7 | import "unsafe"
8 | import "errors"
9 | import "github.com/veandco/go-sdl2/sdl"
10 |
11 | // Flags which may be passed to img.Init() to load support of image formats, can be bitwise OR'd together.
12 | const (
13 | INIT_JPG = 0x00000001 // JPG
14 | INIT_PNG = 0x00000002 // PNG
15 | INIT_TIF = 0x00000004 // TIF
16 | INIT_WEBP = 0x00000008 // WebP
17 | )
18 |
19 | // LinkedVersion returns the version of the dynamically linked SDL_image library.
20 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_7.html)
21 | func LinkedVersion() *sdl.Version {
22 | return (*sdl.Version)(unsafe.Pointer(C.IMG_Linked_Version()))
23 | }
24 |
25 | // Init loads dynamic libraries and prepares them for use. Flags should be one or more flags from IMG_InitFlags OR'd together. It returns the flags successfully initialized, or 0 on failure.
26 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_8.html)
27 | func Init(flags int) int {
28 | _flags := (C.int)(flags)
29 | return int(C.IMG_Init(_flags))
30 | }
31 |
32 | // Quit unloads libraries loaded with img.Init().
33 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_9.html)
34 | func Quit() {
35 | C.IMG_Quit()
36 | }
37 |
38 | // GetError returns the last error that occurred, or an empty string if there hasn't been an error message set since the last call to sdl.ClearError().
39 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_45.html)
40 | func GetError() error {
41 | e := C.IMG_GetError()
42 | if e == nil {
43 | return nil
44 | }
45 | return errors.New(C.GoString(e))
46 | }
47 |
48 | // LoadTypedRW loads an image from an SDL data source. The 'type' may be one of: "BMP", "GIF", "PNG", etc. If the image format supports a transparent pixel, SDL will set the colorkey for the surface.
49 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_13.html)
50 | func LoadTypedRW(src *sdl.RWops, freesrc bool, type_ string) (*sdl.Surface, error) {
51 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
52 | _freesrc := (C.int)(sdl.Btoi(freesrc))
53 | _type := C.CString(type_)
54 | defer C.free(unsafe.Pointer(_type))
55 | _surface := C.IMG_LoadTyped_RW(_src, _freesrc, _type)
56 | if _surface == nil {
57 | return nil, GetError()
58 | }
59 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
60 | }
61 |
62 | // Load loads a file for use as an image in a new surface.
63 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_11.html)
64 | func Load(file string) (*sdl.Surface, error) {
65 | _file := C.CString(file)
66 | defer C.free(unsafe.Pointer(_file))
67 | _surface := C.IMG_Load(_file)
68 | if _surface == nil {
69 | return nil, GetError()
70 | }
71 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
72 | }
73 |
74 | // LoadRW loads an image from an SDL data source for use as a surface.
75 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_12.html)
76 | func LoadRW(src *sdl.RWops, freesrc bool) (*sdl.Surface, error) {
77 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
78 | _freesrc := (C.int)(sdl.Btoi(freesrc))
79 | _surface := C.IMG_Load_RW(_src, _freesrc)
80 | if _surface == nil {
81 | return nil, GetError()
82 | }
83 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
84 | }
85 |
86 | // LoadTexture loads an image directly into a render texture.
87 | func LoadTexture(renderer *sdl.Renderer, file string) (*sdl.Texture, error) {
88 | _renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
89 | _file := C.CString(file)
90 | defer C.free(unsafe.Pointer(_file))
91 | _surface := C.IMG_LoadTexture(_renderer, _file)
92 | if _surface == nil {
93 | return nil, GetError()
94 | }
95 | return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
96 | }
97 |
98 | // LoadTextureRW loads an image from an SDL data source directly into a render texture.
99 | func LoadTextureRW(renderer *sdl.Renderer, src *sdl.RWops, freesrc bool) (*sdl.Texture, error) {
100 | _renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
101 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
102 | _freesrc := (C.int)(sdl.Btoi(freesrc))
103 | _surface := C.IMG_LoadTexture_RW(_renderer, _src, _freesrc)
104 | if _surface == nil {
105 | return nil, GetError()
106 | }
107 | return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
108 | }
109 |
110 | // IsICO reports whether ICO format is supported and image data is readable as an ICO.
111 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_31.html)
112 | func IsICO(src *sdl.RWops) bool {
113 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
114 | return int(C.IMG_isICO(_src)) > 0
115 | }
116 |
117 | // IsCUR reports whether CUR format is supported and image data is readable as a CUR.
118 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_30.html)
119 | func IsCUR(src *sdl.RWops) bool {
120 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
121 | return int(C.IMG_isCUR(_src)) > 0
122 | }
123 |
124 | // IsBMP reports whether BMP format is supported and image data is readable as a BMP.
125 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_32.html)
126 | func IsBMP(src *sdl.RWops) bool {
127 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
128 | return int(C.IMG_isBMP(_src)) > 0
129 | }
130 |
131 | // IsGIF reports whether GIF format is supported and image data is readable as a GIF.
132 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_37.html)
133 | func IsGIF(src *sdl.RWops) bool {
134 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
135 | return int(C.IMG_isGIF(_src)) > 0
136 | }
137 |
138 | // IsJPG reports whether JPG format is supported and image data is readable as a JPG.
139 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_38.html)
140 | func IsJPG(src *sdl.RWops) bool {
141 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
142 | return int(C.IMG_isJPG(_src)) > 0
143 | }
144 |
145 | // IsLBM reports whether LBM format is supported and image data is readable as an LBM.
146 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_41.html)
147 | func IsLBM(src *sdl.RWops) bool {
148 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
149 | return int(C.IMG_isLBM(_src)) > 0
150 | }
151 |
152 | // IsPCX reports whether PCX format is supported and image data is readable as a PCX.
153 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_36.html)
154 | func IsPCX(src *sdl.RWops) bool {
155 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
156 | return int(C.IMG_isPCX(_src)) > 0
157 | }
158 |
159 | // IsPNG reports whether PNG format is supported and image data is readable as a PNG.
160 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_40.html)
161 | func IsPNG(src *sdl.RWops) bool {
162 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
163 | return int(C.IMG_isPNG(_src)) > 0
164 | }
165 |
166 | // IsPNM reports whether PNM format is supported and image data is readable as a PNM.
167 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_33.html)
168 | func IsPNM(src *sdl.RWops) bool {
169 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
170 | return int(C.IMG_isPNM(_src)) > 0
171 | }
172 |
173 | // IsTIF reports whether TIF format is supported and image data is readable as a TIF.
174 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_39.html)
175 | func IsTIF(src *sdl.RWops) bool {
176 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
177 | return int(C.IMG_isTIF(_src)) > 0
178 | }
179 |
180 | // IsXCF reports whether XCF format is supported and image data is readable as an XCF.
181 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_35.html)
182 | func IsXCF(src *sdl.RWops) bool {
183 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
184 | return int(C.IMG_isXCF(_src)) > 0
185 | }
186 |
187 | // IsXPM reports whether XPM format is supported and image data is readable as an XPM.
188 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_34.html)
189 | func IsXPM(src *sdl.RWops) bool {
190 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
191 | return int(C.IMG_isXPM(_src)) > 0
192 | }
193 |
194 | // IsXV reports whether XV format is supported and image data is readable as an XV thumbnail.
195 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_42.html)
196 | func IsXV(src *sdl.RWops) bool {
197 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
198 | return int(C.IMG_isXV(_src)) > 0
199 | }
200 |
201 | // IsWEBP reports whether WEBP format is supported and image data is readable as a WEBP.
202 | func IsWEBP(src *sdl.RWops) bool {
203 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
204 | return int(C.IMG_isWEBP(_src)) > 0
205 | }
206 |
207 | // LoadICORW loads an ICO image from an SDL data source for use as a surface.
208 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_15.html)
209 | func LoadICORW(src *sdl.RWops) (*sdl.Surface, error) {
210 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
211 | _surface := C.IMG_LoadICO_RW(_src)
212 | if _surface == nil {
213 | return nil, GetError()
214 | }
215 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
216 | }
217 |
218 | // LoadCURRW loads a CUR image from an SDL data source for use as a surface.
219 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_14.html)
220 | func LoadCURRW(src *sdl.RWops) (*sdl.Surface, error) {
221 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
222 | _surface := C.IMG_LoadCUR_RW(_src)
223 | if _surface == nil {
224 | return nil, GetError()
225 | }
226 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
227 | }
228 |
229 | // LoadBMPRW loads a BMP image from an SDL data source for use as a surface.
230 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_16.html)
231 | func LoadBMPRW(src *sdl.RWops) (*sdl.Surface, error) {
232 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
233 | _surface := C.IMG_LoadBMP_RW(_src)
234 | if _surface == nil {
235 | return nil, GetError()
236 | }
237 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
238 | }
239 |
240 | // LoadGIFRW loads a GIF image from an SDL data source for use as a surface.
241 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_21.html)
242 | func LoadGIFRW(src *sdl.RWops) (*sdl.Surface, error) {
243 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
244 | _surface := C.IMG_LoadGIF_RW(_src)
245 | if _surface == nil {
246 | return nil, GetError()
247 | }
248 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
249 | }
250 |
251 | // LoadJPGRW loads a JPG image from an SDL data source for use as a surface.
252 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_22.html)
253 | func LoadJPGRW(src *sdl.RWops) (*sdl.Surface, error) {
254 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
255 | _surface := C.IMG_LoadJPG_RW(_src)
256 | if _surface == nil {
257 | return nil, GetError()
258 | }
259 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
260 | }
261 |
262 | // LoadLBMRW loads an LBM image from an SDL data source for use as a surface.
263 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_26.html)
264 | func LoadLBMRW(src *sdl.RWops) (*sdl.Surface, error) {
265 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
266 | _surface := C.IMG_LoadLBM_RW(_src)
267 | if _surface == nil {
268 | return nil, GetError()
269 | }
270 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
271 | }
272 |
273 | // LoadPCXRW loads a PCX image from an SDL data source for use as a surface.
274 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_20.html)
275 | func LoadPCXRW(src *sdl.RWops) (*sdl.Surface, error) {
276 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
277 | _surface := C.IMG_LoadPCX_RW(_src)
278 | if _surface == nil {
279 | return nil, GetError()
280 | }
281 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
282 | }
283 |
284 | // LoadPNGRW loads a PNG image from an SDL data source for use as a surface.
285 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_24.html)
286 | func LoadPNGRW(src *sdl.RWops) (*sdl.Surface, error) {
287 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
288 | _surface := C.IMG_LoadPNG_RW(_src)
289 | if _surface == nil {
290 | return nil, GetError()
291 | }
292 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
293 | }
294 |
295 | // LoadPNMRW loads a PNM image from an SDL data source for use as a surface.
296 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_17.html)
297 | func LoadPNMRW(src *sdl.RWops) (*sdl.Surface, error) {
298 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
299 | _surface := C.IMG_LoadPNM_RW(_src)
300 | if _surface == nil {
301 | return nil, GetError()
302 | }
303 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
304 | }
305 |
306 | // LoadTGARW loads a TGA image from an SDL data source for use as a surface.
307 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_25.html)
308 | func LoadTGARW(src *sdl.RWops) (*sdl.Surface, error) {
309 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
310 | _surface := C.IMG_LoadTGA_RW(_src)
311 | if _surface == nil {
312 | return nil, GetError()
313 | }
314 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
315 | }
316 |
317 | // LoadTIFRW loads a TIF image from an SDL data source for use as a surface.
318 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_23.html)
319 | func LoadTIFRW(src *sdl.RWops) (*sdl.Surface, error) {
320 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
321 | _surface := C.IMG_LoadTIF_RW(_src)
322 | if _surface == nil {
323 | return nil, GetError()
324 | }
325 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
326 | }
327 |
328 | // LoadXCFRW loads an XCF image from an SDL data source for use as a surface.
329 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_19.html)
330 | func LoadXCFRW(src *sdl.RWops) (*sdl.Surface, error) {
331 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
332 | _surface := C.IMG_LoadXCF_RW(_src)
333 | if _surface == nil {
334 | return nil, GetError()
335 | }
336 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
337 | }
338 |
339 | // LoadXPMRW loads an XPM image from an SDL data source for use as a surface.
340 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_18.html)
341 | func LoadXPMRW(src *sdl.RWops) (*sdl.Surface, error) {
342 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
343 | _surface := C.IMG_LoadXPM_RW(_src)
344 | if _surface == nil {
345 | return nil, GetError()
346 | }
347 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
348 | }
349 |
350 | // LoadXVRW loads an XV thumbnail image from an SDL data source for use as a surface.
351 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_27.html)
352 | func LoadXVRW(src *sdl.RWops) (*sdl.Surface, error) {
353 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
354 | _surface := C.IMG_LoadXV_RW(_src)
355 | if _surface == nil {
356 | return nil, GetError()
357 | }
358 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
359 | }
360 |
361 | // LoadWEBPRW loads a WEBP image from an SDL data source for use as a surface.
362 | func LoadWEBPRW(src *sdl.RWops) (*sdl.Surface, error) {
363 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
364 | _surface := C.IMG_LoadWEBP_RW(_src)
365 | if _surface == nil {
366 | return nil, GetError()
367 | }
368 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
369 | }
370 |
371 | // ReadXPMFromArray loads an XPM image from xpm data for use as a surface.
372 | // (http://www.libsdl.org/projects/SDL_image/docs/SDL_image_28.html)
373 | func ReadXPMFromArray(xpm string) (*sdl.Surface, error) {
374 | _xpm := C.CString(xpm)
375 | defer C.free(unsafe.Pointer(_xpm))
376 | _surface := C.IMG_ReadXPMFromArray(&_xpm)
377 | if _surface == nil {
378 | return nil, GetError()
379 | }
380 | return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
381 | }
382 |
383 | // SavePNG saves a surface as PNG file.
384 | func SavePNG(surface *sdl.Surface, file string) error {
385 | _surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
386 | _file := C.CString(file)
387 | defer C.free(unsafe.Pointer(_file))
388 | _ret := C.IMG_SavePNG(_surface, _file)
389 | if _ret < 0 {
390 | return GetError()
391 | }
392 | return nil
393 | }
394 |
395 | // SavePNGRW saves a surface to an SDL data source.
396 | func SavePNGRW(surface *sdl.Surface, dst *sdl.RWops, freedst int) error {
397 | _surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
398 | _dst := (*C.SDL_RWops)(unsafe.Pointer(dst))
399 | _freedst := (C.int)(freedst)
400 | _ret := C.IMG_SavePNG_RW(_surface, _dst, _freedst)
401 | if _ret < 0 {
402 | return GetError()
403 | }
404 | return nil
405 | }
406 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/img/sdl_image_cgo.go:
--------------------------------------------------------------------------------
1 | // +build !static
2 |
3 | package img
4 |
5 | //#cgo linux freebsd darwin pkg-config: sdl2
6 | //#cgo linux freebsd darwin LDFLAGS: -lSDL2_image
7 | //#cgo windows LDFLAGS: -lSDL2 -lSDL2_image
8 | import "C"
9 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/img/sdl_image_cgo_static.go:
--------------------------------------------------------------------------------
1 | // +build static
2 |
3 | package img
4 |
5 | //#cgo CFLAGS: -I${SRCDIR}/../.go-sdl2-libs/include -I${SRCDIR}/../.go-sdl2-libs/include/SDL2
6 | //#cgo LDFLAGS: -L${SRCDIR}/../.go-sdl2-libs
7 | //#cgo linux,386 LDFLAGS: -lSDL2_image_linux_386 -Wl,--no-undefined -lpng_linux_386 -ljpeg_linux_386 -lSDL2_linux_386 -lm -ldl -lz -lasound -lm -ldl -lpthread -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt
8 | //#cgo linux,amd64 LDFLAGS: -lSDL2_image_linux_amd64 -Wl,--no-undefined -lpng_linux_amd64 -ljpeg_linux_amd64 -lSDL2_linux_amd64 -lm -ldl -lz -lasound -lm -ldl -lpthread -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt
9 | //#cgo windows,386 LDFLAGS: -lSDL2_image_windows_386 -Wl,--no-undefined -lpng_windows_386 -ljpeg_windows_386 -lz_windows_386 -lSDL2_windows_386 -lSDL2main_windows_386 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
10 | //#cgo windows,amd64 LDFLAGS: -lSDL2_image_windows_amd64 -Wl,--no-undefined -lpng_windows_amd64 -ljpeg_windows_amd64 -lz_windows_amd64 -lSDL2_windows_amd64 -lSDL2main_windows_amd64 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
11 | //#cgo darwin,amd64 LDFLAGS: -lSDL2_image_darwin_amd64 -lSDL2_darwin_amd64 -lpng_darwin_amd64 -ljpeg_darwin_amd64 -lm -lz -liconv -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit
12 | //#cgo android,arm LDFLAGS: -lSDL2_image_android_arm -Wl,--no-undefined -lpng_android_arm -ljpeg_android_arm -lSDL2_android_arm -lm -ldl -lz -llog -landroid -lGLESv2
13 | //#cgo linux,arm LDFLAGS: -lSDL2_image_linux_arm -Wl,--no-undefined -lpng_linux_arm -ljpeg_linux_arm -lSDL2_linux_arm -lm -ldl -lz -liconv
14 | import "C"
15 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/img/sdl_image_wrapper.h:
--------------------------------------------------------------------------------
1 | #if defined(__WIN32)
2 | #include
3 | #include
4 | #else
5 | #include
6 | #endif
7 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/TODO.md:
--------------------------------------------------------------------------------
1 | ## 2.0.6
2 |
3 | ### General
4 |
5 | Blend Mode
6 |
7 | - [ ] SDL_ComposeCustomBlendMode()
8 |
9 | CPU Info
10 |
11 | - [ ] SDL_HasNEON()
12 |
13 | Game Controller
14 |
15 | - [x] SDL_GameControllerGetVendor()
16 | - [x] SDL_GameControllerGetProduct()
17 | - [x] SDL_GameControllerGetProductVersion()
18 | - [x] SDL_GameControllerNumMappings()
19 | - [x] SDL_GameControllerMappingForIndex()
20 |
21 | Hints
22 |
23 | - [ ] SDL_HINT_AUDIO_RESAMPLING_MODE
24 | - [ ] SDL_HINT_RENDER_LOGICAL_SIZE_MODE
25 | - [ ] SDL_HINT_MOUSE_NORMAL_SPEED_SCALE
26 | - [ ] SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE
27 | - [ ] SDL_HINT_TOUCH_MOUSE_EVENTS
28 |
29 | Joystick
30 |
31 | - [x] SDL_JoystickGetDeviceVendor()
32 | - [x] SDL_JoystickGetDeviceProduct()
33 | - [x] SDL_JoystickGetDeviceProductVersion()
34 | - [x] SDL_JoystickGetDeviceType()
35 | - [x] SDL_JoystickGetDeviceInstanceID()
36 | - [x] SDL_JoystickGetVendor()
37 | - [x] SDL_JoystickGetProduct()
38 | - [x] SDL_JoystickGetProductVersion()
39 | - [x] SDL_JoystickGetType()
40 | - [x] SDL_JoystickGetAxisInitialState()
41 |
42 | RW Ops
43 |
44 | - [ ] SDL_LoadFile()
45 | - [ ] SDL_LoadFile_RW()
46 |
47 | Surface
48 |
49 | - [ ] SDL_DuplicateSurface()
50 |
51 | Vulkan
52 |
53 | - [ ] SDL_Vulkan_LoadLibrary()
54 | - [ ] SDL_Vulkan_GetVkGetInstanceProcAddr()
55 | - [ ] SDL_Vulkan_GetInstanceExtensions()
56 | - [ ] SDL_Vulkan_CreateSurface()
57 | - [ ] SDL_Vulkan_GetDrawableSize()
58 | - [ ] SDL_Vulkan_UnloadLibrary()
59 |
60 | ### Windows
61 |
62 | Hints
63 |
64 | - [ ] SDL_HINT_WINDOWS_INTRESOURCE_ICON
65 | - [ ] SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL
66 |
67 | ## Miscellaneous
68 |
69 | - [ ] Add ability to set window title bar color on runtime
70 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/blendmode.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // BlendMode is an enumeration of blend modes used in Render.Copy() and drawing operations.
8 | // (https://wiki.libsdl.org/SDL_BlendMode)
9 | type BlendMode uint32
10 |
11 | // BlendMode is an enumeration of blend modes used in Render.Copy() and drawing operations.
12 | // (https://wiki.libsdl.org/SDL_BlendMode)
13 | const (
14 | BLENDMODE_NONE = C.SDL_BLENDMODE_NONE // no blending
15 | BLENDMODE_BLEND = C.SDL_BLENDMODE_BLEND // alpha blending
16 | BLENDMODE_ADD = C.SDL_BLENDMODE_ADD // additive blending
17 | BLENDMODE_MOD = C.SDL_BLENDMODE_MOD // color modulate
18 | )
19 |
20 | func (bm BlendMode) c() C.SDL_BlendMode {
21 | return C.SDL_BlendMode(C.Uint32(bm))
22 | }
23 |
24 | func (bm *BlendMode) cptr() *C.SDL_BlendMode {
25 | return (*C.SDL_BlendMode)(unsafe.Pointer(bm))
26 | }
27 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/clipboard.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // SetClipboardText puts UTF-8 text into the clipboard.
8 | // (https://wiki.libsdl.org/SDL_SetClipboardText)
9 | func SetClipboardText(text string) error {
10 | _text := C.CString(text)
11 | defer C.free(unsafe.Pointer(_text))
12 | if C.SDL_SetClipboardText(_text) < 0 {
13 | return GetError()
14 | }
15 | return nil
16 | }
17 |
18 | // GetClipboardText returns UTF-8 text from the clipboard.
19 | // (https://wiki.libsdl.org/SDL_GetClipboardText)
20 | func GetClipboardText() (string, error) {
21 | text := C.SDL_GetClipboardText()
22 | if text == nil {
23 | return "", GetError()
24 | }
25 | defer C.SDL_free(unsafe.Pointer(text))
26 | _text := C.GoString(text)
27 | return _text, nil
28 | }
29 |
30 | // HasClipboardText reports whether the clipboard exists and contains a text string that is non-empty.
31 | // (https://wiki.libsdl.org/SDL_HasClipboardText)
32 | func HasClipboardText() bool {
33 | return C.SDL_HasClipboardText() > 0
34 | }
35 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/cpuinfo.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | #if !(SDL_VERSION_ATLEAST(2,0,1))
7 | #pragma message("SDL_GetSystemRAM is not supported before SDL 2.0.1")
8 | static inline int SDL_GetSystemRAM()
9 | {
10 | return -1;
11 | }
12 | #endif
13 |
14 | #if !(SDL_VERSION_ATLEAST(2,0,2))
15 | #pragma message("SDL_HasAVX is not supported before SDL 2.0.2")
16 | static inline SDL_bool SDL_HasAVX()
17 | {
18 | return SDL_FALSE;
19 | }
20 | #endif
21 |
22 | */
23 | import "C"
24 |
25 | // CACHELINE_SIZE is a cacheline size used for padding.
26 | const CACHELINE_SIZE = C.SDL_CACHELINE_SIZE
27 |
28 | // GetCPUCount returns the number of CPU cores available.
29 | // (https://wiki.libsdl.org/SDL_GetCPUCount)
30 | func GetCPUCount() int {
31 | return int(C.SDL_GetCPUCount())
32 | }
33 |
34 | // GetCPUCacheLineSize returns the L1 cache line size of the CPU.
35 | // (https://wiki.libsdl.org/SDL_GetCPUCacheLineSize)
36 | func GetCPUCacheLineSize() int {
37 | return int(C.SDL_GetCPUCacheLineSize())
38 | }
39 |
40 | // HasRDTSC reports whether the CPU has the RDTSC instruction.
41 | // (https://wiki.libsdl.org/SDL_HasRDTSC)
42 | func HasRDTSC() bool {
43 | return C.SDL_HasRDTSC() > 0
44 | }
45 |
46 | // HasAltiVec reports whether the CPU has AltiVec features.
47 | // (https://wiki.libsdl.org/SDL_HasAltiVec)
48 | func HasAltiVec() bool {
49 | return C.SDL_HasAltiVec() > 0
50 | }
51 |
52 | // HasMMX reports whether the CPU has MMX features.
53 | // (https://wiki.libsdl.org/SDL_HasMMX)
54 | func HasMMX() bool {
55 | return C.SDL_HasMMX() > 0
56 | }
57 |
58 | // Has3DNow reports whether the CPU has 3DNow! features.
59 | // (https://wiki.libsdl.org/SDL_Has3DNow)
60 | func Has3DNow() bool {
61 | return C.SDL_Has3DNow() > 0
62 | }
63 |
64 | // HasSSE reports whether the CPU has SSE features.
65 | // (https://wiki.libsdl.org/SDL_HasSSE)
66 | func HasSSE() bool {
67 | return C.SDL_HasSSE() > 0
68 | }
69 |
70 | // HasSSE2 reports whether the CPU has SSE2 features.
71 | // (https://wiki.libsdl.org/SDL_HasSSE2)
72 | func HasSSE2() bool {
73 | return C.SDL_HasSSE2() > 0
74 | }
75 |
76 | // HasSSE3 reports whether the CPU has SSE3 features.
77 | // (https://wiki.libsdl.org/SDL_HasSSE3)
78 | func HasSSE3() bool {
79 | return C.SDL_HasSSE3() > 0
80 | }
81 |
82 | // HasSSE41 reports whether the CPU has SSE4.1 features.
83 | // (https://wiki.libsdl.org/SDL_HasSSE41)
84 | func HasSSE41() bool {
85 | return C.SDL_HasSSE41() > 0
86 | }
87 |
88 | // HasSSE42 reports whether the CPU has SSE4.2 features.
89 | // (https://wiki.libsdl.org/SDL_HasSSE42)
90 | func HasSSE42() bool {
91 | return C.SDL_HasSSE42() > 0
92 | }
93 |
94 | // GetSystemRAM returns the amount of RAM configured in the system.
95 | // (https://wiki.libsdl.org/SDL_GetSystemRAM)
96 | func GetSystemRAM() int {
97 | return int(C.SDL_GetSystemRAM())
98 | }
99 |
100 | // HasAVX reports whether the CPU has AVX features.
101 | // (https://wiki.libsdl.org/SDL_HasAVX)
102 | func HasAVX() bool {
103 | return C.SDL_HasAVX() > 0
104 | }
105 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/endian.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 |
6 | // Endian-specific values.
7 | // (https://wiki.libsdl.org/CategoryEndian)
8 | const (
9 | BYTEORDER = C.SDL_BYTEORDER // macro that corresponds to the byte order used by the processor type it was compiled for
10 | LIL_ENDIAN = C.SDL_LIL_ENDIAN // byte order is 1234, where the least significant byte is stored first
11 | BIG_ENDIAN = C.SDL_BIG_ENDIAN // byte order is 4321, where the most significant byte is stored first
12 | )
13 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/error.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | void GoSetError(const char *fmt) {
7 | SDL_SetError("%s", fmt);
8 | }
9 | */
10 | // #include "sdl_wrapper.h"
11 | import "C"
12 | import "errors"
13 |
14 | // SDL error codes with their corresponding predefined strings.
15 | const (
16 | ENOMEM ErrorCode = C.SDL_ENOMEM // out of memory
17 | EFREAD = C.SDL_EFREAD // error reading from datastream
18 | EFWRITE = C.SDL_EFWRITE // error writing to datastream
19 | EFSEEK = C.SDL_EFSEEK // error seeking in datastream
20 | UNSUPPORTED = C.SDL_UNSUPPORTED // that operation is not supported
21 | LASTERROR = C.SDL_LASTERROR // the highest numbered predefined error
22 | )
23 |
24 | // ErrorCode is an error code used in SDL error messages.
25 | type ErrorCode uint32
26 | type cErrorCode C.SDL_errorcode
27 |
28 | func (ec ErrorCode) c() C.SDL_errorcode {
29 | return C.SDL_errorcode(ec)
30 | }
31 |
32 | // GetError returns the last error that occurred, or an empty string if there hasn't been an error message set since the last call to ClearError().
33 | // (https://wiki.libsdl.org/SDL_GetError)
34 | func GetError() error {
35 | if err := C.SDL_GetError(); err != nil {
36 | gostr := C.GoString(err)
37 | // SDL_GetError returns "an empty string if there hasn't been an error message"
38 | if len(gostr) > 0 {
39 | return errors.New(gostr)
40 | }
41 | }
42 | return nil
43 | }
44 |
45 | // SetError set the SDL error message.
46 | // (https://wiki.libsdl.org/SDL_SetError)
47 | func SetError(err error) {
48 | if err != nil {
49 | C.GoSetError(C.CString(err.Error()))
50 | return
51 | }
52 | C.GoSetError(nil)
53 | }
54 |
55 | // ClearError clears any previous error message.
56 | // (https://wiki.libsdl.org/SDL_ClearError)
57 | func ClearError() {
58 | C.SDL_ClearError()
59 | }
60 |
61 | // Error sets the SDL error message to the specified error code.
62 | func Error(code ErrorCode) {
63 | C.SDL_Error(code.c())
64 | }
65 |
66 | // OutOfMemory sets SDL error message to ENOMEM (out of memory).
67 | func OutOfMemory() {
68 | Error(ENOMEM)
69 | }
70 |
71 | // Unsupported sets SDL error message to UNSUPPORTED (that operation is not supported).
72 | func Unsupported() {
73 | Error(UNSUPPORTED)
74 | }
75 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/events.c:
--------------------------------------------------------------------------------
1 | #include "_cgo_export.h"
2 | #include "events.h"
3 |
4 | void setEventFilter()
5 | {
6 | SDL_SetEventFilter((SDL_EventFilter)goSetEventFilterCallback, NULL);
7 | }
8 |
9 | void clearEventFilter()
10 | {
11 | SDL_SetEventFilter(NULL, NULL);
12 | }
13 |
14 | void filterEvents(void *userdata)
15 | {
16 | SDL_FilterEvents((SDL_EventFilter)goEventFilterCallback, userdata);
17 | }
18 |
19 | void addEventWatch(void *userdata)
20 | {
21 | SDL_AddEventWatch((SDL_EventFilter)goEventFilterCallback, userdata);
22 | }
23 |
24 | void delEventWatch(void *userdata)
25 | {
26 | SDL_DelEventWatch((SDL_EventFilter)goEventFilterCallback, userdata);
27 | }
28 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/events.h:
--------------------------------------------------------------------------------
1 | #ifndef _GO_SDL_EVENTS_H
2 | #define _GO_SDL_EVENTS_H
3 |
4 | extern void setEventFilter();
5 | extern void clearEventFilter();
6 | extern void filterEvents(void *userdata);
7 | extern void addEventWatch(void *userdata);
8 | extern void delEventWatch(void *userdata);
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/filesystem.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | #if !(SDL_VERSION_ATLEAST(2,0,1))
7 | #pragma message("SDL_GetBasePath is not supported before SDL 2.0.1")
8 | static inline char* SDL_GetBasePath()
9 | {
10 | return NULL;
11 | }
12 |
13 | #pragma message("SDL_GetPrefPath is not supported before SDL 2.0.1")
14 | static inline char* SDL_GetPrefPath(const char *org, const char *app)
15 | {
16 | return NULL;
17 | }
18 | #endif
19 |
20 | */
21 | import "C"
22 | import "unsafe"
23 |
24 | // GetBasePath returns the directory where the application was run from. This is where the application data directory is.
25 | // (https://wiki.libsdl.org/SDL_GetBasePath)
26 | func GetBasePath() string {
27 | _val := C.SDL_GetBasePath()
28 | defer C.SDL_free(unsafe.Pointer(_val))
29 | return C.GoString(_val)
30 | }
31 |
32 | // GetPrefPath returns the "pref dir". This is meant to be where the application can write personal files (Preferences and save games, etc.) that are specific to the application. This directory is unique per user and per application.
33 | // (https://wiki.libsdl.org/SDL_GetPrefPath)
34 | func GetPrefPath(org, app string) string {
35 | _org := C.CString(org)
36 | _app := C.CString(app)
37 | defer C.free(unsafe.Pointer(_org))
38 | defer C.free(unsafe.Pointer(_app))
39 | _val := C.SDL_GetPrefPath(_org, _app)
40 | defer C.SDL_free(unsafe.Pointer(_val))
41 | return C.GoString(_val)
42 | }
43 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/gamecontroller.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | #if !(SDL_VERSION_ATLEAST(2,0,4))
7 | #pragma message("SDL_GameControllerFromInstanceID is not supported before SDL 2.0.4")
8 | static SDL_GameController* SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
9 | {
10 | return NULL;
11 | }
12 | #endif
13 |
14 | #if !(SDL_VERSION_ATLEAST(2,0,6))
15 | #pragma message("SDL_GameControllerGetVendor is not supported before SDL 2.0.6")
16 | static Uint16 SDL_GameControllerGetVendor(SDL_GameController* gamecontroller)
17 | {
18 | return 0;
19 | }
20 |
21 | #pragma message("SDL_GameControllerGetProduct is not supported before SDL 2.0.6")
22 | static Uint16 SDL_GameControllerGetProduct(SDL_GameController* gamecontroller)
23 | {
24 | return 0;
25 | }
26 |
27 | #pragma message("SDL_GameControllerGetProductVersion is not supported before SDL 2.0.6")
28 | static Uint16 SDL_GameControllerGetProductVersion(SDL_GameController* gamecontroller)
29 | {
30 | return 0;
31 | }
32 |
33 | #pragma message("SDL_GameControllerNumMappings is not supported before SDL 2.0.6")
34 | static int SDL_GameControllerNumMappings(void)
35 | {
36 | return 0;
37 | }
38 |
39 | #pragma message("SDL_GameControllerMappingForIndex is not supported before SDL 2.0.6")
40 | static char* SDL_GameControllerMappingForIndex(int mapping_index)
41 | {
42 | return NULL;
43 | }
44 | #endif
45 | */
46 | import "C"
47 | import "unsafe"
48 | import "encoding/binary"
49 |
50 | // Types of game controller inputs.
51 | const (
52 | CONTROLLER_BINDTYPE_NONE = C.SDL_CONTROLLER_BINDTYPE_NONE
53 | CONTROLLER_BINDTYPE_BUTTON = C.SDL_CONTROLLER_BINDTYPE_BUTTON
54 | CONTROLLER_BINDTYPE_AXIS = C.SDL_CONTROLLER_BINDTYPE_AXIS
55 | CONTROLLER_BINDTYPE_HAT = C.SDL_CONTROLLER_BINDTYPE_HAT
56 | )
57 |
58 | // An enumeration of axes available from a controller.
59 | // (https://wiki.libsdl.org/SDL_GameControllerAxis)
60 | const (
61 | CONTROLLER_AXIS_INVALID = C.SDL_CONTROLLER_AXIS_INVALID
62 | CONTROLLER_AXIS_LEFTX = C.SDL_CONTROLLER_AXIS_LEFTX
63 | CONTROLLER_AXIS_LEFTY = C.SDL_CONTROLLER_AXIS_LEFTY
64 | CONTROLLER_AXIS_RIGHTX = C.SDL_CONTROLLER_AXIS_RIGHTX
65 | CONTROLLER_AXIS_RIGHTY = C.SDL_CONTROLLER_AXIS_RIGHTY
66 | CONTROLLER_AXIS_TRIGGERLEFT = C.SDL_CONTROLLER_AXIS_TRIGGERLEFT
67 | CONTROLLER_AXIS_TRIGGERRIGHT = C.SDL_CONTROLLER_AXIS_TRIGGERRIGHT
68 | CONTROLLER_AXIS_MAX = C.SDL_CONTROLLER_AXIS_MAX
69 | )
70 |
71 | // An enumeration of buttons available from a controller.
72 | // (https://wiki.libsdl.org/SDL_GameControllerButton)
73 | const (
74 | CONTROLLER_BUTTON_INVALID = C.SDL_CONTROLLER_BUTTON_INVALID
75 | CONTROLLER_BUTTON_A = C.SDL_CONTROLLER_BUTTON_A
76 | CONTROLLER_BUTTON_B = C.SDL_CONTROLLER_BUTTON_B
77 | CONTROLLER_BUTTON_X = C.SDL_CONTROLLER_BUTTON_X
78 | CONTROLLER_BUTTON_Y = C.SDL_CONTROLLER_BUTTON_Y
79 | CONTROLLER_BUTTON_BACK = C.SDL_CONTROLLER_BUTTON_BACK
80 | CONTROLLER_BUTTON_GUIDE = C.SDL_CONTROLLER_BUTTON_GUIDE
81 | CONTROLLER_BUTTON_START = C.SDL_CONTROLLER_BUTTON_START
82 | CONTROLLER_BUTTON_LEFTSTICK = C.SDL_CONTROLLER_BUTTON_LEFTSTICK
83 | CONTROLLER_BUTTON_RIGHTSTICK = C.SDL_CONTROLLER_BUTTON_RIGHTSTICK
84 | CONTROLLER_BUTTON_LEFTSHOULDER = C.SDL_CONTROLLER_BUTTON_LEFTSHOULDER
85 | CONTROLLER_BUTTON_RIGHTSHOULDER = C.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
86 | CONTROLLER_BUTTON_DPAD_UP = C.SDL_CONTROLLER_BUTTON_DPAD_UP
87 | CONTROLLER_BUTTON_DPAD_DOWN = C.SDL_CONTROLLER_BUTTON_DPAD_DOWN
88 | CONTROLLER_BUTTON_DPAD_LEFT = C.SDL_CONTROLLER_BUTTON_DPAD_LEFT
89 | CONTROLLER_BUTTON_DPAD_RIGHT = C.SDL_CONTROLLER_BUTTON_DPAD_RIGHT
90 | CONTROLLER_BUTTON_MAX = C.SDL_CONTROLLER_BUTTON_MAX
91 | )
92 |
93 | // GameControllerBindType is a type of game controller input.
94 | type GameControllerBindType C.SDL_GameControllerBindType
95 |
96 | // GameControllerAxis is an axis on a game controller.
97 | // (https://wiki.libsdl.org/SDL_GameControllerAxis)
98 | type GameControllerAxis C.SDL_GameControllerAxis
99 |
100 | // GameControllerButton is a button on a game controller.
101 | // (https://wiki.libsdl.org/SDL_GameControllerButton)
102 | type GameControllerButton C.SDL_GameControllerButton
103 |
104 | // GameController used to identify an SDL game controller.
105 | type GameController C.SDL_GameController
106 |
107 | // GameControllerButtonBind SDL joystick layer binding for controller button/axis mapping.
108 | type GameControllerButtonBind C.SDL_GameControllerButtonBind
109 |
110 | func (ctrl *GameController) cptr() *C.SDL_GameController {
111 | return (*C.SDL_GameController)(unsafe.Pointer(ctrl))
112 | }
113 |
114 | func (axis GameControllerAxis) c() C.SDL_GameControllerAxis {
115 | return C.SDL_GameControllerAxis(axis)
116 | }
117 |
118 | func (btn GameControllerButton) c() C.SDL_GameControllerButton {
119 | return C.SDL_GameControllerButton(btn)
120 | }
121 |
122 | // GameControllerAddMapping adds support for controllers that SDL is unaware of or to cause an existing controller to have a different binding.
123 | // (https://wiki.libsdl.org/SDL_GameControllerAddMapping)
124 | func GameControllerAddMapping(mappingString string) int {
125 | _mappingString := C.CString(mappingString)
126 | defer C.free(unsafe.Pointer(_mappingString))
127 | return int(C.SDL_GameControllerAddMapping(_mappingString))
128 | }
129 |
130 | // GameControllerNumMappings returns the number of mappings installed.
131 | func GameControllerNumMappings() int {
132 | return int(C.SDL_GameControllerNumMappings())
133 | }
134 |
135 | // GameControllerMappingForIndex returns the game controller mapping string at a particular index.
136 | func GameControllerMappingForIndex(index int) string {
137 | mappingString := C.SDL_GameControllerMappingForIndex(C.int(index))
138 | defer C.free(unsafe.Pointer(mappingString))
139 | return C.GoString(mappingString)
140 | }
141 |
142 | // GameControllerMappingForGUID returns the game controller mapping string for a given GUID.
143 | // (https://wiki.libsdl.org/SDL_GameControllerMappingForGUID)
144 | func GameControllerMappingForGUID(guid JoystickGUID) string {
145 | mappingString := C.SDL_GameControllerMappingForGUID(guid.c())
146 | defer C.free(unsafe.Pointer(mappingString))
147 | return C.GoString(mappingString)
148 | }
149 |
150 | // IsGameController reports whether the given joystick is supported by the game controller interface.
151 | // (https://wiki.libsdl.org/SDL_IsGameController)
152 | func IsGameController(index int) bool {
153 | return C.SDL_IsGameController(C.int(index)) == C.SDL_TRUE
154 | }
155 |
156 | // GameControllerNameForIndex returns the implementation dependent name for the game controller.
157 | // (https://wiki.libsdl.org/SDL_GameControllerNameForIndex)
158 | func GameControllerNameForIndex(index int) string {
159 | return C.GoString(C.SDL_GameControllerNameForIndex(C.int(index)))
160 | }
161 |
162 | // GameControllerOpen opens a gamecontroller for use.
163 | // (https://wiki.libsdl.org/SDL_GameControllerOpen)
164 | func GameControllerOpen(index int) *GameController {
165 | return (*GameController)(C.SDL_GameControllerOpen(C.int(index)))
166 | }
167 |
168 | // GameControllerFromInstanceID returns the GameController associated with an instance id.
169 | // (https://wiki.libsdl.org/SDL_GameControllerFromInstanceID)
170 | func GameControllerFromInstanceID(joyid JoystickID) *GameController {
171 | return (*GameController)(C.SDL_GameControllerFromInstanceID(joyid.c()))
172 | }
173 |
174 | // Name returns the implementation dependent name for an opened game controller.
175 | // (https://wiki.libsdl.org/SDL_GameControllerName)
176 | func (ctrl *GameController) Name() string {
177 | return C.GoString(C.SDL_GameControllerName(ctrl.cptr()))
178 | }
179 |
180 | // Vendor returns the USB vendor ID of an opened controller, if available, 0 otherwise.
181 | func (ctrl *GameController) Vendor() int {
182 | return int(C.SDL_GameControllerGetVendor(ctrl.cptr()))
183 | }
184 |
185 | // Product returns the USB product ID of an opened controller, if available, 0 otherwise.
186 | func (ctrl *GameController) Product() int {
187 | return int(C.SDL_GameControllerGetProduct(ctrl.cptr()))
188 | }
189 |
190 | // ProductVersion returns the product version of an opened controller, if available, 0 otherwise.
191 | func (ctrl *GameController) ProductVersion() int {
192 | return int(C.SDL_GameControllerGetProductVersion(ctrl.cptr()))
193 | }
194 |
195 | // Attached reports whether a controller has been opened and is currently connected.
196 | // (https://wiki.libsdl.org/SDL_GameControllerGetAttached)
197 | func (ctrl *GameController) Attached() bool {
198 | return C.SDL_GameControllerGetAttached(ctrl.cptr()) == C.SDL_TRUE
199 | }
200 |
201 | // Mapping returns the current mapping of a Game Controller.
202 | // (https://wiki.libsdl.org/SDL_GameControllerMapping)
203 | func (ctrl *GameController) Mapping() string {
204 | mappingString := C.SDL_GameControllerMapping(ctrl.cptr())
205 | defer C.free(unsafe.Pointer(mappingString))
206 | return C.GoString(mappingString)
207 | }
208 |
209 | // Joystick returns the Joystick ID from a Game Controller. The game controller builds on the Joystick API, but to be able to use the Joystick's functions with a gamepad, you need to use this first to get the joystick object.
210 | // (https://wiki.libsdl.org/SDL_GameControllerGetJoystick)
211 | func (ctrl *GameController) Joystick() *Joystick {
212 | return (*Joystick)(unsafe.Pointer(C.SDL_GameControllerGetJoystick(ctrl.cptr())))
213 | }
214 |
215 | // GameControllerEventState returns the current state of, enable, or disable events dealing with Game Controllers. This will not disable Joystick events, which can also be fired by a controller (see https://wiki.libsdl.org/SDL_JoystickEventState).
216 | // (https://wiki.libsdl.org/SDL_GameControllerEventState)
217 | func GameControllerEventState(state int) int {
218 | return int(C.SDL_GameControllerEventState(C.int(state)))
219 | }
220 |
221 | // GameControllerUpdate manually pumps game controller updates if not using the loop.
222 | // (https://wiki.libsdl.org/SDL_GameControllerUpdate)
223 | func GameControllerUpdate() {
224 | C.SDL_GameControllerUpdate()
225 | }
226 |
227 | // GameControllerGetAxisFromString converts a string into an enum representation for a GameControllerAxis.
228 | // (https://wiki.libsdl.org/SDL_GameControllerGetAxisFromString)
229 | func GameControllerGetAxisFromString(pchString string) GameControllerAxis {
230 | _pchString := C.CString(pchString)
231 | defer C.free(unsafe.Pointer(_pchString))
232 | return GameControllerAxis(C.SDL_GameControllerGetAxisFromString(_pchString))
233 | }
234 |
235 | // GameControllerGetStringForAxis converts from an axis enum to a string.
236 | // (https://wiki.libsdl.org/SDL_GameControllerGetStringForAxis)
237 | func GameControllerGetStringForAxis(axis GameControllerAxis) string {
238 | return C.GoString(C.SDL_GameControllerGetStringForAxis(axis.c()))
239 | }
240 |
241 | // BindForAxis returns the SDL joystick layer binding for a controller button mapping.
242 | // (https://wiki.libsdl.org/SDL_GameControllerGetBindForAxis)
243 | func (ctrl *GameController) BindForAxis(axis GameControllerAxis) GameControllerButtonBind {
244 | return GameControllerButtonBind(C.SDL_GameControllerGetBindForAxis(ctrl.cptr(), axis.c()))
245 | }
246 |
247 | // Axis returns the current state of an axis control on a game controller.
248 | // (https://wiki.libsdl.org/SDL_GameControllerGetAxis)
249 | func (ctrl *GameController) Axis(axis GameControllerAxis) int16 {
250 | return int16(C.SDL_GameControllerGetAxis(ctrl.cptr(), axis.c()))
251 | }
252 |
253 | // GameControllerGetButtonFromString turns a string into a button mapping.
254 | // (https://wiki.libsdl.org/SDL_GameControllerGetButtonFromString)
255 | func GameControllerGetButtonFromString(pchString string) GameControllerButton {
256 | _pchString := C.CString(pchString)
257 | defer C.free(unsafe.Pointer(_pchString))
258 | return GameControllerButton(C.SDL_GameControllerGetButtonFromString(_pchString))
259 | }
260 |
261 | // GameControllerGetStringForButton turns a button enum into a string mapping.
262 | // (https://wiki.libsdl.org/SDL_GameControllerGetStringForButton)
263 | func GameControllerGetStringForButton(btn GameControllerButton) string {
264 | return C.GoString(C.SDL_GameControllerGetStringForButton(btn.c()))
265 | }
266 |
267 | // BindForButton returns the SDL joystick layer binding for this controller button mapping.
268 | // (https://wiki.libsdl.org/SDL_GameControllerGetBindForButton)
269 | func (ctrl *GameController) BindForButton(btn GameControllerButton) GameControllerButtonBind {
270 | return GameControllerButtonBind(C.SDL_GameControllerGetBindForButton(ctrl.cptr(), btn.c()))
271 | }
272 |
273 | // Button returns the current state of a button on a game controller.
274 | // (https://wiki.libsdl.org/SDL_GameControllerGetButton)
275 | func (ctrl *GameController) Button(btn GameControllerButton) byte {
276 | return byte(C.SDL_GameControllerGetButton(ctrl.cptr(), btn.c()))
277 | }
278 |
279 | // Close closes a game controller previously opened with GameControllerOpen().
280 | // (https://wiki.libsdl.org/SDL_GameControllerClose)
281 | func (ctrl *GameController) Close() {
282 | C.SDL_GameControllerClose(ctrl.cptr())
283 | }
284 |
285 | // Type returns the type of game controller input for this SDL joystick layer binding.
286 | func (bind *GameControllerButtonBind) Type() int {
287 | return int(bind.bindType)
288 | }
289 |
290 | // Button returns button mapped for this SDL joystick layer binding.
291 | func (bind *GameControllerButtonBind) Button() int {
292 | val, _ := binary.Varint(bind.value[:4])
293 | return int(val)
294 | }
295 |
296 | // Axis returns axis mapped for this SDL joystick layer binding.
297 | func (bind *GameControllerButtonBind) Axis() int {
298 | val, _ := binary.Varint(bind.value[:4])
299 | return int(val)
300 | }
301 |
302 | // Hat returns hat mapped for this SDL joystick layer binding.
303 | func (bind *GameControllerButtonBind) Hat() int {
304 | val, _ := binary.Varint(bind.value[:4])
305 | return int(val)
306 | }
307 |
308 | // HatMask returns hat mask for this SDL joystick layer binding.
309 | func (bind *GameControllerButtonBind) HatMask() int {
310 | val, _ := binary.Varint(bind.value[4:8])
311 | return int(val)
312 | }
313 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/gesture.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 |
6 | // GestureID is the unique id of the closest gesture to the performed stroke.
7 | type GestureID C.SDL_GestureID
8 |
9 | func (g GestureID) c() C.SDL_GestureID {
10 | return C.SDL_GestureID(g)
11 | }
12 |
13 | // RecordGesture begins recording a gesture on a specified touch device or all touch devices.
14 | // (https://wiki.libsdl.org/SDL_RecordGesture)
15 | func RecordGesture(t TouchID) int {
16 | return int(C.SDL_RecordGesture(t.c()))
17 | }
18 |
19 | // SaveAllDollarTemplates saves all currently loaded Dollar Gesture templates.
20 | // (https://wiki.libsdl.org/SDL_SaveAllDollarTemplates)
21 | func SaveAllDollarTemplates(src *RWops) int {
22 | return int(C.SDL_SaveAllDollarTemplates(src.cptr()))
23 | }
24 |
25 | // SaveDollarTemplate saves a currently loaded Dollar Gesture template.
26 | // (https://wiki.libsdl.org/SDL_SaveDollarTemplate)
27 | func SaveDollarTemplate(g GestureID, src *RWops) int {
28 | return int(C.SDL_SaveDollarTemplate(g.c(), src.cptr()))
29 | }
30 |
31 | // LoadDollarTemplates loads Dollar Gesture templates from a file.
32 | // (https://wiki.libsdl.org/SDL_LoadDollarTemplates)
33 | func LoadDollarTemplates(t TouchID, src *RWops) int {
34 | return int(C.SDL_LoadDollarTemplates(t.c(), src.cptr()))
35 | }
36 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/helpers.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // Btoi returns 0 or 1 according to the value of b.
4 | func Btoi(b bool) int {
5 | if b == true {
6 | return 1
7 | }
8 |
9 | return 0
10 | }
11 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/hints.c:
--------------------------------------------------------------------------------
1 | #include "_cgo_export.h"
2 |
3 | #include "sdl_wrapper.h"
4 | #include "hints.h"
5 |
6 | void hintCallback(void *userdata, const char *name, const char *oldValue, const char *newValue)
7 | {
8 | goHintCallback((char *) name, (char *) oldValue, (char *) newValue);
9 | }
10 |
11 | void addHintCallback(const char *name)
12 | {
13 | SDL_AddHintCallback(name, hintCallback, NULL);
14 | }
15 |
16 | void delHintCallback(const char *name)
17 | {
18 | SDL_DelHintCallback(name, hintCallback, NULL);}
19 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/hints.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 | #include "hints.h"
6 |
7 | #if !(SDL_VERSION_ATLEAST(2,0,4))
8 | #define SDL_HINT_NO_SIGNAL_HANDLERS ""
9 | #define SDL_HINT_THREAD_STACK_SIZE ""
10 | #define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN ""
11 | #define SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP ""
12 | #define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 ""
13 | #define SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING ""
14 | #define SDL_HINT_MAC_BACKGROUND_APP ""
15 | #define SDL_HINT_IME_INTERNAL_EDITING ""
16 | #define SDL_HINT_VIDEO_X11_NET_WM_PING ""
17 | #define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH ""
18 | #define SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION ""
19 | #define SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION ""
20 | #endif
21 | #if !(SDL_VERSION_ATLEAST(2,0,3))
22 | #define SDL_HINT_WINRT_PRIVACY_POLICY_URL ""
23 | #define SDL_HINT_WINRT_PRIVACY_POLICY_LABEL ""
24 | #define SDL_HINT_WINRT_HANDLE_BACK_BUTTON ""
25 | #define SDL_HINT_RENDER_DIRECT3D11_DEBUG ""
26 | #endif
27 | #if !(SDL_VERSION_ATLEAST(2,0,2))
28 | #define SDL_HINT_ACCELEROMETER_AS_JOYSTICK ""
29 | #define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK ""
30 | #define SDL_HINT_VIDEO_ALLOW_SCREENSAVER ""
31 | #define SDL_HINT_MOUSE_RELATIVE_MODE_WARP ""
32 | #define SDL_HINT_VIDEO_WIN_D3DCOMPILER ""
33 | #define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT ""
34 | #define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES ""
35 | #endif
36 | #if !(SDL_VERSION_ATLEAST(2,0,1))
37 | #define SDL_HINT_RENDER_DIRECT3D_THREADSAFE ""
38 | #define SDL_HINT_VIDEO_HIGHDPI_DISABLED ""
39 | #endif
40 | */
41 | import "C"
42 | import "unsafe"
43 |
44 | // Configuration hints
45 | // (https://wiki.libsdl.org/CategoryHints)
46 | const (
47 | HINT_FRAMEBUFFER_ACCELERATION = C.SDL_HINT_FRAMEBUFFER_ACCELERATION // specifies how 3D acceleration is used with Window.GetSurface()
48 | HINT_RENDER_DRIVER = C.SDL_HINT_RENDER_DRIVER // specifies which render driver to use
49 | HINT_RENDER_OPENGL_SHADERS = C.SDL_HINT_RENDER_OPENGL_SHADERS // specifies whether the OpenGL render driver uses shaders
50 | HINT_RENDER_DIRECT3D_THREADSAFE = C.SDL_HINT_RENDER_DIRECT3D_THREADSAFE // specifies whether the Direct3D device is initialized for thread-safe operations
51 | HINT_RENDER_DIRECT3D11_DEBUG = C.SDL_HINT_RENDER_DIRECT3D11_DEBUG // specifies a variable controlling whether to enable Direct3D 11+'s Debug Layer
52 | HINT_RENDER_SCALE_QUALITY = C.SDL_HINT_RENDER_SCALE_QUALITY // specifies scaling quality
53 | HINT_RENDER_VSYNC = C.SDL_HINT_RENDER_VSYNC // specifies whether sync to vertical refresh is enabled or disabled in CreateRenderer() to avoid tearing
54 | HINT_VIDEO_ALLOW_SCREENSAVER = C.SDL_HINT_VIDEO_ALLOW_SCREENSAVER // specifies whether the screensaver is enabled
55 | HINT_VIDEO_X11_NET_WM_PING = C.SDL_HINT_VIDEO_X11_NET_WM_PING // specifies whether the X11 _NET_WM_PING protocol should be supported
56 | HINT_VIDEO_X11_XVIDMODE = C.SDL_HINT_VIDEO_X11_XVIDMODE // specifies whether the X11 VidMode extension should be used
57 | HINT_VIDEO_X11_XINERAMA = C.SDL_HINT_VIDEO_X11_XINERAMA // specifies whether the X11 Xinerama extension should be used
58 | HINT_VIDEO_X11_XRANDR = C.SDL_HINT_VIDEO_X11_XRANDR // specifies whether the X11 XRandR extension should be used
59 | HINT_GRAB_KEYBOARD = C.SDL_HINT_GRAB_KEYBOARD // specifies whether grabbing input grabs the keyboard
60 | HINT_MOUSE_RELATIVE_MODE_WARP = C.SDL_HINT_MOUSE_RELATIVE_MODE_WARP // specifies whether relative mouse mode is implemented using mouse warping
61 | HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS = C.SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS // specifies if a Window is minimized if it loses key focus when in fullscreen mode
62 | HINT_IDLE_TIMER_DISABLED = C.SDL_HINT_IDLE_TIMER_DISABLED // specifies a variable controlling whether the idle timer is disabled on iOS
63 | HINT_IME_INTERNAL_EDITING = C.SDL_HINT_IME_INTERNAL_EDITING // specifies whether certain IMEs should handle text editing internally instead of sending TextEditingEvents
64 | HINT_ORIENTATIONS = C.SDL_HINT_ORIENTATIONS // specifies a variable controlling which orientations are allowed on iOS
65 | HINT_ACCELEROMETER_AS_JOYSTICK = C.SDL_HINT_ACCELEROMETER_AS_JOYSTICK // specifies whether the Android / iOS built-in accelerometer should be listed as a joystick device, rather than listing actual joysticks only
66 | HINT_XINPUT_ENABLED = C.SDL_HINT_XINPUT_ENABLED // specifies if Xinput gamepad devices are detected
67 | HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING = C.SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING // specifies that SDL should use the old axis and button mapping for XInput devices
68 | HINT_GAMECONTROLLERCONFIG = C.SDL_HINT_GAMECONTROLLERCONFIG // specifies extra gamecontroller db entries
69 | HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS = C.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS // specifies if joystick (and gamecontroller) events are enabled even when the application is in the background
70 | HINT_ALLOW_TOPMOST = C.SDL_HINT_ALLOW_TOPMOST // specifies if top most bit on an SDL Window can be set
71 | HINT_THREAD_STACK_SIZE = C.SDL_HINT_THREAD_STACK_SIZE // specifies a variable specifying SDL's threads stack size in bytes or "0" for the backend's default size
72 | HINT_TIMER_RESOLUTION = C.SDL_HINT_TIMER_RESOLUTION // specifies the timer resolution in milliseconds
73 | HINT_VIDEO_HIGHDPI_DISABLED = C.SDL_HINT_VIDEO_HIGHDPI_DISABLED // specifies if high-DPI windows ("Retina" on Mac and iOS) are not allowed
74 | HINT_MAC_BACKGROUND_APP = C.SDL_HINT_MAC_BACKGROUND_APP // specifies if the SDL app should not be forced to become a foreground process on Mac OS X
75 | HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK = C.SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK // specifies whether ctrl+click should generate a right-click event on Mac
76 | HINT_VIDEO_WIN_D3DCOMPILER = C.SDL_HINT_VIDEO_WIN_D3DCOMPILER // specifies which shader compiler to preload when using the Chrome ANGLE binaries
77 | HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT = C.SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT // specifies the address of another Window* (as a hex string formatted with "%p")
78 | HINT_WINRT_PRIVACY_POLICY_URL = C.SDL_HINT_WINRT_PRIVACY_POLICY_URL // specifies a URL to a WinRT app's privacy policy
79 | HINT_WINRT_PRIVACY_POLICY_LABEL = C.SDL_HINT_WINRT_PRIVACY_POLICY_LABEL // specifies a label text for a WinRT app's privacy policy link
80 | HINT_WINRT_HANDLE_BACK_BUTTON = C.SDL_HINT_WINRT_HANDLE_BACK_BUTTON // specifies a variable to allow back-button-press events on Windows Phone to be marked as handled
81 | HINT_VIDEO_MAC_FULLSCREEN_SPACES = C.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES // specifies policy for fullscreen Spaces on Mac OS X
82 | HINT_NO_SIGNAL_HANDLERS = C.SDL_HINT_NO_SIGNAL_HANDLERS // specifies not to catch the SIGINT or SIGTERM signals
83 | HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN = C.SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN // specifies whether the window frame and title bar are interactive when the cursor is hidden
84 | HINT_WINDOWS_ENABLE_MESSAGELOOP = C.SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP // specifies whether the windows message loop is processed by SDL
85 | HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 = C.SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 // specifies that SDL should not to generate WINDOWEVENT_CLOSE events for Alt+F4 on Microsoft Windows
86 | HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH = C.SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH // specifies a variable to control whether mouse and touch events are to be treated together or separately
87 | HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION = C.SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION // specifies the Android APK expansion main file version
88 | HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION = C.SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION // specifies the Android APK expansion patch file version
89 | )
90 |
91 | // An enumeration of hint priorities.
92 | // (https://wiki.libsdl.org/SDL_HintPriority)
93 | const (
94 | HINT_DEFAULT = C.SDL_HINT_DEFAULT // low priority, used for default values
95 | HINT_NORMAL = C.SDL_HINT_NORMAL // medium priority
96 | HINT_OVERRIDE = C.SDL_HINT_OVERRIDE // high priority
97 | )
98 |
99 | // HintCallback is the function to call when the hint value changes.
100 | type HintCallback func(data interface{}, name, oldValue, newValue string)
101 |
102 | // HintCallbackAndData contains a callback function and userdata.
103 | type HintCallbackAndData struct {
104 | callback HintCallback // the function to call when the hint value changes
105 | data interface{} // data to pass to the callback function
106 | }
107 |
108 | var hintCallbacks = make(map[string]HintCallbackAndData)
109 |
110 | // HintPriority is a hint priority used in SetHintWithPriority().
111 | // (https://wiki.libsdl.org/SDL_HintPriority)
112 | type HintPriority C.SDL_HintPriority
113 |
114 | func (hp HintPriority) c() C.SDL_HintPriority {
115 | return C.SDL_HintPriority(hp)
116 | }
117 |
118 | // SetHintWithPriority sets a hint with a specific priority.
119 | // (https://wiki.libsdl.org/SDL_SetHintWithPriority)
120 | func SetHintWithPriority(name, value string, hp HintPriority) bool {
121 | _name := C.CString(name)
122 | _value := C.CString(value)
123 | defer C.free(unsafe.Pointer(_name))
124 | defer C.free(unsafe.Pointer(_value))
125 | return C.SDL_SetHintWithPriority(_name, _value, hp.c()) > 0
126 | }
127 |
128 | // SetHint sets a hint with normal priority.
129 | // (https://wiki.libsdl.org/SDL_SetHint)
130 | func SetHint(name, value string) bool {
131 | _name := C.CString(name)
132 | _value := C.CString(value)
133 | defer C.free(unsafe.Pointer(_name))
134 | defer C.free(unsafe.Pointer(_value))
135 | return C.SDL_SetHint(_name, _value) > 0
136 | }
137 |
138 | // GetHint returns the value of a hint.
139 | // (https://wiki.libsdl.org/SDL_GetHint)
140 | func GetHint(name string) string {
141 | _name := C.CString(name)
142 | defer C.free(unsafe.Pointer(_name))
143 | return C.GoString(C.SDL_GetHint(_name))
144 | }
145 |
146 | // ClearHints clears all hints.
147 | // (https://wiki.libsdl.org/SDL_ClearHints)
148 | func ClearHints() {
149 | C.SDL_ClearHints()
150 | }
151 |
152 | // AddHintCallback adds a function to watch a particular hint.
153 | // (https://wiki.libsdl.org/SDL_AddHintCallback)
154 | func AddHintCallback(name string, fn HintCallback, data interface{}) {
155 | _name := C.CString(name)
156 | hintCallbacks[name] = HintCallbackAndData{
157 | callback: fn,
158 | data: data,
159 | }
160 | C.addHintCallback(_name)
161 | }
162 |
163 | // DelHintCallback removes a function watching a particular hint.
164 | // (https://wiki.libsdl.org/SDL_DelHintCallback)
165 | func DelHintCallback(name string) {
166 | _name := C.CString(name)
167 | delete(hintCallbacks, name)
168 | C.delHintCallback(_name)
169 | }
170 |
171 | //export goHintCallback
172 | func goHintCallback(_name, _oldValue, _newValue *C.char) {
173 | name := C.GoString(_name)
174 | oldValue := C.GoString(_oldValue)
175 | newValue := C.GoString(_newValue)
176 | if cb, ok := hintCallbacks[name]; ok {
177 | cb.callback(cb.data, name, oldValue, newValue)
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/hints.h:
--------------------------------------------------------------------------------
1 | void hintCallback(void *userdata, const char *name, const char *oldValue, const char *newValue);
2 | void addHintCallback(const char *name);
3 | void delHintCallback(const char *name);
4 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/joystick.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | #if !(SDL_VERSION_ATLEAST(2,0,4))
7 | #pragma message("SDL_JoystickPowerLevel is not supported before SDL 2.0.4")
8 | typedef enum
9 | {
10 | SDL_JOYSTICK_POWER_UNKNOWN = -1,
11 | SDL_JOYSTICK_POWER_EMPTY,
12 | SDL_JOYSTICK_POWER_LOW,
13 | SDL_JOYSTICK_POWER_MEDIUM,
14 | SDL_JOYSTICK_POWER_FULL,
15 | SDL_JOYSTICK_POWER_WIRED,
16 | SDL_JOYSTICK_POWER_MAX
17 | } SDL_JoystickPowerLevel;
18 |
19 | #pragma message("SDL_JoystickCurrentPowerLevel is not supported before SDL 2.0.4")
20 | static SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick* joystick)
21 | {
22 | return SDL_JOYSTICK_POWER_UNKNOWN;
23 | }
24 |
25 | #pragma message("SDL_JoystickFromInstanceID is not supported before SDL 2.0.4")
26 | static SDL_Joystick* SDL_JoystickFromInstanceID(SDL_JoystickID joyid)
27 | {
28 | return NULL;
29 | }
30 | #endif
31 |
32 | #if !(SDL_VERSION_ATLEAST(2,0,6))
33 | #pragma message("SDL_JoystickType is not supported before SDL 2.0.6")
34 | typedef enum
35 | {
36 | SDL_JOYSTICK_TYPE_UNKNOWN,
37 | SDL_JOYSTICK_TYPE_GAMECONTROLLER,
38 | SDL_JOYSTICK_TYPE_WHEEL,
39 | SDL_JOYSTICK_TYPE_ARCADE_STICK,
40 | SDL_JOYSTICK_TYPE_FLIGHT_STICK,
41 | SDL_JOYSTICK_TYPE_DANCE_PAD,
42 | SDL_JOYSTICK_TYPE_GUITAR,
43 | SDL_JOYSTICK_TYPE_DRUM_KIT,
44 | SDL_JOYSTICK_TYPE_ARCADE_PAD,
45 | SDL_JOYSTICK_TYPE_THROTTLE
46 | } SDL_JoystickType;
47 |
48 | #pragma message("SDL_JoystickGetDeviceVendor is not supported before SDL 2.0.6")
49 | static Uint16 SDL_JoystickGetDeviceVendor(int device_index)
50 | {
51 | return 0;
52 | }
53 |
54 | #pragma message("SDL_JoystickGetDeviceProduct is not supported before SDL 2.0.6")
55 | static Uint16 SDL_JoystickGetDeviceProduct(int device_index)
56 | {
57 | return 0;
58 | }
59 |
60 | #pragma message("SDL_JoystickGetDeviceProductVersion is not supported before SDL 2.0.6")
61 | static Uint16 SDL_JoystickGetDeviceProductVersion(int device_index)
62 | {
63 | return 0;
64 | }
65 |
66 | #pragma message("SDL_JoystickGetDeviceType is not supported before SDL 2.0.6")
67 | static SDL_JoystickType SDL_JoystickGetDeviceType(int device_index)
68 | {
69 | return SDL_JOYSTICK_TYPE_UNKNOWN;
70 | }
71 |
72 | #pragma message("SDL_JoystickGetDeviceInstanceID is not supported before SDL 2.0.6")
73 | static SDL_JoystickID SDL_JoystickGetDeviceInstanceID(int device_index)
74 | {
75 | return 0;
76 | }
77 |
78 | #pragma message("SDL_JoystickGetVendor is not supported before SDL 2.0.6")
79 | static Uint16 SDL_JoystickGetVendor(SDL_Joystick* joystick)
80 | {
81 | return 0;
82 | }
83 |
84 | #pragma message("SDL_JoystickGetProduct is not supported before SDL 2.0.6")
85 | static Uint16 SDL_JoystickGetProduct(SDL_Joystick* joystick)
86 | {
87 | return 0;
88 | }
89 |
90 | #pragma message("SDL_JoystickGetProductVersion is not supported before SDL 2.0.6")
91 | static Uint16 SDL_JoystickGetProductVersion(SDL_Joystick* joystick)
92 | {
93 | return 0;
94 | }
95 |
96 | #pragma message("SDL_JoystickGetType is not supported before SDL 2.0.6")
97 | static SDL_JoystickType SDL_JoystickGetType(SDL_Joystick* joystick)
98 | {
99 | return SDL_JOYSTICK_TYPE_UNKNOWN;
100 | }
101 |
102 | #pragma message("SDL_JoystickGetAxisInitialState is not supported before SDL 2.0.6")
103 | static SDL_bool SDL_JoystickGetAxisInitialState(SDL_Joystick* joystick, int axis, Sint16* state)
104 | {
105 | return SDL_FALSE;
106 | }
107 | #endif
108 | */
109 | import "C"
110 | import "unsafe"
111 |
112 | // Hat positions.
113 | // (https://wiki.libsdl.org/SDL_JoystickGetHat)
114 | const (
115 | HAT_CENTERED = C.SDL_HAT_CENTERED
116 | HAT_UP = C.SDL_HAT_UP
117 | HAT_RIGHT = C.SDL_HAT_RIGHT
118 | HAT_DOWN = C.SDL_HAT_DOWN
119 | HAT_LEFT = C.SDL_HAT_LEFT
120 | HAT_RIGHTUP = C.SDL_HAT_RIGHTUP
121 | HAT_RIGHTDOWN = C.SDL_HAT_RIGHTDOWN
122 | HAT_LEFTUP = C.SDL_HAT_LEFTUP
123 | HAT_LEFTDOWN = C.SDL_HAT_LEFTDOWN
124 | )
125 |
126 | // Types of a joystick.
127 | const (
128 | JOYSTICK_TYPE_UNKNOWN = C.SDL_JOYSTICK_TYPE_UNKNOWN
129 | JOYSTICK_TYPE_GAMECONTROLLER = C.SDL_JOYSTICK_TYPE_GAMECONTROLLER
130 | JOYSTICK_TYPE_WHEEL = C.SDL_JOYSTICK_TYPE_WHEEL
131 | JOYSTICK_TYPE_ARCADE_STICK = C.SDL_JOYSTICK_TYPE_ARCADE_STICK
132 | JOYSTICK_TYPE_FLIGHT_STICK = C.SDL_JOYSTICK_TYPE_FLIGHT_STICK
133 | JOYSTICK_TYPE_DANCE_PAD = C.SDL_JOYSTICK_TYPE_DANCE_PAD
134 | JOYSTICK_TYPE_GUITAR = C.SDL_JOYSTICK_TYPE_GUITAR
135 | JOYSTICK_TYPE_DRUM_KIT = C.SDL_JOYSTICK_TYPE_DRUM_KIT
136 | JOYSTICK_TYPE_ARCADE_PAD = C.SDL_JOYSTICK_TYPE_ARCADE_PAD
137 | JOYSTICK_TYPE_THROTTLE = C.SDL_JOYSTICK_TYPE_THROTTLE
138 | )
139 |
140 | // An enumeration of battery levels of a joystick.
141 | // (https://wiki.libsdl.org/SDL_JoystickPowerLevel)
142 | const (
143 | JOYSTICK_POWER_UNKNOWN = C.SDL_JOYSTICK_POWER_UNKNOWN
144 | JOYSTICK_POWER_EMPTY = C.SDL_JOYSTICK_POWER_EMPTY
145 | JOYSTICK_POWER_LOW = C.SDL_JOYSTICK_POWER_LOW
146 | JOYSTICK_POWER_MEDIUM = C.SDL_JOYSTICK_POWER_MEDIUM
147 | JOYSTICK_POWER_FULL = C.SDL_JOYSTICK_POWER_FULL
148 | JOYSTICK_POWER_WIRED = C.SDL_JOYSTICK_POWER_WIRED
149 | JOYSTICK_POWER_MAX = C.SDL_JOYSTICK_POWER_MAX
150 | )
151 |
152 | // Joystick is an SDL joystick.
153 | type Joystick C.SDL_Joystick
154 |
155 | // JoystickGUID is a stable unique id for a joystick device.
156 | type JoystickGUID C.SDL_JoystickGUID
157 |
158 | // JoystickID is joystick's instance id.
159 | type JoystickID C.SDL_JoystickID
160 |
161 | // JoystickType is a type of a joystick.
162 | type JoystickType C.SDL_JoystickType
163 |
164 | // JoystickPowerLevel is a battery level of a joystick.
165 | type JoystickPowerLevel C.SDL_JoystickPowerLevel
166 |
167 | func (joy *Joystick) cptr() *C.SDL_Joystick {
168 | return (*C.SDL_Joystick)(unsafe.Pointer(joy))
169 | }
170 |
171 | func (guid JoystickGUID) c() C.SDL_JoystickGUID {
172 | return C.SDL_JoystickGUID(guid)
173 | }
174 |
175 | func (joyid JoystickID) c() C.SDL_JoystickID {
176 | return C.SDL_JoystickID(joyid)
177 | }
178 |
179 | // NumJoysticks returns the number of joysticks attached to the system.
180 | // (https://wiki.libsdl.org/SDL_NumJoysticks)
181 | func NumJoysticks() int {
182 | return (int)(C.SDL_NumJoysticks())
183 | }
184 |
185 | // JoystickNameForIndex returns the implementation dependent name of a joystick.
186 | // (https://wiki.libsdl.org/SDL_JoystickNameForIndex)
187 | func JoystickNameForIndex(index int) string {
188 | return (C.GoString)(C.SDL_JoystickNameForIndex(C.int(index)))
189 | }
190 |
191 | // JoystickGetDeviceGUID returns the implementation dependent GUID for the joystick at a given device index.
192 | // (https://wiki.libsdl.org/SDL_JoystickGetDeviceGUID)
193 | func JoystickGetDeviceGUID(index int) JoystickGUID {
194 | return (JoystickGUID)(C.SDL_JoystickGetDeviceGUID(C.int(index)))
195 | }
196 |
197 | // JoystickGetDeviceVendor returns the USB vendor ID of a joystick, if available, 0 otherwise.
198 | func JoystickGetDeviceVendor(index int) int {
199 | return int(C.SDL_JoystickGetDeviceVendor(C.int(index)))
200 | }
201 |
202 | // JoystickGetDeviceProduct returns the USB product ID of a joystick, if available, 0 otherwise.
203 | func JoystickGetDeviceProduct(index int) int {
204 | return int(C.SDL_JoystickGetDeviceProduct(C.int(index)))
205 | }
206 |
207 | // JoystickGetDeviceProductVersion returns the product version of a joystick, if available, 0 otherwise.
208 | func JoystickGetDeviceProductVersion(index int) int {
209 | return int(C.SDL_JoystickGetDeviceProductVersion(C.int(index)))
210 | }
211 |
212 | // JoystickGetDeviceType returns the type of a joystick.
213 | func JoystickGetDeviceType(index int) JoystickType {
214 | return JoystickType(C.SDL_JoystickGetDeviceType(C.int(index)))
215 | }
216 |
217 | // JoystickGetDeviceInstanceID returns the instance ID of a joystick.
218 | func JoystickGetDeviceInstanceID(index int) JoystickID {
219 | return JoystickID(C.SDL_JoystickGetDeviceInstanceID(C.int(index)))
220 | }
221 |
222 | // JoystickGetGUIDString returns an ASCII string representation for a given JoystickGUID.
223 | // (https://wiki.libsdl.org/SDL_JoystickGetGUIDString)
224 | func JoystickGetGUIDString(guid JoystickGUID) string {
225 | _pszGUID := make([]rune, 1024)
226 | pszGUID := C.CString(string(_pszGUID[:]))
227 | defer C.free(unsafe.Pointer(pszGUID))
228 | C.SDL_JoystickGetGUIDString(guid.c(), pszGUID, C.int(unsafe.Sizeof(_pszGUID)))
229 | return C.GoString(pszGUID)
230 | }
231 |
232 | // JoystickGetGUIDFromString converts a GUID string into a JoystickGUID structure.
233 | // (https://wiki.libsdl.org/SDL_JoystickGetGUIDFromString)
234 | func JoystickGetGUIDFromString(pchGUID string) JoystickGUID {
235 | _pchGUID := C.CString(pchGUID)
236 | defer C.free(unsafe.Pointer(_pchGUID))
237 | return (JoystickGUID)(C.SDL_JoystickGetGUIDFromString(_pchGUID))
238 | }
239 |
240 | // JoystickUpdate updates the current state of the open joysticks.
241 | // (https://wiki.libsdl.org/SDL_JoystickUpdate)
242 | func JoystickUpdate() {
243 | C.SDL_JoystickUpdate()
244 | }
245 |
246 | // JoystickEventState enables or disables joystick event polling.
247 | // (https://wiki.libsdl.org/SDL_JoystickEventState)
248 | func JoystickEventState(state int) int {
249 | return (int)(C.SDL_JoystickEventState(C.int(state)))
250 | }
251 |
252 | // JoystickOpen opens a joystick for use.
253 | // (https://wiki.libsdl.org/SDL_JoystickOpen)
254 | func JoystickOpen(index int) *Joystick {
255 | return (*Joystick)(C.SDL_JoystickOpen(C.int(index)))
256 | }
257 |
258 | // JoystickFromInstanceID returns the Joystick associated with an instance id.
259 | // (https://wiki.libsdl.org/SDL_JoystickFromInstanceID)
260 | func JoystickFromInstanceID(joyid JoystickID) *Joystick {
261 | return (*Joystick)(C.SDL_JoystickFromInstanceID(joyid.c()))
262 | }
263 |
264 | // Name returns the implementation dependent name of a joystick.
265 | // (https://wiki.libsdl.org/SDL_JoystickName)
266 | func (joy *Joystick) Name() string {
267 | return (C.GoString)(C.SDL_JoystickName(joy.cptr()))
268 | }
269 |
270 | // GUID returns the implementation-dependent GUID for the joystick.
271 | // (https://wiki.libsdl.org/SDL_JoystickGetGUID)
272 | func (joy *Joystick) GUID() JoystickGUID {
273 | return (JoystickGUID)(C.SDL_JoystickGetGUID(joy.cptr()))
274 | }
275 |
276 | // Vendor returns the USB vendor ID of an opened joystick, if available, 0 otherwise.
277 | func (joy *Joystick) Vendor() int {
278 | return int(C.SDL_JoystickGetVendor(joy.cptr()))
279 | }
280 |
281 | // Product returns the USB product ID of an opened joystick, if available, 0 otherwise.
282 | func (joy *Joystick) Product() int {
283 | return int(C.SDL_JoystickGetProduct(joy.cptr()))
284 | }
285 |
286 | // ProductVersion returns the product version of an opened joystick, if available, 0 otherwise.
287 | func (joy *Joystick) ProductVersion() int {
288 | return int(C.SDL_JoystickGetProductVersion(joy.cptr()))
289 | }
290 |
291 | // Type returns the the type of an opened joystick.
292 | func (joy *Joystick) Type() JoystickType {
293 | return JoystickType(C.SDL_JoystickGetType(joy.cptr()))
294 | }
295 |
296 | // Attached returns the status of a specified joystick.
297 | // (https://wiki.libsdl.org/SDL_JoystickGetAttached)
298 | func (joy *Joystick) Attached() bool {
299 | return C.SDL_JoystickGetAttached(joy.cptr()) == C.SDL_TRUE
300 | }
301 |
302 | // InstanceID returns the instance ID of an opened joystick.
303 | // (https://wiki.libsdl.org/SDL_JoystickInstanceID)
304 | func (joy *Joystick) InstanceID() JoystickID {
305 | return (JoystickID)(C.SDL_JoystickInstanceID(joy.cptr()))
306 | }
307 |
308 | // NumAxes returns the number of general axis controls on a joystick.
309 | // (https://wiki.libsdl.org/SDL_JoystickNumAxes)
310 | func (joy *Joystick) NumAxes() int {
311 | return (int)(C.SDL_JoystickNumAxes(joy.cptr()))
312 | }
313 |
314 | // NumBalls returns the number of trackballs on a joystick.
315 | // (https://wiki.libsdl.org/SDL_JoystickNumBalls)
316 | func (joy *Joystick) NumBalls() int {
317 | return (int)(C.SDL_JoystickNumBalls(joy.cptr()))
318 | }
319 |
320 | // NumHats returns the number of POV hats on a joystick.
321 | // (https://wiki.libsdl.org/SDL_JoystickNumHats)
322 | func (joy *Joystick) NumHats() int {
323 | return (int)(C.SDL_JoystickNumHats(joy.cptr()))
324 | }
325 |
326 | // NumButtons returns the number of buttons on a joystick.
327 | // (https://wiki.libsdl.org/SDL_JoystickNumButtons)
328 | func (joy *Joystick) NumButtons() int {
329 | return (int)(C.SDL_JoystickNumButtons(joy.cptr()))
330 | }
331 |
332 | // Axis returns the current state of an axis control on a joystick.
333 | // (https://wiki.libsdl.org/SDL_JoystickGetAxis)
334 | func (joy *Joystick) Axis(axis int) int16 {
335 | return (int16)(C.SDL_JoystickGetAxis(joy.cptr(), C.int(axis)))
336 | }
337 |
338 | // AxisInitialState returns the initial state of an axis control on a joystick, ok is true if this axis has any initial value.
339 | func (joy *Joystick) AxisInitialState(axis int) (state int16, ok bool) {
340 | ok = C.SDL_JoystickGetAxisInitialState(joy.cptr(), C.int(axis), (*C.Sint16)(&state)) == C.SDL_TRUE
341 | return
342 | }
343 |
344 | // Hat returns the current state of a POV hat on a joystick.
345 | // (https://wiki.libsdl.org/SDL_JoystickGetHat)
346 | func (joy *Joystick) Hat(hat int) byte {
347 | return (byte)(C.SDL_JoystickGetHat(joy.cptr(), C.int(hat)))
348 | }
349 |
350 | // Ball returns the ball axis change since the last poll.
351 | // (https://wiki.libsdl.org/SDL_JoystickGetBall)
352 | func (joy *Joystick) Ball(ball int, dx, dy *int32) int {
353 | _dx := (*C.int)(unsafe.Pointer(dx))
354 | _dy := (*C.int)(unsafe.Pointer(dy))
355 | return (int)(C.SDL_JoystickGetBall(joy.cptr(), C.int(ball), _dx, _dy))
356 | }
357 |
358 | // Button the current state of a button on a joystick.
359 | // (https://wiki.libsdl.org/SDL_JoystickGetButton)
360 | func (joy *Joystick) Button(button int) byte {
361 | return (byte)(C.SDL_JoystickGetButton(joy.cptr(), C.int(button)))
362 | }
363 |
364 | // Close closes a joystick previously opened with JoystickOpen().
365 | // (https://wiki.libsdl.org/SDL_JoystickClose)
366 | func (joy *Joystick) Close() {
367 | C.SDL_JoystickClose(joy.cptr())
368 | }
369 |
370 | // CurrentPowerLevel returns the battery level of a joystick as JoystickPowerLevel.
371 | // (https://wiki.libsdl.org/SDL_JoystickCurrentPowerLevel)
372 | func (joy *Joystick) CurrentPowerLevel() JoystickPowerLevel {
373 | return JoystickPowerLevel(C.SDL_JoystickCurrentPowerLevel(joy.cptr()))
374 | }
375 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/keyboard.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 | import "reflect"
7 |
8 | // Keysym contains key information used in key events.
9 | // (https://wiki.libsdl.org/SDL_Keysym)
10 | type Keysym struct {
11 | Scancode Scancode // SDL physical key code
12 | Sym Keycode // SDL virtual key code
13 | Mod uint16 // current key modifiers
14 | unused uint32 // unused
15 | }
16 |
17 | // GetKeyboardFocus returns the window which currently has keyboard focus.
18 | // (https://wiki.libsdl.org/SDL_GetKeyboardFocus)
19 | func GetKeyboardFocus() *Window {
20 | return (*Window)(unsafe.Pointer(C.SDL_GetKeyboardFocus()))
21 | }
22 |
23 | // GetKeyboardState returns a snapshot of the current state of the keyboard.
24 | // (https://wiki.libsdl.org/SDL_GetKeyboardState)
25 | func GetKeyboardState() []uint8 {
26 | var numkeys C.int
27 | start := C.SDL_GetKeyboardState(&numkeys)
28 | sh := reflect.SliceHeader{}
29 | sh.Len = int(numkeys)
30 | sh.Cap = int(numkeys)
31 | sh.Data = uintptr(unsafe.Pointer(start))
32 | return *(*[]uint8)(unsafe.Pointer(&sh))
33 | }
34 |
35 | // GetModState returns the current key modifier state for the keyboard.
36 | // (https://wiki.libsdl.org/SDL_GetModState)
37 | func GetModState() Keymod {
38 | return (Keymod)(C.SDL_GetModState())
39 | }
40 |
41 | // SetModState sets the current key modifier state for the keyboard.
42 | // (https://wiki.libsdl.org/SDL_SetModState)
43 | func SetModState(mod Keymod) {
44 | C.SDL_SetModState(mod.c())
45 | }
46 |
47 | // GetKeyFromScancode returns the key code corresponding to the given scancode according to the current keyboard layout.
48 | // (https://wiki.libsdl.org/SDL_GetKeyFromScancode)
49 | func GetKeyFromScancode(code Scancode) Keycode {
50 | return (Keycode)(C.SDL_GetKeyFromScancode(code.c()))
51 | }
52 |
53 | // GetScancodeFromKey returns the scancode corresponding to the given key code according to the current keyboard layout.
54 | // (https://wiki.libsdl.org/SDL_GetScancodeFromKey)
55 | func GetScancodeFromKey(code Keycode) Scancode {
56 | return (Scancode)(C.SDL_GetScancodeFromKey(code.c()))
57 | }
58 |
59 | // GetScancodeName returns a human-readable name for a scancode
60 | // (https://wiki.libsdl.org/SDL_GetScancodeName)
61 | func GetScancodeName(code Scancode) string {
62 | return (C.GoString)(C.SDL_GetScancodeName(code.c()))
63 | }
64 |
65 | // GetScancodeFromName returns a scancode from a human-readable name.
66 | // (https://wiki.libsdl.org/SDL_GetScancodeFromName)
67 | func GetScancodeFromName(name string) Scancode {
68 | _name := C.CString(name)
69 | defer C.free(unsafe.Pointer(_name))
70 | return (Scancode)(C.SDL_GetScancodeFromName(_name))
71 | }
72 |
73 | // GetKeyName returns a human-readable name for a key.
74 | // (https://wiki.libsdl.org/SDL_GetKeyName)
75 | func GetKeyName(code Keycode) string {
76 | return (C.GoString)(C.SDL_GetKeyName(code.c()))
77 | }
78 |
79 | // GetKeyFromName returns a key code from a human-readable name.
80 | // (https://wiki.libsdl.org/SDL_GetKeyFromName)
81 | func GetKeyFromName(name string) Keycode {
82 | _name := C.CString(name)
83 | defer C.free(unsafe.Pointer(_name))
84 | return (Keycode)(C.SDL_GetKeyFromName(_name))
85 | }
86 |
87 | // StartTextInput starts accepting Unicode text input events.
88 | // (https://wiki.libsdl.org/SDL_StartTextInput)
89 | func StartTextInput() {
90 | C.SDL_StartTextInput()
91 | }
92 |
93 | // IsTextInputActive checks whether or not Unicode text input events are enabled.
94 | // (https://wiki.libsdl.org/SDL_IsTextInputActive)
95 | func IsTextInputActive() bool {
96 | return C.SDL_IsTextInputActive() > 0
97 | }
98 |
99 | // StopTextInput stops receiving any text input events.
100 | // (https://wiki.libsdl.org/SDL_StopTextInput)
101 | func StopTextInput() {
102 | C.SDL_StopTextInput()
103 | }
104 |
105 | // SetTextInputRect sets the rectangle used to type Unicode text inputs.
106 | // (https://wiki.libsdl.org/SDL_SetTextInputRect)
107 | func SetTextInputRect(rect *Rect) {
108 | C.SDL_SetTextInputRect(rect.cptr())
109 | }
110 |
111 | // HasScreenKeyboardSupport reports whether the platform has some screen keyboard support.
112 | // (https://wiki.libsdl.org/SDL_HasScreenKeyboardSupport)
113 | func HasScreenKeyboardSupport() bool {
114 | return C.SDL_HasScreenKeyboardSupport() > 0
115 | }
116 |
117 | // IsScreenKeyboardShown reports whether the screen keyboard is shown for given window.
118 | // (https://wiki.libsdl.org/SDL_IsScreenKeyboardShown)
119 | func IsScreenKeyboardShown(window *Window) bool {
120 | return C.SDL_IsScreenKeyboardShown(window.cptr()) > 0
121 | }
122 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/loadso.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // SharedObject is a pointer to the object handle.
8 | type SharedObject uintptr
9 |
10 | // LoadObject dynamically loads a shared object and returns a pointer to the object handle.
11 | // (https://wiki.libsdl.org/SDL_LoadObject)
12 | func LoadObject(sofile string) SharedObject {
13 | _sofile := C.CString(sofile)
14 | defer C.free(unsafe.Pointer(_sofile))
15 | return (SharedObject)(C.SDL_LoadObject(_sofile))
16 | }
17 |
18 | // LoadFunction returns a pointer to the named function from the shared object.
19 | // (https://wiki.libsdl.org/SDL_LoadFunction)
20 | func (handle SharedObject) LoadFunction(name string) unsafe.Pointer {
21 | _name := C.CString(name)
22 | defer C.free(unsafe.Pointer(_name))
23 | return (unsafe.Pointer)(C.SDL_LoadFunction((unsafe.Pointer)(handle), _name))
24 | }
25 |
26 | // Unload unloads a shared object from memory.
27 | // (https://wiki.libsdl.org/SDL_UnloadObject)
28 | func (handle SharedObject) Unload() {
29 | C.SDL_UnloadObject((unsafe.Pointer)(handle))
30 | }
31 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/log.c:
--------------------------------------------------------------------------------
1 | #include "_cgo_export.h"
2 |
3 | void LogSetOutputFunction(void *data)
4 | {
5 | SDL_LogSetOutputFunction((SDL_LogOutputFunction)logOutputFunction, data);
6 | }
7 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/log.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 | #include "log.h"
6 |
7 | static inline void _SDL_Log(const char *fmt)
8 | {
9 | SDL_Log("%s", fmt);
10 | }
11 |
12 | static inline void _SDL_LogVerbose(int category, const char *fmt)
13 | {
14 | SDL_LogVerbose(category, "%s", fmt);
15 | }
16 |
17 | static inline void _SDL_LogDebug(int category, const char *fmt)
18 | {
19 | SDL_LogDebug(category, "%s", fmt);
20 | }
21 |
22 | static inline void _SDL_LogInfo(int category, const char *fmt)
23 | {
24 | SDL_LogInfo(category, "%s", fmt);
25 | }
26 |
27 | static inline void _SDL_LogWarn(int category, const char *fmt)
28 | {
29 | SDL_LogWarn(category, "%s", fmt);
30 | }
31 |
32 | static inline void _SDL_LogError(int category, const char *fmt)
33 | {
34 | SDL_LogError(category, "%s", fmt);
35 | }
36 |
37 | static inline void _SDL_LogCritical(int category, const char *fmt)
38 | {
39 | SDL_LogCritical(category, "%s", fmt);
40 | }
41 |
42 | static inline void _SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt)
43 | {
44 | SDL_LogCritical(category, "%s", fmt);
45 | }
46 | */
47 | import "C"
48 | import "fmt"
49 | import "unsafe"
50 |
51 | // An enumeration of the predefined log categories.
52 | // (https://wiki.libsdl.org/SDL_LOG_CATEGORY)
53 | const (
54 | LOG_CATEGORY_APPLICATION = iota // application log
55 | LOG_CATEGORY_ERROR // error log
56 | LOG_CATEGORY_ASSERT // assert log
57 | LOG_CATEGORY_SYSTEM // system log
58 | LOG_CATEGORY_AUDIO // audio log
59 | LOG_CATEGORY_VIDEO // video log
60 | LOG_CATEGORY_RENDER // render log
61 | LOG_CATEGORY_INPUT // input log
62 | LOG_CATEGORY_TEST // test log
63 | LOG_CATEGORY_RESERVED1 // reserved for future SDL library use
64 | LOG_CATEGORY_RESERVED2 // reserved for future SDL library use
65 | LOG_CATEGORY_RESERVED3 // reserved for future SDL library use
66 | LOG_CATEGORY_RESERVED4 // reserved for future SDL library use
67 | LOG_CATEGORY_RESERVED5 // reserved for future SDL library use
68 | LOG_CATEGORY_RESERVED6 // reserved for future SDL library use
69 | LOG_CATEGORY_RESERVED7 // reserved for future SDL library use
70 | LOG_CATEGORY_RESERVED8 // reserved for future SDL library use
71 | LOG_CATEGORY_RESERVED9 // reserved for future SDL library use
72 | LOG_CATEGORY_RESERVED10 // reserved for future SDL library use
73 | LOG_CATEGORY_CUSTOM // reserved for application use
74 | )
75 |
76 | // An enumeration of the predefined log priorities.
77 | // (https://wiki.libsdl.org/SDL_LogPriority)
78 | const (
79 | LOG_PRIORITY_VERBOSE = iota + 1 // verbose
80 | LOG_PRIORITY_DEBUG // debug
81 | LOG_PRIORITY_INFO // info
82 | LOG_PRIORITY_WARN // warn
83 | LOG_PRIORITY_ERROR // error
84 | LOG_PRIORITY_CRITICAL // critical
85 | NUM_LOG_PRIORITIES // (internal use)
86 | )
87 |
88 | // LogPriority is a predefined log priority.
89 | // (https://wiki.libsdl.org/SDL_LogPriority)
90 | type LogPriority C.SDL_LogPriority
91 |
92 | func (p LogPriority) c() C.SDL_LogPriority {
93 | return C.SDL_LogPriority(p)
94 | }
95 |
96 | // LogSetAllPriority sets the priority of all log categories.
97 | // (https://wiki.libsdl.org/SDL_LogSetAllPriority)
98 | func LogSetAllPriority(p LogPriority) {
99 | C.SDL_LogSetAllPriority(p.c())
100 | }
101 |
102 | // LogSetPriority sets the priority of a particular log category.
103 | // (https://wiki.libsdl.org/SDL_LogSetPriority)
104 | func LogSetPriority(category int, p LogPriority) {
105 | C.SDL_LogSetPriority(C.int(category), p.c())
106 | }
107 |
108 | // LogGetPriority returns the priority of a particular log category.
109 | // (https://wiki.libsdl.org/SDL_LogGetPriority)
110 | func LogGetPriority(category int) LogPriority {
111 | return LogPriority(C.SDL_LogGetPriority(C.int(category)))
112 | }
113 |
114 | // LogResetPriorities resets all priorities to default.
115 | // (https://wiki.libsdl.org/SDL_LogResetPriorities)
116 | func LogResetPriorities() {
117 | C.SDL_LogResetPriorities()
118 | }
119 |
120 | // Log logs a message with LOG_CATEGORY_APPLICATION and LOG_PRIORITY_INFO.
121 | // (https://wiki.libsdl.org/SDL_Log)
122 | func Log(str string, args ...interface{}) {
123 | str = fmt.Sprintf(str, args...)
124 |
125 | cstr := C.CString(str)
126 | defer C.free(unsafe.Pointer(cstr))
127 |
128 | C._SDL_Log(cstr)
129 | }
130 |
131 | // LogVerbose logs a message with LOG_PRIORITY_VERBOSE.
132 | // (https://wiki.libsdl.org/SDL_LogVerbose)
133 | func LogVerbose(category int, str string, args ...interface{}) {
134 | str = fmt.Sprintf(str, args...)
135 |
136 | cstr := C.CString(str)
137 | defer C.free(unsafe.Pointer(cstr))
138 |
139 | C._SDL_LogVerbose(C.int(category), cstr)
140 | }
141 |
142 | // LogDebug logs a message with LOG_PRIORITY_DEBUG.
143 | // (https://wiki.libsdl.org/SDL_LogDebug)
144 | func LogDebug(category int, str string, args ...interface{}) {
145 | str = fmt.Sprintf(str, args...)
146 |
147 | cstr := C.CString(str)
148 | defer C.free(unsafe.Pointer(cstr))
149 |
150 | C._SDL_LogDebug(C.int(category), cstr)
151 | }
152 |
153 | // LogInfo logs a message with LOG_PRIORITY_INFO.
154 | // (https://wiki.libsdl.org/SDL_LogInfo)
155 | func LogInfo(category int, str string, args ...interface{}) {
156 | str = fmt.Sprintf(str, args...)
157 |
158 | cstr := C.CString(str)
159 | defer C.free(unsafe.Pointer(cstr))
160 |
161 | C._SDL_LogInfo(C.int(category), cstr)
162 | }
163 |
164 | // LogWarn logs a message with LOG_PRIORITY_WARN.
165 | // (https://wiki.libsdl.org/SDL_LogWarn)
166 | func LogWarn(category int, str string, args ...interface{}) {
167 | str = fmt.Sprintf(str, args...)
168 |
169 | cstr := C.CString(str)
170 | defer C.free(unsafe.Pointer(cstr))
171 |
172 | C._SDL_LogWarn(C.int(category), cstr)
173 | }
174 |
175 | // LogError logs a message with LOG_PRIORITY_ERROR.
176 | // (https://wiki.libsdl.org/SDL_LogError)
177 | func LogError(category int, str string, args ...interface{}) {
178 | str = fmt.Sprintf(str, args...)
179 |
180 | cstr := C.CString(str)
181 | defer C.free(unsafe.Pointer(cstr))
182 |
183 | C._SDL_LogError(C.int(category), cstr)
184 | }
185 |
186 | // LogCritical logs a message with LOG_PRIORITY_CRITICAL.
187 | // (https://wiki.libsdl.org/SDL_LogCritical)
188 | func LogCritical(category int, str string, args ...interface{}) {
189 | str = fmt.Sprintf(str, args...)
190 |
191 | cstr := C.CString(str)
192 | defer C.free(unsafe.Pointer(cstr))
193 |
194 | C._SDL_LogCritical(C.int(category), cstr)
195 | }
196 |
197 | // LogMessage logs a message with the specified category and priority.
198 | // (https://wiki.libsdl.org/SDL_LogMessage)
199 | func LogMessage(category int, pri LogPriority, str string, args ...interface{}) {
200 | str = fmt.Sprintf(str, args...)
201 |
202 | cstr := C.CString(str)
203 | defer C.free(unsafe.Pointer(cstr))
204 |
205 | C._SDL_LogMessage(C.int(category), C.SDL_LogPriority(pri), cstr)
206 | }
207 |
208 | // LogOutputFunction is the function to call instead of the default
209 | type LogOutputFunction func(data interface{}, category int, pri LogPriority, message string)
210 |
211 | type logOutputFunctionCtx struct {
212 | f LogOutputFunction
213 | d interface{}
214 | }
215 |
216 | // Yissakhar Z. Beck (DeedleFake)'s implementation
217 | //
218 | //export logOutputFunction
219 | func logOutputFunction(data unsafe.Pointer, category C.int, pri C.SDL_LogPriority, message *C.char) {
220 | ctx := (*logOutputFunctionCtx)(data)
221 |
222 | ctx.f(ctx.d, int(category), LogPriority(pri), C.GoString(message))
223 | }
224 |
225 | var (
226 | logOutputFunctionCache LogOutputFunction
227 | logOutputDataCache interface{}
228 | )
229 |
230 | // LogGetOutputFunction returns the current log output function.
231 | // (https://wiki.libsdl.org/SDL_LogGetOutputFunction)
232 | func LogGetOutputFunction() (LogOutputFunction, interface{}) {
233 | return logOutputFunctionCache, logOutputDataCache
234 | }
235 |
236 | // LogSetOutputFunction replaces the default log output function with one of your own.
237 | // (https://wiki.libsdl.org/SDL_LogSetOutputFunction)
238 | func LogSetOutputFunction(f LogOutputFunction, data interface{}) {
239 | ctx := &logOutputFunctionCtx{
240 | f: f,
241 | d: data,
242 | }
243 |
244 | C.LogSetOutputFunction(unsafe.Pointer(ctx))
245 |
246 | logOutputFunctionCache = f
247 | logOutputDataCache = data
248 | }
249 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/log.h:
--------------------------------------------------------------------------------
1 | void LogSetOutputFunction(void *data);
2 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/mouse.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | #if defined(__WIN32)
7 | #include
8 | #else
9 | #include
10 | #endif
11 |
12 | #if !(SDL_VERSION_ATLEAST(2,0,4))
13 | #pragma message("SDL_CaptureMouse is not supported before SDL 2.0.4")
14 | static int SDL_CaptureMouse(SDL_bool enabled)
15 | {
16 | return -1;
17 | }
18 |
19 | #pragma message("SDL_MOUSEWHEEL_NORMAL is not supported before SDL 2.0.4")
20 | #define SDL_MOUSEWHEEL_NORMAL (0)
21 |
22 | #pragma message("SDL_MOUSEWHEEL_FLIPPED is not supported before SDL 2.0.4")
23 | #define SDL_MOUSEWHEEL_FLIPPED (0)
24 | #endif
25 | */
26 | import "C"
27 | import "unsafe"
28 |
29 | // Cursor types for CreateSystemCursor()
30 | const (
31 | SYSTEM_CURSOR_ARROW = C.SDL_SYSTEM_CURSOR_ARROW // arrow
32 | SYSTEM_CURSOR_IBEAM = C.SDL_SYSTEM_CURSOR_IBEAM // i-beam
33 | SYSTEM_CURSOR_WAIT = C.SDL_SYSTEM_CURSOR_WAIT // wait
34 | SYSTEM_CURSOR_CROSSHAIR = C.SDL_SYSTEM_CURSOR_CROSSHAIR // crosshair
35 | SYSTEM_CURSOR_WAITARROW = C.SDL_SYSTEM_CURSOR_WAITARROW // small wait cursor (or wait if not available)
36 | SYSTEM_CURSOR_SIZENWSE = C.SDL_SYSTEM_CURSOR_SIZENWSE // double arrow pointing northwest and southeast
37 | SYSTEM_CURSOR_SIZENESW = C.SDL_SYSTEM_CURSOR_SIZENESW // double arrow pointing northeast and southwest
38 | SYSTEM_CURSOR_SIZEWE = C.SDL_SYSTEM_CURSOR_SIZEWE // double arrow pointing west and east
39 | SYSTEM_CURSOR_SIZENS = C.SDL_SYSTEM_CURSOR_SIZENS // double arrow pointing north and south
40 | SYSTEM_CURSOR_SIZEALL = C.SDL_SYSTEM_CURSOR_SIZEALL // four pointed arrow pointing north, south, east, and west
41 | SYSTEM_CURSOR_NO = C.SDL_SYSTEM_CURSOR_NO // slashed circle or crossbones
42 | SYSTEM_CURSOR_HAND = C.SDL_SYSTEM_CURSOR_HAND // hand
43 | NUM_SYSTEM_CURSORS = C.SDL_NUM_SYSTEM_CURSORS // (only for bounding internal arrays)
44 | )
45 |
46 | // Scroll direction types for the Scroll event
47 | const (
48 | MOUSEWHEEL_NORMAL = C.SDL_MOUSEWHEEL_NORMAL // the scroll direction is normal
49 | MOUSEWHEEL_FLIPPED = C.SDL_MOUSEWHEEL_FLIPPED // the scroll direction is flipped / natural
50 | )
51 |
52 | // Used as a mask when testing buttons in buttonstate.
53 | const (
54 | BUTTON_LEFT = C.SDL_BUTTON_LEFT // left mouse button
55 | BUTTON_MIDDLE = C.SDL_BUTTON_MIDDLE // middle mouse button
56 | BUTTON_RIGHT = C.SDL_BUTTON_RIGHT // right mouse button
57 | BUTTON_X1 = C.SDL_BUTTON_X1 // x1 mouse button
58 | BUTTON_X2 = C.SDL_BUTTON_X2 // x2 mouse button
59 | )
60 |
61 | // Cursor is a custom cursor created by CreateCursor() or CreateColorCursor().
62 | type Cursor C.SDL_Cursor
63 |
64 | // SystemCursor is a system cursor created by CreateSystemCursor().
65 | type SystemCursor C.SDL_SystemCursor
66 |
67 | func (c *Cursor) cptr() *C.SDL_Cursor {
68 | return (*C.SDL_Cursor)(unsafe.Pointer(c))
69 | }
70 |
71 | func (c SystemCursor) c() C.SDL_SystemCursor {
72 | return C.SDL_SystemCursor(c)
73 | }
74 |
75 | // GetMouseFocus returns the window which currently has mouse focus.
76 | // (https://wiki.libsdl.org/SDL_GetMouseFocus)
77 | func GetMouseFocus() *Window {
78 | return (*Window)(unsafe.Pointer(C.SDL_GetMouseFocus()))
79 | }
80 |
81 | // GetMouseState returns the current state of the mouse.
82 | // (https://wiki.libsdl.org/SDL_GetMouseState)
83 | func GetMouseState() (x, y int32, state uint32) {
84 | var _x, _y C.int
85 | _state := uint32(C.SDL_GetMouseState(&_x, &_y))
86 | return int32(_x), int32(_y), _state
87 | }
88 |
89 | // GetRelativeMouseState returns the relative state of the mouse.
90 | // (https://wiki.libsdl.org/SDL_GetRelativeMouseState)
91 | func GetRelativeMouseState() (x, y int32, state uint32) {
92 | var _x, _y C.int
93 | _state := uint32(C.SDL_GetRelativeMouseState(&_x, &_y))
94 | return int32(_x), int32(_y), _state
95 | }
96 |
97 | // WarpMouseInWindow moves the mouse to the given position within the window.
98 | // (https://wiki.libsdl.org/SDL_WarpMouseInWindow)
99 | func (window *Window) WarpMouseInWindow(x, y int32) {
100 | C.SDL_WarpMouseInWindow(window.cptr(), C.int(x), C.int(y))
101 | }
102 |
103 | // SetRelativeMouseMode sets relative mouse mode.
104 | // (https://wiki.libsdl.org/SDL_SetRelativeMouseMode)
105 | func SetRelativeMouseMode(enabled bool) int {
106 | return int(C.SDL_SetRelativeMouseMode(C.SDL_bool(Btoi(enabled))))
107 | }
108 |
109 | // GetRelativeMouseMode reports where relative mouse mode is enabled.
110 | // (https://wiki.libsdl.org/SDL_GetRelativeMouseMode)
111 | func GetRelativeMouseMode() bool {
112 | return C.SDL_GetRelativeMouseMode() > 0
113 | }
114 |
115 | // CreateCursor creates a cursor using the specified bitmap data and mask (in MSB format).
116 | // (https://wiki.libsdl.org/SDL_CreateCursor)
117 | func CreateCursor(data, mask *uint8, w, h, hotX, hotY int32) *Cursor {
118 | _data := (*C.Uint8)(unsafe.Pointer(data))
119 | _mask := (*C.Uint8)(unsafe.Pointer(mask))
120 | return (*Cursor)(C.SDL_CreateCursor(_data, _mask, C.int(w), C.int(h), C.int(hotX), C.int(hotY)))
121 | }
122 |
123 | // CreateColorCursor creates a color cursor.
124 | // (https://wiki.libsdl.org/SDL_CreateColorCursor)
125 | func CreateColorCursor(surface *Surface, hotX, hotY int32) *Cursor {
126 | return (*Cursor)(C.SDL_CreateColorCursor(surface.cptr(), C.int(hotX), C.int(hotY)))
127 | }
128 |
129 | // CreateSystemCursor creates a system cursor.
130 | // (https://wiki.libsdl.org/SDL_CreateSystemCursor)
131 | func CreateSystemCursor(id SystemCursor) *Cursor {
132 | return (*Cursor)(C.SDL_CreateSystemCursor(id.c()))
133 | }
134 |
135 | // SetCursor sets the active cursor.
136 | // (https://wiki.libsdl.org/SDL_SetCursor)
137 | func SetCursor(cursor *Cursor) {
138 | C.SDL_SetCursor(cursor.cptr())
139 | }
140 |
141 | // GetCursor returns the active cursor.
142 | // (https://wiki.libsdl.org/SDL_GetCursor)
143 | func GetCursor() *Cursor {
144 | return (*Cursor)(C.SDL_GetCursor())
145 | }
146 |
147 | // GetDefaultCursor returns the default cursor.
148 | // (https://wiki.libsdl.org/SDL_GetDefaultCursor)
149 | func GetDefaultCursor() *Cursor {
150 | return (*Cursor)(C.SDL_GetDefaultCursor())
151 | }
152 |
153 | // FreeCursor frees a cursor created with CreateCursor(), CreateColorCursor() or CreateSystemCursor().
154 | // (https://wiki.libsdl.org/SDL_FreeCursor)
155 | func FreeCursor(cursor *Cursor) {
156 | C.SDL_FreeCursor(cursor.cptr())
157 | }
158 |
159 | // ShowCursor toggles whether or not the cursor is shown.
160 | // (https://wiki.libsdl.org/SDL_ShowCursor)
161 | func ShowCursor(toggle int) (int, error) {
162 | i := int(C.SDL_ShowCursor(C.int(toggle)))
163 | return i, errorFromInt(i)
164 | }
165 |
166 | // CaptureMouse captures the mouse and tracks input outside an SDL window.
167 | // (https://wiki.libsdl.org/SDL_CaptureMouse)
168 | func CaptureMouse(toggle bool) error {
169 | var ierr C.int
170 | if toggle {
171 | ierr = C.SDL_CaptureMouse(C.SDL_TRUE)
172 | } else {
173 | ierr = C.SDL_CaptureMouse(C.SDL_FALSE)
174 | }
175 | if ierr != 0 {
176 | return GetError()
177 | }
178 | return nil
179 | }
180 |
181 | // Button is used as a mask when testing buttons in buttonstate.
182 | func Button(flag uint32) uint32 {
183 | return 1 << (flag - 1)
184 | }
185 |
186 | // ButtonLMask is used as a mask when testing buttons in buttonstate.
187 | func ButtonLMask() uint32 {
188 | return Button(BUTTON_LEFT)
189 | }
190 |
191 | // ButtonMMask is used as a mask when testing buttons in buttonstate.
192 | func ButtonMMask() uint32 {
193 | return Button(BUTTON_MIDDLE)
194 | }
195 |
196 | // ButtonRMask is used as a mask when testing buttons in buttonstate.
197 | func ButtonRMask() uint32 {
198 | return Button(BUTTON_RIGHT)
199 | }
200 |
201 | // ButtonX1Mask is used as a mask when testing buttons in buttonstate.
202 | func ButtonX1Mask() uint32 {
203 | return Button(BUTTON_X1)
204 | }
205 |
206 | // ButtonX2Mask is used as a mask when testing buttons in buttonstate.
207 | func ButtonX2Mask() uint32 {
208 | return Button(BUTTON_X2)
209 | }
210 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/mutex.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // ThreadID is the thread identifier for a thread.
8 | type ThreadID uint64
9 |
10 | // Mutex is the SDL mutex structure.
11 | type Mutex struct {
12 | Recursive int
13 | Owner ThreadID
14 | Sem *Sem
15 | }
16 |
17 | // Sem is the SDL semaphore structure.
18 | type Sem struct {
19 | Count uint32
20 | WaitersCount uint32
21 | CountLock *Mutex
22 | CountNonzero *Cond
23 | }
24 |
25 | // Cond is the SDL condition variable structure.
26 | type Cond struct {
27 | Lock *Mutex
28 | Waiting int
29 | Signals int
30 | WaitSem *Sem
31 | WaitDone *Sem
32 | }
33 |
34 | func (m *Mutex) cptr() *C.SDL_mutex {
35 | return (*C.SDL_mutex)(unsafe.Pointer(m))
36 | }
37 |
38 | func (s *Sem) cptr() *C.SDL_sem {
39 | return (*C.SDL_sem)(unsafe.Pointer(s))
40 | }
41 |
42 | func (c *Cond) cptr() *C.SDL_cond {
43 | return (*C.SDL_cond)(unsafe.Pointer(c))
44 | }
45 |
46 | // CreateMutex creates a new mutex.
47 | // (https://wiki.libsdl.org/SDL_CreateMutex)
48 | func CreateMutex() (*Mutex, error) {
49 | mutex := C.SDL_CreateMutex()
50 | if mutex == nil {
51 | return nil, GetError()
52 | }
53 | return (*Mutex)(unsafe.Pointer(mutex)), nil
54 | }
55 |
56 | // Lock locks a mutex created with CreateMutex().
57 | // (https://wiki.libsdl.org/SDL_LockMutex)
58 | func (mutex *Mutex) Lock() error {
59 | ret := int(C.SDL_LockMutex(mutex.cptr()))
60 | if ret != 0 {
61 | return GetError()
62 | }
63 | return nil
64 | }
65 |
66 | // TryLock tries to lock a mutex without blocking.
67 | // (https://wiki.libsdl.org/SDL_TryLockMutex)
68 | func (mutex *Mutex) TryLock() error {
69 | ret := int(C.SDL_TryLockMutex(mutex.cptr()))
70 | if ret != 0 {
71 | return GetError()
72 | }
73 | return nil
74 | }
75 |
76 | // Unlock unlocks a mutex created with CreateMutex().
77 | // (https://wiki.libsdl.org/SDL_UnlockMutex)
78 | func (mutex *Mutex) Unlock() error {
79 | ret := int(C.SDL_UnlockMutex(mutex.cptr()))
80 | if ret != 0 {
81 | return GetError()
82 | }
83 | return nil
84 | }
85 |
86 | // Destroy destroys a mutex created with CreateMutex().
87 | // (https://wiki.libsdl.org/SDL_DestroyMutex)
88 | func (mutex *Mutex) Destroy() {
89 | C.SDL_DestroyMutex(mutex.cptr())
90 | }
91 |
92 | // CreateSemaphore creates a semaphore.
93 | // (https://wiki.libsdl.org/SDL_CreateSemaphore)
94 | func CreateSemaphore(initialValue uint32) (*Sem, error) {
95 | sem := C.SDL_CreateSemaphore(C.Uint32(initialValue))
96 | if sem == nil {
97 | return nil, GetError()
98 | }
99 | return (*Sem)(unsafe.Pointer(sem)), nil
100 | }
101 |
102 | // Destroy destroys a semaphore.
103 | // (https://wiki.libsdl.org/SDL_DestroySemaphore)
104 | func (sem *Sem) Destroy() {
105 | C.SDL_DestroySemaphore(sem.cptr())
106 | }
107 |
108 | // Wait waits until a semaphore has a positive value and then decrements it.
109 | // (https://wiki.libsdl.org/SDL_SemWait)
110 | func (sem *Sem) Wait() error {
111 | ret := int(C.SDL_SemWait(sem.cptr()))
112 | if ret != 0 {
113 | return GetError()
114 | }
115 | return nil
116 | }
117 |
118 | // TryWait sees if a semaphore has a positive value and decrement it if it does.
119 | // (https://wiki.libsdl.org/SDL_SemTryWait)
120 | func (sem *Sem) TryWait() error {
121 | ret := int(C.SDL_SemTryWait(sem.cptr()))
122 | if ret != 0 {
123 | return GetError()
124 | }
125 | return nil
126 | }
127 |
128 | // WaitTimeout waits until a semaphore has a positive value and then decrements it.
129 | // (https://wiki.libsdl.org/SDL_SemWaitTimeout)
130 | func (sem *Sem) WaitTimeout(ms uint32) error {
131 | ret := int(C.SDL_SemWaitTimeout(sem.cptr(), C.Uint32(ms)))
132 | if ret != 0 {
133 | return GetError()
134 | }
135 | return nil
136 | }
137 |
138 | // Post atomically increments a semaphore's value and wake waiting threads.
139 | // (https://wiki.libsdl.org/SDL_SemPost)
140 | func (sem *Sem) Post() error {
141 | ret := int(C.SDL_SemPost(sem.cptr()))
142 | if ret != 0 {
143 | return GetError()
144 | }
145 | return nil
146 | }
147 |
148 | // Value returns the current value of a semaphore.
149 | // (https://wiki.libsdl.org/SDL_SemValue)
150 | func (sem *Sem) Value() uint32 {
151 | return uint32(C.SDL_SemValue(sem.cptr()))
152 | }
153 |
154 | // CreateCond (https://wiki.libsdl.org/SDL_CreateCond)
155 | func CreateCond() *Cond {
156 | return (*Cond)(unsafe.Pointer(C.SDL_CreateCond()))
157 | }
158 |
159 | // Destroy creates a condition variable.
160 | // (https://wiki.libsdl.org/SDL_DestroyCond)
161 | func (cond *Cond) Destroy() {
162 | C.SDL_DestroyCond(cond.cptr())
163 | }
164 |
165 | // Signal restarts one of the threads that are waiting on the condition variable.
166 | // (https://wiki.libsdl.org/SDL_CondSignal)
167 | func (cond *Cond) Signal() error {
168 | ret := int(C.SDL_CondSignal(cond.cptr()))
169 | if ret != 0 {
170 | return GetError()
171 | }
172 | return nil
173 | }
174 |
175 | // Broadcast restarts all threads that are waiting on the condition variable.
176 | // (https://wiki.libsdl.org/SDL_CondBroadcast)
177 | func (cond *Cond) Broadcast() error {
178 | ret := int(C.SDL_CondBroadcast(cond.cptr()))
179 | if ret != 0 {
180 | return GetError()
181 | }
182 | return nil
183 | }
184 |
185 | // Wait waits until a condition variable is signaled.
186 | // (https://wiki.libsdl.org/SDL_CondWait)
187 | func (cond *Cond) Wait(mutex *Mutex) error {
188 | ret := int(C.SDL_CondWait(cond.cptr(), mutex.cptr()))
189 | if ret != 0 {
190 | return GetError()
191 | }
192 | return nil
193 | }
194 |
195 | // WaitTimeout waits until a condition variable is signaled or a specified amount of time has passed.
196 | // (https://wiki.libsdl.org/SDL_CondWaitTimeout)
197 | func (cond *Cond) WaitTimeout(mutex *Mutex, ms uint32) error {
198 | ret := int(C.SDL_CondWaitTimeout(cond.cptr(), mutex.cptr(), C.Uint32(ms)))
199 | if ret != 0 {
200 | return GetError()
201 | }
202 | return nil
203 | }
204 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/pixels.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // PixelFormat contains pixel format information.
8 | // (https://wiki.libsdl.org/SDL_PixelFormat)
9 | type PixelFormat struct {
10 | Format uint32 // one of the PIXELFORMAT values (https://wiki.libsdl.org/SDL_PixelFormatEnum)
11 | Palette *Palette // palette structure associated with this pixel format, or nil if the format doesn't have a palette (https://wiki.libsdl.org/SDL_Palette)
12 | BitsPerPixel uint8 // the number of significant bits in a pixel value, eg: 8, 15, 16, 24, 32
13 | BytesPerPixel uint8 // the number of bytes required to hold a pixel value, eg: 1, 2, 3, 4
14 | _ [2]uint8 // padding
15 | Rmask uint32 // a mask representing the location of the red component of the pixel
16 | Gmask uint32 // a mask representing the location of the green component of the pixel
17 | Bmask uint32 // a mask representing the location of the blue component of the pixel
18 | Amask uint32 // a mask representing the location of the alpha component of the pixel or 0 if the pixel format doesn't have any alpha information
19 | rLoss uint8 // (internal use)
20 | gLoss uint8 // (internal use)
21 | bLoss uint8 // (internal use)
22 | aLoss uint8 // (internal use)
23 | rShift uint8 // (internal use)
24 | gShift uint8 // (internal use)
25 | bShift uint8 // (internal use)
26 | aShift uint8 // (internal use)
27 | refCount int32 // (internal use)
28 | next *PixelFormat // (internal use)
29 | }
30 | type cPixelFormat C.SDL_PixelFormat
31 |
32 | // Palette contains palette information.
33 | // (https://wiki.libsdl.org/SDL_Palette)
34 | type Palette struct {
35 | Ncolors int32 // the number of colors in the palette
36 | Colors *Color // an array of Color structures representing the palette (https://wiki.libsdl.org/SDL_Color)
37 | version uint32 // incrementally tracks changes to the palette (internal use)
38 | refCount int32 // reference count (internal use)
39 | }
40 | type cPalette C.SDL_Palette
41 |
42 | // Color represents a color.
43 | // (https://wiki.libsdl.org/SDL_Color)
44 | type Color struct {
45 | R uint8 // the red component in the range 0-255
46 | G uint8 // the green component in the range 0-255
47 | B uint8 // the blue component in the range 0-255
48 | A uint8 // the alpha component in the range 0-255
49 | }
50 |
51 | // Uint32 return uint32 representation of RGBA color.
52 | func (c Color) Uint32() uint32 {
53 | var v uint32
54 | v |= uint32(c.A) << 24
55 | v |= uint32(c.R) << 16
56 | v |= uint32(c.G) << 8
57 | v |= uint32(c.B)
58 | return v
59 | }
60 |
61 | // RGBA returns the alpha-premultiplied red, green, blue and alpha values
62 | // for the color. Each value ranges within [0, 0xffff], but is represented
63 | // by a uint32 so that multiplying by a blend factor up to 0xffff will not
64 | // overflow.
65 | //
66 | // An alpha-premultiplied color component c has been scaled by alpha (a),
67 | // so has valid values 0 <= c <= a.
68 | func (c Color) RGBA() (r, g, b, a uint32) {
69 | r = uint32(c.R)
70 | r |= r << 8
71 | g = uint32(c.G)
72 | g |= g << 8
73 | b = uint32(c.B)
74 | b |= b << 8
75 | a = uint32(c.A)
76 | a |= a << 8
77 | return
78 | }
79 |
80 | // Pixel types.
81 | const (
82 | PIXELTYPE_UNKNOWN = C.SDL_PIXELTYPE_UNKNOWN
83 | PIXELTYPE_INDEX1 = C.SDL_PIXELTYPE_INDEX1
84 | PIXELTYPE_INDEX4 = C.SDL_PIXELTYPE_INDEX4
85 | PIXELTYPE_INDEX8 = C.SDL_PIXELTYPE_INDEX8
86 | PIXELTYPE_PACKED8 = C.SDL_PIXELTYPE_PACKED8
87 | PIXELTYPE_PACKED16 = C.SDL_PIXELTYPE_PACKED16
88 | PIXELTYPE_PACKED32 = C.SDL_PIXELTYPE_PACKED32
89 | PIXELTYPE_ARRAYU8 = C.SDL_PIXELTYPE_ARRAYU8
90 | PIXELTYPE_ARRAYU16 = C.SDL_PIXELTYPE_ARRAYU16
91 | PIXELTYPE_ARRAYU32 = C.SDL_PIXELTYPE_ARRAYU32
92 | PIXELTYPE_ARRAYF16 = C.SDL_PIXELTYPE_ARRAYF16
93 | PIXELTYPE_ARRAYF32 = C.SDL_PIXELTYPE_ARRAYF32
94 | )
95 |
96 | // Bitmap pixel order high bit -> low bit.
97 | const (
98 | BITMAPORDER_NONE = C.SDL_BITMAPORDER_NONE
99 | BITMAPORDER_4321 = C.SDL_BITMAPORDER_4321
100 | BITMAPORDER_1234 = C.SDL_BITMAPORDER_1234
101 | )
102 |
103 | // Packed component order high bit -> low bit.
104 | const (
105 | PACKEDORDER_NONE = C.SDL_PACKEDORDER_NONE
106 | PACKEDORDER_XRGB = C.SDL_PACKEDORDER_XRGB
107 | PACKEDORDER_RGBX = C.SDL_PACKEDORDER_RGBX
108 | PACKEDORDER_ARGB = C.SDL_PACKEDORDER_ARGB
109 | PACKEDORDER_RGBA = C.SDL_PACKEDORDER_RGBA
110 | PACKEDORDER_XBGR = C.SDL_PACKEDORDER_XBGR
111 | PACKEDORDER_BGRX = C.SDL_PACKEDORDER_BGRX
112 | PACKEDORDER_ABGR = C.SDL_PACKEDORDER_ABGR
113 | PACKEDORDER_BGRA = C.SDL_PACKEDORDER_BGRA
114 | )
115 |
116 | // Array component order low byte -> high byte.
117 | const (
118 | ARRAYORDER_NONE = C.SDL_ARRAYORDER_NONE
119 | ARRAYORDER_RGB = C.SDL_ARRAYORDER_RGB
120 | ARRAYORDER_RGBA = C.SDL_ARRAYORDER_RGBA
121 | ARRAYORDER_ARGB = C.SDL_ARRAYORDER_ARGB
122 | ARRAYORDER_BGR = C.SDL_ARRAYORDER_BGR
123 | ARRAYORDER_BGRA = C.SDL_ARRAYORDER_BGRA
124 | ARRAYORDER_ABGR = C.SDL_ARRAYORDER_ABGR
125 | )
126 |
127 | // Packed component layout.
128 | const (
129 | PACKEDLAYOUT_NONE = C.SDL_PACKEDLAYOUT_NONE
130 | PACKEDLAYOUT_332 = C.SDL_PACKEDLAYOUT_332
131 | PACKEDLAYOUT_4444 = C.SDL_PACKEDLAYOUT_4444
132 | PACKEDLAYOUT_1555 = C.SDL_PACKEDLAYOUT_1555
133 | PACKEDLAYOUT_5551 = C.SDL_PACKEDLAYOUT_5551
134 | PACKEDLAYOUT_565 = C.SDL_PACKEDLAYOUT_565
135 | PACKEDLAYOUT_8888 = C.SDL_PACKEDLAYOUT_8888
136 | PACKEDLAYOUT_2101010 = C.SDL_PACKEDLAYOUT_2101010
137 | PACKEDLAYOUT_1010102 = C.SDL_PACKEDLAYOUT_1010102
138 | )
139 |
140 | // Pixel format values.
141 | const (
142 | PIXELFORMAT_UNKNOWN = C.SDL_PIXELFORMAT_UNKNOWN
143 | PIXELFORMAT_INDEX1LSB = C.SDL_PIXELFORMAT_INDEX1LSB
144 | PIXELFORMAT_INDEX1MSB = C.SDL_PIXELFORMAT_INDEX1MSB
145 | PIXELFORMAT_INDEX4LSB = C.SDL_PIXELFORMAT_INDEX4LSB
146 | PIXELFORMAT_INDEX4MSB = C.SDL_PIXELFORMAT_INDEX4MSB
147 | PIXELFORMAT_INDEX8 = C.SDL_PIXELFORMAT_INDEX8
148 | PIXELFORMAT_RGB332 = C.SDL_PIXELFORMAT_RGB332
149 | PIXELFORMAT_RGB444 = C.SDL_PIXELFORMAT_RGB444
150 | PIXELFORMAT_RGB555 = C.SDL_PIXELFORMAT_RGB555
151 | PIXELFORMAT_BGR555 = C.SDL_PIXELFORMAT_BGR555
152 | PIXELFORMAT_ARGB4444 = C.SDL_PIXELFORMAT_ARGB4444
153 | PIXELFORMAT_RGBA4444 = C.SDL_PIXELFORMAT_RGBA4444
154 | PIXELFORMAT_ABGR4444 = C.SDL_PIXELFORMAT_ABGR4444
155 | PIXELFORMAT_BGRA4444 = C.SDL_PIXELFORMAT_BGRA4444
156 | PIXELFORMAT_ARGB1555 = C.SDL_PIXELFORMAT_ARGB1555
157 | PIXELFORMAT_RGBA5551 = C.SDL_PIXELFORMAT_RGBA5551
158 | PIXELFORMAT_ABGR1555 = C.SDL_PIXELFORMAT_ABGR1555
159 | PIXELFORMAT_BGRA5551 = C.SDL_PIXELFORMAT_BGRA5551
160 | PIXELFORMAT_RGB565 = C.SDL_PIXELFORMAT_RGB565
161 | PIXELFORMAT_BGR565 = C.SDL_PIXELFORMAT_BGR565
162 | PIXELFORMAT_RGB24 = C.SDL_PIXELFORMAT_RGB24
163 | PIXELFORMAT_BGR24 = C.SDL_PIXELFORMAT_BGR24
164 | PIXELFORMAT_RGB888 = C.SDL_PIXELFORMAT_RGB888
165 | PIXELFORMAT_RGBX8888 = C.SDL_PIXELFORMAT_RGBX8888
166 | PIXELFORMAT_BGR888 = C.SDL_PIXELFORMAT_BGR888
167 | PIXELFORMAT_BGRX8888 = C.SDL_PIXELFORMAT_BGRX8888
168 | PIXELFORMAT_ARGB8888 = C.SDL_PIXELFORMAT_ARGB8888
169 | PIXELFORMAT_RGBA8888 = C.SDL_PIXELFORMAT_RGBA8888
170 | PIXELFORMAT_ABGR8888 = C.SDL_PIXELFORMAT_ABGR8888
171 | PIXELFORMAT_BGRA8888 = C.SDL_PIXELFORMAT_BGRA8888
172 | PIXELFORMAT_ARGB2101010 = C.SDL_PIXELFORMAT_ARGB2101010
173 | PIXELFORMAT_YV12 = C.SDL_PIXELFORMAT_YV12
174 | PIXELFORMAT_IYUV = C.SDL_PIXELFORMAT_IYUV
175 | PIXELFORMAT_YUY2 = C.SDL_PIXELFORMAT_YUY2
176 | PIXELFORMAT_UYVY = C.SDL_PIXELFORMAT_UYVY
177 | PIXELFORMAT_YVYU = C.SDL_PIXELFORMAT_YVYU
178 | )
179 |
180 | // Pixel format variables.
181 | var (
182 | PIXELFORMAT_RGBA32 int
183 | PIXELFORMAT_ARGB32 int
184 | PIXELFORMAT_BGRA32 int
185 | PIXELFORMAT_ABGR32 int
186 | )
187 |
188 | // These define alpha as the opacity of a surface.
189 | const (
190 | ALPHA_OPAQUE = C.SDL_ALPHA_OPAQUE
191 | ALPHA_TRANSPARENT = C.SDL_ALPHA_TRANSPARENT
192 | )
193 |
194 | func init() {
195 | if BYTEORDER == BIG_ENDIAN {
196 | PIXELFORMAT_RGBA32 = PIXELFORMAT_RGBA8888
197 | PIXELFORMAT_ARGB32 = PIXELFORMAT_ARGB8888
198 | PIXELFORMAT_BGRA32 = PIXELFORMAT_BGRA8888
199 | PIXELFORMAT_ABGR32 = PIXELFORMAT_ABGR8888
200 | } else {
201 | PIXELFORMAT_RGBA32 = PIXELFORMAT_ABGR8888
202 | PIXELFORMAT_ARGB32 = PIXELFORMAT_BGRA8888
203 | PIXELFORMAT_BGRA32 = PIXELFORMAT_ARGB8888
204 | PIXELFORMAT_ABGR32 = PIXELFORMAT_RGBA8888
205 | }
206 | }
207 |
208 | func (format *PixelFormat) cptr() *C.SDL_PixelFormat {
209 | return (*C.SDL_PixelFormat)(unsafe.Pointer(format))
210 | }
211 |
212 | func (palette *Palette) cptr() *C.SDL_Palette {
213 | return (*C.SDL_Palette)(unsafe.Pointer(palette))
214 | }
215 |
216 | /*
217 | * the following code is modified version of the code from bitbucket.org/dooots/go-sdl2
218 | */
219 |
220 | // GetPixelFormatName returns the human readable name of a pixel format.
221 | // (https://wiki.libsdl.org/SDL_GetPixelFormatName)
222 | func GetPixelFormatName(format uint) string {
223 | return C.GoString(C.SDL_GetPixelFormatName(C.Uint32(format)))
224 | }
225 |
226 | // PixelFormatEnumToMasks converts one of the enumerated pixel formats to a bpp value and RGBA masks.
227 | // (https://wiki.libsdl.org/SDL_PixelFormatEnumToMasks)
228 | func PixelFormatEnumToMasks(format uint) (bpp int, rmask, gmask, bmask, amask uint32, err error) {
229 | result := C.SDL_PixelFormatEnumToMasks(C.Uint32(format), (*C.int)(unsafe.Pointer(&bpp)),
230 | (*C.Uint32)(&rmask), (*C.Uint32)(&gmask), (*C.Uint32)(&bmask),
231 | (*C.Uint32)(&amask))
232 | if result == C.SDL_FALSE {
233 | err = GetError()
234 | }
235 | return
236 | }
237 |
238 | // MasksToPixelFormatEnum converts a bpp value and RGBA masks to an enumerated pixel format.
239 | // (https://wiki.libsdl.org/SDL_MasksToPixelFormatEnum)
240 | func MasksToPixelFormatEnum(bpp int, rmask, gmask, bmask, amask uint32) uint {
241 | return uint(C.SDL_MasksToPixelFormatEnum(C.int(bpp), C.Uint32(rmask), C.Uint32(gmask),
242 | C.Uint32(bmask), C.Uint32(amask)))
243 | }
244 |
245 | // AllocFormat creates a PixelFormat structure corresponding to a pixel format.
246 | // (https://wiki.libsdl.org/SDL_AllocFormat)
247 | func AllocFormat(format uint) (*PixelFormat, error) {
248 | r := (*PixelFormat)(unsafe.Pointer(C.SDL_AllocFormat(C.Uint32(format))))
249 | if r == nil {
250 | return nil, GetError()
251 | }
252 | return r, nil
253 | }
254 |
255 | // Free frees the PixelFormat structure allocated by AllocFormat().
256 | // (https://wiki.libsdl.org/SDL_FreeFormat)
257 | func (format *PixelFormat) Free() {
258 | C.SDL_FreeFormat((*C.SDL_PixelFormat)(unsafe.Pointer(format)))
259 | }
260 |
261 | // AllocPalette creates a palette structure with the specified number of color entries.
262 | // (https://wiki.libsdl.org/SDL_AllocPalette)
263 | func AllocPalette(ncolors int) (*Palette, error) {
264 | r := (*Palette)(unsafe.Pointer(C.SDL_AllocPalette(C.int(ncolors))))
265 | if r == nil {
266 | return nil, GetError()
267 | }
268 | return r, nil
269 | }
270 |
271 | // SetPalette sets the palette for the pixel format structure.
272 | // (https://wiki.libsdl.org/SDL_SetPixelFormatPalette)
273 | func (format *PixelFormat) SetPalette(palette *Palette) error {
274 | r := C.SDL_SetPixelFormatPalette((*C.SDL_PixelFormat)(unsafe.Pointer(format)),
275 | (*C.SDL_Palette)(unsafe.Pointer(palette)))
276 | if r != 0 {
277 | return GetError()
278 | }
279 | return nil
280 | }
281 |
282 | // SetColors sets a range of colors in the palette.
283 | // (https://wiki.libsdl.org/SDL_SetPaletteColors)
284 | func (palette *Palette) SetColors(colors []Color) error {
285 | var ptr *C.SDL_Color
286 | if len(colors) > 0 {
287 | ptr = (*C.SDL_Color)(unsafe.Pointer(&colors[0]))
288 | }
289 |
290 | r := C.SDL_SetPaletteColors((*C.SDL_Palette)(unsafe.Pointer(palette)),
291 | ptr, 0, C.int(len(colors)))
292 | if r != 0 {
293 | return GetError()
294 | }
295 | return nil
296 | }
297 |
298 | // Free frees the palette created with AllocPalette().
299 | // (https://wiki.libsdl.org/SDL_FreePalette)
300 | func (palette *Palette) Free() {
301 | C.SDL_FreePalette((*C.SDL_Palette)(unsafe.Pointer(palette)))
302 | }
303 |
304 | // MapRGB maps an RGB triple to an opaque pixel value for a given pixel format.
305 | // (https://wiki.libsdl.org/SDL_MapRGB)
306 | func MapRGB(format *PixelFormat, r, g, b uint8) uint32 {
307 | return uint32(C.SDL_MapRGB((*C.SDL_PixelFormat)(unsafe.Pointer(format)),
308 | C.Uint8(r), C.Uint8(g), C.Uint8(b)))
309 | }
310 |
311 | // MapRGBA maps an RGBA quadruple to a pixel value for a given pixel format.
312 | // (https://wiki.libsdl.org/SDL_MapRGBA)
313 | func MapRGBA(format *PixelFormat, r, g, b, a uint8) uint32 {
314 | return uint32(C.SDL_MapRGBA((*C.SDL_PixelFormat)(unsafe.Pointer(format)),
315 | C.Uint8(r), C.Uint8(g), C.Uint8(b), C.Uint8(a)))
316 | }
317 |
318 | // GetRGB returns RGB values from a pixel in the specified format.
319 | // (https://wiki.libsdl.org/SDL_GetRGB)
320 | func GetRGB(pixel uint32, format *PixelFormat) (r, g, b uint8) {
321 | C.SDL_GetRGB(C.Uint32(pixel), (*C.SDL_PixelFormat)(unsafe.Pointer(format)),
322 | (*C.Uint8)(&r), (*C.Uint8)(&g), (*C.Uint8)(&b))
323 | return
324 | }
325 |
326 | // GetRGBA returns RGBA values from a pixel in the specified format.
327 | // (https://wiki.libsdl.org/SDL_GetRGBA)
328 | func GetRGBA(pixel uint32, format *PixelFormat) (r, g, b, a uint8) {
329 | C.SDL_GetRGBA(C.Uint32(pixel), (*C.SDL_PixelFormat)(unsafe.Pointer(format)),
330 | (*C.Uint8)(&r), (*C.Uint8)(&g), (*C.Uint8)(&b), (*C.Uint8)(&a))
331 | return
332 | }
333 |
334 | // CalculateGammaRamp calculates a 256 entry gamma ramp for a gamma value.
335 | // (https://wiki.libsdl.org/SDL_CalculateGammaRamp)
336 | func CalculateGammaRamp(gamma float32, ramp *[256]uint16) {
337 | C.SDL_CalculateGammaRamp(C.float(gamma), (*C.Uint16)(unsafe.Pointer(&ramp[0])))
338 | }
339 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/power.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 |
6 | // An enumeration of the basic state of the system's power supply.
7 | // (https://wiki.libsdl.org/SDL_PowerState)
8 | const (
9 | POWERSTATE_UNKNOWN = C.SDL_POWERSTATE_UNKNOWN // cannot determine power status
10 | POWERSTATE_ON_BATTERY = C.SDL_POWERSTATE_ON_BATTERY // not plugged in, running on the battery
11 | POWERSTATE_NO_BATTERY = C.SDL_POWERSTATE_NO_BATTERY // plugged in, no battery available
12 | POWERSTATE_CHARGING = C.SDL_POWERSTATE_CHARGING // plugged in, charging battery
13 | POWERSTATE_CHARGED = C.SDL_POWERSTATE_CHARGED // plugged in, battery charged
14 | )
15 |
16 | // PowerState is the basic state for the system's power supply.
17 | // (https://wiki.libsdl.org/SDL_PowerState)
18 | type PowerState C.SDL_PowerState
19 |
20 | // GetPowerInfo returns the current power supply details.
21 | // (https://wiki.libsdl.org/SDL_GetPowerInfo)
22 | func GetPowerInfo() (int, int, int) {
23 | _secs := C.int(0)
24 | _percent := C.int(0)
25 | _state := C.SDL_GetPowerInfo(&_secs, &_percent)
26 | return (int)(_state), (int)(_secs), (int)(_percent)
27 | }
28 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/rect.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // Point defines a two dimensional point.
8 | // (https://wiki.libsdl.org/SDL_Point)
9 | type Point struct {
10 | X int32 // the x coordinate of the point
11 | Y int32 // the y coordinate of the point
12 | }
13 |
14 | // Rect contains the definition of a rectangle, with the origin at the upper left.
15 | // (https://wiki.libsdl.org/SDL_Rect)
16 | type Rect struct {
17 | X int32 // the x location of the rectangle's upper left corner
18 | Y int32 // the y location of the rectangle's upper left corner
19 | W int32 // the width of the rectangle
20 | H int32 // the height of the rectangle
21 | }
22 |
23 | func (p *Point) cptr() *C.SDL_Point {
24 | return (*C.SDL_Point)(unsafe.Pointer(p))
25 | }
26 |
27 | func (a *Rect) cptr() *C.SDL_Rect {
28 | return (*C.SDL_Rect)(unsafe.Pointer(a))
29 | }
30 |
31 | // InRect reports whether the point resides inside a rectangle.
32 | // (https://wiki.libsdl.org/SDL_PointInRect)
33 | func (p *Point) InRect(r *Rect) bool {
34 | if (p.X >= r.X) && (p.X < (r.X + r.W)) &&
35 | (p.Y >= r.Y) && (p.Y < (r.Y + r.H)) {
36 | return true
37 | }
38 | return false
39 | }
40 |
41 | // Empty reports whether a rectangle has no area.
42 | // (https://wiki.libsdl.org/SDL_RectEmpty)
43 | func (a *Rect) Empty() bool {
44 | return a == nil || a.W <= 0 || a.H <= 0
45 | }
46 |
47 | // Equals reports whether two rectangles are equal.
48 | // (https://wiki.libsdl.org/SDL_RectEquals)
49 | func (a *Rect) Equals(b *Rect) bool {
50 | if (a != nil) && (b != nil) &&
51 | (a.X == b.X) && (a.Y == b.Y) &&
52 | (a.W == b.W) && (a.H == b.H) {
53 | return true
54 | }
55 | return false
56 | }
57 |
58 | // HasIntersection reports whether two rectangles intersect.
59 | // (https://wiki.libsdl.org/SDL_HasIntersection)
60 | func (a *Rect) HasIntersection(b *Rect) bool {
61 | if a == nil || b == nil {
62 | return false
63 | }
64 |
65 | // Special case for empty rects
66 | if a.Empty() || b.Empty() {
67 | return false
68 | }
69 |
70 | if a.X >= b.X+b.W || a.X+a.W <= b.X || a.Y >= b.Y+b.H || a.Y+a.H <= b.Y {
71 | return false
72 | }
73 |
74 | return true
75 | }
76 |
77 | // Intersect calculates the intersection of two rectangles.
78 | // (https://wiki.libsdl.org/SDL_IntersectRect)
79 | func (a *Rect) Intersect(b *Rect) (Rect, bool) {
80 | var result Rect
81 |
82 | if a == nil || b == nil {
83 | return result, false
84 | }
85 |
86 | // Special case for empty rects
87 | if a.Empty() || b.Empty() {
88 | result.W = 0
89 | result.H = 0
90 | return result, false
91 | }
92 |
93 | aMin := a.X
94 | aMax := aMin + a.W
95 | bMin := b.X
96 | bMax := bMin + b.W
97 | if bMin > aMin {
98 | aMin = bMin
99 | }
100 | result.X = aMin
101 | if bMax < aMax {
102 | aMax = bMax
103 | }
104 | result.W = aMax - aMin
105 |
106 | aMin = a.Y
107 | aMax = aMin + a.H
108 | bMin = b.Y
109 | bMax = bMin + b.H
110 | if bMin > aMin {
111 | aMin = bMin
112 | }
113 | result.Y = aMin
114 | if bMax < aMax {
115 | aMax = bMax
116 | }
117 | result.H = aMax - aMin
118 |
119 | return result, !result.Empty()
120 | }
121 |
122 | // Union calculates the union of two rectangles.
123 | // (https://wiki.libsdl.org/SDL_UnionRect)
124 | func (a *Rect) Union(b *Rect) Rect {
125 | var result Rect
126 |
127 | if a == nil || b == nil {
128 | return result
129 | }
130 |
131 | // Special case for empty rects
132 | if a.Empty() {
133 | return *b
134 | } else if b.Empty() {
135 | return *a
136 | } else if a.Empty() && b.Empty() {
137 | return result
138 | }
139 |
140 | aMin := a.X
141 | aMax := aMin + a.W
142 | bMin := b.X
143 | bMax := bMin + b.W
144 | if bMin < aMin {
145 | aMin = bMin
146 | }
147 | result.X = aMin
148 | if bMax > aMax {
149 | aMax = bMax
150 | }
151 | result.W = aMax - aMin
152 |
153 | aMin = a.Y
154 | aMax = aMin + a.H
155 | bMin = b.Y
156 | bMax = bMin + b.H
157 | if bMin < aMin {
158 | aMin = bMin
159 | }
160 | result.Y = aMin
161 | if bMax > aMax {
162 | aMax = bMax
163 | }
164 | result.H = aMax - aMin
165 |
166 | return result
167 | }
168 |
169 | // EnclosePoints calculates a minimal rectangle that encloses a set of points.
170 | // (https://wiki.libsdl.org/SDL_EnclosePoints)
171 | func EnclosePoints(points []Point, clip *Rect) (Rect, bool) {
172 | var result Rect
173 |
174 | if len(points) == 0 {
175 | return result, false
176 | }
177 |
178 | var minX, minY, maxX, maxY int32
179 | if clip != nil {
180 | added := false
181 | clipMinX := clip.X
182 | clipMinY := clip.Y
183 | clipMaxX := clip.X + clip.W - 1
184 | clipMaxY := clip.Y + clip.H - 1
185 |
186 | // If the clip has no size, we're done
187 | if clip.Empty() {
188 | return result, false
189 | }
190 |
191 | for _, val := range points {
192 | // Check if the point is inside the clip rect
193 | if val.X < clipMinX || val.X > clipMaxX || val.Y < clipMinY || val.Y > clipMaxY {
194 | continue
195 | }
196 |
197 | if !added {
198 | // If it's the first point
199 | minX = val.X
200 | maxX = val.X
201 | minY = val.Y
202 | maxY = val.Y
203 | added = true
204 | }
205 |
206 | // Find mins and maxes
207 | if val.X < minX {
208 | minX = val.X
209 | } else if val.X > maxX {
210 | maxX = val.X
211 | }
212 | if val.Y < minY {
213 | minY = val.Y
214 | } else if val.Y > maxY {
215 | maxY = val.Y
216 | }
217 | }
218 | } else {
219 | for i, val := range points {
220 | if i == 0 {
221 | // Populate the first point
222 | minX = val.X
223 | maxX = val.X
224 | minY = val.Y
225 | maxY = val.Y
226 | continue
227 | }
228 |
229 | // Find mins and maxes
230 | if val.X < minX {
231 | minX = val.X
232 | } else if val.X > maxX {
233 | maxX = val.X
234 | }
235 | if val.Y < minY {
236 | minY = val.Y
237 | } else if val.Y > maxY {
238 | maxY = val.Y
239 | }
240 | }
241 | }
242 |
243 | result.X = minX
244 | result.Y = minY
245 | result.W = (maxX - minX) + 1
246 | result.H = (maxY - minY) + 1
247 |
248 | return result, true
249 | }
250 |
251 | const (
252 | codeBottom = 1
253 | codeTop = 2
254 | codeLeft = 4
255 | codeRight = 8
256 | )
257 |
258 | func computeOutCode(rect *Rect, x, y int32) int {
259 | code := 0
260 | if y < rect.Y {
261 | code |= codeTop
262 | } else if y >= rect.Y+rect.H {
263 | code |= codeBottom
264 | }
265 | if x < rect.X {
266 | code |= codeLeft
267 | } else if x >= rect.X+rect.W {
268 | code |= codeRight
269 | }
270 |
271 | return code
272 | }
273 |
274 | // IntersectLine calculates the intersection of a rectangle and a line segment.
275 | // (https://wiki.libsdl.org/SDL_IntersectRectAndLine)
276 | func (a *Rect) IntersectLine(X1, Y1, X2, Y2 *int32) bool {
277 | if a.Empty() {
278 | return false
279 | }
280 |
281 | x1 := *X1
282 | y1 := *Y1
283 | x2 := *X2
284 | y2 := *Y2
285 | rectX1 := a.X
286 | rectY1 := a.Y
287 | rectX2 := a.X + a.W - 1
288 | rectY2 := a.Y + a.H - 1
289 |
290 | // Check if the line is entirely inside the rect
291 | if x1 >= rectX1 && x1 <= rectX2 && x2 >= rectX1 && x2 <= rectX2 &&
292 | y1 >= rectY1 && y1 <= rectY2 && y2 >= rectY1 && y2 <= rectY2 {
293 | return true
294 | }
295 |
296 | // Check if the line is entirely outside the rect
297 | if (x1 < rectX1 && x2 < rectX1) || (x1 > rectX2 && x2 > rectX2) ||
298 | (y1 < rectY1 && y2 < rectY1) || (y1 > rectY2 && y2 > rectY2) {
299 | return false
300 | }
301 |
302 | // Check if the line is horizontal
303 | if y1 == y2 {
304 | if x1 < rectX1 {
305 | *X1 = rectX1
306 | } else if x1 > rectX2 {
307 | *X1 = rectX2
308 | }
309 | if x2 < rectX1 {
310 | *X2 = rectX1
311 | } else if x2 > rectX2 {
312 | *X2 = rectX2
313 | }
314 |
315 | return true
316 | }
317 |
318 | // Check if the line is vertical
319 | if x1 == x2 {
320 | if y1 < rectY1 {
321 | *Y1 = rectY1
322 | } else if y1 > rectY2 {
323 | *Y1 = rectY2
324 | }
325 | if y2 < rectY1 {
326 | *Y2 = rectY1
327 | } else if y2 > rectY2 {
328 | *Y2 = rectY2
329 | }
330 |
331 | return true
332 | }
333 |
334 | // Use Cohen-Sutherland algorithm when all shortcuts fail
335 | outCode1 := computeOutCode(a, x1, y1)
336 | outCode2 := computeOutCode(a, x2, y2)
337 | for outCode1 != 0 || outCode2 != 0 {
338 | if outCode1&outCode2 != 0 {
339 | return false
340 | }
341 |
342 | if outCode1 != 0 {
343 | var x, y int32
344 | if outCode1&codeTop != 0 {
345 | y = rectY1
346 | x = x1 + ((x2-x1)*(y-y1))/(y2-y1)
347 | } else if outCode1&codeBottom != 0 {
348 | y = rectY2
349 | x = x1 + ((x2-x1)*(y-y1))/(y2-y1)
350 | } else if outCode1&codeLeft != 0 {
351 | x = rectX1
352 | y = y1 + ((y2-y1)*(x-x1))/(x2-x1)
353 | } else if outCode1&codeRight != 0 {
354 | x = rectX2
355 | y = y1 + ((y2-y1)*(x-x1))/(x2-x1)
356 | }
357 |
358 | x1 = x
359 | y1 = y
360 | outCode1 = computeOutCode(a, x, y)
361 | } else {
362 | var x, y int32
363 | if outCode2&codeTop != 0 {
364 | y = rectY1
365 | x = x1 + ((x2-x1)*(y-y1))/(y2-y1)
366 | } else if outCode2&codeBottom != 0 {
367 | y = rectY2
368 | x = x1 + ((x2-x1)*(y-y1))/(y2-y1)
369 | } else if outCode2&codeLeft != 0 {
370 | x = rectX1
371 | y = y1 + ((y2-y1)*(x-x1))/(x2-x1)
372 | } else if outCode2&codeRight != 0 {
373 | x = rectX2
374 | y = y1 + ((y2-y1)*(x-x1))/(x2-x1)
375 | }
376 |
377 | x2 = x
378 | y2 = y
379 | outCode2 = computeOutCode(a, x, y)
380 | }
381 | }
382 |
383 | *X1 = x1
384 | *Y1 = y1
385 | *X2 = x2
386 | *Y2 = y2
387 |
388 | return true
389 | }
390 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/rwops.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 | static Sint64 RWsize(SDL_RWops *ctx)
6 | {
7 | return ctx->size(ctx);
8 | }
9 |
10 | static Sint64 RWseek(SDL_RWops *ctx, Sint64 offset, int whence)
11 | {
12 | return ctx->seek(ctx, offset, whence);
13 | }
14 |
15 | static size_t RWread(SDL_RWops *ctx, void *ptr, size_t size, size_t maxnum)
16 | {
17 | return ctx->read(ctx, ptr, size, maxnum);
18 | }
19 |
20 | static size_t RWwrite(SDL_RWops *ctx, void *ptr, size_t size, size_t num)
21 | {
22 | return ctx->write(ctx, ptr, size, num);
23 | }
24 |
25 | static int RWclose(SDL_RWops *ctx)
26 | {
27 | return ctx->close(ctx);
28 | }
29 | */
30 | import "C"
31 | import "unsafe"
32 |
33 | // RWops types
34 | const (
35 | RWOPS_UNKNOWN = 0 // unknown stream type
36 | RWOPS_WINFILE = 1 // win32 file
37 | RWOPS_STDFILE = 2 // stdio file
38 | RWOPS_JNIFILE = 3 // android asset
39 | RWOPS_MEMORY = 4 // memory stream
40 | RWOPS_MEMORY_RO = 5 // read-only memory stream
41 | )
42 |
43 | // RWops seek from
44 | const (
45 | RW_SEEK_SET = C.RW_SEEK_SET // seek from the beginning of data
46 | RW_SEEK_CUR = C.RW_SEEK_CUR // seek relative to current read point
47 | RW_SEEK_END = C.RW_SEEK_END // seek relative to the end of data
48 | )
49 |
50 | // RWops provides an abstract interface to stream I/O. Applications can generally ignore the specifics of this structure's internals and treat them as opaque pointers. The details are important to lower-level code that might need to implement one of these, however.
51 | // (https://wiki.libsdl.org/SDL_RWops)
52 | type RWops C.SDL_RWops
53 |
54 | func (rwops *RWops) cptr() *C.SDL_RWops {
55 | return (*C.SDL_RWops)(rwops)
56 | }
57 |
58 | // RWFromFile creates a new RWops structure for reading from and/or writing to a named file.
59 | // (https://wiki.libsdl.org/SDL_RWFromFile)
60 | func RWFromFile(file, mode string) *RWops {
61 | _file := C.CString(file)
62 | _mode := C.CString(mode)
63 | defer C.free(unsafe.Pointer(_file))
64 | defer C.free(unsafe.Pointer(_mode))
65 | return (*RWops)(unsafe.Pointer(C.SDL_RWFromFile(_file, _mode)))
66 | }
67 |
68 | // RWFromMem prepares a read-write memory buffer for use with RWops.
69 | // (https://wiki.libsdl.org/SDL_RWFromMem)
70 | func RWFromMem(mem unsafe.Pointer, size int) *RWops {
71 | if mem == nil {
72 | return nil
73 | }
74 | return (*RWops)(unsafe.Pointer(C.SDL_RWFromMem(mem, C.int(size))))
75 | }
76 |
77 | // AllocRW allocates an empty, unpopulated RWops structure.
78 | // (https://wiki.libsdl.org/SDL_AllocRW)
79 | func AllocRW() *RWops {
80 | return (*RWops)(unsafe.Pointer(C.SDL_AllocRW()))
81 | }
82 |
83 | // FreeRW frees the RWops structure allocated by AllocRW().
84 | // (https://wiki.libsdl.org/SDL_FreeRW)
85 | func (rwops *RWops) FreeRW() {
86 | if rwops == nil {
87 | return
88 | }
89 | C.SDL_FreeRW(rwops.cptr())
90 | }
91 |
92 | // RWsize returns the size of the data stream in the RWops.
93 | // (https://wiki.libsdl.org/SDL_RWsize)
94 | func (rwops *RWops) RWsize() int64 {
95 | return int64(C.RWsize(rwops.cptr()))
96 | }
97 |
98 | // RWseek seek within the RWops data stream.
99 | // (https://wiki.libsdl.org/SDL_RWseek)
100 | func (rwops *RWops) RWseek(offset int64, whence int) int64 {
101 | if rwops == nil {
102 | return -1
103 | }
104 | return int64(C.RWseek(rwops.cptr(), C.Sint64(offset), C.int(whence)))
105 | }
106 |
107 | // RWread read from a data source.
108 | // (https://wiki.libsdl.org/SDL_RWread)
109 | func (rwops *RWops) RWread(ptr unsafe.Pointer, size, maxnum uint) uint {
110 | if rwops == nil {
111 | return 0
112 | }
113 | return uint(C.RWread(rwops.cptr(), ptr, C.size_t(size), C.size_t(maxnum)))
114 | }
115 |
116 | // RWtell returns the current read/write offset in the RWops data stream.
117 | // (https://wiki.libsdl.org/SDL_RWtell)
118 | func (rwops *RWops) RWtell() int64 {
119 | if rwops == nil {
120 | return 0
121 | }
122 | return int64(C.RWseek(rwops.cptr(), 0, RW_SEEK_CUR))
123 | }
124 |
125 | // RWwrite writes to the RWops data stream.
126 | // (https://wiki.libsdl.org/SDL_RWwrite)
127 | func (rwops *RWops) RWwrite(ptr unsafe.Pointer, size, num uint) uint {
128 | if rwops == nil {
129 | return 0
130 | }
131 | if ptr == nil {
132 | return 0
133 | }
134 | return uint(C.RWwrite(rwops.cptr(), ptr, C.size_t(size), C.size_t(size)))
135 | }
136 |
137 | // RWclose closes and frees the allocated RWops structure.
138 | // (https://wiki.libsdl.org/SDL_RWclose)
139 | func (rwops *RWops) RWclose() error {
140 | if rwops != nil && C.RWclose(rwops.cptr()) != 0 {
141 | return GetError()
142 | }
143 | return nil
144 | }
145 |
146 | // ReadU8 reads a byte from the RWops.
147 | // (https://wiki.libsdl.org/SDL_ReadU8)
148 | func (rwops *RWops) ReadU8() uint8 {
149 | if rwops == nil {
150 | return 0
151 | }
152 | return uint8(C.SDL_ReadU8(rwops.cptr()))
153 | }
154 |
155 | // ReadLE16 reads 16 bits of little-endian data from the RWops and returns in native format.
156 | // (https://wiki.libsdl.org/SDL_ReadLE16)
157 | func (rwops *RWops) ReadLE16() uint16 {
158 | if rwops == nil {
159 | return 0
160 | }
161 | return uint16(C.SDL_ReadLE16(rwops.cptr()))
162 | }
163 |
164 | // ReadBE16 read 16 bits of big-endian data from the RWops and returns in native format.
165 | // (https://wiki.libsdl.org/SDL_ReadBE16)
166 | func (rwops *RWops) ReadBE16() uint16 {
167 | if rwops == nil {
168 | return 0
169 | }
170 | return uint16(C.SDL_ReadBE16(rwops.cptr()))
171 | }
172 |
173 | // ReadLE32 reads 32 bits of little-endian data from the RWops and returns in native format.
174 | // (https://wiki.libsdl.org/SDL_ReadLE32)
175 | func (rwops *RWops) ReadLE32() uint32 {
176 | if rwops == nil {
177 | return 0
178 | }
179 | return uint32(C.SDL_ReadLE32(rwops.cptr()))
180 | }
181 |
182 | // ReadBE32 reads 32 bits of big-endian data from the RWops and returns in native format.
183 | // (https://wiki.libsdl.org/SDL_ReadBE32)
184 | func (rwops *RWops) ReadBE32() uint32 {
185 | if rwops == nil {
186 | return 0
187 | }
188 | return uint32(C.SDL_ReadBE32(rwops.cptr()))
189 | }
190 |
191 | // ReadLE64 reads 64 bits of little-endian data from the RWops and returns in native format.
192 | // (https://wiki.libsdl.org/SDL_ReadLE64)
193 | func (rwops *RWops) ReadLE64() uint64 {
194 | if rwops == nil {
195 | return 0
196 | }
197 | return uint64(C.SDL_ReadLE64(rwops.cptr()))
198 | }
199 |
200 | // ReadBE64 reads 64 bits of big-endian data from the RWops and returns in native format.
201 | // (https://wiki.libsdl.org/SDL_ReadBE64)
202 | func (rwops *RWops) ReadBE64() uint64 {
203 | if rwops == nil {
204 | return 0
205 | }
206 | return uint64(C.SDL_ReadBE64(rwops.cptr()))
207 | }
208 |
209 | // WriteU8 writes a byte to the RWops.
210 | // (https://wiki.libsdl.org/SDL_WriteU8)
211 | func (rwops *RWops) WriteU8(value uint8) uint {
212 | if rwops == nil {
213 | return 0
214 | }
215 | return uint(C.SDL_WriteU8(rwops.cptr(), C.Uint8(value)))
216 | }
217 |
218 | // WriteLE16 writes 16 bits in native format to the RWops as little-endian data.
219 | // (https://wiki.libsdl.org/SDL_WriteLE16)
220 | func (rwops *RWops) WriteLE16(value uint16) uint {
221 | if rwops == nil {
222 | return 0
223 | }
224 | return uint(C.SDL_WriteLE16(rwops.cptr(), C.Uint16(value)))
225 | }
226 |
227 | // WriteBE16 writes 16 bits in native format to the RWops as big-endian data.
228 | // (https://wiki.libsdl.org/SDL_WriteBE16)
229 | func (rwops *RWops) WriteBE16(value uint16) uint {
230 | if rwops == nil {
231 | return 0
232 | }
233 | return uint(C.SDL_WriteBE16(rwops.cptr(), C.Uint16(value)))
234 | }
235 |
236 | // WriteLE32 writes 32 bits in native format to the RWops as little-endian data.
237 | // (https://wiki.libsdl.org/SDL_WriteLE32)
238 | func (rwops *RWops) WriteLE32(value uint32) uint {
239 | if rwops == nil {
240 | return 0
241 | }
242 | return uint(C.SDL_WriteLE32(rwops.cptr(), C.Uint32(value)))
243 | }
244 |
245 | // WriteBE32 writes 32 bits in native format to the RWops as big-endian data.
246 | // (https://wiki.libsdl.org/SDL_WriteBE32)
247 | func (rwops *RWops) WriteBE32(value uint32) uint {
248 | if rwops == nil {
249 | return 0
250 | }
251 | return uint(C.SDL_WriteBE32(rwops.cptr(), C.Uint32(value)))
252 | }
253 |
254 | // WriteLE64 writes 64 bits in native format to the RWops as little-endian data.
255 | // (https://wiki.libsdl.org/SDL_WriteLE64)
256 | func (rwops *RWops) WriteLE64(value uint64) uint {
257 | if rwops == nil {
258 | return 0
259 | }
260 | return uint(C.SDL_WriteLE64(rwops.cptr(), C.Uint64(value)))
261 | }
262 |
263 | // WriteBE64 writes 64 bits in native format to the RWops as big-endian data.
264 | // (https://wiki.libsdl.org/SDL_WriteBE64)
265 | func (rwops *RWops) WriteBE64(value uint64) uint {
266 | if rwops == nil {
267 | return 0
268 | }
269 | return uint(C.SDL_WriteBE64(rwops.cptr(), C.Uint64(value)))
270 | }
271 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/sdl.go:
--------------------------------------------------------------------------------
1 | // Package sdl is SDL2 wrapped for Go users. It enables interoperability between Go and the SDL2 library which is written in C. That means the original SDL2 installation is required for this to work. SDL2 is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.
2 | package sdl
3 |
4 | //#include "sdl_wrapper.h"
5 | import "C"
6 |
7 | import (
8 | "runtime"
9 | )
10 |
11 | // These are the flags which may be passed to SDL_Init().
12 | // (https://wiki.libsdl.org/SDL_Init)
13 | const (
14 | INIT_TIMER = 0x00000001 // timer subsystem
15 | INIT_AUDIO = 0x00000010 // audio subsystem
16 | INIT_VIDEO = 0x00000020 // video subsystem; automatically initializes the events subsystem
17 | INIT_JOYSTICK = 0x00000200 // joystick subsystem; automatically initializes the events subsystem
18 | INIT_HAPTIC = 0x00001000 // haptic (force feedback) subsystem
19 | INIT_GAMECONTROLLER = 0x00002000 // controller subsystem; automatically initializes the joystick subsystem
20 | INIT_EVENTS = 0x00004000 // events subsystem
21 | INIT_NOPARACHUTE = 0x00100000 // compatibility; this flag is ignored
22 |
23 | INIT_EVERYTHING = INIT_TIMER | INIT_AUDIO | INIT_VIDEO | INIT_EVENTS | INIT_JOYSTICK | INIT_HAPTIC | INIT_GAMECONTROLLER // all of the above subsystems
24 | )
25 |
26 | const (
27 | RELEASED = 0
28 | PRESSED = 1
29 | )
30 |
31 | // Calls a function in the main thread. It is only properly initialized inside
32 | // sdl.Main(..). As a default, it panics. It is used by sdl.Do(..) below.
33 | var callInMain = func(f func()) {
34 | panic("sdl.Main(main func()) must be called before sdl.Do(f func())")
35 | }
36 |
37 | func init() {
38 | // Make sure the main goroutine is bound to the main thread.
39 | runtime.LockOSThread()
40 | }
41 |
42 | // Main entry point. Run this function at the beginning of main(), and pass your
43 | // own main body to it as a function. E.g.:
44 | //
45 | // func main() {
46 | // sdl.Main(func() {
47 | // // Your code here....
48 | // // [....]
49 | //
50 | // // Calls to SDL can be made by any goroutine, but always guarded by sdl.Do()
51 | // sdl.Do(func() {
52 | // sdl.Init(0)
53 | // })
54 | // })
55 | // }
56 | //
57 | // Avoid calling functions like os.Exit(..) within your passed-in function since
58 | // they don't respect deferred calls. Instead, do this:
59 | //
60 | // func main() {
61 | // var exitcode int
62 | // sdl.Main(func() {
63 | // exitcode = run()) // assuming run has signature func() int
64 | // })
65 | // os.Exit(exitcode)
66 | // }
67 | func Main(main func()) {
68 | // Queue of functions that are thread-sensitive
69 | callQueue := make(chan func())
70 |
71 | // Properly initialize callInMain for use by sdl.Do(..)
72 | callInMain = func(f func()) {
73 | done := make(chan bool, 1)
74 | callQueue <- func() {
75 | f()
76 | done <- true
77 | }
78 | <-done
79 | }
80 |
81 | go func() {
82 | main()
83 | // fmt.Println("END") // to check if os.Exit(..) is called by main() above
84 | close(callQueue)
85 | }()
86 |
87 | for f := range callQueue {
88 | f()
89 | }
90 | }
91 |
92 | // Do the specified function in the main thread.
93 | // For this function to work, you must have correctly used sdl.Main(..) in your
94 | // main() function. Calling this function before/without sdl.Main(..) will cause
95 | // a panic.
96 | func Do(f func()) {
97 | callInMain(f)
98 | }
99 |
100 | // Init initialize the SDL library. This must be called before using most other SDL functions.
101 | // (https://wiki.libsdl.org/SDL_Init)
102 | func Init(flags uint32) error {
103 | if C.SDL_Init(C.Uint32(flags)) != 0 {
104 | return GetError()
105 | }
106 | return nil
107 | }
108 |
109 | // Quit cleans up all initialized subsystems. You should call it upon all exit conditions.
110 | // (https://wiki.libsdl.org/SDL_Quit)
111 | func Quit() {
112 | C.SDL_Quit()
113 |
114 | eventFilterCache = nil
115 | for k := range eventWatches {
116 | delete(eventWatches, k)
117 | }
118 | }
119 |
120 | // InitSubSystem initializes specific SDL subsystems.
121 | // (https://wiki.libsdl.org/SDL_InitSubSystem)
122 | func InitSubSystem(flags uint32) error {
123 | if C.SDL_InitSubSystem(C.Uint32(flags)) != 0 {
124 | return GetError()
125 | }
126 | return nil
127 | }
128 |
129 | // QuitSubSystem shuts down specific SDL subsystems.
130 | // (https://wiki.libsdl.org/SDL_QuitSubSystem)
131 | func QuitSubSystem(flags uint32) {
132 | C.SDL_QuitSubSystem(C.Uint32(flags))
133 | }
134 |
135 | // WasInit returns a mask of the specified subsystems which have previously been initialized.
136 | // (https://wiki.libsdl.org/SDL_WasInit)
137 | func WasInit(flags uint32) uint32 {
138 | return uint32(C.SDL_WasInit(C.Uint32(flags)))
139 | }
140 |
141 | // GetPlatform returns the name of the platform.
142 | // (https://wiki.libsdl.org/SDL_GetPlatform)
143 | func GetPlatform() string {
144 | return string(C.GoString(C.SDL_GetPlatform()))
145 | }
146 |
147 | // errorFromInt returns GetError() if passed negative value, otherwise it returns nil.
148 | func errorFromInt(code int) error {
149 | if code < 0 {
150 | return GetError()
151 | }
152 | return nil
153 | }
154 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/sdl_cgo.go:
--------------------------------------------------------------------------------
1 | // +build !static
2 |
3 | package sdl
4 |
5 | //#cgo windows LDFLAGS: -lSDL2
6 | //#cgo linux freebsd darwin pkg-config: sdl2
7 | import "C"
8 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/sdl_cgo_static.go:
--------------------------------------------------------------------------------
1 | // +build static
2 |
3 | package sdl
4 |
5 | //#cgo CFLAGS: -I${SRCDIR}/../.go-sdl2-libs/include -I${SRCDIR}/../.go-sdl2-libs/include/SDL2
6 | //#cgo LDFLAGS: -L${SRCDIR}/../.go-sdl2-libs
7 | //#cgo linux,386 LDFLAGS: -lSDL2_linux_386 -Wl,--no-undefined -lm -ldl -lasound -lm -ldl -lpthread -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt
8 | //#cgo linux,amd64 LDFLAGS: -lSDL2_linux_amd64 -Wl,--no-undefined -lm -ldl -lasound -lm -ldl -lpthread -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt
9 | //#cgo windows,386 LDFLAGS: -lSDL2_windows_386 -Wl,--no-undefined -lSDL2main_windows_386 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
10 | //#cgo windows,amd64 LDFLAGS: -lSDL2_windows_amd64 -Wl,--no-undefined -lSDL2main_windows_amd64 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
11 | //#cgo darwin,amd64 LDFLAGS: -lSDL2_darwin_amd64 -lm -liconv -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit
12 | //#cgo android,arm LDFLAGS: -lSDL2_android_arm -Wl,--no-undefined -lm -ldl -llog -landroid -lGLESv2
13 | //#cgo linux,arm LDFLAGS: -lSDL2_linux_arm -Wl,--no-undefined -lm -ldl -liconv
14 | import "C"
15 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/sdl_wrapper.h:
--------------------------------------------------------------------------------
1 | #if defined(_WIN32)
2 | #include
3 | #include
4 | #else
5 | #include
6 | #endif
7 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/surface.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | #if !(SDL_VERSION_ATLEAST(2,0,5))
7 | #pragma message("SDL_CreateRGBSurfaceWithFormat is not supported before SDL 2.0.5")
8 | static inline SDL_Surface* SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
9 | {
10 | return NULL;
11 | }
12 |
13 | #pragma message("SDL_CreateRGBSurfaceWithFormatFrom is not supported before SDL 2.0.5")
14 | static inline SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom(void* pixels, int width, int height, int depth, int pitch, Uint32 format)
15 | {
16 | return NULL;
17 | }
18 | #endif
19 | */
20 | import "C"
21 | import "unsafe"
22 | import "reflect"
23 |
24 | // Surface flags (internal use)
25 | const (
26 | SWSURFACE = C.SDL_SWSURFACE // just here for compatibility
27 | PREALLOC = C.SDL_PREALLOC // surface uses preallocated memory
28 | RLEACCEL = C.SDL_RLEACCEL // surface is RLE encoded
29 | DONTFREE = C.SDL_DONTFREE // surface is referenced internally
30 | )
31 |
32 | // Surface contains a collection of pixels used in software blitting.
33 | // (https://wiki.libsdl.org/SDL_Surface)
34 | type Surface struct {
35 | flags uint32 // (internal use)
36 | Format *PixelFormat // the format of the pixels stored in the surface (read-only) (https://wiki.libsdl.org/SDL_PixelFormat)
37 | W int32 // the width in pixels (read-only)
38 | H int32 // the height in pixels (read-only)
39 | Pitch int32 // the length of a row of pixels in bytes (read-only)
40 | pixels unsafe.Pointer // the pointer to the actual pixel data; use Pixels() for access
41 | UserData unsafe.Pointer // an arbitrary pointer you can set
42 | locked int32 // used for surfaces that require locking (internal use)
43 | lockData unsafe.Pointer // used for surfaces that require locking (internal use)
44 | ClipRect Rect // a Rect structure used to clip blits to the surface which can be set by SetClipRect() (read-only)
45 | _ unsafe.Pointer // map; info for fast blit mapping to other surfaces (internal use)
46 | RefCount int32 // reference count that can be incremented by the application
47 | }
48 | type cSurface C.SDL_Surface
49 |
50 | func (surface *Surface) cptr() *C.SDL_Surface {
51 | return (*C.SDL_Surface)(unsafe.Pointer(surface))
52 | }
53 |
54 | // MustLock reports whether the surface must be locked for access.
55 | // (https://wiki.libsdl.org/SDL_MUSTLOCK)
56 | func (surface *Surface) MustLock() bool {
57 | return (surface.flags & RLEACCEL) != 0
58 | }
59 |
60 | // CreateRGBSurface allocates a new RGB surface.
61 | // (https://wiki.libsdl.org/SDL_CreateRGBSurface)
62 | func CreateRGBSurface(flags uint32, width, height, depth int32, Rmask, Gmask, Bmask, Amask uint32) (*Surface, error) {
63 | surface := (*Surface)(unsafe.Pointer(C.SDL_CreateRGBSurface(
64 | C.Uint32(flags),
65 | C.int(width),
66 | C.int(height),
67 | C.int(depth),
68 | C.Uint32(Rmask),
69 | C.Uint32(Gmask),
70 | C.Uint32(Bmask),
71 | C.Uint32(Amask))))
72 | if surface == nil {
73 | return nil, GetError()
74 | }
75 | return surface, nil
76 | }
77 |
78 | // CreateRGBSurfaceFrom allocate a new RGB surface with existing pixel data.
79 | // (https://wiki.libsdl.org/SDL_CreateRGBSurfaceFrom)
80 | func CreateRGBSurfaceFrom(pixels unsafe.Pointer, width, height int32, depth, pitch int, Rmask, Gmask, Bmask, Amask uint32) (*Surface, error) {
81 | surface := (*Surface)(unsafe.Pointer(C.SDL_CreateRGBSurfaceFrom(
82 | pixels,
83 | C.int(width),
84 | C.int(height),
85 | C.int(depth),
86 | C.int(pitch),
87 | C.Uint32(Rmask),
88 | C.Uint32(Gmask),
89 | C.Uint32(Bmask),
90 | C.Uint32(Amask))))
91 | if surface == nil {
92 | return nil, GetError()
93 | }
94 | return surface, nil
95 | }
96 |
97 | // CreateRGBSurfaceWithFormat allocates an RGB surface.
98 | // (https://wiki.libsdl.org/SDL_CreateRGBSurfaceWithFormat)
99 | func CreateRGBSurfaceWithFormat(flags uint32, width, height, depth int32, format uint32) (*Surface, error) {
100 | surface := (*Surface)(unsafe.Pointer(C.SDL_CreateRGBSurfaceWithFormat(
101 | C.Uint32(flags),
102 | C.int(width),
103 | C.int(height),
104 | C.int(depth),
105 | C.Uint32(format))))
106 | if surface == nil {
107 | return nil, GetError()
108 | }
109 | return surface, nil
110 | }
111 |
112 | // CreateRGBSurfaceWithFormatFrom allocates an RGB surface from provided pixel data.
113 | // (https://wiki.libsdl.org/SDL_CreateRGBSurfaceWithFormatFrom)
114 | func CreateRGBSurfaceWithFormatFrom(pixels unsafe.Pointer, width, height, depth, pitch int32, format uint32) (*Surface, error) {
115 | surface := (*Surface)(unsafe.Pointer(C.SDL_CreateRGBSurfaceWithFormatFrom(
116 | pixels,
117 | C.int(width),
118 | C.int(height),
119 | C.int(depth),
120 | C.int(pitch),
121 | C.Uint32(format))))
122 | if surface == nil {
123 | return nil, GetError()
124 | }
125 | return surface, nil
126 | }
127 |
128 | // Free frees the RGB surface.
129 | // (https://wiki.libsdl.org/SDL_FreeSurface)
130 | func (surface *Surface) Free() {
131 | C.SDL_FreeSurface(surface.cptr())
132 | }
133 |
134 | // SetPalette sets the palette used by the surface.
135 | // (https://wiki.libsdl.org/SDL_SetSurfacePalette)
136 | func (surface *Surface) SetPalette(palette *Palette) error {
137 | if C.SDL_SetSurfacePalette(surface.cptr(), palette.cptr()) != 0 {
138 | return GetError()
139 | }
140 | return nil
141 | }
142 |
143 | // Lock sets up the surface for directly accessing the pixels.
144 | // (https://wiki.libsdl.org/SDL_LockSurface)
145 | func (surface *Surface) Lock() error {
146 | if C.SDL_LockSurface(surface.cptr()) != 0 {
147 | return GetError()
148 | }
149 | return nil
150 | }
151 |
152 | // Unlock releases the surface after directly accessing the pixels.
153 | // (https://wiki.libsdl.org/SDL_UnlockSurface)
154 | func (surface *Surface) Unlock() {
155 | C.SDL_UnlockSurface(surface.cptr())
156 | }
157 |
158 | // LoadBMPRW loads a BMP image from a seekable SDL data stream (memory or file).
159 | // (https://wiki.libsdl.org/SDL_LoadBMP_RW)
160 | func LoadBMPRW(src *RWops, freeSrc bool) (*Surface, error) {
161 | surface := (*Surface)(unsafe.Pointer(C.SDL_LoadBMP_RW(src.cptr(), C.int(Btoi(freeSrc)))))
162 | if surface == nil {
163 | return nil, GetError()
164 | }
165 | return surface, nil
166 | }
167 |
168 | // LoadBMP loads a surface from a BMP file.
169 | // (https://wiki.libsdl.org/SDL_LoadBMP)
170 | func LoadBMP(file string) (*Surface, error) {
171 | return LoadBMPRW(RWFromFile(file, "rb"), true)
172 | }
173 |
174 | // SaveBMPRW save the surface to a seekable SDL data stream (memory or file) in BMP format.
175 | // (https://wiki.libsdl.org/SDL_SaveBMP_RW)
176 | func (surface *Surface) SaveBMPRW(dst *RWops, freeDst bool) error {
177 | if C.SDL_SaveBMP_RW(surface.cptr(), dst.cptr(), C.int(Btoi(freeDst))) != 0 {
178 | return GetError()
179 | }
180 | return nil
181 | }
182 |
183 | // SaveBMP saves the surface to a BMP file.
184 | // (https://wiki.libsdl.org/SDL_SaveBMP)
185 | func (surface *Surface) SaveBMP(file string) error {
186 | return surface.SaveBMPRW(RWFromFile(file, "wb"), true)
187 | }
188 |
189 | // SetRLE sets the RLE acceleration hint for the surface.
190 | // (https://wiki.libsdl.org/SDL_SetSurfaceRLE)
191 | func (surface *Surface) SetRLE(flag bool) error {
192 | if C.SDL_SetSurfaceRLE(surface.cptr(), C.int(Btoi(flag))) != 0 {
193 | return GetError()
194 | }
195 | return nil
196 | }
197 |
198 | // SetColorKey sets the color key (transparent pixel) in the surface.
199 | // (https://wiki.libsdl.org/SDL_SetColorKey)
200 | func (surface *Surface) SetColorKey(flag bool, key uint32) error {
201 | if C.SDL_SetColorKey(surface.cptr(), C.int(Btoi(flag)), C.Uint32(key)) != 0 {
202 | return GetError()
203 | }
204 | return nil
205 | }
206 |
207 | // GetColorKey retruns the color key (transparent pixel) for the surface.
208 | // (https://wiki.libsdl.org/SDL_GetColorKey)
209 | func (surface *Surface) GetColorKey() (key uint32, err error) {
210 | _key := (*C.Uint32)(unsafe.Pointer(&key))
211 | if C.SDL_GetColorKey(surface.cptr(), _key) != 0 {
212 | return key, GetError()
213 | }
214 | return key, nil
215 | }
216 |
217 | // SetColorMod sets an additional color value multiplied into blit operations.
218 | // (https://wiki.libsdl.org/SDL_SetSurfaceColorMod)
219 | func (surface *Surface) SetColorMod(r, g, b uint8) error {
220 | if C.SDL_SetSurfaceColorMod(surface.cptr(), C.Uint8(r), C.Uint8(g), C.Uint8(b)) != 0 {
221 | return GetError()
222 | }
223 | return nil
224 | }
225 |
226 | // GetColorMod returns the additional color value multiplied into blit operations.
227 | // (https://wiki.libsdl.org/SDL_GetSurfaceColorMod)
228 | func (surface *Surface) GetColorMod() (r, g, b uint8, err error) {
229 | _r := (*C.Uint8)(unsafe.Pointer(&r))
230 | _g := (*C.Uint8)(unsafe.Pointer(&g))
231 | _b := (*C.Uint8)(unsafe.Pointer(&b))
232 | if C.SDL_GetSurfaceColorMod(surface.cptr(), _r, _g, _b) != 0 {
233 | return r, g, b, GetError()
234 | }
235 | return r, g, b, nil
236 | }
237 |
238 | // SetAlphaMod sets an additional alpha value used in blit operations.
239 | // (https://wiki.libsdl.org/SDL_SetSurfaceAlphaMod)
240 | func (surface *Surface) SetAlphaMod(alpha uint8) error {
241 | if C.SDL_SetSurfaceAlphaMod(surface.cptr(), C.Uint8(alpha)) != 0 {
242 | return GetError()
243 | }
244 | return nil
245 | }
246 |
247 | // GetAlphaMod returns the additional alpha value used in blit operations.
248 | // (https://wiki.libsdl.org/SDL_GetSurfaceAlphaMod)
249 | func (surface *Surface) GetAlphaMod() (alpha uint8, err error) {
250 | _alpha := (*C.Uint8)(unsafe.Pointer(&alpha))
251 | if C.SDL_GetSurfaceAlphaMod(surface.cptr(), _alpha) != 0 {
252 | return alpha, GetError()
253 | }
254 | return alpha, nil
255 | }
256 |
257 | // SetBlendMode sets the blend mode used for blit operations.
258 | // (https://wiki.libsdl.org/SDL_SetSurfaceBlendMode)
259 | func (surface *Surface) SetBlendMode(bm BlendMode) error {
260 | if C.SDL_SetSurfaceBlendMode(surface.cptr(), bm.c()) != 0 {
261 | return GetError()
262 | }
263 | return nil
264 | }
265 |
266 | // GetBlendMode returns the blend mode used for blit operations.
267 | // (https://wiki.libsdl.org/SDL_GetSurfaceBlendMode)
268 | func (surface *Surface) GetBlendMode() (bm BlendMode, err error) {
269 | if C.SDL_GetSurfaceBlendMode(surface.cptr(), bm.cptr()) != 0 {
270 | return bm, GetError()
271 | }
272 | return bm, nil
273 | }
274 |
275 | // SetClipRect sets the clipping rectangle for the surface
276 | // (https://wiki.libsdl.org/SDL_SetClipRect)
277 | func (surface *Surface) SetClipRect(rect *Rect) bool {
278 | return C.SDL_SetClipRect(surface.cptr(), rect.cptr()) > 0
279 | }
280 |
281 | // GetClipRect returns the clipping rectangle for a surface.
282 | // (https://wiki.libsdl.org/SDL_GetClipRect)
283 | func (surface *Surface) GetClipRect(rect *Rect) {
284 | C.SDL_GetClipRect(surface.cptr(), rect.cptr())
285 | }
286 |
287 | // Convert copies the existing surface into a new one that is optimized for blitting to a surface of a specified pixel format.
288 | // (https://wiki.libsdl.org/SDL_ConvertSurface)
289 | func (surface *Surface) Convert(fmt *PixelFormat, flags uint32) (*Surface, error) {
290 | _surface := (*Surface)(unsafe.Pointer(C.SDL_ConvertSurface(surface.cptr(), fmt.cptr(), C.Uint32(flags))))
291 | if _surface == nil {
292 | return nil, GetError()
293 | }
294 | return _surface, nil
295 | }
296 |
297 | // ConvertFormat copies the existing surface to a new surface of the specified format.
298 | // (https://wiki.libsdl.org/SDL_ConvertSurfaceFormat)
299 | func (surface *Surface) ConvertFormat(pixelFormat uint32, flags uint32) (*Surface, error) {
300 | _surface := (*Surface)(unsafe.Pointer(C.SDL_ConvertSurfaceFormat(surface.cptr(), C.Uint32(pixelFormat), C.Uint32(flags))))
301 | if _surface == nil {
302 | return nil, GetError()
303 | }
304 | return _surface, nil
305 | }
306 |
307 | // ConvertPixels copies a block of pixels of one format to another format.
308 | // (https://wiki.libsdl.org/SDL_ConvertPixels)
309 | func ConvertPixels(width, height int32, srcFormat uint32, src unsafe.Pointer, srcPitch int,
310 | dstFormat uint32, dst unsafe.Pointer, dstPitch int) error {
311 | if C.SDL_ConvertPixels(C.int(width), C.int(height), C.Uint32(srcFormat), src, C.int(srcPitch), C.Uint32(dstFormat), dst, C.int(dstPitch)) != 0 {
312 | return GetError()
313 | }
314 | return nil
315 | }
316 |
317 | // FillRect performs a fast fill of a rectangle with a specific color.
318 | // (https://wiki.libsdl.org/SDL_FillRect)
319 | func (surface *Surface) FillRect(rect *Rect, color uint32) error {
320 | if C.SDL_FillRect(surface.cptr(), rect.cptr(), C.Uint32(color)) != 0 {
321 | return GetError()
322 | }
323 | return nil
324 | }
325 |
326 | // FillRects performs a fast fill of a set of rectangles with a specific color.
327 | // (https://wiki.libsdl.org/SDL_FillRects)
328 | func (surface *Surface) FillRects(rects []Rect, color uint32) error {
329 | if C.SDL_FillRects(surface.cptr(), rects[0].cptr(), C.int(len(rects)), C.Uint32(color)) != 0 {
330 | return GetError()
331 | }
332 | return nil
333 | }
334 |
335 | // Blit performs a fast surface copy to a destination surface.
336 | // (https://wiki.libsdl.org/SDL_BlitSurface)
337 | func (surface *Surface) Blit(srcRect *Rect, dst *Surface, dstRect *Rect) error {
338 | if C.SDL_BlitSurface(surface.cptr(), srcRect.cptr(), dst.cptr(), dstRect.cptr()) != 0 {
339 | return GetError()
340 | }
341 | return nil
342 | }
343 |
344 | // BlitScaled performs a scaled surface copy to a destination surface.
345 | // (https://wiki.libsdl.org/SDL_BlitScaled)
346 | func (surface *Surface) BlitScaled(srcRect *Rect, dst *Surface, dstRect *Rect) error {
347 | if C.SDL_BlitScaled(surface.cptr(), srcRect.cptr(), dst.cptr(), dstRect.cptr()) != 0 {
348 | return GetError()
349 | }
350 | return nil
351 | }
352 |
353 | // UpperBlit has been replaced by Blit().
354 | // (https://wiki.libsdl.org/SDL_UpperBlit)
355 | func (surface *Surface) UpperBlit(srcRect *Rect, dst *Surface, dstRect *Rect) error {
356 | if C.SDL_UpperBlit(surface.cptr(), srcRect.cptr(), dst.cptr(), dstRect.cptr()) != 0 {
357 | return GetError()
358 | }
359 | return nil
360 | }
361 |
362 | // LowerBlit performs low-level surface blitting only.
363 | // (https://wiki.libsdl.org/SDL_LowerBlit)
364 | func (surface *Surface) LowerBlit(srcRect *Rect, dst *Surface, dstRect *Rect) error {
365 | if C.SDL_LowerBlit(surface.cptr(), srcRect.cptr(), dst.cptr(), dstRect.cptr()) != 0 {
366 | return GetError()
367 | }
368 | return nil
369 | }
370 |
371 | // SoftStretch has been replaced by BlitScaled().
372 | // (https://wiki.libsdl.org/SDL_SoftStretch)
373 | func (surface *Surface) SoftStretch(srcRect *Rect, dst *Surface, dstRect *Rect) error {
374 | if C.SDL_SoftStretch(surface.cptr(), srcRect.cptr(), dst.cptr(), dstRect.cptr()) != 0 {
375 | return GetError()
376 | }
377 | return nil
378 | }
379 |
380 | // UpperBlitScaled has been replaced by BlitScaled().
381 | // (https://wiki.libsdl.org/SDL_UpperBlitScaled)
382 | func (surface *Surface) UpperBlitScaled(srcRect *Rect, dst *Surface, dstRect *Rect) error {
383 | if C.SDL_UpperBlitScaled(surface.cptr(), srcRect.cptr(), dst.cptr(), dstRect.cptr()) != 0 {
384 | return GetError()
385 | }
386 | return nil
387 | }
388 |
389 | // LowerBlitScaled performs low-level surface scaled blitting only.
390 | // (https://wiki.libsdl.org/SDL_LowerBlitScaled)
391 | func (surface *Surface) LowerBlitScaled(srcRect *Rect, dst *Surface, dstRect *Rect) error {
392 | if C.SDL_LowerBlitScaled(surface.cptr(), srcRect.cptr(), dst.cptr(), dstRect.cptr()) != 0 {
393 | return GetError()
394 | }
395 | return nil
396 | }
397 |
398 | // PixelNum returns the number of pixels stored in the surface.
399 | func (surface *Surface) PixelNum() int {
400 | return int(surface.W * surface.H)
401 | }
402 |
403 | // BytesPerPixel return the number of significant bits in a pixel values of the surface.
404 | func (surface *Surface) BytesPerPixel() int {
405 | return int(surface.Format.BytesPerPixel)
406 | }
407 |
408 | // Pixels returns the actual pixel data of the surface.
409 | func (surface *Surface) Pixels() []byte {
410 | var b []byte
411 | length := int(surface.W*surface.H) * int(surface.Format.BytesPerPixel)
412 | sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
413 | sliceHeader.Cap = int(length)
414 | sliceHeader.Len = int(length)
415 | sliceHeader.Data = uintptr(surface.pixels)
416 | return b
417 | }
418 |
419 | // Data returns the pointer to the actual pixel data of the surface.
420 | func (surface *Surface) Data() unsafe.Pointer {
421 | return surface.pixels
422 | }
423 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/sysrender.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // Texture contains an efficient, driver-specific representation of pixel data.
8 | // (https://wiki.libsdl.org/SDL_Texture)
9 | type Texture C.SDL_Texture
10 |
11 | // Renderer contains a rendering state.
12 | // (https://wiki.libsdl.org/SDL_Renderer)
13 | type Renderer C.SDL_Renderer
14 |
15 | func (t *Texture) cptr() *C.SDL_Texture {
16 | return (*C.SDL_Texture)(unsafe.Pointer(t))
17 | }
18 |
19 | func (r *Renderer) cptr() *C.SDL_Renderer {
20 | return (*C.SDL_Renderer)(unsafe.Pointer(r))
21 | }
22 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/system_android.go:
--------------------------------------------------------------------------------
1 | // +build go1.4
2 |
3 | package sdl
4 |
5 | // #include "sdl_wrapper.h"
6 | import "C"
7 | import "unsafe"
8 |
9 | // External storage states. See the official Android developer guide for more information.
10 | // (http://developer.android.com/guide/topics/data/data-storage.html)
11 | const (
12 | ANDROID_EXTERNAL_STORAGE_READ = C.SDL_ANDROID_EXTERNAL_STORAGE_READ
13 | ANDROID_EXTERNAL_STORAGE_WRITE = C.SDL_ANDROID_EXTERNAL_STORAGE_WRITE
14 | )
15 |
16 | // AndroidGetInternalStoragePath returns the path used for internal storage for this application.
17 | // (https://wiki.libsdl.org/SDL_AndroidGetInternalStoragePath)
18 | func AndroidGetInternalStoragePath() string {
19 | return C.GoString(C.SDL_AndroidGetInternalStoragePath())
20 | }
21 |
22 | // AndroidGetExternalStoragePath returns the path used for external storage for this application.
23 | // (https://wiki.libsdl.org/SDL_AndroidGetExternalStoragePath)
24 | func AndroidGetExternalStoragePath() string {
25 | return C.GoString(C.SDL_AndroidGetExternalStoragePath())
26 | }
27 |
28 | // AndroidGetExternalStorageState returns the current state of external storage.
29 | // (https://wiki.libsdl.org/SDL_AndroidGetExternalStorageState)
30 | func AndroidGetExternalStorageState() int {
31 | return int(C.SDL_AndroidGetExternalStorageState())
32 | }
33 |
34 | // AndroidGetJNIEnv returns the Java native interface object (JNIEnv) of the current thread on Android builds.
35 | // (https://wiki.libsdl.org/SDL_AndroidGetJNIEnv)
36 | func AndroidGetJNIEnv() unsafe.Pointer {
37 | return unsafe.Pointer(C.SDL_AndroidGetJNIEnv())
38 | }
39 |
40 | // AndroidGetActivity returns the Java instance of the activity class in an Android application.
41 | // (https://wiki.libsdl.org/SDL_AndroidGetActivity)
42 | func AndroidGetActivity() unsafe.Pointer {
43 | return unsafe.Pointer(C.SDL_AndroidGetActivity())
44 | }
45 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/syswm.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | /*
4 | #include "sdl_wrapper.h"
5 |
6 | #if defined(__WIN32)
7 | #include
8 | #else
9 | #include
10 | #endif
11 |
12 | #if !(SDL_VERSION_ATLEAST(2,0,2))
13 | #define SDL_SYSWM_WAYLAND SDL_SYSWM_UNKNOWN
14 | #define SDL_SYSWM_MIR SDL_SYSWM_UNKNOWN
15 | #endif
16 |
17 | #if !(SDL_VERSION_ATLEAST(2,0,3))
18 | #pragma message("SDL_SYSWM_WINRT is not supported before SDL 2.0.3")
19 | #define SDL_SYSWM_WINRT (0)
20 | #endif
21 |
22 | #if !(SDL_VERSION_ATLEAST(2,0,4))
23 | #pragma message("SDL_SYSWM_ANDROID is not supported before SDL 2.0.4")
24 | #define SDL_SYSWM_ANDROID (0)
25 | #endif
26 |
27 | #if !(SDL_VERSION_ATLEAST(2,0,5))
28 | #pragma message("SDL_SYSWM_VIVANTE is not supported before SDL 2.0.5")
29 | #define SDL_SYSWM_VIVANTE (0)
30 | #endif
31 | */
32 | import "C"
33 | import "unsafe"
34 |
35 | // Various supported windowing subsystems.
36 | const (
37 | SYSWM_UNKNOWN = C.SDL_SYSWM_UNKNOWN
38 | SYSWM_WINDOWS = C.SDL_SYSWM_WINDOWS // Microsoft Windows
39 | SYSWM_X11 = C.SDL_SYSWM_X11 // X Window System
40 | SYSWM_DIRECTFB = C.SDL_SYSWM_DIRECTFB // DirectFB
41 | SYSWM_COCOA = C.SDL_SYSWM_COCOA // Apple Mac OS X
42 | SYSWM_UIKIT = C.SDL_SYSWM_UIKIT // Apple iOS
43 | SYSWM_WAYLAND = C.SDL_SYSWM_WAYLAND // Wayland (>= SDL 2.0.2)
44 | SYSWM_MIR = C.SDL_SYSWM_MIR // Mir (>= SDL 2.0.2)
45 | SYSWM_WINRT = C.SDL_SYSWM_WINRT // WinRT (>= SDL 2.0.3)
46 | SYSWM_ANDROID = C.SDL_SYSWM_ANDROID // Android (>= SDL 2.0.4)
47 | SYSWM_VIVANTE = C.SDL_SYSWM_VIVANTE // Vivante (>= SDL 2.0.5)
48 | )
49 |
50 | // SysWMInfo contains system-dependent information about a window.
51 | // (https://wiki.libsdl.org/SDL_SysWMinfo)
52 | type SysWMInfo struct {
53 | Version Version // a Version structure that contains the current SDL version
54 | Subsystem uint32 // the windowing system type
55 | dummy [24]byte // unused (to help compilers when no specific system is available)
56 | }
57 |
58 | // WindowsInfo contains Microsoft Windows window information.
59 | type WindowsInfo struct {
60 | Window unsafe.Pointer // the window handle
61 | }
62 |
63 | // X11Info contains X Window System window information.
64 | type X11Info struct {
65 | Display unsafe.Pointer // the X11 display
66 | Window uint // the X11 window
67 | }
68 |
69 | // DFBInfo contains DirectFB window information.
70 | type DFBInfo struct {
71 | Dfb unsafe.Pointer // the DirectFB main interface
72 | Window unsafe.Pointer // the DirectFB window handle
73 | Surface unsafe.Pointer // the DirectFB client surface
74 | }
75 |
76 | // CocoaInfo contains Apple Mac OS X window information.
77 | type CocoaInfo struct {
78 | Window unsafe.Pointer // the Cocoa window
79 | }
80 |
81 | // UIKitInfo contains Apple iOS window information.
82 | type UIKitInfo struct {
83 | Window unsafe.Pointer // the UIKit window
84 | }
85 |
86 | func (info *SysWMInfo) cptr() *C.SDL_SysWMinfo {
87 | return (*C.SDL_SysWMinfo)(unsafe.Pointer(info))
88 | }
89 |
90 | // GetWMInfo returns driver specific information about a window.
91 | // (https://wiki.libsdl.org/SDL_GetWindowWMInfo)
92 | func (window *Window) GetWMInfo() (*SysWMInfo, error) {
93 | var info SysWMInfo
94 | VERSION(&info.Version)
95 | if C.SDL_GetWindowWMInfo(window.cptr(), info.cptr()) == 0 {
96 | return nil, GetError()
97 | }
98 | return &info, nil
99 | }
100 |
101 | // GetWindowsInfo returns Microsoft Windows window information.
102 | func (info *SysWMInfo) GetWindowsInfo() *WindowsInfo {
103 | return (*WindowsInfo)(unsafe.Pointer(&info.dummy[0]))
104 | }
105 |
106 | // GetX11Info returns X Window System window information.
107 | func (info *SysWMInfo) GetX11Info() *X11Info {
108 | return (*X11Info)(unsafe.Pointer(&info.dummy[0]))
109 | }
110 |
111 | // GetDFBInfo returns DirectFB window information.
112 | func (info *SysWMInfo) GetDFBInfo() *DFBInfo {
113 | return (*DFBInfo)(unsafe.Pointer(&info.dummy[0]))
114 | }
115 |
116 | // GetCocoaInfo returns Apple Mac OS X window information.
117 | func (info *SysWMInfo) GetCocoaInfo() *CocoaInfo {
118 | return (*CocoaInfo)(unsafe.Pointer(&info.dummy[0]))
119 | }
120 |
121 | // GetUIKitInfo returns Apple iOS window information.
122 | func (info *SysWMInfo) GetUIKitInfo() *UIKitInfo {
123 | return (*UIKitInfo)(unsafe.Pointer(&info.dummy[0]))
124 | }
125 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/timer.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 |
6 | // GetTicks returns the number of milliseconds since the SDL library initialization.
7 | // (https://wiki.libsdl.org/SDL_GetTicks)
8 | func GetTicks() uint32 {
9 | return uint32(C.SDL_GetTicks())
10 | }
11 |
12 | // GetPerformanceCounter returns the current value of the high resolution counter.
13 | // (https://wiki.libsdl.org/SDL_GetPerformanceCounter)
14 | func GetPerformanceCounter() uint64 {
15 | return uint64(C.SDL_GetPerformanceCounter())
16 | }
17 |
18 | // GetPerformanceFrequency returns the count per second of the high resolution counter.
19 | // (https://wiki.libsdl.org/SDL_GetPerformanceFrequency)
20 | func GetPerformanceFrequency() uint64 {
21 | return uint64(C.SDL_GetPerformanceFrequency())
22 | }
23 |
24 | // Delay waits a specified number of milliseconds before returning.
25 | // (https://wiki.libsdl.org/SDL_Delay)
26 | func Delay(ms uint32) {
27 | C.SDL_Delay(C.Uint32(ms))
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/touch.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // TOUCH_MOUSEID is the device ID for mouse events simulated with touch input
8 | const TOUCH_MOUSEID = C.SDL_TOUCH_MOUSEID
9 |
10 | // TouchID is the ID of a touch device.
11 | type TouchID C.SDL_TouchID
12 |
13 | // FingerID is a finger id.
14 | type FingerID C.SDL_FingerID
15 |
16 | // Finger contains touch information.
17 | type Finger struct {
18 | ID FingerID // the finger id
19 | X float32 // the x-axis location of the touch event, normalized (0...1)
20 | Y float32 // the y-axis location of the touch event, normalized (0...1)
21 | Pressure float32 // the quantity of pressure applied, normalized (0...1)
22 | }
23 |
24 | func (t TouchID) c() C.SDL_TouchID {
25 | return C.SDL_TouchID(t)
26 | }
27 |
28 | // GetNumTouchDevices returns the number of registered touch devices.
29 | // (https://wiki.libsdl.org/SDL_GetNumTouchDevices)
30 | func GetNumTouchDevices() int {
31 | return int(C.SDL_GetNumTouchDevices())
32 | }
33 |
34 | // GetTouchDevice returns the touch ID with the given index.
35 | // (https://wiki.libsdl.org/SDL_GetTouchDevice)
36 | func GetTouchDevice(index int) TouchID {
37 | return TouchID(C.SDL_GetTouchDevice(C.int(index)))
38 | }
39 |
40 | // GetNumTouchFingers returns the number of active fingers for a given touch device.
41 | // (https://wiki.libsdl.org/SDL_GetNumTouchFingers)
42 | func GetNumTouchFingers(t TouchID) int {
43 | return int(C.SDL_GetNumTouchFingers(t.c()))
44 | }
45 |
46 | // GetTouchFinger returns the finger object for specified touch device ID and finger index.
47 | // (https://wiki.libsdl.org/SDL_GetTouchFinger)
48 | func GetTouchFinger(t TouchID, index int) *Finger {
49 | return (*Finger)(unsafe.Pointer(C.SDL_GetTouchFinger(t.c(), C.int(index))))
50 | }
51 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/sdl/version.go:
--------------------------------------------------------------------------------
1 | package sdl
2 |
3 | // #include "sdl_wrapper.h"
4 | import "C"
5 | import "unsafe"
6 |
7 | // The version of SDL in use.
8 | const (
9 | MAJOR_VERSION = C.SDL_MAJOR_VERSION // major version
10 | MINOR_VERSION = C.SDL_MINOR_VERSION // minor version
11 | PATCHLEVEL = C.SDL_PATCHLEVEL // update version (patchlevel)
12 | )
13 |
14 | // Version contains information about the version of SDL in use.
15 | // (https://wiki.libsdl.org/SDL_version)
16 | type Version struct {
17 | Major uint8 // major version
18 | Minor uint8 // minor version
19 | Patch uint8 // update version (patchlevel)
20 | }
21 | type cVersion C.SDL_version
22 |
23 | func (v *Version) cptr() *C.SDL_version {
24 | return (*C.SDL_version)(unsafe.Pointer(v))
25 | }
26 |
27 | // VERSION fills the selected struct with the version of SDL in use.
28 | // (https://wiki.libsdl.org/SDL_VERSION)
29 | func VERSION(v *Version) {
30 | v.Major = MAJOR_VERSION
31 | v.Minor = MINOR_VERSION
32 | v.Patch = PATCHLEVEL
33 | }
34 |
35 | // VERSIONNUM converts separate version components into a single numeric value.
36 | // (https://wiki.libsdl.org/SDL_VERSIONNUM)
37 | func VERSIONNUM(x, y, z int) int {
38 | return (x*1000 + y*100 + z)
39 | }
40 |
41 | // COMPILEDVERSION returns the SDL version number that you compiled against.
42 | // (https://wiki.libsdl.org/SDL_COMPILEDVERSION)
43 | func COMPILEDVERSION() int {
44 | return VERSIONNUM(MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL)
45 | }
46 |
47 | // VERSION_ATLEAST reports whether the SDL version compiled against is at least as new as the specified version.
48 | // (https://wiki.libsdl.org/SDL_VERSION_ATLEAST)
49 | func VERSION_ATLEAST(x, y, z int) bool {
50 | return COMPILEDVERSION() >= VERSIONNUM(x, y, z)
51 | }
52 |
53 | // GetVersion returns the version of SDL that is linked against your program.
54 | // (https://wiki.libsdl.org/SDL_GetVersion)
55 | func GetVersion(v *Version) {
56 | C.SDL_GetVersion(v.cptr())
57 | }
58 |
59 | // GetRevision returns the code revision of SDL that is linked against your program.
60 | // (https://wiki.libsdl.org/SDL_GetRevision)
61 | func GetRevision() string {
62 | return (string)(C.GoString(C.SDL_GetRevision()))
63 | }
64 |
65 | // GetRevisionNumber returns the revision number of SDL that is linked against your program.
66 | // (https://wiki.libsdl.org/SDL_GetRevisionNumber)
67 | func GetRevisionNumber() int {
68 | return (int)(C.SDL_GetRevisionNumber())
69 | }
70 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/ttf/sdl_ttf.go:
--------------------------------------------------------------------------------
1 | // Package ttf is a TrueType font rendering library that is used with the SDL library, and almost as portable. It depends on freetype2 to handle the TrueType font data. It allows a programmer to use multiple TrueType fonts without having to code a font rendering routine themselves. With the power of outline fonts and antialiasing, high quality text output can be obtained without much effort.
2 | package ttf
3 |
4 | //#include
5 | //#include "sdl_ttf_wrapper.h"
6 | //void Do_TTF_SetError(const char *str) {
7 | // TTF_SetError("%s", str);
8 | //}
9 | import "C"
10 | import "github.com/veandco/go-sdl2/sdl"
11 | import "unsafe"
12 | import "errors"
13 |
14 | // Hinting settings.
15 | const (
16 | HINTING_NORMAL = int(C.TTF_HINTING_NORMAL)
17 | HINTING_LIGHT = int(C.TTF_HINTING_LIGHT)
18 | HINTING_MONO = int(C.TTF_HINTING_MONO)
19 | HINTING_NONE = int(C.TTF_HINTING_NONE)
20 | )
21 |
22 | // Font rendering styles.
23 | const (
24 | STYLE_NORMAL = 0
25 | STYLE_BOLD = 0x01
26 | STYLE_ITALIC = 0x02
27 | STYLE_UNDERLINE = 0x04
28 | STYLE_STRIKETHROUGH = 0x08
29 | )
30 |
31 | // Font contains font information.
32 | type Font struct {
33 | f *C.TTF_Font
34 | }
35 |
36 | // Init initializes the truetype font API. This must be called before using other functions in this library, except ttf.WasInit(). SDL does not have to be initialized before this call.
37 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_8.html)
38 | func Init() error {
39 | if C.TTF_Init() == -1 {
40 | return GetError()
41 | }
42 | return nil
43 | }
44 |
45 | // WasInit reports whether the truetype font API is initialized. Use this before ttf.Init() to avoid initializing twice in a row. Or use this to determine if you need to call ttf.Quit().
46 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_9.html)
47 | func WasInit() bool {
48 | return int(C.TTF_WasInit()) != 0
49 | }
50 |
51 | // Quit shuts down and cleanups the truetype font API. After calling this the SDL_ttf functions should not be used, excepting ttf.WasInit(). You may, of course, use ttf.Init() to use the functionality again.
52 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_10.html)
53 | func Quit() {
54 | C.TTF_Quit()
55 | }
56 |
57 | // GetError returns the last error that occurred, or an empty string if there hasn't been an error message set since the last call to sdl.ClearError().
58 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_12.html)
59 | func GetError() error {
60 | e := C.TTF_GetError()
61 | if e == nil {
62 | return nil
63 | }
64 | return errors.New(C.GoString(e))
65 | }
66 |
67 | // SetError sets the SDL error message to the specified string.
68 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_11.html)
69 | func SetError(err string) {
70 | _err := C.CString(err)
71 | defer C.free(unsafe.Pointer(_err))
72 | C.Do_TTF_SetError(_err)
73 | }
74 |
75 | // ByteSwappedUnicode tells SDL_ttf whether UNICODE (Uint16 per character) text is generally byteswapped.
76 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_20.html)
77 | func ByteSwappedUnicode(swap bool) {
78 | val := 0
79 | if swap {
80 | val = 1
81 | }
82 | C.TTF_ByteSwappedUNICODE(C.int(val))
83 | }
84 |
85 | // OpenFont loads file for use as a font, at the specified size. This is actually OpenFontIndex(file, size, 0). This can load TTF and FON files.
86 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_14.html)
87 | func OpenFont(file string, size int) (*Font, error) {
88 | _file := C.CString(file)
89 | defer C.free(unsafe.Pointer(_file))
90 | _size := (C.int)(size)
91 | f := (*C.TTF_Font)(C.TTF_OpenFont(_file, _size))
92 |
93 | if f == nil {
94 | return nil, GetError()
95 | }
96 | return &Font{f}, nil
97 | }
98 |
99 | // OpenFontIndex loads file, face index, for use as a font, at the specified size. This is actually OpenFontIndexRW(RWFromFile(file), size, index), but checks that the RWops it creates is not NULL. This can load TTF and FON files.
100 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_16.html)
101 | func OpenFontIndex(file string, size int, index int) (*Font, error) {
102 | _file := C.CString(file)
103 | defer C.free(unsafe.Pointer(_file))
104 | _size := (C.int)(size)
105 | _index := (C.long)(index)
106 | f := (*C.TTF_Font)(C.TTF_OpenFontIndex(_file, _size, _index))
107 |
108 | if f == nil {
109 | return nil, GetError()
110 | }
111 | return &Font{f}, nil
112 | }
113 |
114 | // OpenFontRW loads src for use as a font, at specified size. This is actually OpenFontIndexRW(src, freesrc, size, 0). This can load TTF and FON formats. Using SDL_RWops is not covered here, but they enable you to load from almost any source.
115 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_15.html)
116 | func OpenFontRW(src *sdl.RWops, freesrc, size int) (*Font, error) {
117 | return OpenFontIndexRW(src, freesrc, size, 0)
118 | }
119 |
120 | // OpenFontIndexRW loads src, face index, for use as a font, at the specified size. This can load TTF and FON formats. Using SDL_RWops is not covered here, but they enable you to load from almost any source.
121 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_17.html)
122 | func OpenFontIndexRW(src *sdl.RWops, freesrc, size, index int) (*Font, error) {
123 | _src := (*C.SDL_RWops)(unsafe.Pointer(src))
124 | _freesrc := (C.int)(freesrc)
125 | _size := (C.int)(size)
126 | _index := (C.long)(index)
127 | f := (*C.TTF_Font)(C.TTF_OpenFontIndexRW(_src, _freesrc, _size, _index))
128 |
129 | if f == nil {
130 | return nil, GetError()
131 | }
132 | return &Font{f}, nil
133 | }
134 |
135 | // RenderUTF8Solid creates an 8-bit palettized surface and render the given text at fast quality with the given font and color. The 0 pixel is the colorkey, giving a transparent background, and the 1 pixel is set to the text color.
136 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_44.html)
137 | func (f *Font) RenderUTF8Solid(text string, color sdl.Color) (*sdl.Surface, error) {
138 | _text := C.CString(text)
139 | defer C.free(unsafe.Pointer(_text))
140 | _c := C.SDL_Color{C.Uint8(color.R), C.Uint8(color.G), C.Uint8(color.B), C.Uint8(color.A)}
141 | surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Solid(f.f, _text, _c)))
142 | if surface == nil {
143 | return nil, GetError()
144 | }
145 | return surface, nil
146 | }
147 |
148 | // RenderUTF8Shaded creates an 8-bit palettized surface and render the given text at high quality with the given font and colors. The 0 pixel is background, while other pixels have varying degrees of the foreground color.
149 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_48.html)
150 | func (f *Font) RenderUTF8Shaded(text string, fg, bg sdl.Color) (*sdl.Surface, error) {
151 | _text := C.CString(text)
152 | defer C.free(unsafe.Pointer(_text))
153 | _fg := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)}
154 | _bg := C.SDL_Color{C.Uint8(bg.R), C.Uint8(bg.G), C.Uint8(bg.B), C.Uint8(bg.A)}
155 | surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Shaded(f.f, _text, _fg, _bg)))
156 | if surface == nil {
157 | return nil, GetError()
158 | }
159 | return surface, nil
160 | }
161 |
162 | // RenderUTF8Blended creates a 32-bit ARGB surface and render the given text at high quality, using alpha blending to dither the font with the given color.
163 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_52.html)
164 | func (f *Font) RenderUTF8Blended(text string, color sdl.Color) (*sdl.Surface, error) {
165 | _text := C.CString(text)
166 | defer C.free(unsafe.Pointer(_text))
167 | _c := C.SDL_Color{C.Uint8(color.R), C.Uint8(color.G), C.Uint8(color.B), C.Uint8(color.A)}
168 | surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Blended(f.f, _text, _c)))
169 | if surface == nil {
170 | return nil, GetError()
171 | }
172 | return surface, nil
173 | }
174 |
175 | // RenderUTF8BlendedWrapped creates a 32-bit ARGB surface and render the given text at high quality, using alpha blending to dither the font with the given color. Text is wrapped to multiple lines on line endings and on word boundaries if it extends beyond wrapLength in pixels.
176 | func (f *Font) RenderUTF8BlendedWrapped(text string, fg sdl.Color, wrapLength int) (*sdl.Surface, error) {
177 | _text := C.CString(text)
178 | defer C.free(unsafe.Pointer(_text))
179 | _c := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)}
180 | surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Blended_Wrapped(f.f, _text, _c, C.Uint32(wrapLength))))
181 | if surface == nil {
182 | return nil, GetError()
183 | }
184 | return surface, nil
185 | }
186 |
187 | // SizeUTF8 returns the resulting surface size (width and height) of the UTF8 encoded text rendered using font. No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using ttf.Height().
188 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_40.html)
189 | func (f *Font) SizeUTF8(text string) (int, int, error) {
190 | _text := C.CString(text)
191 | defer C.free(unsafe.Pointer(_text))
192 | var w C.int
193 | var h C.int
194 | result := C.TTF_SizeUTF8(f.f, _text, &w, &h)
195 | if result == 0 {
196 | return int(w), int(h), nil
197 | }
198 | return int(w), int(h), GetError()
199 | }
200 |
201 | // Close frees the memory used by font, and frees font itself as well. Do not use font after this without loading a new font to it.
202 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_18.html)
203 | func (f *Font) Close() {
204 | C.TTF_CloseFont(f.f)
205 | f.f = nil
206 | }
207 |
208 | // Height returns the maximum pixel height of all glyphs of the loaded font.
209 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_29.html)
210 | func (f *Font) Height() int { return int(C.TTF_FontHeight(f.f)) }
211 |
212 | // Ascent returns the maximum pixel ascent of all glyphs of the loaded font. This can also be interpreted as the distance from the top of the font to the baseline.
213 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_30.html)
214 | func (f *Font) Ascent() int { return int(C.TTF_FontAscent(f.f)) }
215 |
216 | // Descent returns the maximum pixel descent of all glyphs of the loaded font. This can also be interpreted as the distance from the baseline to the bottom of the font.
217 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_31.html)
218 | func (f *Font) Descent() int { return int(C.TTF_FontDescent(f.f)) }
219 |
220 | // LineSkip returns the recommended pixel height of a rendered line of text of the loaded font.
221 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_32.html)
222 | func (f *Font) LineSkip() int { return int(C.TTF_FontLineSkip(f.f)) }
223 |
224 | // Faces returns the number of faces ("sub-fonts") available in the loaded font.
225 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_33.html)
226 | func (f *Font) Faces() int { return int(C.TTF_FontFaces(f.f)) }
227 |
228 | // GetStyle returns the rendering style of the loaded font.
229 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_21.html)
230 | func (f *Font) GetStyle() int {
231 | return int(C.TTF_GetFontStyle(f.f))
232 | }
233 |
234 | // SetStyle sets the rendering style of the loaded font.
235 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_22.html)
236 | func (f *Font) SetStyle(style int) {
237 | C.TTF_SetFontStyle(f.f, C.int(style))
238 | }
239 |
240 | // GetHinting returns the current hinting setting of the loaded font.
241 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_25.html)
242 | func (f *Font) GetHinting() int {
243 | return int(C.TTF_GetFontHinting(f.f))
244 | }
245 |
246 | // SetHinting sets the hinting of the loaded font.
247 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_26.html)
248 | func (f *Font) SetHinting(hinting int) {
249 | C.TTF_SetFontHinting(f.f, C.int(hinting))
250 | }
251 |
252 | // GetKerning returns the current kerning setting of the loaded font.
253 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_27.html)
254 | func (f *Font) GetKerning() bool {
255 | return int(C.TTF_GetFontKerning(f.f)) == 1
256 | }
257 |
258 | // SetKerning sets whther to use kerning when rendering the loaded font. This has no effect on individual glyphs, but rather when rendering whole strings of characters, at least a word at a time. Perhaps the only time to disable this is when kerning is not working for a specific font, resulting in overlapping glyphs or abnormal spacing within words.
259 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_28.html)
260 | func (f *Font) SetKerning(allowed bool) {
261 | val := 0
262 | if allowed {
263 | val = 1
264 | }
265 | C.TTF_SetFontKerning(f.f, C.int(val))
266 | }
267 |
268 | // GetOutline returns the current outline size of the loaded font.
269 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_23.html)
270 | func (f *Font) GetOutline() int {
271 | return int(C.TTF_GetFontOutline(f.f))
272 | }
273 |
274 | // SetOutline sets the outline pixel width of the loaded font.
275 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_24.html)
276 | func (f *Font) SetOutline(outline int) {
277 | C.TTF_SetFontOutline(f.f, C.int(outline))
278 | }
279 |
280 | // FaceIsFixedWidth reports whether the current font face of the loaded font is a fixed width font. Fixed width fonts are monospace, meaning every character that exists in the font is the same width, thus you can assume that a rendered string's width is going to be the result of a simple calculation: glyph_width * string_length.
281 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_34.html)
282 | func (f *Font) FaceIsFixedWidth() bool {
283 | return int(C.TTF_FontFaceIsFixedWidth(f.f)) != 0
284 | }
285 |
286 | // FaceFamilyName returns the current font face family name from the loaded font.
287 | // (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_35.html)
288 | func (f *Font) FaceFamilyName() string {
289 | _fname := C.TTF_FontFaceFamilyName(f.f)
290 | fname := C.GoString(_fname)
291 | return fname
292 | }
293 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/ttf/sdl_ttf_cgo.go:
--------------------------------------------------------------------------------
1 | // +build !static
2 |
3 | package ttf
4 |
5 | //#cgo windows LDFLAGS: -lSDL2 -lSDL2_ttf
6 | //#cgo linux freebsd darwin pkg-config: sdl2
7 | //#cgo linux freebsd darwin LDFLAGS: -lSDL2_ttf
8 | import "C"
9 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/ttf/sdl_ttf_cgo_static.go:
--------------------------------------------------------------------------------
1 | // +build static
2 |
3 | package ttf
4 |
5 | //#cgo CFLAGS: -I${SRCDIR}/../.go-sdl2-libs/include -I${SRCDIR}/../.go-sdl2-libs/include/SDL2
6 | //#cgo LDFLAGS: -L${SRCDIR}/../.go-sdl2-libs
7 | //#cgo linux,386 LDFLAGS: -lSDL2_ttf_linux_386 -Wl,--no-undefined -lfreetype_linux_386 -lSDL2_linux_386 -lm -ldl -lasound -lm -ldl -lpthread -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt
8 | //#cgo linux,amd64 LDFLAGS: -lSDL2_ttf_linux_amd64 -Wl,--no-undefined -lfreetype_linux_amd64 -lSDL2_linux_amd64 -lm -ldl -lasound -lm -ldl -lpthread -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt
9 | //#cgo windows,386 LDFLAGS: -lSDL2_ttf_windows_386 -Wl,--no-undefined -lfreetype_windows_386 -lSDL2_windows_386 -lSDL2main_windows_386 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
10 | //#cgo windows,amd64 LDFLAGS: -lSDL2_ttf_windows_amd64 -Wl,--no-undefined -lfreetype_windows_amd64 -lSDL2_windows_amd64 -lSDL2main_windows_amd64 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
11 | //#cgo darwin,amd64 LDFLAGS: -lSDL2_ttf_darwin_amd64 -lm -liconv -lfreetype_darwin_amd64 -lSDL2_darwin_amd64 -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit
12 | //#cgo android,arm LDFLAGS: -lSDL2_ttf_android_arm -Wl,--no-undefined -lfreetype_android_arm -lSDL2_android_arm -lm -ldl -llog -landroid -lGLESv2
13 | //#cgo linux,arm LDFLAGS: -lSDL2_ttf_linux_arm -Wl,--no-undefined -lfreetype_linux_arm -lSDL2_linux_arm -lm -ldl -liconv
14 | import "C"
15 |
--------------------------------------------------------------------------------
/vendor/github.com/veandco/go-sdl2/ttf/sdl_ttf_wrapper.h:
--------------------------------------------------------------------------------
1 | #if defined(__WIN32)
2 | #include
3 | #include
4 | #else
5 | #include
6 | #endif
7 |
--------------------------------------------------------------------------------
/vendor/modules.txt:
--------------------------------------------------------------------------------
1 | # github.com/veandco/go-sdl2 v0.3.0
2 | github.com/veandco/go-sdl2/img
3 | github.com/veandco/go-sdl2/sdl
4 | github.com/veandco/go-sdl2/ttf
5 |
--------------------------------------------------------------------------------