-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnimfire.nim
More file actions
66 lines (55 loc) · 2.89 KB
/
nimfire.nim
File metadata and controls
66 lines (55 loc) · 2.89 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
from pixie/fileformats/png import decodePng
from nglfw import GlfwImage, setWindowIcon
from nimfire/types import Window
from nimfire/colors import BLACK
from chroma import ColorRGBX
import glFB except Window
import vmath
#[ Forward functions]#
proc fillBackground* (w: var Window, colour: ColorRGBX = w.bg_colour)
proc initWindow* (res: (int, int), title: string, resizable: bool = false, bg_colour: ColorRGBX = BLACK): Window =
#[ Creates initial Window object. Arguments:
- res : (int, int) | required >> Resolution of the window
- title : string | required >> Title of the window
- resizable : bool | default = false >> Whether window should be resizeable
- bg_colour : ColorRGBX | default = BLACK >> Colour of the background ]#
result.scr = Screen.new(res[0], res[1], title, resizable)
result.bg_colour = bg_colour
result.fillBackground()
#[ Returns tuple with current window size (using GLFW function). Use over `res` field ]#
proc getRes* (w: Window): (int, int) =
return (w.scr.win.getSize()[0].int, w.scr.win.getSize()[1].int)
#[ Checks whether specific coordinates are within window ]#
proc isWithin* (w: var Window, pos: (int, int)): bool =
return (
(-1 < pos[0] and pos[0] < getRes(w)[0]) and (-1 < pos[1] and pos[1] < getRes(w)[1])
)
#[ Draws one colour on whole screen ]#
proc fillBackground* (w: var Window, colour: ColorRGBX = w.bg_colour) =
for pix in w.scr.pixels(): pix = colour
#[ Draws on specific coordinates - alias for gl*FB <scr[x, y] = c> ]#
proc fillPos* (w: var Window, pos: (int, int), colour: ColorRGBX) =
if isWithin(w, pos):
w.scr[pos[0], pos[1]] = colour
#[ Let you manually clean canvas by drawing background over what was drawn ]#
proc clear* (w: var Window) =
w.fillBackground()
#[ Returns whether Window is ticking - stops when exit event is called ]#
proc tick* (w: var Window): bool =
return not w.scr.close()
#[ Updates the screen. Should be used on every 'tick(Window)' check. Arguments:
- manual : bool | default = false >> Decide on whether you control clearing
of window by yourself or this proc ]#
proc update* (w: var Window, manual: bool = false) =
w.scr.update()
if not manual:
w.clear()
#[ Exits the application ]#
proc finish* (w: var Window) =
w.scr.term()
#[ ALIASES ]#
proc ignite* (res: (int, int), title: string, resizable: bool = false, bg_colour: ColorRGBX = BLACK): Window = # initWindow()
return initWindow(res, title, resizable, bg_colour)
proc isBurning* (w: var Window): bool = return w.tick() # tick()
proc addWood* (w: var Window) = w.update() # update()
proc extinguish* (w: var Window) = w.finish() # finish()