1package ui
2
3import (
4 "fmt"
5 "uidev/phnparser"
6 "uidev/renderer"
7)
8
9var BuildVersion string
10
11var DisplayedMenu = 0 // 0 - Boot ; 1 - Book Select ; 2 - Book reading
12var UISelectionIndex = 0
13var TopBarTitle string
14
15var UIMargin int
16var UITopBarHeight int
17var UILineHeight int
18var UIFontHorizontalSpacing int
19
20var UIMaxBookLines int
21
22var UIFrameCount = 0
23
24func RenderUI() {
25 renderer.PerformanceTrackerStart()
26 renderer.BlankScreen(0)
27 switch DisplayedMenu {
28 case 0:
29 renderer.DrawPihonLogo()
30 renderer.AddTextAllDisplays(UIMargin, renderer.ScreenHeight-UILineHeight-UIMargin+1, 1, BuildVersion)
31 case 1:
32 DrawTopBar(UIMargin, UITopBarHeight)
33 // Book Info
34 // Title
35 renderer.AddTextAllDisplays(UIMargin, UIMargin*2+UITopBarHeight, 1, phnparser.LibraryTitles[UISelectionIndex])
36 // Author
37 renderer.AddTextAllDisplays(UIMargin, UIMargin*3+UILineHeight+UITopBarHeight, 1, phnparser.LibraryAuthors[UISelectionIndex])
38 // Format / Size
39 renderer.AddTextAllDisplays(UIMargin, renderer.ScreenHeight-UILineHeight-UIMargin+1, 1, phnparser.LibraryFormats[UISelectionIndex]+" "+fmt.Sprintf("%.2fMB", float64(phnparser.LibraryFileSizes[UISelectionIndex])/float64(1024*1024)))
40 // Hash
41 renderer.AddTextAllDisplays(UIMargin, renderer.ScreenHeight-2*UILineHeight-2*UIMargin+1, 1, phnparser.LibraryHashes[UISelectionIndex][:phnparser.MaxLengthOfLine])
42 // Reading progress
43 //renderer.AddTextAllDisplays(renderer.ScreenWidth*renderer.ScreenCount-len("1/123")*UIFontHorizontalSpacing-UIMargin+3, renderer.ScreenHeight-UIMargin-UILineHeight+1, 1, "1/123")
44 case 2:
45 TopBarTitle = phnparser.LoadedBookTitle
46 DrawTopBar(UIMargin, UITopBarHeight)
47 // Book text
48 for i := 0; i < UIMaxBookLines; i++ {
49 if UISelectionIndex*UIMaxBookLines+i < len(phnparser.LoadedBookLines) {
50 renderer.AddTextAllDisplays(UIMargin, UIMargin*(2+i)+UITopBarHeight+i*UILineHeight, 1, phnparser.LoadedBookLines[UISelectionIndex*UIMaxBookLines+i])
51 }
52 }
53 default:
54 fmt.Printf("Error! Menu does not exist!")
55 }
56 fmt.Printf("Frame render took %fms.\n", float64(renderer.PerformanceTrackerEnd())/float64(1000000))
57 renderer.UpdateFrameBuffersToFiles(renderer.FrameBuffers[0], 0, UIFrameCount)
58 renderer.UpdateFrameBuffersToFiles(renderer.FrameBuffers[1], 1, UIFrameCount)
59 UIFrameCount++
60}
61
62func DrawTopBar(UIMargin int, UITopBarHeight int) {
63 // Top bar
64 renderer.DrawHorizontalLine(0, UITopBarHeight, 256, 1)
65 renderer.AddTextAllDisplays(UIMargin, UIMargin, 1, TopBarTitle)
66 renderer.DrawLightningIcon()
67 renderer.DrawWifiEnabledIcon()
68}