import "ecere" class MainFrame : Window { displayDriver = "OpenGL"; caption = "Game Menu Demo"; background = black; foreground = white; borderStyle = sizable; hasMaximize = true; hasMinimize = true; hasClose = true; clientSize = { 632, 438 }; MainMenu mainMenu { this }; GameViewport game { this }; GameMenu gameMenu { this }; } class MainMenu : Window { background = gray; font = { "Comic Sans MS", 30 }; anchor = { left = 0, top = 0, right = 0, bottom = 0 }; Button btnPlay { this, caption = "Play Game", p, anchor = { top = 0.4 }; bool NotifyClicked(Button button, int x, int y, Modifiers mods) { Destroy(0); mainFrame.game.Create(); return true; } }; Button btnQuit { this, caption = "Quit Game", q, anchor = { top = 0.6 }; bool NotifyClicked(Button button, int x, int y, Modifiers mods) { mainFrame.Destroy(0); return true; } }; } class GameViewport : Window { autoCreate = false; opacity = 0; anchor = { 0, 0, 0, 0 }; font = { "Comic Sans MS", 12 }; int t; Timer timer { this, 0.1, true; bool DelayExpired() { t++; Update(null); return true; } }; void OnRedraw(Surface surface) { ColorHSV color { h = (t*4) % 360, 100, 100 }; ColorKey keys[2] = { { color, 0.0f }, { white, 1.0f } }; surface.Gradient(keys, 2, 0.5f, vertical, 0,0, clientSize.w-1, clientSize.h-1); surface.WriteTextf(0, 0, "Escape for game menu..."); } bool OnKeyHit(Key key, unichar ch) { switch(key) { case escape: // Pause the game timer.started = false; mainFrame.gameMenu.Create(); break; } return true; } } class GameMenu : Window { autoCreate = false; background = black; opacity = 0.5; drawBehind = true; anchor = { 0, 0, 0, 0 }; font = { "Comic Sans MS", 30 }; Button btnBackToGame { this, caption = "Back to Game", escape, anchor = { top = 0.4 }; bool NotifyClicked(Button button, int x, int y, Modifiers mods) { // Unpause the game mainFrame.game.timer.started = true; Destroy(0); return true; } }; Button btnBackToMenu { this, caption = "Quit to Main Menu", q, anchor = { top = 0.6 }; bool NotifyClicked(Button button, int x, int y, Modifiers mods) { Destroy(0); mainFrame.mainMenu.Create(); return true; } }; } MainFrame mainFrame {};