add back ghost/guardedalloc from trunk

This commit is contained in:
2011-05-11 20:37:11 +00:00
parent ee7b7a500a
commit b2d752d020
110 changed files with 30924 additions and 0 deletions

173
intern/ghost/CMakeLists.txt Normal file
View File

@@ -0,0 +1,173 @@
# $Id$
# ***** BEGIN GPL 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.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2006, Blender Foundation
# All rights reserved.
#
# The Original Code is: all of this file.
#
# Contributor(s): Jacques Beaurain.
#
# ***** END GPL LICENSE BLOCK *****
set(INC
.
../string
../../source/blender/imbuf
../../source/blender/makesdna
${GLEW_INCLUDE_PATH}
)
set(SRC
intern/GHOST_Buttons.cpp
intern/GHOST_CallbackEventConsumer.cpp
intern/GHOST_C-api.cpp
intern/GHOST_Path-api.cpp
intern/GHOST_DisplayManager.cpp
intern/GHOST_EventManager.cpp
intern/GHOST_EventPrinter.cpp
intern/GHOST_ISystem.cpp
intern/GHOST_ISystemPaths.cpp
intern/GHOST_ModifierKeys.cpp
intern/GHOST_NDOFManager.cpp
intern/GHOST_Path-api.cpp
intern/GHOST_Rect.cpp
intern/GHOST_System.cpp
intern/GHOST_TimerManager.cpp
intern/GHOST_Window.cpp
intern/GHOST_WindowManager.cpp
GHOST_C-api.h
GHOST_IEvent.h
GHOST_IEventConsumer.h
GHOST_ISystem.h
GHOST_ISystemPaths.h
GHOST_ITimerTask.h
GHOST_IWindow.h
GHOST_Path-api.h
GHOST_Rect.h
GHOST_Types.h
intern/GHOST_Buttons.h
intern/GHOST_CallbackEventConsumer.h
intern/GHOST_Debug.h
intern/GHOST_DisplayManager.h
intern/GHOST_Event.h
intern/GHOST_EventButton.h
intern/GHOST_EventCursor.h
intern/GHOST_EventDragnDrop.h
intern/GHOST_EventKey.h
intern/GHOST_EventManager.h
intern/GHOST_EventNDOF.h
intern/GHOST_EventPrinter.h
intern/GHOST_EventString.h
intern/GHOST_EventTrackpad.h
intern/GHOST_EventWheel.h
intern/GHOST_ModifierKeys.h
intern/GHOST_NDOFManager.h
intern/GHOST_System.h
intern/GHOST_SystemPaths.h
intern/GHOST_TimerManager.h
intern/GHOST_TimerTask.h
intern/GHOST_Window.h
intern/GHOST_WindowManager.h
)
if(APPLE)
if(WITH_COCOA)
list(APPEND SRC
intern/GHOST_DisplayManagerCocoa.mm
intern/GHOST_SystemCocoa.mm
intern/GHOST_SystemPathsCocoa.mm
intern/GHOST_WindowCocoa.mm
intern/GHOST_DisplayManagerCocoa.h
intern/GHOST_SystemCocoa.h
intern/GHOST_SystemPathsCocoa.h
intern/GHOST_WindowCocoa.h
)
else()
list(APPEND SRC
intern/GHOST_DisplayManagerCarbon.cpp
intern/GHOST_SystemCarbon.cpp
intern/GHOST_SystemPathsCarbon.cpp
intern/GHOST_WindowCarbon.cpp
intern/GHOST_DisplayManagerCarbon.h
intern/GHOST_SystemCarbon.h
intern/GHOST_SystemPathsCarbon.h
intern/GHOST_WindowCarbon.h
)
endif()
if(WITH_CODEC_QUICKTIME)
add_definitions(-DWITH_QUICKTIME)
endif()
elseif(UNIX)
if(WITH_X11_XINPUT)
add_definitions(-DWITH_X11_XINPUT)
endif()
list(APPEND INC ${X11_X11_INCLUDE_PATH})
list(APPEND SRC
intern/GHOST_DisplayManagerX11.cpp
intern/GHOST_SystemX11.cpp
intern/GHOST_SystemPathsX11.cpp
intern/GHOST_WindowX11.cpp
intern/GHOST_DisplayManagerX11.h
intern/GHOST_SystemX11.h
intern/GHOST_SystemPathsX11.h
intern/GHOST_WindowX11.h
)
if(NOT WITH_INSTALL_PORTABLE)
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}")
endif()
if(X11_XF86keysym_INCLUDE_PATH)
add_definitions(-DWITH_XF86KEYSYM)
list(APPEND INC ${X11_XF86keysym_INCLUDE_PATH})
endif()
elseif(WIN32)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
endif()
list(APPEND INC ${WINTAB_INC})
list(APPEND SRC
intern/GHOST_DisplayManagerWin32.cpp
intern/GHOST_SystemWin32.cpp
intern/GHOST_SystemPathsWin32.cpp
intern/GHOST_WindowWin32.cpp
intern/GHOST_DropTargetWin32.cpp
intern/GHOST_DisplayManagerWin32.h
intern/GHOST_DropTargetWin32.h
intern/GHOST_SystemWin32.h
intern/GHOST_SystemPathsWin32.h
intern/GHOST_WindowWin32.h
intern/GHOST_TaskbarWin32.h
)
endif()
blender_add_lib(bf_intern_ghost "${SRC}" "${INC}")

864
intern/ghost/GHOST_C-api.h Normal file
View File

@@ -0,0 +1,864 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \ingroup GHOST
*
* \file GHOST_C-api.h
* \brief GHOST C-API function and type declarations.
*/
#ifndef GHOST_C_API_H
#define GHOST_C_API_H
#include "GHOST_Types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Creates a "handle" for a C++ GHOST object.
* A handle is just an opaque pointer to an empty struct.
* In the API the pointer is casted to the actual C++ class.
* \param name Name of the handle to create.
*/
GHOST_DECLARE_HANDLE(GHOST_SystemHandle);
GHOST_DECLARE_HANDLE(GHOST_TimerTaskHandle);
GHOST_DECLARE_HANDLE(GHOST_WindowHandle);
GHOST_DECLARE_HANDLE(GHOST_EventHandle);
GHOST_DECLARE_HANDLE(GHOST_RectangleHandle);
GHOST_DECLARE_HANDLE(GHOST_EventConsumerHandle);
/**
* Definition of a callback routine that receives events.
* @param event The event received.
* @param userdata The callback's user data, supplied to GHOST_CreateSystem.
*/
typedef int (*GHOST_EventCallbackProcPtr)(GHOST_EventHandle event, GHOST_TUserDataPtr userdata);
/**
* Creates the one and only system.
* @return a handle to the system.
*/
extern GHOST_SystemHandle GHOST_CreateSystem(void);
/**
* Disposes the one and only system.
* @param systemhandle The handle to the system
* @return An indication of success.
*/
extern GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle);
/**
* Creates an event consumer object
* @param eventCallback The event callback routine.
* @param userdata Pointer to user data returned to the callback routine.
*/
extern GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback, GHOST_TUserDataPtr userdata);
/**
* Disposes an event consumer object
* @param consumerhandle Handle to the event consumer.
* @return An indication of success.
*/
extern GHOST_TSuccess GHOST_DisposeEventConsumer(GHOST_EventConsumerHandle consumerhandle);
/**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* Based on ANSI clock() routine.
* @param systemhandle The handle to the system
* @return The number of milliseconds.
*/
extern GHOST_TUns64 GHOST_GetMilliSeconds(GHOST_SystemHandle systemhandle);
/**
* Installs a timer.
* Note that, on most operating systems, messages need to be processed in order
* for the timer callbacks to be invoked.
* @param systemhandle The handle to the system
* @param delay The time to wait for the first call to the timerProc (in milliseconds)
* @param interval The interval between calls to the timerProc (in milliseconds)
* @param timerProc The callback invoked when the interval expires,
* @param userData Placeholder for user data.
* @return A timer task (0 if timer task installation failed).
*/
extern GHOST_TimerTaskHandle GHOST_InstallTimer(GHOST_SystemHandle systemhandle,
GHOST_TUns64 delay,
GHOST_TUns64 interval,
GHOST_TimerProcPtr timerProc,
GHOST_TUserDataPtr userData);
/**
* Removes a timer.
* @param systemhandle The handle to the system
* @param timerTask Timer task to be removed.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_RemoveTimer(GHOST_SystemHandle systemhandle,
GHOST_TimerTaskHandle timertaskhandle);
/***************************************************************************************
** Display/window management functionality
***************************************************************************************/
/**
* Returns the number of displays on this system.
* @param systemhandle The handle to the system
* @return The number of displays.
*/
extern GHOST_TUns8 GHOST_GetNumDisplays(GHOST_SystemHandle systemhandle);
/**
* Returns the dimensions of the main display on this system.
* @param systemhandle The handle to the system
* @param width A pointer the width gets put in
* @param height A pointer the height gets put in
* @return void.
*/
extern void GHOST_GetMainDisplayDimensions(GHOST_SystemHandle systemhandle,
GHOST_TUns32* width,
GHOST_TUns32* height);
/**
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
* @param systemhandle The handle to the system
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
* @return A handle to the new window ( == NULL if creation failed).
*/
extern GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
const char* title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const int stereoVisual,
const GHOST_TUns16 numOfAASamples);
/**
* Returns the window user data.
* @param windowhandle The handle to the window
* @return The window user data.
*/
extern GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandle);
/**
* Changes the window user data.
* @param windowhandle The handle to the window
* @param data The window user data.
*/
extern void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle,
GHOST_TUserDataPtr userdata);
/**
* Dispose a window.
* @param systemhandle The handle to the system
* @param window Handle to the window to be disposed.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle,
GHOST_WindowHandle windowhandle);
/**
* Returns whether a window is valid.
* @param systemhandle The handle to the system
* @param window Handle to the window to be checked.
* @return Indication of validity.
*/
extern int GHOST_ValidWindow(GHOST_SystemHandle systemhandle,
GHOST_WindowHandle windowhandle);
/**
* Begins full screen mode.
* @param systemhandle The handle to the system
* @param setting The new setting of the display.
* @return A handle to the window displayed in full screen.
* This window is invalid after full screen has been ended.
*/
extern GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle,
GHOST_DisplaySetting* setting,
const int stereoVisual);
/**
* Ends full screen mode.
* @param systemhandle The handle to the system
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle);
/**
* Returns current full screen mode status.
* @param systemhandle The handle to the system
* @return The current status.
*/
extern int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle);
/***************************************************************************************
** Event management functionality
***************************************************************************************/
/**
* Retrieves events from the system and stores them in the queue.
* @param systemhandle The handle to the system
* @param waitForEvent Boolean to indicate that ProcessEvents should
* wait (block) until the next event before returning.
* @return Indication of the presence of events.
*/
extern int GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, int waitForEvent);
/**
* Retrieves events from the queue and send them to the event consumers.
* @param systemhandle The handle to the system
* @return Indication of the presence of events.
*/
extern int GHOST_DispatchEvents(GHOST_SystemHandle systemhandle);
/**
* Adds the given event consumer to our list.
* @param systemhandle The handle to the system
* @param consumerhandle The event consumer to add.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle,
GHOST_EventConsumerHandle consumerhandle);
/**
* Remove the given event consumer to our list.
* @param systemhandle The handle to the system
* @param consumerhandle The event consumer to remove.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_RemoveEventConsumer(GHOST_SystemHandle systemhandle,
GHOST_EventConsumerHandle consumerhandle);
/***************************************************************************************
** Progress bar functionality
***************************************************************************************/
/**
* Sets the progress bar value displayed in the window/application icon
* @param windowhandle The handle to the window
* @param progress The progress % (0.0 to 1.0)
*/
extern GHOST_TSuccess GHOST_SetProgressBar(GHOST_WindowHandle windowhandle, float progress);
/**
* Hides the progress bar in the icon
* @param windowhandle The handle to the window
*/
extern GHOST_TSuccess GHOST_EndProgressBar(GHOST_WindowHandle windowhandle);
/***************************************************************************************
** N-degree of freedom device management functionality
***************************************************************************************/
/**
* Open N-degree of freedom devices
*/
extern int GHOST_OpenNDOF(GHOST_SystemHandle systemhandle,
GHOST_WindowHandle windowhandle,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
);
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/**
* Returns the current cursor shape.
* @param windowhandle The handle to the window
* @return The current cursor shape.
*/
extern GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandle);
/**
* Set the shape of the cursor.
* @param windowhandle The handle to the window
* @param cursor The new cursor shape type id.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle,
GHOST_TStandardCursor cursorshape);
/**
* Set the shape of the cursor to a custom cursor.
* @param windowhandle The handle to the window
* @param bitmap The bitmap data for the cursor.
* @param mask The mask data for the cursor.
* @param hotX The X coordinate of the cursor hotspot.
* @param hotY The Y coordinate of the cursor hotspot.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle,
GHOST_TUns8 bitmap[16][2],
GHOST_TUns8 mask[16][2],
int hotX,
int hotY);
/**
* Set the shape of the cursor to a custom cursor of specified size.
* @param windowhandle The handle to the window
* @param bitmap The bitmap data for the cursor.
* @param mask The mask data for the cursor.
* @parm sizex, sizey The size of the cursor
* @param hotX The X coordinate of the cursor hotspot.
* @param hotY The Y coordinate of the cursor hotspot.
* @param fg_color, bg_color Colors of the cursor
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetCustomCursorShapeEx(GHOST_WindowHandle windowhandle,
GHOST_TUns8 *bitmap,
GHOST_TUns8 *mask,
int sizex, int sizey,
int hotX, int hotY,
int fg_color, int bg_color );
/**
* Returns the visibility state of the cursor.
* @param windowhandle The handle to the window
* @return The visibility state of the cursor.
*/
extern int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle);
/**
* Shows or hides the cursor.
* @param windowhandle The handle to the window
* @param visible The new visibility state of the cursor.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle,
int visible);
/**
* Returns the current location of the cursor (location in screen coordinates)
* @param systemhandle The handle to the system
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle,
GHOST_TInt32* x,
GHOST_TInt32* y);
/**
* Updates the location of the cursor (location in screen coordinates).
* Not all operating systems allow the cursor to be moved (without the input device being moved).
* @param systemhandle The handle to the system
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
GHOST_TInt32 x,
GHOST_TInt32 y);
/**
* Grabs the cursor for a modal operation, to keep receiving
* events when the mouse is outside the window. X11 only, others
* do this automatically.
* @param windowhandle The handle to the window
* @param mode The new grab state of the cursor.
* @param bounds The grab ragion (optional) - left,top,right,bottom
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
GHOST_TGrabCursorMode mode,
int* bounds);
/***************************************************************************************
** Access to mouse button and keyboard states.
***************************************************************************************/
/**
* Returns the state of a modifier key (ouside the message queue).
* @param systemhandle The handle to the system
* @param mask The modifier key state to retrieve.
* @param isDown Pointer to return modifier state in.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle,
GHOST_TModifierKeyMask mask,
int* isDown);
/**
* Returns the state of a mouse button (ouside the message queue).
* @param systemhandle The handle to the system
* @param mask The button state to retrieve.
* @param isDown Pointer to return button state in.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle,
GHOST_TButtonMask mask,
int* isDown);
/***************************************************************************************
** Drag'n'drop operations
***************************************************************************************/
/**
* Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
*/
extern void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, GHOST_TInt8 canAccept);
/**
* Returns the event type.
* @param eventhandle The handle to the event
* @return The event type.
*/
extern GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle);
/**
* Returns the time this event was generated.
* @param eventhandle The handle to the event
* @return The event generation time.
*/
extern GHOST_TUns64 GHOST_GetEventTime(GHOST_EventHandle eventhandle);
/**
* Returns the window this event was generated on,
* or NULL if it is a 'system' event.
* @param eventhandle The handle to the event
* @return The generating window.
*/
extern GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle);
/**
* Returns the event data.
* @param eventhandle The handle to the event
* @return The event data.
*/
extern GHOST_TEventDataPtr GHOST_GetEventData(GHOST_EventHandle eventhandle);
/**
* Returns the timer callback.
* @param timertaskhandle The handle to the timertask
* @return The timer callback.
*/
extern GHOST_TimerProcPtr GHOST_GetTimerProc(GHOST_TimerTaskHandle timertaskhandle);
/**
* Changes the timer callback.
* @param timertaskhandle The handle to the timertask
* @param timerProc The timer callback.
*/
extern void GHOST_SetTimerProc(GHOST_TimerTaskHandle timertaskhandle,
GHOST_TimerProcPtr timerProc);
/**
* Returns the timer user data.
* @param timertaskhandle The handle to the timertask
* @return The timer user data.
*/
extern GHOST_TUserDataPtr GHOST_GetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle);
/**
* Changes the time user data.
* @param timertaskhandle The handle to the timertask
* @param data The timer user data.
*/
extern void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle,
GHOST_TUserDataPtr userData);
/**
* Returns indication as to whether the window is valid.
* @param windowhandle The handle to the window
* @return The validity of the window.
*/
extern int GHOST_GetValid(GHOST_WindowHandle windowhandle) ;
/**
* Returns the type of drawing context used in this window.
* @param windowhandle The handle to the window
* @return The current type of drawing context.
*/
extern GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle);
/**
* Tries to install a rendering context in this window.
* @param windowhandle The handle to the window
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
extern GHOST_TSuccess GHOST_SetDrawingContextType(GHOST_WindowHandle windowhandle,
GHOST_TDrawingContextType type);
/**
* Sets the title displayed in the title bar.
* @param windowhandle The handle to the window
* @param title The title to display in the title bar.
*/
extern void GHOST_SetTitle(GHOST_WindowHandle windowhandle,
const char* title);
/**
* Returns the title displayed in the title bar. The title
* should be free'd with free().
*
* @param windowhandle The handle to the window
* @return The title, free with free().
*/
extern char* GHOST_GetTitle(GHOST_WindowHandle windowhandle);
/**
* Returns the window rectangle dimensions.
* These are screen coordinates.
* @param windowhandle The handle to the window
* @return A handle to the bounding rectangle of the window.
*/
extern GHOST_RectangleHandle GHOST_GetWindowBounds(GHOST_WindowHandle windowhandle);
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* @param windowhandle The handle to the window
* @return A handle to the bounding rectangle of the window.
*/
extern GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle);
/**
* Disposes a rectangle object
* @param rectanglehandle Handle to the rectangle.
*/
void GHOST_DisposeRectangle(GHOST_RectangleHandle rectanglehandle);
/**
* Resizes client rectangle width.
* @param windowhandle The handle to the window
* @param width The new width of the client area of the window.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetClientWidth(GHOST_WindowHandle windowhandle,
GHOST_TUns32 width);
/**
* Resizes client rectangle height.
* @param windowhandle The handle to the window
* @param height The new height of the client area of the window.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetClientHeight(GHOST_WindowHandle windowhandle,
GHOST_TUns32 height);
/**
* Resizes client rectangle.
* @param windowhandle The handle to the window
* @param width The new width of the client area of the window.
* @param height The new height of the client area of the window.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetClientSize(GHOST_WindowHandle windowhandle,
GHOST_TUns32 width,
GHOST_TUns32 height);
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param windowhandle The handle to the window
* @param inX The x-coordinate on the screen.
* @param inY The y-coordinate on the screen.
* @param outX The x-coordinate in the client rectangle.
* @param outY The y-coordinate in the client rectangle.
*/
extern void GHOST_ScreenToClient(GHOST_WindowHandle windowhandle,
GHOST_TInt32 inX,
GHOST_TInt32 inY,
GHOST_TInt32* outX,
GHOST_TInt32* outY) ;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param windowhandle The handle to the window
* @param inX The x-coordinate in the client rectangle.
* @param inY The y-coordinate in the client rectangle.
* @param outX The x-coordinate on the screen.
* @param outY The y-coordinate on the screen.
*/
extern void GHOST_ClientToScreen(GHOST_WindowHandle windowhandle,
GHOST_TInt32 inX,
GHOST_TInt32 inY,
GHOST_TInt32* outX,
GHOST_TInt32* outY);
/**
* Returns the state of the window (normal, minimized, maximized).
* @param windowhandle The handle to the window
* @return The state of the window.
*/
extern GHOST_TWindowState GHOST_GetWindowState(GHOST_WindowHandle windowhandle);
/**
* Sets the state of the window (normal, minimized, maximized).
* @param windowhandle The handle to the window
* @param state The state of the window.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetWindowState(GHOST_WindowHandle windowhandle,
GHOST_TWindowState state);
/**
* Sets the window "modified" status, indicating unsaved changes
* @param windowhandle The handle to the window
* @param isUnsavedChanges Unsaved changes or not
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetWindowModifiedState(GHOST_WindowHandle windowhandle,
GHOST_TUns8 isUnsavedChanges);
/**
* Sets the order of the window (bottom, top).
* @param windowhandle The handle to the window
* @param order The order of the window.
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_SetWindowOrder(GHOST_WindowHandle windowhandle,
GHOST_TWindowOrder order);
/**
* Swaps front and back buffers of a window.
* @param windowhandle The handle to the window
* @return An intean success indicator.
*/
extern GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle);
/**
* Activates the drawing context of this window.
* @param windowhandle The handle to the window
* @return An intean success indicator.
*/
extern GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle);
/**
* Invalidates the contents of this window.
* @param windowhandle The handle to the window
* @return Indication of success.
*/
extern GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle);
/**
* Returns the status of the tablet
* @param windowhandle The handle to the window
* @return Status of tablet
*/
extern const GHOST_TabletData *GHOST_GetTabletData(GHOST_WindowHandle windowhandle);
/**
* Access to rectangle width.
* @param rectanglehandle The handle to the rectangle
* @return width of the rectangle
*/
extern GHOST_TInt32 GHOST_GetWidthRectangle(GHOST_RectangleHandle rectanglehandle);
/**
* Access to rectangle height.
* @param rectanglehandle The handle to the rectangle
* @return height of the rectangle
*/
extern GHOST_TInt32 GHOST_GetHeightRectangle(GHOST_RectangleHandle rectanglehandle);
/**
* Gets all members of the rectangle.
* @param rectanglehandle The handle to the rectangle
* @param l Pointer to return left coordinate in.
* @param t Pointer to return top coordinate in.
* @param r Pointer to return right coordinate in.
* @param b Pointer to return bottom coordinate in.
*/
extern void GHOST_GetRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32* l,
GHOST_TInt32* t,
GHOST_TInt32* r,
GHOST_TInt32* b);
/**
* Sets all members of the rectangle.
* @param rectanglehandle The handle to the rectangle
* @param l requested left coordinate of the rectangle
* @param t requested top coordinate of the rectangle
* @param r requested right coordinate of the rectangle
* @param b requested bottom coordinate of the rectangle
*/
extern void GHOST_SetRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 l,
GHOST_TInt32 t,
GHOST_TInt32 r,
GHOST_TInt32 b);
/**
* Returns whether this rectangle is empty.
* Empty rectangles are rectangles that have width==0 and/or height==0.
* @param rectanglehandle The handle to the rectangle
* @return intean value (true == empty rectangle)
*/
extern GHOST_TSuccess GHOST_IsEmptyRectangle(GHOST_RectangleHandle rectanglehandle);
/**
* Returns whether this rectangle is valid.
* Valid rectangles are rectangles that have m_l <= m_r and m_t <= m_b. Thus, emapty rectangles are valid.
* @param rectanglehandle The handle to the rectangle
* @return intean value (true==valid rectangle)
*/
extern GHOST_TSuccess GHOST_IsValidRectangle(GHOST_RectangleHandle rectanglehandle);
/**
* Grows (or shrinks the rectangle).
* The method avoids negative insets making the rectangle invalid
* @param rectanglehandle The handle to the rectangle
* @param i The amount of offset given to each extreme (negative values shrink the rectangle).
*/
extern void GHOST_InsetRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 i);
/**
* Does a union of the rectangle given and this rectangle.
* The result is stored in this rectangle.
* @param rectanglehandle The handle to the rectangle
* @param r The rectangle that is input for the union operation.
*/
extern void GHOST_UnionRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_RectangleHandle anotherrectanglehandle);
/**
* Grows the rectangle to included a point.
* @param rectanglehandle The handle to the rectangle
* @param x The x-coordinate of the point.
* @param y The y-coordinate of the point.
*/
extern void GHOST_UnionPointRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 x,
GHOST_TInt32 y);
/**
* Returns whether the point is inside this rectangle.
* Point on the boundary is considered inside.
* @param rectanglehandle The handle to the rectangle
* @param x x-coordinate of point to test.
* @param y y-coordinate of point to test.
* @return intean value (true if point is inside).
*/
extern GHOST_TSuccess GHOST_IsInsideRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 x,
GHOST_TInt32 y);
/**
* Returns whether the rectangle is inside this rectangle.
* @param rectanglehandle The handle to the rectangle
* @param r rectangle to test.
* @return visibility (not, partially or fully visible).
*/
extern GHOST_TVisibility GHOST_GetRectangleVisibility(GHOST_RectangleHandle rectanglehandle,
GHOST_RectangleHandle anotherrectanglehandle);
/**
* Sets rectangle members.
* Sets rectangle members such that it is centered at the given location.
* @param rectanglehandle The handle to the rectangle
* @param cx requested center x-coordinate of the rectangle
* @param cy requested center y-coordinate of the rectangle
*/
extern void GHOST_SetCenterRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 cx,
GHOST_TInt32 cy);
/**
* Sets rectangle members.
* Sets rectangle members such that it is centered at the given location,
* with the width requested.
* @param rectanglehandle The handle to the rectangle
* @param cx requested center x-coordinate of the rectangle
* @param cy requested center y-coordinate of the rectangle
* @param w requested width of the rectangle
* @param h requested height of the rectangle
*/
extern void GHOST_SetRectangleCenter(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 cx,
GHOST_TInt32 cy,
GHOST_TInt32 w,
GHOST_TInt32 h);
/**
* Clips a rectangle.
* Updates the rectangle given such that it will fit within this one.
* This can result in an empty rectangle.
* @param rectanglehandle The handle to the rectangle
* @param r the rectangle to clip
* @return whether clipping has occurred
*/
extern GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_RectangleHandle anotherrectanglehandle);
/**
* Return the data from the clipboad
* @param return the selection instead, X11 only feature
* @return clipboard data
*/
extern GHOST_TUns8* GHOST_getClipboard(int selection);
/**
* Put data to the Clipboard
* @param set the selection instead, X11 only feature
*/
extern void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection);
/**
* Toggles console
* @action 0 - Hides
* 1 - Shows
* 2 - Toggles
* 3 - Hides if it runs not from command line
* * - Does nothing
* @return current status (1 -visible, 0 - hidden)
*/
extern int GHOST_toggleConsole(int action);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,97 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/GHOST_IEvent.h
* \ingroup GHOST
* Declaration of GHOST_IEvent interface class.
*/
#ifndef _GHOST_IEVENT_H_
#define _GHOST_IEVENT_H_
#include <stddef.h>
#include "GHOST_Types.h"
class GHOST_IWindow;
/**
* Interface class for events received from GHOST.
* You should not need to inherit this class. The system will pass these events
* to the GHOST_IEventConsumer::processEvent() method of event consumers.<br>
* Use the getType() method to retrieve the type of event and the getData()
* method to get the event data out. Using the event type you can cast the
* event data to the correct event dat structure.
* @see GHOST_IEventConsumer#processEvent
* @see GHOST_TEventType
* @author Maarten Gribnau
* @date May 31, 2001
*/
class GHOST_IEvent
{
public:
/**
* Destructor.
*/
virtual ~GHOST_IEvent()
{
}
/**
* Returns the event type.
* @return The event type.
*/
virtual GHOST_TEventType getType() = 0;
/**
* Returns the time this event was generated.
* @return The event generation time.
*/
virtual GHOST_TUns64 getTime() = 0;
/**
* Returns the window this event was generated on,
* or NULL if it is a 'system' event.
* @return The generating window.
*/
virtual GHOST_IWindow* getWindow() = 0;
/**
* Returns the event data.
* @return The event data.
*/
virtual GHOST_TEventDataPtr getData() = 0;
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_IEvent"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
};
#endif // _GHOST_IEVENT_H_

View File

@@ -0,0 +1,75 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/GHOST_IEventConsumer.h
* \ingroup GHOST
* Declaration of GHOST_IEventConsumer interface class.
*/
#ifndef _GHOST_IEVENT_CONSUMER_H_
#define _GHOST_IEVENT_CONSUMER_H_
#include "GHOST_IEvent.h"
/**
* Interface class for objects interested in receiving events.
* Objects interested in events should inherit this class and implement the
* processEvent() method. They should then be registered with the system that
* they want to receive events. The system will call the processEvent() method
* for every installed event consumer to pass events.
* @see GHOST_ISystem#addEventConsumer
* @author Maarten Gribnau
* @date May 14, 2001
*/
class GHOST_IEventConsumer
{
public:
/**
* Destructor.
*/
virtual ~GHOST_IEventConsumer()
{
}
/**
* This method is called by the system when it has events to dispatch.
* @see GHOST_ISystem#dispatchEvents
* @param event The event that can be handled or ignored.
* @return Indication as to whether the event was handled.
*/
virtual bool processEvent(GHOST_IEvent* event) = 0;
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_IEventConsumer"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
};
#endif // _GHOST_EVENT_CONSUMER_H_

View File

@@ -0,0 +1,410 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/GHOST_ISystem.h
* \ingroup GHOST
* %Main interface file for C++ Api with declaration of GHOST_ISystem interface
* class.
* Contains the doxygen documentation main page.
*/
#ifndef _GHOST_ISYSTEM_H_
#define _GHOST_ISYSTEM_H_
#include "GHOST_Types.h"
#include "GHOST_ITimerTask.h"
#include "GHOST_IWindow.h"
class GHOST_IEventConsumer;
/**
* \page GHOSTPage GHOST
*
* \section intro Introduction
*
* GHOST is yet another acronym. It stands for "Generic Handy Operating System
* Toolkit". It has been created to replace the OpenGL utility tool kit
* <a href="http://www.opengl.org/developers/documentation/glut.html">GLUT</a>.
* GLUT was used in <a href="http://www.blender3d.com">Blender</a> until the
* point that Blender needed to be ported to Apple's Mac OSX. Blender needed a
* number of modifications in GLUT to work but the GLUT sources for OSX were
* unavailable at the time. The decision was made to build our own replacement
* for GLUT. In those days, NaN Technologies BV was the company that developed
* Blender.
* <br><br>
* Enough history. What does GHOST have to offer?<br>
* In short: everything that Blender needed from GLUT to run on all it's supported
* operating systems and some extra's.
* This includes :
* <ul>
* <li> Time(r) management.</li>
* <li> Display/window management (windows are only created on the main display).
* <li> Event management.</li>
* <li> Cursor shape management (no custom cursors for now).</li>
* <li> Access to the state of the mouse buttons and the keyboard.</li>
* <li> Menus for windows with events generated when they are accessed (this is
* work in progress).</li>
* </ul>
* Font management has been moved to a separate library.
*
* \section platforms Platforms
*
* \section Building GHOST
*
* \section interface Interface
* GHOST has two programming interfaces:
* <ul>
* <li>The C-API. For programs written in C.</li>
* <li>The C++-API. For programs written in C++.</li>
* </ul>
* GHOST itself is writtem in C++ and the C-API is a wrapper around the C++
* API.
*
* \subsection cplusplus_api The C++ API consists of the following files:
* <ul>
* <li>GHOST_IEvent.h</li>
* <li>GHOST_IEventConsumer.h</li>
* <li>GHOST_ISystem.h</li>
* <li>GHOST_ITimerTask.h</li>
* <li>GHOST_IWindow.h</li>
* <li>GHOST_Rect.h</li>
* <li>GHOST_Types.h</li>
* </ul>
* For an example of using the C++-API, have a look at the GHOST_C-Test.cpp
* program in the ?/ghost/test/gears/ directory.
*
* \subsection c_api The C-API
* To use GHOST in programs written in C, include the file GHOST_C-API.h in
* your program. This file includes the GHOST_Types.h file for all GHOST types
* and defines functions that give you access to the same functionality present
* in the C++ API.<br>
* For an example of using the C-API, have a look at the GHOST_C-Test.c program
* in the ?/ghost/test/gears/ directory.
*
* \section work Work in progress
* \todo write WIP section
*/
/** \interface GHOST_ISystem
* Interface for classes that provide access to the operating system.
* There should be only one system class in an application.
* Therefore, the routines to create and dispose the system are static.
* Provides:
* -# Time(r) management.
* -# Display/window management (windows are only created on the main display).
* -# Event management.
* -# Cursor shape management (no custom cursors for now).
* -# Access to the state of the mouse buttons and the keyboard.
* -# Menus for windows with events generated when they are accessed (this is
* work in progress).
* @author Maarten Gribnau
* @date May 30, 2001
*/
class GHOST_ISystem
{
public:
/**
* Creates the one and only system.
* @return An indication of success.
*/
static GHOST_TSuccess createSystem();
/**
* Disposes the one and only system.
* @return An indication of success.
*/
static GHOST_TSuccess disposeSystem();
/**
* Returns a pointer to the one and only system (nil if it hasn't been created).
* @return A pointer to the system.
*/
static GHOST_ISystem* getSystem();
protected:
/**
* Constructor.
* Protected default constructor to force use of static createSystem member.
*/
GHOST_ISystem() {}
/**
* Destructor.
* Protected default constructor to force use of static dispose member.
*/
virtual ~GHOST_ISystem() {}
public:
/***************************************************************************************
** Time(r) functionality
***************************************************************************************/
/**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* Based on ANSI clock() routine.
* @return The number of milliseconds.
*/
virtual GHOST_TUns64 getMilliSeconds() const = 0;
/**
* Installs a timer.
* Note that, on most operating systems, messages need to be processed in order
* for the timer callbacks to be invoked.
* @param delay The time to wait for the first call to the timerProc (in milliseconds)
* @param interval The interval between calls to the timerProc (in milliseconds)
* @param timerProc The callback invoked when the interval expires,
* @param userData Placeholder for user data.
* @return A timer task (0 if timer task installation failed).
*/
virtual GHOST_ITimerTask* installTimer(GHOST_TUns64 delay, GHOST_TUns64 interval, GHOST_TimerProcPtr timerProc, GHOST_TUserDataPtr userData = 0) = 0;
/**
* Removes a timer.
* @param timerTask Timer task to be removed.
* @return Indication of success.
*/
virtual GHOST_TSuccess removeTimer(GHOST_ITimerTask* timerTask) = 0;
/***************************************************************************************
** Display/window management functionality
***************************************************************************************/
/**
* Returns the number of displays on this system.
* @return The number of displays.
*/
virtual GHOST_TUns8 getNumDisplays() const = 0;
/**
* Returns the dimensions of the main display on this system.
* @return The dimension of the main display.
*/
virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const = 0;
/**
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Create a stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
virtual GHOST_IWindow* createWindow(
const STR_String& title,
GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
GHOST_TWindowState state, GHOST_TDrawingContextType type,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0) = 0;
/**
* Dispose a window.
* @param window Pointer to the window to be disposed.
* @return Indication of success.
*/
virtual GHOST_TSuccess disposeWindow(GHOST_IWindow* window) = 0;
/**
* Returns whether a window is valid.
* @param window Pointer to the window to be checked.
* @return Indication of validity.
*/
virtual bool validWindow(GHOST_IWindow* window) = 0;
/**
* Begins full screen mode.
* @param setting The new setting of the display.
* @param window Window displayed in full screen.
* This window is invalid after full screen has been ended.
* @return Indication of success.
*/
virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
const bool stereoVisual) = 0;
/**
* Ends full screen mode.
* @return Indication of success.
*/
virtual GHOST_TSuccess endFullScreen(void) = 0;
/**
* Returns current full screen mode status.
* @return The current status.
*/
virtual bool getFullScreen(void) = 0;
/***************************************************************************************
** Event management functionality
***************************************************************************************/
/**
* Retrieves events from the system and stores them in the queue.
* @param waitForEvent Flag to wait for an event (or return immediately).
* @return Indication of the presence of events.
*/
virtual bool processEvents(bool waitForEvent) = 0;
/**
* Retrieves events from the queue and send them to the event consumers.
* @return Indication of the presence of events.
*/
virtual bool dispatchEvents() = 0;
/**
* Adds the given event consumer to our list.
* @param consumer The event consumer to add.
* @return Indication of success.
*/
virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer) = 0;
/**
* Removes the given event consumer to our list.
* @param consumer The event consumer to remove.
* @return Indication of success.
*/
virtual GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer* consumer) = 0;
/***************************************************************************************
** N-degree of freedom device management functionality
***************************************************************************************/
/**
* Starts the N-degree of freedom device manager
*/
virtual int openNDOF(GHOST_IWindow*,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
// original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler
) = 0;
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/**
* Returns the current location of the cursor (location in screen coordinates)
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const = 0;
/**
* Updates the location of the cursor (location in screen coordinates).
* Not all operating systems allow the cursor to be moved (without the input device being moved).
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) = 0;
/***************************************************************************************
** Access to mouse button and keyboard states.
***************************************************************************************/
/**
* Returns the state of a modifier key (ouside the message queue).
* @param mask The modifier key state to retrieve.
* @param isDown The state of a modifier key (true == pressed).
* @return Indication of success.
*/
virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const = 0;
/**
* Returns the state of a mouse button (ouside the message queue).
* @param mask The button state to retrieve.
* @param isDown Button state.
* @return Indication of success.
*/
virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const = 0;
/**
* Toggles console
* @action 0 - Hides
* 1 - Shows
* 2 - Toggles
* 3 - Hides if it runs not from command line
* * - Does nothing
* @return current status (1 -visible, 0 - hidden)
*/
virtual int toggleConsole(int action) = 0;
/***************************************************************************************
** Access to clipboard.
***************************************************************************************/
/**
* Returns the selection buffer
* @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer
*
*/
virtual GHOST_TUns8* getClipboard(bool selection) const = 0;
/**
* Put data to the Clipboard
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
protected:
/**
* Initialize the system.
* @return Indication of success.
*/
virtual GHOST_TSuccess init() = 0;
/**
* Shut the system down.
* @return Indication of success.
*/
virtual GHOST_TSuccess exit() = 0;
/** The one and only system */
static GHOST_ISystem* m_system;
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_ISystem"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
};
#endif // _GHOST_ISYSTEM_H_

View File

@@ -0,0 +1,103 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/GHOST_ISystemPaths.h
* \ingroup GHOST
*/
#ifndef _GHOST_ISYSTEMPATHS_H_
#define _GHOST_ISYSTEMPATHS_H_
#include "GHOST_Types.h"
class GHOST_ISystemPaths
{
public:
/**
* Creates the one and only system.
* @return An indication of success.
*/
static GHOST_TSuccess create();
/**
* Disposes the one and only system.
* @return An indication of success.
*/
static GHOST_TSuccess dispose();
/**
* Returns a pointer to the one and only system (nil if it hasn't been created).
* @return A pointer to the system.
*/
static GHOST_ISystemPaths* get();
protected:
/**
* Constructor.
* Protected default constructor to force use of static createSystem member.
*/
GHOST_ISystemPaths() {}
/**
* Destructor.
* Protected default constructor to force use of static dispose member.
*/
virtual ~GHOST_ISystemPaths() {}
public:
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const = 0;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const = 0;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
/**
* Add the file to the operating system most recently used files
*/
virtual void addToSystemRecentFiles(const char* filename) const = 0;
private:
/** The one and only system paths*/
static GHOST_ISystemPaths* m_systemPaths;
};
#endif

View File

@@ -0,0 +1,96 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/GHOST_ITimerTask.h
* \ingroup GHOST
* Declaration of GHOST_ITimerTask interface class.
*/
#ifndef _GHOST_ITIMER_TASK_H_
#define _GHOST_ITIMER_TASK_H_
#include "GHOST_Types.h"
/**
* Interface for a timer task.
* Timer tasks are created by the system and can be installed by the system.
* After installation, the timer callback-procedure or "timerProc" will be called
* periodically. You should not need to inherit this class. It is passed to the
* application in the timer-callback.<br>
* <br>
* Note that GHOST processes timers in the UI thread. You should ask GHOST
* process messages in order for the timer-callbacks to be called.
* @see GHOST_ISystem#installTimer
* @see GHOST_TimerProcPtr
* @author Maarten Gribnau
* @date May 31, 2001
*/
class GHOST_ITimerTask
{
public:
/**
* Destructor.
*/
virtual ~GHOST_ITimerTask()
{
}
/**
* Returns the timer callback.
* @return The timer callback.
*/
virtual GHOST_TimerProcPtr getTimerProc() const = 0;
/**
* Changes the timer callback.
* @param timerProc The timer callback.
*/
virtual void setTimerProc(const GHOST_TimerProcPtr timerProc) = 0;
/**
* Returns the timer user data.
* @return The timer user data.
*/
virtual GHOST_TUserDataPtr getUserData() const = 0;
/**
* Changes the time user data.
* @param data The timer user data.
*/
virtual void setUserData(const GHOST_TUserDataPtr userData) = 0;
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_ITimerTask"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
};
#endif // _GHOST_ITIMER_TASK_H_

View File

@@ -0,0 +1,317 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/GHOST_IWindow.h
* \ingroup GHOST
* Declaration of GHOST_IWindow interface class.
*/
#ifndef _GHOST_IWINDOW_H_
#define _GHOST_IWINDOW_H_
#include "STR_String.h"
#include "GHOST_Rect.h"
#include "GHOST_Types.h"
/**
* Interface for GHOST windows.
*
* You can create a window with the system's GHOST_ISystem::createWindow
* method.
* @see GHOST_ISystem#createWindow
*
* There are two coordinate systems:
* <ul>
* <li>The screen coordinate system. The origin of the screen is located in the
* upper left corner of the screen.</li>
* <li>The client rectangle coordinate system. The client rectangle of a window
* is the area that is drawable by the application (excluding title bars etc.).
* </li>
* </ul>
* @author Maarten Gribnau
* @date May 31, 2001
*/
class GHOST_IWindow
{
public:
/**
* Destructor.
*/
virtual ~GHOST_IWindow()
{
}
/**
* Returns indication as to whether the window is valid.
* @return The validity of the window.
*/
virtual bool getValid() const = 0;
/**
* Returns the associated OS object/handle
* @return The associated OS object/handle
*/
virtual void* getOSWindow() const = 0;
/**
* Returns the type of drawing context used in this window.
* @return The current type of drawing context.
*/
virtual GHOST_TDrawingContextType getDrawingContextType() = 0;
/**
* Tries to install a rendering context in this window.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
virtual GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) = 0;
/**
* Sets the title displayed in the title bar.
* @param title The title to display in the title bar.
*/
virtual void setTitle(const STR_String& title) = 0;
/**
* Returns the title displayed in the title bar.
* @param title The title displayed in the title bar.
*/
virtual void getTitle(STR_String& title) const = 0;
/**
* Returns the window rectangle dimensions.
* These are screen coordinates.
* @param bounds The bounding rectangle of the window.
*/
virtual void getWindowBounds(GHOST_Rect& bounds) const = 0;
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* @param bounds The bounding rectangle of the client area of the window.
*/
virtual void getClientBounds(GHOST_Rect& bounds) const = 0;
/**
* Resizes client rectangle width.
* @param width The new width of the client area of the window.
*/
virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width) = 0;
/**
* Resizes client rectangle height.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height) = 0;
/**
* Resizes client rectangle.
* @param width The new width of the client area of the window.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height) = 0;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate on the screen.
* @param inY The y-coordinate on the screen.
* @param outX The x-coordinate in the client rectangle.
* @param outY The y-coordinate in the client rectangle.
*/
virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate in the client rectangle.
* @param inY The y-coordinate in the client rectangle.
* @param outX The x-coordinate on the screen.
* @param outY The y-coordinate on the screen.
*/
virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0;
/**
* Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
*/
virtual void setAcceptDragOperation(bool canAccept) = 0;
/**
* Returns acceptance of the dropped object
* Usually called by the "object dropped" event handling function
*/
virtual bool canAcceptDragOperation() const = 0;
/**
* Returns the state of the window (normal, minimized, maximized).
* @return The state of the window.
*/
virtual GHOST_TWindowState getState() const = 0;
/**
* Sets the state of the window (normal, minimized, maximized).
* @param state The state of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setState(GHOST_TWindowState state) = 0;
/**
* Sets the window "modified" status, indicating unsaved changes
* @param isUnsavedChanges Unsaved changes or not
* @return Indication of success.
*/
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges) = 0;
/**
* Gets the window "modified" status, indicating unsaved changes
* @return True if there are unsaved changes
*/
virtual bool getModifiedState() = 0;
/**
* Sets the order of the window (bottom, top).
* @param order The order of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order) = 0;
/**
* Swaps front and back buffers of a window.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess swapBuffers() = 0;
/**
* Activates the drawing context of this window.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess activateDrawingContext() = 0;
/**
* Invalidates the contents of this window.
* @return Indication of success.
*/
virtual GHOST_TSuccess invalidate() = 0;
/**
* Returns the window user data.
* @return The window user data.
*/
virtual GHOST_TUserDataPtr getUserData() const = 0;
/**
* Changes the window user data.
* @param data The window user data.
*/
virtual void setUserData(const GHOST_TUserDataPtr userData) = 0;
/**
* Returns the tablet data (pressure etc).
* @return The tablet data (pressure etc).
*/
virtual const GHOST_TabletData* GetTabletData() = 0;
/***************************************************************************************
** Progress bar functionality
***************************************************************************************/
/**
* Sets the progress bar value displayed in the window/application icon
* @param progress The progress %
*/
virtual GHOST_TSuccess setProgressBar(float progress) = 0;
/**
* Hides the progress bar in the icon
*/
virtual GHOST_TSuccess endProgressBar() = 0;
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/**
* Returns the current cursor shape.
* @return The current cursor shape.
*/
virtual GHOST_TStandardCursor getCursorShape() const = 0;
/**
* Set the shape of the cursor.
* @param cursor The new cursor shape type id.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape) = 0;
/**
* Set the shape of the cursor to a custom cursor.
* @param bitmap The bitmap data for the cursor.
* @param mask The mask data for the cursor.
* @param hotX The X coordinate of the cursor hotspot.
* @param hotY The Y coordinate of the cursor hotspot.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 bitmap[16][2],
GHOST_TUns8 mask[16][2],
int hotX,
int hotY) = 0;
virtual GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 *bitmap,
GHOST_TUns8 *mask,
int sizex, int sizey,
int hotX, int hotY,
int fg_color, int bg_color) = 0;
/**
* Returns the visibility state of the cursor.
* @return The visibility state of the cursor.
*/
virtual bool getCursorVisibility() const = 0;
/**
* Shows or hides the cursor.
* @param visible The new visibility state of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorVisibility(bool visible) = 0;
/**
* Grabs the cursor for a modal operation.
* @param grab The new grab state of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds) { return GHOST_kSuccess; };
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_IWindow"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
};
#endif // _GHOST_IWINDOW_H_

View File

@@ -0,0 +1,87 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 by Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/GHOST_Path-api.h
* \ingroup GHOST
*/
#ifndef GHOST_PATH_API_H
#define GHOST_PATH_API_H
#include "GHOST_Types.h"
#ifdef __cplusplus
extern "C" {
#endif
GHOST_DECLARE_HANDLE(GHOST_SystemPathsHandle);
/**
* Creates the one and only instance of the system path access.
* @return An indication of success.
*/
extern GHOST_TSuccess GHOST_CreateSystemPaths(void);
/**
* Disposes the one and only system.
* @return An indication of success.
*/
extern GHOST_TSuccess GHOST_DisposeSystemPaths(void);
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
extern const GHOST_TUns8* GHOST_getSystemDir(void);
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* @return Unsigned char string pointing to user dir (eg ~).
*/
extern const GHOST_TUns8* GHOST_getUserDir(void);
/**
* Determine the dir in which the binary file is found.
* @return Unsigned char string pointing to binary dir (eg ~/usr/local/bin/).
*/
extern const GHOST_TUns8* GHOST_getBinaryDir(void);
/**
* Add the file to the operating system most recently used files
*/
extern void GHOST_addToSystemRecentFiles(const char* filename);
#ifdef __cplusplus
}
#endif
#endif

259
intern/ghost/GHOST_Rect.h Normal file
View File

@@ -0,0 +1,259 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Debug.h
* \ingroup GHOST
* Macro's used in GHOST debug target.
*/
#ifndef _H_GHOST_Rect
#define _H_GHOST_Rect
#include "GHOST_Types.h"
/**
* Implements rectangle functionality.
* The four extreme coordinates are stored as left, top, right and bottom.
* To be valid, a rectangle should have a left coordinate smaller than or equal to right.
* To be valid, a rectangle should have a top coordinate smaller than or equal to bottom.
* @author Maarten Gribnau
* @date May 10, 2001
*/
class GHOST_Rect {
public:
/**
* Constructs a rectangle with the given values.
* @param l requested left coordinate of the rectangle
* @param t requested top coordinate of the rectangle
* @param r requested right coordinate of the rectangle
* @param b requested bottom coordinate of the rectangle
*/
GHOST_Rect(GHOST_TInt32 l=0, GHOST_TInt32 t=0, GHOST_TInt32 r=0, GHOST_TInt32 b=0)
: m_l(l), m_t(t), m_r(r), m_b(b) {}
/**
* Copy constructor.
* @param r rectangle to copy
*/
GHOST_Rect(const GHOST_Rect& r)
: m_l(r.m_l), m_t(r.m_t), m_r(r.m_r), m_b(r.m_b) {}
/**
* Destructor.
*/
virtual ~GHOST_Rect() {};
/**
* Access to rectangle width.
* @return width of the rectangle
*/
virtual inline GHOST_TInt32 getWidth() const;
/**
* Access to rectangle height.
* @return height of the rectangle
*/
virtual inline GHOST_TInt32 getHeight() const;
/**
* Sets all members of the rectangle.
* @param l requested left coordinate of the rectangle
* @param t requested top coordinate of the rectangle
* @param r requested right coordinate of the rectangle
* @param b requested bottom coordinate of the rectangle
*/
virtual inline void set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b);
/**
* Returns whether this rectangle is empty.
* Empty rectangles are rectangles that have width==0 and/or height==0.
* @return boolean value (true==empty rectangle)
*/
virtual inline bool isEmpty() const;
/**
* Returns whether this rectangle is valid.
* Valid rectangles are rectangles that have m_l <= m_r and m_t <= m_b. Thus, emapty rectangles are valid.
* @return boolean value (true==valid rectangle)
*/
virtual inline bool isValid() const;
/**
* Grows (or shrinks the rectangle).
* The method avoids negative insets making the rectangle invalid
* @param i The amount of offset given to each extreme (negative values shrink the rectangle).
*/
virtual void inset(GHOST_TInt32 i);
/**
* Does a union of the rectangle given and this rectangle.
* The result is stored in this rectangle.
* @param r The rectangle that is input for the union operation.
*/
virtual inline void unionRect(const GHOST_Rect& r);
/**
* Grows the rectangle to included a point.
* @param x The x-coordinate of the point.
* @param y The y-coordinate of the point.
*/
virtual inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y);
/**
* Grows the rectangle to included a point.
* @param x The x-coordinate of the point.
* @param y The y-coordinate of the point.
*/
virtual inline void wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, GHOST_TInt32 ofs);
/**
* Returns whether the point is inside this rectangle.
* Point on the boundary is considered inside.
* @param x x-coordinate of point to test.
* @param y y-coordinate of point to test.
* @return boolean value (true if point is inside).
*/
virtual inline bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const;
/**
* Returns whether the rectangle is inside this rectangle.
* @param r rectangle to test.
* @return visibility (not, partially or fully visible).
*/
virtual GHOST_TVisibility getVisibility(GHOST_Rect& r) const;
/**
* Sets rectangle members.
* Sets rectangle members such that it is centered at the given location.
* @param cx requested center x-coordinate of the rectangle
* @param cy requested center y-coordinate of the rectangle
*/
virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy);
/**
* Sets rectangle members.
* Sets rectangle members such that it is centered at the given location,
* with the width requested.
* @param cx requested center x-coordinate of the rectangle
* @param cy requested center y-coordinate of the rectangle
* @param w requested width of the rectangle
* @param h requested height of the rectangle
*/
virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, GHOST_TInt32 h);
/**
* Clips a rectangle.
* Updates the rectangle given such that it will fit within this one.
* This can result in an empty rectangle.
* @param r the rectangle to clip
* @return whether clipping has occurred
*/
virtual bool clip(GHOST_Rect& r) const;
/** Left coordinate of the rectangle */
GHOST_TInt32 m_l;
/** Top coordinate of the rectangle */
GHOST_TInt32 m_t;
/** Right coordinate of the rectangle */
GHOST_TInt32 m_r;
/** Bottom coordinate of the rectangle */
GHOST_TInt32 m_b;
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_Rect"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
};
inline GHOST_TInt32 GHOST_Rect::getWidth() const
{
return m_r - m_l;
}
inline GHOST_TInt32 GHOST_Rect::getHeight() const
{
return m_b - m_t;
}
inline void GHOST_Rect::set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b)
{
m_l = l; m_t = t; m_r = r; m_b = b;
}
inline bool GHOST_Rect::isEmpty() const
{
return (getWidth() == 0) || (getHeight() == 0);
}
inline bool GHOST_Rect::isValid() const
{
return (m_l <= m_r) && (m_t <= m_b);
}
inline void GHOST_Rect::unionRect(const GHOST_Rect& r)
{
if (r.m_l < m_l) m_l = r.m_l;
if (r.m_r > m_r) m_r = r.m_r;
if (r.m_t < m_t) m_t = r.m_t;
if (r.m_b > m_b) m_b = r.m_b;
}
inline void GHOST_Rect::unionPoint(GHOST_TInt32 x, GHOST_TInt32 y)
{
if (x < m_l) m_l = x;
if (x > m_r) m_r = x;
if (y < m_t) m_t = y;
if (y > m_b) m_b = y;
}
#include <stdio.h>
inline void GHOST_Rect::wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, GHOST_TInt32 ofs)
{
GHOST_TInt32 w= getWidth();
GHOST_TInt32 h= getHeight();
/* highly unlikely but avoid eternal loop */
if(w-ofs*2 <= 0 || h-ofs*2 <= 0)
return;
while(x-ofs < m_l) x+= w-(ofs*2);
while(y-ofs < m_t) y+= h-(ofs*2);
while(x+ofs > m_r) x-= w-(ofs*2);
while(y+ofs > m_b) y-= h-(ofs*2);
}
inline bool GHOST_Rect::isInside(GHOST_TInt32 x, GHOST_TInt32 y) const
{
return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);
}
#endif // _H_GHOST_Rect

516
intern/ghost/GHOST_Types.h Normal file
View File

@@ -0,0 +1,516 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/GHOST_Types.h
* \ingroup GHOST
*/
#ifndef _GHOST_TYPES_H_
#define _GHOST_TYPES_H_
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
#define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
typedef char GHOST_TInt8;
typedef unsigned char GHOST_TUns8;
typedef short GHOST_TInt16;
typedef unsigned short GHOST_TUns16;
typedef int GHOST_TInt32;
typedef unsigned int GHOST_TUns32;
#ifdef WIN32
#define WM_BLND_NDOF_AXIS WM_USER + 1
#define WM_BLND_NDOF_BTN WM_USER + 2
#endif
#if defined(WIN32) && !defined(FREE_WINDOWS)
typedef __int64 GHOST_TInt64;
typedef unsigned __int64 GHOST_TUns64;
#else
typedef long long GHOST_TInt64;
typedef unsigned long long GHOST_TUns64;
#endif
typedef void* GHOST_TUserDataPtr;
typedef enum
{
GHOST_kFailure = 0,
GHOST_kSuccess
} GHOST_TSuccess;
/* Xtilt and Ytilt represent how much the pen is tilted away from
* vertically upright in either the X or Y direction, with X and Y the
* axes of the tablet surface.
* In other words, Xtilt and Ytilt are components of a vector created by projecting
* the pen's angle in 3D space vertically downwards on to the XY plane
* --Matt
*/
typedef enum {
GHOST_kTabletModeNone = 0,
GHOST_kTabletModeStylus,
GHOST_kTabletModeEraser
} GHOST_TTabletMode;
typedef struct GHOST_TabletData {
GHOST_TTabletMode Active; /* 0=None, 1=Stylus, 2=Eraser */
float Pressure; /* range 0.0 (not touching) to 1.0 (full pressure) */
float Xtilt; /* range 0.0 (upright) to 1.0 (tilted fully against the tablet surface) */
float Ytilt; /* as above */
} GHOST_TabletData;
typedef enum {
GHOST_kNotVisible = 0,
GHOST_kPartiallyVisible,
GHOST_kFullyVisible
} GHOST_TVisibility;
typedef enum {
GHOST_kFireTimeNever = 0xFFFFFFFF
} GHOST_TFireTimeConstant;
typedef enum {
GHOST_kModifierKeyLeftShift = 0,
GHOST_kModifierKeyRightShift,
GHOST_kModifierKeyLeftAlt,
GHOST_kModifierKeyRightAlt,
GHOST_kModifierKeyLeftControl,
GHOST_kModifierKeyRightControl,
GHOST_kModifierKeyOS,
GHOST_kModifierKeyNumMasks
} GHOST_TModifierKeyMask;
typedef enum {
GHOST_kWindowStateNormal = 0,
GHOST_kWindowStateMaximized,
GHOST_kWindowStateMinimized,
GHOST_kWindowStateFullScreen,
GHOST_kWindowStateEmbedded,
GHOST_kWindowState8Normal = 8,
GHOST_kWindowState8Maximized,
GHOST_kWindowState8Minimized,
GHOST_kWindowState8FullScreen,
GHOST_kWindowStateModified,
GHOST_kWindowStateUnModified
} GHOST_TWindowState;
/** Constants for the answer to the blender exit request */
typedef enum {
GHOST_kExitCancel = 0,
GHOST_kExitNow
} GHOST_TExitRequestResponse;
typedef enum {
GHOST_kWindowOrderTop = 0,
GHOST_kWindowOrderBottom
} GHOST_TWindowOrder;
typedef enum {
GHOST_kDrawingContextTypeNone = 0,
GHOST_kDrawingContextTypeOpenGL
} GHOST_TDrawingContextType;
typedef enum {
GHOST_kButtonMaskLeft = 0,
GHOST_kButtonMaskMiddle,
GHOST_kButtonMaskRight,
GHOST_kButtonMaskButton4,
GHOST_kButtonMaskButton5,
GHOST_kButtonNumMasks
} GHOST_TButtonMask;
typedef enum {
GHOST_kEventUnknown = 0,
GHOST_kEventCursorMove, /// Mouse move event
GHOST_kEventButtonDown, /// Mouse button event
GHOST_kEventButtonUp, /// Mouse button event
GHOST_kEventWheel, /// Mouse wheel event
GHOST_kEventTrackpad, /// Trackpad event
GHOST_kEventNDOFMotion, /// N degree of freedom device motion event
GHOST_kEventNDOFButton, /// N degree of freedom device button event
GHOST_kEventKeyDown,
GHOST_kEventKeyUp,
// GHOST_kEventKeyAuto,
GHOST_kEventQuit,
GHOST_kEventWindowClose,
GHOST_kEventWindowActivate,
GHOST_kEventWindowDeactivate,
GHOST_kEventWindowUpdate,
GHOST_kEventWindowSize,
GHOST_kEventWindowMove,
GHOST_kEventDraggingEntered,
GHOST_kEventDraggingUpdated,
GHOST_kEventDraggingExited,
GHOST_kEventDraggingDropDone,
GHOST_kEventOpenMainFile, // Needed for Cocoa to open double-clicked .blend file at startup
GHOST_kEventTimer,
GHOST_kNumEventTypes
} GHOST_TEventType;
typedef enum {
GHOST_kStandardCursorFirstCursor = 0,
GHOST_kStandardCursorDefault = 0,
GHOST_kStandardCursorRightArrow,
GHOST_kStandardCursorLeftArrow,
GHOST_kStandardCursorInfo,
GHOST_kStandardCursorDestroy,
GHOST_kStandardCursorHelp,
GHOST_kStandardCursorCycle,
GHOST_kStandardCursorSpray,
GHOST_kStandardCursorWait,
GHOST_kStandardCursorText,
GHOST_kStandardCursorCrosshair,
GHOST_kStandardCursorUpDown,
GHOST_kStandardCursorLeftRight,
GHOST_kStandardCursorTopSide,
GHOST_kStandardCursorBottomSide,
GHOST_kStandardCursorLeftSide,
GHOST_kStandardCursorRightSide,
GHOST_kStandardCursorTopLeftCorner,
GHOST_kStandardCursorTopRightCorner,
GHOST_kStandardCursorBottomRightCorner,
GHOST_kStandardCursorBottomLeftCorner,
GHOST_kStandardCursorCopy,
GHOST_kStandardCursorCustom,
GHOST_kStandardCursorNumCursors,
GHOST_kStandardCursorPencil
} GHOST_TStandardCursor;
typedef enum {
GHOST_kKeyUnknown = -1,
GHOST_kKeyBackSpace,
GHOST_kKeyTab,
GHOST_kKeyLinefeed,
GHOST_kKeyClear,
GHOST_kKeyEnter = 0x0D,
GHOST_kKeyEsc = 0x1B,
GHOST_kKeySpace = ' ',
GHOST_kKeyQuote = 0x27,
GHOST_kKeyComma = ',',
GHOST_kKeyMinus = '-',
GHOST_kKeyPeriod = '.',
GHOST_kKeySlash = '/',
// Number keys
GHOST_kKey0 = '0',
GHOST_kKey1,
GHOST_kKey2,
GHOST_kKey3,
GHOST_kKey4,
GHOST_kKey5,
GHOST_kKey6,
GHOST_kKey7,
GHOST_kKey8,
GHOST_kKey9,
GHOST_kKeySemicolon = ';',
GHOST_kKeyEqual = '=',
// Character keys
GHOST_kKeyA = 'A',
GHOST_kKeyB,
GHOST_kKeyC,
GHOST_kKeyD,
GHOST_kKeyE,
GHOST_kKeyF,
GHOST_kKeyG,
GHOST_kKeyH,
GHOST_kKeyI,
GHOST_kKeyJ,
GHOST_kKeyK,
GHOST_kKeyL,
GHOST_kKeyM,
GHOST_kKeyN,
GHOST_kKeyO,
GHOST_kKeyP,
GHOST_kKeyQ,
GHOST_kKeyR,
GHOST_kKeyS,
GHOST_kKeyT,
GHOST_kKeyU,
GHOST_kKeyV,
GHOST_kKeyW,
GHOST_kKeyX,
GHOST_kKeyY,
GHOST_kKeyZ,
GHOST_kKeyLeftBracket = '[',
GHOST_kKeyRightBracket = ']',
GHOST_kKeyBackslash = 0x5C,
GHOST_kKeyAccentGrave = '`',
GHOST_kKeyLeftShift = 0x100,
GHOST_kKeyRightShift,
GHOST_kKeyLeftControl,
GHOST_kKeyRightControl,
GHOST_kKeyLeftAlt,
GHOST_kKeyRightAlt,
GHOST_kKeyOS, // Command key on Apple, Windows key(s) on Windows
GHOST_kKeyGrLess , // German PC only!
GHOST_kKeyCapsLock,
GHOST_kKeyNumLock,
GHOST_kKeyScrollLock,
GHOST_kKeyLeftArrow,
GHOST_kKeyRightArrow,
GHOST_kKeyUpArrow,
GHOST_kKeyDownArrow,
GHOST_kKeyPrintScreen,
GHOST_kKeyPause,
GHOST_kKeyInsert,
GHOST_kKeyDelete,
GHOST_kKeyHome,
GHOST_kKeyEnd,
GHOST_kKeyUpPage,
GHOST_kKeyDownPage,
// Numpad keys
GHOST_kKeyNumpad0,
GHOST_kKeyNumpad1,
GHOST_kKeyNumpad2,
GHOST_kKeyNumpad3,
GHOST_kKeyNumpad4,
GHOST_kKeyNumpad5,
GHOST_kKeyNumpad6,
GHOST_kKeyNumpad7,
GHOST_kKeyNumpad8,
GHOST_kKeyNumpad9,
GHOST_kKeyNumpadPeriod,
GHOST_kKeyNumpadEnter,
GHOST_kKeyNumpadPlus,
GHOST_kKeyNumpadMinus,
GHOST_kKeyNumpadAsterisk,
GHOST_kKeyNumpadSlash,
// Function keys
GHOST_kKeyF1,
GHOST_kKeyF2,
GHOST_kKeyF3,
GHOST_kKeyF4,
GHOST_kKeyF5,
GHOST_kKeyF6,
GHOST_kKeyF7,
GHOST_kKeyF8,
GHOST_kKeyF9,
GHOST_kKeyF10,
GHOST_kKeyF11,
GHOST_kKeyF12,
GHOST_kKeyF13,
GHOST_kKeyF14,
GHOST_kKeyF15,
GHOST_kKeyF16,
GHOST_kKeyF17,
GHOST_kKeyF18,
GHOST_kKeyF19,
GHOST_kKeyF20,
GHOST_kKeyF21,
GHOST_kKeyF22,
GHOST_kKeyF23,
GHOST_kKeyF24,
// Multimedia keypad buttons
GHOST_kKeyMediaPlay,
GHOST_kKeyMediaStop,
GHOST_kKeyMediaFirst,
GHOST_kKeyMediaLast
} GHOST_TKey;
typedef enum {
GHOST_kGrabDisable = 0, /* grab not set */
GHOST_kGrabNormal, /* no cursor adjustments */
GHOST_kGrabWrap, /* wrap the mouse location to prevent limiting screen bounds */
GHOST_kGrabHide, /* hide the mouse while grabbing and restore the original location on release (numbuts) */
} GHOST_TGrabCursorMode;
typedef void* GHOST_TEventDataPtr;
typedef struct {
/** The x-coordinate of the cursor position. */
GHOST_TInt32 x;
/** The y-coordinate of the cursor position. */
GHOST_TInt32 y;
} GHOST_TEventCursorData;
typedef struct {
/** The mask of the mouse button. */
GHOST_TButtonMask button;
} GHOST_TEventButtonData;
typedef struct {
/** Displacement of a mouse wheel. */
GHOST_TInt32 z;
} GHOST_TEventWheelData;
typedef enum {
GHOST_kTrackpadEventUnknown =0,
GHOST_kTrackpadEventScroll,
GHOST_kTrackpadEventRotate,
GHOST_kTrackpadEventSwipe, /* Reserved, not used for now */
GHOST_kTrackpadEventMagnify
} GHOST_TTrackpadEventSubTypes;
typedef struct {
/** The event subtype */
GHOST_TTrackpadEventSubTypes subtype;
/** The x-location of the trackpad event */
GHOST_TInt32 x;
/** The y-location of the trackpad event */
GHOST_TInt32 y;
/** The x-delta or value of the trackpad event */
GHOST_TInt32 deltaX;
/** The y-delta (currently only for scroll subtype) of the trackpad event */
GHOST_TInt32 deltaY;
} GHOST_TEventTrackpadData;
typedef enum {
GHOST_kDragnDropTypeUnknown =0,
GHOST_kDragnDropTypeFilenames, /*Array of strings representing file names (full path) */
GHOST_kDragnDropTypeString, /* Unformatted text UTF-8 string */
GHOST_kDragnDropTypeBitmap /*Bitmap image data */
} GHOST_TDragnDropTypes;
typedef struct {
/** The x-coordinate of the cursor position. */
GHOST_TInt32 x;
/** The y-coordinate of the cursor position. */
GHOST_TInt32 y;
/** The dropped item type */
GHOST_TDragnDropTypes dataType;
/** The "dropped content" */
GHOST_TEventDataPtr data;
} GHOST_TEventDragnDropData;
typedef struct {
int count;
GHOST_TUns8 **strings;
} GHOST_TStringArray;
/* original patch used floats, but the driver return ints and uns. We will calibrate in view, no sense on doing conversions twice */
/* as all USB device controls are likely to use ints, this is also more future proof */
//typedef struct {
// /** N-degree of freedom device data */
// float tx, ty, tz; /** -x left, +y up, +z forward */
// float rx, ry, rz;
// float dt;
//} GHOST_TEventNDOFData;
typedef struct {
/** N-degree of freedom device data v2*/
int changed;
GHOST_TUns64 client;
GHOST_TUns64 address;
GHOST_TInt16 tx, ty, tz; /** -x left, +y up, +z forward */
GHOST_TInt16 rx, ry, rz;
GHOST_TInt16 buttons;
GHOST_TUns64 time;
GHOST_TUns64 delta;
} GHOST_TEventNDOFData;
typedef int (*GHOST_NDOFLibraryInit_fp)(void);
typedef void (*GHOST_NDOFLibraryShutdown_fp)(void* deviceHandle);
typedef void* (*GHOST_NDOFDeviceOpen_fp)(void* platformData);
// original patch windows callback. In mac os X version the callback is internal to the plug-in and post an event to main thead.
// not necessary faster, but better integration with other events.
//typedef int (*GHOST_NDOFEventHandler_fp)(float* result7, void* deviceHandle, unsigned int message, unsigned int* wParam, unsigned long* lParam);
//typedef void (*GHOST_NDOFCallBack_fp)(GHOST_TEventNDOFDataV2 *VolDatas);
typedef struct {
/** The key code. */
GHOST_TKey key;
/** The ascii code for the key event ('\0' if none). */
char ascii;
} GHOST_TEventKeyData;
typedef struct {
/** Number of pixels on a line. */
GHOST_TUns32 xPixels;
/** Number of lines. */
GHOST_TUns32 yPixels;
/** Numberof bits per pixel. */
GHOST_TUns32 bpp;
/** Refresh rate (in Hertz). */
GHOST_TUns32 frequency;
} GHOST_DisplaySetting;
#ifdef _WIN32
typedef long GHOST_TEmbedderWindowID;
#endif // _WIN32
#ifndef _WIN32
// I can't use "Window" from "<X11/Xlib.h>" because it conflits with Window defined in winlay.h
typedef int GHOST_TEmbedderWindowID;
#endif // _WIN32
/**
* A timer task callback routine.
* @param task The timer task object.
* @param time The current time.
*/
#ifdef __cplusplus
class GHOST_ITimerTask;
typedef void (*GHOST_TimerProcPtr)(GHOST_ITimerTask* task, GHOST_TUns64 time);
#else
struct GHOST_TimerTaskHandle__;
typedef void (*GHOST_TimerProcPtr)(struct GHOST_TimerTaskHandle__* task, GHOST_TUns64 time);
#endif
#endif // _GHOST_TYPES_H_

70
intern/ghost/SConscript Normal file
View File

@@ -0,0 +1,70 @@
#!/usr/bin/python
import sys
import os
Import ('env')
window_system = env['OURPLATFORM']
sources = env.Glob('intern/*.cpp')
if window_system == 'darwin':
sources += env.Glob('intern/*.mm')
pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_SystemPaths', 'GHOST_Window', 'GHOST_DropTarget']
defs=['_USE_MATH_DEFINES']
if window_system in ('linux2', 'openbsd3', 'sunos5', 'freebsd7', 'freebsd8', 'freebsd9', 'irix6', 'aix4', 'aix5'):
for f in pf:
try:
sources.remove('intern' + os.sep + f + 'Win32.cpp')
sources.remove('intern' + os.sep + f + 'Carbon.cpp')
except ValueError:
pass
defs += ['PREFIX=\\"/usr/local/\\"'] # XXX, make an option
defs += ['WITH_X11_XINPUT'] # XXX, make an option
elif window_system in ('win32-vc', 'win32-mingw', 'cygwin', 'linuxcross', 'win64-vc'):
for f in pf:
try:
sources.remove('intern' + os.sep + f + 'X11.cpp')
sources.remove('intern' + os.sep + f + 'Carbon.cpp')
except ValueError:
pass
elif window_system == 'darwin':
if env['WITH_GHOST_COCOA']:
if env['WITH_BF_QUICKTIME']:
defs.append('WITH_QUICKTIME')
if env['USE_QTKIT']:
defs.append('USE_QTKIT')
for f in pf:
try:
sources.remove('intern' + os.sep + f + 'Win32.cpp')
sources.remove('intern' + os.sep + f + 'X11.cpp')
sources.remove('intern' + os.sep + f + 'Carbon.cpp')
except ValueError:
pass
else:
for f in pf:
try:
sources.remove('intern' + os.sep + f + 'Win32.cpp')
sources.remove('intern' + os.sep + f + 'X11.cpp')
sources.remove('intern' + os.sep + f + 'Cocoa.mm')
except ValueError:
pass
else:
print "Unknown window system specified."
Exit()
if env['BF_GHOST_DEBUG']:
defs.append('BF_GHOST_DEBUG')
incs = '. ../string #extern/glew/include #source/blender/imbuf #source/blender/makesdna ' + env['BF_OPENGL_INC']
if window_system in ('win32-vc', 'win32-mingw', 'cygwin', 'linuxcross', 'win64-vc'):
incs = env['BF_WINTAB_INC'] + ' ' + incs
if window_system in ('win32-vc', 'win64-vc'):
env.BlenderLib ('bf_intern_ghost', sources, Split(incs), defines=defs, libtype=['intern','player'], priority = [40,15]) #, cc_compileflags=env['CCFLAGS'].append('/WX') )
else:
env.BlenderLib ('bf_intern_ghost', sources, Split(incs), defines=defs, libtype=['intern','player'], priority = [40,15] )

View File

@@ -0,0 +1,626 @@
#---------------------------------------------------------------------------
# General configuration options
#---------------------------------------------------------------------------
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
PROJECT_NAME = "GHOST (Generic Handy Operating System Toolkit)"
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER = 1.0
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
# If a relative path is entered, it will be relative to the location
# where doxygen was started. If left blank the current directory will be used.
OUTPUT_DIRECTORY = ./interface
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
# documentation generated by doxygen is written. Doxygen will use this
# information to generate all constant output in the proper language.
# The default language is English, other supported languages are:
# Dutch, French, Italian, Czech, Swedish, German, Finnish, Japanese,
# Korean, Hungarian, Norwegian, Spanish, Romanian, Russian, Croatian,
# Polish, Portuguese and Slovene.
OUTPUT_LANGUAGE = English
# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
# documentation are documented, even if no documentation was available.
# Private class members and static file members will be hidden unless
# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
EXTRACT_ALL = YES
# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
# will be included in the documentation.
EXTRACT_PRIVATE = NO
# If the EXTRACT_STATIC tag is set to YES all static members of a file
# will be included in the documentation.
EXTRACT_STATIC = YES
# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
# undocumented members of documented classes, files or namespaces.
# If set to NO (the default) these members will be included in the
# various overviews, but no documentation section is generated.
# This option has no effect if EXTRACT_ALL is enabled.
HIDE_UNDOC_MEMBERS = NO
# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
# undocumented classes that are normally visible in the class hierarchy.
# If set to NO (the default) these class will be included in the various
# overviews. This option has no effect if EXTRACT_ALL is enabled.
HIDE_UNDOC_CLASSES = NO
# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
# include brief member descriptions after the members that are listed in
# the file and class documentation (similar to JavaDoc).
# Set to NO to disable this.
BRIEF_MEMBER_DESC = YES
# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
# the brief description of a member or function before the detailed description.
# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
# brief descriptions will be completely suppressed.
REPEAT_BRIEF = YES
# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
# Doxygen will generate a detailed section even if there is only a brief
# description.
ALWAYS_DETAILED_SEC = YES
# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
# path before files name in the file list and in the header files. If set
# to NO the shortest path that makes the file name unique will be used.
FULL_PATH_NAMES = NO
# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
# can be used to strip a user defined part of the path. Stripping is
# only done if one of the specified strings matches the left-hand part of
# the path. It is allowed to use relative paths in the argument list.
STRIP_FROM_PATH =
# The INTERNAL_DOCS tag determines if documentation
# that is typed after a \internal command is included. If the tag is set
# to NO (the default) then the documentation will be excluded.
# Set it to YES to include the internal documentation.
INTERNAL_DOCS = NO
# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
# generate a class diagram (in Html and LaTeX) for classes with base or
# super classes. Setting the tag to NO turns the diagrams off.
CLASS_DIAGRAMS = YES
# If the SOURCE_BROWSER tag is set to YES then a list of source files will
# be generated. Documented entities will be cross-referenced with these sources.
SOURCE_BROWSER = YES
# Setting the INLINE_SOURCES tag to YES will include the body
# of functions and classes directly in the documentation.
INLINE_SOURCES = NO
# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
# doxygen to hide any special comment blocks from generated source code
# fragments. Normal C and C++ comments will always remain visible.
STRIP_CODE_COMMENTS = YES
# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
# file names in lower case letters. If set to YES upper case letters are also
# allowed. This is useful if you have classes or files whose names only differ
# in case and if your file system supports case sensitive file names. Windows
# users are adviced to set this option to NO.
CASE_SENSE_NAMES = YES
# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
# will show members with their full class and namespace scopes in the
# documentation. If set to YES the scope will be hidden.
HIDE_SCOPE_NAMES = NO
# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
# will generate a verbatim copy of the header file for each class for
# which an include is specified. Set to NO to disable this.
VERBATIM_HEADERS = YES
# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
# will put list of the files that are included by a file in the documentation
# of that file.
SHOW_INCLUDE_FILES = YES
# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
# will interpret the first line (until the first dot) of a JavaDoc-style
# comment as the brief description. If set to NO, the JavaDoc
# comments will behave just like the Qt-style comments (thus requiring an
# explict @brief command for a brief description.
JAVADOC_AUTOBRIEF = YES
# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
# member inherits the documentation from any documented member that it
# reimplements.
INHERIT_DOCS = YES
# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
# is inserted in the documentation for inline members.
INLINE_INFO = YES
# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
# will sort the (detailed) documentation of file and class members
# alphabetically by member name. If set to NO the members will appear in
# declaration order.
SORT_MEMBER_DOCS = YES
# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
# tag is set to YES, then doxygen will reuse the documentation of the first
# member in the group (if any) for the other members of the group. By default
# all members of a group must be documented explicitly.
DISTRIBUTE_GROUP_DOC = NO
# The TAB_SIZE tag can be used to set the number of spaces in a tab.
# Doxygen uses this value to replace tabs by spaces in code fragments.
TAB_SIZE = 4
# The ENABLE_SECTIONS tag can be used to enable conditional
# documentation sections, marked by \if sectionname ... \endif.
ENABLED_SECTION =
# The GENERATE_TODOLIST tag can be used to enable (YES) or
# disable (NO) the todo list. This list is created by putting \todo
# commands in the documentation
GENERATE_TODOLIST = YES
# The GENERATE_TESTLIST tag can be used to enable (YES) or
# disable (NO) the test list. This list is created by putting \test
# commands in the documentation.
GENERATE_TESTLIST = YES
# This tag can be used to specify a number of aliases that acts
# as commands in the documentation. An alias has the form "name=value".
# For example adding "sideeffect=\par Side Effects:\n" will allow you to
# put the command \sideeffect (or @sideeffect) in the documentation, which
# will result in a user defined paragraph with heading "Side Effects:".
# You can put \n's in the value part of an alias to insert newlines.
ALIASES =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
# The QUIET tag can be used to turn on/off the messages that are generated
# by doxygen. Possible values are YES and NO. If left blank NO is used.
QUIET = NO
# The WARNINGS tag can be used to turn on/off the warning messages that are
# generated by doxygen. Possible values are YES and NO. If left blank
# NO is used.
WARNINGS = YES
# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
# automatically be disabled.
WARN_IF_UNDOCUMENTED = YES
# The WARN_FORMAT tag determines the format of the warning messages that
# doxygen can produce. The string should contain the $file, $line, and $text
# tags, which will be replaced by the file and line number from which the
# warning originated and the warning text.
WARN_FORMAT = "$file:$line: $text"
# The WARN_LOGFILE tag can be used to specify a file to which warning
# and error messages should be written. If left blank the output is written
# to stderr.
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
# The INPUT tag can be used to specify the files and/or directories that contain
# documented source files. You may enter file names like "myfile.cpp" or
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = ..
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
# and *.h) to filter out the source-files in the directories. If left
# blank all files are included.
FILE_PATTERNS = *.h *.cpp *.c
# The RECURSIVE tag can be used to turn specify whether or not subdirectories
# should be searched for input files as well. Possible values are YES and NO.
# If left blank NO is used.
RECURSIVE = NO
# The EXCLUDE tag can be used to specify files and/or directories that should
# excluded from the INPUT source files. This way you can easily exclude a
# subdirectory from a directory tree whose root is specified with the INPUT tag.
EXCLUDE =
# If the value of the INPUT tag contains directories, you can use the
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
# certain files from those directories.
EXCLUDE_PATTERNS =
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see
# the \include command).
EXAMPLE_PATH = ../test
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
# and *.h) to filter out the source-files in the directories. If left
# blank all files are included.
EXAMPLE_PATTERNS = *.h *.cpp *.c
# The IMAGE_PATH tag can be used to specify one or more files or
# directories that contain image that are included in the documentation (see
# the \image command).
IMAGE_PATH =
# The INPUT_FILTER tag can be used to specify a program that doxygen should
# invoke to filter for each input file. Doxygen will invoke the filter program
# by executing (via popen()) the command <filter> <input-file>, where <filter>
# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
# input file. Doxygen will then use the output that the filter program writes
# to standard output.
INPUT_FILTER =
# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
# INPUT_FILTER) will be used to filter the input files when producing source
# files to browse.
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
# of all compounds will be generated. Enable this if the project
# contains a lot of classes, structs, unions or interfaces.
ALPHABETICAL_INDEX = YES
# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
# in which this list will be split (can be a number in the range [1..20])
COLS_IN_ALPHA_INDEX = 5
# In case all classes in a project start with a common prefix, all
# classes will be put under the same header in the alphabetical index.
# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
# should be ignored while generating the index headers.
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
# generate HTML output.
GENERATE_HTML = YES
# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `html' will be used as the default path.
HTML_OUTPUT = html
# The HTML_HEADER tag can be used to specify a personal HTML header for
# each generated HTML page. If it is left blank doxygen will generate a
# standard header.
HTML_HEADER =
# The HTML_FOOTER tag can be used to specify a personal HTML footer for
# each generated HTML page. If it is left blank doxygen will generate a
# standard footer.
HTML_FOOTER =
# The HTML_STYLESHEET tag can be used to specify a user defined cascading
# style sheet that is used by each HTML page. It can be used to
# fine-tune the look of the HTML output. If the tag is left blank doxygen
# will generate a default style sheet
HTML_STYLESHEET =
# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
# files or namespaces will be aligned in HTML using tables. If set to
# NO a bullet list will be used.
HTML_ALIGN_MEMBERS = YES
# If the GENERATE_HTMLHELP tag is set to YES, additional index files
# will be generated that can be used as input for tools like the
# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
# of the generated HTML documentation.
GENERATE_HTMLHELP = YES
# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
# top of each HTML page. The value NO (the default) enables the index and
# the value YES disables it.
DISABLE_INDEX = NO
# This tag can be used to set the number of enum values (range [1..20])
# that doxygen will group on one line in the generated HTML documentation.
ENUM_VALUES_PER_LINE = 4
# If the GENERATE_TREEVIEW tag is set to YES, a side pannel will be
# generated containing a tree-like index structure (just like the one that
# is generated for HTML Help). For this to work a browser that supports
# JavaScript and frames is required (for instance Netscape 4.0+
# or Internet explorer 4.0+).
GENERATE_TREEVIEW = YES
# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
# used to set the initial width (in pixels) of the frame in which the tree
# is shown.
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
# generate Latex output.
GENERATE_LATEX = NO
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `latex' will be used as the default path.
LATEX_OUTPUT = latex
# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
# LaTeX documents. This may be useful for small projects and may help to
# save some trees in general.
COMPACT_LATEX = NO
# The PAPER_TYPE tag can be used to set the paper type that is used
# by the printer. Possible values are: a4, a4wide, letter, legal and
# executive. If left blank a4wide will be used.
PAPER_TYPE = a4wide
# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
# packages that should be included in the LaTeX output.
EXTRA_PACKAGES =
# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
# the generated latex document. The header should contain everything until
# the first chapter. If it is left blank doxygen will generate a
# standard header. Notice: only use this tag if you know what you are doing!
LATEX_HEADER =
# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
# is prepared for conversion to pdf (using ps2pdf). The pdf file will
# contain links (just like the HTML output) instead of page references
# This makes the output suitable for online browsing using a pdf viewer.
PDF_HYPERLINKS = NO
# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
# plain latex in the generated Makefile. Set this option to YES to get a
# higher quality PDF documentation.
USE_PDFLATEX = NO
# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
# command to the generated LaTeX files. This will instruct LaTeX to keep
# running if errors occur, instead of asking the user for help.
# This option is also used when generating formulas in HTML.
LATEX_BATCHMODE = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
# The RTF output is optimised for Word 97 and may not look very pretty with
# other RTF readers or editors.
GENERATE_RTF = NO
# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `rtf' will be used as the default path.
RTF_OUTPUT = rtf
# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
# RTF documents. This may be useful for small projects and may help to
# save some trees in general.
COMPACT_RTF = NO
# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
# will contain hyperlink fields. The RTF file will
# contain links (just like the HTML output) instead of page references.
# This makes the output suitable for online browsing using a WORD or other.
# programs which support those fields.
# Note: wordpad (write) and others do not support links.
RTF_HYPERLINKS = NO
# Load stylesheet definitions from file. Syntax is similar to doxygen's
# config file, i.e. a series of assigments. You only have to provide
# replacements, missing definitions are set to their default value.
RTF_STYLESHEET_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
# generate man pages
GENERATE_MAN = NO
# The MAN_OUTPUT tag is used to specify where the man pages will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `man' will be used as the default path.
MAN_OUTPUT = man
# The MAN_EXTENSION tag determines the extension that is added to
# the generated man pages (default is the subroutine's section .3)
MAN_EXTENSION = .3
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
# If the GENERATE_XML tag is set to YES Doxygen will
# generate an XML file that captures the structure of
# the code including all documentation. Warning: This feature
# is still experimental and very incomplete.
GENERATE_XML = NO
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
# evaluate all C-preprocessor directives found in the sources and include
# files.
ENABLE_PREPROCESSING = YES
# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
# names in the source code. If set to NO (the default) only conditional
# compilation will be performed. Macro expansion can be done in a controlled
# way by setting EXPAND_ONLY_PREDEF to YES.
MACRO_EXPANSION = NO
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
# then the macro expansion is limited to the macros specified with the
# PREDEFINED and EXPAND_AS_PREDEFINED tags.
EXPAND_ONLY_PREDEF = NO
# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
# in the INCLUDE_PATH (see below) will be search if a #include is found.
SEARCH_INCLUDES = YES
# The INCLUDE_PATH tag can be used to specify one or more directories that
# contain include files that are not input files but should be processed by
# the preprocessor.
INCLUDE_PATH =
# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
# patterns (like *.h and *.hpp) to filter out the header-files in the
# directories. If left blank, the patterns specified with FILE_PATTERNS will
# be used.
INCLUDE_FILE_PATTERNS =
# The PREDEFINED tag can be used to specify one or more macro names that
# are defined before the preprocessor is started (similar to the -D option of
# gcc). The argument of the tag is a list of macros of the form: name
# or name=definition (no spaces). If the definition and the = are
# omitted =1 is assumed.
PREDEFINED =
# If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.
# The macro definition that is found in the sources will be used.
# Use the PREDEFINED tag if you want to use a different macro definition.
EXPAND_AS_DEFINED =
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
# The TAGFILES tag can be used to specify one or more tagfiles.
TAGFILES =
# When a file name is specified after GENERATE_TAGFILE, doxygen will create
# a tag file that is based on the input files it reads.
GENERATE_TAGFILE =
# If the ALLEXTERNALS tag is set to YES all external classes will be listed
# in the class index. If set to NO only the inherited external classes
# will be listed.
ALLEXTERNALS =
# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of `which perl').
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
# available from the path. This tool is part of Graphviz, a graph visualization
# toolkit from AT&T and Lucent Bell Labs. The other options in this section
# have no effect if this option is set to NO (the default)
HAVE_DOT = YES
# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
# will generate a graph for each documented class showing the direct and
# indirect inheritance relations. Setting this tag to YES will force the
# the CLASS_DIAGRAMS tag to NO.
CLASS_GRAPH = YES
# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
# will generate a graph for each documented class showing the direct and
# indirect implementation dependencies (inheritance, containment, and
# class references variables) of the class with other documented classes.
COLLABORATION_GRAPH = YES
# If the ENABLE_PREPROCESSING, INCLUDE_GRAPH, and HAVE_DOT tags are set to
# YES then doxygen will generate a graph for each documented file showing
# the direct and indirect include dependencies of the file with other
# documented files.
INCLUDE_GRAPH = YES
# If the ENABLE_PREPROCESSING, INCLUDED_BY_GRAPH, and HAVE_DOT tags are set to
# YES then doxygen will generate a graph for each documented header file showing
# the documented files that directly or indirectly include this file
INCLUDED_BY_GRAPH = YES
# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
# will graphical hierarchy of all classes instead of a textual one.
GRAPHICAL_HIERARCHY = YES
# The tag DOT_PATH can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found on the path.
DOT_PATH =
# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
# (in pixels) of the graphs generated by dot. If a graph becomes larger than
# this value, doxygen will try to truncate the graph, so that it fits within
# the specified constraint. Beware that most browsers cannot cope with very
# large images.
MAX_DOT_GRAPH_WIDTH = 1024
# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
# (in pixels) of the graphs generated by dot. If a graph becomes larger than
# this value, doxygen will try to truncate the graph, so that it fits within
# the specified constraint. Beware that most browsers cannot cope with very
# large images.
MAX_DOT_GRAPH_HEIGHT = 1024
# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
# generate a legend page explaining the meaning of the various boxes and
# arrows in the dot generated graphs.
GENERATE_LEGEND = YES
#---------------------------------------------------------------------------
# Configuration::addtions related to the search engine
#---------------------------------------------------------------------------
# The SEARCHENGINE tag specifies whether or not a search engine should be
# used. If set to NO the values of all tags below this one will be ignored.
SEARCHENGINE = NO
# The CGI_NAME tag should be the name of the CGI script that
# starts the search engine (doxysearch) with the correct parameters.
# A script with this name will be generated by doxygen.
CGI_NAME= search.cgi
# The CGI_URL tag should be the absolute URL to the directory where the
# cgi binaries are located. See the documentation of your http daemon for
# details.
CGI_URL=
# The DOC_URL tag should be the absolute URL to the directory where the
# documentation is located. If left blank the absolute path to the
# documentation, with file:// prepended to it, will be used.
DOC_URL=
# The DOC_ABSPATH tag should be the absolute path to the directory where the
# documentation is located. If left blank the directory on the local machine
# will be used.
DOC_ABSPATH=
# The BIN_ABSPATH tag must point to the directory where the doxysearch binary
# is installed.
BIN_ABSPATH= /bin
# The EXT_DOC_PATHS tag can be used to specify one or more paths to
# documentation generated for other projects. This allows doxysearch to search
# the documentation for these projects as well.
EXT_DOC_PATHS=

View File

@@ -0,0 +1,79 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Buttons.cpp
* \ingroup GHOST
*/
#include "GHOST_Buttons.h"
GHOST_Buttons::GHOST_Buttons()
{
clear();
}
bool GHOST_Buttons::get(GHOST_TButtonMask mask) const
{
switch (mask) {
case GHOST_kButtonMaskLeft:
return m_ButtonLeft;
case GHOST_kButtonMaskMiddle:
return m_ButtonMiddle;
case GHOST_kButtonMaskRight:
return m_ButtonRight;
default:
return false;
}
}
void GHOST_Buttons::set(GHOST_TButtonMask mask, bool down)
{
switch (mask) {
case GHOST_kButtonMaskLeft:
m_ButtonLeft = down; break;
case GHOST_kButtonMaskMiddle:
m_ButtonMiddle = down; break;
case GHOST_kButtonMaskRight:
m_ButtonRight = down; break;
default:
break;
}
}
void GHOST_Buttons::clear()
{
m_ButtonLeft = false;
m_ButtonMiddle = false;
m_ButtonRight = false;
}
GHOST_Buttons::~GHOST_Buttons() {}

View File

@@ -0,0 +1,79 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Buttons.h
* \ingroup GHOST
* Declaration of GHOST_Buttons struct.
*/
#ifndef _GHOST_BUTTONS_H_
#define _GHOST_BUTTONS_H_
#include "GHOST_Types.h"
/**
* This struct stores the state of the mouse buttons.
* Buttons can be set using button masks.
* @author Maarten Gribnau
* @date May 15, 2001
*/
struct GHOST_Buttons {
/**
* Constructor.
*/
GHOST_Buttons();
virtual ~GHOST_Buttons();
/**
* Returns the state of a single button.
* @param mask. Key button to return.
* @return The state of the button (pressed == true).
*/
virtual bool get(GHOST_TButtonMask mask) const;
/**
* Updates the state of a single button.
* @param mask. Button state to update.
* @param down. The new state of the button.
*/
virtual void set(GHOST_TButtonMask mask, bool down);
/**
* Sets the state of all buttons to up.
*/
virtual void clear();
GHOST_TUns8 m_ButtonLeft : 1;
GHOST_TUns8 m_ButtonMiddle : 1;
GHOST_TUns8 m_ButtonRight : 1;
};
#endif // _GHOST_BUTTONS_H_

View File

@@ -0,0 +1,885 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_C-api.cpp
* \ingroup GHOST
*/
/*
* GHOST_C-Api.cpp
*
* C Api for GHOST
*
* Version: $Id$
*/
#include <stdlib.h>
#include "intern/GHOST_Debug.h"
#include "GHOST_C-api.h"
#include "GHOST_ISystem.h"
#include "GHOST_IEvent.h"
#include "GHOST_IEventConsumer.h"
#include "intern/GHOST_CallbackEventConsumer.h"
GHOST_SystemHandle GHOST_CreateSystem(void)
{
GHOST_ISystem::createSystem();
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return (GHOST_SystemHandle)system;
}
GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->disposeSystem();
}
GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback, GHOST_TUserDataPtr userdata)
{
return (GHOST_EventConsumerHandle) new GHOST_CallbackEventConsumer (eventCallback, userdata);
}
GHOST_TSuccess GHOST_DisposeEventConsumer(GHOST_EventConsumerHandle consumerhandle)
{
delete ((GHOST_CallbackEventConsumer*)consumerhandle);
return GHOST_kSuccess;
}
GHOST_TUns64 GHOST_GetMilliSeconds(GHOST_SystemHandle systemhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->getMilliSeconds();
}
GHOST_TimerTaskHandle GHOST_InstallTimer(GHOST_SystemHandle systemhandle,
GHOST_TUns64 delay,
GHOST_TUns64 interval,
GHOST_TimerProcPtr timerproc,
GHOST_TUserDataPtr userdata)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return (GHOST_TimerTaskHandle) system->installTimer(delay, interval, timerproc, userdata);
}
GHOST_TSuccess GHOST_RemoveTimer(GHOST_SystemHandle systemhandle,
GHOST_TimerTaskHandle timertaskhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
return system->removeTimer(timertask);
}
GHOST_TUns8 GHOST_GetNumDisplays(GHOST_SystemHandle systemhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->getNumDisplays();
}
void GHOST_GetMainDisplayDimensions(GHOST_SystemHandle systemhandle,
GHOST_TUns32* width,
GHOST_TUns32* height)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
system->getMainDisplayDimensions(*width, *height);
}
GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
const char* title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const int stereoVisual,
const GHOST_TUns16 numOfAASamples)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
bool bstereoVisual;
if(stereoVisual)
bstereoVisual = true;
else
bstereoVisual = false;
return (GHOST_WindowHandle) system->createWindow(title, left, top, width, height,
state, type, bstereoVisual, numOfAASamples);
}
GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->getUserData();
}
void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr userdata)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
window->setUserData(userdata);
}
GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle,
GHOST_WindowHandle windowhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return system->disposeWindow(window);
}
int GHOST_ValidWindow(GHOST_SystemHandle systemhandle,
GHOST_WindowHandle windowhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return (int) system->validWindow(window);
}
GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle,
GHOST_DisplaySetting* setting,
const int stereoVisual)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
GHOST_IWindow* window = NULL;
bool bstereoVisual;
if(stereoVisual)
bstereoVisual = true;
else
bstereoVisual = false;
system->beginFullScreen(*setting, &window, bstereoVisual);
return (GHOST_WindowHandle)window;
}
GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->endFullScreen();
}
int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return (int) system->getFullScreen();
}
int GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, int waitForEvent)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return (int) system->processEvents(waitForEvent?true:false);
}
int GHOST_DispatchEvents(GHOST_SystemHandle systemhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return (int) system->dispatchEvents();
}
GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->addEventConsumer((GHOST_CallbackEventConsumer*)consumerhandle);
}
GHOST_TSuccess GHOST_RemoveEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->removeEventConsumer((GHOST_CallbackEventConsumer*)consumerhandle);
}
GHOST_TSuccess GHOST_SetProgressBar(GHOST_WindowHandle windowhandle,float progress)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setProgressBar(progress);
}
GHOST_TSuccess GHOST_EndProgressBar(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->endProgressBar();
}
int GHOST_OpenNDOF(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
//original patch only
/* GHOST_NDOFEventHandler_fp setNdofEventHandler)*/
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->openNDOF((GHOST_IWindow*) windowhandle,
setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen);
// original patch
// setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen, setNdofEventHandler);
}
GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->getCursorShape();
}
GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle,
GHOST_TStandardCursor cursorshape)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setCursorShape(cursorshape);
}
GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle,
GHOST_TUns8 bitmap[16][2],
GHOST_TUns8 mask[16][2],
int hotX,
int hotY)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setCustomCursorShape(bitmap, mask, hotX, hotY);
}
GHOST_TSuccess GHOST_SetCustomCursorShapeEx(GHOST_WindowHandle windowhandle,
GHOST_TUns8 *bitmap,
GHOST_TUns8 *mask,
int sizex,
int sizey,
int hotX,
int hotY,
int fg_color,
int bg_color)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setCustomCursorShape(bitmap, mask, sizex, sizey,
hotX, hotY, fg_color, bg_color);
}
int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return (int) window->getCursorVisibility();
}
GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle,
int visible)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setCursorVisibility(visible?true:false);
}
GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle,
GHOST_TInt32* x,
GHOST_TInt32* y)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->getCursorPosition(*x, *y);
}
GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
GHOST_TInt32 x,
GHOST_TInt32 y)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->setCursorPosition(x, y);
}
GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
GHOST_TGrabCursorMode mode,
int *bounds)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
GHOST_Rect bounds_rect, bounds_win;
if(bounds) {
/* if this is X11 specific we need a function that converts */
window->getClientBounds(bounds_win);
window->clientToScreen(bounds[0], bounds_win.getHeight() - bounds[1], bounds_rect.m_l, bounds_rect.m_t);
window->clientToScreen(bounds[2], bounds_win.getHeight() - bounds[3], bounds_rect.m_r, bounds_rect.m_b);
}
return window->setCursorGrab(mode, bounds ? &bounds_rect:NULL);
}
GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle,
GHOST_TModifierKeyMask mask,
int* isDown)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
GHOST_TSuccess result;
bool isdown= false;
result = system->getModifierKeyState(mask, isdown);
*isDown = (int) isdown;
return result;
}
GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle,
GHOST_TButtonMask mask,
int* isDown)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
GHOST_TSuccess result;
bool isdown= false;
result = system->getButtonState(mask, isdown);
*isDown = (int) isdown;
return result;
}
void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, GHOST_TInt8 canAccept)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
window->setAcceptDragOperation(canAccept);
}
GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
{
GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;
return event->getType();
}
GHOST_TUns64 GHOST_GetEventTime(GHOST_EventHandle eventhandle)
{
GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;
return event->getTime();
}
GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle)
{
GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;
return (GHOST_WindowHandle) event->getWindow();
}
GHOST_TEventDataPtr GHOST_GetEventData(GHOST_EventHandle eventhandle)
{
GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;
return event->getData();
}
GHOST_TimerProcPtr GHOST_GetTimerProc(GHOST_TimerTaskHandle timertaskhandle)
{
GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
return timertask->getTimerProc();
}
void GHOST_SetTimerProc(GHOST_TimerTaskHandle timertaskhandle,
GHOST_TimerProcPtr timerproc)
{
GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
timertask->setTimerProc(timerproc);
}
GHOST_TUserDataPtr GHOST_GetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle)
{
GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
return timertask->getUserData();
}
void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle,
GHOST_TUserDataPtr userdata)
{
GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
timertask->setUserData(userdata);
}
int GHOST_GetValid(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return (int) window->getValid();
}
GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->getDrawingContextType();
}
GHOST_TSuccess GHOST_SetDrawingContextType(GHOST_WindowHandle windowhandle,
GHOST_TDrawingContextType type)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setDrawingContextType(type);
}
void GHOST_SetTitle(GHOST_WindowHandle windowhandle,
const char* title)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
window->setTitle(title);
}
char* GHOST_GetTitle(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
STR_String title;
window->getTitle(title);
char *ctitle = (char*) malloc(title.Length() + 1);
if (ctitle == NULL) return NULL;
strcpy(ctitle, title.Ptr());
return ctitle;
}
GHOST_RectangleHandle GHOST_GetWindowBounds(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
GHOST_Rect* rectangle = NULL;
rectangle = new GHOST_Rect();
window->getWindowBounds(*rectangle);
return (GHOST_RectangleHandle)rectangle;
}
GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
GHOST_Rect* rectangle = NULL;
rectangle = new GHOST_Rect();
window->getClientBounds(*rectangle);
return (GHOST_RectangleHandle)rectangle;
}
void GHOST_DisposeRectangle(GHOST_RectangleHandle rectanglehandle)
{
delete (GHOST_Rect*) rectanglehandle;
}
GHOST_TSuccess GHOST_SetClientWidth(GHOST_WindowHandle windowhandle,
GHOST_TUns32 width)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setClientWidth(width);
}
GHOST_TSuccess GHOST_SetClientHeight(GHOST_WindowHandle windowhandle,
GHOST_TUns32 height)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setClientHeight(height);
}
GHOST_TSuccess GHOST_SetClientSize(GHOST_WindowHandle windowhandle,
GHOST_TUns32 width,
GHOST_TUns32 height)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setClientSize(width, height);
}
void GHOST_ScreenToClient(GHOST_WindowHandle windowhandle,
GHOST_TInt32 inX,
GHOST_TInt32 inY,
GHOST_TInt32* outX,
GHOST_TInt32* outY)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
window->screenToClient(inX, inY, *outX, *outY);
}
void GHOST_ClientToScreen(GHOST_WindowHandle windowhandle,
GHOST_TInt32 inX,
GHOST_TInt32 inY,
GHOST_TInt32* outX,
GHOST_TInt32* outY)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
window->clientToScreen(inX, inY, *outX, *outY);
}
GHOST_TWindowState GHOST_GetWindowState(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->getState();
}
GHOST_TSuccess GHOST_SetWindowState(GHOST_WindowHandle windowhandle,
GHOST_TWindowState state)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setState(state);
}
GHOST_TSuccess GHOST_SetWindowModifiedState(GHOST_WindowHandle windowhandle, GHOST_TUns8 isUnsavedChanges)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setModifiedState(isUnsavedChanges);
}
GHOST_TSuccess GHOST_SetWindowOrder(GHOST_WindowHandle windowhandle,
GHOST_TWindowOrder order)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->setOrder(order);
}
GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->swapBuffers();
}
GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->activateDrawingContext();
}
GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
return window->invalidate();
}
extern const GHOST_TabletData* GHOST_GetTabletData(GHOST_WindowHandle windowhandle)
{
return ((GHOST_IWindow*)windowhandle)->GetTabletData();
}
GHOST_TInt32 GHOST_GetWidthRectangle(GHOST_RectangleHandle rectanglehandle)
{
return ((GHOST_Rect*)rectanglehandle)->getWidth();
}
GHOST_TInt32 GHOST_GetHeightRectangle(GHOST_RectangleHandle rectanglehandle)
{
return ((GHOST_Rect*)rectanglehandle)->getHeight();
}
void GHOST_GetRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32* l,
GHOST_TInt32* t,
GHOST_TInt32* r,
GHOST_TInt32* b)
{
GHOST_Rect *rect= (GHOST_Rect*) rectanglehandle;
*l= rect->m_l;
*t= rect->m_t;
*r= rect->m_r;
*b= rect->m_b;
}
void GHOST_SetRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 l,
GHOST_TInt32 t,
GHOST_TInt32 r,
GHOST_TInt32 b)
{
((GHOST_Rect*)rectanglehandle)->set(l, t, r, b);
}
GHOST_TSuccess GHOST_IsEmptyRectangle(GHOST_RectangleHandle rectanglehandle)
{
GHOST_TSuccess result = GHOST_kFailure;
if (((GHOST_Rect*)rectanglehandle)->isEmpty())
result = GHOST_kSuccess;
return result;
}
GHOST_TSuccess GHOST_IsValidRectangle(GHOST_RectangleHandle rectanglehandle)
{
GHOST_TSuccess result = GHOST_kFailure;
if(((GHOST_Rect*)rectanglehandle)->isValid())
result = GHOST_kSuccess;
return result;
}
void GHOST_InsetRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 i)
{
((GHOST_Rect*)rectanglehandle)->inset(i);
}
void GHOST_UnionRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_RectangleHandle anotherrectanglehandle)
{
((GHOST_Rect*)rectanglehandle)->unionRect(*(GHOST_Rect*)anotherrectanglehandle);
}
void GHOST_UnionPointRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 x,
GHOST_TInt32 y)
{
((GHOST_Rect*)rectanglehandle)->unionPoint(x, y);
}
GHOST_TSuccess GHOST_IsInsideRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 x,
GHOST_TInt32 y)
{
GHOST_TSuccess result = GHOST_kFailure;
if (((GHOST_Rect*)rectanglehandle)->isInside(x, y))
result = GHOST_kSuccess;
return result;
}
GHOST_TVisibility GHOST_GetRectangleVisibility(GHOST_RectangleHandle rectanglehandle,
GHOST_RectangleHandle anotherrectanglehandle)
{
GHOST_TVisibility visible = GHOST_kNotVisible;
visible = ((GHOST_Rect*)rectanglehandle)->getVisibility(*(GHOST_Rect*)anotherrectanglehandle);
return visible;
}
void GHOST_SetCenterRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 cx,
GHOST_TInt32 cy)
{
((GHOST_Rect*)rectanglehandle)->setCenter(cx, cy);
}
void GHOST_SetRectangleCenter(GHOST_RectangleHandle rectanglehandle,
GHOST_TInt32 cx,
GHOST_TInt32 cy,
GHOST_TInt32 w,
GHOST_TInt32 h)
{
((GHOST_Rect*)rectanglehandle)->setCenter(cx, cy, w, h);
}
GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
GHOST_RectangleHandle anotherrectanglehandle)
{
GHOST_TSuccess result = GHOST_kFailure;
if (((GHOST_Rect*)rectanglehandle)->clip(*(GHOST_Rect*)anotherrectanglehandle))
result = GHOST_kSuccess;
return result;
}
GHOST_TUns8* GHOST_getClipboard(int selection)
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system->getClipboard(selection);
}
void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection)
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
system->putClipboard(buffer, selection);
}
int GHOST_toggleConsole(int action)
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system->toggleConsole(action);
}

View File

@@ -0,0 +1,57 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_CallbackEventConsumer.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date October 25, 2001
*/
#include "GHOST_Debug.h"
#include "GHOST_C-api.h"
#include "GHOST_CallbackEventConsumer.h"
GHOST_CallbackEventConsumer::GHOST_CallbackEventConsumer(GHOST_EventCallbackProcPtr eventCallback,
GHOST_TUserDataPtr userData)
{
m_eventCallback = eventCallback;
m_userData = userData;
}
bool GHOST_CallbackEventConsumer::processEvent(GHOST_IEvent* event)
{
return m_eventCallback((GHOST_EventHandle)event, m_userData) != 0;
}

View File

@@ -0,0 +1,80 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_CallbackEventConsumer.h
* \ingroup GHOST
* Declaration of GHOST_CallbackEventConsumer class.
*/
#ifndef _GHOST_CALLBACK_EVENT_CONSUMER_H_
#define _GHOST_CALLBACK_EVENT_CONSUMER_H_
#include "GHOST_IEventConsumer.h"
#include "GHOST_C-api.h"
/**
* Event consumer that will forward events to a call-back routine.
* Especially useful for the C-API.
* @author Maarten Gribnau
* @date October 25, 2001
*/
class GHOST_CallbackEventConsumer : public GHOST_IEventConsumer
{
public:
/**
* Constructor.
* @param eventCallback The call-back routine invoked.
* @param userData The data passed back though the call-back routine.
*/
GHOST_CallbackEventConsumer(
GHOST_EventCallbackProcPtr eventCallback,
GHOST_TUserDataPtr userData);
/**
* Destructor.
*/
virtual ~GHOST_CallbackEventConsumer(void)
{
}
/**
* This method is called by an event producer when an event is available.
* @param event The event that can be handled or ignored.
* @return Indication as to whether the event was handled.
*/
virtual bool processEvent(GHOST_IEvent* event);
protected:
/** The call-back routine invoked. */
GHOST_EventCallbackProcPtr m_eventCallback;
/** The data passed back though the call-back routine. */
GHOST_TUserDataPtr m_userData;
};
#endif // _GHOST_CALLBACK_EVENT_CONSUMER_H_

View File

@@ -0,0 +1,70 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Debug.h
* \ingroup GHOST
* Macro's used in GHOST debug target.
*/
#ifndef _GHOST_DEBUG_H_
#define _GHOST_DEBUG_H_
#if defined(WIN32) && !defined(FREE_WINDOWS)
#ifdef DEBUG
#pragma warning (disable:4786) // suppress stl-MSVC debug info warning
// #define GHOST_DEBUG
#endif // DEBUG
#endif // WIN32
#ifdef BF_GHOST_DEBUG
#define GHOST_DEBUG // spit ghost events to stdout
#endif // BF_GHOST_DEBUG
#ifdef GHOST_DEBUG
#include <iostream>
#include <stdio.h> //for printf()
#endif // GHOST_DEBUG
#ifdef GHOST_DEBUG
#define GHOST_PRINT(x) { std::cout << x; }
#define GHOST_PRINTF(x, ...) { printf(x, __VA_ARGS__); }
#else // GHOST_DEBUG
#define GHOST_PRINT(x)
#define GHOST_PRINTF(x, ...)
#endif // GHOST_DEBUG
#ifdef GHOST_DEBUG
#define GHOST_ASSERT(x, info) { if (!(x)) {GHOST_PRINT("assertion failed: "); GHOST_PRINT(info); GHOST_PRINT("\n"); } }
#else // GHOST_DEBUG
#define GHOST_ASSERT(x, info)
#endif // GHOST_DEBUG
#endif // _GHOST_DEBUG_H_

View File

@@ -0,0 +1,218 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManager.cpp
* \ingroup GHOST
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date September 21, 2001
*/
#include "GHOST_DisplayManager.h"
#include "GHOST_Debug.h"
GHOST_DisplayManager::GHOST_DisplayManager(
void)
: m_settingsInitialized(false)
{
}
GHOST_DisplayManager::~GHOST_DisplayManager(void)
{
}
GHOST_TSuccess
GHOST_DisplayManager::initialize(
void)
{
GHOST_TSuccess success;
if (!m_settingsInitialized) {
success = initializeSettings();
m_settingsInitialized = true;
}
else {
success = GHOST_kSuccess;
}
return success;
}
GHOST_TSuccess
GHOST_DisplayManager::getNumDisplays(
GHOST_TUns8& /*numDisplays*/) const
{
// Don't know if we have a display...
return GHOST_kFailure;
}
GHOST_TSuccess
GHOST_DisplayManager::getNumDisplaySettings(
GHOST_TUns8 display,
GHOST_TInt32& numSettings) const
{
GHOST_TSuccess success;
GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::getNumDisplaySettings(): m_settingsInitialized=false");
GHOST_TUns8 numDisplays;
success = getNumDisplays(numDisplays);
if (success == GHOST_kSuccess) {
if (display < numDisplays) {
numSettings = m_settings[display].size();
}
else {
success = GHOST_kFailure;
}
}
return success;
}
GHOST_TSuccess
GHOST_DisplayManager::getDisplaySetting(
GHOST_TUns8 display,
GHOST_TInt32 index,
GHOST_DisplaySetting& setting) const
{
GHOST_TSuccess success;
GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::getNumDisplaySettings(): m_settingsInitialized=false");
GHOST_TUns8 numDisplays;
success = getNumDisplays(numDisplays);
if (success == GHOST_kSuccess) {
if (display < numDisplays && ((GHOST_TUns8)index < m_settings[display].size())) {
setting = m_settings[display][index];
}
else {
success = GHOST_kFailure;
}
}
return success;
}
GHOST_TSuccess
GHOST_DisplayManager::getCurrentDisplaySetting(
GHOST_TUns8 /*display*/,
GHOST_DisplaySetting& /*setting*/) const
{
return GHOST_kFailure;
}
GHOST_TSuccess
GHOST_DisplayManager::setCurrentDisplaySetting(
GHOST_TUns8 /*display*/,
const GHOST_DisplaySetting& /*setting*/)
{
return GHOST_kFailure;
}
GHOST_TSuccess
GHOST_DisplayManager::findMatch(
GHOST_TUns8 display,
const GHOST_DisplaySetting& setting,
GHOST_DisplaySetting& match) const
{
GHOST_TSuccess success = GHOST_kSuccess;
GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::findMatch(): m_settingsInitialized=false");
int criteria[4] = { setting.xPixels, setting.yPixels, setting.bpp, setting.frequency };
int capabilities[4];
double field, score;
double best = 1e12; // A big number
int found = 0;
// Look at all the display modes
for (int i = 0; (i < (int)m_settings[display].size()); i++) {
// Store the capabilities of the display device
capabilities[0] = m_settings[display][i].xPixels;
capabilities[1] = m_settings[display][i].yPixels;
capabilities[2] = m_settings[display][i].bpp;
capabilities[3] = m_settings[display][i].frequency;
// Match against all the fields of the display settings
score = 0;
for (int j = 0; j < 4; j++) {
field = capabilities[j] - criteria[j];
score += field * field;
}
if (score < best) {
found = i;
best = score;
}
}
match = m_settings[display][found];
GHOST_PRINT("GHOST_DisplayManager::findMatch(): settings of match:\n");
GHOST_PRINT(" setting.xPixels=" << match.xPixels << "\n");
GHOST_PRINT(" setting.yPixels=" << match.yPixels << "\n");
GHOST_PRINT(" setting.bpp=" << match.bpp << "\n");
GHOST_PRINT(" setting.frequency=" << match.frequency << "\n");
return success;
}
GHOST_TSuccess
GHOST_DisplayManager::initializeSettings(
void)
{
GHOST_TUns8 numDisplays;
GHOST_TSuccess success = getNumDisplays(numDisplays);
if (success == GHOST_kSuccess) {
for (GHOST_TUns8 display = 0; (display < numDisplays) && (success == GHOST_kSuccess); display++) {
GHOST_DisplaySettings displaySettings;
m_settings.push_back(displaySettings);
GHOST_TInt32 numSettings;
success = getNumDisplaySettings(display, numSettings);
if (success == GHOST_kSuccess) {
GHOST_TInt32 index;
GHOST_DisplaySetting setting;
for (index = 0; (index < numSettings) && (success == GHOST_kSuccess); index++) {
success = getDisplaySetting(display, index, setting);
m_settings[display].push_back(setting);
}
}
else {
break;
}
}
}
return success;
}

View File

@@ -0,0 +1,134 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManager.h
* \ingroup GHOST
* Declaration of GHOST_DisplayManager class.
*/
#ifndef _GHOST_DISPLAY_MANAGER_H_
#define _GHOST_DISPLAY_MANAGER_H_
#include "GHOST_Types.h"
#include <vector>
/**
* Manages system displays (platform independent implementation).
* @author Maarten Gribnau
* @date September 21, 2001
*/
class GHOST_DisplayManager
{
public:
enum { kMainDisplay = 0 };
/**
* Constructor.
*/
GHOST_DisplayManager(void);
/**
* Destructor.
*/
virtual ~GHOST_DisplayManager(void);
/**
* Initializes the list with devices and settings.
* @return Indication of success.
*/
virtual GHOST_TSuccess initialize(void);
/**
* Returns the number of display devices on this system.
* @param numDisplays The number of displays on this system.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const;
/**
* Returns the number of display settings for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The number of settings of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param index The setting index to be returned.
* @param setting The setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const;
/**
* Changes the current setting for this display device.
* The setting given to this method is matched againts the available diplay settings.
* The best match is activated (@see findMatch()).
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The setting of the display device to be matched and activated.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting);
protected:
typedef std::vector<GHOST_DisplaySetting> GHOST_DisplaySettings;
/**
* Finds the best display settings match.
* @param display The index of the display device.
* @param setting The setting to match.
* @param match The optimal display setting.
* @return Indication of success.
*/
GHOST_TSuccess findMatch(GHOST_TUns8 display, const GHOST_DisplaySetting& setting, GHOST_DisplaySetting& match) const;
/**
* Retrieves settings for each display device and stores them.
* @return Indication of success.
*/
GHOST_TSuccess initializeSettings(void);
/** Tells whether the list of display modes has been stored already. */
bool m_settingsInitialized;
/** The list with display settings for the main display. */
std::vector<GHOST_DisplaySettings> m_settings;
};
#endif // _GHOST_DISPLAY_MANAGER_H_

View File

@@ -0,0 +1,179 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerCarbon.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date September 21, 2001
*/
#include "GHOST_DisplayManagerCarbon.h"
#include "GHOST_Debug.h"
// We do not support multiple monitors at the moment
GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(void)
{
if (::CGGetActiveDisplayList(0, NULL, &m_numDisplays) != CGDisplayNoErr)
{
m_numDisplays = 0;
m_displayIDs = NULL;
}
if (m_numDisplays > 0)
{
m_displayIDs = new CGDirectDisplayID [m_numDisplays];
GHOST_ASSERT((m_displayIDs!=NULL), "GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(): memory allocation failed");
::CGGetActiveDisplayList(m_numDisplays, m_displayIDs, &m_numDisplays);
}
}
GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplays(GHOST_TUns8& numDisplays) const
{
numDisplays = (GHOST_TUns8) m_numDisplays;
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getNumDisplaySettings(): only main display is supported");
CFArrayRef displayModes;
displayModes = ::CGDisplayAvailableModes(m_displayIDs[display]);
CFIndex numModes = ::CFArrayGetCount(displayModes);
numSettings = (GHOST_TInt32)numModes;
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCarbon::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getDisplaySetting(): only main display is supported");
CFArrayRef displayModes;
CGDirectDisplayID d = m_displayIDs[display];
displayModes = ::CGDisplayAvailableModes(d);
//CFIndex numModes = ::CFArrayGetCount(displayModes);/*unused*/
//GHOST_TInt32 numSettings = (GHOST_TInt32)numModes; /*unused*/
CFDictionaryRef displayModeValues = (CFDictionaryRef)::CFArrayGetValueAtIndex(displayModes, index);
setting.xPixels = getValue(displayModeValues, kCGDisplayWidth);
setting.yPixels = getValue(displayModeValues, kCGDisplayHeight);
setting.bpp = getValue(displayModeValues, kCGDisplayBitsPerPixel);
setting.frequency = getValue(displayModeValues, kCGDisplayRefreshRate);
#ifdef GHOST_DEBUG
printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
#endif // GHOST_DEBUG
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(): only main display is supported");
CFDictionaryRef displayModeValues = ::CGDisplayCurrentMode(m_displayIDs[display]);
setting.xPixels = getValue(displayModeValues, kCGDisplayWidth);
setting.yPixels = getValue(displayModeValues, kCGDisplayHeight);
setting.bpp = getValue(displayModeValues, kCGDisplayBitsPerPixel);
setting.frequency = getValue(displayModeValues, kCGDisplayRefreshRate);
#ifdef GHOST_DEBUG
printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
#endif // GHOST_DEBUG
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): only main display is supported");
#ifdef GHOST_DEBUG
printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): requested settings:\n");
printf(" setting.xPixels=%d\n", setting.xPixels);
printf(" setting.yPixels=%d\n", setting.yPixels);
printf(" setting.bpp=%d\n", setting.bpp);
printf(" setting.frequency=%d\n", setting.frequency);
#endif // GHOST_DEBUG
CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
m_displayIDs[display],
(size_t)setting.bpp,
(size_t)setting.xPixels,
(size_t)setting.yPixels,
(CGRefreshRate)setting.frequency,
NULL);
#ifdef GHOST_DEBUG
printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): switching to:\n");
printf(" setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
printf(" setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
printf(" setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
printf(" setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate));
#endif // GHOST_DEBUG
CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
return err == CGDisplayNoErr ? GHOST_kSuccess : GHOST_kFailure;
}
long GHOST_DisplayManagerCarbon::getValue(CFDictionaryRef values, CFStringRef key) const
{
CFNumberRef numberValue = (CFNumberRef) CFDictionaryGetValue(values, key);
if (!numberValue)
{
return -1;
}
long intValue;
if (!CFNumberGetValue(numberValue, kCFNumberLongType, &intValue))
{
return -1;
}
return intValue;
}

View File

@@ -0,0 +1,117 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerCarbon.h
* \ingroup GHOST
* Declaration of GHOST_DisplayManagerCarbon class.
*/
#ifndef _GHOST_DISPLAY_MANAGER_CARBON_H_
#define _GHOST_DISPLAY_MANAGER_CARBON_H_
#ifndef __APPLE__
#error Apple only!
#endif // __APPLE__
#include "GHOST_DisplayManager.h"
#define __CARBONSOUND__
#include <Carbon/Carbon.h>
/**
* Manages system displays (Mac OSX/Carbon implementation).
* @see GHOST_DisplayManager
* @author Maarten Gribnau
* @date September 21, 2001
*/
class GHOST_DisplayManagerCarbon : public GHOST_DisplayManager
{
public:
/**
* Constructor.
*/
GHOST_DisplayManagerCarbon(void);
/**
* Returns the number of display devices on this system.
* @param numDisplays The number of displays on this system.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const;
/**
* Returns the number of display settings for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The number of settings of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param index The setting index to be returned.
* @param setting The setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const;
/**
* Changes the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting);
protected:
/**
* Returns a value from a dictionary.
* @param values Dictionary to return value from.
* @param key Key to return value for.
* @return The value for this key.
*/
long getValue(CFDictionaryRef values, CFStringRef key) const;
/** Cached number of displays. */
CGDisplayCount m_numDisplays;
/** Cached display id's for each display. */
CGDirectDisplayID* m_displayIDs;
};
#endif // _GHOST_DISPLAY_MANAGER_CARBON_H_

View File

@@ -0,0 +1,107 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerCocoa.h
* \ingroup GHOST
* Declaration of GHOST_DisplayManagerCocoa class.
*/
#ifndef _GHOST_DISPLAY_MANAGER_COCOA_H_
#define _GHOST_DISPLAY_MANAGER_COCOA_H_
#ifndef __APPLE__
#error Apple only!
#endif // __APPLE__
#include "GHOST_DisplayManager.h"
/**
* Manages system displays (Mac OSX/Cocoa implementation).
* @see GHOST_DisplayManager
* @author Maarten Gribnau
* @date September 21, 2001
*/
class GHOST_DisplayManagerCocoa : public GHOST_DisplayManager
{
public:
/**
* Constructor.
*/
GHOST_DisplayManagerCocoa(void);
/**
* Returns the number of display devices on this system.
* @param numDisplays The number of displays on this system.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const;
/**
* Returns the number of display settings for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The number of settings of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param index The setting index to be returned.
* @param setting The setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const;
/**
* Changes the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting);
protected:
//Do not cache values as OS X supports screen hot plug
/** Cached number of displays. */
//CGDisplayCount m_numDisplays;
/** Cached display id's for each display. */
//CGDirectDisplayID* m_displayIDs;
};
#endif // _GHOST_DISPLAY_MANAGER_COCOA_H_

View File

@@ -0,0 +1,168 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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): Maarten Gribnau 09/2001
Damien Plisson 10/2009
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <Cocoa/Cocoa.h>
#include "GHOST_DisplayManagerCocoa.h"
#include "GHOST_Debug.h"
// We do not support multiple monitors at the moment
GHOST_DisplayManagerCocoa::GHOST_DisplayManagerCocoa(void)
{
}
GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplays(GHOST_TUns8& numDisplays) const
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
numDisplays = (GHOST_TUns8) [[NSScreen screens] count];
[pool drain];
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getNumDisplaySettings(): only main display is supported");
numSettings = (GHOST_TInt32)3; //Width, Height, BitsPerPixel
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCocoa::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
{
//Note that only current display setting is available
NSScreen *askedDisplay;
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getDisplaySetting(): only main display is supported");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (display == kMainDisplay) //Screen #0 may not be the main one
askedDisplay = [NSScreen mainScreen];
else
askedDisplay = [[NSScreen screens] objectAtIndex:display];
if(askedDisplay == nil) {
[pool drain];
return GHOST_kFailure;
}
NSRect frame = [askedDisplay visibleFrame];
setting.xPixels = frame.size.width;
setting.yPixels = frame.size.height;
setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
setting.frequency = 0; //No more CRT display...
#ifdef GHOST_DEBUG
printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
#endif // GHOST_DEBUG
[pool drain];
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
{
NSScreen *askedDisplay;
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(): only main display is supported");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (display == kMainDisplay) //Screen #0 may not be the main one
askedDisplay = [NSScreen mainScreen];
else
askedDisplay = [[NSScreen screens] objectAtIndex:display];
if(askedDisplay == nil) {
[pool drain];
return GHOST_kFailure;
}
NSRect frame = [askedDisplay visibleFrame];
setting.xPixels = frame.size.width;
setting.yPixels = frame.size.height;
setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
setting.frequency = 0; //No more CRT display...
#ifdef GHOST_DEBUG
printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
#endif // GHOST_DEBUG
[pool drain];
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): only main display is supported");
#ifdef GHOST_DEBUG
printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): requested settings:\n");
printf(" setting.xPixels=%d\n", setting.xPixels);
printf(" setting.yPixels=%d\n", setting.yPixels);
printf(" setting.bpp=%d\n", setting.bpp);
printf(" setting.frequency=%d\n", setting.frequency);
#endif // GHOST_DEBUG
//Display configuration is no more available in 10.6
/* CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
m_displayIDs[display],
(size_t)setting.bpp,
(size_t)setting.xPixels,
(size_t)setting.yPixels,
(CGRefreshRate)setting.frequency,
NULL);*/
#ifdef GHOST_DEBUG
/* printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): switching to:\n");
printf(" setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
printf(" setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
printf(" setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
printf(" setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate)); */
#endif // GHOST_DEBUG
//CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
return /*err == CGDisplayNoErr ? GHOST_kSuccess :*/ GHOST_kFailure;
}

View File

@@ -0,0 +1,182 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerWin32.cpp
* \ingroup GHOST
* \author Maarten Gribnau
* \date September 21, 2001
*/
#include "GHOST_DisplayManagerWin32.h"
#include "GHOST_Debug.h"
// We do not support multiple monitors at the moment
#include <windows.h>
#define COMPILE_MULTIMON_STUBS
#ifndef FREE_WINDOWS
#include <multimon.h>
#endif
GHOST_DisplayManagerWin32::GHOST_DisplayManagerWin32(void)
{
}
GHOST_TSuccess GHOST_DisplayManagerWin32::getNumDisplays(GHOST_TUns8& numDisplays) const
{
// We do not support multiple monitors at the moment
numDisplays = ::GetSystemMetrics(SM_CMONITORS);
return numDisplays > 0 ? GHOST_kSuccess : GHOST_kFailure;
}
/*
* When you call EnumDisplaySettings with iModeNum set to zero, the operating system
* initializes and caches information about the display device. When you call
* EnumDisplaySettings with iModeNum set to a non-zero value, the function returns
* the information that was cached the last time the function was called with iModeNum
* set to zero.
*/
GHOST_TSuccess GHOST_DisplayManagerWin32::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerWin32::getNumDisplaySettings(): only main displlay is supported");
numSettings = 0;
DEVMODE dm;
while (::EnumDisplaySettings(NULL, numSettings, &dm)) {
numSettings++;
}
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerWin32::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerWin32::getDisplaySetting(): only main display is supported");
GHOST_TSuccess success;
DEVMODE dm;
if (::EnumDisplaySettings(NULL, index, &dm)) {
#ifdef GHOST_DEBUG
printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, dm.dmDisplayFrequency);
#endif // GHOST_DEBUG
setting.xPixels = dm.dmPelsWidth;
setting.yPixels = dm.dmPelsHeight;
setting.bpp = dm.dmBitsPerPel;
/* When you call the EnumDisplaySettings function, the dmDisplayFrequency member
* may return with the value 0 or 1. These values represent the display hardware's
* default refresh rate. This default rate is typically set by switches on a display
* card or computer motherboard, or by a configuration program that does not use
* Win32 display functions such as ChangeDisplaySettings.
*/
/* First, we tried to explicitly set the frequency to 60 if EnumDisplaySettings
* returned 0 or 1 but this doesn't work since later on an exact match will
* be searched. And this will never happen if we change it to 60. Now we rely
* on the default h/w setting.
*/
setting.frequency = dm.dmDisplayFrequency;
success = GHOST_kSuccess;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_DisplayManagerWin32::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerWin32::getCurrentDisplaySetting(): only main display is supported");
return getDisplaySetting(kMainDisplay, ENUM_CURRENT_SETTINGS, setting);
}
GHOST_TSuccess GHOST_DisplayManagerWin32::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
{
GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerWin32::setCurrentDisplaySetting(): only main display is supported");
GHOST_DisplaySetting match;
findMatch(display, setting, match);
DEVMODE dm;
int i = 0;
while (::EnumDisplaySettings(NULL, i++, &dm)) {
if ((dm.dmBitsPerPel == match.bpp) &&
(dm.dmPelsWidth == match.xPixels) &&
(dm.dmPelsHeight == match.yPixels) &&
(dm.dmDisplayFrequency == match.frequency)) {
break;
}
}
/*
dm.dmBitsPerPel = match.bpp;
dm.dmPelsWidth = match.xPixels;
dm.dmPelsHeight = match.yPixels;
dm.dmDisplayFrequency = match.frequency;
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
dm.dmSize = sizeof(DEVMODE);
dm.dmDriverExtra = 0;
*/
#ifdef GHOST_DEBUG
printf("display change: Requested settings:\n");
printf(" dmBitsPerPel=%d\n", dm.dmBitsPerPel);
printf(" dmPelsWidth=%d\n", dm.dmPelsWidth);
printf(" dmPelsHeight=%d\n", dm.dmPelsHeight);
printf(" dmDisplayFrequency=%d\n", dm.dmDisplayFrequency);
#endif // GHOST_DEBUG
LONG status = ::ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
#ifdef GHOST_DEBUG
switch (status)
{
case DISP_CHANGE_SUCCESSFUL:
printf("display change: The settings change was successful.\n");
break;
case DISP_CHANGE_RESTART:
printf("display change: The computer must be restarted in order for the graphics mode to work.\n");
break;
case DISP_CHANGE_BADFLAGS:
printf("display change: An invalid set of flags was passed in.\n");
break;
case DISP_CHANGE_BADPARAM:
printf("display change: An invalid parameter was passed in. This can include an invalid flag or combination of flags.\n");
break;
case DISP_CHANGE_FAILED:
printf("display change: The display driver failed the specified graphics mode.\n");
break;
case DISP_CHANGE_BADMODE:
printf("display change: The graphics mode is not supported.\n");
break;
case DISP_CHANGE_NOTUPDATED:
printf("display change: Windows NT: Unable to write settings to the registry.\n");
break;
default:
printf("display change: Return value invalid\n");
break;
}
#endif // GHOST_DEBUG
return status == DISP_CHANGE_SUCCESSFUL? GHOST_kSuccess : GHOST_kFailure;
}

View File

@@ -0,0 +1,102 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerWin32.h
* \ingroup GHOST
* Declaration of GHOST_DisplayManagerWin32 class.
*/
#ifndef _GHOST_DISPLAY_MANAGER_WIN32_H_
#define _GHOST_DISPLAY_MANAGER_WIN32_H_
#ifndef WIN32
#error WIN32 only!
#endif // WIN32
#include "GHOST_DisplayManager.h"
/**
* Manages system displays (WIN32 implementation).
* @author Maarten Gribnau
* @date September 21, 2001
*/
class GHOST_DisplayManagerWin32 : public GHOST_DisplayManager
{
public:
/**
* Constructor.
*/
GHOST_DisplayManagerWin32(void);
/**
* Returns the number of display devices on this system.
* @param numDisplays The number of displays on this system.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplays(GHOST_TUns8& numDisplays) const;
/**
* Returns the number of display settings for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The number of settings of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param index The setting index to be returned.
* @param setting The setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const;
/**
* Changes the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting);
protected:
};
#endif // _GHOST_DISPLAY_MANAGER_WIN32_H_

View File

@@ -0,0 +1,126 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerX11.cpp
* \ingroup GHOST
*/
#include "GHOST_DisplayManagerX11.h"
#include "GHOST_SystemX11.h"
GHOST_DisplayManagerX11::
GHOST_DisplayManagerX11(
GHOST_SystemX11 *system
) :
GHOST_DisplayManager(),
m_system(system)
{
//nothing to do.
}
GHOST_TSuccess
GHOST_DisplayManagerX11::
getNumDisplays(
GHOST_TUns8& numDisplays
) const{
numDisplays = m_system->getNumDisplays();
return GHOST_kSuccess;
}
GHOST_TSuccess
GHOST_DisplayManagerX11::
getNumDisplaySettings(
GHOST_TUns8 display,
GHOST_TInt32& numSettings
) const{
// We only have one X11 setting at the moment.
GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
numSettings = GHOST_TInt32(1);
return GHOST_kSuccess;
}
GHOST_TSuccess
GHOST_DisplayManagerX11::
getDisplaySetting(
GHOST_TUns8 display,
GHOST_TInt32 index,
GHOST_DisplaySetting& setting
) const {
GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
GHOST_ASSERT(index < 1, "Requested setting outside of valid range.\n");
Display * x_display = m_system->getXDisplay();
if (x_display == NULL) {
return GHOST_kFailure;
}
setting.xPixels = DisplayWidth(x_display, DefaultScreen(x_display));
setting.yPixels = DisplayHeight(x_display, DefaultScreen(x_display));
setting.bpp = DefaultDepth(x_display,DefaultScreen(x_display));
// Don't think it's possible to get this value from X!
// So let's guess!!
setting.frequency = 60;
return GHOST_kSuccess;
}
GHOST_TSuccess
GHOST_DisplayManagerX11::
getCurrentDisplaySetting(
GHOST_TUns8 display,
GHOST_DisplaySetting& setting
) const {
return getDisplaySetting(display,GHOST_TInt32(0),setting);
}
GHOST_TSuccess
GHOST_DisplayManagerX11::
setCurrentDisplaySetting(
GHOST_TUns8 display,
const GHOST_DisplaySetting& setting
){
// This is never going to work robustly in X
// but it's currently part of the full screen interface
// we fudge it for now.
return GHOST_kSuccess;
}

View File

@@ -0,0 +1,124 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerX11.h
* \ingroup GHOST
* Declaration of GHOST_DisplayManagerX11 class.
*/
#ifndef _GHOST_DISPLAY_MANAGER_X11_H_
#define _GHOST_DISPLAY_MANAGER_X11_H_
#include "GHOST_DisplayManager.h"
class GHOST_SystemX11;
/**
* Manages system displays (X11 implementation).
* @author Laurence Bourn
* @date October 26, 2001
*/
class GHOST_DisplayManagerX11 : public GHOST_DisplayManager
{
public:
/**
* Constructor.
*/
GHOST_DisplayManagerX11(
GHOST_SystemX11 *system
);
/**
* Returns the number of display devices on this system.
* @param numDisplays The number of displays on this system.
* @return Indication of success.
*/
GHOST_TSuccess
getNumDisplays(
GHOST_TUns8& numDisplays
) const;
/**
* Returns the number of display settings for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The number of settings of the display device with this index.
* @return Indication of success.
*/
GHOST_TSuccess
getNumDisplaySettings(
GHOST_TUns8 display,
GHOST_TInt32& numSettings
) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param index The setting index to be returned.
* @param setting The setting of the display device with this index.
* @return Indication of success.
*/
GHOST_TSuccess
getDisplaySetting(
GHOST_TUns8 display,
GHOST_TInt32 index,
GHOST_DisplaySetting& setting
) const;
/**
* Returns the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
GHOST_TSuccess
getCurrentDisplaySetting(
GHOST_TUns8 display,
GHOST_DisplaySetting& setting
) const;
/**
* Changes the current setting for this display device.
* @param display The index of the display to query with 0 <= display < getNumDisplays().
* @param setting The current setting of the display device with this index.
* @return Indication of success.
*/
GHOST_TSuccess
setCurrentDisplaySetting(
GHOST_TUns8 display,
const GHOST_DisplaySetting& setting
);
private :
GHOST_SystemX11 * m_system;
};
#endif //

View File

@@ -0,0 +1,431 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DropTargetWin32.cpp
* \ingroup GHOST
*/
#include "GHOST_Debug.h"
#include "GHOST_DropTargetWin32.h"
#ifdef GHOST_DEBUG
// utility
void printLastError(void);
#endif // GHOST_DEBUG
GHOST_DropTargetWin32::GHOST_DropTargetWin32(GHOST_WindowWin32 * window, GHOST_SystemWin32 * system)
:
m_window(window),
m_system(system)
{
m_cRef = 1;
m_hWnd = window->getHWND();
m_draggedObjectType = GHOST_kDragnDropTypeUnknown;
// register our window as drop target
::RegisterDragDrop(m_hWnd, this);
}
GHOST_DropTargetWin32::~GHOST_DropTargetWin32()
{
::RevokeDragDrop(m_hWnd);
}
/*
* IUnknown::QueryInterface
*/
HRESULT __stdcall GHOST_DropTargetWin32::QueryInterface (REFIID riid, void ** ppvObj)
{
if (!ppvObj)
return E_INVALIDARG;
*ppvObj = NULL;
if(riid == IID_IUnknown || riid == IID_IDropTarget)
{
AddRef();
*ppvObj = (void*)this;
return S_OK;
}
else
{
*ppvObj = 0;
return E_NOINTERFACE;
}
}
/*
* IUnknown::AddRef
*/
ULONG __stdcall GHOST_DropTargetWin32::AddRef(void)
{
return ::InterlockedIncrement(&m_cRef);
}
/*
* IUnknown::Release
*/
ULONG __stdcall GHOST_DropTargetWin32::Release(void)
{
ULONG refs = ::InterlockedDecrement(&m_cRef);
if(refs == 0)
{
delete this;
return 0;
}
else
{
return refs;
}
}
/*
* Implementation of IDropTarget::DragEnter
*/
HRESULT __stdcall GHOST_DropTargetWin32::DragEnter(IDataObject * pDataObject, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
// we accept all drop by default
m_window->setAcceptDragOperation(true);
*pdwEffect = DROPEFFECT_NONE;
m_draggedObjectType = getGhostType(pDataObject);
m_system->pushDragDropEvent(GHOST_kEventDraggingEntered, m_draggedObjectType, m_window, pt.x, pt.y, NULL);
return S_OK;
}
/*
* Implementation of IDropTarget::DragOver
*/
HRESULT __stdcall GHOST_DropTargetWin32::DragOver(DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
if(m_window->canAcceptDragOperation())
{
*pdwEffect = allowedDropEffect(*pdwEffect);
}
else
{
*pdwEffect = DROPEFFECT_NONE;
//*pdwEffect = DROPEFFECT_COPY; // XXX Uncomment to test drop. Drop will not be called if pdwEffect == DROPEFFECT_NONE.
}
m_system->pushDragDropEvent(GHOST_kEventDraggingUpdated, m_draggedObjectType, m_window, pt.x, pt.y, NULL);
return S_OK;
}
/*
* Implementation of IDropTarget::DragLeave
*/
HRESULT __stdcall GHOST_DropTargetWin32::DragLeave(void)
{
m_system->pushDragDropEvent(GHOST_kEventDraggingExited, m_draggedObjectType, m_window, 0, 0, NULL);
m_draggedObjectType = GHOST_kDragnDropTypeUnknown;
return S_OK;
}
/* Implementation of IDropTarget::Drop
* This function will not be called if pdwEffect is set to DROPEFFECT_NONE in
* the implementation of IDropTarget::DragOver
*/
HRESULT __stdcall GHOST_DropTargetWin32::Drop(IDataObject * pDataObject, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
void * data = getGhostData(pDataObject);
if(m_window->canAcceptDragOperation())
{
*pdwEffect = allowedDropEffect(*pdwEffect);
}
else
{
*pdwEffect = DROPEFFECT_NONE;
}
if (data)
m_system->pushDragDropEvent(GHOST_kEventDraggingDropDone, m_draggedObjectType, m_window, pt.x, pt.y, data );
m_draggedObjectType = GHOST_kDragnDropTypeUnknown;
return S_OK;
}
/*
* Helpers
*/
DWORD GHOST_DropTargetWin32::allowedDropEffect(DWORD dwAllowed)
{
DWORD dwEffect = DROPEFFECT_NONE;
if(dwAllowed & DROPEFFECT_COPY)
dwEffect = DROPEFFECT_COPY;
return dwEffect;
}
GHOST_TDragnDropTypes GHOST_DropTargetWin32::getGhostType(IDataObject * pDataObject)
{
/* Text
* Note: Unicode text is aviable as CF_TEXT too, the system can do the
* conversion, but we do the conversion ourself with WC_NO_BEST_FIT_CHARS.
*/
FORMATETC fmtetc = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
if(pDataObject->QueryGetData(&fmtetc) == S_OK)
{
return GHOST_kDragnDropTypeString;
}
// Filesnames
fmtetc.cfFormat = CF_HDROP;
if(pDataObject->QueryGetData(&fmtetc) == S_OK)
{
return GHOST_kDragnDropTypeFilenames;
}
return GHOST_kDragnDropTypeUnknown;
}
void * GHOST_DropTargetWin32::getGhostData(IDataObject * pDataObject)
{
GHOST_TDragnDropTypes type = getGhostType(pDataObject);
switch(type)
{
case GHOST_kDragnDropTypeFilenames:
return getDropDataAsFilenames(pDataObject);
break;
case GHOST_kDragnDropTypeString:
return getDropDataAsString(pDataObject);
break;
case GHOST_kDragnDropTypeBitmap:
//return getDropDataAsBitmap(pDataObject);
break;
default:
#ifdef GHOST_DEBUG
::printf("\nGHOST_kDragnDropTypeUnknown");
#endif // GHOST_DEBUG
return NULL;
break;
}
return NULL;
}
void * GHOST_DropTargetWin32::getDropDataAsFilenames(IDataObject * pDataObject)
{
UINT totfiles, nvalid=0;
WCHAR fpath [MAX_PATH];
char * temp_path;
GHOST_TStringArray *strArray = NULL;
FORMATETC fmtetc = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stgmed;
HDROP hdrop;
// Check if dataobject supplies the format we want.
// Double checking here, first in getGhostType.
if(pDataObject->QueryGetData(&fmtetc) == S_OK)
{
if(pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
{
hdrop = (HDROP)::GlobalLock(stgmed.hGlobal);
totfiles = ::DragQueryFileW ( hdrop, -1, NULL, 0 );
if (!totfiles)
{
::GlobalUnlock(stgmed.hGlobal);
return NULL;
}
strArray = (GHOST_TStringArray*) ::malloc(sizeof(GHOST_TStringArray));
strArray->count = 0;
strArray->strings = (GHOST_TUns8**) ::malloc(totfiles*sizeof(GHOST_TUns8*));
for ( UINT nfile = 0; nfile < totfiles; nfile++ )
{
if ( ::DragQueryFileW ( hdrop, nfile, fpath, MAX_PATH ) > 0 )
{
if ( !WideCharToANSI(fpath, temp_path) )
{
continue;
}
// Just ignore paths that could not be converted verbatim.
if (strpbrk(temp_path, "?"))
{
#ifdef GHOST_DEBUG
::printf("\ndiscarding path that contains illegal characters: %s", temp_path);
#endif // GHOST_DEBUG
::free(temp_path);
temp_path = NULL;
continue;
}
strArray->strings[nvalid] = (GHOST_TUns8*) temp_path;
strArray->count = nvalid+1;
nvalid++;
}
}
// Free up memory.
::GlobalUnlock(stgmed.hGlobal);
::ReleaseStgMedium(&stgmed);
return strArray;
}
}
return NULL;
}
void * GHOST_DropTargetWin32::getDropDataAsString(IDataObject * pDataObject)
{
char* tmp_string;
FORMATETC fmtetc = { CF_UNICODETEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stgmed;
// Try unicode first.
// Check if dataobject supplies the format we want.
if(pDataObject->QueryGetData(&fmtetc) == S_OK)
{
if(pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
{
LPCWSTR wstr = (LPCWSTR)::GlobalLock(stgmed.hGlobal);
if ( !WideCharToANSI(wstr, tmp_string) )
{
::GlobalUnlock(stgmed.hGlobal);
return NULL;
}
// Free memory
::GlobalUnlock(stgmed.hGlobal);
::ReleaseStgMedium(&stgmed);
#ifdef GHOST_DEBUG
::printf("\n<converted droped unicode string>\n%s\n</droped converted unicode string>\n",tmp_string);
#endif // GHOST_DEBUG
return tmp_string;
}
}
fmtetc.cfFormat = CF_TEXT;
if(pDataObject->QueryGetData(&fmtetc) == S_OK)
{
if(pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
{
char * str = (char*)::GlobalLock(stgmed.hGlobal);
tmp_string = (char*)::malloc(::strlen(str)+1);
if ( !tmp_string )
{
::GlobalUnlock(stgmed.hGlobal);
return NULL;
}
if ( !::strcpy(tmp_string, str) )
{
::free(tmp_string);
::GlobalUnlock(stgmed.hGlobal);
return NULL;
}
// Free memory
::GlobalUnlock(stgmed.hGlobal);
::ReleaseStgMedium(&stgmed);
return tmp_string;
}
}
return NULL;
}
int GHOST_DropTargetWin32::WideCharToANSI(LPCWSTR in, char * &out)
{
int size;
out = NULL; //caller should free if != NULL
// Get the required size.
size = ::WideCharToMultiByte(CP_ACP, //System Default Codepage
0x00000400, // WC_NO_BEST_FIT_CHARS
in,
-1, //-1 null terminated, makes output null terminated too.
NULL,
0,
NULL,NULL
);
if(!size)
{
#ifdef GHOST_DEBUG
::printLastError();
#endif // GHOST_DEBUG
return 0;
}
out = (char*)::malloc(size);
if (!out)
{
::printf("\nmalloc failed!!!");
return 0;
}
size = ::WideCharToMultiByte(CP_ACP,
0x00000400,
in,
-1,
(LPSTR) out,
size,
NULL,NULL
);
if(!size)
{
#ifdef GHOST_DEBUG
::printLastError();
#endif //GHOST_DEBUG
::free(out);
out = NULL;
}
return size;
}
#ifdef GHOST_DEBUG
void printLastError(void)
{
LPTSTR s;
DWORD err;
err = GetLastError();
if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
err,
0,
(LPTSTR)&s,
0,
NULL)
)
{
printf("\nLastError: (%d) %s\n", (int)err, s);
LocalFree(s);
}
}
#endif // GHOST_DEBUG

View File

@@ -0,0 +1,160 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DropTargetWin32.h
* \ingroup GHOST
*/
#ifndef _GHOST_DROP_TARGET_WIN32_H_
#define _GHOST_DROP_TARGET_WIN32_H_
#include <windows.h>
#include <string.h>
#include <GHOST_Types.h>
#include "GHOST_WindowWin32.h"
#include "GHOST_SystemWin32.h"
class GHOST_DropTargetWin32 : public IDropTarget
{
public:
/* IUnknownd implementation.
* Enables clients to get pointers to other interfaces on a given object
* through the QueryInterface method, and manage the existence of the object
* through the AddRef and Release methods. All other COM interfaces are
* inherited, directly or indirectly, from IUnknown. Therefore, the three
* methods in IUnknown are the first entries in the VTable for every interface.
*/
HRESULT __stdcall QueryInterface (REFIID riid, void ** ppvObj);
ULONG __stdcall AddRef (void);
ULONG __stdcall Release (void);
/* IDropTarget implementation
+ The IDropTarget interface is one of the interfaces you implement to
provide drag-and-drop operations in your application. It contains methods
used in any application that can be a target for data during a
drag-and-drop operation. A drop-target application is responsible for:
*
* - Determining the effect of the drop on the target application.
* - Incorporating any valid dropped data when the drop occurs.
* - Communicating target feedback to the source so the source application
* can provide appropriate visual feedback such as setting the cursor.
* - Implementing drag scrolling.
* - Registering and revoking its application windows as drop targets.
*
* The IDropTarget interface contains methods that handle all these
* responsibilities except registering and revoking the application window
* as a drop target, for which you must call the RegisterDragDrop and the
* RevokeDragDrop functions.
*/
HRESULT __stdcall DragEnter (IDataObject * pDataObject, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect);
HRESULT __stdcall DragOver (DWORD grfKeyState, POINTL pt, DWORD * pdwEffect);
HRESULT __stdcall DragLeave (void);
HRESULT __stdcall Drop (IDataObject * pDataObject, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect);
/**
* Constructor
* With the modifier keys, we want to distinguish left and right keys.
* Sometimes this is not possible (Windows ME for instance). Then, we want
* events generated for both keys.
* @param window The window to register as drop target.
* @param system The associated system.
*/
GHOST_DropTargetWin32(GHOST_WindowWin32 * window, GHOST_SystemWin32 * system);
/**
* Destructor
* Do NOT destroy directly. Use Release() instead to make COM happy.
*/
~GHOST_DropTargetWin32();
private:
/* Internal helper functions */
/**
* Base the effect on those allowed by the dropsource.
* @param dwAllowed Drop sources allowed drop effect.
* @return The allowed drop effect.
*/
DWORD allowedDropEffect(DWORD dwAllowed);
/**
* Query DataObject for the data types it supports.
* @param pDataObject Pointer to the DataObject.
* @return GHOST data type.
*/
GHOST_TDragnDropTypes getGhostType(IDataObject * pDataObject);
/**
* Get data to pass in event.
* It checks the type and calls specific functions for each type.
* @param pDataObject Pointer to the DataObject.
* @return Pointer to data.
*/
void * getGhostData(IDataObject * pDataObject);
/**
* Allocate data as file array to pass in event.
* @param pDataObject Pointer to the DataObject.
* @return Pointer to data.
*/
void * getDropDataAsFilenames(IDataObject * pDataObject);
/**
* Allocate data as string to pass in event.
* @param pDataObject Pointer to the DataObject.
* @return Pointer to data.
*/
void * getDropDataAsString(IDataObject * pDataObject);
/**
* Convert Unicode to ANSI, replacing unconvertable chars with '?'.
* The ANSI codepage is the system default codepage,
* and can change from system to system.
* @param in LPCWSTR.
* @param out char *. Is set to NULL on failure.
* @return 0 on failure. Else the size of the string including '\0'.
*/
int WideCharToANSI(LPCWSTR in, char * &out);
/* Private member variables */
/* COM reference count. */
LONG m_cRef;
/* Handle of the associated window. */
HWND m_hWnd;
/* The associated GHOST_WindowWin32. */
GHOST_WindowWin32 * m_window;
/* The System. */
GHOST_SystemWin32 * m_system;
/* Data type of the dragged object */
GHOST_TDragnDropTypes m_draggedObjectType;
};
#endif // _GHOST_DROP_TARGET_WIN32_H_

View File

@@ -0,0 +1,108 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Event.h
* \ingroup GHOST
* Declaration of GHOST_Event class.
*/
#ifndef _GHOST_EVENT_H_
#define _GHOST_EVENT_H_
#include "GHOST_IEvent.h"
/**
* Base class for events received the operating system.
* @author Maarten Gribnau
* @date May 11, 2001
*/
class GHOST_Event : public GHOST_IEvent
{
public:
/**
* Constructor.
* @param msec The time this event was generated.
* @param type The type of this event.
* @param window The generating window (or NULL if system event).
*/
GHOST_Event(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window)
: m_type(type), m_time(msec), m_window(window), m_data(0)
{
}
/**
* Returns the event type.
* @return The event type.
*/
virtual GHOST_TEventType getType()
{
return m_type;
}
/**
* Returns the time this event was generated.
* @return The event generation time.
*/
virtual GHOST_TUns64 getTime()
{
return m_time;
}
/**
* Returns the window this event was generated on,
* or NULL if it is a 'system' event.
* @return The generating window.
*/
virtual GHOST_IWindow* getWindow()
{
return m_window;
}
/**
* Returns the event data.
* @return The event data.
*/
virtual GHOST_TEventDataPtr getData()
{
return m_data;
}
protected:
/** Type of this event. */
GHOST_TEventType m_type;
/** The time this event was generated. */
GHOST_TUns64 m_time;
/** Pointer to the generating window. */
GHOST_IWindow* m_window;
/** Pointer to the event data. */
GHOST_TEventDataPtr m_data;
};
#endif // _GHOST_EVENT_H_

View File

@@ -0,0 +1,68 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventButton.h
* \ingroup GHOST
* Declaration of GHOST_EventButton class.
*/
#ifndef _GHOST_EVENT_BUTTON_H_
#define _GHOST_EVENT_BUTTON_H_
#include "GHOST_Event.h"
/**
* Mouse button event.
* @author Maarten Gribnau
* @date May 11, 2001
*/
class GHOST_EventButton : public GHOST_Event
{
public:
/**
* Constructor.
* @param time The time this event was generated.
* @param type The type of this event.
* @param x The x-coordinate of the location the cursor was at at the time of the event.
* @param y The y-coordinate of the location the cursor was at at the time of the event.
* @param buttons The state of the buttons was at at the time of the event.
*/
GHOST_EventButton(GHOST_TUns64 time, GHOST_TEventType type, GHOST_IWindow* window, GHOST_TButtonMask button)
: GHOST_Event(time, type, window)
{
m_buttonEventData.button = button;
m_data = &m_buttonEventData;
}
protected:
/** The button event data. */
GHOST_TEventButtonData m_buttonEventData;
};
#endif // _GHOST_EVENT_BUTTON_H_

View File

@@ -0,0 +1,69 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventCursor.h
* \ingroup GHOST
* Declaration of GHOST_EventCursor class.
*/
#ifndef _GHOST_EVENT_CURSOR_H_
#define _GHOST_EVENT_CURSOR_H_
#include "GHOST_Event.h"
/**
* Cursor event.
* @author Maarten Gribnau
* @date May 11, 2001
*/
class GHOST_EventCursor : public GHOST_Event
{
public:
/**
* Constructor.
* @param msec The time this event was generated.
* @param type The type of this event.
* @param x The x-coordinate of the location the cursor was at at the time of the event.
* @param y The y-coordinate of the location the cursor was at at the time of the event.
*/
GHOST_EventCursor(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window, GHOST_TInt32 x, GHOST_TInt32 y)
: GHOST_Event(msec, type, window)
{
m_cursorEventData.x = x;
m_cursorEventData.y = y;
m_data = &m_cursorEventData;
}
protected:
/** The x,y-coordinates of the cursor position. */
GHOST_TEventCursorData m_cursorEventData;
};
#endif // _GHOST_EVENT_CURSOR_H_

View File

@@ -0,0 +1,131 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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): Damien Plisson 11/2009
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventDragnDrop.h
* \ingroup GHOST
*/
#ifndef _GHOST_EVENT_DRAGNDROP_H_
#define _GHOST_EVENT_DRAGNDROP_H_
#include "GHOST_Event.h"
extern "C" {
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
};
/**
* Drag & drop event
*
* The dragging sequence is performed in four phases:
*
* <li> Start sequence (GHOST_kEventDraggingEntered) that tells a drag'n'drop operation has started. Already gives the object data type,
* and the entering mouse location
*
* <li> Update mouse position (GHOST_kEventDraggingUpdated) sent upon each mouse move until the drag'n'drop operation stops, to give the updated mouse position.
* Useful to highlight a potential destination, and update the status (through GHOST_setAcceptDragOperation) telling if the object can be dropped at
* the current cursor position.
*
* <li> Abort drag'n'drop sequence (GHOST_kEventDraggingExited) sent when the user moved the mouse outside the window.
*
* <li> Send the dropped data (GHOST_kEventDraggingDropDone)
*
* <li> Outside of the normal sequence, dropped data can be sent (GHOST_kEventDraggingDropOnIcon). This can happen when the user drops an object
* on the application icon. (Also used in OSX to pass the filename of the document the user doubled-clicked in the finder)
*
* <br><br>Note that the mouse positions are given in Blender coordinates (y=0 at bottom)
*
* <br>Currently supported object types :
* <li>UTF-8 string
* <li>array of strings representing filenames (GHOST_TStringArray)
* <li>bitmap ImBuf
*/
class GHOST_EventDragnDrop : public GHOST_Event
{
public:
/**
* Constructor.
* @param time The time this event was generated.
* @param type The type of this event.
* @param dataType The type of the drop candidate object
* @param window The window where the event occurred
* @param x The x-coordinate of the location the cursor was at at the time of the event.
* @param y The y-coordinate of the location the cursor was at at the time of the event.
* @param data The "content" dropped in the window
*/
GHOST_EventDragnDrop(GHOST_TUns64 time, GHOST_TEventType type, GHOST_TDragnDropTypes dataType, GHOST_IWindow* window,
int x, int y, GHOST_TEventDataPtr data)
: GHOST_Event(time, type, window)
{
m_dragnDropEventData.x = x;
m_dragnDropEventData.y = y;
m_dragnDropEventData.dataType = dataType;
m_dragnDropEventData.data = data;
m_data = &m_dragnDropEventData;
}
~GHOST_EventDragnDrop()
{
//Free the dropped object data
if (m_dragnDropEventData.data == NULL)
return;
switch (m_dragnDropEventData.dataType) {
case GHOST_kDragnDropTypeBitmap:
IMB_freeImBuf((ImBuf*)m_dragnDropEventData.data);
break;
case GHOST_kDragnDropTypeFilenames:
{
GHOST_TStringArray *strArray = (GHOST_TStringArray*)m_dragnDropEventData.data;
int i;
for (i=0;i<strArray->count;i++)
free(strArray->strings[i]);
free(strArray);
}
break;
case GHOST_kDragnDropTypeString:
free(m_dragnDropEventData.data);
break;
default:
break;
}
}
protected:
/** The x,y-coordinates of the cursor position. */
GHOST_TEventDragnDropData m_dragnDropEventData;
};
#endif // _GHOST_EVENT_DRAGNDROP_H_

View File

@@ -0,0 +1,82 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventKey.h
* \ingroup GHOST
* Declaration of GHOST_EventKey class.
*/
#ifndef _GHOST_EVENT_KEY_H_
#define _GHOST_EVENT_KEY_H_
#include "GHOST_Event.h"
/**
* Key event.
* @author Maarten Gribnau
* @date May 11, 2001
*/
class GHOST_EventKey : public GHOST_Event
{
public:
/**
* Constructor.
* @param msec The time this event was generated.
* @param type The type of key event.
* @param key The key code of the key.
*/
GHOST_EventKey(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window, GHOST_TKey key)
: GHOST_Event(msec, type, window)
{
m_keyEventData.key = key;
m_keyEventData.ascii = '\0';
m_data = &m_keyEventData;
}
/**
* Constructor.
* @param msec The time this event was generated.
* @param type The type of key event.
* @param key The key code of the key.
* @param ascii The ascii code for the key event.
*/
GHOST_EventKey(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window, GHOST_TKey key, char ascii)
: GHOST_Event(msec, type, window)
{
m_keyEventData.key = key;
m_keyEventData.ascii = ascii;
m_data = &m_keyEventData;
}
protected:
/** The key event data. */
GHOST_TEventKeyData m_keyEventData;
};
#endif // _GHOST_EVENT_KEY_H_

View File

@@ -0,0 +1,268 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventManager.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 14, 2001
*/
#include "GHOST_EventManager.h"
#include <algorithm>
#include "GHOST_Debug.h"
GHOST_EventManager::GHOST_EventManager()
{
}
GHOST_EventManager::~GHOST_EventManager()
{
disposeEvents();
TConsumerVector::iterator iter= m_consumers.begin();
while (iter != m_consumers.end())
{
GHOST_IEventConsumer* consumer = *iter;
delete consumer;
m_consumers.erase(iter);
iter = m_consumers.begin();
}
}
GHOST_TUns32 GHOST_EventManager::getNumEvents()
{
return (GHOST_TUns32) m_events.size();
}
GHOST_TUns32 GHOST_EventManager::getNumEvents(GHOST_TEventType type)
{
GHOST_TUns32 numEvents = 0;
TEventStack::iterator p;
for (p = m_events.begin(); p != m_events.end(); p++) {
if ((*p)->getType() == type) {
numEvents++;
}
}
return numEvents;
}
GHOST_IEvent* GHOST_EventManager::peekEvent()
{
GHOST_IEvent* event = 0;
if (m_events.size() > 0) {
event = m_events.back();
}
return event;
}
GHOST_TSuccess GHOST_EventManager::pushEvent(GHOST_IEvent* event)
{
GHOST_TSuccess success;
GHOST_ASSERT(event, "invalid event");
if (m_events.size() < m_events.max_size()) {
m_events.push_front(event);
success = GHOST_kSuccess;
}
else {
success = GHOST_kFailure;
}
return success;
}
bool GHOST_EventManager::dispatchEvent(GHOST_IEvent* event)
{
bool handled;
if (event) {
handled = true;
TConsumerVector::iterator iter;
for (iter = m_consumers.begin(); iter != m_consumers.end(); iter++) {
if ((*iter)->processEvent(event)) {
handled = false;
}
}
}
else {
handled = false;
}
return handled;
}
bool GHOST_EventManager::dispatchEvent()
{
GHOST_IEvent* event = popEvent();
bool handled = false;
if (event) {
handled = dispatchEvent(event);
delete event;
}
return handled;
}
bool GHOST_EventManager::dispatchEvents()
{
bool handled;
if (getNumEvents()) {
handled = true;
while (getNumEvents()) {
if (!dispatchEvent()) {
handled = false;
}
}
}
else {
handled = false;
}
return handled;
}
GHOST_TSuccess GHOST_EventManager::addConsumer(GHOST_IEventConsumer* consumer)
{
GHOST_TSuccess success;
GHOST_ASSERT(consumer, "invalid consumer");
// Check to see whether the consumer is already in our list
TConsumerVector::const_iterator iter = std::find(m_consumers.begin(), m_consumers.end(), consumer);
if (iter == m_consumers.end()) {
// Add the consumer
m_consumers.push_back(consumer);
success = GHOST_kSuccess;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_EventManager::removeConsumer(GHOST_IEventConsumer* consumer)
{
GHOST_TSuccess success;
GHOST_ASSERT(consumer, "invalid consumer");
// Check to see whether the consumer is in our list
TConsumerVector::iterator iter = std::find(m_consumers.begin(), m_consumers.end(), consumer);
if (iter != m_consumers.end()) {
// Remove the consumer
m_consumers.erase(iter);
success = GHOST_kSuccess;
}
else {
success = GHOST_kFailure;
}
return success;
}
void GHOST_EventManager::removeWindowEvents(GHOST_IWindow* window)
{
TEventStack::iterator iter;
iter = m_events.begin();
while (iter != m_events.end())
{
GHOST_IEvent* event = *iter;
if (event->getWindow() == window)
{
GHOST_PRINT("GHOST_EventManager::removeWindowEvents(): removing event\n");
/*
* Found an event for this window, remove it.
* The iterator will become invalid.
*/
delete event;
m_events.erase(iter);
iter = m_events.begin();
}
else
{
iter++;
}
}
}
void GHOST_EventManager::removeTypeEvents(GHOST_TEventType type, GHOST_IWindow* window)
{
TEventStack::iterator iter;
iter = m_events.begin();
while (iter != m_events.end())
{
GHOST_IEvent* event = *iter;
if ((event->getType() == type) && (!window || (event->getWindow() == window)))
{
GHOST_PRINT("GHOST_EventManager::removeTypeEvents(): removing event\n");
/*
* Found an event of this type for the window, remove it.
* The iterator will become invalid.
*/
delete event;
m_events.erase(iter);
iter = m_events.begin();
}
else
{
iter++;
}
}
}
GHOST_IEvent* GHOST_EventManager::popEvent()
{
GHOST_IEvent* event = peekEvent();
if (event) {
m_events.pop_back();
}
return event;
}
void GHOST_EventManager::disposeEvents()
{
while (m_events.size() > 0) {
GHOST_ASSERT(m_events[0], "invalid event");
delete m_events[0];
m_events.pop_front();
}
}

View File

@@ -0,0 +1,175 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventManager.h
* \ingroup GHOST
* Declaration of GHOST_EventManager class.
*/
#ifndef _GHOST_EVENT_MANAGER_H_
#define _GHOST_EVENT_MANAGER_H_
#include <deque>
#include <vector>
#include "GHOST_IEventConsumer.h"
/**
* Manages an event stack and a list of event consumers.
* The stack works on a FIFO (First In First Out) basis.
* Events are pushed on the front of the stack and retrieved from the back.
* Ownership of the event is transferred to the event manager as soon as an event is pushed.
* Ownership of the event is transferred from the event manager as soon as an event is popped.
* Events can be dispatched to the event consumers.
*/
class GHOST_EventManager
{
public:
/**
* Constructor.
*/
GHOST_EventManager();
/**
* Destructor.
*/
virtual ~GHOST_EventManager();
/**
* Returns the number of events currently on the stack.
* @return The number of events on the stack.
*/
virtual GHOST_TUns32 getNumEvents();
/**
* Returns the number of events of a certain type currently on the stack.
* @param type The type of events to be counted.
* @return The number of events on the stack of this type.
*/
virtual GHOST_TUns32 getNumEvents(GHOST_TEventType type);
/**
* Return the event at the top of the stack without removal.
* Do not delete the event!
* @return The event at the top of the stack.
*/
virtual GHOST_IEvent* peekEvent();
/**
* Pushes an event on the stack.
* To dispatch it, call dispatchEvent() or dispatchEvents().
* Do not delete the event!
* @param event The event to push on the stack.
*/
virtual GHOST_TSuccess pushEvent(GHOST_IEvent* event);
/**
* Dispatches the given event directly, bypassing the event stack.
* @return Indication as to whether any of the consumers handled the event.
*/
virtual bool dispatchEvent(GHOST_IEvent* event);
/**
* Dispatches the event at the back of the stack.
* The event will be removed from the stack.
* @return Indication as to whether any of the consumers handled the event.
*/
virtual bool dispatchEvent();
/**
* Dispatches all the events on the stack.
* The event stack will be empty afterwards.
* @return Indication as to whether any of the consumers handled the events.
*/
virtual bool dispatchEvents();
/**
* Adds a consumer to the list of event consumers.
* @param consumer The consumer added to the list.
* @return Indication as to whether addition has succeeded.
*/
virtual GHOST_TSuccess addConsumer(GHOST_IEventConsumer* consumer);
/**
* Removes a consumer from the list of event consumers.
* @param consumer The consumer removed from the list.
* @return Indication as to whether removal has succeeded.
*/
virtual GHOST_TSuccess removeConsumer(GHOST_IEventConsumer* consumer);
/**
* Removes all events for a window from the stack.
* @param window The window to remove events for.
*/
virtual void
removeWindowEvents(
GHOST_IWindow* window
);
/**
* Removes all events of a certain type from the stack.
* The window parameter is optional. If non-null, the routine will remove
* events only associated with that window.
* @param type The type of events to be removed.
* @param window The window to remove the events for.
*/
virtual void
removeTypeEvents(
GHOST_TEventType type,
GHOST_IWindow* window = 0
);
protected:
/**
* Returns the event at the top of the stack and removes it.
* Delete the event after use!
* @return The event at the top of the stack.
*/
virtual GHOST_IEvent* popEvent();
/**
* Removes all events from the stack.
*/
virtual void disposeEvents();
/** A stack with events. */
typedef std::deque<GHOST_IEvent*> TEventStack;
/** The event stack. */
std::deque<GHOST_IEvent*> m_events;
/** A vector with event consumers. */
typedef std::vector<GHOST_IEventConsumer*> TConsumerVector;
/** The list with event consumers. */
TConsumerVector m_consumers;
};
#endif // _GHOST_EVENT_MANAGER_H_

View File

@@ -0,0 +1,62 @@
/*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventNDOF.h
* \ingroup GHOST
*/
#ifndef _GHOST_EVENT_NDOF_H_
#define _GHOST_EVENT_NDOF_H_
#include "GHOST_Event.h"
/**
* N-degree of freedom device event.
*/
class GHOST_EventNDOF : public GHOST_Event
{
public:
/**
* Constructor.
* @param msec The time this event was generated.
* @param type The type of this event.
* @param x The x-coordinate of the location the cursor was at at the time of the event.
* @param y The y-coordinate of the location the cursor was at at the time of the event.
*/
GHOST_EventNDOF(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window,
GHOST_TEventNDOFData data)
: GHOST_Event(msec, type, window)
{
m_ndofEventData = data;
m_data = &m_ndofEventData;
}
protected:
/** translation & rotation from the device. */
GHOST_TEventNDOFData m_ndofEventData;
};
#endif // _GHOST_EVENT_NDOF_H_

View File

@@ -0,0 +1,347 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventPrinter.cpp
* \ingroup GHOST
* Declaration of GHOST_EventPrinter class.
*/
#include "GHOST_EventPrinter.h"
#include <iostream>
#include "GHOST_EventKey.h"
#include "GHOST_EventDragnDrop.h"
#include "GHOST_Debug.h"
bool GHOST_EventPrinter::processEvent(GHOST_IEvent* event)
{
bool handled = true;
GHOST_ASSERT(event, "event==0");
if (event->getType() == GHOST_kEventWindowUpdate) return false;
std::cout << "\nGHOST_EventPrinter::processEvent, time: " << (GHOST_TInt32)event->getTime() << ", type: ";
switch (event->getType()) {
case GHOST_kEventUnknown:
std::cout << "GHOST_kEventUnknown"; handled = false;
break;
case GHOST_kEventButtonUp:
{
GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData();
std::cout << "GHOST_kEventCursorButtonUp, button: " << buttonData->button;
}
break;
case GHOST_kEventButtonDown:
{
GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData();
std::cout << "GHOST_kEventButtonDown, button: " << buttonData->button;
}
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();
std::cout << "GHOST_kEventCursorMove, (x,y): (" << cursorData->x << "," << cursorData->y << ")";
}
break;
case GHOST_kEventKeyUp:
{
GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData();
STR_String str;
getKeyString(keyData->key, str);
std::cout << "GHOST_kEventKeyUp, key: " << str.Ptr();
}
break;
case GHOST_kEventKeyDown:
{
GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData();
STR_String str;
getKeyString(keyData->key, str);
std::cout << "GHOST_kEventKeyDown, key: " << str.Ptr();
}
break;
case GHOST_kEventDraggingEntered:
{
GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
std::cout << "GHOST_kEventDraggingEntered, dragged object type : " << dragnDropData->dataType;
std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
}
break;
case GHOST_kEventDraggingUpdated:
{
GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
std::cout << "GHOST_kEventDraggingUpdated, dragged object type : " << dragnDropData->dataType;
std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
}
break;
case GHOST_kEventDraggingExited:
{
GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
std::cout << "GHOST_kEventDraggingExited, dragged object type : " << dragnDropData->dataType;
}
break;
case GHOST_kEventDraggingDropDone:
{
GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
std::cout << "GHOST_kEventDraggingDropDone,";
std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
switch (dragnDropData->dataType) {
case GHOST_kDragnDropTypeString:
std::cout << " type : GHOST_kDragnDropTypeString,";
std::cout << "\n String received = " << (char*)dragnDropData->data;
break;
case GHOST_kDragnDropTypeFilenames:
{
GHOST_TStringArray *strArray = (GHOST_TStringArray*)dragnDropData->data;
int i;
std::cout << " type : GHOST_kDragnDropTypeFilenames,";
std::cout << "\n Received " << strArray->count << " filename" << (strArray->count > 1 ? "s:" : ":");
for (i=0;i<strArray->count;i++)
std::cout << "\n File[" << i << "] : " << strArray->strings[i];
}
break;
default:
break;
}
}
break;
case GHOST_kEventOpenMainFile:
{
GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
if (eventData)
std::cout << "GHOST_kEventOpenMainFile for path : " << (char*)eventData;
else
std::cout << "GHOST_kEventOpenMainFile with no path specified!!";
}
break;
case GHOST_kEventQuit:
std::cout << "GHOST_kEventQuit";
break;
case GHOST_kEventWindowClose:
std::cout << "GHOST_kEventWindowClose";
break;
case GHOST_kEventWindowActivate:
std::cout << "GHOST_kEventWindowActivate";
break;
case GHOST_kEventWindowDeactivate:
std::cout << "GHOST_kEventWindowDeactivate";
break;
case GHOST_kEventWindowUpdate:
std::cout << "GHOST_kEventWindowUpdate";
break;
case GHOST_kEventWindowSize:
std::cout << "GHOST_kEventWindowSize";
break;
default:
std::cout << "not found"; handled = false;
break;
}
return handled;
}
void GHOST_EventPrinter::getKeyString(GHOST_TKey key, STR_String& str) const
{
if ((key >= GHOST_kKeyComma) && (key <= GHOST_kKeyRightBracket)) {
str = ((char)key);
} else if ((key >= GHOST_kKeyNumpad0) && (key <= GHOST_kKeyNumpad9)) {
int number = key - GHOST_kKeyNumpad0;
STR_String numberStr (number);
str = "Numpad";
str += numberStr;
#if defined(__sun__) || defined(__sun)
} else if (key == 268828432) { /* solaris keyboards are messed up */
/* This should really test XK_F11 but that doesn't work */
str = "F11";
} else if (key == 268828433) { /* solaris keyboards are messed up */
/* This should really test XK_F12 but that doesn't work */
str = "F12";
#endif
} else if ((key >= GHOST_kKeyF1) && (key <= GHOST_kKeyF24)) {
int number = key - GHOST_kKeyF1 + 1;
STR_String numberStr (number);
str = "F";
str += numberStr;
} else {
switch (key)
{
case GHOST_kKeyBackSpace:
str = "BackSpace";
break;
case GHOST_kKeyTab:
str = "Tab";
break;
case GHOST_kKeyLinefeed:
str = "Linefeed";
break;
case GHOST_kKeyClear:
str = "Clear";
break;
case GHOST_kKeyEnter:
str = "Enter";
break;
case GHOST_kKeyEsc:
str = "Esc";
break;
case GHOST_kKeySpace:
str = "Space";
break;
case GHOST_kKeyQuote:
str = "Quote";
break;
case GHOST_kKeyBackslash:
str = "\\";
break;
case GHOST_kKeyAccentGrave:
str = "`";
break;
case GHOST_kKeyLeftShift:
str = "LeftShift";
break;
case GHOST_kKeyRightShift:
str = "RightShift";
break;
case GHOST_kKeyLeftControl:
str = "LeftControl";
break;
case GHOST_kKeyRightControl:
str = "RightControl";
break;
case GHOST_kKeyLeftAlt:
str = "LeftAlt";
break;
case GHOST_kKeyRightAlt:
str = "RightAlt";
break;
case GHOST_kKeyOS:
str = "OS";
break;
case GHOST_kKeyGrLess:
// PC german!
str = "GrLess";
break;
case GHOST_kKeyCapsLock:
str = "CapsLock";
break;
case GHOST_kKeyNumLock:
str = "NumLock";
break;
case GHOST_kKeyScrollLock:
str = "ScrollLock";
break;
case GHOST_kKeyLeftArrow:
str = "LeftArrow";
break;
case GHOST_kKeyRightArrow:
str = "RightArrow";
break;
case GHOST_kKeyUpArrow:
str = "UpArrow";
break;
case GHOST_kKeyDownArrow:
str = "DownArrow";
break;
case GHOST_kKeyPrintScreen:
str = "PrintScreen";
break;
case GHOST_kKeyPause:
str = "Pause";
break;
case GHOST_kKeyInsert:
str = "Insert";
break;
case GHOST_kKeyDelete:
str = "Delete";
break;
case GHOST_kKeyHome:
str = "Home";
break;
case GHOST_kKeyEnd:
str = "End";
break;
case GHOST_kKeyUpPage:
str = "UpPage";
break;
case GHOST_kKeyDownPage:
str = "DownPage";
break;
case GHOST_kKeyNumpadPeriod:
str = "NumpadPeriod";
break;
case GHOST_kKeyNumpadEnter:
str = "NumpadEnter";
break;
case GHOST_kKeyNumpadPlus:
str = "NumpadPlus";
break;
case GHOST_kKeyNumpadMinus:
str = "NumpadMinus";
break;
case GHOST_kKeyNumpadAsterisk:
str = "NumpadAsterisk";
break;
case GHOST_kKeyNumpadSlash:
str = "NumpadSlash";
break;
case GHOST_kKeyMediaPlay:
str = "MediaPlayPause";
break;
case GHOST_kKeyMediaStop:
str = "MediaStop";
break;
case GHOST_kKeyMediaFirst:
str = "MediaFirst";
break;
case GHOST_kKeyMediaLast:
str = "MediaLast";
break;
default:
str = "unknown";
break;
}
}
}

View File

@@ -0,0 +1,65 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventPrinter.h
* \ingroup GHOST
* Declaration of GHOST_EventPrinter class.
*/
#ifndef _GHOST_EVENT_PRINTER_H_
#define _GHOST_EVENT_PRINTER_H_
#include "GHOST_IEventConsumer.h"
#include "STR_String.h"
/**
* An Event consumer that prints all the events to standard out.
* Really useful when debugging.
*/
class GHOST_EventPrinter : public GHOST_IEventConsumer
{
public:
/**
* Prints all the events received to std out.
* @param event The event that can be handled or not.
* @return Indication as to whether the event was handled.
*/
virtual bool processEvent(GHOST_IEvent* event);
protected:
/**
* Converts GHOST key code to a readable string.
* @param key The GHOST key code to convert.
* @param str The GHOST key code converted to a readable string.
*/
void getKeyString(GHOST_TKey key, STR_String& str) const;
};
#endif // _GHOST_EVENT_PRINTER_H_

View File

@@ -0,0 +1,67 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventString.h
* \ingroup GHOST
* Declaration of GHOST_EventString class.
*/
#ifndef _GHOST_EVENTSTRING_H_
#define _GHOST_EVENTSTRING_H_
#include "GHOST_Event.h"
/**
* Generic class for events with string data
* @author Damien Plisson
* @date Feb 1, 2010
*/
class GHOST_EventString : public GHOST_Event
{
public:
/**
* Constructor.
* @param msec The time this event was generated.
* @param type The type of this event.
* @param window The generating window (or NULL if system event).
* @param data_ptr Pointer to the (unformatted) data associated with the event
*/
GHOST_EventString(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window, GHOST_TEventDataPtr data_ptr)
: GHOST_Event(msec, type, window) {
m_data = data_ptr;
}
~GHOST_EventString()
{
if (m_data) free(m_data);
}
};
#endif // _GHOST_EVENTSTRING_H_

View File

@@ -0,0 +1,72 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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): James Deery 11/2009
* Damien Plisson 12/2009
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventTrackpad.h
* \ingroup GHOST
* Declaration of GHOST_EventTrackpad class.
*/
#ifndef _GHOST_EVENT_TRACKPAD_H_
#define _GHOST_EVENT_TRACKPAD_H_
#include "GHOST_Event.h"
/**
* Trackpad (scroll, magnify, rotate, ...) event.
*/
class GHOST_EventTrackpad : public GHOST_Event
{
public:
/**
* Constructor.
* @param msec The time this event was generated.
* @param type The type of this event.
* @param subtype The subtype of the event.
* @param x The x-delta of the pan event.
* @param y The y-delta of the pan event.
*/
GHOST_EventTrackpad(GHOST_TUns64 msec, GHOST_IWindow* window, GHOST_TTrackpadEventSubTypes subtype, GHOST_TInt32 x, GHOST_TInt32 y, GHOST_TInt32 deltaX, GHOST_TInt32 deltaY)
: GHOST_Event(msec, GHOST_kEventTrackpad, window)
{
m_trackpadEventData.subtype = subtype;
m_trackpadEventData.x = x;
m_trackpadEventData.y = y;
m_trackpadEventData.deltaX = deltaX;
m_trackpadEventData.deltaY = deltaY;
m_data = &m_trackpadEventData;
}
protected:
/** The mouse pan data */
GHOST_TEventTrackpadData m_trackpadEventData;
};
#endif // _GHOST_EVENT_PAN_H_

View File

@@ -0,0 +1,69 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_EventWheel.h
* \ingroup GHOSTeel.h
* Declaration of GHOST_EventWheel class.
*/
#ifndef _GHOST_EVENT_WHEEL_H_
#define _GHOST_EVENT_WHEEL_H_
#include "GHOST_Event.h"
/**
* Mouse wheel event.
* The displacement of the mouse wheel is counted in ticks.
* A positive value means the wheel is turned away from the user.
* @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_IWindow* window, GHOST_TInt32 z)
: GHOST_Event(msec, GHOST_kEventWheel, 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_

View File

@@ -0,0 +1,108 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_ISystem.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 7, 2001
*/
#include "GHOST_ISystem.h"
#ifdef WIN32
# include "GHOST_SystemWin32.h"
#else
# ifdef __APPLE__
# ifdef GHOST_COCOA
# include "GHOST_SystemCocoa.h"
# else
# include "GHOST_SystemCarbon.h"
# endif
# else
# include "GHOST_SystemX11.h"
# endif
#endif
GHOST_ISystem* GHOST_ISystem::m_system = 0;
GHOST_TSuccess GHOST_ISystem::createSystem()
{
GHOST_TSuccess success;
if (!m_system) {
#ifdef WIN32
m_system = new GHOST_SystemWin32 ();
#else
# ifdef __APPLE__
# ifdef GHOST_COCOA
m_system = new GHOST_SystemCocoa ();
# else
m_system = new GHOST_SystemCarbon ();
# endif
# else
m_system = new GHOST_SystemX11 ();
# endif
#endif
success = m_system != 0 ? GHOST_kSuccess : GHOST_kFailure;
}
else {
success = GHOST_kFailure;
}
if (success) {
success = m_system->init();
}
return success;
}
GHOST_TSuccess GHOST_ISystem::disposeSystem()
{
GHOST_TSuccess success = GHOST_kSuccess;
if (m_system) {
delete m_system;
m_system = 0;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_ISystem* GHOST_ISystem::getSystem()
{
return m_system;
}

View File

@@ -0,0 +1,109 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_ISystemPaths.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 7, 2001
*/
#include "GHOST_ISystemPaths.h"
#ifdef WIN32
# include "GHOST_SystemPathsWin32.h"
#else
# ifdef __APPLE__
# ifdef GHOST_COCOA
# include "GHOST_SystemPathsCocoa.h"
# else
# include "GHOST_SystemPathsCarbon.h"
# endif
# else
# include "GHOST_SystemPathsX11.h"
# endif
#endif
GHOST_ISystemPaths* GHOST_ISystemPaths::m_systemPaths = 0;
GHOST_TSuccess GHOST_ISystemPaths::create()
{
GHOST_TSuccess success;
if (!m_systemPaths) {
#ifdef WIN32
m_systemPaths = new GHOST_SystemPathsWin32 ();
#else
# ifdef __APPLE__
# ifdef GHOST_COCOA
m_systemPaths = new GHOST_SystemPathsCocoa ();
# else
m_systemPaths = new GHOST_SystemPathsarbon ();
# endif
# else
m_systemPaths = new GHOST_SystemPathsX11 ();
# endif
#endif
success = m_systemPaths != 0 ? GHOST_kSuccess : GHOST_kFailure;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_ISystemPaths::dispose()
{
GHOST_TSuccess success = GHOST_kSuccess;
if (m_systemPaths) {
delete m_systemPaths;
m_systemPaths = 0;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_ISystemPaths* GHOST_ISystemPaths::get()
{
if (!m_systemPaths) {
create();
}
return m_systemPaths;
}

View File

@@ -0,0 +1,140 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_ModifierKeys.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 31, 2001
*/
#include "GHOST_ModifierKeys.h"
GHOST_ModifierKeys::GHOST_ModifierKeys()
{
clear();
}
GHOST_ModifierKeys::~GHOST_ModifierKeys() {}
GHOST_TKey GHOST_ModifierKeys::getModifierKeyCode(GHOST_TModifierKeyMask mask)
{
GHOST_TKey key;
switch (mask) {
case GHOST_kModifierKeyLeftShift: key = GHOST_kKeyLeftShift; break;
case GHOST_kModifierKeyRightShift: key = GHOST_kKeyRightShift; break;
case GHOST_kModifierKeyLeftAlt: key = GHOST_kKeyLeftAlt; break;
case GHOST_kModifierKeyRightAlt: key = GHOST_kKeyRightAlt; break;
case GHOST_kModifierKeyLeftControl: key = GHOST_kKeyLeftControl; break;
case GHOST_kModifierKeyRightControl: key = GHOST_kKeyRightControl; break;
case GHOST_kModifierKeyOS: key = GHOST_kKeyOS; break;
default:
// Should not happen
key = GHOST_kKeyUnknown;
break;
}
return key;
}
bool GHOST_ModifierKeys::get(GHOST_TModifierKeyMask mask) const
{
switch (mask) {
case GHOST_kModifierKeyLeftShift:
return m_LeftShift;
case GHOST_kModifierKeyRightShift:
return m_RightShift;
case GHOST_kModifierKeyLeftAlt:
return m_LeftAlt;
case GHOST_kModifierKeyRightAlt:
return m_RightAlt;
case GHOST_kModifierKeyLeftControl:
return m_LeftControl;
case GHOST_kModifierKeyRightControl:
return m_RightControl;
case GHOST_kModifierKeyOS:
return m_OS;
default:
return false;
}
}
void GHOST_ModifierKeys::set(GHOST_TModifierKeyMask mask, bool down)
{
switch (mask) {
case GHOST_kModifierKeyLeftShift:
m_LeftShift = down; break;
case GHOST_kModifierKeyRightShift:
m_RightShift = down; break;
case GHOST_kModifierKeyLeftAlt:
m_LeftAlt = down; break;
case GHOST_kModifierKeyRightAlt:
m_RightAlt = down; break;
case GHOST_kModifierKeyLeftControl:
m_LeftControl = down; break;
case GHOST_kModifierKeyRightControl:
m_RightControl = down; break;
case GHOST_kModifierKeyOS:
m_OS = down; break;
default:
break;
}
}
void GHOST_ModifierKeys::clear()
{
m_LeftShift = false;
m_RightShift = false;
m_LeftAlt = false;
m_RightAlt = false;
m_LeftControl = false;
m_RightControl = false;
m_OS = false;
}
bool GHOST_ModifierKeys::equals(const GHOST_ModifierKeys& keys) const
{
return (m_LeftShift == keys.m_LeftShift) &&
(m_RightShift == keys.m_RightShift) &&
(m_LeftAlt == keys.m_LeftAlt) &&
(m_RightAlt == keys.m_RightAlt) &&
(m_LeftControl == keys.m_LeftControl) &&
(m_RightControl == keys.m_RightControl) &&
(m_OS == keys.m_OS);
}

View File

@@ -0,0 +1,105 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_ModifierKeys.h
* \ingroup GHOST
* Declaration of GHOST_ModifierKeys struct.
*/
#ifndef _GHOST_MODIFIER_KEYS_H_
#define _GHOST_MODIFIER_KEYS_H_
#include "GHOST_Types.h"
/**
* Stores the state of modifier keys.
* Discriminates between left and right modifier keys.
* @author Maarten Gribnau
* @date May 17, 2001
*/
struct GHOST_ModifierKeys
{
/**
* Constructor.
*/
GHOST_ModifierKeys();
virtual ~GHOST_ModifierKeys();
/**
* Returns the modifier key's key code from a modifier key mask.
* @param mask The mask of the modifier key.
* @return The modifier key's key code.
*/
static GHOST_TKey getModifierKeyCode(GHOST_TModifierKeyMask mask);
/**
* Returns the state of a single modifier key.
* @param mask. Key state to return.
* @return The state of the key (pressed == true).
*/
virtual bool get(GHOST_TModifierKeyMask mask) const;
/**
* Updates the state of a single modifier key.
* @param mask. Key state to update.
* @param down. The new state of the key.
*/
virtual void set(GHOST_TModifierKeyMask mask, bool down);
/**
* Sets the state of all modifier keys to up.
*/
virtual void clear();
/**
* Determines whether to modifier key states are equal.
* @param keys. The modifier key state to compare to.
* @return Indication of equality.
*/
virtual bool equals(const GHOST_ModifierKeys& keys) const;
/** Bitfield that stores the appropriate key state. */
GHOST_TUns8 m_LeftShift : 1;
/** Bitfield that stores the appropriate key state. */
GHOST_TUns8 m_RightShift : 1;
/** Bitfield that stores the appropriate key state. */
GHOST_TUns8 m_LeftAlt : 1;
/** Bitfield that stores the appropriate key state. */
GHOST_TUns8 m_RightAlt : 1;
/** Bitfield that stores the appropriate key state. */
GHOST_TUns8 m_LeftControl : 1;
/** Bitfield that stores the appropriate key state. */
GHOST_TUns8 m_RightControl : 1;
/** Bitfield that stores the appropriate key state. */
GHOST_TUns8 m_OS : 1;
};
#endif // _GHOST_MODIFIER_KEYS_H_

View File

@@ -0,0 +1,132 @@
/*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_NDOFManager.cpp
* \ingroup GHOST
*/
#include <stdio.h> /* just for printf */
#include "GHOST_NDOFManager.h"
// the variable is outside the class because it must be accessed from plugin
static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
#if !defined(_WIN32) && !defined(__APPLE__)
#include "GHOST_SystemX11.h"
#endif
namespace
{
GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
}
GHOST_NDOFManager::GHOST_NDOFManager()
{
m_DeviceHandle = 0;
// discover the API from the plugin
ndofLibraryInit = 0;
ndofLibraryShutdown = 0;
ndofDeviceOpen = 0;
}
GHOST_NDOFManager::~GHOST_NDOFManager()
{
if (ndofLibraryShutdown)
ndofLibraryShutdown(m_DeviceHandle);
m_DeviceHandle = 0;
}
int
GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
{
int Pid;
ndofLibraryInit = setNdofLibraryInit;
ndofLibraryShutdown = setNdofLibraryShutdown;
ndofDeviceOpen = setNdofDeviceOpen;
if (ndofLibraryInit && ndofDeviceOpen)
{
Pid= ndofLibraryInit();
#if 0
printf("%i client \n", Pid);
#endif
#if defined(_WIN32) || defined(__APPLE__)
m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);
#else
GHOST_SystemX11 *sys;
sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
void *ndofInfo = sys->prepareNdofInfo(&currentNdofValues);
m_DeviceHandle = ndofDeviceOpen(ndofInfo);
#endif
return (Pid > 0) ? 0 : 1;
} else
return 1;
}
bool
GHOST_NDOFManager::available() const
{
return m_DeviceHandle != 0;
}
bool
GHOST_NDOFManager::event_present() const
{
if( currentNdofValues.changed >0) {
printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n" ,
currentNdofValues.time, currentNdofValues.buttons,
currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
return true;
}else
return false;
}
void GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
{
datas.tx = currentNdofValues.tx;
datas.ty = currentNdofValues.ty;
datas.tz = currentNdofValues.tz;
datas.rx = currentNdofValues.rx;
datas.ry = currentNdofValues.ry;
datas.rz = currentNdofValues.rz;
datas.buttons = currentNdofValues.buttons;
datas.client = currentNdofValues.client;
datas.address = currentNdofValues.address;
datas.time = currentNdofValues.time;
datas.delta = currentNdofValues.delta;
}

View File

@@ -0,0 +1,57 @@
/*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_NDOFManager.h
* \ingroup GHOST
*/
#ifndef _GHOST_NDOFMANAGER_H_
#define _GHOST_NDOFMANAGER_H_
#include "GHOST_System.h"
#include "GHOST_IWindow.h"
class GHOST_NDOFManager
{
public:
GHOST_NDOFManager();
virtual ~GHOST_NDOFManager();
int deviceOpen(GHOST_IWindow* window,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
void GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const;
bool available() const;
bool event_present() const;
protected:
void* m_DeviceHandle;
};
#endif

View File

@@ -0,0 +1,74 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 by Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Path-api.cpp
* \ingroup GHOST
*/
#include "intern/GHOST_Debug.h"
#include "GHOST_Types.h"
#include "GHOST_Path-api.h"
#include "GHOST_ISystemPaths.h"
GHOST_TSuccess GHOST_CreateSystemPaths(void)
{
return GHOST_ISystemPaths::create();;
}
GHOST_TSuccess GHOST_DisposeSystemPaths(void)
{
return GHOST_ISystemPaths::dispose();
}
const GHOST_TUns8* GHOST_getSystemDir()
{
GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get();
return systemPaths ? systemPaths->getSystemDir() : 0;
}
const GHOST_TUns8* GHOST_getUserDir()
{
GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get();
return systemPaths ? systemPaths->getUserDir() : 0; /* shouldn't be NULL */
}
const GHOST_TUns8* GHOST_getBinaryDir()
{
GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get();
return systemPaths ? systemPaths->getBinaryDir() : 0; /* shouldn't be NULL */
}
void GHOST_addToSystemRecentFiles(const char* filename)
{
GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get();
if (systemPaths) {
systemPaths->addToSystemRecentFiles(filename);
}
}

View File

@@ -0,0 +1,142 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Rect.cpp
* \ingroup GHOST
*/
#include "GHOST_Rect.h"
void GHOST_Rect::inset(GHOST_TInt32 i)
{
if (i > 0) {
// Grow the rectangle
m_l -= i;
m_r += i;
m_t -= i;
m_b += i;
}
else if (i < 0) {
// Shrink the rectangle, check for insets larger than half the size
GHOST_TInt32 i2 = i * 2;
if (getWidth() > i2) {
m_l += i;
m_r -= i;
}
else {
m_l = m_l + ((m_r - m_l) / 2);
m_r = m_l;
}
if (getHeight() > i2) {
m_t += i;
m_b -= i;
}
else {
m_t = m_t + ((m_b - m_t) / 2);
m_b = m_t;
}
}
}
GHOST_TVisibility GHOST_Rect::getVisibility(GHOST_Rect& r) const
{
bool lt = isInside(r.m_l, r.m_t);
bool rt = isInside(r.m_r, r.m_t);
bool lb = isInside(r.m_l, r.m_b);
bool rb = isInside(r.m_r, r.m_b);
GHOST_TVisibility v;
if (lt && rt && lb && rb) {
// All points inside, rectangle is inside this
v = GHOST_kFullyVisible;
}
else if (!(lt || rt || lb || rb)) {
// None of the points inside
// Check to see whether the rectangle is larger than this one
if ((r.m_l < m_l) && (r.m_t < m_t) && (r.m_r > m_r) && (r.m_b > m_b)) {
v = GHOST_kPartiallyVisible;
}
else {
v = GHOST_kNotVisible;
}
}
else {
// Some of the points inside, rectangle is partially inside
v = GHOST_kPartiallyVisible;
}
return v;
}
void GHOST_Rect::setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy)
{
GHOST_TInt32 offset = cx - (m_l + (m_r - m_l)/2);
m_l += offset;
m_r += offset;
offset = cy - (m_t + (m_b - m_t)/2);
m_t += offset;
m_b += offset;
}
void GHOST_Rect::setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, GHOST_TInt32 h)
{
long w_2, h_2;
w_2 = w >> 1;
h_2 = h >> 1;
m_l = cx - w_2;
m_t = cy - h_2;
m_r = m_l + w;
m_b = m_t + h;
}
bool GHOST_Rect::clip(GHOST_Rect& r) const
{
bool clipped = false;
if (r.m_l < m_l) {
r.m_l = m_l;
clipped = true;
}
if (r.m_t < m_t) {
r.m_t = m_t;
clipped = true;
}
if (r.m_r > m_r) {
r.m_r = m_r;
clipped = true;
}
if (r.m_b > m_b) {
r.m_b = m_b;
clipped = true;
}
return clipped;
}

View File

@@ -0,0 +1,357 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_System.cpp
* \ingroup GHOST
* \author Maarten Gribnau
* \date May 7, 2001
*/
#include "GHOST_System.h"
#include <time.h>
#include <stdio.h> /* just for printf */
#include "GHOST_DisplayManager.h"
#include "GHOST_EventManager.h"
#include "GHOST_NDOFManager.h"
#include "GHOST_TimerTask.h"
#include "GHOST_TimerManager.h"
#include "GHOST_WindowManager.h"
GHOST_System::GHOST_System()
: m_displayManager(0), m_timerManager(0), m_windowManager(0), m_eventManager(0), m_ndofManager(0)
{
}
GHOST_System::~GHOST_System()
{
exit();
}
GHOST_TUns64 GHOST_System::getMilliSeconds() const
{
GHOST_TUns64 millis = ::clock();
if (CLOCKS_PER_SEC != 1000) {
millis *= 1000;
millis /= CLOCKS_PER_SEC;
}
return millis;
}
GHOST_ITimerTask* GHOST_System::installTimer(GHOST_TUns64 delay, GHOST_TUns64 interval, GHOST_TimerProcPtr timerProc, GHOST_TUserDataPtr userData)
{
GHOST_TUns64 millis = getMilliSeconds();
GHOST_TimerTask* timer = new GHOST_TimerTask(millis+delay, interval, timerProc, userData);
if (timer) {
if (m_timerManager->addTimer(timer) == GHOST_kSuccess) {
// Check to see whether we need to fire the timer right away
m_timerManager->fireTimers(millis);
}
else {
delete timer;
timer = 0;
}
}
return timer;
}
GHOST_TSuccess GHOST_System::removeTimer(GHOST_ITimerTask* timerTask)
{
GHOST_TSuccess success = GHOST_kFailure;
if (timerTask) {
success = m_timerManager->removeTimer((GHOST_TimerTask*)timerTask);
}
return success;
}
GHOST_TSuccess GHOST_System::disposeWindow(GHOST_IWindow* window)
{
GHOST_TSuccess success;
/*
* Remove all pending events for the window.
*/
if (m_windowManager->getWindowFound(window)) {
m_eventManager->removeWindowEvents(window);
}
if (window == m_windowManager->getFullScreenWindow()) {
success = endFullScreen();
}
else {
if (m_windowManager->getWindowFound(window)) {
success = m_windowManager->removeWindow(window);
if (success) {
delete window;
}
}
else {
success = GHOST_kFailure;
}
}
return success;
}
bool GHOST_System::validWindow(GHOST_IWindow* window)
{
return m_windowManager->getWindowFound(window);
}
GHOST_TSuccess GHOST_System::beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
const bool stereoVisual)
{
GHOST_TSuccess success = GHOST_kFailure;
GHOST_ASSERT(m_windowManager, "GHOST_System::beginFullScreen(): invalid window manager")
if (m_displayManager) {
if (!m_windowManager->getFullScreen()) {
m_displayManager->getCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, m_preFullScreenSetting);
//GHOST_PRINT("GHOST_System::beginFullScreen(): activating new display settings\n");
success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, setting);
if (success == GHOST_kSuccess) {
//GHOST_PRINT("GHOST_System::beginFullScreen(): creating full-screen window\n");
success = createFullScreenWindow((GHOST_Window**)window, stereoVisual);
if (success == GHOST_kSuccess) {
m_windowManager->beginFullScreen(*window, stereoVisual);
}
else {
m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, m_preFullScreenSetting);
}
}
}
}
if (success == GHOST_kFailure) {
GHOST_PRINT("GHOST_System::beginFullScreen(): could not enter full-screen mode\n");
}
return success;
}
GHOST_TSuccess GHOST_System::endFullScreen(void)
{
GHOST_TSuccess success = GHOST_kFailure;
GHOST_ASSERT(m_windowManager, "GHOST_System::endFullScreen(): invalid window manager")
if (m_windowManager->getFullScreen()) {
//GHOST_IWindow* window = m_windowManager->getFullScreenWindow();
//GHOST_PRINT("GHOST_System::endFullScreen(): leaving window manager full-screen mode\n");
success = m_windowManager->endFullScreen();
GHOST_ASSERT(m_displayManager, "GHOST_System::endFullScreen(): invalid display manager")
//GHOST_PRINT("GHOST_System::endFullScreen(): leaving full-screen mode\n");
success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, m_preFullScreenSetting);
}
else {
success = GHOST_kFailure;
}
return success;
}
bool GHOST_System::getFullScreen(void)
{
bool fullScreen;
if (m_windowManager) {
fullScreen = m_windowManager->getFullScreen();
}
else {
fullScreen = false;
}
return fullScreen;
}
bool GHOST_System::dispatchEvents()
{
bool handled;
if (m_eventManager) {
handled = m_eventManager->dispatchEvents();
}
else {
handled = false;
}
m_timerManager->fireTimers(getMilliSeconds());
return handled;
}
GHOST_TSuccess GHOST_System::addEventConsumer(GHOST_IEventConsumer* consumer)
{
GHOST_TSuccess success;
if (m_eventManager) {
success = m_eventManager->addConsumer(consumer);
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_System::removeEventConsumer(GHOST_IEventConsumer* consumer)
{
GHOST_TSuccess success;
if (m_eventManager) {
success = m_eventManager->removeConsumer(consumer);
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent* event)
{
GHOST_TSuccess success;
if (m_eventManager) {
success = m_eventManager->pushEvent(event);
}
else {
success = GHOST_kFailure;
}
return success;
}
int GHOST_System::openNDOF(GHOST_IWindow* w,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
{
return m_ndofManager->deviceOpen(w,
setNdofLibraryInit,
setNdofLibraryShutdown,
setNdofDeviceOpen);
}
GHOST_TSuccess GHOST_System::getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const
{
GHOST_ModifierKeys keys;
// Get the state of all modifier keys
GHOST_TSuccess success = getModifierKeys(keys);
if (success) {
// Isolate the state of the key requested
isDown = keys.get(mask);
}
return success;
}
GHOST_TSuccess GHOST_System::getButtonState(GHOST_TButtonMask mask, bool& isDown) const
{
GHOST_Buttons buttons;
// Get the state of all mouse buttons
GHOST_TSuccess success = getButtons(buttons);
if (success) {
// Isolate the state of the mouse button requested
isDown = buttons.get(mask);
}
return success;
}
GHOST_TSuccess GHOST_System::init()
{
m_timerManager = new GHOST_TimerManager ();
m_windowManager = new GHOST_WindowManager ();
m_eventManager = new GHOST_EventManager ();
m_ndofManager = new GHOST_NDOFManager();
#if 0
if(m_ndofManager)
printf("ndof manager \n");
#endif
#ifdef GHOST_DEBUG
if (m_eventManager) {
m_eventPrinter = new GHOST_EventPrinter();
m_eventManager->addConsumer(m_eventPrinter);
}
#endif // GHOST_DEBUG
if (m_timerManager && m_windowManager && m_eventManager) {
return GHOST_kSuccess;
} else {
return GHOST_kFailure;
}
}
GHOST_TSuccess GHOST_System::exit()
{
if (getFullScreen()) {
endFullScreen();
}
if (m_displayManager) {
delete m_displayManager;
m_displayManager = 0;
}
if (m_windowManager) {
delete m_windowManager;
m_windowManager = 0;
}
if (m_timerManager) {
delete m_timerManager;
m_timerManager = 0;
}
if (m_eventManager) {
delete m_eventManager;
m_eventManager = 0;
}
if (m_ndofManager) {
delete m_ndofManager;
m_ndofManager = 0;
}
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window** window, const bool stereoVisual)
{
GHOST_TSuccess success;
GHOST_ASSERT(m_displayManager, "GHOST_System::createFullScreenWindow(): invalid display manager")
GHOST_DisplaySetting settings;
success = m_displayManager->getCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, settings);
if (success) {
//GHOST_PRINT("GHOST_System::createFullScreenWindow(): creating full-screen window\n");
*window = (GHOST_Window*)createWindow(
STR_String (""),
0, 0, settings.xPixels, settings.yPixels,
GHOST_kWindowStateFullScreen,
GHOST_kDrawingContextTypeOpenGL,
stereoVisual);
success = *window == 0 ? GHOST_kFailure : GHOST_kSuccess;
}
return success;
}

View File

@@ -0,0 +1,373 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_System.h
* \ingroup GHOST
* Declaration of GHOST_System class.
*/
#ifndef _GHOST_SYSTEM_H_
#define _GHOST_SYSTEM_H_
#include "GHOST_ISystem.h"
#include "GHOST_Debug.h"
#include "GHOST_Buttons.h"
#include "GHOST_ModifierKeys.h"
#include "GHOST_EventManager.h"
#ifdef GHOST_DEBUG
#include "GHOST_EventPrinter.h"
#endif // GHOST_DEBUG
class GHOST_DisplayManager;
class GHOST_Event;
class GHOST_TimerManager;
class GHOST_Window;
class GHOST_WindowManager;
class GHOST_NDOFManager;
/**
* Implementation of platform independent functionality of the GHOST_ISystem
* interface.
* GHOST_System is an abstract class because not all methods of GHOST_ISystem
* are implemented.
* @see GHOST_ISystem.
* @author Maarten Gribnau
* @date May 7, 2001
*/
class GHOST_System : public GHOST_ISystem
{
protected:
/**
* Constructor.
* Protected default constructor to force use of static createSystem member.
*/
GHOST_System();
/**
* Destructor.
* Protected default constructor to force use of static dispose member.
*/
virtual ~GHOST_System();
public:
/***************************************************************************************
** Time(r) functionality
***************************************************************************************/
/**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* Based on ANSI clock() routine.
* @return The number of milliseconds.
*/
virtual GHOST_TUns64 getMilliSeconds() const;
/**
* Installs a timer.
* Note that, on most operating systems, messages need to be processed in order
* for the timer callbacks to be invoked.
* @param delay The time to wait for the first call to the timerProc (in milliseconds)
* @param interval The interval between calls to the timerProc
* @param timerProc The callback invoked when the interval expires,
* @param userData Placeholder for user data.
* @return A timer task (0 if timer task installation failed).
*/
virtual GHOST_ITimerTask* installTimer(GHOST_TUns64 delay, GHOST_TUns64 interval, GHOST_TimerProcPtr timerProc, GHOST_TUserDataPtr userData = 0);
/**
* Removes a timer.
* @param timerTask Timer task to be removed.
* @return Indication of success.
*/
virtual GHOST_TSuccess removeTimer(GHOST_ITimerTask* timerTask);
/***************************************************************************************
** Display/window management functionality
***************************************************************************************/
/**
* Inherited from GHOST_ISystem but left pure virtual
*
* virtual GHOST_TUns8 getNumDisplays() const = 0;
* virtual void getMainDisplayDimensions(...) const = 0;
* virtual GHOST_IWindow* createWindow(..)
*/
/**
* Dispose a window.
* @param window Pointer to the window to be disposed.
* @return Indication of success.
*/
virtual GHOST_TSuccess disposeWindow(GHOST_IWindow* window);
/**
* Returns whether a window is valid.
* @param window Pointer to the window to be checked.
* @return Indication of validity.
*/
virtual bool validWindow(GHOST_IWindow* window);
/**
* Begins full screen mode.
* @param setting The new setting of the display.
* @param window Window displayed in full screen.
* @param stereoVisual Stereo visual for quad buffered stereo.
* This window is invalid after full screen has been ended.
* @return Indication of success.
*/
virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
const bool stereoVisual);
/**
* Ends full screen mode.
* @return Indication of success.
*/
virtual GHOST_TSuccess endFullScreen(void);
/**
* Returns current full screen mode status.
* @return The current status.
*/
virtual bool getFullScreen(void);
/***************************************************************************************
** Event management functionality
***************************************************************************************/
/**
* Inherited from GHOST_ISystem but left pure virtual
*
* virtual bool processEvents(bool waitForEvent) = 0;
*/
/**
* Dispatches all the events on the stack.
* The event stack will be empty afterwards.
* @return Indication as to whether any of the consumers handled the events.
*/
virtual bool dispatchEvents();
/**
* Adds the given event consumer to our list.
* @param consumer The event consumer to add.
* @return Indication of success.
*/
virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer);
/**
* Remove the given event consumer to our list.
* @param consumer The event consumer to remove.
* @return Indication of success.
*/
virtual GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer* consumer);
/***************************************************************************************
** N-degree of freedom devcice management functionality
***************************************************************************************/
/** Inherited from GHOST_ISystem
* Opens the N-degree of freedom device manager
* return 0 if device found, 1 otherwise
*/
virtual int openNDOF(GHOST_IWindow* w,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
// original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler);
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/** Inherited from GHOST_ISystem but left pure virtual
* GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const = 0;
* GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y)
*/
/***************************************************************************************
** Access to mouse button and keyboard states.
***************************************************************************************/
/**
* Returns the state of a modifier key (ouside the message queue).
* @param mask The modifier key state to retrieve.
* @param isDown The state of a modifier key (true == pressed).
* @return Indication of success.
*/
virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const;
/**
* Returns the state of a mouse button (ouside the message queue).
* @param mask The button state to retrieve.
* @param isDown Button state.
* @return Indication of success.
*/
virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const;
/***************************************************************************************
** Other (internal) functionality.
***************************************************************************************/
/**
* Pushes an event on the stack.
* To dispatch it, call dispatchEvent() or dispatchEvents().
* Do not delete the event!
* @param event The event to push on the stack.
*/
virtual GHOST_TSuccess pushEvent(GHOST_IEvent* event);
/**
* Returns the timer manager.
* @return The timer manager.
*/
inline virtual GHOST_TimerManager* getTimerManager() const;
/**
* Returns a pointer to our event manager.
* @return A pointer to our event manager.
*/
virtual inline GHOST_EventManager* getEventManager() const;
/**
* Returns a pointer to our window manager.
* @return A pointer to our window manager.
*/
virtual inline GHOST_WindowManager* getWindowManager() const;
/**
* Returns a pointer to our n-degree of freedeom manager.
* @return A pointer to our n-degree of freedeom manager.
*/
virtual inline GHOST_NDOFManager* getNDOFManager() const;
/**
* Returns the state of all modifier keys.
* @param keys The state of all modifier keys (true == pressed).
* @return Indication of success.
*/
virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const = 0;
/**
* Returns the state of the mouse buttons (ouside the message queue).
* @param buttons The state of the buttons.
* @return Indication of success.
*/
virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const = 0;
/**
* Returns the selection buffer
* @param selection Only used on X11
* @return Returns the clipboard data
*
*/
virtual GHOST_TUns8* getClipboard(bool selection) const = 0;
/**
* Put data to the Clipboard
* @param buffer The buffer to copy to the clipboard
* @param selection The clipboard to copy too only used on X11
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
protected:
/**
* Initialize the system.
* @return Indication of success.
*/
virtual GHOST_TSuccess init();
/**
* Shut the system down.
* @return Indication of success.
*/
virtual GHOST_TSuccess exit();
/**
* Creates a fullscreen window.
* @param window The window created.
* @return Indication of success.
*/
virtual GHOST_TSuccess createFullScreenWindow(GHOST_Window** window,
const bool stereoVisual);
/** The display manager (platform dependant). */
GHOST_DisplayManager* m_displayManager;
/** The timer manager. */
GHOST_TimerManager* m_timerManager;
/** The window manager. */
GHOST_WindowManager* m_windowManager;
/** The event manager. */
GHOST_EventManager* m_eventManager;
/** The N-degree of freedom device manager */
GHOST_NDOFManager* m_ndofManager;
/** Prints all the events. */
#ifdef GHOST_DEBUG
GHOST_EventPrinter* m_eventPrinter;
#endif // GHOST_DEBUG
/** Settings of the display before the display went fullscreen. */
GHOST_DisplaySetting m_preFullScreenSetting;
};
inline GHOST_TimerManager* GHOST_System::getTimerManager() const
{
return m_timerManager;
}
inline GHOST_EventManager* GHOST_System::getEventManager() const
{
return m_eventManager;
}
inline GHOST_WindowManager* GHOST_System::getWindowManager() const
{
return m_windowManager;
}
inline GHOST_NDOFManager* GHOST_System::getNDOFManager() const
{
return m_ndofManager;
}
#endif // _GHOST_SYSTEM_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,290 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemCarbon.h
* \ingroup GHOST
* Declaration of GHOST_SystemCarbon class.
*/
#ifndef _GHOST_SYSTEM_CARBON_H_
#define _GHOST_SYSTEM_CARBON_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#define __CARBONSOUND__
#include <Carbon/Carbon.h>
#include "GHOST_System.h"
class GHOST_EventCursor;
class GHOST_EventKey;
class GHOST_EventWindow;
/**
* OSX/Carbon Implementation of GHOST_System class.
* @see GHOST_System.
* @author Maarten Gribnau
* @date May 21, 2001
*/
class GHOST_SystemCarbon : public GHOST_System {
public:
/**
* Constructor.
*/
GHOST_SystemCarbon();
/**
* Destructor.
*/
~GHOST_SystemCarbon();
/***************************************************************************************
** Time(r) functionality
***************************************************************************************/
/**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* Based on ANSI clock() routine.
* @return The number of milliseconds.
*/
virtual GHOST_TUns64 getMilliSeconds() const;
/***************************************************************************************
** Display/window management functionality
***************************************************************************************/
/**
* Returns the number of displays on this system.
* @return The number of displays.
*/
virtual GHOST_TUns8 getNumDisplays() const;
/**
* Returns the dimensions of the main display on this system.
* @return The dimension of the main display.
*/
virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
/**
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
virtual GHOST_IWindow* createWindow(
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const bool stereoVisual,
const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0
);
virtual GHOST_TSuccess beginFullScreen(
const GHOST_DisplaySetting& setting,
GHOST_IWindow** window,
const bool stereoVisual
);
virtual GHOST_TSuccess endFullScreen( void );
/***************************************************************************************
** Event management functionality
***************************************************************************************/
/**
* Gets events from the system and stores them in the queue.
* @param waitForEvent Flag to wait for an event (or return immediately).
* @return Indication of the presence of events.
*/
virtual bool processEvents(bool waitForEvent);
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/**
* Returns the current location of the cursor (location in screen coordinates)
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
/**
* Updates the location of the cursor (location in screen coordinates).
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
/***************************************************************************************
** Access to mouse button and keyboard states.
***************************************************************************************/
/**
* Returns the state of all modifier keys.
* @param keys The state of all modifier keys (true == pressed).
* @return Indication of success.
*/
virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
/**
* Returns the state of the mouse buttons (ouside the message queue).
* @param buttons The state of the buttons.
* @return Indication of success.
*/
virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
/**
* Returns Clipboard data
* @param selection Indicate which buffer to return
* @return Returns the selected buffer
*/
virtual GHOST_TUns8* getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard
* @param buffer The buffer to be copied
* @param selection Indicates which buffer to copy too, only used on X11
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* @see GHOST_ISystem
*/
int toggleConsole(int action) { return 0; }
protected:
/**
* Initializes the system.
* For now, it justs registers the window class (WNDCLASS).
* @return A success value.
*/
virtual GHOST_TSuccess init();
/**
* Closes the system down.
* @return A success value.
*/
virtual GHOST_TSuccess exit();
/**
* Handles a tablet event.
* @param event A Mac event.
* @return Indication whether the event was handled.
*/
OSStatus handleTabletEvent(EventRef event);
/**
* Handles a mouse event.
* @param event A Mac event.
* @return Indication whether the event was handled.
*/
OSStatus handleMouseEvent(EventRef event);
/**
* Handles a key event.
* @param event A Mac event.
* @return Indication whether the event was handled.
*/
OSStatus handleKeyEvent(EventRef event);
/**
* Handles a window event.
* @param event A Mac event.
* @return Indication whether the event was handled.
*/
OSStatus handleWindowEvent(EventRef event);
/**
* Handles all basic Mac application stuff for a mouse down event.
* @param event A Mac event.
* @return Indication whether the event was handled.
*/
bool handleMouseDown(EventRef event);
/**
* Handles a Mac menu command.
* @param menuResult A Mac menu/item identifier.
* @return Indication whether the event was handled.
*/
bool handleMenuCommand(GHOST_TInt32 menuResult);
/* callback for blender generated events */
// static OSStatus blendEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData);
/**
* Callback for Carbon when it has events.
*/
static OSStatus sEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData);
/** Apple Event Handlers */
static OSErr sAEHandlerLaunch(const AppleEvent *event, AppleEvent *reply, SInt32 refCon);
static OSErr sAEHandlerOpenDocs(const AppleEvent *event, AppleEvent *reply, SInt32 refCon);
static OSErr sAEHandlerPrintDocs(const AppleEvent *event, AppleEvent *reply, SInt32 refCon);
static OSErr sAEHandlerQuit(const AppleEvent *event, AppleEvent *reply, SInt32 refCon);
/**
* Callback for Mac Timer tasks that expire.
* @param tmTask Pointer to the timer task that expired.
*/
//static void s_timerCallback(TMTaskPtr tmTask);
/** Event handler reference. */
EventHandlerRef m_handler;
/** Start time at initialization. */
GHOST_TUns64 m_start_time;
/** State of the modifiers. */
UInt32 m_modifierMask;
/** Ignores window size messages (when window is dragged). */
bool m_ignoreWindowSizedMessages;
};
#endif // _GHOST_SYSTEM_CARBON_H_

View File

@@ -0,0 +1,306 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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): Maarten Gribnau 05/2001
* Damien Plisson 09/2009
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemCocoa.h
* \ingroup GHOST
* Declaration of GHOST_SystemCocoa class.
*/
#ifndef _GHOST_SYSTEM_COCOA_H_
#define _GHOST_SYSTEM_COCOA_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
//#define __CARBONSOUND__
#include "GHOST_System.h"
class GHOST_EventCursor;
class GHOST_EventKey;
class GHOST_EventWindow;
class GHOST_WindowCocoa;
class GHOST_SystemCocoa : public GHOST_System {
public:
/**
* Constructor.
*/
GHOST_SystemCocoa();
/**
* Destructor.
*/
~GHOST_SystemCocoa();
/***************************************************************************************
** Time(r) functionality
***************************************************************************************/
/**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* Based on ANSI clock() routine.
* @return The number of milliseconds.
*/
virtual GHOST_TUns64 getMilliSeconds() const;
/***************************************************************************************
** Display/window management functionality
***************************************************************************************/
/**
* Returns the number of displays on this system.
* @return The number of displays.
*/
virtual GHOST_TUns8 getNumDisplays() const;
/**
* Returns the dimensions of the main display on this system.
* @return The dimension of the main display.
*/
virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
/**
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
virtual GHOST_IWindow* createWindow(
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0
);
virtual GHOST_TSuccess beginFullScreen(
const GHOST_DisplaySetting& setting,
GHOST_IWindow** window,
const bool stereoVisual
);
virtual GHOST_TSuccess endFullScreen( void );
/***************************************************************************************
** Event management functionality
***************************************************************************************/
/**
* Gets events from the system and stores them in the queue.
* @param waitForEvent Flag to wait for an event (or return immediately).
* @return Indication of the presence of events.
*/
virtual bool processEvents(bool waitForEvent);
/**
* Handle User request to quit, from Menu bar Quit, and Cmd+Q
* Display alert panel if changes performed since last save
*/
GHOST_TUns8 handleQuitRequest();
/**
* Handle Cocoa openFile event
* Display confirmation request panel if changes performed since last save
*/
bool handleOpenDocumentRequest(void *filepathStr);
/**
* Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
* @param eventType The type of drag'n'drop event
* @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image)
* @param mouseX x mouse coordinate (in cocoa base window coordinates)
* @param mouseY y mouse coordinate
* @param window The window on which the event occurred
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,
GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data);
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/**
* Returns the current location of the cursor (location in screen coordinates)
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
/**
* Updates the location of the cursor (location in screen coordinates).
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
/***************************************************************************************
** Access to mouse button and keyboard states.
***************************************************************************************/
/**
* Returns the state of all modifier keys.
* @param keys The state of all modifier keys (true == pressed).
* @return Indication of success.
*/
virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
/**
* Returns the state of the mouse buttons (ouside the message queue).
* @param buttons The state of the buttons.
* @return Indication of success.
*/
virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
/**
* Returns Clipboard data
* @param selection Indicate which buffer to return
* @return Returns the selected buffer
*/
virtual GHOST_TUns8* getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard
* @param buffer The buffer to be copied
* @param selection Indicates which buffer to copy too, only used on X11
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* Handles a window event. Called by GHOST_WindowCocoa window delegate
* @param eventType The type of window event
* @param window The window on which the event occurred
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window);
/**
* Handles the Cocoa event telling the application has become active (again)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleApplicationBecomeActiveEvent();
/**
* @see GHOST_ISystem
*/
int toggleConsole(int action) { return 0; }
protected:
/**
* Initializes the system.
* For now, it justs registers the window class (WNDCLASS).
* @return A success value.
*/
virtual GHOST_TSuccess init();
/**
* Handles a tablet event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @param eventType The type of the event. It needs to be passed separately as it can be either directly in the event type, or as a subtype if combined with a mouse button event
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleTabletEvent(void *eventPtr, short eventType);
/**
* Handles a mouse event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleMouseEvent(void *eventPtr);
/**
* Handles a key event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleKeyEvent(void *eventPtr);
/**
* Performs the actual cursor position update (location in screen coordinates).
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
GHOST_TSuccess setMouseCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
/** Start time at initialization. */
GHOST_TUns64 m_start_time;
/** Event has been processed directly by Cocoa and has sent a ghost event to be dispatched */
bool m_outsideLoopEventProcessed;
/** Raised window is not yet known by the window manager, so delay application become active event handling */
bool m_needDelayedApplicationBecomeActiveEventProcessing;
/** Mouse buttons state */
GHOST_TUns32 m_pressedMouseButtons;
/** State of the modifiers. */
GHOST_TUns32 m_modifierMask;
/** Ignores window size messages (when window is dragged). */
bool m_ignoreWindowSizedMessages;
/** Stores the mouse cursor delta due to setting a new cursor position
* Needed because cocoa event delta cursor move takes setCursorPosition changes too.
*/
GHOST_TInt32 m_cursorDelta_x, m_cursorDelta_y;
/** Multitouch trackpad availability */
bool m_hasMultiTouchTrackpad;
/** Multitouch gesture in progress, useful to distinguish trackpad from mouse scroll events */
bool m_isGestureInProgress;
};
#endif // _GHOST_SYSTEM_COCOA_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,84 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPaths.h
* \ingroup GHOST
*/
#ifndef _GHOST_SYSTEMPATHS_H_
#define _GHOST_SYSTEMPATHS_H_
#include "GHOST_ISystemPaths.h"
class GHOST_SystemPaths : public GHOST_ISystemPaths
{
protected:
/**
* Constructor.
* Protected default constructor to force use of static createSystem member.
*/
GHOST_SystemPaths(){};
/**
* Destructor.
* Protected default constructor to force use of static dispose member.
*/
virtual ~GHOST_SystemPaths(){};
public:
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const = 0;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const = 0;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
/**
* Add the file to the operating system most recently used files
*/
virtual void addToSystemRecentFiles(const char* filename) const = 0;
};
#endif

View File

@@ -0,0 +1,88 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPathsCarbon.cpp
* \ingroup GHOST
*/
#include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
#include "GHOST_SystemPathsCarbon.h"
/***/
GHOST_SystemPathsCarbon::GHOST_SystemPathsCarbon()
{
}
GHOST_SystemPathsCarbon::~GHOST_SystemPathsCarbon()
{
}
const GHOST_TUns8* GHOST_SystemPathsCarbon::getSystemDir() const
{
return (GHOST_TUns8*)"/Library/Application Support";
}
const GHOST_TUns8* GHOST_SystemPathsCarbon::getUserDir() const
{
static char usrPath[256] = "";
char* env = getenv("HOME");
if (env) {
strncpy(usrPath, env, 245);
usrPath[245]=0;
strcat(usrPath, "/Library/Application Support");
return (GHOST_TUns8*) usrPath;
}
else
return NULL;
}
const GHOST_TUns8* GHOST_SystemPathsCarbon::getBinaryDir() const
{
CFURLRef bundleURL;
CFStringRef pathStr;
static char path[256];
CFBundleRef mainBundle = CFBundleGetMainBundle();
bundleURL = CFBundleCopyBundleURL(mainBundle);
pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII);
CFRelease(pathStr);
CFRelease(bundleURL);
return (GHOST_TUns8*)path;
}
void GHOST_SystemPathsCarbon::addToSystemRecentFiles(const char* filename) const
{
/* XXXXX TODO: Implementation for Carbon if possible */
}

View File

@@ -0,0 +1,92 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPathsCarbon.h
* \ingroup GHOST
*/
#ifndef _GHOST_SYSTEM_PATHS_CARBON_H_
#define _GHOST_SYSTEM_PATHS_CARBON_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#include <Carbon/Carbon.h>
#include "GHOST_SystemPaths.h"
/**
* OSX/Carbon Implementation of GHOST_SystemPaths class.
* @see GHOST_System.
* @author Andrea Weikert
* @date Aug 1, 2010
*/
class GHOST_SystemPathsCarbon : public GHOST_SystemPaths {
public:
/**
* Constructor.
*/
GHOST_SystemPathsCarbon();
/**
* Destructor.
*/
~GHOST_SystemPathsCarbon();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
/**
* Add the file to the operating system most recently used files
*/
void addToSystemRecentFiles(const char* filename) const;
};
#endif // _GHOST_SYSTEM_CARBON_H_

View File

@@ -0,0 +1,84 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPathsCocoa.h
* \ingroup GHOST
*/
#ifndef _GHOST_SYSTEM_PATHS_COCOA_H_
#define _GHOST_SYSTEM_PATHS_COCOA_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#include "GHOST_SystemPaths.h"
class GHOST_SystemPathsCocoa : public GHOST_SystemPaths {
public:
/**
* Constructor.
*/
GHOST_SystemPathsCocoa();
/**
* Destructor.
*/
~GHOST_SystemPathsCocoa();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
/**
* Add the file to the operating system most recently used files
*/
void addToSystemRecentFiles(const char* filename) const;
};
#endif // _GHOST_SYSTEM_COCOA_H_

View File

@@ -0,0 +1,121 @@
/**
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
#import <Cocoa/Cocoa.h>
/*For the currently not ported to Cocoa keyboard layout functions (64bit & 10.6 compatible)*/
#include <Carbon/Carbon.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include "GHOST_SystemPathsCocoa.h"
#pragma mark initialization/finalization
GHOST_SystemPathsCocoa::GHOST_SystemPathsCocoa()
{
}
GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa()
{
}
#pragma mark Base directories retrieval
const GHOST_TUns8* GHOST_SystemPathsCocoa::getSystemDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0)
basePath = [paths objectAtIndex:0];
else {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
const GHOST_TUns8* GHOST_SystemPathsCocoa::getUserDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [paths objectAtIndex:0];
else {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
const GHOST_TUns8* GHOST_SystemPathsCocoa::getBinaryDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
basePath = [[NSBundle mainBundle] bundlePath];
if (basePath == nil) {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char* filename) const
{
/* XXXXX TODO: Implementation for X11 if possible */
}

View File

@@ -0,0 +1,115 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2011 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Blender Foundation
* Andrea Weikert
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPathsWin32.cpp
* \ingroup GHOST
*/
#include "GHOST_SystemPathsWin32.h"
#define WIN32_LEAN_AND_MEAN
#ifdef _WIN32_IE
#undef _WIN32_IE
#endif
#define _WIN32_IE 0x0501
#include <windows.h>
#include <shlobj.h>
#if defined(__MINGW32__) || defined(__CYGWIN__)
#if !defined(SHARD_PIDL)
#define SHARD_PIDL 0x00000001L
#endif
#if !defined(SHARD_PATHA)
#define SHARD_PATHA 0x00000002L
#endif
#if !defined(SHARD_PATHA)
#define SHARD_PATHW 0x00000003L
#endif
#if !defined(SHARD_PATH)
#ifdef UNICODE
#define SHARD_PATH SHARD_PATHW
#else
#define SHARD_PATH SHARD_PATHA
#endif
#endif
#endif
GHOST_SystemPathsWin32::GHOST_SystemPathsWin32()
{
}
GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32()
{
}
const GHOST_TUns8* GHOST_SystemPathsWin32::getSystemDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemPathsWin32::getUserDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const
{
static char fullname[MAX_PATH];
if(GetModuleFileName(0, fullname, MAX_PATH)) {
return (GHOST_TUns8*)fullname;
}
return NULL;
}
void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char* filename) const
{
/* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */
SHAddToRecentDocs(SHARD_PATH,filename);
}

View File

@@ -0,0 +1,91 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPathsWin32.h
* \ingroup GHOST
*/
#ifndef _GHOST_SYSTEM_PATHS_WIN32_H_
#define _GHOST_SYSTEM_PATHS_WIN32_H_
#ifndef WIN32
#error WIN32 only!
#endif // WIN32
#include <windows.h>
#include "GHOST_SystemPaths.h"
/**
* WIN32 Implementation of GHOST_SystemPaths class.
* @see GHOST_SystemPaths.
* @author Andrea Weikert
* @date August 1, 2010
*/
class GHOST_SystemPathsWin32 : public GHOST_SystemPaths {
public:
/**
* Constructor.
*/
GHOST_SystemPathsWin32();
/**
* Destructor.
*/
virtual ~GHOST_SystemPathsWin32();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/).
*/
const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/).
*/
const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
const GHOST_TUns8* getBinaryDir() const;
/**
* Add the file to the operating system most recently used files
*/
void addToSystemRecentFiles(const char* filename) const;
};
#endif // _GHOST_SYSTEM_PATHS_WIN32_H_

View File

@@ -0,0 +1,85 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPathsX11.cpp
* \ingroup GHOST
*/
#include "GHOST_SystemPathsX11.h"
#include "GHOST_Debug.h"
// For timing
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h> // for fprintf only
#include <cstdlib> // for exit
using namespace std;
GHOST_SystemPathsX11::GHOST_SystemPathsX11()
{
}
GHOST_SystemPathsX11::~GHOST_SystemPathsX11()
{
}
const GHOST_TUns8* GHOST_SystemPathsX11::getSystemDir() const
{
/* no prefix assumes a portable build which only uses bundled scripts */
#ifdef PREFIX
return (GHOST_TUns8*) PREFIX "/share";
#else
return NULL;
#endif
}
const GHOST_TUns8* GHOST_SystemPathsX11::getUserDir() const
{
const char* env = getenv("HOME");
if(env) {
return (GHOST_TUns8*) env;
} else {
return NULL;
}
}
const GHOST_TUns8* GHOST_SystemPathsX11::getBinaryDir() const
{
return NULL;
}
void GHOST_SystemPathsX11::addToSystemRecentFiles(const char* filename) const
{
/* XXXXX TODO: Implementation for X11 if possible */
}

View File

@@ -0,0 +1,82 @@
/*
* $Id$
*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemPathsX11.h
* \ingroup GHOST
*/
#ifndef _GHOST_SYSTEM_PATHS_X11_H_
#define _GHOST_SYSTEM_PATHS_X11_H_
#include "GHOST_SystemPaths.h"
#include "../GHOST_Types.h"
class GHOST_SystemPathsX11 : public GHOST_SystemPaths {
public:
/**
* Constructor
* this class should only be instanciated by GHOST_ISystem.
*/
GHOST_SystemPathsX11();
/**
* Destructor.
*/
virtual ~GHOST_SystemPathsX11();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
const GHOST_TUns8* getBinaryDir() const;
/**
* Add the file to the operating system most recently used files
*/
void addToSystemRecentFiles(const char* filename) const;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,489 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemWin32.h
* \ingroup GHOST
* Declaration of GHOST_SystemWin32 class.
*/
#ifndef _GHOST_SYSTEM_WIN32_H_
#define _GHOST_SYSTEM_WIN32_H_
#ifndef WIN32
#error WIN32 only!
#endif // WIN32
#include <windows.h>
#include "GHOST_System.h"
#if defined(__CYGWIN32__)
# define __int64 long long
#endif
#ifndef WM_INPUT
#define WM_INPUT 0x00FF
#endif
#ifndef RID_INPUT
#define RID_INPUT 0x10000003
#endif
#ifndef RI_KEY_BREAK
#define RI_KEY_BREAK 0x1
#endif
#ifndef RI_KEY_E0
#define RI_KEY_E0 0x2
#endif
#ifndef RI_KEY_E1
#define RI_KEY_E1 0x4
#endif
#ifndef RIM_TYPEMOUSE
#define RIM_TYPEMOUSE 0x0
#define RIM_TYPEKEYBOARD 0x1
#define RIM_TYPEHID 0x2
typedef struct tagRAWINPUTDEVICE {
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE;
typedef struct tagRAWINPUTHEADER {
DWORD dwType;
DWORD dwSize;
HANDLE hDevice;
WPARAM wParam;
} RAWINPUTHEADER;
typedef struct tagRAWMOUSE {
USHORT usFlags;
union {
ULONG ulButtons;
struct {
USHORT usButtonFlags;
USHORT usButtonData;
};
};
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformation;
} RAWMOUSE;
typedef struct tagRAWKEYBOARD {
USHORT MakeCode;
USHORT Flags;
USHORT Reserved;
USHORT VKey;
UINT Message;
ULONG ExtraInformation;
} RAWKEYBOARD;
typedef struct tagRAWHID {
DWORD dwSizeHid;
DWORD dwCount;
BYTE bRawData[1];
} RAWHID;
typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
} RAWINPUT;
DECLARE_HANDLE(HRAWINPUT);
#endif
#ifdef FREE_WINDOWS
#define NEED_RAW_PROC
typedef BOOL (WINAPI * LPFNDLLRRID)(RAWINPUTDEVICE*,UINT, UINT);
#define RegisterRawInputDevices(pRawInputDevices, uiNumDevices, cbSize) ((pRegisterRawInputDevices)?pRegisterRawInputDevices(pRawInputDevices, uiNumDevices, cbSize):0)
typedef UINT (WINAPI * LPFNDLLGRID)(HRAWINPUT, UINT, LPVOID, PUINT, UINT);
#define GetRawInputData(hRawInput, uiCommand, pData, pcbSize, cbSizeHeader) ((pGetRawInputData)?pGetRawInputData(hRawInput, uiCommand, pData, pcbSize, cbSizeHeader):(UINT)-1)
#endif
class GHOST_EventButton;
class GHOST_EventCursor;
class GHOST_EventKey;
class GHOST_EventWheel;
class GHOST_EventWindow;
class GHOST_EventDragnDrop;
/**
* WIN32 Implementation of GHOST_System class.
* @see GHOST_System.
* @author Maarten Gribnau
* @date May 10, 2001
*/
class GHOST_SystemWin32 : public GHOST_System {
public:
/**
* Constructor.
*/
GHOST_SystemWin32();
/**
* Destructor.
*/
virtual ~GHOST_SystemWin32();
/***************************************************************************************
** Time(r) functionality
***************************************************************************************/
/**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* This overloaded method uses the high frequency timer if available.
* @return The number of milliseconds.
*/
virtual GHOST_TUns64 getMilliSeconds() const;
/***************************************************************************************
** Display/window management functionality
***************************************************************************************/
/**
* Returns the number of displays on this system.
* @return The number of displays.
*/
virtual GHOST_TUns8 getNumDisplays() const;
/**
* Returns the dimensions of the main display on this system.
* @return The dimension of the main display.
*/
virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
/**
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
virtual GHOST_IWindow* createWindow(
const STR_String& title,
GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
GHOST_TWindowState state, GHOST_TDrawingContextType type,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0 );
/***************************************************************************************
** Event management functionality
***************************************************************************************/
/**
* Gets events from the system and stores them in the queue.
* @param waitForEvent Flag to wait for an event (or return immediately).
* @return Indication of the presence of events.
*/
virtual bool processEvents(bool waitForEvent);
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/**
* Returns the current location of the cursor (location in screen coordinates)
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
/**
* Updates the location of the cursor (location in screen coordinates).
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
/***************************************************************************************
** Access to mouse button and keyboard states.
***************************************************************************************/
/**
* Returns the state of all modifier keys.
* @param keys The state of all modifier keys (true == pressed).
* @return Indication of success.
*/
virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
/**
* Returns the state of the mouse buttons (ouside the message queue).
* @param buttons The state of the buttons.
* @return Indication of success.
*/
virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
/**
* Returns unsinged char from CUT_BUFFER0
* @param selection Used by X11 only
* @return Returns the Clipboard
*/
virtual GHOST_TUns8* getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard
* @param selection Used by X11 only
* @return No return
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* Creates a drag'n'drop event and pushes it immediately onto the event queue.
* Called by GHOST_DropTargetWin32 class.
* @param eventType The type of drag'n'drop event
* @param draggedObjectType The type object concerned (currently array of file names, string, ?bitmap)
* @param mouseX x mouse coordinate (in window coordinates)
* @param mouseY y mouse coordinate
* @param window The window on which the event occurred
* @return Indication whether the event was handled.
*/
static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,GHOST_IWindow* window, int mouseX, int mouseY, void* data);
protected:
/**
* Initializes the system.
* For now, it justs registers the window class (WNDCLASS).
* @return A success value.
*/
virtual GHOST_TSuccess init();
/**
* Closes the system down.
* @return A success value.
*/
virtual GHOST_TSuccess exit();
/**
* Converts raw WIN32 key codes from the wndproc to GHOST keys.
* @param window-> The window for this handling
* @param vKey The virtual key from hardKey
* @param ScanCode The ScanCode of pressed key (simular to PS/2 Set 1)
* @param extend Flag if key is not primerly (left or right)
* @return The GHOST key (GHOST_kKeyUnknown if no match).
*/
virtual GHOST_TKey convertKey(GHOST_IWindow *window, short vKey, short ScanCode, short extend) const;
/**
* Catches raw WIN32 key codes from WM_INPUT in the wndproc.
* @param window-> The window for this handling
* @param wParam The wParam from the wndproc
* @param lParam The lParam from the wndproc
* @param keyDown Pointer flag that specify if a key is down
* @param vk Pointer to virtual key
* @return The GHOST key (GHOST_kKeyUnknown if no match).
*/
virtual GHOST_TKey hardKey(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam, int * keyDown, char * vk);
/**
* Creates modifier key event(s) and updates the key data stored locally (m_modifierKeys).
* With the modifier keys, we want to distinguish left and right keys.
* Sometimes this is not possible (Windows ME for instance). Then, we want
* events generated for both keys.
* @param window The window receiving the event (the active window).
*/
GHOST_EventKey* processModifierKeys(GHOST_IWindow *window);
/**
* Creates mouse button event.
* @param type The type of event to create.
* @param window The window receiving the event (the active window).
* @param mask The button mask of this event.
* @return The event created.
*/
static GHOST_EventButton* processButtonEvent(GHOST_TEventType type, GHOST_IWindow *window, GHOST_TButtonMask mask);
/**
* Creates cursor event.
* @param type The type of event to create.
* @param window The window receiving the event (the active window).
* @return The event created.
*/
static GHOST_EventCursor* processCursorEvent(GHOST_TEventType type, GHOST_IWindow *Iwindow);
/**
* Creates a mouse wheel event.
* @param window The window receiving the event (the active window).
* @param wParam The wParam from the wndproc
* @param lParam The lParam from the wndproc
*/
static GHOST_EventWheel* processWheelEvent(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam);
/**
* Creates a key event and updates the key data stored locally (m_modifierKeys).
* In most cases this is a straightforward conversion of key codes.
* For the modifier keys however, we want to distinguish left and right keys.
* @param window The window receiving the event (the active window).
* @param wParam The wParam from the wndproc
* @param lParam The lParam from the wndproc
*/
static GHOST_EventKey* processKeyEvent(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam);
/**
* Process special keys (VK_OEM_*), to see if current key layout
* gives us anything special, like ! on french AZERTY.
* @param window The window receiving the event (the active window).
* @param vKey The virtual key from hardKey
* @param ScanCode The ScanCode of pressed key (simular to PS/2 Set 1)
*/
virtual GHOST_TKey processSpecialKey(GHOST_IWindow *window, short vKey, short scanCode) const;
/**
* Creates a window event.
* @param type The type of event to create.
* @param window The window receiving the event (the active window).
* @return The event created.
*/
static GHOST_Event* processWindowEvent(GHOST_TEventType type, GHOST_IWindow* window);
/**
* Handles minimum window size.
* @param minmax The MINMAXINFO structure.
*/
static void processMinMaxInfo(MINMAXINFO * minmax);
/**
* Returns the local state of the modifier keys (from the message queue).
* @param keys The state of the keys.
*/
inline virtual void retrieveModifierKeys(GHOST_ModifierKeys& keys) const;
/**
* Stores the state of the modifier keys locally.
* For internal use only!
* @param keys The new state of the modifier keys.
*/
inline virtual void storeModifierKeys(const GHOST_ModifierKeys& keys);
/**
* Check current key layout for AltGr
*/
inline virtual void handleKeyboardChange(void);
/**
* Windows call back routine for our window class.
*/
static LRESULT WINAPI s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
/**
* Initiates WM_INPUT messages from keyboard
*/
GHOST_TInt32 initKeyboardRawInput(void);
/**
* Toggles console
* @action 0 - Hides
* 1 - Shows
* 2 - Toggles
* 3 - Hides if it runs not from command line
* * - Does nothing
* @return current status (1 -visible, 0 - hidden)
*/
int toggleConsole(int action);
/** The current state of the modifier keys. */
GHOST_ModifierKeys m_modifierKeys;
/** State variable set at initialization. */
bool m_hasPerformanceCounter;
/** High frequency timer variable. */
__int64 m_freq;
/** High frequency timer variable. */
__int64 m_start;
/** AltGr on current keyboard layout. */
bool m_hasAltGr;
/** language identifier. */
WORD m_langId;
/** stores keyboard layout. */
HKL m_keylayout;
/** Console status */
int m_consoleStatus;
/** handle for user32.dll*/
HMODULE user32;
#ifdef NEED_RAW_PROC
/* pointer to RegisterRawInputDevices function */
LPFNDLLRRID pRegisterRawInputDevices;
/* pointer to GetRawInputData function */
LPFNDLLGRID pGetRawInputData;
#endif
};
inline void GHOST_SystemWin32::retrieveModifierKeys(GHOST_ModifierKeys& keys) const
{
keys = m_modifierKeys;
}
inline void GHOST_SystemWin32::storeModifierKeys(const GHOST_ModifierKeys& keys)
{
m_modifierKeys = keys;
}
inline void GHOST_SystemWin32::handleKeyboardChange(void)
{
m_keylayout = GetKeyboardLayout(0); // get keylayout for current thread
int i;
SHORT s;
// save the language identifier.
m_langId = LOWORD(m_keylayout);
for(m_hasAltGr = false, i = 32; i < 256; ++i) {
s = VkKeyScanEx((char)i, m_keylayout);
// s == -1 means no key that translates passed char code
// high byte contains shift state. bit 2 ctrl pressed, bit 4 alt pressed
// if both are pressed, we have AltGr keycombo on keylayout
if(s!=-1 && (s & 0x600) == 0x600) {
m_hasAltGr = true;
break;
}
}
}
#endif // _GHOST_SYSTEM_WIN32_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,312 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemX11.h
* \ingroup GHOST
* Declaration of GHOST_SystemX11 class.
*/
#ifndef _GHOST_SYSTEM_X11_H_
#define _GHOST_SYSTEM_X11_H_
#include <X11/Xlib.h>
#include <GL/glx.h>
#include "GHOST_System.h"
#include "../GHOST_Types.h"
class GHOST_WindowX11;
/**
* X11 Implementation of GHOST_System class.
* @see GHOST_System.
* @author Laurence Bourn
* @date October 26, 2001
*/
class GHOST_SystemX11 : public GHOST_System {
public:
/**
* Constructor
* this class should only be instanciated by GHOST_ISystem.
*/
GHOST_SystemX11(
);
/**
* Destructor.
*/
virtual ~GHOST_SystemX11();
GHOST_TSuccess
init(
);
/**
* @section Interface Inherited from GHOST_ISystem
*/
/**
* Returns the system time.
* Returns the number of milliseconds since the start of the system process.
* @return The number of milliseconds.
*/
GHOST_TUns64
getMilliSeconds(
) const;
/**
* Returns the number of displays on this system.
* @return The number of displays.
*/
GHOST_TUns8
getNumDisplays(
) const;
/**
* Returns the dimensions of the main display on this system.
* @return The dimension of the main display.
*/
void
getMainDisplayDimensions(
GHOST_TUns32& width,
GHOST_TUns32& height
) const;
/**
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Create a stereo visual for quad buffered stereo.
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
GHOST_IWindow*
createWindow(
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const bool stereoVisual,
const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0
);
/**
* @section Interface Inherited from GHOST_ISystem
*/
/**
* Retrieves events from the system and stores them in the queue.
* @param waitForEvent Flag to wait for an event (or return immediately).
* @return Indication of the presence of events.
*/
bool
processEvents(
bool waitForEvent
);
/**
* @section Interface Inherited from GHOST_System
*/
GHOST_TSuccess
getCursorPosition(
GHOST_TInt32& x,
GHOST_TInt32& y
) const;
GHOST_TSuccess
setCursorPosition(
GHOST_TInt32 x,
GHOST_TInt32 y
);
/**
* Returns the state of all modifier keys.
* @param keys The state of all modifier keys (true == pressed).
* @return Indication of success.
*/
GHOST_TSuccess
getModifierKeys(
GHOST_ModifierKeys& keys
) const ;
/**
* Returns the state of the mouse buttons (ouside the message queue).
* @param buttons The state of the buttons.
* @return Indication of success.
*/
GHOST_TSuccess
getButtons(
GHOST_Buttons& buttons
) const;
/**
* @section Interface Dirty
* Flag a window as dirty. This will
* generate a GHOST window update event on a call to processEvents()
*/
void
addDirtyWindow(
GHOST_WindowX11 * bad_wind
);
/**
* return a pointer to the X11 display structure
*/
Display *
getXDisplay(
) {
return m_display;
}
void *
prepareNdofInfo(
volatile GHOST_TEventNDOFData *current_values
);
/* Helped function for get data from the clipboard. */
void getClipboard_xcout(XEvent evt, Atom sel, Atom target,
unsigned char **txt, unsigned long *len,
unsigned int *context) const;
/**
* Returns unsinged char from CUT_BUFFER0
* @param selection Get selection, X11 only feature
* @return Returns the Clipboard indicated by Flag
*/
GHOST_TUns8 *getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard
* @param buffer The buffer to copy to the clipboard
* @param selection Set the selection into the clipboard, X11 only feature
*/
void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* @see GHOST_ISystem
*/
int toggleConsole(int action) { return 0; }
/**
* Atom used for ICCCM, WM-spec and Motif.
* We only need get this atom at the start, it's relative
* to the display not the window and are public for every
* window that need it.
*/
Atom m_wm_state;
Atom m_wm_change_state;
Atom m_net_state;
Atom m_net_max_horz;
Atom m_net_max_vert;
Atom m_net_fullscreen;
Atom m_motif;
Atom m_wm_take_focus;
Atom m_wm_protocols;
Atom m_delete_window_atom;
/* Atoms for Selection, copy & paste. */
Atom m_targets;
Atom m_string;
Atom m_compound_text;
Atom m_text;
Atom m_clipboard;
Atom m_primary;
Atom m_xclip_out;
Atom m_incr;
Atom m_utf8_string;
private :
Display * m_display;
/// The vector of windows that need to be updated.
std::vector<GHOST_WindowX11 *> m_dirty_windows;
/// Start time at initialization.
GHOST_TUns64 m_start_time;
/// A vector of keyboard key masks
char m_keyboard_vector[32];
/* to prevent multiple warp, we store the time of the last warp event
* and stop accumulating all events generated before that */
Time m_last_warp;
/**
* Return the ghost window associated with the
* X11 window xwind
*/
GHOST_WindowX11 *
findGhostWindow(
Window xwind
) const ;
void
processEvent(
XEvent *xe
);
Time
lastEventTime(
Time default_time
);
bool
generateWindowExposeEvents(
);
GHOST_TKey
convertXKey(
KeySym key
);
};
#endif

View File

@@ -0,0 +1,76 @@
/** \file ghost/intern/GHOST_TaskbarWin32.h
* \ingroup GHOST
*/
#ifndef GHOST_TASKBARWIN32_H_
#define GHOST_TASKBARWIN32_H_
#ifndef WIN32
#error WIN32 only!
#endif // WIN32
#include <windows.h>
#include <shlobj.h>
/* MinGW needs it */
#ifdef FREE_WINDOWS
#ifdef WINVER
#undef WINVER
#endif
#define WINVER 0x0501
#endif /* FREE_WINDOWS */
// ITaskbarList, ITaskbarList2 and ITaskbarList3 might be missing, present here in that case.
// Note, ITaskbarList3 is supported only since Windows 7, though. Check for that is done in
// GHOST_WindowWin32
#ifndef __ITaskbarList_INTERFACE_DEFINED__
#define __ITaskbarList_INTERFACE_DEFINED__
extern "C" {const GUID CLSID_TaskbarList = {0x56FDF344, 0xFD6D, 0x11D0, {0x95, 0x8A, 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90} };
const GUID IID_ITaskbarList = {0x56FDF342, 0xFD6D, 0x11D0, {0x95, 0x8A, 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90} }; }
class ITaskbarList : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE HrInit (void) = 0;
virtual HRESULT STDMETHODCALLTYPE AddTab (HWND hwnd) = 0;
virtual HRESULT STDMETHODCALLTYPE DeleteTab (HWND hwnd) = 0;
virtual HRESULT STDMETHODCALLTYPE ActivateTab (HWND hwnd) = 0;
virtual HRESULT STDMETHODCALLTYPE SetActiveAlt (HWND hwnd) = 0;
};
#endif /* ITaskbarList */
#ifndef __ITaskbarList2_INTERFACE_DEFINED__
#define __ITaskbarList2_INTERFACE_DEFINED__
extern "C" {const GUID IID_ITaskbarList2 = {0x602D4995, 0xB13A, 0x429b, {0xA6, 0x6E, 0x19, 0x35, 0xE4, 0x4F, 0x43, 0x17} }; }
class ITaskbarList2 : public ITaskbarList
{
public:
virtual HRESULT STDMETHODCALLTYPE MarkFullscreenWindow(HWND hwnd, BOOL fFullscreen) = 0;
};
#endif /* ITaskbarList2 */
#ifndef __ITaskbarList3_INTERFACE_DEFINED__
#define __ITaskbarList3_INTERFACE_DEFINED__
typedef enum THUMBBUTTONFLAGS {THBF_ENABLED = 0, THBF_DISABLED = 0x1, THBF_DISMISSONCLICK = 0x2, THBF_NOBACKGROUND = 0x4, THBF_HIDDEN = 0x8, THBF_NONINTERACTIVE = 0x10} THUMBBUTTONFLAGS;
typedef enum THUMBBUTTONMASK {THB_BITMAP = 0x1, THB_ICON = 0x2, THB_TOOLTIP = 0x4, THB_FLAGS = 0x8} THUMBBUTTONMASK;
typedef struct THUMBBUTTON {THUMBBUTTONMASK dwMask; UINT iId; UINT iBitmap; HICON hIcon; WCHAR szTip[260]; THUMBBUTTONFLAGS dwFlags; } THUMBBUTTON;
typedef enum TBPFLAG {TBPF_NOPROGRESS = 0, TBPF_INDETERMINATE = 0x1, TBPF_NORMAL = 0x2, TBPF_ERROR = 0x4, TBPF_PAUSED = 0x8 } TBPFLAG;
#define THBN_CLICKED 0x1800
extern "C" {const GUID IID_ITaskList3 = { 0xEA1AFB91, 0x9E28, 0x4B86, {0x90, 0xE9, 0x9E, 0x9F, 0x8A, 0x5E, 0xEF, 0xAF} };}
class ITaskbarList3 : public ITaskbarList2
{
public:
virtual HRESULT STDMETHODCALLTYPE SetProgressValue (HWND hwnd, ULONGLONG ullCompleted, ULONGLONG ullTotal) = 0;
virtual HRESULT STDMETHODCALLTYPE SetProgressState (HWND hwnd, TBPFLAG tbpFlags) = 0;
virtual HRESULT STDMETHODCALLTYPE RegisterTab (HWND hwndTab, HWND hwndMDI) = 0;
virtual HRESULT STDMETHODCALLTYPE UnregisterTab (HWND hwndTab) = 0;
virtual HRESULT STDMETHODCALLTYPE SetTabOrder (HWND hwndTab, HWND hwndInsertBefore) = 0;
virtual HRESULT STDMETHODCALLTYPE SetTabActive (HWND hwndTab, HWND hwndMDI, DWORD dwReserved) = 0;
virtual HRESULT STDMETHODCALLTYPE ThumbBarAddButtons (HWND hwnd, UINT cButtons, THUMBBUTTON * pButton) = 0;
virtual HRESULT STDMETHODCALLTYPE ThumbBarUpdateButtons (HWND hwnd, UINT cButtons, THUMBBUTTON * pButton) = 0;
virtual HRESULT STDMETHODCALLTYPE ThumbBarSetImageList (HWND hwnd, HIMAGELIST himl) = 0;
virtual HRESULT STDMETHODCALLTYPE SetOverlayIcon (HWND hwnd, HICON hIcon, LPCWSTR pszDescription) = 0;
virtual HRESULT STDMETHODCALLTYPE SetThumbnailTooltip (HWND hwnd, LPCWSTR pszTip) = 0;
virtual HRESULT STDMETHODCALLTYPE SetThumbnailClip (HWND hwnd, RECT *prcClip) = 0;
};
#endif /* ITaskbarList3 */
#endif /*GHOST_TASKBARWIN32_H_*/

View File

@@ -0,0 +1,165 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_TimerManager.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 31, 2001
*/
#include "GHOST_TimerManager.h"
#include <algorithm>
#include "GHOST_TimerTask.h"
GHOST_TimerManager::GHOST_TimerManager()
{
}
GHOST_TimerManager::~GHOST_TimerManager()
{
disposeTimers();
}
GHOST_TUns32 GHOST_TimerManager::getNumTimers()
{
return (GHOST_TUns32)m_timers.size();
}
bool GHOST_TimerManager::getTimerFound(GHOST_TimerTask* timer)
{
TTimerVector::const_iterator iter = std::find(m_timers.begin(), m_timers.end(), timer);
return iter != m_timers.end();
}
GHOST_TSuccess GHOST_TimerManager::addTimer(GHOST_TimerTask* timer)
{
GHOST_TSuccess success;
if (!getTimerFound(timer)) {
// Add the timer task
m_timers.push_back(timer);
success = GHOST_kSuccess;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_TimerManager::removeTimer(GHOST_TimerTask* timer)
{
GHOST_TSuccess success;
TTimerVector::iterator iter = std::find(m_timers.begin(), m_timers.end(), timer);
if (iter != m_timers.end()) {
// Remove the timer task
m_timers.erase(iter);
delete timer;
timer = 0;
success = GHOST_kSuccess;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TUns64 GHOST_TimerManager::nextFireTime()
{
GHOST_TUns64 smallest = GHOST_kFireTimeNever;
TTimerVector::iterator iter;
for (iter = m_timers.begin(); iter != m_timers.end(); iter++) {
GHOST_TUns64 next = (*iter)->getNext();
if (next<smallest)
smallest = next;
}
return smallest;
}
bool GHOST_TimerManager::fireTimers(GHOST_TUns64 time)
{
TTimerVector::iterator iter;
bool anyProcessed = false;
for (iter = m_timers.begin(); iter != m_timers.end(); iter++) {
if (fireTimer(time, *iter))
anyProcessed = true;
}
return anyProcessed;
}
bool GHOST_TimerManager::fireTimer(GHOST_TUns64 time, GHOST_TimerTask* task)
{
GHOST_TUns64 next = task->getNext();
// Check if the timer should be fired
if (time > next) {
// Fire the timer
GHOST_TimerProcPtr timerProc = task->getTimerProc();
GHOST_TUns64 start = task->getStart();
timerProc(task, time - start);
// Update the time at which we will fire it again
GHOST_TUns64 interval = task->getInterval();
GHOST_TUns64 numCalls = (next - start) / interval;
numCalls++;
next = start + numCalls * interval;
task->setNext(next);
return true;
} else {
return false;
}
}
void GHOST_TimerManager::disposeTimers()
{
while (m_timers.size() > 0) {
delete m_timers[0];
m_timers.erase(m_timers.begin());
}
}

View File

@@ -0,0 +1,126 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_TimerManager.h
* \ingroup GHOST
* Declaration of GHOST_TimerManager class.
*/
#ifndef _GHOST_TIMER_MANAGER_H_
#define _GHOST_TIMER_MANAGER_H_
#include <vector>
#include "GHOST_Types.h"
class GHOST_TimerTask;
/**
* Manages a list of timer tasks.
* Timer tasks added are owned by the manager.
* Don't delete timer task objects.
* @author Maarten Gribnau
* @date May 31, 2001
*/
class GHOST_TimerManager
{
public:
/**
* Constructor.
*/
GHOST_TimerManager();
/**
* Destructor.
*/
virtual ~GHOST_TimerManager();
/**
* Returns the number of timer tasks.
* @return The number of events on the stack.
*/
virtual GHOST_TUns32 getNumTimers();
/**
* Returns whther this timer task ins in our list.
* @return Indication of presence.
*/
virtual bool getTimerFound(GHOST_TimerTask* timer);
/**
* Adds a timer task to the list.
* It is only added when it not already present in the list.
* @param timer The timer task added to the list.
* @return Indication as to whether addition has succeeded.
*/
virtual GHOST_TSuccess addTimer(GHOST_TimerTask* timer);
/**
* Removes a timer task from the list.
* It is only removed when it is found in the list.
* @param timer The timer task to be removed from the list.
* @return Indication as to whether removal has succeeded.
*/
virtual GHOST_TSuccess removeTimer(GHOST_TimerTask* timer);
/**
* Finds the soonest time the next timer would fire.
* @return The soonest time the next timer would fire,
* or GHOST_kFireTimeNever if no timers exist.
*/
virtual GHOST_TUns64 nextFireTime();
/**
* Checks all timer tasks to see if they are expired and fires them if needed.
* @param time The current time.
* @return True if any timers were fired.
*/
virtual bool fireTimers(GHOST_TUns64 time);
/**
* Checks this timer task to see if they are expired and fires them if needed.
* @param time The current time.
* @param task The timer task to check and optionally fire.
* @return True if the timer fired.
*/
virtual bool fireTimer(GHOST_TUns64 time, GHOST_TimerTask* task);
protected:
/**
* Deletes all timers.
*/
void disposeTimers();
typedef std::vector<GHOST_TimerTask*> TTimerVector;
/** The list with event consumers. */
TTimerVector m_timers;
};
#endif // _GHOST_TIMER_MANAGER_H_

View File

@@ -0,0 +1,189 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_TimerTask.h
* \ingroup GHOST
* Declaration of GHOST_TimerTask class.
*/
#ifndef _GHOST_TIMER_TASK_H_
#define _GHOST_TIMER_TASK_H_
#include "GHOST_ITimerTask.h"
/**
* Implementation of a timer task.
* @author Maarten Gribnau
* @date May 28, 2001
*/
class GHOST_TimerTask : public GHOST_ITimerTask
{
public:
/**
* Constructor.
* @param start The timer start time.
* @param interval The interval between calls to the timerProc
* @param timerProc The callbak invoked when the interval expires.
* @param data The timer user data.
*/
GHOST_TimerTask(GHOST_TUns64 start, GHOST_TUns64 interval, GHOST_TimerProcPtr timerProc, GHOST_TUserDataPtr userData = 0)
: m_start(start), m_interval(interval), m_next(start), m_timerProc(timerProc), m_userData(userData), m_auxData(0)
{
}
/**
* Returns the timer start time.
* @return The timer start time.
*/
inline virtual GHOST_TUns64 getStart() const
{
return m_start;
}
/**
* Changes the timer start time.
* @param start The timer start time.
*/
virtual void setStart(GHOST_TUns64 start)
{
m_start = start;
}
/**
* Returns the timer interval.
* @return The timer interval.
*/
inline virtual GHOST_TUns64 getInterval() const
{
return m_interval;
}
/**
* Changes the timer interval.
* @param interval The timer interval.
*/
virtual void setInterval(GHOST_TUns64 interval)
{
m_interval = interval;
}
/**
* Returns the time the timerProc will be called.
* @return The time the timerProc will be called.
*/
inline virtual GHOST_TUns64 getNext() const
{
return m_next;
}
/**
* Changes the time the timerProc will be called.
* @param next The time the timerProc will be called.
*/
virtual void setNext(GHOST_TUns64 next)
{
m_next = next;
}
/**
* Returns the timer callback.
* @return the timer callback.
*/
inline virtual GHOST_TimerProcPtr getTimerProc() const
{
return m_timerProc;
}
/**
* Changes the timer callback.
* @param The timer callback.
*/
inline virtual void setTimerProc(const GHOST_TimerProcPtr timerProc)
{
m_timerProc = timerProc;
}
/**
* Returns the timer user data.
* @return The timer user data.
*/
inline virtual GHOST_TUserDataPtr getUserData() const
{
return m_userData;
}
/**
* Changes the time user data.
* @param data The timer user data.
*/
virtual void setUserData(const GHOST_TUserDataPtr userData)
{
m_userData = userData;
}
/**
* Returns the auxiliary storage room.
* @return The auxiliary storage room.
*/
inline virtual GHOST_TUns32 getAuxData() const
{
return m_auxData;
}
/**
* Changes the auxiliary storage room.
* @param auxData The auxiliary storage room.
*/
virtual void setAuxData(GHOST_TUns32 auxData)
{
m_auxData = auxData;
}
protected:
/** The time the timer task was started. */
GHOST_TUns64 m_start;
/** The interval between calls. */
GHOST_TUns64 m_interval;
/** The time the timerProc will be called. */
GHOST_TUns64 m_next;
/** The callback invoked when the timer expires. */
GHOST_TimerProcPtr m_timerProc;
/** The timer task user data. */
GHOST_TUserDataPtr m_userData;
/** Auxiliary storage room. */
GHOST_TUns32 m_auxData;
};
#endif // _GHOST_TIMER_TASK_H_

View File

@@ -0,0 +1,189 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Window.cpp
* \ingroup GHOST
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 10, 2001
*/
#include "GHOST_Window.h"
GHOST_Window::GHOST_Window(
const STR_String& /*title*/,
GHOST_TInt32 /*left*/, GHOST_TInt32 /*top*/, GHOST_TUns32 width, GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const bool stereoVisual,
const GHOST_TUns16 numOfAASamples)
:
m_drawingContextType(type),
m_cursorVisible(true),
m_cursorGrab(GHOST_kGrabDisable),
m_cursorShape(GHOST_kStandardCursorDefault),
m_stereoVisual(stereoVisual),
m_numOfAASamples(numOfAASamples)
{
m_isUnsavedChanges = false;
m_canAcceptDragOperation = false;
m_progressBarVisible = false;
m_cursorGrabAccumPos[0] = 0;
m_cursorGrabAccumPos[1] = 0;
m_fullScreen = state == GHOST_kWindowStateFullScreen;
if (m_fullScreen) {
m_fullScreenWidth = width;
m_fullScreenHeight = height;
}
}
GHOST_Window::~GHOST_Window()
{
}
void* GHOST_Window::getOSWindow() const
{
return NULL;
}
GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
{
GHOST_TSuccess success = GHOST_kSuccess;
if (type != m_drawingContextType) {
success = removeDrawingContext();
if (success) {
success = installDrawingContext(type);
m_drawingContextType = type;
}
else {
m_drawingContextType = GHOST_kDrawingContextTypeNone;
}
}
return success;
}
GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
{
if (setWindowCursorVisibility(visible)) {
m_cursorVisible = visible;
return GHOST_kSuccess;
}
else {
return GHOST_kFailure;
}
}
GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds)
{
if(m_cursorGrab == mode)
return GHOST_kSuccess;
if (setWindowCursorGrab(mode)) {
if(mode==GHOST_kGrabDisable)
m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1;
else if (bounds) {
m_cursorGrabBounds= *bounds;
} else { /* if bounds not defined, use window */
getClientBounds(m_cursorGrabBounds);
}
m_cursorGrab = mode;
return GHOST_kSuccess;
}
else {
return GHOST_kFailure;
}
}
GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect& bounds)
{
bounds= m_cursorGrabBounds;
return (bounds.m_l==-1 && bounds.m_r==-1) ? GHOST_kFailure : GHOST_kSuccess;
}
GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
{
if (setWindowCursorShape(cursorShape)) {
m_cursorShape = cursorShape;
return GHOST_kSuccess;
}
else {
return GHOST_kFailure;
}
}
GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
int hotX, int hotY)
{
return setCustomCursorShape( (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask,
16, 16, hotX, hotY, 0, 1 );
}
GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
int sizex, int sizey, int hotX, int hotY,
int fg_color, int bg_color )
{
if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey,hotX, hotY, fg_color, bg_color)) {
m_cursorShape = GHOST_kStandardCursorCustom;
return GHOST_kSuccess;
}
else {
return GHOST_kFailure;
}
}
void GHOST_Window::setAcceptDragOperation(bool canAccept)
{
m_canAcceptDragOperation = canAccept;
}
bool GHOST_Window::canAcceptDragOperation() const
{
return m_canAcceptDragOperation;
}
GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
{
m_isUnsavedChanges = isUnsavedChanges;
return GHOST_kSuccess;
}
bool GHOST_Window::getModifiedState()
{
return m_isUnsavedChanges;
}

View File

@@ -0,0 +1,395 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_Window.h
* \ingroup GHOST
* Declaration of GHOST_Window class.
*/
#ifndef _GHOST_WINDOW_H_
#define _GHOST_WINDOW_H_
#include "GHOST_IWindow.h"
class STR_String;
/**
* Platform independent implementation of GHOST_IWindow.
* Dimensions are given in screen coordinates that are relative to the
* upper-left corner of the screen.
* Implements part of the GHOST_IWindow interface and adds some methods to
* be implemented by childs of this class.
* @author Maarten Gribnau
* @date May 7, 2001
*/
class GHOST_Window : public GHOST_IWindow
{
public:
/**
* @section Interface inherited from GHOST_IWindow left for derived class
* implementation.
* virtual bool getValid() const = 0;
* virtual void setTitle(const STR_String& title) = 0;
* virtual void getTitle(STR_String& title) const = 0;
* virtual void getWindowBounds(GHOST_Rect& bounds) const = 0;
* virtual void getClientBounds(GHOST_Rect& bounds) const = 0;
* virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width) = 0;
* virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height) = 0;
* virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height) = 0;
* virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0;
* virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0;
* virtual GHOST_TWindowState getState() const = 0;
* virtual GHOST_TSuccess setState(GHOST_TWindowState state) = 0;
* virtual GHOST_TWindowOrder getOrder(void) = 0;
* virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order) = 0;
* virtual GHOST_TSuccess swapBuffers() = 0;
* virtual GHOST_TSuccess activateDrawingContext() = 0;
* virtual GHOST_TSuccess invalidate() = 0;
*/
/**
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
* @param title The text shown in the title bar of the window.
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param heigh The height the window.
* @param state The state the window is initially opened with.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_Window(
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0);
/**
* @section Interface inherited from GHOST_IWindow left for derived class
* implementation.
* virtual bool getValid() const = 0;
* virtual void setTitle(const STR_String& title) = 0;
* virtual void getTitle(STR_String& title) const = 0;
* virtual void getWindowBounds(GHOST_Rect& bounds) const = 0;
* virtual void getClientBounds(GHOST_Rect& bounds) const = 0;
* virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width) = 0;
* virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height) = 0;
* virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height) = 0;
* virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0;
* virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0;
* virtual GHOST_TWindowState getState() const = 0;
* virtual GHOST_TSuccess setState(GHOST_TWindowState state) = 0;
* virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order) = 0;
* virtual GHOST_TSuccess swapBuffers() = 0;
* virtual GHOST_TSuccess activateDrawingContext() = 0;
* virtual GHOST_TSuccess invalidate() = 0;
*/
/**
* Destructor.
* Closes the window and disposes resources allocated.
*/
virtual ~GHOST_Window();
/**
* Returns the associated OS object/handle
* @return The associated OS object/handle
*/
virtual void* getOSWindow() const;
/**
* Returns the current cursor shape.
* @return The current cursor shape.
*/
inline virtual GHOST_TStandardCursor getCursorShape() const;
/**
* Set the shape of the cursor.
* @param cursor The new cursor shape type id.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape);
/**
* Set the shape of the cursor to a custom cursor.
* @param bitmap The bitmap data for the cursor.
* @param mask The mask data for the cursor.
* @param hotX The X coordinate of the cursor hotspot.
* @param hotY The Y coordinate of the cursor hotspot.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 bitmap[16][2],
GHOST_TUns8 mask[16][2],
int hotX,
int hotY);
virtual GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 *bitmap,
GHOST_TUns8 *mask,
int sizex, int sizey,
int hotX, int hotY,
int fg_color, int bg_color);
/**
* Returns the visibility state of the cursor.
* @return The visibility state of the cursor.
*/
inline virtual bool getCursorVisibility() const;
inline virtual GHOST_TGrabCursorMode getCursorGrabMode() const;
inline virtual void getCursorGrabInitPos(GHOST_TInt32 &x, GHOST_TInt32 &y) const;
inline virtual void getCursorGrabAccum(GHOST_TInt32 &x, GHOST_TInt32 &y) const;
inline virtual void setCursorGrabAccum(GHOST_TInt32 x, GHOST_TInt32 y);
/**
* Shows or hides the cursor.
* @param visible The new visibility state of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorVisibility(bool visible);
/**
* Sets the cursor grab.
* @param mode The new grab state of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds);
/**
* Gets the cursor grab region, if unset the window is used.
* reset when grab is disabled.
*/
virtual GHOST_TSuccess getCursorGrabBounds(GHOST_Rect& bounds);
/**
* Sets the progress bar value displayed in the window/application icon
* @param progress The progress % (0.0 to 1.0)
*/
virtual GHOST_TSuccess setProgressBar(float progress) {return GHOST_kFailure;};
/**
* Hides the progress bar in the icon
*/
virtual GHOST_TSuccess endProgressBar() {return GHOST_kFailure;};
/**
* Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
*/
virtual void setAcceptDragOperation(bool canAccept);
/**
* Returns acceptance of the dropped object
* Usually called by the "object dropped" event handling function
*/
virtual bool canAcceptDragOperation() const;
/**
* Sets the window "modified" status, indicating unsaved changes
* @param isUnsavedChanges Unsaved changes or not
* @return Indication of success.
*/
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges);
/**
* Gets the window "modified" status, indicating unsaved changes
* @return True if there are unsaved changes
*/
virtual bool getModifiedState();
/**
* Returns the type of drawing context used in this window.
* @return The current type of drawing context.
*/
inline virtual GHOST_TDrawingContextType getDrawingContextType();
/**
* Tries to install a rendering context in this window.
* Child classes do not need to overload this method.
* They should overload the installDrawingContext and removeDrawingContext instead.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
virtual GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type);
/**
* Returns the window user data.
* @return The window user data.
*/
inline virtual GHOST_TUserDataPtr getUserData() const
{
return m_userData;
}
/**
* Changes the window user data.
* @param data The window user data.
*/
virtual void setUserData(const GHOST_TUserDataPtr userData)
{
m_userData = userData;
}
protected:
/**
* Tries to install a rendering context in this window.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type) = 0;
/**
* Removes the current drawing context.
* @return Indication as to whether removal has succeeded.
*/
virtual GHOST_TSuccess removeDrawingContext() = 0;
/**
* Sets the cursor visibility on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible) = 0;
/**
* Sets the cursor grab on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode) { return GHOST_kSuccess; };
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) = 0;
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
int hotX, int hotY) = 0;
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
int szx, int szy, int hotX, int hotY, int fg, int bg) = 0;
/** The the of drawing context installed in this window. */
GHOST_TDrawingContextType m_drawingContextType;
/** The window user data */
GHOST_TUserDataPtr m_userData;
/** The current visibility of the cursor */
bool m_cursorVisible;
/** The current grabbed state of the cursor */
GHOST_TGrabCursorMode m_cursorGrab;
/** Initial grab location. */
GHOST_TInt32 m_cursorGrabInitPos[2];
/** Accumulated offset from m_cursorGrabInitPos. */
GHOST_TInt32 m_cursorGrabAccumPos[2];
/** Wrap the cursor within this region. */
GHOST_Rect m_cursorGrabBounds;
/** The current shape of the cursor */
GHOST_TStandardCursor m_cursorShape;
/** The presence of progress indicator with the application icon */
bool m_progressBarVisible;
/** The acceptance of the "drop candidate" of the current drag'n'drop operation */
bool m_canAcceptDragOperation;
/** Modified state : are there unsaved changes */
bool m_isUnsavedChanges;
/** Stores wether this is a full screen window. */
bool m_fullScreen;
/** Stereo visual created. Only necessary for 'real' stereo support,
* ie quad buffered stereo. This is not always possible, depends on
* the graphics h/w
*/
bool m_stereoVisual;
/** Number of samples used in anti-aliasing, set to 0 if no AA **/
GHOST_TUns16 m_numOfAASamples;
/** Full-screen width */
GHOST_TUns32 m_fullScreenWidth;
/** Full-screen height */
GHOST_TUns32 m_fullScreenHeight;
};
inline GHOST_TDrawingContextType GHOST_Window::getDrawingContextType()
{
return m_drawingContextType;
}
inline bool GHOST_Window::getCursorVisibility() const
{
return m_cursorVisible;
}
inline GHOST_TGrabCursorMode GHOST_Window::getCursorGrabMode() const
{
return m_cursorGrab;
}
inline void GHOST_Window::getCursorGrabInitPos(GHOST_TInt32 &x, GHOST_TInt32 &y) const
{
x = m_cursorGrabInitPos[0];
y = m_cursorGrabInitPos[1];
}
inline void GHOST_Window::getCursorGrabAccum(GHOST_TInt32 &x, GHOST_TInt32 &y) const
{
x= m_cursorGrabAccumPos[0];
y= m_cursorGrabAccumPos[1];
}
inline void GHOST_Window::setCursorGrabAccum(GHOST_TInt32 x, GHOST_TInt32 y)
{
m_cursorGrabAccumPos[0]= x;
m_cursorGrabAccumPos[1]= y;
}
inline GHOST_TStandardCursor GHOST_Window::getCursorShape() const
{
return m_cursorShape;
}
#endif // _GHOST_WINDOW_H

View File

@@ -0,0 +1,748 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowCarbon.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 10, 2001
*/
#include "GHOST_WindowCarbon.h"
#include "GHOST_Debug.h"
AGLContext GHOST_WindowCarbon::s_firstaglCtx = NULL;
#ifdef GHOST_DRAW_CARBON_GUTTER
const GHOST_TInt32 GHOST_WindowCarbon::s_sizeRectSize = 16;
#endif //GHOST_DRAW_CARBON_GUTTER
static const GLint sPreferredFormatWindow[10] = {
AGL_RGBA,
AGL_DOUBLEBUFFER,
AGL_ACCELERATED,
AGL_DEPTH_SIZE, 32,
AGL_NONE,
};
static const GLint sPreferredFormatFullScreen[11] = {
AGL_RGBA,
AGL_DOUBLEBUFFER,
AGL_ACCELERATED,
AGL_FULLSCREEN,
AGL_DEPTH_SIZE, 32,
AGL_NONE,
};
WindowRef ugly_hack=NULL;
const EventTypeSpec kWEvents[] = {
{ kEventClassWindow, kEventWindowZoom }, /* for new zoom behaviour */
};
static OSStatus myWEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData) {
WindowRef mywindow;
GHOST_WindowCarbon *ghost_window;
OSStatus err;
int theState;
if (::GetEventKind(event) == kEventWindowZoom) {
err = ::GetEventParameter (event,kEventParamDirectObject,typeWindowRef,NULL,sizeof(mywindow),NULL, &mywindow);
ghost_window = (GHOST_WindowCarbon *) GetWRefCon(mywindow);
theState = ghost_window->getMac_windowState();
if (theState == 1)
ghost_window->setMac_windowState(2);
else if (theState == 2)
ghost_window->setMac_windowState(1);
}
return eventNotHandledErr;
}
GHOST_WindowCarbon::GHOST_WindowCarbon(
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const bool stereoVisual,
const GHOST_TUns16 numOfAASamples
) :
GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone),
m_windowRef(0),
m_grafPtr(0),
m_aglCtx(0),
m_customCursor(0),
m_fullScreenDirty(false)
{
Str255 title255;
OSStatus err;
//fprintf(stderr," main screen top %i left %i height %i width %i\n", top, left, height, width);
if (state >= GHOST_kWindowState8Normal ) {
if(state == GHOST_kWindowState8Normal) state= GHOST_kWindowStateNormal;
else if(state == GHOST_kWindowState8Maximized) state= GHOST_kWindowStateMaximized;
else if(state == GHOST_kWindowState8Minimized) state= GHOST_kWindowStateMinimized;
else if(state == GHOST_kWindowState8FullScreen) state= GHOST_kWindowStateFullScreen;
// state = state - 8; this was the simple version of above code, doesnt work in gcc 4.0
setMac_windowState(1);
} else
setMac_windowState(0);
if (state != GHOST_kWindowStateFullScreen) {
Rect bnds = { top, left, top+height, left+width };
// Boolean visible = (state == GHOST_kWindowStateNormal) || (state == GHOST_kWindowStateMaximized); /*unused*/
gen2mac(title, title255);
err = ::CreateNewWindow( kDocumentWindowClass,
kWindowStandardDocumentAttributes+kWindowLiveResizeAttribute,
&bnds,
&m_windowRef);
if ( err != noErr) {
fprintf(stderr," error creating window %i \n",(int)err);
} else {
::SetWRefCon(m_windowRef,(SInt32)this);
setTitle(title);
err = InstallWindowEventHandler (m_windowRef, myWEventHandlerProc, GetEventTypeCount(kWEvents), kWEvents,NULL,NULL);
if ( err != noErr) {
fprintf(stderr," error creating handler %i \n",(int)err);
} else {
// ::TransitionWindow (m_windowRef,kWindowZoomTransitionEffect,kWindowShowTransitionAction,NULL);
::ShowWindow(m_windowRef);
::MoveWindow (m_windowRef, left, top,true);
}
}
if (m_windowRef) {
m_grafPtr = ::GetWindowPort(m_windowRef);
setDrawingContextType(type);
updateDrawingContext();
activateDrawingContext();
}
if(ugly_hack==NULL) {
ugly_hack= m_windowRef;
// when started from commandline, window remains in the back... also for play anim
ProcessSerialNumber psn;
GetCurrentProcess(&psn);
SetFrontProcess(&psn);
}
}
else {
/*
Rect bnds = { top, left, top+height, left+width };
gen2mac("", title255);
m_windowRef = ::NewCWindow(
nil, // Storage
&bnds, // Bounding rectangle of the window
title255, // Title of the window
0, // Window initially visible
plainDBox, // procID
(WindowRef)-1L, // Put window before all other windows
0, // Window has minimize box
(SInt32)this); // Store a pointer to the class in the refCon
*/
//GHOST_PRINT("GHOST_WindowCarbon::GHOST_WindowCarbon(): creating full-screen OpenGL context\n");
setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);;installDrawingContext(GHOST_kDrawingContextTypeOpenGL);
updateDrawingContext();
activateDrawingContext();
m_tablet.Active = GHOST_kTabletModeNone;
}
}
GHOST_WindowCarbon::~GHOST_WindowCarbon()
{
if (m_customCursor) delete m_customCursor;
if(ugly_hack==m_windowRef) ugly_hack= NULL;
// printf("GHOST_WindowCarbon::~GHOST_WindowCarbon(): removing drawing context\n");
if(ugly_hack==NULL) setDrawingContextType(GHOST_kDrawingContextTypeNone);
if (m_windowRef) {
::DisposeWindow(m_windowRef);
m_windowRef = 0;
}
}
bool GHOST_WindowCarbon::getValid() const
{
bool valid;
if (!m_fullScreen) {
valid = (m_windowRef != 0) && (m_grafPtr != 0) && ::IsValidWindowPtr(m_windowRef);
}
else {
valid = true;
}
return valid;
}
void GHOST_WindowCarbon::setTitle(const STR_String& title)
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setTitle(): window invalid")
Str255 title255;
gen2mac(title, title255);
::SetWTitle(m_windowRef, title255);
}
void GHOST_WindowCarbon::getTitle(STR_String& title) const
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getTitle(): window invalid")
Str255 title255;
::GetWTitle(m_windowRef, title255);
mac2gen(title255, title);
}
void GHOST_WindowCarbon::getWindowBounds(GHOST_Rect& bounds) const
{
OSStatus success;
Rect rect;
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getWindowBounds(): window invalid")
success = ::GetWindowBounds(m_windowRef, kWindowStructureRgn, &rect);
bounds.m_b = rect.bottom;
bounds.m_l = rect.left;
bounds.m_r = rect.right;
bounds.m_t = rect.top;
}
void GHOST_WindowCarbon::getClientBounds(GHOST_Rect& bounds) const
{
Rect rect;
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getClientBounds(): window invalid")
//::GetPortBounds(m_grafPtr, &rect);
::GetWindowBounds(m_windowRef, kWindowContentRgn, &rect);
bounds.m_b = rect.bottom;
bounds.m_l = rect.left;
bounds.m_r = rect.right;
bounds.m_t = rect.top;
// Subtract gutter height from bottom
#ifdef GHOST_DRAW_CARBON_GUTTER
if ((bounds.m_b - bounds.m_t) > s_sizeRectSize)
{
bounds.m_b -= s_sizeRectSize;
}
else
{
bounds.m_t = bounds.m_b;
}
#endif //GHOST_DRAW_CARBON_GUTTER
}
GHOST_TSuccess GHOST_WindowCarbon::setClientWidth(GHOST_TUns32 width)
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setClientWidth(): window invalid")
GHOST_Rect cBnds, wBnds;
getClientBounds(cBnds);
if (((GHOST_TUns32)cBnds.getWidth()) != width) {
::SizeWindow(m_windowRef, width, cBnds.getHeight(), true);
}
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_WindowCarbon::setClientHeight(GHOST_TUns32 height)
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setClientHeight(): window invalid")
GHOST_Rect cBnds, wBnds;
getClientBounds(cBnds);
#ifdef GHOST_DRAW_CARBON_GUTTER
if (((GHOST_TUns32)cBnds.getHeight()) != height+s_sizeRectSize) {
::SizeWindow(m_windowRef, cBnds.getWidth(), height+s_sizeRectSize, true);
}
#else //GHOST_DRAW_CARBON_GUTTER
if (((GHOST_TUns32)cBnds.getHeight()) != height) {
::SizeWindow(m_windowRef, cBnds.getWidth(), height, true);
}
#endif //GHOST_DRAW_CARBON_GUTTER
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_WindowCarbon::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setClientSize(): window invalid")
GHOST_Rect cBnds, wBnds;
getClientBounds(cBnds);
#ifdef GHOST_DRAW_CARBON_GUTTER
if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
(((GHOST_TUns32)cBnds.getHeight()) != height+s_sizeRectSize)) {
::SizeWindow(m_windowRef, width, height+s_sizeRectSize, true);
}
#else //GHOST_DRAW_CARBON_GUTTER
if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
(((GHOST_TUns32)cBnds.getHeight()) != height)) {
::SizeWindow(m_windowRef, width, height, true);
}
#endif //GHOST_DRAW_CARBON_GUTTER
return GHOST_kSuccess;
}
GHOST_TWindowState GHOST_WindowCarbon::getState() const
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getState(): window invalid")
GHOST_TWindowState state;
if (::IsWindowVisible(m_windowRef) == false) {
state = GHOST_kWindowStateMinimized;
}
else if (::IsWindowInStandardState(m_windowRef, nil, nil)) {
state = GHOST_kWindowStateMaximized;
}
else {
state = GHOST_kWindowStateNormal;
}
return state;
}
void GHOST_WindowCarbon::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::screenToClient(): window invalid")
Point point;
point.h = inX;
point.v = inY;
GrafPtr oldPort;
::GetPort(&oldPort);
::SetPort(m_grafPtr);
::GlobalToLocal(&point);
::SetPort(oldPort);
outX = point.h;
outY = point.v;
}
void GHOST_WindowCarbon::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::clientToScreen(): window invalid")
Point point;
point.h = inX;
point.v = inY;
GrafPtr oldPort;
::GetPort(&oldPort);
::SetPort(m_grafPtr);
::LocalToGlobal(&point);
::SetPort(oldPort);
outX = point.h;
outY = point.v;
}
GHOST_TSuccess GHOST_WindowCarbon::setState(GHOST_TWindowState state)
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setState(): window invalid")
switch (state) {
case GHOST_kWindowStateMinimized:
::HideWindow(m_windowRef);
break;
case GHOST_kWindowStateModified:
SetWindowModified(m_windowRef, 1);
break;
case GHOST_kWindowStateUnModified:
SetWindowModified(m_windowRef, 0);
break;
case GHOST_kWindowStateMaximized:
case GHOST_kWindowStateNormal:
default:
::ShowWindow(m_windowRef);
break;
}
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_WindowCarbon::setOrder(GHOST_TWindowOrder order)
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setOrder(): window invalid")
if (order == GHOST_kWindowOrderTop) {
//::BringToFront(m_windowRef); is wrong, front window should be active for input too
::SelectWindow(m_windowRef);
}
else {
/* doesnt work if you do this with a mouseclick */
::SendBehind(m_windowRef, nil);
}
return GHOST_kSuccess;
}
/*#define WAIT_FOR_VSYNC 1*/
#ifdef WAIT_FOR_VSYNC
#include <OpenGL/OpenGL.h>
#endif
GHOST_TSuccess GHOST_WindowCarbon::swapBuffers()
{
#ifdef WAIT_FOR_VSYNC
/* wait for vsync, to avoid tearing artifacts */
long VBL = 1;
CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
#endif
GHOST_TSuccess succeeded = GHOST_kSuccess;
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
if (m_aglCtx) {
::aglSwapBuffers(m_aglCtx);
}
else {
succeeded = GHOST_kFailure;
}
}
return succeeded;
}
GHOST_TSuccess GHOST_WindowCarbon::updateDrawingContext()
{
GHOST_TSuccess succeeded = GHOST_kSuccess;
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
if (m_aglCtx) {
::aglUpdateContext(m_aglCtx);
}
else {
succeeded = GHOST_kFailure;
}
}
return succeeded;
}
GHOST_TSuccess GHOST_WindowCarbon::activateDrawingContext()
{
GHOST_TSuccess succeeded = GHOST_kSuccess;
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
if (m_aglCtx) {
::aglSetCurrentContext(m_aglCtx);
#ifdef GHOST_DRAW_CARBON_GUTTER
// Restrict drawing to non-gutter area
::aglEnable(m_aglCtx, AGL_BUFFER_RECT);
GHOST_Rect bnds;
getClientBounds(bnds);
GLint b[4] =
{
bnds.m_l,
bnds.m_t+s_sizeRectSize,
bnds.m_r-bnds.m_l,
bnds.m_b-bnds.m_t
};
GLboolean result = ::aglSetInteger(m_aglCtx, AGL_BUFFER_RECT, b);
#endif //GHOST_DRAW_CARBON_GUTTER
}
else {
succeeded = GHOST_kFailure;
}
}
return succeeded;
}
GHOST_TSuccess GHOST_WindowCarbon::installDrawingContext(GHOST_TDrawingContextType type)
{
GHOST_TSuccess success = GHOST_kFailure;
switch (type) {
case GHOST_kDrawingContextTypeOpenGL:
{
if (!getValid()) break;
AGLPixelFormat pixelFormat;
if (!m_fullScreen) {
pixelFormat = ::aglChoosePixelFormat(0, 0, sPreferredFormatWindow);
m_aglCtx = ::aglCreateContext(pixelFormat, s_firstaglCtx);
if (!m_aglCtx) break;
if (!s_firstaglCtx) s_firstaglCtx = m_aglCtx;
success = ::aglSetDrawable(m_aglCtx, m_grafPtr) == GL_TRUE ? GHOST_kSuccess : GHOST_kFailure;
}
else {
//GHOST_PRINT("GHOST_WindowCarbon::installDrawingContext(): init full-screen OpenGL\n");
GDHandle device=::GetMainDevice();pixelFormat=::aglChoosePixelFormat(&device,1,sPreferredFormatFullScreen);
m_aglCtx = ::aglCreateContext(pixelFormat, 0);
if (!m_aglCtx) break;
if (!s_firstaglCtx) s_firstaglCtx = m_aglCtx;
//GHOST_PRINT("GHOST_WindowCarbon::installDrawingContext(): created OpenGL context\n");
//::CGGetActiveDisplayList(0, NULL, &m_numDisplays)
success = ::aglSetFullScreen(m_aglCtx, m_fullScreenWidth, m_fullScreenHeight, 75, 0) == GL_TRUE ? GHOST_kSuccess : GHOST_kFailure;
/*
if (success == GHOST_kSuccess) {
GHOST_PRINT("GHOST_WindowCarbon::installDrawingContext(): init full-screen OpenGL succeeded\n");
}
else {
GHOST_PRINT("GHOST_WindowCarbon::installDrawingContext(): init full-screen OpenGL failed\n");
}
*/
}
::aglDestroyPixelFormat(pixelFormat);
}
break;
case GHOST_kDrawingContextTypeNone:
success = GHOST_kSuccess;
break;
default:
break;
}
return success;
}
GHOST_TSuccess GHOST_WindowCarbon::removeDrawingContext()
{
GHOST_TSuccess success = GHOST_kFailure;
switch (m_drawingContextType) {
case GHOST_kDrawingContextTypeOpenGL:
if (m_aglCtx) {
aglSetCurrentContext(NULL);
aglSetDrawable(m_aglCtx, NULL);
//aglDestroyContext(m_aglCtx);
if (s_firstaglCtx == m_aglCtx) s_firstaglCtx = NULL;
success = ::aglDestroyContext(m_aglCtx) == GL_TRUE ? GHOST_kSuccess : GHOST_kFailure;
m_aglCtx = 0;
}
break;
case GHOST_kDrawingContextTypeNone:
success = GHOST_kSuccess;
break;
default:
break;
}
return success;
}
GHOST_TSuccess GHOST_WindowCarbon::invalidate()
{
GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::invalidate(): window invalid")
if (!m_fullScreen) {
Rect rect;
::GetPortBounds(m_grafPtr, &rect);
::InvalWindowRect(m_windowRef, &rect);
}
else {
//EventRef event;
//OSStatus status = ::CreateEvent(NULL, kEventClassWindow, kEventWindowUpdate, 0, 0, &event);
//GHOST_PRINT("GHOST_WindowCarbon::invalidate(): created event " << status << " \n");
//status = ::SetEventParameter(event, kEventParamDirectObject, typeWindowRef, sizeof(WindowRef), this);
//GHOST_PRINT("GHOST_WindowCarbon::invalidate(): set event parameter " << status << " \n");
//status = ::PostEventToQueue(::GetMainEventQueue(), event, kEventPriorityStandard);
//status = ::SendEventToEventTarget(event, ::GetApplicationEventTarget());
//GHOST_PRINT("GHOST_WindowCarbon::invalidate(): added event to queue " << status << " \n");
m_fullScreenDirty = true;
}
return GHOST_kSuccess;
}
void GHOST_WindowCarbon::gen2mac(const STR_String& in, Str255 out) const
{
STR_String tempStr = in;
int num = tempStr.Length();
if (num > 255) num = 255;
::memcpy(out+1, tempStr.Ptr(), num);
out[0] = num;
}
void GHOST_WindowCarbon::mac2gen(const Str255 in, STR_String& out) const
{
char tmp[256];
::memcpy(tmp, in+1, in[0]);
tmp[in[0]] = '\0';
out = tmp;
}
void GHOST_WindowCarbon::loadCursor(bool visible, GHOST_TStandardCursor cursor) const
{
static bool systemCursorVisible = true;
if (visible != systemCursorVisible) {
if (visible) {
::ShowCursor();
systemCursorVisible = true;
}
else {
::HideCursor();
systemCursorVisible = false;
}
}
if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {
::SetCursor( m_customCursor );
} else {
int carbon_cursor;
#define GCMAP(ghostCursor, carbonCursor) case ghostCursor: carbon_cursor = carbonCursor; break
switch (cursor) {
default:
GCMAP( GHOST_kStandardCursorDefault, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorRightArrow, kThemeAliasArrowCursor);
GCMAP( GHOST_kStandardCursorLeftArrow, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorInfo, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorDestroy, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorHelp, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorCycle, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorSpray, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorWait, kThemeWatchCursor);
GCMAP( GHOST_kStandardCursorText, kThemeIBeamCursor);
GCMAP( GHOST_kStandardCursorCrosshair, kThemeCrossCursor);
GCMAP( GHOST_kStandardCursorUpDown, kThemeClosedHandCursor);
GCMAP( GHOST_kStandardCursorLeftRight, kThemeClosedHandCursor);
GCMAP( GHOST_kStandardCursorTopSide, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorBottomSide, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorLeftSide, kThemeResizeLeftCursor);
GCMAP( GHOST_kStandardCursorRightSide, kThemeResizeRightCursor);
GCMAP( GHOST_kStandardCursorTopLeftCorner, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorTopRightCorner, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorBottomRightCorner, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorBottomLeftCorner, kThemeArrowCursor);
GCMAP( GHOST_kStandardCursorCopy, kThemeCopyArrowCursor);
};
#undef GCMAP
::SetThemeCursor(carbon_cursor);
}
}
bool GHOST_WindowCarbon::getFullScreenDirty()
{
return m_fullScreen && m_fullScreenDirty;
}
GHOST_TSuccess GHOST_WindowCarbon::setWindowCursorVisibility(bool visible)
{
if (::FrontWindow() == m_windowRef) {
loadCursor(visible, getCursorShape());
}
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_WindowCarbon::setWindowCursorShape(GHOST_TStandardCursor shape)
{
if (m_customCursor) {
delete m_customCursor;
m_customCursor = 0;
}
if (::FrontWindow() == m_windowRef) {
loadCursor(getCursorVisibility(), shape);
}
return GHOST_kSuccess;
}
#if 0
/** Reverse the bits in a GHOST_TUns8 */
static GHOST_TUns8 uns8ReverseBits(GHOST_TUns8 ch)
{
ch= ((ch>>1)&0x55) | ((ch<<1)&0xAA);
ch= ((ch>>2)&0x33) | ((ch<<2)&0xCC);
ch= ((ch>>4)&0x0F) | ((ch<<4)&0xF0);
return ch;
}
#endif
/** Reverse the bits in a GHOST_TUns16 */
static GHOST_TUns16 uns16ReverseBits(GHOST_TUns16 shrt)
{
shrt= ((shrt>>1)&0x5555) | ((shrt<<1)&0xAAAA);
shrt= ((shrt>>2)&0x3333) | ((shrt<<2)&0xCCCC);
shrt= ((shrt>>4)&0x0F0F) | ((shrt<<4)&0xF0F0);
shrt= ((shrt>>8)&0x00FF) | ((shrt<<8)&0xFF00);
return shrt;
}
GHOST_TSuccess GHOST_WindowCarbon::setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color)
{
int y;
if (m_customCursor) {
delete m_customCursor;
m_customCursor = 0;
}
m_customCursor = new Cursor;
if (!m_customCursor) return GHOST_kFailure;
for (y=0; y<16; y++) {
#if !defined(__LITTLE_ENDIAN__)
m_customCursor->data[y] = uns16ReverseBits((bitmap[2*y]<<0) | (bitmap[2*y+1]<<8));
m_customCursor->mask[y] = uns16ReverseBits((mask[2*y]<<0) | (mask[2*y+1]<<8));
#else
m_customCursor->data[y] = uns16ReverseBits((bitmap[2*y+1]<<0) | (bitmap[2*y]<<8));
m_customCursor->mask[y] = uns16ReverseBits((mask[2*y+1]<<0) | (mask[2*y]<<8));
#endif
}
m_customCursor->hotSpot.h = hotX;
m_customCursor->hotSpot.v = hotY;
if (::FrontWindow() == m_windowRef) {
loadCursor(getCursorVisibility(), GHOST_kStandardCursorCustom);
}
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_WindowCarbon::setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2],
GHOST_TUns8 mask[16][2], int hotX, int hotY)
{
return setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*) mask, 16, 16, hotX, hotY, 0, 1);
}
void GHOST_WindowCarbon::setMac_windowState(short value)
{
mac_windowState = value;
}
short GHOST_WindowCarbon::getMac_windowState()
{
return mac_windowState;
}

View File

@@ -0,0 +1,313 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowCarbon.h
* \ingroup GHOST
* Declaration of GHOST_WindowCarbon class.
*/
#ifndef _GHOST_WINDOW_CARBON_H_
#define _GHOST_WINDOW_CARBON_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#include "GHOST_Window.h"
#include "STR_String.h"
#define __CARBONSOUND__
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
/**
* Window on Mac OSX/Carbon.
* Carbon windows have a size widget in the lower right corner of the window.
* To force it to be visible, the height of the client rectangle is reduced so
* that applications do not draw in that area. GHOST will manage that area
* which is called the gutter.
* When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent
* OpenGL drawing outside the reduced client rectangle.
* @author Maarten Gribnau
* @date May 23, 2001
*/
class GHOST_WindowCarbon : public GHOST_Window {
public:
/**
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
* @param title The text shown in the title bar of the window.
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state the window is initially opened with.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
*/
GHOST_WindowCarbon(
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0
);
/**
* Destructor.
* Closes the window and disposes resources allocated.
*/
virtual ~GHOST_WindowCarbon();
/**
* Returns indication as to whether the window is valid.
* @return The validity of the window.
*/
virtual bool getValid() const;
/**
* Sets the title displayed in the title bar.
* @param title The title to display in the title bar.
*/
virtual void setTitle(const STR_String& title);
/**
* Returns the title displayed in the title bar.
* @param title The title displayed in the title bar.
*/
virtual void getTitle(STR_String& title) const;
/**
* Returns the window rectangle dimensions.
* The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
* @param bounds The bounding rectangle of the window.
*/
virtual void getWindowBounds(GHOST_Rect& bounds) const;
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* @param bounds The bounding rectangle of the cleient area of the window.
*/
virtual void getClientBounds(GHOST_Rect& bounds) const;
/**
* Resizes client rectangle width.
* @param width The new width of the client area of the window.
*/
virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
/**
* Resizes client rectangle height.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
/**
* Resizes client rectangle.
* @param width The new width of the client area of the window.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
/**
* Returns the state of the window (normal, minimized, maximized).
* @return The state of the window.
*/
virtual GHOST_TWindowState getState() const;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate on the screen.
* @param inY The y-coordinate on the screen.
* @param outX The x-coordinate in the client rectangle.
* @param outY The y-coordinate in the client rectangle.
*/
virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate in the client rectangle.
* @param inY The y-coordinate in the client rectangle.
* @param outX The x-coordinate on the screen.
* @param outY The y-coordinate on the screen.
*/
virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Sets the state of the window (normal, minimized, maximized).
* @param state The state of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setState(GHOST_TWindowState state);
/**
* Sets the order of the window (bottom, top).
* @param order The order of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
/**
* Swaps front and back buffers of a window.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess swapBuffers();
/**
* Updates the drawing context of this window. Needed
* whenever the window is changed.
* @return Indication of success.
*/
GHOST_TSuccess updateDrawingContext();
/**
* Activates the drawing context of this window.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess activateDrawingContext();
virtual void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
/**
* Returns the dirty state of the window when in full-screen mode.
* @return Whether it is dirty.
*/
virtual bool getFullScreenDirty();
/* accessor for fullscreen window */
virtual void setMac_windowState(short value);
virtual short getMac_windowState();
const GHOST_TabletData* GetTabletData()
{ return &m_tablet; }
GHOST_TabletData& GetCarbonTabletData()
{ return m_tablet; }
protected:
/**
* Tries to install a rendering context in this window.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
/**
* Removes the current drawing context.
* @return Indication as to whether removal has succeeded.
*/
virtual GHOST_TSuccess removeDrawingContext();
/**
* Invalidates the contents of this window.
* @return Indication of success.
*/
virtual GHOST_TSuccess invalidate();
/**
* Sets the cursor visibility on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
/**
* Converts a string object to a Mac Pascal string.
* @param in The string object to be converted.
* @param out The converted string.
*/
virtual void gen2mac(const STR_String& in, Str255 out) const;
/**
* Converts a Mac Pascal string to a string object.
* @param in The string to be converted.
* @param out The converted string object.
*/
virtual void mac2gen(const Str255 in, STR_String& out) const;
WindowRef m_windowRef;
CGrafPtr m_grafPtr;
AGLContext m_aglCtx;
/** The first created OpenGL context (for sharing display lists) */
static AGLContext s_firstaglCtx;
Cursor* m_customCursor;
GHOST_TabletData m_tablet;
/** When running in full-screen this tells whether to refresh the window. */
bool m_fullScreenDirty;
/** specific MacOs X full screen window setting as we use partially system mechanism
values : 0 not maximizable default
1 normal state
2 maximized state
this will be reworked when rebuilding GHOST carbon to use new OS X apis
in order to be unified with GHOST fullscreen/maximised settings
(lukep)
**/
short mac_windowState;
/**
* The width/height of the size rectangle in the lower right corner of a
* Mac/Carbon window. This is also the height of the gutter area.
*/
#ifdef GHOST_DRAW_CARBON_GUTTER
static const GHOST_TInt32 s_sizeRectSize;
#endif // GHOST_DRAW_CARBON_GUTTER
};
#endif // _GHOST_WINDOW_CARBON_H_

View File

@@ -0,0 +1,309 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowCocoa.h
* \ingroup GHOST
* Declaration of GHOST_WindowCocoa class.
*/
#ifndef _GHOST_WINDOW_COCOA_H_
#define _GHOST_WINDOW_COCOA_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#include "GHOST_Window.h"
#include "STR_String.h"
@class CocoaWindow;
class GHOST_SystemCocoa;
/**
* Window on Mac OSX/Cocoa.
* Carbon windows have a size widget in the lower right corner of the window.
* To force it to be visible, the height of the client rectangle is reduced so
* that applications do not draw in that area. GHOST will manage that area
* which is called the gutter.
* When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent
* OpenGL drawing outside the reduced client rectangle.
* @author Maarten Gribnau
* @date May 23, 2001
*/
class GHOST_WindowCocoa : public GHOST_Window {
public:
/**
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
* @param systemCocoa The associated system class to forward events to
* @param title The text shown in the title bar of the window.
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state the window is initially opened with.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_WindowCocoa(
GHOST_SystemCocoa *systemCocoa,
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0
);
/**
* Destructor.
* Closes the window and disposes resources allocated.
*/
virtual ~GHOST_WindowCocoa();
/**
* Returns indication as to whether the window is valid.
* @return The validity of the window.
*/
virtual bool getValid() const;
/**
* Returns the associated NSWindow object
* @return The associated NSWindow object
*/
virtual void* getOSWindow() const;
/**
* Sets the title displayed in the title bar.
* @param title The title to display in the title bar.
*/
virtual void setTitle(const STR_String& title);
/**
* Returns the title displayed in the title bar.
* @param title The title displayed in the title bar.
*/
virtual void getTitle(STR_String& title) const;
/**
* Returns the window rectangle dimensions.
* The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
* @param bounds The bounding rectangle of the window.
*/
virtual void getWindowBounds(GHOST_Rect& bounds) const;
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* @param bounds The bounding rectangle of the cleient area of the window.
*/
virtual void getClientBounds(GHOST_Rect& bounds) const;
/**
* Resizes client rectangle width.
* @param width The new width of the client area of the window.
*/
virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
/**
* Resizes client rectangle height.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
/**
* Resizes client rectangle.
* @param width The new width of the client area of the window.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
/**
* Returns the state of the window (normal, minimized, maximized).
* @return The state of the window.
*/
virtual GHOST_TWindowState getState() const;
/**
* Sets the window "modified" status, indicating unsaved changes
* @param isUnsavedChanges Unsaved changes or not
* @return Indication of success.
*/
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges);
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate on the screen.
* @param inY The y-coordinate on the screen.
* @param outX The x-coordinate in the client rectangle.
* @param outY The y-coordinate in the client rectangle.
*/
virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate in the client rectangle.
* @param inY The y-coordinate in the client rectangle.
* @param outX The x-coordinate on the screen.
* @param outY The y-coordinate on the screen.
*/
virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Gets the screen the window is displayed in
* @return The NSScreen object
*/
NSScreen* getScreen();
/**
* Sets the state of the window (normal, minimized, maximized).
* @param state The state of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setState(GHOST_TWindowState state);
/**
* Sets the order of the window (bottom, top).
* @param order The order of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
/**
* Swaps front and back buffers of a window.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess swapBuffers();
/**
* Updates the drawing context of this window. Needed
* whenever the window is changed.
* @return Indication of success.
*/
GHOST_TSuccess updateDrawingContext();
/**
* Activates the drawing context of this window.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess activateDrawingContext();
virtual void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
const GHOST_TabletData* GetTabletData()
{ return &m_tablet; }
GHOST_TabletData& GetCocoaTabletData()
{ return m_tablet; }
/**
* Sets the progress bar value displayed in the window/application icon
* @param progress The progress % (0.0 to 1.0)
*/
virtual GHOST_TSuccess setProgressBar(float progress);
/**
* Hides the progress bar icon
*/
virtual GHOST_TSuccess endProgressBar();
protected:
/**
* Tries to install a rendering context in this window.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
/**
* Removes the current drawing context.
* @return Indication as to whether removal has succeeded.
*/
virtual GHOST_TSuccess removeDrawingContext();
/**
* Invalidates the contents of this window.
* @return Indication of success.
*/
virtual GHOST_TSuccess invalidate();
/**
* Sets the cursor visibility on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
/**
* Sets the cursor grab on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
/** The window containing the OpenGL view */
CocoaWindow *m_window;
/** The openGL view */
NSOpenGLView *m_openGLView;
/** The opgnGL drawing context */
NSOpenGLContext *m_openGLContext;
/** The mother SystemCocoa class to send events */
GHOST_SystemCocoa *m_systemCocoa;
/** The first created OpenGL context (for sharing display lists) */
static NSOpenGLContext *s_firstOpenGLcontext;
NSCursor* m_customCursor;
GHOST_TabletData m_tablet;
};
#endif // _GHOST_WINDOW_COCOA_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,220 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowManager.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 11, 2001
*/
#include "GHOST_WindowManager.h"
#include <algorithm>
#include "GHOST_Debug.h"
#include "GHOST_Window.h"
GHOST_WindowManager::GHOST_WindowManager() :
m_fullScreenWindow(0),
m_activeWindow(0),
m_activeWindowBeforeFullScreen(0)
{
}
GHOST_WindowManager::~GHOST_WindowManager()
{
/* m_windows is freed by GHOST_System::disposeWindow */
}
GHOST_TSuccess GHOST_WindowManager::addWindow(GHOST_IWindow* window)
{
GHOST_TSuccess success = GHOST_kFailure;
if (window) {
if (!getWindowFound(window)) {
// Store the pointer to the window
m_windows.push_back(window);
success = GHOST_kSuccess;
}
}
return success;
}
GHOST_TSuccess GHOST_WindowManager::removeWindow(const GHOST_IWindow* window)
{
GHOST_TSuccess success = GHOST_kFailure;
if (window) {
if (window == m_fullScreenWindow) {
endFullScreen();
}
else {
vector<GHOST_IWindow*>::iterator result = find(m_windows.begin(), m_windows.end(), window);
if (result != m_windows.end()) {
setWindowInactive(window);
m_windows.erase(result);
success = GHOST_kSuccess;
}
}
}
return success;
}
bool GHOST_WindowManager::getWindowFound(const GHOST_IWindow* window) const
{
bool found = false;
if (window) {
if (getFullScreen() && (window == m_fullScreenWindow)) {
found = true;
}
else {
vector<GHOST_IWindow*>::const_iterator result = find(m_windows.begin(), m_windows.end(), window);
if (result != m_windows.end()) {
found = true;
}
}
}
return found;
}
bool GHOST_WindowManager::getFullScreen(void) const
{
return m_fullScreenWindow != 0;
}
GHOST_IWindow* GHOST_WindowManager::getFullScreenWindow(void) const
{
return m_fullScreenWindow;
}
GHOST_TSuccess GHOST_WindowManager::beginFullScreen(GHOST_IWindow* window,
bool stereoVisual)
{
GHOST_TSuccess success = GHOST_kFailure;
GHOST_ASSERT(window, "GHOST_WindowManager::beginFullScreen(): invalid window");
GHOST_ASSERT(window->getValid(), "GHOST_WindowManager::beginFullScreen(): invalid window");
if (!getFullScreen()) {
m_fullScreenWindow = window;
m_activeWindowBeforeFullScreen = getActiveWindow();
setActiveWindow(m_fullScreenWindow);
success = GHOST_kSuccess;
}
return success;
}
GHOST_TSuccess GHOST_WindowManager::endFullScreen(void)
{
GHOST_TSuccess success = GHOST_kFailure;
if (getFullScreen()) {
if (m_fullScreenWindow != 0) {
//GHOST_PRINT("GHOST_WindowManager::endFullScreen(): deleting full-screen window\n");
setWindowInactive(m_fullScreenWindow);
delete m_fullScreenWindow;
//GHOST_PRINT("GHOST_WindowManager::endFullScreen(): done\n");
m_fullScreenWindow = 0;
if (m_activeWindowBeforeFullScreen) {
setActiveWindow(m_activeWindowBeforeFullScreen);
}
}
success = GHOST_kSuccess;
}
return success;
}
GHOST_TSuccess GHOST_WindowManager::setActiveWindow(GHOST_IWindow* window)
{
GHOST_TSuccess success = GHOST_kSuccess;
if (window != m_activeWindow) {
if (getWindowFound(window)) {
m_activeWindow = window;
}
else {
success = GHOST_kFailure;
}
}
return success;
}
GHOST_IWindow* GHOST_WindowManager::getActiveWindow(void) const
{
return m_activeWindow;
}
void GHOST_WindowManager::setWindowInactive(const GHOST_IWindow* window)
{
if (window == m_activeWindow) {
m_activeWindow = 0;
}
}
std::vector<GHOST_IWindow *> &GHOST_WindowManager::getWindows()
{
return m_windows;
}
GHOST_IWindow* GHOST_WindowManager::getWindowAssociatedWithOSWindow(void* osWindow)
{
std::vector<GHOST_IWindow*>::iterator iter;
for (iter = m_windows.begin(); iter != m_windows.end(); iter++) {
if ((*iter)->getOSWindow() == osWindow)
return *iter;
}
return NULL;
}
bool GHOST_WindowManager::getAnyModifiedState()
{
bool isAnyModified = false;
std::vector<GHOST_IWindow*>::iterator iter;
for (iter = m_windows.begin(); iter != m_windows.end(); iter++) {
if ((*iter)->getModifiedState())
isAnyModified = true;
}
return isAnyModified;
}

View File

@@ -0,0 +1,174 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowManager.h
* \ingroup GHOST
* Declaration of GHOST_WindowManager class.
*/
#ifndef _GHOST_WINDOW_MANAGER_H_
#define _GHOST_WINDOW_MANAGER_H_
#include <vector>
#include "GHOST_Rect.h"
#include "GHOST_IWindow.h"
/**
* Manages system windows (platform independent implementation).
* @author Maarten Gribnau
* @date May 11, 2001
*/
class GHOST_WindowManager
{
public:
/**
* Constructor.
*/
GHOST_WindowManager();
/**
* Destructor.
*/
virtual ~GHOST_WindowManager();
/**
* Add a window to our list.
* It is only added if it is not already in the list.
* @param window Pointer to the window to be added.
* @return Indication of success.
*/
virtual GHOST_TSuccess addWindow(GHOST_IWindow* window);
/**
* Remove a window from our list.
* @param window Pointer to the window to be removed.
* @return Indication of success.
*/
virtual GHOST_TSuccess removeWindow(const GHOST_IWindow* window);
/**
* Returns whether the window is in our list.
* @param window Pointer to the window to query.
* @return A boolean indicator.
*/
virtual bool getWindowFound(const GHOST_IWindow* window) const;
/**
* Returns whether one of the windows is fullscreen.
* @return A boolean indicator.
*/
virtual bool getFullScreen(void) const;
/**
* Returns pointer to the full-screen window.
* @return The fll-screen window (0 if not in full-screen).
*/
virtual GHOST_IWindow* getFullScreenWindow(void) const;
/**
* Activates fullscreen mode for a window.
* @param window The window displayed fullscreen.
* @return Indication of success.
*/
virtual GHOST_TSuccess beginFullScreen(GHOST_IWindow* window, const bool stereoVisual);
/**
* Closes fullscreen mode down.
* @return Indication of success.
*/
virtual GHOST_TSuccess endFullScreen(void);
/**
* Sets new window as active window (the window receiving events).
* There can be only one window active which should be in the current window list.
* @param window The new active window.
*/
virtual GHOST_TSuccess setActiveWindow(GHOST_IWindow* window);
/**
* Returns the active window (the window receiving events).
* There can be only one window active which should be in the current window list.
* @return window The active window (or NULL if there is none).
*/
virtual GHOST_IWindow* getActiveWindow(void) const;
/**
* Set this window to be inactive (not receiving events).
* @param window The window to decativate.
*/
virtual void setWindowInactive(const GHOST_IWindow* window);
/**
* Return a vector of the windows currently managed by this
* class.
* @warning It is very dangerous to mess with the contents of
* this vector. Please do not destroy or add windows use the
* interface above for this,
*/
std::vector<GHOST_IWindow *> & getWindows();
/**
* Finds the window associated with an OS window object/handle
* @param osWindow The OS window object/handle
* @return The associated window, null if none corresponds
*/
virtual GHOST_IWindow* getWindowAssociatedWithOSWindow(void* osWindow);
/**
* Return true if any windows has a modified status
* @return True if any window has unsaved changes
*/
bool getAnyModifiedState();
protected:
/** The list of windows managed */
std::vector<GHOST_IWindow*> m_windows;
/** Window in fullscreen state. There can be only one of this which is not in or window list. */
GHOST_IWindow* m_fullScreenWindow;
/** The active window. */
GHOST_IWindow* m_activeWindow;
/** Window that was active before entering fullscreen state. */
GHOST_IWindow* m_activeWindowBeforeFullScreen;
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_WindowManager"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
};
#endif // _GHOST_WINDOW_MANAGER_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,400 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowWin32.h
* \ingroup GHOST
* Declaration of GHOST_WindowWin32 class.
*/
#ifndef _GHOST_WINDOW_WIN32_H_
#define _GHOST_WINDOW_WIN32_H_
#ifndef WIN32
#error WIN32 only!
#endif // WIN32
#include "GHOST_Window.h"
/* MinGW needs it */
#ifdef FREE_WINDOWS
#ifdef WINVER
#undef WINVER
#endif
#define WINVER 0x0501
#endif
#include <windows.h>
#include "GHOST_TaskbarWin32.h"
#include <wintab.h>
#define PACKETDATA (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR)
#define PACKETMODE PK_BUTTONS
#include <pktdef.h>
class GHOST_SystemWin32;
class GHOST_DropTargetWin32;
// typedefs for WinTab functions to allow dynamic loading
typedef UINT (API * GHOST_WIN32_WTInfo) ( UINT, UINT, LPVOID );
typedef HCTX (API * GHOST_WIN32_WTOpen) (HWND, LPLOGCONTEXTA, BOOL);
typedef BOOL (API * GHOST_WIN32_WTClose) (HCTX);
typedef BOOL (API * GHOST_WIN32_WTPacket) (HCTX, UINT, LPVOID);
/**
* GHOST window on M$ Windows OSs.
* @author Maarten Gribnau
* @date May 10, 2001
*/
class GHOST_WindowWin32 : public GHOST_Window {
public:
/**
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
* @param title The text shown in the title bar of the window.
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state the window is initially opened with.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_WindowWin32(
GHOST_SystemWin32 * system,
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0,
GHOST_TEmbedderWindowID parentWindowHwnd=0,
GHOST_TSuccess msEnabled = GHOST_kFailure,
int msPixelFormat = 0
);
/**
* Destructor.
* Closes the window and disposes resources allocated.
*/
virtual ~GHOST_WindowWin32();
/**
* Returns the window to replace this one if it's getting replaced
* @return The window replacing this one.
*/
GHOST_Window *getNextWindow();
/**
* Returns indication as to whether the window is valid.
* @return The validity of the window.
*/
virtual bool getValid() const;
/**
* Access to the handle of the window.
* @return The handle of the window.
*/
virtual HWND getHWND() const;
/**
* Sets the title displayed in the title bar.
* @param title The title to display in the title bar.
*/
virtual void setTitle(const STR_String& title);
/**
* Returns the title displayed in the title bar.
* @param title The title displayed in the title bar.
*/
virtual void getTitle(STR_String& title) const;
/**
* Returns the window rectangle dimensions.
* The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
* @param bounds The bounding rectangle of the window.
*/
virtual void getWindowBounds(GHOST_Rect& bounds) const;
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* @param bounds The bounding rectangle of the cleient area of the window.
*/
virtual void getClientBounds(GHOST_Rect& bounds) const;
/**
* Resizes client rectangle width.
* @param width The new width of the client area of the window.
*/
virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
/**
* Resizes client rectangle height.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
/**
* Resizes client rectangle.
* @param width The new width of the client area of the window.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
/**
* Returns the state of the window (normal, minimized, maximized).
* @return The state of the window.
*/
virtual GHOST_TWindowState getState() const;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate on the screen.
* @param inY The y-coordinate on the screen.
* @param outX The x-coordinate in the client rectangle.
* @param outY The y-coordinate in the client rectangle.
*/
virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate in the client rectangle.
* @param inY The y-coordinate in the client rectangle.
* @param outX The x-coordinate on the screen.
* @param outY The y-coordinate on the screen.
*/
virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Sets the state of the window (normal, minimized, maximized).
* @param state The state of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setState(GHOST_TWindowState state);
/**
* Sets the order of the window (bottom, top).
* @param order The order of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
/**
* Swaps front and back buffers of a window.
* @return Indication of success.
*/
virtual GHOST_TSuccess swapBuffers();
/**
* Activates the drawing context of this window.
* @return Indication of success.
*/
virtual GHOST_TSuccess activateDrawingContext();
/**
* Invalidates the contents of this window.
*/
virtual GHOST_TSuccess invalidate();
/**
* Sets the progress bar value displayed in the window/application icon
* @param progress The progress %
*/
virtual GHOST_TSuccess setProgressBar(float progress);
/**
* Hides the progress bar in the icon
*/
virtual GHOST_TSuccess endProgressBar();
/**
* Returns the name of the window class.
* @return The name of the window class.
*/
static LPCSTR getWindowClassName() { return s_windowClassName; }
/**
* Register a mouse click event (should be called
* for any real button press, controls mouse
* capturing).
*
* @param press
* 0 - mouse pressed
* 1 - mouse released
* 2 - operator grab
* 3 - operator ungrab
*/
void registerMouseClickEvent(int press);
/**
* Inform the window that it has lost mouse capture,
* called in response to native window system messages.
*/
void lostMouseCapture();
/**
* Loads the windows equivalent of a standard GHOST cursor.
* @param visible Flag for cursor visibility.
* @param cursorShape The cursor shape.
*/
void loadCursor(bool visible, GHOST_TStandardCursor cursorShape) const;
const GHOST_TabletData* GetTabletData()
{ return m_tabletData; }
void processWin32TabletInitEvent();
void processWin32TabletEvent(WPARAM wParam, LPARAM lParam);
protected:
GHOST_TSuccess initMultisample(PIXELFORMATDESCRIPTOR pfd);
/**
* Tries to install a rendering context in this window.
* @param type The type of rendering context installed.
* @return Indication of success.
*/
virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
/**
* Removes the current drawing context.
* @return Indication of success.
*/
virtual GHOST_TSuccess removeDrawingContext();
/**
* Sets the cursor visibility on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
/**
* Sets the cursor grab on the window using native window system calls.
* Using registerMouseClickEvent.
* @param mode GHOST_TGrabCursorMode.
*/
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
virtual GHOST_TSuccess setWindowCustomCursorShape(
GHOST_TUns8 *bitmap,
GHOST_TUns8 *mask,
int sizex,
int sizey,
int hotX,
int hotY,
int fg_color,
int bg_color
);
/** Pointer to system */
GHOST_SystemWin32 * m_system;
/** Pointer to COM IDropTarget implementor */
GHOST_DropTargetWin32 * m_dropTarget;
/** Window handle. */
HWND m_hWnd;
/** Device context handle. */
HDC m_hDC;
/** OpenGL rendering context. */
HGLRC m_hGlRc;
/** The first created OpenGL context (for sharing display lists) */
static HGLRC s_firsthGLRc;
/** The first created device context handle. */
static HDC s_firstHDC;
/** Flag for if window has captured the mouse */
bool m_hasMouseCaptured;
/** Flag if an operator grabs the mouse with WM_cursor_grab/ungrab()
* Multiple grabs must be realesed with a single ungrab*/
bool m_hasGrabMouse;
/** Count of number of pressed buttons */
int m_nPressedButtons;
/** HCURSOR structure of the custom cursor */
HCURSOR m_customCursor;
/** ITaskbarList3 structure for progress bar*/
ITaskbarList3 * m_Bar;
static LPCSTR s_windowClassName;
static const int s_maxTitleLength;
/** WinTab dll handle */
HMODULE m_wintab;
/** Tablet data for GHOST */
GHOST_TabletData* m_tabletData;
/** Stores the Tablet context if detected Tablet features using WinTab.dll */
HCTX m_tablet;
LONG m_maxPressure;
LONG m_maxAzimuth, m_maxAltitude;
/** Preferred number of samples */
GHOST_TUns16 m_multisample;
/** Check if multisample is supported */
GHOST_TSuccess m_multisampleEnabled;
/** The pixelFormat to use for multisample */
int m_msPixelFormat;
/** We need to following to recreate the window */
const STR_String& m_title;
GHOST_TInt32 m_left;
GHOST_TInt32 m_top;
GHOST_TUns32 m_width;
GHOST_TUns32 m_height;
GHOST_TWindowState m_normal_state;
bool m_stereo;
/** The GHOST_System passes this to wm if this window is being replaced */
GHOST_Window *m_nextWindow;
/** Hwnd to parent window */
GHOST_TEmbedderWindowID m_parentWindowHwnd;
};
#endif // _GHOST_WINDOW_WIN32_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,370 @@
/*
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowX11.h
* \ingroup GHOST
* Declaration of GHOST_WindowX11 class.
*/
#ifndef _GHOST_WINDOWX11_H_
#define _GHOST_WINDOWX11_H_
#include "GHOST_Window.h"
#include <X11/Xlib.h>
#include <GL/glx.h>
// For tablets
#include <X11/extensions/XInput.h>
#include <map>
class STR_String;
class GHOST_SystemX11;
/**
* X11 implementation of GHOST_IWindow.
* Dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
* @author Laurence Bourn
* @date October 26, 2001
*/
class GHOST_WindowX11 : public GHOST_Window
{
public:
/**
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
* @param title The text shown in the title bar of the window.
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state the window is initially opened with.
* @param parentWindow Parent (embedder) window
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_WindowX11(
GHOST_SystemX11 *system,
Display * display,
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
const GHOST_TEmbedderWindowID parentWindow,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
const bool stereoVisual = false,
const GHOST_TUns16 numOfAASamples = 0
);
bool
getValid(
) const;
void
setTitle(const STR_String& title);
void
getTitle(
STR_String& title
) const;
void
getWindowBounds(
GHOST_Rect& bounds
) const;
void
getClientBounds(
GHOST_Rect& bounds
) const;
GHOST_TSuccess
setClientWidth(
GHOST_TUns32 width
);
GHOST_TSuccess
setClientHeight(
GHOST_TUns32 height
);
GHOST_TSuccess
setClientSize(
GHOST_TUns32 width,
GHOST_TUns32 height
);
void
screenToClient(
GHOST_TInt32 inX,
GHOST_TInt32 inY,
GHOST_TInt32& outX,
GHOST_TInt32& outY
) const;
void
clientToScreen(
GHOST_TInt32 inX,
GHOST_TInt32 inY,
GHOST_TInt32& outX,
GHOST_TInt32& outY
) const;
GHOST_TWindowState
getState(
) const ;
GHOST_TSuccess
setState(
GHOST_TWindowState state
);
GHOST_TSuccess
setOrder(
GHOST_TWindowOrder order
);
GHOST_TSuccess
swapBuffers(
);
GHOST_TSuccess
activateDrawingContext(
);
GHOST_TSuccess
invalidate(
);
/**
* Destructor.
* Closes the window and disposes resources allocated.
*/
~GHOST_WindowX11();
/**
* @section x11specific X11 system specific calls
*/
/**
* The reverse of invalidate! Tells this window
* that all events for it have been pushed into
* the GHOST event queue.
*/
void
validate(
);
/**
* Return a handle to the x11 window type.
*/
Window
getXWindow(
);
class XTablet
{
public:
GHOST_TabletData CommonData;
XDevice* StylusDevice;
XDevice* EraserDevice;
XID StylusID, EraserID;
int MotionEvent;
int ProxInEvent;
int ProxOutEvent;
int PressureLevels;
int XtiltLevels, YtiltLevels;
};
XTablet& GetXTablet()
{ return m_xtablet; }
const GHOST_TabletData* GetTabletData()
{ return &m_xtablet.CommonData; }
/*
* Need this in case that we want start the window
* in FullScree or Maximized state.
* Check GHOST_WindowX11.cpp
*/
bool m_post_init;
GHOST_TWindowState m_post_state;
protected:
/**
* Tries to install a rendering context in this window.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
GHOST_TSuccess
installDrawingContext(
GHOST_TDrawingContextType type
);
/**
* Removes the current drawing context.
* @return Indication as to whether removal has succeeded.
*/
GHOST_TSuccess
removeDrawingContext(
);
/**
* Sets the cursor visibility on the window using
* native window system calls.
*/
GHOST_TSuccess
setWindowCursorVisibility(
bool visible
);
/**
* Sets the cursor grab on the window using
* native window system calls.
* @param warp Only used when grab is enabled, hides the mouse and allows gragging outside the screen.
*/
GHOST_TSuccess
setWindowCursorGrab(
GHOST_TGrabCursorMode mode
);
GHOST_TGrabCursorMode
getWindowCursorGrab() const;
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
GHOST_TSuccess
setWindowCursorShape(
GHOST_TStandardCursor shape
);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
GHOST_TSuccess
setWindowCustomCursorShape(
GHOST_TUns8 bitmap[16][2],
GHOST_TUns8 mask[16][2],
int hotX,
int hotY
);
/**
* Sets the cursor shape on the window using
* native window system calls (Arbitrary size/color).
*/
GHOST_TSuccess
setWindowCustomCursorShape(
GHOST_TUns8 *bitmap,
GHOST_TUns8 *mask,
int sizex,
int sizey,
int hotX,
int hotY,
int fg_color,
int bg_color
);
private :
/// Force use of public constructor.
GHOST_WindowX11(
);
GHOST_WindowX11(
const GHOST_WindowX11 &
);
Cursor
getStandardCursor(
GHOST_TStandardCursor g_cursor
);
Cursor
getEmptyCursor(
);
void initXInputDevices();
GLXContext m_context;
Window m_window;
Display *m_display;
XVisualInfo *m_visual;
GHOST_TWindowState m_normal_state;
/** The first created OpenGL context (for sharing display lists) */
static GLXContext s_firstContext;
/// A pointer to the typed system class.
GHOST_SystemX11 * m_system;
bool m_valid_setup;
/** Used to concatenate calls to invalidate() on this window. */
bool m_invalid_window;
/** XCursor structure of an empty (blank) cursor */
Cursor m_empty_cursor;
/** XCursor structure of the custom cursor */
Cursor m_custom_cursor;
/** Cache of XC_* ID's to XCursor structures */
std::map<unsigned int, Cursor> m_standard_cursors;
/* Tablet devices */
XTablet m_xtablet;
void icccmSetState(int state);
int icccmGetState() const;
void netwmMaximized(bool set);
bool netwmIsMaximized() const;
void netwmFullScreen(bool set);
bool netwmIsFullScreen() const;
void motifFullScreen(bool set);
bool motifIsFullScreen() const;
};
#endif // _GHOST_WINDOWX11_H_

View File

@@ -0,0 +1,557 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
*
* Simple test file for the GHOST library.
* The OpenGL gear code is taken from the Qt sample code which,
* in turn, is probably taken from somewhere as well.
* @author Maarten Gribnau
* @date May 31, 2001
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define FALSE 0
#include "GHOST_C-api.h"
#if defined(WIN32) || defined(__APPLE__)
#ifdef WIN32
#include <windows.h>
#include <GL/gl.h>
#else /* WIN32 */
/* __APPLE__ is defined */
#include <AGL/gl.h>
#endif /* WIN32 */
#else /* defined(WIN32) || defined(__APPLE__) */
#include <GL/gl.h>
#endif /* defined(WIN32) || defined(__APPLE__) */
static void gearsTimerProc(GHOST_TimerTaskHandle task, GHOST_TUns64 time);
int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData);
static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
static GLfloat fAngle = 0.0;
static int sExitRequested = 0;
static GHOST_SystemHandle shSystem = NULL;
static GHOST_WindowHandle sMainWindow = NULL;
static GHOST_WindowHandle sSecondaryWindow = NULL;
static GHOST_TStandardCursor sCursor = GHOST_kStandardCursorFirstCursor;
static GHOST_WindowHandle sFullScreenWindow = NULL;
static GHOST_TimerTaskHandle sTestTimer;
static GHOST_TimerTaskHandle sGearsTimer;
static void testTimerProc(GHOST_TimerTaskHandle task, GHOST_TUns64 time)
{
printf("timer1, time=%d\n", (int)time);
}
static void gearGL(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth)
{
GLint i;
GLfloat r0, r1, r2;
GLfloat angle, da;
GLfloat u, v, len;
const double pi = 3.14159264;
r0 = inner_radius;
r1 = (float)(outer_radius - tooth_depth/2.0);
r2 = (float)(outer_radius + tooth_depth/2.0);
da = (float)(2.0*pi / teeth / 4.0);
glShadeModel(GL_FLAT);
glNormal3f(0.0, 0.0, 1.0);
/* draw front face */
glBegin(GL_QUAD_STRIP);
for (i=0;i<=teeth;i++) {
angle = (float)(i * 2.0*pi / teeth);
glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5));
glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5));
glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5));
glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5));
}
glEnd();
/* draw front sides of teeth */
glBegin(GL_QUADS);
da = (float)(2.0*pi / teeth / 4.0);
for (i=0;i<teeth;i++) {
angle = (float)(i * 2.0*pi / teeth);
glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5));
glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(width*0.5));
glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(width*0.5));
glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5));
}
glEnd();
glNormal3f(0.0, 0.0, -1.0);
/* draw back face */
glBegin(GL_QUAD_STRIP);
for (i=0;i<=teeth;i++) {
angle = (float)(i * 2.0*pi / teeth);
glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5));
glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5));
glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5));
glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5));
}
glEnd();
/* draw back sides of teeth */
glBegin(GL_QUADS);
da = (float)(2.0*pi / teeth / 4.0);
for (i=0;i<teeth;i++) {
angle = (float)(i * 2.0*pi / teeth);
glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5));
glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(-width*0.5));
glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(-width*0.5));
glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5));
}
glEnd();
/* draw outward faces of teeth */
glBegin(GL_QUAD_STRIP);
for (i=0;i<teeth;i++) {
angle = (float)(i * 2.0*pi / teeth);
glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5));
glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5));
u = (float)(r2*cos(angle+da) - r1*cos(angle));
v = (float)(r2*sin(angle+da) - r1*sin(angle));
len = (float)(sqrt(u*u + v*v));
u /= len;
v /= len;
glNormal3f(v, -u, 0.0);
glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(width*0.5));
glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(-width*0.5));
glNormal3f((float)(cos(angle)), (float)(sin(angle)), 0.0);
glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(width*0.5));
glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(-width*0.5));
u = (float)(r1*cos(angle+3*da) - r2*cos(angle+2*da));
v = (float)(r1*sin(angle+3*da) - r2*sin(angle+2*da));
glNormal3f(v, -u, 0.0);
glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5));
glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5));
glNormal3f((float)(cos(angle)), (float)(sin(angle)), 0.0);
}
glVertex3f((float)(r1*cos(0.0)), (float)(r1*sin(0.0)), (float)(width*0.5));
glVertex3f((float)(r1*cos(0.0)), (float)(r1*sin(0.0)), (float)(-width*0.5));
glEnd();
glShadeModel(GL_SMOOTH);
/* draw inside radius cylinder */
glBegin(GL_QUAD_STRIP);
for (i=0;i<=teeth;i++) {
angle = (float)(i * 2.0*pi / teeth);
glNormal3f((float)(-cos(angle)), (float)(-sin(angle)), 0.0);
glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5));
glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5));
}
glEnd();
}
static void drawGearGL(int id)
{
static GLfloat pos[4] = { 5.0f, 5.0f, 10.0f, 1.0f };
static GLfloat ared[4] = { 0.8f, 0.1f, 0.0f, 1.0f };
static GLfloat agreen[4] = { 0.0f, 0.8f, 0.2f, 1.0f };
static GLfloat ablue[4] = { 0.2f, 0.2f, 1.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
switch (id)
{
case 1:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ared);
gearGL(1.0f, 4.0f, 1.0f, 20, 0.7f);
break;
case 2:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, agreen);
gearGL(0.5f, 2.0f, 2.0f, 10, 0.7f);
break;
case 3:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ablue);
gearGL(1.3f, 2.0f, 0.5f, 10, 0.7f);
break;
default:
break;
}
glEnable(GL_NORMALIZE);
}
static void drawGL(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(view_rotx, 1.0, 0.0, 0.0);
glRotatef(view_roty, 0.0, 1.0, 0.0);
glRotatef(view_rotz, 0.0, 0.0, 1.0);
glPushMatrix();
glTranslatef(-3.0, -2.0, 0.0);
glRotatef(fAngle, 0.0, 0.0, 1.0);
drawGearGL(1);
glPopMatrix();
glPushMatrix();
glTranslatef(3.1f, -2.0f, 0.0f);
glRotatef((float)(-2.0*fAngle-9.0), 0.0, 0.0, 1.0);
drawGearGL(2);
glPopMatrix();
glPushMatrix();
glTranslatef(-3.1f, 2.2f, -1.8f);
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glRotatef((float)(2.0*fAngle-2.0), 0.0, 0.0, 1.0);
drawGearGL(3);
glPopMatrix();
glPopMatrix();
}
static void setViewPortGL(GHOST_WindowHandle hWindow)
{
GHOST_RectangleHandle hRect = NULL;
GLfloat w, h;
GHOST_ActivateWindowDrawingContext(hWindow);
hRect = GHOST_GetClientBounds(hWindow);
w = (float)GHOST_GetWidthRectangle(hRect) / (float)GHOST_GetHeightRectangle(hRect);
h = 1.0;
glViewport(0, 0, GHOST_GetWidthRectangle(hRect), GHOST_GetHeightRectangle(hRect));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-w, w, -h, h, 5.0, 60.0);
/* glOrtho(0, bnds.getWidth(), 0, bnds.getHeight(), -10, 10); */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -40.0);
glClearColor(.2f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
GHOST_DisposeRectangle(hRect);
}
int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData)
{
int handled = 1;
int cursor;
int visibility;
GHOST_TEventKeyData* keyData = NULL;
GHOST_TEventWheelData* wheelData = NULL;
GHOST_DisplaySetting setting;
GHOST_WindowHandle window = GHOST_GetEventWindow(hEvent);
switch (GHOST_GetEventType(hEvent))
{
/*
case GHOST_kEventUnknown:
break;
case GHOST_kEventCursorButton:
break;
case GHOST_kEventCursorMove:
break;
*/
case GHOST_kEventWheel:
{
wheelData = (GHOST_TEventWheelData*)GHOST_GetEventData(hEvent);
if (wheelData->z > 0)
{
view_rotz += 5.f;
}
else
{
view_rotz -= 5.f;
}
}
break;
case GHOST_kEventKeyUp:
break;
case GHOST_kEventKeyDown:
{
keyData = (GHOST_TEventKeyData*)GHOST_GetEventData(hEvent);
switch (keyData->key)
{
case GHOST_kKeyC:
{
cursor = sCursor;
cursor++;
if (cursor >= GHOST_kStandardCursorNumCursors)
{
cursor = GHOST_kStandardCursorFirstCursor;
}
sCursor = (GHOST_TStandardCursor)cursor;
GHOST_SetCursorShape(window, sCursor);
}
break;
case GHOST_kKeyF:
if (!GHOST_GetFullScreen(shSystem))
{
/* Begin fullscreen mode */
setting.bpp = 24;
setting.frequency = 85;
setting.xPixels = 640;
setting.yPixels = 480;
/*
setting.bpp = 16;
setting.frequency = 75;
setting.xPixels = 640;
setting.yPixels = 480;
*/
sFullScreenWindow = GHOST_BeginFullScreen(shSystem, &setting,
FALSE /* stereo flag */);
}
else
{
GHOST_EndFullScreen(shSystem);
sFullScreenWindow = 0;
}
break;
case GHOST_kKeyH:
{
visibility = GHOST_GetCursorVisibility(window);
GHOST_SetCursorVisibility(window, !visibility);
}
break;
case GHOST_kKeyQ:
if (GHOST_GetFullScreen(shSystem))
{
GHOST_EndFullScreen(shSystem);
sFullScreenWindow = 0;
}
sExitRequested = 1;
case GHOST_kKeyT:
if (!sTestTimer)
{
sTestTimer = GHOST_InstallTimer(shSystem, 0, 1000, testTimerProc, NULL);
}
else
{
GHOST_RemoveTimer(shSystem, sTestTimer);
sTestTimer = 0;
}
break;
case GHOST_kKeyW:
{
if (sMainWindow)
{
char *title = GHOST_GetTitle(sMainWindow);
char *ntitle = malloc(strlen(title)+2);
sprintf(ntitle, "%s-", title);
GHOST_SetTitle(sMainWindow, ntitle);
free(ntitle);
free(title);
}
}
break;
default:
break;
}
}
break;
case GHOST_kEventWindowClose:
{
GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent);
if (window2 == sMainWindow)
{
sExitRequested = 1;
}
else
{
if (sGearsTimer)
{
GHOST_RemoveTimer(shSystem, sGearsTimer);
sGearsTimer = 0;
}
GHOST_DisposeWindow(shSystem, window2);
}
}
break;
case GHOST_kEventWindowActivate:
handled = 0;
break;
case GHOST_kEventWindowDeactivate:
handled = 0;
break;
case GHOST_kEventWindowUpdate:
{
GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent);
if (!GHOST_ValidWindow(shSystem, window2))
break;
setViewPortGL(window2);
drawGL();
GHOST_SwapWindowBuffers(window2);
}
break;
default:
handled = 0;
break;
}
return handled;
}
int main(int argc, char** argv)
{
char* title1 = "gears - main window";
char* title2 = "gears - secondary window";
GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(processEvent, NULL);
/* Create the system */
shSystem = GHOST_CreateSystem();
GHOST_AddEventConsumer(shSystem, consumer);
if (shSystem)
{
/* Create the main window */
sMainWindow = GHOST_CreateWindow(shSystem,
title1,
10,
64,
320,
200,
GHOST_kWindowStateNormal,
GHOST_kDrawingContextTypeOpenGL,
FALSE);
if (!sMainWindow)
{
printf("could not create main window\n");
exit(-1);
}
/* Create a secondary window */
sSecondaryWindow = GHOST_CreateWindow(shSystem,
title2,
340,
64,
320,
200,
GHOST_kWindowStateNormal,
GHOST_kDrawingContextTypeOpenGL,
FALSE);
if (!sSecondaryWindow)
{
printf("could not create secondary window\n");
exit(-1);
}
/* Install a timer to have the gears running */
sGearsTimer = GHOST_InstallTimer(shSystem,
0,
10,
gearsTimerProc,
sMainWindow);
/* Enter main loop */
while (!sExitRequested)
{
if (!GHOST_ProcessEvents(shSystem, 0))
{
#ifdef WIN32
/* If there were no events, be nice to other applications */
Sleep(10);
#endif
}
GHOST_DispatchEvents(shSystem);
}
}
/* Dispose windows */
if (GHOST_ValidWindow(shSystem, sMainWindow))
{
GHOST_DisposeWindow(shSystem, sMainWindow);
}
if (GHOST_ValidWindow(shSystem, sSecondaryWindow))
{
GHOST_DisposeWindow(shSystem, sSecondaryWindow);
}
/* Dispose the system */
GHOST_DisposeSystem(shSystem);
GHOST_DisposeEventConsumer(consumer);
return 0;
}
static void gearsTimerProc(GHOST_TimerTaskHandle hTask, GHOST_TUns64 time)
{
GHOST_WindowHandle hWindow = NULL;
fAngle += 2.0;
view_roty += 1.0;
hWindow = (GHOST_WindowHandle)GHOST_GetTimerTaskUserData(hTask);
if (GHOST_GetFullScreen(shSystem))
{
/* Running full screen */
GHOST_InvalidateWindow(sFullScreenWindow);
}
else
{
if (GHOST_ValidWindow(shSystem, hWindow))
{
GHOST_InvalidateWindow(hWindow);
}
}
}

View File

@@ -0,0 +1,754 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* Simple test file for the GHOST library.
* The OpenGL gear code is taken from the Qt sample code which,
* in turn, is probably taken from somewhere as well.
* @author Maarten Gribnau
* @date May 31, 2001
* Stereo code by Raymond de Vries, januari 2002
*/
#include <iostream>
#include <math.h>
#if defined(WIN32) || defined(__APPLE__)
#ifdef WIN32
#include <windows.h>
#include <atlbase.h>
#include <GL/gl.h>
#else // WIN32
// __APPLE__ is defined
#include <AGL/gl.h>
#endif // WIN32
#else // defined(WIN32) || defined(__APPLE__)
#include <GL/gl.h>
#endif // defined(WIN32) || defined(__APPLE__)
#include "STR_String.h"
#include "GHOST_Rect.h"
#include "GHOST_ISystem.h"
#include "GHOST_IEvent.h"
#include "GHOST_IEventConsumer.h"
#define LEFT_EYE 0
#define RIGHT_EYE 1
static bool nVidiaWindows; // very dirty but hey, it's for testing only
static void gearsTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time);
static class Application* fApp;
static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
static GLfloat fAngle = 0.0;
static GHOST_ISystem* fSystem = 0;
void StereoProjection(float left, float right, float bottom, float top, float nearplane, float farplane,
float zero_plane, float dist,
float eye);
static void testTimerProc(GHOST_ITimerTask* /*task*/, GHOST_TUns64 time)
{
std::cout << "timer1, time=" << (int)time << "\n";
}
static void gearGL(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth)
{
GLint i;
GLfloat r0, r1, r2;
GLfloat angle, da;
GLfloat u, v, len;
r0 = inner_radius;
r1 = outer_radius - tooth_depth/2.0;
r2 = outer_radius + tooth_depth/2.0;
const double pi = 3.14159264;
da = 2.0*pi / teeth / 4.0;
glShadeModel(GL_FLAT);
glNormal3f(0.0, 0.0, 1.0);
/* draw front face */
glBegin(GL_QUAD_STRIP);
for (i=0;i<=teeth;i++) {
angle = i * 2.0*pi / teeth;
glVertex3f(r0*cos(angle), r0*sin(angle), width*0.5);
glVertex3f(r1*cos(angle), r1*sin(angle), width*0.5);
glVertex3f(r0*cos(angle), r0*sin(angle), width*0.5);
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5);
}
glEnd();
/* draw front sides of teeth */
glBegin(GL_QUADS);
da = 2.0*pi / teeth / 4.0;
for (i=0;i<teeth;i++) {
angle = i * 2.0*pi / teeth;
glVertex3f(r1*cos(angle), r1*sin(angle), width*0.5);
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), width*0.5);
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5);
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5);
}
glEnd();
glNormal3f(0.0, 0.0, -1.0);
/* draw back face */
glBegin(GL_QUAD_STRIP);
for (i=0;i<=teeth;i++) {
angle = i * 2.0*pi / teeth;
glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5);
glVertex3f(r0*cos(angle), r0*sin(angle), -width*0.5);
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5);
glVertex3f(r0*cos(angle), r0*sin(angle), -width*0.5);
}
glEnd();
/* draw back sides of teeth */
glBegin(GL_QUADS);
da = 2.0*pi / teeth / 4.0;
for (i=0;i<teeth;i++) {
angle = i * 2.0*pi / teeth;
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5);
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5);
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), -width*0.5);
glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5);
}
glEnd();
/* draw outward faces of teeth */
glBegin(GL_QUAD_STRIP);
for (i=0;i<teeth;i++) {
angle = i * 2.0*pi / teeth;
glVertex3f(r1*cos(angle), r1*sin(angle), width*0.5);
glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5);
u = r2*cos(angle+da) - r1*cos(angle);
v = r2*sin(angle+da) - r1*sin(angle);
len = sqrt(u*u + v*v);
u /= len;
v /= len;
glNormal3f(v, -u, 0.0);
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), width*0.5);
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), -width*0.5);
glNormal3f(cos(angle), sin(angle), 0.0);
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5);
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5);
u = r1*cos(angle+3*da) - r2*cos(angle+2*da);
v = r1*sin(angle+3*da) - r2*sin(angle+2*da);
glNormal3f(v, -u, 0.0);
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5);
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5);
glNormal3f(cos(angle), sin(angle), 0.0);
}
glVertex3f(r1*cos(0.0), r1*sin(0.0), width*0.5);
glVertex3f(r1*cos(0.0), r1*sin(0.0), -width*0.5);
glEnd();
glShadeModel(GL_SMOOTH);
/* draw inside radius cylinder */
glBegin(GL_QUAD_STRIP);
for (i=0;i<=teeth;i++) {
angle = i * 2.0*pi / teeth;
glNormal3f(-cos(angle), -sin(angle), 0.0);
glVertex3f(r0*cos(angle), r0*sin(angle), -width*0.5);
glVertex3f(r0*cos(angle), r0*sin(angle), width*0.5);
}
glEnd();
}
static void drawGearGL(int id)
{
static GLfloat pos[4] = { 5.0f, 5.0f, 10.0f, 1.0f };
static GLfloat ared[4] = { 0.8f, 0.1f, 0.0f, 1.0f };
static GLfloat agreen[4] = { 0.0f, 0.8f, 0.2f, 1.0f };
static GLfloat ablue[4] = { 0.2f, 0.2f, 1.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
switch (id)
{
case 1:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ared);
gearGL(1.0f, 4.0f, 1.0f, 20, 0.7f);
break;
case 2:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, agreen);
gearGL(0.5f, 2.0f, 2.0f, 10, 0.7f);
break;
case 3:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ablue);
gearGL(1.3f, 2.0f, 0.5f, 10, 0.7f);
break;
default:
break;
}
glEnable(GL_NORMALIZE);
}
void RenderCamera()
{
glRotatef(view_rotx, 1.0, 0.0, 0.0);
glRotatef(view_roty, 0.0, 1.0, 0.0);
glRotatef(view_rotz, 0.0, 0.0, 1.0);
}
void RenderScene()
{
glPushMatrix();
glTranslatef(-3.0, -2.0, 0.0);
glRotatef(fAngle, 0.0, 0.0, 1.0);
drawGearGL(1);
glPopMatrix();
glPushMatrix();
glTranslatef(3.1f, -2.0f, 0.0f);
glRotatef(-2.0 * fAngle - 9.0, 0.0, 0.0, 1.0);
drawGearGL(2);
glPopMatrix();
glPushMatrix();
glTranslatef(-3.1f, 2.2f, -1.8f);
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(2.0 * fAngle - 2.0, 0.0, 0.0, 1.0);
drawGearGL(3);
glPopMatrix();
}
static void View(GHOST_IWindow* window, bool stereo, int eye = 0)
{
window->activateDrawingContext();
GHOST_Rect bnds;
int noOfScanlines = 0, lowerScanline = 0;
int verticalBlankingInterval = 32; // hard coded for testing purposes, display device dependant
float left, right, bottom, top;
float nearplane, farplane, zeroPlane, distance;
float eyeSeparation = 0.62f;
window->getClientBounds(bnds);
// viewport
if(stereo)
{
if(nVidiaWindows)
{
// handled by nVidia driver so act as normal (explicitly put here since
// it -is- stereo)
glViewport(0, 0, bnds.getWidth(), bnds.getHeight());
}
else
{ // generic cross platform above-below stereo
noOfScanlines = (bnds.getHeight() - verticalBlankingInterval) / 2;
switch(eye)
{
case LEFT_EYE:
// upper half of window
lowerScanline = bnds.getHeight() - noOfScanlines;
break;
case RIGHT_EYE:
// lower half of window
lowerScanline = 0;
break;
}
}
}
else
{
noOfScanlines = bnds.getHeight();
lowerScanline = 0;
}
glViewport(0, lowerScanline, bnds.getWidth(), noOfScanlines);
// projection
left = -6.0;
right = 6.0;
bottom = -4.8f;
top = 4.8f;
nearplane = 5.0;
farplane = 60.0;
if(stereo)
{
zeroPlane = 0.0;
distance = 14.5;
switch(eye)
{
case LEFT_EYE:
StereoProjection(left, right, bottom, top, nearplane, farplane, zeroPlane, distance, -eyeSeparation / 2.0);
break;
case RIGHT_EYE:
StereoProjection(left, right, bottom, top, nearplane, farplane, zeroPlane, distance, eyeSeparation / 2.0);
break;
}
}
else
{
// left = -w;
// right = w;
// bottom = -h;
// top = h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left, right, bottom, top, 5.0, 60.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -40.0);
}
glClearColor(.2f,0.0f,0.0f,0.0f);
}
void StereoProjection(float left, float right, float bottom, float top, float nearplane, float farplane,
float zero_plane, float dist,
float eye)
/* Perform the perspective projection for one eye's subfield.
The projection is in the direction of the negative z axis.
-6.0, 6.0, -4.8, 4.8,
left, right, bottom, top = the coordinate range, in the plane of zero
parallax setting, which will be displayed on the screen. The
ratio between (right-left) and (top-bottom) should equal the aspect
ratio of the display.
6.0, -6.0,
near, far = the z-coordinate values of the clipping planes.
0.0,
zero_plane = the z-coordinate of the plane of zero parallax setting.
14.5,
dist = the distance from the center of projection to the plane
of zero parallax.
-0.31
eye = half the eye separation; positive for the right eye subfield,
negative for the left eye subfield.
*/
{
float xmid, ymid, clip_near, clip_far, topw, bottomw, leftw, rightw,
dx, dy, n_over_d;
dx = right - left;
dy = top - bottom;
xmid = (right + left) / 2.0;
ymid = (top + bottom) / 2.0;
clip_near = dist + zero_plane - nearplane;
clip_far = dist + zero_plane - farplane;
n_over_d = clip_near / dist;
topw = n_over_d * dy / 2.0;
bottomw = -topw;
rightw = n_over_d * (dx / 2.0 - eye);
leftw = n_over_d *(-dx / 2.0 - eye);
/* Need to be in projection mode for this. */
glLoadIdentity();
glFrustum(leftw, rightw, bottomw, topw, clip_near, clip_far);
glTranslatef(-xmid - eye, -ymid, -zero_plane - dist);
return;
} /* stereoproj */
class Application : public GHOST_IEventConsumer {
public:
Application(GHOST_ISystem* system);
~Application(void);
virtual bool processEvent(GHOST_IEvent* event);
GHOST_ISystem* m_system;
GHOST_IWindow* m_mainWindow;
GHOST_IWindow* m_secondaryWindow;
GHOST_IWindow* m_fullScreenWindow;
GHOST_ITimerTask* m_gearsTimer, *m_testTimer;
GHOST_TStandardCursor m_cursor;
bool m_exitRequested;
bool stereo;
};
Application::Application(GHOST_ISystem* system)
: m_system(system), m_mainWindow(0), m_secondaryWindow(0), m_fullScreenWindow(0),
m_gearsTimer(0), m_testTimer(0), m_cursor(GHOST_kStandardCursorFirstCursor),
m_exitRequested(false), stereo(false)
{
fApp = this;
// Create the main window
STR_String title1 ("gears - main window");
m_mainWindow = system->createWindow(title1, 10, 64, 320, 200, GHOST_kWindowStateNormal,
GHOST_kDrawingContextTypeOpenGL, true /* stereo flag */);
if (!m_mainWindow) {
std::cout << "could not create main window\n";
exit(-1);
}
// Create a secondary window
STR_String title2 ("gears - secondary window");
m_secondaryWindow = system->createWindow(title2, 340, 64, 320, 200, GHOST_kWindowStateNormal,
GHOST_kDrawingContextTypeOpenGL, false /* stereo flag */);
if (!m_secondaryWindow) {
cout << "could not create secondary window\n";
exit(-1);
}
// Install a timer to have the gears running
m_gearsTimer = system->installTimer(0 /*delay*/, 20/*interval*/, gearsTimerProc, m_mainWindow);
}
Application::~Application(void)
{
// Dispose windows
if (m_system->validWindow(m_mainWindow)) {
m_system->disposeWindow(m_mainWindow);
}
if (m_system->validWindow(m_secondaryWindow)) {
m_system->disposeWindow(m_secondaryWindow);
}
}
bool Application::processEvent(GHOST_IEvent* event)
{
GHOST_IWindow* window = event->getWindow();
bool handled = true;
switch (event->getType()) {
/* case GHOST_kEventUnknown:
break;
case GHOST_kEventCursorButton:
std::cout << "GHOST_kEventCursorButton"; break;
case GHOST_kEventCursorMove:
std::cout << "GHOST_kEventCursorMove"; break;
*/
case GHOST_kEventWheel:
{
GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*) event->getData();
if (wheelData->z > 0)
{
view_rotz += 5.f;
}
else
{
view_rotz -= 5.f;
}
}
break;
case GHOST_kEventKeyUp:
break;
case GHOST_kEventKeyDown:
{
GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*) event->getData();
switch (keyData->key) {
case GHOST_kKeyC:
{
int cursor = m_cursor;
cursor++;
if (cursor >= GHOST_kStandardCursorNumCursors) {
cursor = GHOST_kStandardCursorFirstCursor;
}
m_cursor = (GHOST_TStandardCursor)cursor;
window->setCursorShape(m_cursor);
}
break;
case GHOST_kKeyE:
{
int x = 200, y= 200;
m_system->setCursorPosition(x,y);
break;
}
case GHOST_kKeyF:
if (!m_system->getFullScreen()) {
// Begin fullscreen mode
GHOST_DisplaySetting setting;
setting.bpp = 16;
setting.frequency = 50;
setting.xPixels = 640;
setting.yPixels = 480;
m_system->beginFullScreen(setting, &m_fullScreenWindow, false /* stereo flag */);
}
else {
m_system->endFullScreen();
m_fullScreenWindow = 0;
}
break;
case GHOST_kKeyH:
window->setCursorVisibility(!window->getCursorVisibility());
break;
case GHOST_kKeyM:
{
bool down = false;
m_system->getModifierKeyState(GHOST_kModifierKeyLeftShift,down);
if (down) {
std::cout << "left shift down\n";
}
m_system->getModifierKeyState(GHOST_kModifierKeyRightShift,down);
if (down) {
std::cout << "right shift down\n"; }
m_system->getModifierKeyState(GHOST_kModifierKeyLeftAlt,down);
if (down) {
std::cout << "left Alt down\n";
}
m_system->getModifierKeyState(GHOST_kModifierKeyRightAlt,down);
if (down) {
std::cout << "right Alt down\n";
}
m_system->getModifierKeyState(GHOST_kModifierKeyLeftControl,down);
if (down) {
std::cout << "left control down\n";
}
m_system->getModifierKeyState(GHOST_kModifierKeyRightControl,down);
if (down) {
std::cout << "right control down\n";
}
}
break;
case GHOST_kKeyQ:
if (m_system->getFullScreen())
{
m_system->endFullScreen();
m_fullScreenWindow = 0;
}
m_exitRequested = true;
break;
case GHOST_kKeyS: // toggle mono and stereo
if(stereo)
stereo = false;
else
stereo = true;
break;
case GHOST_kKeyT:
if (!m_testTimer) {
m_testTimer = m_system->installTimer(0, 1000, testTimerProc);
}
else {
m_system->removeTimer(m_testTimer);
m_testTimer = 0;
}
break;
case GHOST_kKeyW:
if (m_mainWindow)
{
STR_String title;
m_mainWindow->getTitle(title);
title += "-";
m_mainWindow->setTitle(title);
}
break;
default:
break;
}
}
break;
case GHOST_kEventWindowClose:
{
GHOST_IWindow* window2 = event->getWindow();
if (window2 == m_mainWindow) {
m_exitRequested = true;
}
else {
m_system->disposeWindow(window2);
}
}
break;
case GHOST_kEventWindowActivate:
handled = false;
break;
case GHOST_kEventWindowDeactivate:
handled = false;
break;
case GHOST_kEventWindowUpdate:
{
GHOST_IWindow* window2 = event->getWindow();
if(!m_system->validWindow(window2))
break;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(stereo)
{
View(window2, stereo, LEFT_EYE);
glPushMatrix();
RenderCamera();
RenderScene();
glPopMatrix();
View(window2, stereo, RIGHT_EYE);
glPushMatrix();
RenderCamera();
RenderScene();
glPopMatrix();
}
else
{
View(window2, stereo);
glPushMatrix();
RenderCamera();
RenderScene();
glPopMatrix();
}
window2->swapBuffers();
}
break;
default:
handled = false;
break;
}
return handled;
}
int main(int /*argc*/, char** /*argv*/)
{
nVidiaWindows = false;
// nVidiaWindows = true;
#ifdef WIN32
/* Set a couple of settings in the registry for the nVidia detonator driver.
* So this is very specific...
*/
if(nVidiaWindows)
{
LONG lresult;
HKEY hkey = 0;
DWORD dwd = 0;
//unsigned char buffer[128];
CRegKey regkey;
//DWORD keyValue;
// lresult = regkey.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\NVIDIA Corporation\\Global\\Stereo3D\\StereoEnable");
lresult = regkey.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\NVIDIA Corporation\\Global\\Stereo3D\\StereoEnable",
KEY_ALL_ACCESS );
if(lresult == ERROR_SUCCESS)
printf("Succesfully opened key\n");
#if 0
lresult = regkey.QueryValue(&keyValue, "StereoEnable");
if(lresult == ERROR_SUCCESS)
printf("Succesfully queried key\n");
#endif
lresult = regkey.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\NVIDIA Corporation\\Global\\Stereo3D\\StereoEnable",
"1");
if(lresult == ERROR_SUCCESS)
printf("Succesfully set value for key\n");
regkey.Close();
if(lresult == ERROR_SUCCESS)
printf("Succesfully closed key\n");
// regkey.Write("2");
}
#endif // WIN32
// Create the system
GHOST_ISystem::createSystem();
fSystem = GHOST_ISystem::getSystem();
if (fSystem) {
// Create an application object
Application app (fSystem);
// Add the application as event consumer
fSystem->addEventConsumer(&app);
// Enter main loop
while (!app.m_exitRequested) {
//printf("main: loop\n");
fSystem->processEvents(true);
fSystem->dispatchEvents();
}
}
// Dispose the system
GHOST_ISystem::disposeSystem();
return 0;
}
static void gearsTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 /*time*/)
{
fAngle += 2.0;
view_roty += 1.0;
GHOST_IWindow* window = (GHOST_IWindow*)task->getUserData();
if (fApp->m_fullScreenWindow) {
// Running full screen
fApp->m_fullScreenWindow->invalidate();
}
else {
if (fSystem->validWindow(window)) {
window->invalidate();
}
}
}

View File

@@ -0,0 +1,64 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
#include "Basic.h"
int min_i(int a, int b) {
return (a<b)?a:b;
}
int max_i(int a, int b) {
return (b<a)?a:b;
}
int clamp_i(int val, int min, int max) {
return min_i(max_i(val, min), max);
}
float min_f(float a, float b) {
return (a<b)?a:b;
}
float max_f(float a, float b) {
return (b<a)?a:b;
}
float clamp_f(float val, float min, float max) {
return min_f(max_f(val, min), max);
}
void rect_copy(int dst[2][2], int src[2][2]) {
dst[0][0]= src[0][0], dst[0][1]= src[0][1];
dst[1][0]= src[1][0], dst[1][1]= src[1][1];
}
int rect_contains_pt(int rect[2][2], int pt[2]){
return ((rect[0][0] <= pt[0] && pt[0] <= rect[1][0]) &&
(rect[0][1] <= pt[1] && pt[1] <= rect[1][1]));
}
int rect_width(int rect[2][2]) {
return (rect[1][0]-rect[0][0]);
}
int rect_height(int rect[2][2]) {
return (rect[1][1]-rect[0][1]);
}

View File

@@ -0,0 +1,42 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
int min_i (int a, int b);
int max_i (int a, int b);
int clamp_i (int val, int min, int max);
float min_f (float a, float b);
float max_f (float a, float b);
float clamp_f (float val, float min, float max);
void rect_copy (int dst[2][2], int src[2][2]);
int rect_contains_pt (int rect[2][2], int pt[2]);
int rect_width (int rect[2][2]);
int rect_height (int rect[2][2]);

View File

@@ -0,0 +1,233 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
#include <stdlib.h>
#include <stdio.h>
#include "MEM_guardedalloc.h"
#include "GHOST_C-api.h"
#include "EventToBuf.h"
char *eventtype_to_string(GHOST_TEventType type) {
switch(type) {
case GHOST_kEventCursorMove: return "CursorMove";
case GHOST_kEventButtonDown: return "ButtonDown";
case GHOST_kEventButtonUp: return "ButtonUp";
case GHOST_kEventKeyDown: return "KeyDown";
case GHOST_kEventKeyUp: return "KeyUp";
case GHOST_kEventQuit: return "Quit";
case GHOST_kEventWindowClose: return "WindowClose";
case GHOST_kEventWindowActivate: return "WindowActivate";
case GHOST_kEventWindowDeactivate: return "WindowDeactivate";
case GHOST_kEventWindowUpdate: return "WindowUpdate";
case GHOST_kEventWindowSize: return "WindowSize";
default:
return "<invalid>";
}
}
static char *keytype_to_string(GHOST_TKey key) {
#define K(key) case GHOST_k##key: return #key;
switch (key) {
K(KeyBackSpace);
K(KeyTab);
K(KeyLinefeed);
K(KeyClear);
K(KeyEnter);
K(KeyEsc);
K(KeySpace);
K(KeyQuote);
K(KeyComma);
K(KeyMinus);
K(KeyPeriod);
K(KeySlash);
K(Key0);
K(Key1);
K(Key2);
K(Key3);
K(Key4);
K(Key5);
K(Key6);
K(Key7);
K(Key8);
K(Key9);
K(KeySemicolon);
K(KeyEqual);
K(KeyA);
K(KeyB);
K(KeyC);
K(KeyD);
K(KeyE);
K(KeyF);
K(KeyG);
K(KeyH);
K(KeyI);
K(KeyJ);
K(KeyK);
K(KeyL);
K(KeyM);
K(KeyN);
K(KeyO);
K(KeyP);
K(KeyQ);
K(KeyR);
K(KeyS);
K(KeyT);
K(KeyU);
K(KeyV);
K(KeyW);
K(KeyX);
K(KeyY);
K(KeyZ);
K(KeyLeftBracket);
K(KeyRightBracket);
K(KeyBackslash);
K(KeyAccentGrave);
K(KeyLeftShift);
K(KeyRightShift);
K(KeyLeftControl);
K(KeyRightControl);
K(KeyLeftAlt);
K(KeyRightAlt);
K(KeyOS);
K(KeyCapsLock);
K(KeyNumLock);
K(KeyScrollLock);
K(KeyLeftArrow);
K(KeyRightArrow);
K(KeyUpArrow);
K(KeyDownArrow);
K(KeyPrintScreen);
K(KeyPause);
K(KeyInsert);
K(KeyDelete);
K(KeyHome);
K(KeyEnd);
K(KeyUpPage);
K(KeyDownPage);
K(KeyNumpad0);
K(KeyNumpad1);
K(KeyNumpad2);
K(KeyNumpad3);
K(KeyNumpad4);
K(KeyNumpad5);
K(KeyNumpad6);
K(KeyNumpad7);
K(KeyNumpad8);
K(KeyNumpad9);
K(KeyNumpadPeriod);
K(KeyNumpadEnter);
K(KeyNumpadPlus);
K(KeyNumpadMinus);
K(KeyNumpadAsterisk);
K(KeyNumpadSlash);
K(KeyF1);
K(KeyF2);
K(KeyF3);
K(KeyF4);
K(KeyF5);
K(KeyF6);
K(KeyF7);
K(KeyF8);
K(KeyF9);
K(KeyF10);
K(KeyF11);
K(KeyF12);
K(KeyF13);
K(KeyF14);
K(KeyF15);
K(KeyF16);
K(KeyF17);
K(KeyF18);
K(KeyF19);
K(KeyF20);
K(KeyF21);
K(KeyF22);
K(KeyF23);
K(KeyF24);
default:
return "KeyUnknown";
}
#undef K
}
void event_to_buf(GHOST_EventHandle evt, char buf[128]) {
GHOST_TEventType type= GHOST_GetEventType(evt);
double time= (double) ((GHOST_TInt64) GHOST_GetEventTime(evt))/1000;
GHOST_WindowHandle win= GHOST_GetEventWindow(evt);
void *data= GHOST_GetEventData(evt);
char *pos= buf;
pos+= sprintf(pos, "event: %6.2f, %16s", time, eventtype_to_string(type));
if (win) {
char *s= GHOST_GetTitle(win);
pos+= sprintf(pos, " - win: %s", s);
free(s);
} else {
pos+= sprintf(pos, " - sys evt");
}
switch (type) {
case GHOST_kEventCursorMove: {
GHOST_TEventCursorData *cd= data;
pos+= sprintf(pos, " - pos: (%d, %d)", cd->x, cd->y);
break;
}
case GHOST_kEventButtonDown:
case GHOST_kEventButtonUp: {
GHOST_TEventButtonData *bd= data;
pos+= sprintf(pos, " - but: %d", bd->button);
break;
}
case GHOST_kEventKeyDown:
case GHOST_kEventKeyUp: {
GHOST_TEventKeyData *kd= data;
pos+= sprintf(pos, " - key: %s (%d)", keytype_to_string(kd->key), kd->key);
if (kd->ascii) pos+= sprintf(pos, " ascii: '%c' (%d)", kd->ascii, kd->ascii);
break;
}
}
}

View File

@@ -0,0 +1,31 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
char *eventtype_to_string(GHOST_TEventType type);
void event_to_buf(GHOST_EventHandle evt, char buf[128]);

View File

@@ -0,0 +1,41 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
#if defined(WIN32) || defined(__APPLE__)
#ifdef WIN32
#include <windows.h>
#include <GL/gl.h>
#else // WIN32
// __APPLE__ is defined
#include <AGL/gl.h>
#endif // WIN32
#else // defined(WIN32) || defined(__APPLE__)
#include <GL/gl.h>
#endif // defined(WIN32) || defined(__APPLE__)

View File

@@ -0,0 +1,859 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
#define FALSE 0
#ifdef WIN32
#pragma warning(disable: 4244 4305)
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "GL.h"
#include "MEM_guardedalloc.h"
#include "GHOST_C-api.h"
#include "BMF_Api.h"
#include "Util.h"
#include "Basic.h"
#include "ScrollBar.h"
#include "EventToBuf.h"
#include "WindowData.h"
/***/
typedef struct _MultiTestApp MultiTestApp;
typedef struct _LoggerWindow LoggerWindow;
void loggerwindow_log(LoggerWindow *lw, char *line);
void multitestapp_toggle_extra_window(MultiTestApp *app);
void multitestapp_free_extrawindow(MultiTestApp *app);
LoggerWindow *multitestapp_get_logger(MultiTestApp *app);
GHOST_SystemHandle multitestapp_get_system(MultiTestApp *app);
void multitestapp_exit(MultiTestApp *app);
/**/
void rect_bevel_side(int rect[2][2], int side, float *lt, float *dk, float *col, int width) {
int ltidx= (side/2)%4;
int dkidx= (ltidx + 1 + (side&1))%4;
int i, corner;
glBegin(GL_LINES);
for (i=0; i<width; i++) {
float ltf= pow(lt[i], 1.0/2.2), dkf= pow(dk[i], 1.0/2.2);
float stf= (dkidx>ltidx)?dkf:ltf;
int lx= rect[1][0]-i-1;
int ly= rect[0][1]+i;
glColor3f(col[0]*stf, col[1]*stf, col[2]*stf);
for (corner=0; corner<4; corner++) {
int x= (corner==0 || corner==1)?(rect[0][0]+i):(rect[1][0]-i-1);
int y= (corner==0 || corner==3)?(rect[0][1]+i):(rect[1][1]-i-1);
if (ltidx==corner)
glColor3f(col[0]*ltf, col[1]*ltf, col[2]*ltf);
if (dkidx==corner)
glColor3f(col[0]*dkf, col[1]*dkf, col[2]*dkf);
glVertex2i(lx, ly);
glVertex2i(lx= x, ly= y);
}
}
glEnd();
glColor3fv(col);
glRecti(rect[0][0]+width, rect[0][1]+width, rect[1][0]-width, rect[1][1]-width);
}
void rect_bevel_smooth(int rect[2][2], int width) {
float *lt= malloc(sizeof(*lt)*width);
float *dk= malloc(sizeof(*dk)*width);
float col[4];
int i;
for (i=0; i<width; i++) {
float v= width-1?((float) i/(width-1)):0;
lt[i]= 1.2 + (1.0-1.2)*v;
dk[i]= 0.2 + (1.0-0.2)*v;
}
glGetFloatv(GL_CURRENT_COLOR, col);
rect_bevel_side(rect, 3, lt, dk, col, width);
free(lt);
free(dk);
}
/*
* MainWindow
*/
typedef struct {
MultiTestApp *app;
GHOST_WindowHandle win;
int size[2];
int lmouse[2], lmbut[3];
int tmouse[2];
} MainWindow;
static void mainwindow_log(MainWindow *mw, char *str) {
loggerwindow_log(multitestapp_get_logger(mw->app), str);
}
static void mainwindow_do_draw(MainWindow *mw) {
GHOST_ActivateWindowDrawingContext(mw->win);
if (mw->lmbut[0]) {
glClearColor(0.5, 0.5, 0.5, 1);
} else {
glClearColor(1, 1, 1, 1);
}
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.5, 0.6, 0.8);
glRecti(mw->tmouse[0]-5, mw->tmouse[1]-5, mw->tmouse[0]+5, mw->tmouse[1]+5);
GHOST_SwapWindowBuffers(mw->win);
}
static void mainwindow_do_reshape(MainWindow *mw) {
GHOST_RectangleHandle bounds= GHOST_GetClientBounds(mw->win);
GHOST_ActivateWindowDrawingContext(mw->win);
mw->size[0]= GHOST_GetWidthRectangle(bounds);
mw->size[1]= GHOST_GetHeightRectangle(bounds);
glViewport(0, 0, mw->size[0], mw->size[1]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, mw->size[0], 0, mw->size[1], -1, 1);
glTranslatef(0.375, 0.375, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
static void mainwindow_do_key(MainWindow *mw, GHOST_TKey key, int press) {
switch(key) {
case GHOST_kKeyC:
if (press)
GHOST_SetCursorShape(mw->win, (GHOST_TStandardCursor) (rand()%(GHOST_kStandardCursorNumCursors)));
break;
case GHOST_kKeyLeftBracket:
if (press)
GHOST_SetCursorVisibility(mw->win, 0);
break;
case GHOST_kKeyRightBracket:
if (press)
GHOST_SetCursorVisibility(mw->win, 1);
break;
case GHOST_kKeyE:
if (press)
multitestapp_toggle_extra_window(mw->app);
break;
case GHOST_kKeyQ:
if (press)
multitestapp_exit(mw->app);
break;
case GHOST_kKeyT:
if (press)
mainwindow_log(mw, "TextTest~|`hello`\"world\",<>/");
break;
case GHOST_kKeyR:
if (press) {
int i;
mainwindow_log(mw, "Invalidating window 10 times");
for (i=0; i<10; i++)
GHOST_InvalidateWindow(mw->win);
}
break;
case GHOST_kKeyF11:
if (press) {
GHOST_SetWindowOrder(mw->win, GHOST_kWindowOrderBottom);
}
break;
}
}
static void mainwindow_do_move(MainWindow *mw, int x, int y) {
mw->lmouse[0]= x, mw->lmouse[1]= y;
if (mw->lmbut[0]) {
mw->tmouse[0]= x, mw->tmouse[1]= y;
GHOST_InvalidateWindow(mw->win);
}
}
static void mainwindow_do_button(MainWindow *mw, int which, int press) {
if (which==GHOST_kButtonMaskLeft) {
mw->lmbut[0]= press;
mw->tmouse[0]= mw->lmouse[0], mw->tmouse[1]= mw->lmouse[1];
GHOST_InvalidateWindow(mw->win);
} else if (which==GHOST_kButtonMaskLeft) {
mw->lmbut[1]= press;
} else if (which==GHOST_kButtonMaskLeft) {
mw->lmbut[2]= press;
}
}
static void mainwindow_handle(void *priv, GHOST_EventHandle evt) {
MainWindow *mw= priv;
GHOST_TEventType type= GHOST_GetEventType(evt);
char buf[256];
event_to_buf(evt, buf);
mainwindow_log(mw, buf);
switch (type) {
case GHOST_kEventCursorMove: {
GHOST_TEventCursorData *cd= GHOST_GetEventData(evt);
int x, y;
GHOST_ScreenToClient(mw->win, cd->x, cd->y, &x, &y);
mainwindow_do_move(mw, x, mw->size[1]-y-1);
break;
}
case GHOST_kEventButtonDown:
case GHOST_kEventButtonUp: {
GHOST_TEventButtonData *bd= GHOST_GetEventData(evt);
mainwindow_do_button(mw, bd->button, (type == GHOST_kEventButtonDown));
break;
}
case GHOST_kEventKeyDown:
case GHOST_kEventKeyUp: {
GHOST_TEventKeyData *kd= GHOST_GetEventData(evt);
mainwindow_do_key(mw, kd->key, (type == GHOST_kEventKeyDown));
break;
}
case GHOST_kEventWindowUpdate:
mainwindow_do_draw(mw);
break;
case GHOST_kEventWindowSize:
mainwindow_do_reshape(mw);
break;
}
}
/**/
static void mainwindow_timer_proc(GHOST_TimerTaskHandle task, GHOST_TUns64 time) {
MainWindow *mw= GHOST_GetTimerTaskUserData(task);
char buf[64];
sprintf(buf, "timer: %6.2f", (double) ((GHOST_TInt64) time)/1000);
mainwindow_log(mw, buf);
}
MainWindow *mainwindow_new(MultiTestApp *app) {
GHOST_SystemHandle sys= multitestapp_get_system(app);
GHOST_WindowHandle win;
win= GHOST_CreateWindow(sys, "MultiTest:Main", 40, 40, 400, 400,
GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL,
FALSE);
if (win) {
MainWindow *mw= MEM_callocN(sizeof(*mw), "mainwindow_new");
mw->app= app;
mw->win= win;
GHOST_SetWindowUserData(mw->win, windowdata_new(mw, mainwindow_handle));
GHOST_InstallTimer(sys, 1000, 10000, mainwindow_timer_proc, mw);
return mw;
} else {
return NULL;
}
}
void mainwindow_free(MainWindow *mw) {
GHOST_SystemHandle sys= multitestapp_get_system(mw->app);
windowdata_free(GHOST_GetWindowUserData(mw->win));
GHOST_DisposeWindow(sys, mw->win);
MEM_freeN(mw);
}
/*
* LoggerWindow
*/
struct _LoggerWindow {
MultiTestApp *app;
GHOST_WindowHandle win;
BMF_Font *font;
int fonttexid;
int fontheight;
int size[2];
int ndisplines;
int textarea[2][2];
ScrollBar *scroll;
char **loglines;
int nloglines, logsize;
int lmbut[3];
int lmouse[2];
};
#define SCROLLBAR_PAD 2
#define SCROLLBAR_WIDTH 14
#define TEXTAREA_PAD 2
static void loggerwindow_recalc_regions(LoggerWindow *lw) {
int nscroll[2][2];
nscroll[0][0]= SCROLLBAR_PAD;
nscroll[0][1]= SCROLLBAR_PAD;
nscroll[1][0]= nscroll[0][0] + SCROLLBAR_WIDTH;
nscroll[1][1]= lw->size[1] - SCROLLBAR_PAD - 1;
lw->textarea[0][0]= nscroll[1][0] + TEXTAREA_PAD;
lw->textarea[0][1]= TEXTAREA_PAD;
lw->textarea[1][0]= lw->size[0] - TEXTAREA_PAD - 1;
lw->textarea[1][1]= lw->size[1] - TEXTAREA_PAD - 1;
lw->ndisplines= (lw->textarea[1][1]-lw->textarea[0][1])/lw->fontheight;
scrollbar_set_thumbpct(lw->scroll, (float) lw->ndisplines/lw->nloglines);
scrollbar_set_rect(lw->scroll, nscroll);
}
static void loggerwindow_setup_window_gl(LoggerWindow *lw) {
glViewport(0, 0, lw->size[0], lw->size[1]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, lw->size[0], 0, lw->size[1], -1, 1);
glTranslatef(0.375, 0.375, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
static void loggerwindow_do_reshape(LoggerWindow *lw) {
GHOST_RectangleHandle bounds= GHOST_GetClientBounds(lw->win);
GHOST_ActivateWindowDrawingContext(lw->win);
lw->size[0]= GHOST_GetWidthRectangle(bounds);
lw->size[1]= GHOST_GetHeightRectangle(bounds);
loggerwindow_recalc_regions(lw);
loggerwindow_setup_window_gl(lw);
}
static void loggerwindow_do_draw(LoggerWindow *lw) {
int i, ndisplines, startline;
int sb_rect[2][2], sb_thumb[2][2];
GHOST_ActivateWindowDrawingContext(lw->win);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.8, 0.8, 0.8);
rect_bevel_smooth(lw->textarea, 4);
scrollbar_get_rect(lw->scroll, sb_rect);
scrollbar_get_thumb(lw->scroll, sb_thumb);
glColor3f(0.6, 0.6, 0.6);
rect_bevel_smooth(sb_rect, 1);
if (scrollbar_is_scrolling(lw->scroll)) {
glColor3f(0.6, 0.7, 0.5);
} else {
glColor3f(0.9, 0.9, 0.92);
}
rect_bevel_smooth(sb_thumb, 1);
startline= scrollbar_get_thumbpos(lw->scroll)*(lw->nloglines-1);
ndisplines= min_i(lw->ndisplines, lw->nloglines-startline);
if (lw->fonttexid!=-1) {
glBindTexture(GL_TEXTURE_2D, lw->fonttexid);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
}
glColor3f(0, 0, 0);
for (i=0; i<ndisplines; i++) {
/* stored in reverse order */
char *line= lw->loglines[(lw->nloglines-1)-(i+startline)];
int x_pos= lw->textarea[0][0] + 4;
int y_pos= lw->textarea[0][1] + 4 + i*lw->fontheight;
if (lw->fonttexid==-1) {
glRasterPos2i(x_pos, y_pos);
BMF_DrawString(lw->font, line);
} else {
BMF_DrawStringTexture(lw->font, line, x_pos, y_pos, 0.0);
}
}
if (lw->fonttexid!=-1) {
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}
GHOST_SwapWindowBuffers(lw->win);
}
static void loggerwindow_do_move(LoggerWindow *lw, int x, int y) {
lw->lmouse[0]= x, lw->lmouse[1]= y;
if (scrollbar_is_scrolling(lw->scroll)) {
scrollbar_keep_scrolling(lw->scroll, y);
GHOST_InvalidateWindow(lw->win);
}
}
static void loggerwindow_do_button(LoggerWindow *lw, int which, int press) {
if (which==GHOST_kButtonMaskLeft) {
lw->lmbut[0]= press;
if (press) {
if (scrollbar_contains_pt(lw->scroll, lw->lmouse)) {
scrollbar_start_scrolling(lw->scroll, lw->lmouse[1]);
GHOST_SetCursorShape(lw->win, GHOST_kStandardCursorUpDown);
GHOST_InvalidateWindow(lw->win);
}
} else {
if (scrollbar_is_scrolling(lw->scroll)) {
scrollbar_stop_scrolling(lw->scroll);
GHOST_SetCursorShape(lw->win, GHOST_kStandardCursorDefault);
GHOST_InvalidateWindow(lw->win);
}
}
} else if (which==GHOST_kButtonMaskMiddle) {
lw->lmbut[1]= press;
} else if (which==GHOST_kButtonMaskRight) {
lw->lmbut[2]= press;
}
}
static void loggerwindow_do_key(LoggerWindow *lw, GHOST_TKey key, int press) {
switch (key) {
case GHOST_kKeyQ:
if (press)
multitestapp_exit(lw->app);
break;
}
}
static void loggerwindow_handle(void *priv, GHOST_EventHandle evt) {
LoggerWindow *lw= priv;
GHOST_TEventType type= GHOST_GetEventType(evt);
switch(type) {
case GHOST_kEventCursorMove: {
GHOST_TEventCursorData *cd= GHOST_GetEventData(evt);
int x, y;
GHOST_ScreenToClient(lw->win, cd->x, cd->y, &x, &y);
loggerwindow_do_move(lw, x, lw->size[1]-y-1);
break;
}
case GHOST_kEventButtonDown:
case GHOST_kEventButtonUp: {
GHOST_TEventButtonData *bd= GHOST_GetEventData(evt);
loggerwindow_do_button(lw, bd->button, (type == GHOST_kEventButtonDown));
break;
}
case GHOST_kEventKeyDown:
case GHOST_kEventKeyUp: {
GHOST_TEventKeyData *kd= GHOST_GetEventData(evt);
loggerwindow_do_key(lw, kd->key, (type == GHOST_kEventKeyDown));
break;
}
case GHOST_kEventWindowUpdate:
loggerwindow_do_draw(lw);
break;
case GHOST_kEventWindowSize:
loggerwindow_do_reshape(lw);
break;
}
}
/**/
LoggerWindow *loggerwindow_new(MultiTestApp *app) {
GHOST_SystemHandle sys= multitestapp_get_system(app);
GHOST_TUns32 screensize[2];
GHOST_WindowHandle win;
GHOST_GetMainDisplayDimensions(sys, &screensize[0], &screensize[1]);
win= GHOST_CreateWindow(sys, "MultiTest:Logger", 40, screensize[1]-432,
800, 300, GHOST_kWindowStateNormal,
GHOST_kDrawingContextTypeOpenGL, FALSE);
if (win) {
LoggerWindow *lw= MEM_callocN(sizeof(*lw), "loggerwindow_new");
int bbox[2][2];
lw->app= app;
lw->win= win;
lw->font= BMF_GetFont(BMF_kScreen12);
lw->fonttexid= BMF_GetFontTexture(lw->font);
BMF_GetBoundingBox(lw->font, &bbox[0][0], &bbox[0][1], &bbox[1][0], &bbox[1][1]);
lw->fontheight= rect_height(bbox);
lw->nloglines= lw->logsize= 0;
lw->loglines= MEM_mallocN(sizeof(*lw->loglines)*lw->nloglines, "loglines");
lw->scroll= scrollbar_new(2, 40);
GHOST_SetWindowUserData(lw->win, windowdata_new(lw, loggerwindow_handle));
loggerwindow_do_reshape(lw);
return lw;
} else {
return NULL;
}
}
void loggerwindow_log(LoggerWindow *lw, char *line) {
if (lw->nloglines==lw->logsize) {
lw->loglines= memdbl(lw->loglines, &lw->logsize, sizeof(*lw->loglines));
}
lw->loglines[lw->nloglines++]= string_dup(line);
scrollbar_set_thumbpct(lw->scroll, (float) lw->ndisplines/lw->nloglines);
GHOST_InvalidateWindow(lw->win);
}
void loggerwindow_free(LoggerWindow *lw) {
GHOST_SystemHandle sys= multitestapp_get_system(lw->app);
int i;
for (i=0; i<lw->nloglines; i++) {
MEM_freeN(lw->loglines[i]);
}
MEM_freeN(lw->loglines);
windowdata_free(GHOST_GetWindowUserData(lw->win));
GHOST_DisposeWindow(sys, lw->win);
MEM_freeN(lw);
}
/*
* ExtraWindow
*/
typedef struct {
MultiTestApp *app;
GHOST_WindowHandle win;
int size[2];
} ExtraWindow;
static void extrawindow_do_draw(ExtraWindow *ew) {
GHOST_ActivateWindowDrawingContext(ew->win);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.8, 0.8, 0.8);
glRecti(10, 10, ew->size[0]-10, ew->size[1]-10);
GHOST_SwapWindowBuffers(ew->win);
}
static void extrawindow_do_reshape(ExtraWindow *ew) {
GHOST_RectangleHandle bounds= GHOST_GetClientBounds(ew->win);
GHOST_ActivateWindowDrawingContext(ew->win);
ew->size[0]= GHOST_GetWidthRectangle(bounds);
ew->size[1]= GHOST_GetHeightRectangle(bounds);
glViewport(0, 0, ew->size[0], ew->size[1]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, ew->size[0], 0, ew->size[1], -1, 1);
glTranslatef(0.375, 0.375, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
static void extrawindow_do_key(ExtraWindow *ew, GHOST_TKey key, int press) {
switch (key) {
case GHOST_kKeyE:
if (press)
multitestapp_toggle_extra_window(ew->app);
break;
}
}
static void extrawindow_spin_cursor(ExtraWindow *ew, GHOST_TUns64 time) {
GHOST_TUns8 bitmap[16][2];
GHOST_TUns8 mask[16][2];
double ftime= (double) ((GHOST_TInt64) time)/1000;
float angle= fmod(ftime, 1.0) * 3.1415*2;
int i;
memset(&bitmap, 0, sizeof(bitmap));
memset(&mask, 0, sizeof(mask));
bitmap[0][0] |= mask[0][0] |= 0xF;
bitmap[1][0] |= mask[1][0] |= 0xF;
bitmap[2][0] |= mask[2][0] |= 0xF;
bitmap[3][0] |= mask[3][0] |= 0xF;
for (i=0; i<7; i++) {
int x = 7 + cos(angle)*i;
int y = 7 + sin(angle)*i;
mask[y][x/8] |= (1 << (x%8));
}
for (i=0; i<64; i++) {
float v= (i/63.0) * 3.1415*2;
int x = 7 + cos(v)*7;
int y = 7 + sin(v)*7;
mask[y][x/8] |= (1 << (x%8));
}
GHOST_SetCustomCursorShape(ew->win, bitmap, mask, 0, 0);
}
static void extrawindow_handle(void *priv, GHOST_EventHandle evt) {
ExtraWindow *ew= priv;
GHOST_TEventType type= GHOST_GetEventType(evt);
char buf[256];
event_to_buf(evt, buf);
loggerwindow_log(multitestapp_get_logger(ew->app), buf);
switch (type) {
case GHOST_kEventKeyDown:
case GHOST_kEventKeyUp: {
GHOST_TEventKeyData *kd= GHOST_GetEventData(evt);
extrawindow_do_key(ew, kd->key, (type == GHOST_kEventKeyDown));
break;
}
case GHOST_kEventCursorMove: {
extrawindow_spin_cursor(ew, GHOST_GetEventTime(evt));
break;
}
case GHOST_kEventWindowClose:
multitestapp_free_extrawindow(ew->app);
break;
case GHOST_kEventWindowUpdate:
extrawindow_do_draw(ew);
break;
case GHOST_kEventWindowSize:
extrawindow_do_reshape(ew);
break;
}
}
/**/
ExtraWindow *extrawindow_new(MultiTestApp *app) {
GHOST_SystemHandle sys= multitestapp_get_system(app);
GHOST_WindowHandle win;
win= GHOST_CreateWindow(sys, "MultiTest:Extra", 500, 40, 400, 400,
GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL,
FALSE);
if (win) {
ExtraWindow *ew= MEM_callocN(sizeof(*ew), "mainwindow_new");
ew->app= app;
ew->win= win;
GHOST_SetWindowUserData(ew->win, windowdata_new(ew, extrawindow_handle));
return ew;
} else {
return NULL;
}
}
void extrawindow_free(ExtraWindow *ew) {
GHOST_SystemHandle sys= multitestapp_get_system(ew->app);
windowdata_free(GHOST_GetWindowUserData(ew->win));
GHOST_DisposeWindow(sys, ew->win);
MEM_freeN(ew);
}
/*
* MultiTestApp
*/
struct _MultiTestApp {
GHOST_SystemHandle sys;
MainWindow *main;
LoggerWindow *logger;
ExtraWindow *extra;
int exit;
};
static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr data) {
MultiTestApp *app= data;
GHOST_WindowHandle win;
win= GHOST_GetEventWindow(evt);
if (win && !GHOST_ValidWindow(app->sys, win)) {
loggerwindow_log(app->logger, "WARNING: bad event, non-valid window\n");
return 1;
}
if (win) {
WindowData *wb= GHOST_GetWindowUserData(win);
windowdata_handle(wb, evt);
} else {
GHOST_TEventType type= GHOST_GetEventType(evt);
/* GHOST_kEventQuit are the only 'system' events,
* that is, events without a window.
*/
switch(type) {
case GHOST_kEventQuit:
app->exit= 1;
break;
default:
fatal("Unhandled system event: %d (%s)\n", type, eventtype_to_string(type));
break;
}
}
return 1;
}
/**/
MultiTestApp *multitestapp_new(void) {
MultiTestApp *app= MEM_mallocN(sizeof(*app), "multitestapp_new");
GHOST_EventConsumerHandle consumer= GHOST_CreateEventConsumer(multitest_event_handler, app);
app->sys= GHOST_CreateSystem();
if (!app->sys)
fatal("Unable to create ghost system");
if (!GHOST_AddEventConsumer(app->sys, consumer))
fatal("Unable to add multitest event consumer ");
app->main= mainwindow_new(app);
if (!app->main)
fatal("Unable to create main window");
app->logger= loggerwindow_new(app);
if (!app->logger)
fatal("Unable to create logger window");
app->extra= NULL;
app->exit= 0;
return app;
}
LoggerWindow *multitestapp_get_logger(MultiTestApp *app) {
return app->logger;
}
GHOST_SystemHandle multitestapp_get_system(MultiTestApp *app) {
return app->sys;
}
void multitestapp_free_extrawindow(MultiTestApp *app) {
extrawindow_free(app->extra);
app->extra= NULL;
}
void multitestapp_toggle_extra_window(MultiTestApp *app) {
if (app->extra) {
multitestapp_free_extrawindow(app);
} else {
app->extra= extrawindow_new(app);
}
}
void multitestapp_exit(MultiTestApp *app) {
app->exit= 1;
}
void multitestapp_run(MultiTestApp *app) {
while (!app->exit) {
GHOST_ProcessEvents(app->sys, 1);
GHOST_DispatchEvents(app->sys);
}
}
void multitestapp_free(MultiTestApp *app) {
mainwindow_free(app->main);
loggerwindow_free(app->logger);
GHOST_DisposeSystem(app->sys);
MEM_freeN(app);
}
/***/
int main(int argc, char **argv) {
MultiTestApp *app= multitestapp_new();
multitestapp_run(app);
multitestapp_free(app);
return 0;
}

View File

@@ -0,0 +1,142 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
#include <stdlib.h>
#include <math.h>
#include "MEM_guardedalloc.h"
#include "Basic.h"
#include "ScrollBar.h"
struct _ScrollBar {
int rect[2][2];
float thumbpos, thumbpct;
int inset;
int minthumb;
int scrolling;
float scrolloffs;
};
static int scrollbar_get_thumbH(ScrollBar *sb) {
int scrollable_h= rect_height(sb->rect) - 2*sb->inset;
return clamp_i(sb->thumbpct*scrollable_h, sb->minthumb, scrollable_h);
}
static int scrollbar_get_thumbableH(ScrollBar *sb) {
int scrollable_h= rect_height(sb->rect) - 2*sb->inset;
int thumb_h= scrollbar_get_thumbH(sb);
return scrollable_h - thumb_h;
}
static float scrollbar_co_to_pos(ScrollBar *sb, int yco) {
int thumb_h= scrollbar_get_thumbH(sb);
int thumbable_h= scrollbar_get_thumbableH(sb);
int thumbable_y= (sb->rect[0][1]+sb->inset) + thumb_h/2;
return (float) (yco-thumbable_y)/thumbable_h;
}
/**/
ScrollBar *scrollbar_new(int inset, int minthumb) {
ScrollBar *sb= MEM_callocN(sizeof(*sb), "scrollbar_new");
sb->inset= inset;
sb->minthumb= minthumb;
return sb;
}
void scrollbar_get_thumb(ScrollBar *sb, int thumb_r[2][2]) {
int thumb_h= scrollbar_get_thumbH(sb);
int thumbable_h= scrollbar_get_thumbableH(sb);
thumb_r[0][0]= sb->rect[0][0]+sb->inset;
thumb_r[1][0]= sb->rect[1][0]-sb->inset;
thumb_r[0][1]= sb->rect[0][1]+sb->inset + sb->thumbpos*thumbable_h;
thumb_r[1][1]= thumb_r[0][1] + thumb_h;
}
int scrollbar_is_scrolling(ScrollBar *sb) {
return sb->scrolling;
}
int scrollbar_contains_pt(ScrollBar *sb, int pt[2]) {
return rect_contains_pt(sb->rect, pt);
}
void scrollbar_start_scrolling(ScrollBar *sb, int yco) {
int thumb_h_2= scrollbar_get_thumbH(sb)/2;
int thumbable_h= scrollbar_get_thumbableH(sb);
float npos= scrollbar_co_to_pos(sb, yco);
sb->scrolloffs= sb->thumbpos - npos;
if (fabs(sb->scrolloffs) >= (float) thumb_h_2/thumbable_h) {
sb->scrolloffs= 0.0;
}
sb->scrolling= 1;
sb->thumbpos= clamp_f(npos + sb->scrolloffs, 0.0, 1.0);
}
void scrollbar_keep_scrolling(ScrollBar *sb, int yco) {
float npos= scrollbar_co_to_pos(sb, yco);
sb->thumbpos= clamp_f(npos + sb->scrolloffs, 0.0, 1.0);
}
void scrollbar_stop_scrolling(ScrollBar *sb) {
sb->scrolling= 0;
sb->scrolloffs= 0.0;
}
void scrollbar_set_thumbpct(ScrollBar *sb, float pct) {
sb->thumbpct= pct;
}
void scrollbar_set_thumbpos(ScrollBar *sb, float pos) {
sb->thumbpos= clamp_f(pos, 0.0, 1.0);
}
void scrollbar_set_rect(ScrollBar *sb, int rect[2][2]) {
rect_copy(sb->rect, rect);
}
float scrollbar_get_thumbpct(ScrollBar *sb) {
return sb->thumbpct;
}
float scrollbar_get_thumbpos(ScrollBar *sb) {
return sb->thumbpos;
}
void scrollbar_get_rect(ScrollBar *sb, int rect_r[2][2]) {
rect_copy(rect_r, sb->rect);
}
void scrollbar_free(ScrollBar *sb) {
MEM_freeN(sb);
}

View File

@@ -0,0 +1,54 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
typedef struct _ScrollBar ScrollBar;
/***/
ScrollBar* scrollbar_new (int inset, int minthumb);
int scrollbar_is_scrolling (ScrollBar *sb);
int scrollbar_contains_pt (ScrollBar *sb, int pt[2]);
void scrollbar_start_scrolling (ScrollBar *sb, int yco);
void scrollbar_keep_scrolling (ScrollBar *sb, int yco);
void scrollbar_stop_scrolling (ScrollBar *sb);
void scrollbar_set_thumbpct (ScrollBar *sb, float pct);
void scrollbar_set_thumbpos (ScrollBar *sb, float pos);
void scrollbar_set_rect (ScrollBar *sb, int rect[2][2]);
float scrollbar_get_thumbpct (ScrollBar *sb);
float scrollbar_get_thumbpos (ScrollBar *sb);
void scrollbar_get_rect (ScrollBar *sb, int rect_r[2][2]);
void scrollbar_get_thumb (ScrollBar *sb, int thumb_r[2][2]);
void scrollbar_free (ScrollBar *sb);

View File

@@ -0,0 +1,70 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "MEM_guardedalloc.h"
#include "Util.h"
void* memdbl(void *mem, int *size_pr, int item_size) {
int cur_size= *size_pr;
int new_size= cur_size?(cur_size*2):1;
void *nmem= MEM_mallocN(new_size*item_size, "memdbl");
memcpy(nmem, mem, cur_size*item_size);
MEM_freeN(mem);
*size_pr= new_size;
return nmem;
}
char* string_dup(char *str) {
int len= strlen(str);
char *nstr= MEM_mallocN(len + 1, "string_dup");
memcpy(nstr, str, len+1);
return nstr;
}
void fatal(char *fmt, ...) {
va_list ap;
fprintf(stderr, "FATAL: ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}

View File

@@ -0,0 +1,33 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
void* memdbl (void *mem, int *size_pr, int item_size);
char* string_dup (char *str);
void fatal (char *fmt, ...);

View File

@@ -0,0 +1,56 @@
/**
* $Id$
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "MEM_guardedalloc.h"
#include "GHOST_C-api.h"
#include "WindowData.h"
struct _WindowData {
void *data;
WindowDataHandler handler;
};
WindowData *windowdata_new(void *data, WindowDataHandler handler) {
WindowData *wb= MEM_mallocN(sizeof(*wb), "windowdata_new");
wb->data= data;
wb->handler= handler;
return wb;
}
void windowdata_handle(WindowData *wb, GHOST_EventHandle evt) {
wb->handler(wb->data, evt);
}
void windowdata_free(WindowData *wb) {
MEM_freeN(wb);
}

Some files were not shown because too many files have changed in this diff Show More