<commit_before>
import view
import animation
import times
import context
import font

export view

# Window type is defined in view module


#TODO: Window size has two notions. Think about it.

method init*(w: Window, frame: Rect) =
    procCall w.View.init(frame)
    w.window = w
    w.animations = @[]

method `title=`*(w: Window, t: string) = discard
method title*(w: Window): string = ""


method onResize*(w: Window, newSize: Size) =
    procCall w.View.setFrameSize(newSize)

proc fps(): int =
    var lastTime {.global.} = epochTime()
    var lastFrame {.global.} = 0.0
    let curTime = epochTime()
    let thisFrame = curTime - lastTime
    lastFrame = (lastFrame * 0.9 + thisFrame * 0.1)
    result = (1.0 / lastFrame).int
    lastTime = curTime

method drawWindow*(w: Window) =
    let c = currentContext()
    var pt = newPoint(w.frame.width - 80, 2)
    c.fillColor = newColor(0.5, 0, 0)
    c.drawText(systemFont(), pt, "FPS: " & $fps())

    w.recursiveDrawSubviews()

method enableAnimation*(w: Window, flag: bool) = discard

method startTextInput*(w: Window, r: Rect) = discard
method stopTextInput*(w: Window) = discard

proc runAnimations*(w: Window) =
    let t = epochTime()
    for a in w.animations:
        a.tick(t)

proc addAnimation*(w: Window, a: Animation) =
    w.animations.add(a)
    a.startTime = epochTime()<commit_msg>Fixed FPS display in WebGL<commit_after>
import view
import animation
import times
import context
import font

export view

# Window type is defined in view module


#TODO: Window size has two notions. Think about it.

method init*(w: Window, frame: Rect) =
    procCall w.View.init(frame)
    w.window = w
    w.animations = @[]

method `title=`*(w: Window, t: string) = discard
method title*(w: Window): string = ""


method onResize*(w: Window, newSize: Size) =
    procCall w.View.setFrameSize(newSize)

# Bug 2488. Can not use {.global.} for JS target.
var lastTime = epochTime()
var lastFrame = 0.0

proc fps(): int =
    let curTime = epochTime()
    let thisFrame = curTime - lastTime
    lastFrame = (lastFrame * 0.9 + thisFrame * 0.1)
    result = (1.0 / lastFrame).int
    lastTime = curTime

method drawWindow*(w: Window) =
    let c = currentContext()
    var pt = newPoint(w.frame.width - 80, 2)
    c.fillColor = newColor(0.5, 0, 0)
    c.drawText(systemFont(), pt, "FPS: " & $fps())

    w.recursiveDrawSubviews()

method enableAnimation*(w: Window, flag: bool) = discard

method startTextInput*(w: Window, r: Rect) = discard
method stopTextInput*(w: Window) = discard

proc runAnimations*(w: Window) =
    let t = epochTime()
    for a in w.animations:
        a.tick(t)

proc addAnimation*(w: Window, a: Animation) =
    w.animations.add(a)
    a.startTime = epochTime()
{'fraction_non_alphanumeric': 0.12946754194018964, 'fraction_numerical': 0.012399708242159009, 'mean_word_length': 3.409967845659164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4576648', 'n_tokens_mistral': 964, 'n_tokens_neox': 924, 'n_words': 288}