File: tuninit2.nim

package info (click to toggle)
nim 2.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,951,164 kB
  • sloc: sh: 24,599; ansic: 1,771; python: 1,493; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (54 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download | duplicates (5)
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
# bug #2316

type
    EventType = enum
      QuitEvent = 5
    AppMain* = ref object of RootObj
        width: int
        height: int
        title: string
        running: bool
        event_type: EventType
    App* = ref object of AppMain
        draw_proc: proc(app: AppMain): void {.closure.}
        events_proc: proc(app: AppMain): void {.closure.}
        update_proc: proc(app: AppMain, dt: float): void {.closure.}
        load_proc: proc(app: AppMain): void {.closure.}


proc initApp*(t: string, w, h: int): App =
    App(width: w, height: h, title: t, event_type: EventType.QuitEvent)


method getTitle*(self: AppMain): string = self.title
method getWidth*(self: AppMain): int = self.width
method getHeight*(self: AppMain): int = self.height


method draw*(self: App, draw: proc(app: AppMain)): void =
    self.draw_proc = draw

method load*(self: App, load: proc(a: AppMain)): void =
    self.load_proc = load

method events*(self: App, events: proc(app: AppMain)): void =
    self.events_proc = events

method update*(self: App, update: proc(app: AppMain, delta: float)): void =
    self.update_proc = update

method run*(self: App): void = discard

var mygame = initApp("Example", 800, 600)

mygame.load(proc(app: AppMain): void =
    echo app.getTitle()
    echo app.getWidth()
    echo app.getHeight()
)

mygame.events(proc(app: AppMain): void =
    discard
)

mygame.run()