Debian Codegraph @

app/internal/testapp/testapp.go

raw symbols SCIP
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build darwin || linux
6
7 // Small test app used by app/app_test.go.
8 package mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/testapp`/
9
10 import (
11 "logscip-go gomod github.com/golang/go/src go1.24.0 log/"
12 "netscip-go gomod github.com/golang/go/src go1.24.0 net/"
13
14 "golang.org/x/mobile/appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/"
15 "golang.org/x/mobile/app/internal/apptestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/"
16 "golang.org/x/mobile/event/lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/"
17 "golang.org/x/mobile/event/paintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/"
18 "golang.org/x/mobile/event/sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/"
19 "golang.org/x/mobile/event/touchscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/"
20 "golang.org/x/mobile/glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/"
21 )
22
23 func mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/testapp`/main().() {
24 appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/.Mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/Main().(func(a appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/.Appscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#) {
25 var (
26 glctx glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#
27 visible bool
28 )
29
30 addr := "127.0.0.1:" + apptestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/.Portscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Port.
31 logscip-go gomod github.com/golang/go/src go1.24.0 log/.Printfscip-go gomod github.com/golang/go/src go1.24.0 log/Printf().("addr: %s", addr)
32
33 conn, err := netscip-go gomod github.com/golang/go/src go1.24.0 net/.Dialscip-go gomod github.com/golang/go/src go1.24.0 net/Dial().("tcp", addr)
34 if err != nil {
35 logscip-go gomod github.com/golang/go/src go1.24.0 log/.Fatalscip-go gomod github.com/golang/go/src go1.24.0 log/Fatal().(err)
36 }
37 defer conn.Closescip-go gomod github.com/golang/go/src go1.24.0 net/Conn#Close().()
38 logscip-go gomod github.com/golang/go/src go1.24.0 log/.Printfscip-go gomod github.com/golang/go/src go1.24.0 log/Printf().("dialled")
39 comm := &apptestscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/.Commscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#{
40 Connscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Conn.: conn,
41 Fatalfscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Fatalf.: logscip-go gomod github.com/golang/go/src go1.24.0 log/.Panicfscip-go gomod github.com/golang/go/src go1.24.0 log/Panicf().,
42 Printfscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Printf.: logscip-go gomod github.com/golang/go/src go1.24.0 log/.Printfscip-go gomod github.com/golang/go/src go1.24.0 log/Printf().,
43 }
44
45 comm.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Send().("hello_from_testapp")
46 comm.Recvscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Recv().("hello_from_host")
47
48 color := "red"
49 sendPainting := false
50 for e := range a.Eventsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Events.() {
51 switch e := a.Filterscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Filter.(e).(type) {
52 case lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/Event#:
53 switch e.Crossesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/Event#Crosses().(lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.StageVisiblescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/StageVisible.) {
54 case lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.CrossOnscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/CrossOn.:
55 comm.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Send().("lifecycle_visible")
56 sendPainting = true
57 visible = true
58 glctx, _ = e.DrawContextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/Event#DrawContext..(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#)
59 case lifecyclescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/.CrossOffscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/lifecycle`/CrossOff.:
60 comm.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Send().("lifecycle_not_visible")
61 visible = false
62 }
63 case sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#:
64 comm.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Send().("size", e.PixelsPerPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#PixelsPerPt., e.Orientationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#Orientation.)
65 case paintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/Event#:
66 if visible {
67 if color == "red" {
68 glctx.ClearColorscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#ClearColor.(1, 0, 0, 1)
69 } else {
70 glctx.ClearColorscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#ClearColor.(0, 1, 0, 1)
71 }
72 glctx.Clearscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#Clear.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.COLOR_BUFFER_BITscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/COLOR_BUFFER_BIT.)
73 a.Publishscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Publish.()
74 }
75 if sendPainting {
76 comm.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Send().("paint", color)
77 sendPainting = false
78 }
79 case touchscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#:
80 comm.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app/internal/apptest`/Comm#Send().("touch", e.Typescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#Type., e.Xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#X., e.Yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#Y.)
81 if e.Typescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/Event#Type. == touchscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/.TypeEndscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/touch`/TypeEnd. {
82 if color == "red" {
83 color = "green"
84 } else {
85 color = "red"
86 }
87 sendPainting = true
88 // Send a paint event so the screen gets redrawn.
89 a.Sendscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/app`/App#Send.(paintscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/paint`/Event#{})
90 }
91 }
92 }
93 })
94 }