tuninit2.nim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # bug #2316
  2. type
  3. EventType = enum
  4. QuitEvent = 5
  5. AppMain* = ref object of RootObj
  6. width: int
  7. height: int
  8. title: string
  9. running: bool
  10. event_type: EventType
  11. App* = ref object of AppMain
  12. draw_proc: proc(app: AppMain): void {.closure.}
  13. events_proc: proc(app: AppMain): void {.closure.}
  14. update_proc: proc(app: AppMain, dt: float): void {.closure.}
  15. load_proc: proc(app: AppMain): void {.closure.}
  16. proc initApp*(t: string, w, h: int): App =
  17. App(width: w, height: h, title: t, event_type: EventType.QuitEvent)
  18. method getTitle*(self: AppMain): string = self.title
  19. method getWidth*(self: AppMain): int = self.width
  20. method getHeight*(self: AppMain): int = self.height
  21. method draw*(self: App, draw: proc(app: AppMain)): void =
  22. self.draw_proc = draw
  23. method load*(self: App, load: proc(a: AppMain)): void =
  24. self.load_proc = load
  25. method events*(self: App, events: proc(app: AppMain)): void =
  26. self.events_proc = events
  27. method update*(self: App, update: proc(app: AppMain, delta: float)): void =
  28. self.update_proc = update
  29. method run*(self: App): void = discard
  30. var mygame = initApp("Example", 800, 600)
  31. mygame.load(proc(app: AppMain): void =
  32. echo app.getTitle()
  33. echo app.getWidth()
  34. echo app.getHeight()
  35. )
  36. mygame.events(proc(app: AppMain): void =
  37. discard
  38. )
  39. mygame.run()