func (context) KeyDown(k nimble.Key) { switch k { case nimble.KeyEscape: switch currentMode { case modeSplash, modeVanity: nimble.Quit() case modeTraining, modeGame: youLose() case modeName: // FIXME - ask for confirmation nimble.Quit() } } if currentMode == modeName { if 0x20 <= k && k < 0x7F { teletype.PrintCharUpper(rune(k)) } else { switch k { case nimble.KeyReturn: acceptScore(uint8(universe.NKill()), teletype.CursorLine()) case nimble.KeyBackspace, nimble.KeyDelete: teletype.Backup() } } } if devConfig { // Shortcuts for debugging switch k { case 'b': // Begin game bootSequencePeriod = 0 setMode(modeGame) case 'e': // End game youLose() case 'r': // Reset score file records = make([]vanity.Record, 0) vanity.WriteToFile(records) case 's': // Score a point universe.TallyKill() case 't': // Begin training bootSequencePeriod = 0 setMode(modeTraining) } } }
func tallyFourierFrame() { if benchmarking { if fourierFrameCount++; fourierFrameCount >= 1000 { nimble.Quit() } } }
// Requires visual inspection func TestMenu(t *testing.T) { i0 := FruitItem{Item{Label: "Apple"}} i1 := Add(MakeRadioItem("Banana", &BananaCherry, 0), Separator) i2 := MakeRadioItem("Cherry", &BananaCherry, 1) i3 := FruitItem{Item{Label: "Date", Flags: Disabled | Separator}} i4 := MakeCheckItem("Elderberry", true, func(val bool) { fmt.Printf("Elderberry=%v\n", val) }) i5 := MakeSimpleItem("Fig", func() { fmt.Printf("Fig!\n") }) i6 := MakeSimpleItem("Quit", func() { nimble.Quit() }) theMenu = Menu{Label: "Fruits", Items: []ItemInterface{&i0, i1, i2, &i3, i4, i5, i6}} nimble.AddRenderClient(&context{}) nimble.AddMouseObserver(&theMenu) nimble.Run(nil) }
func (*context) KeyDown(k nimble.Key) { DisplayCursor(true) if 0x20 <= k && k < 0x7F { PrintChar(rune(k)) } else { switch k { case nimble.KeyReturn: PrintChar('\n') case nimble.KeyEscape: nimble.Quit() case nimble.KeyBackspace, nimble.KeyDelete: Backup() } } }
) var ( fileMenu = menu.Menu{Label: "File"} displayMenu = menu.Menu{Label: "Display", Items: []menu.ItemInterface{autoGain}} ratingsMenu = menu.Menu{Label: "Ratings"} invadersMenu = menu.Menu{Label: "Invaders"} colorMenu = menu.Menu{Label: "Color"} ) // Items for "File" menu var ( beginGameItem, trainingItem *menu.SimpleItem exitItem = menu.MakeSimpleItem("Exit", func() { nimble.Quit() }) ) // Items for "Display" menu var autoGain = menu.MakeCheckItem("Autogain", true, nil) // Items for "Ratings" menu var ( highScores *menu.SimpleItem cpuSpeed = menu.MakeSimpleItem("CPU Speed", func() { teletype.Reset() teletype.PrintUpper(fmt.Sprintf("HFT SPEED = %.1f GFlops\n", fourier.Benchmark()*1E-9)) }) )