Browse Source

transition to freeglut

SakiKawasaki 4 years ago
parent
commit
4aa0da3701

+ 1 - 1
README.md

@@ -14,7 +14,7 @@
 # Install
 1. Install this repo
    -  `nimble install nodesnim` or `nimble install https://github.com/Ethosa/nodesnim.git`
-2. Download OpenGL, SDL2_image, SDL2_mixer and GLUT Runtime binaries for your OS
+2. Download OpenGL, SDL2_image, SDL2_mixer and freeglut Runtime binaries for your OS
    -  [SDL2](https://www.libsdl.org/download-2.0.php)
    -  [SDL2_image](https://www.libsdl.org/projects/SDL_image/)
    -  [SDL2_mixer](https://www.libsdl.org/projects/SDL_mixer/)

+ 8 - 0
src/nodesnim/core/input.nim

@@ -11,6 +11,7 @@ type
     MOUSE,     ## Mouse button.
     TOUCH,     ## Touch screen.
     MOTION,    ## Mouse motion.
+    WHEEL,     ## Mouse wheel.
     KEYBOARD,  ## Keyboard input
     UNKNOWN    ## Unknown event.
 
@@ -35,6 +36,7 @@ type
   InputEventVoid* = distinct int8
   InputEventMouseButton* = distinct int8
   InputEventMouseMotion* = distinct int8
+  InputEventMouseWheel* = distinct int8
   InputEventTouchScreen* = distinct int8
   InputEventKeyboard* = distinct int8
 
@@ -114,6 +116,10 @@ proc isInputEventMouseMotion*(a: InputEvent): bool =
   ## Returns true, when `a` kind is a MOTION.
   a.kind == MOTION
 
+proc isInputEventMouseWheel*(a: InputEvent): bool =
+  ## Returns true, when `a` kind is a WHEEL.
+  a.kind == WHEEL
+
 proc isInputEventTouchScreen*(a: InputEvent): bool =
   ## Returns true, when `a` kind is a TOUCH.
   a.kind == TOUCH
@@ -226,6 +232,8 @@ proc `$`*(event: InputEvent): string =
     "InputEventMouseButton(x: " & $event.x & ", y: " & $event.y & ", pressed:" & $event.pressed & ", button: " & button & ")"
   of MOTION:
     "InputEventMotionButton(x: " & $event.x & ", y: " & $event.y & ", xrel:" & $event.xrel & ", yrel:" & $event.yrel & ")"
+  of WHEEL:
+    "InputEventMouseWheel(x: " & $event.x & ", y: " & $event.y & ", button:" & $event.button_index & ", yrel:" & $event.yrel & ")"
   of TOUCH:
     "InputEventTouchScreen(x: " & $event.x & ", y: " & $event.y & ")"
   of KEYBOARD:

+ 2 - 0
src/nodesnim/nodescontrol/scroll.nim

@@ -182,6 +182,8 @@ method handle*(self: ScrollPtr, event: InputEvent, mouse_on: var NodePtr) =
           self.scrollBy(0, -40)
         elif event.key_cint == K_DOWN:
           self.scrollBy(0, 40)
+    elif event.kind == WHEEL:
+      self.scrollBy(0, -20 * event.yrel)
 
   # Mouse Y
   if (mouse_in_y and mouse_pressed and event.kind == MOUSE) or self.thumb_y_has_mouse:

+ 1 - 0
src/nodesnim/thirdparty/opengl/glut.nim

@@ -296,6 +296,7 @@ proc glutDisplayFunc*(f: TGlutVoidCallback)
 proc glutReshapeFunc*(f: TGlut2IntCallback)
 proc glutKeyboardFunc*(f: TGlut1Char2IntCallback)
 proc glutMouseFunc*(f: TGlut4IntCallback)
+proc glutMouseWheelFunc*(f: TGlut4IntCallback)
 proc glutMotionFunc*(f: TGlut2IntCallback)
 proc glutPassiveMotionFunc*(f: TGlut2IntCallback)
 proc glutEntryFunc*(f: TGlut1IntCallback)

+ 12 - 0
src/nodesnim/window.nim

@@ -90,6 +90,17 @@ proc mouse(button, state, x, y: cint) {.cdecl.} =
 
   current_scene.handleScene(last_event, mouse_on, paused)
 
+proc wheel(button, dir, x, y: cint) {.cdecl.} =
+  ## Handle mouse wheel input.
+  check(InputEventMouseWheel, false, false)
+  last_event.button_index = button
+  last_event.x = x.float
+  last_event.y = y.float
+  last_event.kind = WHEEL
+  last_event.yrel = dir.float
+
+  current_scene.handleScene(last_event, mouse_on, paused)
+
 proc keyboardpress(c: int8, x, y: cint) {.cdecl.} =
   ## Called when press any key on keyboard.
   if c < 0:
@@ -247,6 +258,7 @@ proc windowLaunch* =
   glutIdleFunc(display)
   glutReshapeFunc(reshape)
   glutMouseFunc(mouse)
+  glutMouseWheelFunc(wheel)
   glutKeyboardFunc(keyboardpress)
   glutKeyboardUpFunc(keyboardup)
   glutSpecialFunc(keyboardspecialpress)