First light of mouse wheel support.
authorMaarten Gribnau <mail@maartengribnau.com>
Thu, 23 Jan 2003 21:39:29 +0000 (21:39 +0000)
committerMaarten Gribnau <mail@maartengribnau.com>
Thu, 23 Jan 2003 21:39:29 +0000 (21:39 +0000)
Only working (soso) on osx.
Maarten

intern/ghost/GHOST_Types.h
intern/ghost/intern/GHOST_EventPrinter.cpp
intern/ghost/intern/GHOST_EventWheel.h [new file with mode: 0644]
intern/ghost/intern/GHOST_SystemCarbon.cpp

index cf148adea109e011a4c93704c468aa63cf1c38c5..a7c89c7e0a64a24916d1a23c3ffdafdea67b1880 100644 (file)
@@ -110,9 +110,10 @@ typedef enum {
 typedef enum {
        GHOST_kEventUnknown = 0,
 
-       GHOST_kEventCursorMove,
-       GHOST_kEventButtonDown,
-       GHOST_kEventButtonUp,
+       GHOST_kEventCursorMove,         /// Mouse move event
+       GHOST_kEventButtonDown,         /// Mouse button event
+       GHOST_kEventButtonUp,           /// Mouse button event
+       GHOST_kEventWheel,                      /// Mouse wheel event
 
        GHOST_kEventKeyDown,
        GHOST_kEventKeyUp,
@@ -310,6 +311,11 @@ typedef struct {
        GHOST_TButtonMask button;
 } GHOST_TEventButtonData;
 
+typedef struct {
+       /** Displacement of a mouse wheel. */
+       GHOST_TInt32 z; 
+} GHOST_TEventWheelData;
+
 typedef struct {
        /** The key code. */
        GHOST_TKey              key;
index 362b40fe5040f3b2e59e12da31cc5ff0ed8f8c9a..953fecbd88f11dda9ce893ebb2c8cc37623b5bfc 100644 (file)
  *
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
-
 /**
-
- * $Id$
- * Copyright (C) 2001 NaN Technologies B.V.
- * @author     Maarten Gribnau
- * @date       May 15, 2001
+ * @file       GHOST_EventPrinter.h
+ * Declaration of GHOST_EventPrinter class.
  */
 
 #include "GHOST_EventPrinter.h"
@@ -73,6 +69,13 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent* event)
                }
                break;
 
+       case GHOST_kEventWheel:
+               {
+               GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*)((GHOST_IEvent*)event)->getData();
+               std::cout << "GHOST_kEventWheel, z: " << wheelData->z;
+               }
+               break;
+
        case GHOST_kEventCursorMove:
                {
                GHOST_TEventCursorData* cursorData = (GHOST_TEventCursorData*)((GHOST_IEvent*)event)->getData();
diff --git a/intern/ghost/intern/GHOST_EventWheel.h b/intern/ghost/intern/GHOST_EventWheel.h
new file mode 100644 (file)
index 0000000..3a5b013
--- /dev/null
@@ -0,0 +1,69 @@
+/**
+ * $Id$
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+/**
+ * @file       GHOST_EventWheel.h
+ * Declaration of GHOST_EventWheel class.
+ */
+
+#ifndef _GHOST_EVENT_WHEEL_H_
+#define _GHOST_EVENT_WHEEL_H_
+
+#include "GHOST_Event.h"
+
+/**
+ * Mouse wheel event.
+ * @author     Maarten Gribnau
+ * @date       May 11, 2001
+ */
+class GHOST_EventWheel : public GHOST_Event
+{
+public:
+       /**
+        * Constructor.
+        * @param msec          The time this event was generated.
+        * @param type          The type of this event.
+        * @param z                     The displacement of the mouse wheel.
+        */
+       GHOST_EventWheel(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window, GHOST_TInt32 z)
+               : GHOST_Event(msec, type, window)
+       {
+               m_wheelEventData.z = z;
+               m_data = &m_wheelEventData;
+       }
+
+protected:
+       /** The z-displacement of the mouse wheel. */
+       GHOST_TEventWheelData m_wheelEventData;
+};
+
+
+#endif // _GHOST_EVENT_WHEEL_H_
+
index 9ae9c2d400618f42a967773b062275d8829ea6bc..acf3e75f860334b4d4a4dac8409bd3c6aa22a28b 100644 (file)
@@ -47,6 +47,7 @@
 #include "GHOST_EventKey.h"
 #include "GHOST_EventButton.h"
 #include "GHOST_EventCursor.h"
+#include "GHOST_EventWheel.h"
 #include "GHOST_TimerManager.h"
 #include "GHOST_TimerTask.h"
 #include "GHOST_WindowManager.h"
@@ -72,7 +73,8 @@ const EventTypeSpec   kEvents[] =
        { kEventClassMouse, kEventMouseUp },
        { kEventClassMouse, kEventMouseMoved },
        { kEventClassMouse, kEventMouseDragged },
-
+       { kEventClassMouse, kEventMouseWheelMoved },
+       
        { kEventClassWindow, kEventWindowClose },
        { kEventClassWindow, kEventWindowActivated },
        { kEventClassWindow, kEventWindowDeactivated },
@@ -525,7 +527,7 @@ OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event)
        GHOST_IWindow* window = m_windowManager->getActiveWindow();
        UInt32 kind = ::GetEventKind(event);
        
-    switch (kind)
+       switch (kind)
     {
                case kEventMouseDown:
                case kEventMouseUp:
@@ -552,7 +554,26 @@ OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event)
                                pushEvent(new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, mousePos.h, mousePos.v));
                        }
             break;
-       }
+
+               case kEventMouseWheelMoved:
+                       {
+                               OSStatus status;
+                               //UInt32 modifiers;
+                               EventMouseWheelAxis axis;
+                               SInt32 delta;
+                               //status = ::GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers);
+                               //GHOST_ASSERT(status == noErr, "GHOST_SystemCarbon::handleMouseEvent(): GetEventParameter() failed");
+                               status = ::GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis);
+                               GHOST_ASSERT(status == noErr, "GHOST_SystemCarbon::handleMouseEvent(): GetEventParameter() failed");
+                               status = ::GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(delta), NULL, &delta);
+                               GHOST_ASSERT(status == noErr, "GHOST_SystemCarbon::handleMouseEvent(): GetEventParameter() failed");
+                               if (axis == kEventMouseWheelAxisY)
+                               {
+                                       pushEvent(new GHOST_EventWheel(getMilliSeconds(), GHOST_kEventWheel, window, delta));
+                               }
+                       }
+                       break;
+               }
        
        return noErr;
 }