-
Notifications
You must be signed in to change notification settings - Fork 2
/
screen_titleScreen.go
70 lines (57 loc) · 2 KB
/
screen_titleScreen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"github.com/ably-labs/Ableye/button"
colour "github.com/ably-labs/Ableye/colours"
"github.com/ably-labs/Ableye/config"
font "github.com/ably-labs/Ableye/fonts"
"github.com/ably-labs/Ableye/text"
_ "image/png"
"log"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
// The elements of the title screen.
var (
title text.Text
tagline text.Text
sdkVersion text.Text
realtimeButton button.Button
ablyLogo *ebiten.Image
)
func initialiseTitleScreen() {
title = text.NewText(titleText, colour.White, font.MplusLargeFont, (screenWidth/2)-115, screenHeight/2)
tagline = text.NewText(taglineText, colour.White, font.MplusNormalFont, (screenWidth/2)-200, (screenHeight/2)+75)
sdkVersion = text.NewText(fmt.Sprintf("SDK version : ably-go %s", config.Cfg.AblyGoSDKVersion), colour.White, font.MplusSmallFont, (screenWidth/2)-100, (screenHeight/2)+125)
realtimeButton = button.NewButton(320, 100, realtimeText, 35, 55, colour.White, font.MplusNormalFont, colour.BrightRed, (screenWidth/2)-155, (screenHeight/2)+200)
// initialise images from image files.
var err error
ablyLogo, _, err = ebitenutil.NewImageFromFile("./images/Ably.png")
if err != nil {
log.Println(err)
}
}
func drawTitleScreen(screen *ebiten.Image) {
//Draw images.
opts := &ebiten.DrawImageOptions{}
opts.GeoM.Translate(float64(screenWidth/2-350), float64(screenHeight/2)-315)
screen.DrawImage(ablyLogo, opts)
//Draw elements.
title.Draw(screen)
tagline.Draw(screen)
sdkVersion.Draw(screen)
realtimeButton.Draw(screen)
}
func updateTitleScreen() {
if realtimeButton.IsMouseOver() {
realtimeButton.SetBgColour(colour.JazzyPink)
ebiten.SetCursorShape(ebiten.CursorShapePointer)
} else {
realtimeButton.SetBgColour(colour.BrightRed)
ebiten.SetCursorShape(ebiten.CursorShapeDefault)
}
// Handle mouse click on realtime button
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) && realtimeButton.IsMouseOver() {
state = clientScreen
}
}