-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglfw_opengl3_imknobs.nim
152 lines (129 loc) · 4.69 KB
/
glfw_opengl3_imknobs.nim
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Compiling:
# nim c -d:ImKnobsEnable --warning:HoleEnumConv:off glfw_opengl3_imknobs
import ../utils/appImGui
when defined(windows):
when not defined(vcc): # imguinVcc.res TODO WIP
include ./res/resource
const MainWinWidth = 1024
const MainWinHeight = 800
#------
# main
#------
proc main() =
var win = createImGui(MainWinWidth, MainWinHeight, title="ImGui-knobs demo")
defer: destroyImGui(win)
var
showDemoWindow = true
showKnobsWindow = true
showFirstWindow = true
let pio = igGetIO()
#-----------
# main loop
#-----------
while not win.handle.windowShouldClose:
glfwPollEvents()
newFrame()
if showDemoWindow:
igShowDemoWindow(addr showDemoWindow)
# show a simple window that we created ourselves.
if showFirstWindow:
igBegin("Nim: Dear ImGui test with Futhark", addr showFirstWindow, 0)
defer: igEnd()
#
igText((ICON_FA_COMMENT & " " & getFrontendVersionString()).cstring)
igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring)
igText("%s %s", ICON_FA_COMMENT_DOTS & " Dear ImGui", igGetVersion())
igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion)
#-----------------------
# Show ImGui-Knobs demo
#-----------------------
var val1 {.global.}: cfloat = 0.25
var val2 {.global.}: cfloat = 0.65
var val3 {.global.}: cfloat = 0.85
var val4 {.global.}: cfloat = 1.0
if showKnobsWindow:
igBegin("ImGui-knobs / CImGui-Knobs Demo", addr showKnobsWindow, 0)
defer: igEnd()
if IgKnobEx("Gain", addr val1, 0.0, 1.0, 0.01, "%.1fdB" ,IgKnobVariant_Tick.IgKnobVariant
,0 # size
, cast[IgKnobFlags](0)
,10 # steps
,-1 # angle_min
,-1 # angle_max
):
# value was changed
discard
igSameLine(0, -1.0)
if IgKnobEx("Mix", addr val2, 0.0, 1.0, 0.01, "%.1f" , IgKnobVariant_Stepped.IgKnobVariant
,0 # size
, cast[IgKnobFlags](0)
,10 # steps
,-1 # angle_min
,-1 # angle_max
):
#value was changed
discard
# Double click to reset
if igIsItemActive() and igIsMouseDoubleClicked_Nil(0):
val2 = 0
igSameLine(0, -1.0)
# Custom colors
igPushStyleColor_Vec4(ImGuiCol_ButtonActive.ImGuiCol, vec4(255, 0, 0, 0.7))
igPushStyleColor_Vec4(ImGuiCol_ButtonHovered.ImGuiCol, vec4(255, 0, 0, 1))
igPushStyleColor_Vec4(ImGuiCol_Button.ImGuiCol, vec4(0 , 255, 0, 1))
#// Push/PopStyleColor() for each colors used (namely ImGuiCol_ButtonActive and ImGuiCol_ButtonHovered for primary and ImGuiCol_Framebg for Track)
if IgKnobEx("Pitch", addr val3, 0.0, 1.0, 0.01, "%.1f" , IgKnobVariant_WiperOnly.IgKnobVariant
,0 # size
, cast[IgKnobFlags](0)
,10 # steps
,-1 # angle_min
,-1 # angle_max
):
# value was changed
discard
igPopStyleColor(3)
igSameLine(0,-1.0)
# Custom min/max angle
if IgKnobEx("Dry", addr val4, 0.0, 1.0, 0.01, "%.1f" , IgKnobVariant_Stepped.IgKnobVariant
, 0 # Size
, cast[IgKnobFlags](0)
, 10 # steps
, 1.570796 # angle_min
, 3.141592 # angle_max
):
# value was changed
discard
igSameLine(0,-1.0)
# Int value
var val5{.global.}: cint = 1
if IgKnobInt("Wet", addr val5, 1, 10, 0.1, "%i", IgKnobVariant_Stepped.IgKnobVariant
, 0 # size
, cast[IgKnobFlags](0)
, 10 # steps
, -1 # angel_min
, -1 # angel_max
):
#value was changed
discard
igSameLine(0,-1.0)
# Vertical drag only
var val6{.global.}: cfloat = 1
if IgKnobEx("Vertical", addr val6, 0.0, 10, 0.1, "%.1f", IgKnobVariant_Space.IgKnobVariant
, 0
, IgKnobFlags_DragVertical.IgKnobFlags
, 10 # steps
, -1 # angel_min
, -1 # angel_max
):
#value was changed
discard
#
render(win)
win.setClearColor(ccolor(elm:(x: val1,y: val2, z: val3, w: val4)))
if not showFirstWindow and not showDemoWindow and not showKnobsWindow:
win.handle.setWindowShouldClose(true) # End program
#### end while
#------
# main
#------
main()